Improve the explanation of version control to include concepts
[bpt/emacs.git] / lisp / vc-svn.el
CommitLineData
1fd3454a
SM
1;;; vc-svn.el --- non-resident support for Subversion version-control
2
c45b3be3 3;; Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
1fd3454a
SM
4
5;; Author: FSF (see vc.el for full credits)
6;; Maintainer: Stefan Monnier <monnier@gnu.org>
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation; either version 2, or (at your option)
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs; see the file COPYING. If not, write to the
086add15
LK
22;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23;; Boston, MA 02110-1301, USA.
1fd3454a
SM
24
25;;; Commentary:
26
27;; This is preliminary support for Subversion (http://subversion.tigris.org/).
28;; It started as `sed s/cvs/svn/ vc.cvs.el' (from version 1.56)
29;; and hasn't been completely fixed since.
30
31;; Sync'd with Subversion's vc-svn.el as of revision 5801.
32
33;;; Bugs:
34
fd140743 35;; - VC-dired is (really) slow.
1fd3454a
SM
36
37;;; Code:
38
39(eval-when-compile
40 (require 'vc))
41
42;;;
43;;; Customization options
44;;;
45
46(defcustom vc-svn-global-switches nil
47 "*Global switches to pass to any SVN command."
48 :type '(choice (const :tag "None" nil)
49 (string :tag "Argument String")
50 (repeat :tag "Argument List"
51 :value ("")
52 string))
bf247b6e 53 :version "22.1"
1fd3454a
SM
54 :group 'vc)
55
56(defcustom vc-svn-register-switches nil
57 "*Extra switches for registering a file into SVN.
58A string or list of strings passed to the checkin program by
59\\[vc-register]."
60 :type '(choice (const :tag "None" nil)
61 (string :tag "Argument String")
62 (repeat :tag "Argument List"
63 :value ("")
64 string))
bf247b6e 65 :version "22.1"
1fd3454a
SM
66 :group 'vc)
67
8462aca5
SM
68(defcustom vc-svn-diff-switches
69 t ;`svn' doesn't support common args like -c or -b.
70 "String or list of strings specifying extra switches for svn diff under VC.
71If nil, use the value of `vc-diff-switches'.
72If you want to force an empty list of arguments, use t."
73 :type '(choice (const :tag "Unspecified" nil)
74 (const :tag "None" t)
1fd3454a
SM
75 (string :tag "Argument String")
76 (repeat :tag "Argument List"
77 :value ("")
78 string))
bf247b6e 79 :version "22.1"
1fd3454a
SM
80 :group 'vc)
81
82(defcustom vc-svn-header (or (cdr (assoc 'SVN vc-header-alist)) '("\$Id\$"))
83 "*Header keywords to be inserted by `vc-insert-headers'."
bf247b6e 84 :version "22.1"
1fd3454a
SM
85 :type '(repeat string)
86 :group 'vc)
87
fc2fb30c
SM
88;; We want to autoload it for use by the autoloaded version of
89;; vc-svn-registered, but we want the value to be compiled at startup, not
90;; at dump time.
91;; ;;;###autoload
92(defconst vc-svn-admin-directory
93 (cond ((and (memq system-type '(cygwin windows-nt ms-dos))
ace2fad9
CY
94 (getenv "SVN_ASP_DOT_NET_HACK"))
95 "_svn")
96 (t ".svn"))
97 "The name of the \".svn\" subdirectory or its equivalent.")
98
8cdd17b4
ER
99;;; Properties of the backend
100
101(defun vc-svn-revision-granularity ()
102 'repository)
1fd3454a
SM
103;;;
104;;; State-querying functions
105;;;
106
ace2fad9
CY
107;;; vc-svn-admin-directory is generally not defined when the
108;;; autoloaded function is called.
109
1fd3454a 110;;;###autoload (defun vc-svn-registered (f)
ace2fad9 111;;;###autoload (let ((admin-dir (cond ((and (eq system-type 'windows-nt)
fc2fb30c
SM
112;;;###autoload (getenv "SVN_ASP_DOT_NET_HACK"))
113;;;###autoload "_svn")
114;;;###autoload (t ".svn"))))
ace2fad9 115;;;###autoload (when (file-readable-p (expand-file-name
fc2fb30c
SM
116;;;###autoload (concat admin-dir "/entries")
117;;;###autoload (file-name-directory f)))
1fd3454a 118;;;###autoload (load "vc-svn")
ace2fad9 119;;;###autoload (vc-svn-registered f))))
1fd3454a 120
3bdc13e4
SM
121;;;###autoload
122(add-to-list 'completion-ignored-extensions ".svn/")
123
1fd3454a
SM
124(defun vc-svn-registered (file)
125 "Check if FILE is SVN registered."
ace2fad9
CY
126 (when (file-readable-p (expand-file-name (concat vc-svn-admin-directory
127 "/entries")
1fd3454a
SM
128 (file-name-directory file)))
129 (with-temp-buffer
130 (cd (file-name-directory file))
aaef169d 131 (let ((status
df4da7f4
SM
132 (condition-case nil
133 ;; Ignore all errors.
134 (vc-svn-command t t file "status" "-v")
135 ;; Some problem happened. E.g. We can't find an `svn'
136 ;; executable. We used to only catch `file-error' but when
137 ;; the process is run on a remote host via Tramp, the error
138 ;; is only reported via the exit status which is turned into
139 ;; an `error' by vc-do-command.
140 (error nil))))
141 (when (eq 0 status)
bc8c1bb4 142 (vc-svn-parse-status file))))))
1fd3454a
SM
143
144(defun vc-svn-state (file &optional localp)
145 "SVN-specific version of `vc-state'."
7ffc77d3 146 (setq localp (or localp (vc-stay-local-p file)))
1fd3454a
SM
147 (with-temp-buffer
148 (cd (file-name-directory file))
149 (vc-svn-command t 0 file "status" (if localp "-v" "-u"))
bc8c1bb4 150 (vc-svn-parse-status file)))
1fd3454a
SM
151
152(defun vc-svn-state-heuristic (file)
153 "SVN-specific state heuristic."
154 (vc-svn-state file 'local))
155
156(defun vc-svn-dir-state (dir &optional localp)
157 "Find the SVN state of all files in DIR."
7ffc77d3 158 (setq localp (or localp (vc-stay-local-p dir)))
1fd3454a
SM
159 (let ((default-directory dir))
160 ;; Don't specify DIR in this command, the default-directory is
161 ;; enough. Otherwise it might fail with remote repositories.
162 (with-temp-buffer
163 (vc-svn-command t 0 nil "status" (if localp "-v" "-u"))
bc8c1bb4 164 (vc-svn-parse-status))))
1fd3454a
SM
165
166(defun vc-svn-workfile-version (file)
167 "SVN-specific version of `vc-workfile-version'."
168 ;; There is no need to consult RCS headers under SVN, because we
169 ;; get the workfile version for free when we recognize that a file
170 ;; is registered in SVN.
171 (vc-svn-registered file)
172 (vc-file-getprop file 'vc-workfile-version))
173
174(defun vc-svn-checkout-model (file)
175 "SVN-specific version of `vc-checkout-model'."
176 ;; It looks like Subversion has no equivalent of CVSREAD.
177 'implicit)
178
5cc7cb96
SM
179;; vc-svn-mode-line-string doesn't exist because the default implementation
180;; works just fine.
181
1fd3454a
SM
182(defun vc-svn-dired-state-info (file)
183 "SVN-specific version of `vc-dired-state-info'."
fd140743
SM
184 (let ((svn-state (vc-state file)))
185 (cond ((eq svn-state 'edited)
186 (if (equal (vc-workfile-version file) "0")
187 "(added)" "(modified)"))
188 ((eq svn-state 'needs-patch) "(patch)")
189 ((eq svn-state 'needs-merge) "(merge)"))))
1fd3454a 190
cbbd2cd3
TTN
191(defun vc-svn-previous-version (file rev)
192 (let ((newrev (1- (string-to-number rev))))
193 (when (< 0 newrev)
194 (number-to-string newrev))))
195
196(defun vc-svn-next-version (file rev)
197 (let ((newrev (1+ (string-to-number rev))))
198 ;; The "workfile version" is an uneasy conceptual fit under Subversion;
199 ;; we use it as the upper bound until a better idea comes along. If the
200 ;; workfile version W coincides with the tree's latest revision R, then
201 ;; this check prevents a "no such revision: R+1" error. Otherwise, it
202 ;; inhibits showing of W+1 through R, which could be considered anywhere
203 ;; from gracious to impolite.
204 (unless (< (string-to-number (vc-file-getprop file 'vc-workfile-version))
205 newrev)
206 (number-to-string newrev))))
207
1fd3454a
SM
208
209;;;
210;;; State-changing functions
211;;;
212
8cdd17b4
ER
213(defun vc-svn-create-repo ()
214 "Create a new SVN repository."
215 (vc-do-command nil 0 "svnadmin" '("create" "SVN"))
216 (vc-do-command nil 0 "svn" '(".")
217 "checkout" (concat "file://" default-directory "SVN")))
218
219(defun vc-svn-register (files &optional rev comment)
220 "Register FILES into the SVN version-control system.
221The COMMENT argument is ignored This does an add but not a commit.
1fd3454a
SM
222
223`vc-register-switches' and `vc-svn-register-switches' are passed to
224the SVN command (in that order)."
8cdd17b4 225 (apply 'vc-svn-command nil 0 files "add" (vc-switches 'SVN 'register)))
1fd3454a
SM
226
227(defun vc-svn-responsible-p (file)
228 "Return non-nil if SVN thinks it is responsible for FILE."
ace2fad9 229 (file-directory-p (expand-file-name vc-svn-admin-directory
1fd3454a
SM
230 (if (file-directory-p file)
231 file
232 (file-name-directory file)))))
233
234(defalias 'vc-svn-could-register 'vc-svn-responsible-p
235 "Return non-nil if FILE could be registered in SVN.
236This is only possible if SVN is responsible for FILE's directory.")
237
8cdd17b4 238(defun vc-svn-checkin (files rev comment)
1fd3454a 239 "SVN-specific version of `vc-backend-checkin'."
8cdd17b4 240 (if rev (error "Committing to a specific revision is unsupported in SVN."))
5129f10c 241 (let ((status (apply
8cdd17b4 242 'vc-svn-command nil 1 files "ci"
5129f10c 243 (nconc (list "-m" comment) (vc-switches 'SVN 'checkin)))))
1fd3454a
SM
244 (set-buffer "*vc*")
245 (goto-char (point-min))
246 (unless (equal status 0)
247 ;; Check checkin problem.
248 (cond
fd140743 249 ((search-forward "Transaction is out of date" nil t)
8cdd17b4
ER
250 (mapc (lambda (file) (vc-file-setprop file 'vc-state 'needs-merge))
251 files)
1fd3454a
SM
252 (error (substitute-command-keys
253 (concat "Up-to-date check failed: "
254 "type \\[vc-next-action] to merge in changes"))))
255 (t
256 (pop-to-buffer (current-buffer))
257 (goto-char (point-min))
258 (shrink-window-if-larger-than-buffer)
259 (error "Check-in failed"))))
260 ;; Update file properties
261 ;; (vc-file-setprop
262 ;; file 'vc-workfile-version
263 ;; (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
264 ))
265
266(defun vc-svn-find-version (file rev buffer)
8cdd17b4 267 "SVN-specific retrieval of a specified version into a buffer."
1fd3454a
SM
268 (apply 'vc-svn-command
269 buffer 0 file
270 "cat"
271 (and rev (not (string= rev ""))
272 (concat "-r" rev))
fd140743 273 (vc-switches 'SVN 'checkout)))
1fd3454a
SM
274
275(defun vc-svn-checkout (file &optional editable rev)
276 (message "Checking out %s..." file)
277 (with-current-buffer (or (get-file-buffer file) (current-buffer))
fd140743 278 (vc-call update file editable rev (vc-switches 'SVN 'checkout)))
1fd3454a
SM
279 (vc-mode-line file)
280 (message "Checking out %s...done" file))
281
282(defun vc-svn-update (file editable rev switches)
283 (if (and (file-exists-p file) (not rev))
fc2fb30c
SM
284 ;; If no revision was specified, there's nothing to do.
285 nil
1fd3454a
SM
286 ;; Check out a particular version (or recreate the file).
287 (vc-file-setprop file 'vc-workfile-version nil)
288 (apply 'vc-svn-command nil 0 file
1fd3454a
SM
289 "update"
290 ;; default for verbose checkout: clear the sticky tag so
291 ;; that the actual update will get the head of the trunk
5cc7cb96
SM
292 (cond
293 ((null rev) "-rBASE")
294 ((or (eq rev t) (equal rev "")) nil)
295 (t (concat "-r" rev)))
1fd3454a
SM
296 switches)))
297
3bdc13e4
SM
298(defun vc-svn-delete-file (file)
299 (vc-svn-command nil 0 file "remove"))
300
2766aaaf
SM
301(defun vc-svn-rename-file (old new)
302 (vc-svn-command nil 0 new "move" (file-relative-name old)))
303
1fd3454a
SM
304(defun vc-svn-revert (file &optional contents-done)
305 "Revert FILE to the version it was based on."
306 (unless contents-done
fc2fb30c 307 (vc-svn-command nil 0 file "revert")))
1fd3454a
SM
308
309(defun vc-svn-merge (file first-version &optional second-version)
310 "Merge changes into current working copy of FILE.
311The changes are between FIRST-VERSION and SECOND-VERSION."
312 (vc-svn-command nil 0 file
c217cb04 313 "merge"
02610d0e 314 "-r" (if second-version
c217cb04
SM
315 (concat first-version ":" second-version)
316 first-version))
1fd3454a
SM
317 (vc-file-setprop file 'vc-state 'edited)
318 (with-current-buffer (get-buffer "*vc*")
319 (goto-char (point-min))
c217cb04
SM
320 (if (looking-at "C ")
321 1 ; signal conflict
1fd3454a
SM
322 0))) ; signal success
323
324(defun vc-svn-merge-news (file)
325 "Merge in any new changes made to FILE."
326 (message "Merging changes into %s..." file)
327 ;; (vc-file-setprop file 'vc-workfile-version nil)
328 (vc-file-setprop file 'vc-checkout-time 0)
329 (vc-svn-command nil 0 file "update")
330 ;; Analyze the merge result reported by SVN, and set
331 ;; file properties accordingly.
332 (with-current-buffer (get-buffer "*vc*")
333 (goto-char (point-min))
334 ;; get new workfile version
335 (if (re-search-forward
1468d754
SM
336 "^\\(Updated to\\|At\\) revision \\([0-9]+\\)" nil t)
337 (vc-file-setprop file 'vc-workfile-version (match-string 2))
1fd3454a
SM
338 (vc-file-setprop file 'vc-workfile-version nil))
339 ;; get file status
1468d754 340 (goto-char (point-min))
1fd3454a 341 (prog1
1468d754 342 (if (looking-at "At revision")
1fd3454a
SM
343 0 ;; there were no news; indicate success
344 (if (re-search-forward
459b1fe4
SM
345 ;; Newer SVN clients have 3 columns of chars (one for the
346 ;; file's contents, then second for its properties, and the
347 ;; third for lock-grabbing info), before the 2 spaces.
348 ;; We also used to match the filename in column 0 without any
349 ;; meta-info before it, but I believe this can never happen.
350 (concat "^\\(\\([ACGDU]\\)\\(.[B ]\\)? \\)"
1468d754 351 (regexp-quote (file-name-nondirectory file)))
1fd3454a
SM
352 nil t)
353 (cond
354 ;; Merge successful, we are in sync with repository now
459b1fe4 355 ((string= (match-string 2) "U")
1fd3454a
SM
356 (vc-file-setprop file 'vc-state 'up-to-date)
357 (vc-file-setprop file 'vc-checkout-time
358 (nth 5 (file-attributes file)))
359 0);; indicate success to the caller
360 ;; Merge successful, but our own changes are still in the file
459b1fe4 361 ((string= (match-string 2) "G")
1fd3454a
SM
362 (vc-file-setprop file 'vc-state 'edited)
363 0);; indicate success to the caller
364 ;; Conflicts detected!
365 (t
366 (vc-file-setprop file 'vc-state 'edited)
367 1);; signal the error to the caller
368 )
369 (pop-to-buffer "*vc*")
370 (error "Couldn't analyze svn update result")))
371 (message "Merging changes into %s...done" file))))
372
373
374;;;
375;;; History functions
376;;;
377
8cdd17b4
ER
378(defun vc-svn-print-log (files &optional buffer)
379 "Get change log(s) associated with FILES."
1fd3454a 380 (save-current-buffer
b349012b 381 (vc-setup-buffer buffer)
1fd3454a
SM
382 (let ((inhibit-read-only t))
383 (goto-char (point-min))
384 ;; Add a line to tell log-view-mode what file this is.
8cdd17b4 385 (insert "Working file(s): " (vc-delistify (mapcar 'file-relative-name files)) "\n"))
1fd3454a 386 (vc-svn-command
b349012b 387 buffer
8cdd17b4
ER
388 (if (and (= (length files) 1) (vc-stay-local-p (car files)) (fboundp 'start-process)) 'async 0)
389 files "log"
bf54d814
SM
390 ;; By default Subversion only shows the log upto the working version,
391 ;; whereas we also want the log of the subsequent commits. At least
392 ;; that's what the vc-cvs.el code does.
8cdd17b4
ER
393 "-rHEAD:0"))))
394
395(defun vc-svn-wash-log ()
396 "Remove all non-comment information from log output."
397 ;; FIXME: not implemented for SVN
398 nil)
399
400(defun vc-svn-diff (files &optional oldvers newvers buffer)
401 "Get a difference report using SVN between two versions of fileset FILES."
402 (let* ((switches
f9d1f3be
SM
403 (if vc-svn-diff-switches
404 (vc-switches 'SVN 'diff)
405 (list "-x" (mapconcat 'identity (vc-switches nil 'diff) " "))))
2d4e93b9 406 (async (and (not vc-disable-async-diff)
8cdd17b4 407 (vc-stay-local-p files)
fd140743 408 (or oldvers newvers) ; Svn diffs those locally.
2766aaaf 409 (fboundp 'start-process))))
b349012b 410 (apply 'vc-svn-command buffer
2766aaaf 411 (if async 'async 0)
8cdd17b4 412 files "diff"
2766aaaf 413 (append
f9d1f3be 414 switches
2766aaaf
SM
415 (when oldvers
416 (list "-r" (if newvers (concat oldvers ":" newvers)
417 oldvers)))))
fd140743
SM
418 (if async 1 ; async diff => pessimistic assumption
419 ;; For some reason `svn diff' does not return a useful
420 ;; status w.r.t whether the diff was empty or not.
8cdd17b4 421 (buffer-size (get-buffer buffer)))))
1fd3454a
SM
422
423(defun vc-svn-diff-tree (dir &optional rev1 rev2)
424 "Diff all files at and below DIR."
5cc7cb96 425 (vc-svn-diff (file-name-as-directory dir) rev1 rev2))
1fd3454a
SM
426
427;;;
428;;; Snapshot system
429;;;
430
431(defun vc-svn-create-snapshot (dir name branchp)
432 "Assign to DIR's current version a given NAME.
433If BRANCHP is non-nil, the name is created as a branch (and the current
5cc7cb96
SM
434workspace is immediately moved to that new branch).
435NAME is assumed to be a URL."
436 (vc-svn-command nil 0 dir "copy" name)
437 (when branchp (vc-svn-retrieve-snapshot dir name nil)))
1fd3454a
SM
438
439(defun vc-svn-retrieve-snapshot (dir name update)
440 "Retrieve a snapshot at and below DIR.
441NAME is the name of the snapshot; if it is empty, do a `svn update'.
5cc7cb96
SM
442If UPDATE is non-nil, then update (resynch) any affected buffers.
443NAME is assumed to be a URL."
444 (vc-svn-command nil 0 dir "switch" name)
445 ;; FIXME: parse the output and obey `update'.
446 )
1fd3454a
SM
447
448;;;
449;;; Miscellaneous
450;;;
451
452;; Subversion makes backups for us, so don't bother.
7ffc77d3 453;; (defalias 'vc-svn-make-version-backups-p 'vc-stay-local-p
1fd3454a
SM
454;; "Return non-nil if version backups should be made for FILE.")
455
456(defun vc-svn-check-headers ()
457 "Check if the current file has any headers in it."
458 (save-excursion
459 (goto-char (point-min))
460 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
461\\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
462
463
464;;;
465;;; Internal functions
466;;;
467
e4cc3f57
SM
468(defcustom vc-svn-program "svn"
469 "Name of the svn executable."
470 :type 'string
471 :group 'vc)
472
8cdd17b4 473(defun vc-svn-command (buffer okstatus file-or-list &rest flags)
1fd3454a
SM
474 "A wrapper around `vc-do-command' for use in vc-svn.el.
475The difference to vc-do-command is that this function always invokes `svn',
476and that it passes `vc-svn-global-switches' to it before FLAGS."
8cdd17b4 477 (apply 'vc-do-command buffer okstatus vc-svn-program file-or-list
1fd3454a
SM
478 (if (stringp vc-svn-global-switches)
479 (cons vc-svn-global-switches flags)
480 (append vc-svn-global-switches
481 flags))))
482
7ffc77d3
SM
483(defun vc-svn-repository-hostname (dirname)
484 (with-temp-buffer
485 (let ((coding-system-for-read
486 (or file-name-coding-system
487 default-file-name-coding-system)))
ace2fad9
CY
488 (vc-insert-file (expand-file-name (concat vc-svn-admin-directory
489 "/entries")
490 dirname)))
7ffc77d3
SM
491 (goto-char (point-min))
492 (when (re-search-forward
c45b3be3 493 ;; Old `svn' used name="svn:this_dir", newer use just name="".
17a5a301
SM
494 (concat "name=\"\\(?:svn:this_dir\\)?\"[\n\t ]*"
495 "\\(?:[-a-z]+=\"[^\"]*\"[\n\t ]*\\)*?"
0b0dad41
SM
496 "url=\"\\(?1:[^\"]+\\)\""
497 ;; Yet newer ones don't use XML any more.
498 "\\|^\ndir\n[0-9]+\n\\(?1:.*\\)") nil t)
17a5a301
SM
499 ;; This is not a hostname but a URL. This may actually be considered
500 ;; as a feature since it allows vc-svn-stay-local to specify different
501 ;; behavior for different modules on the same server.
502 (match-string 1))))
1fd3454a 503
bc8c1bb4 504(defun vc-svn-parse-status (&optional filename)
1fd3454a 505 "Parse output of \"svn status\" command in the current buffer.
bc8c1bb4
SM
506Set file properties accordingly. Unless FILENAME is non-nil, parse only
507information about FILENAME and return its status."
1fd3454a
SM
508 (let (file status)
509 (goto-char (point-min))
510 (while (re-search-forward
c45b3be3
SM
511 ;; Ignore the files with status in [IX?].
512 "^[ ACDGMR!~][ MC][ L][ +][ S]..\\([ *]\\) +\\([-0-9]+\\) +\\([0-9?]+\\) +\\([^ ]+\\) +" nil t)
513 ;; If the username contains spaces, the output format is ambiguous,
514 ;; so don't trust the output's filename unless we have to.
515 (setq file (or filename
516 (expand-file-name
517 (buffer-substring (point) (line-end-position)))))
1fd3454a
SM
518 (setq status (char-after (line-beginning-position)))
519 (unless (eq status ??)
bc8c1bb4
SM
520 ;; `vc-BACKEND-registered' must not set vc-backend,
521 ;; which is instead set in vc-registered.
522 (unless filename (vc-file-setprop file 'vc-backend 'SVN))
fd140743
SM
523 ;; Use the last-modified revision, so that searching in vc-print-log
524 ;; output works.
525 (vc-file-setprop file 'vc-workfile-version (match-string 3))
1fd3454a
SM
526 (vc-file-setprop
527 file 'vc-state
528 (cond
529 ((eq status ?\ )
530 (if (eq (char-after (match-beginning 1)) ?*)
531 'needs-patch
532 (vc-file-setprop file 'vc-checkout-time
533 (nth 5 (file-attributes file)))
534 'up-to-date))
535 ((eq status ?A)
fd140743
SM
536 ;; If the file was actually copied, (match-string 2) is "-".
537 (vc-file-setprop file 'vc-workfile-version "0")
1fd3454a
SM
538 (vc-file-setprop file 'vc-checkout-time 0)
539 'edited)
540 ((memq status '(?M ?C))
541 (if (eq (char-after (match-beginning 1)) ?*)
542 'needs-merge
543 'edited))
bc8c1bb4
SM
544 (t 'edited)))))
545 (if filename (vc-file-getprop filename 'vc-state))))
1fd3454a
SM
546
547(defun vc-svn-dir-state-heuristic (dir)
548 "Find the SVN state of all files in DIR, using only local information."
549 (vc-svn-dir-state dir 'local))
550
551(defun vc-svn-valid-symbolic-tag-name-p (tag)
552 "Return non-nil if TAG is a valid symbolic tag name."
553 ;; According to the SVN manual, a valid symbolic tag must start with
554 ;; an uppercase or lowercase letter and can contain uppercase and
555 ;; lowercase letters, digits, `-', and `_'.
556 (and (string-match "^[a-zA-Z]" tag)
557 (not (string-match "[^a-z0-9A-Z-_]" tag))))
558
559(defun vc-svn-valid-version-number-p (tag)
560 "Return non-nil if TAG is a valid version number."
561 (and (string-match "^[0-9]" tag)
562 (not (string-match "[^0-9]" tag))))
563
17a5a301
SM
564;; Support for `svn annotate'
565
566(defun vc-svn-annotate-command (file buf &optional rev)
567 (vc-svn-command buf 0 file "annotate" (if rev (concat "-r" rev))))
568
569(defun vc-svn-annotate-time-of-rev (rev)
570 ;; Arbitrarily assume 10 commmits per day.
571 (/ (string-to-number rev) 10.0))
572
573(defun vc-svn-annotate-current-time ()
574 (vc-svn-annotate-time-of-rev vc-annotate-parent-rev))
575
576(defconst vc-svn-annotate-re "[ \t]*\\([0-9]+\\)[ \t]+[^\t ]+ ")
577
578(defun vc-svn-annotate-time ()
579 (when (looking-at vc-svn-annotate-re)
580 (goto-char (match-end 0))
581 (vc-svn-annotate-time-of-rev (match-string 1))))
582
583(defun vc-svn-annotate-extract-revision-at-line ()
584 (save-excursion
585 (beginning-of-line)
586 (if (looking-at vc-svn-annotate-re) (match-string 1))))
587
1fd3454a
SM
588(provide 'vc-svn)
589
f9d1f3be 590;; arch-tag: 02f10c68-2b4d-453a-90fc-1eee6cfb268d
1fd3454a 591;;; vc-svn.el ends here