(mh-send-letter): Call split-string on mh-send-args when sending
[bpt/emacs.git] / lisp / vc-svn.el
1 ;;; vc-svn.el --- non-resident support for Subversion version-control
2
3 ;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
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 3, 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
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 ;;; Commentary:
26
27 ;; Sync'd with Subversion's vc-svn.el as of revision 5801. but this version
28 ;; has been extensively modified since to handle filesets.
29
30 ;;; Code:
31
32 (eval-when-compile
33 (require 'vc))
34
35 ;;;
36 ;;; Customization options
37 ;;;
38
39 (defcustom vc-svn-global-switches nil
40 "*Global switches to pass to any SVN command."
41 :type '(choice (const :tag "None" nil)
42 (string :tag "Argument String")
43 (repeat :tag "Argument List"
44 :value ("")
45 string))
46 :version "22.1"
47 :group 'vc)
48
49 (defcustom vc-svn-register-switches nil
50 "*Extra switches for registering a file into SVN.
51 A string or list of strings passed to the checkin program by
52 \\[vc-register]."
53 :type '(choice (const :tag "None" nil)
54 (string :tag "Argument String")
55 (repeat :tag "Argument List"
56 :value ("")
57 string))
58 :version "22.1"
59 :group 'vc)
60
61 (defcustom vc-svn-diff-switches
62 t ;`svn' doesn't support common args like -c or -b.
63 "String or list of strings specifying extra switches for svn diff under VC.
64 If nil, use the value of `vc-diff-switches'.
65 If you want to force an empty list of arguments, use t."
66 :type '(choice (const :tag "Unspecified" nil)
67 (const :tag "None" t)
68 (string :tag "Argument String")
69 (repeat :tag "Argument List"
70 :value ("")
71 string))
72 :version "22.1"
73 :group 'vc)
74
75 (defcustom vc-svn-header (or (cdr (assoc 'SVN vc-header-alist)) '("\$Id\$"))
76 "*Header keywords to be inserted by `vc-insert-headers'."
77 :version "22.1"
78 :type '(repeat string)
79 :group 'vc)
80
81 ;; We want to autoload it for use by the autoloaded version of
82 ;; vc-svn-registered, but we want the value to be compiled at startup, not
83 ;; at dump time.
84 ;; ;;;###autoload
85 (defconst vc-svn-admin-directory
86 (cond ((and (memq system-type '(cygwin windows-nt ms-dos))
87 (getenv "SVN_ASP_DOT_NET_HACK"))
88 "_svn")
89 (t ".svn"))
90 "The name of the \".svn\" subdirectory or its equivalent.")
91
92 ;;; Properties of the backend
93
94 (defun vc-svn-revision-granularity ()
95 'repository)
96 ;;;
97 ;;; State-querying functions
98 ;;;
99
100 ;;; vc-svn-admin-directory is generally not defined when the
101 ;;; autoloaded function is called.
102
103 ;;;###autoload (defun vc-svn-registered (f)
104 ;;;###autoload (let ((admin-dir (cond ((and (eq system-type 'windows-nt)
105 ;;;###autoload (getenv "SVN_ASP_DOT_NET_HACK"))
106 ;;;###autoload "_svn")
107 ;;;###autoload (t ".svn"))))
108 ;;;###autoload (when (file-readable-p (expand-file-name
109 ;;;###autoload (concat admin-dir "/entries")
110 ;;;###autoload (file-name-directory f)))
111 ;;;###autoload (load "vc-svn")
112 ;;;###autoload (vc-svn-registered f))))
113
114 ;;;###autoload
115 (add-to-list 'completion-ignored-extensions ".svn/")
116
117 (defun vc-svn-registered (file)
118 "Check if FILE is SVN registered."
119 (when (file-readable-p (expand-file-name (concat vc-svn-admin-directory
120 "/entries")
121 (file-name-directory file)))
122 (with-temp-buffer
123 (cd (file-name-directory file))
124 (let ((status
125 (condition-case nil
126 ;; Ignore all errors.
127 (vc-svn-command t t file "status" "-v")
128 ;; Some problem happened. E.g. We can't find an `svn'
129 ;; executable. We used to only catch `file-error' but when
130 ;; the process is run on a remote host via Tramp, the error
131 ;; is only reported via the exit status which is turned into
132 ;; an `error' by vc-do-command.
133 (error nil))))
134 (when (eq 0 status)
135 (let ((parsed (vc-svn-parse-status file)))
136 (and parsed (not (memq parsed '(ignored unregistered))))))))))
137
138 (defun vc-svn-state (file &optional localp)
139 "SVN-specific version of `vc-state'."
140 (setq localp (or localp (vc-stay-local-p file)))
141 (with-temp-buffer
142 (cd (file-name-directory file))
143 (vc-svn-command t 0 file "status" (if localp "-v" "-u"))
144 (vc-svn-parse-status file)))
145
146 (defun vc-svn-state-heuristic (file)
147 "SVN-specific state heuristic."
148 (vc-svn-state file 'local))
149
150 (defun vc-svn-dir-state (dir &optional localp)
151 "Find the SVN state of all files in DIR and its subdirectories."
152 (setq localp (or localp (vc-stay-local-p dir)))
153 (let ((default-directory dir))
154 ;; Don't specify DIR in this command, the default-directory is
155 ;; enough. Otherwise it might fail with remote repositories.
156 (with-temp-buffer
157 (buffer-disable-undo) ;; Because these buffers can get huge
158 (vc-svn-command t 0 nil "status" (if localp "-v" "-u"))
159 (vc-svn-parse-status))))
160
161 (defun vc-svn-after-dir-status (callback buffer)
162 (let ((state-map '((?A . added)
163 (?C . edited)
164 (?D . removed)
165 (?I . ignored)
166 (?M . edited)
167 (?R . removed)
168 (?? . unregistered)
169 ;; This is what vc-svn-parse-status does.
170 (?~ . edited)))
171 result)
172 (goto-char (point-min))
173 (while (re-search-forward "^\\(.\\)..... \\(.*\\)$" nil t)
174 (let ((state (cdr (assq (aref (match-string 1) 0) state-map)))
175 (filename (match-string 2)))
176 (when state
177 (setq result (cons (cons filename state) result)))))
178 (funcall callback result buffer)))
179
180 (defun vc-svn-dir-status (dir callback buffer)
181 "Run 'svn status' for DIR and update BUFFER via CALLBACK.
182 CALLBACK is called as (CALLBACK RESULT BUFFER), where
183 RESULT is a list of conses (FILE . STATE) for directory DIR."
184 (with-current-buffer (get-buffer-create
185 (generate-new-buffer-name " *vc svn status*"))
186 (vc-svn-command (current-buffer) 'async nil "status")
187 (vc-exec-after
188 `(vc-svn-after-dir-status (quote ,callback) ,buffer))
189 (current-buffer)))
190
191 (defun vc-svn-working-revision (file)
192 "SVN-specific version of `vc-working-revision'."
193 ;; There is no need to consult RCS headers under SVN, because we
194 ;; get the workfile version for free when we recognize that a file
195 ;; is registered in SVN.
196 (vc-svn-registered file)
197 (vc-file-getprop file 'vc-working-revision))
198
199 (defun vc-svn-checkout-model (file)
200 "SVN-specific version of `vc-checkout-model'."
201 ;; It looks like Subversion has no equivalent of CVSREAD.
202 'implicit)
203
204 ;; vc-svn-mode-line-string doesn't exist because the default implementation
205 ;; works just fine.
206
207 (defun vc-svn-dired-state-info (file)
208 "SVN-specific version of `vc-dired-state-info'."
209 (let ((svn-state (vc-state file)))
210 (cond ((eq svn-state 'edited)
211 (if (equal (vc-working-revision file) "0")
212 "(added)" "(modified)"))
213 (t
214 ;; fall back to the default VC representation
215 (vc-default-dired-state-info 'SVN file)))))
216
217
218 (defun vc-svn-previous-revision (file rev)
219 (let ((newrev (1- (string-to-number rev))))
220 (when (< 0 newrev)
221 (number-to-string newrev))))
222
223 (defun vc-svn-next-revision (file rev)
224 (let ((newrev (1+ (string-to-number rev))))
225 ;; The "working revision" is an uneasy conceptual fit under Subversion;
226 ;; we use it as the upper bound until a better idea comes along. If the
227 ;; workfile version W coincides with the tree's latest revision R, then
228 ;; this check prevents a "no such revision: R+1" error. Otherwise, it
229 ;; inhibits showing of W+1 through R, which could be considered anywhere
230 ;; from gracious to impolite.
231 (unless (< (string-to-number (vc-file-getprop file 'vc-working-revision))
232 newrev)
233 (number-to-string newrev))))
234
235
236 ;;;
237 ;;; State-changing functions
238 ;;;
239
240 (defun vc-svn-create-repo ()
241 "Create a new SVN repository."
242 (vc-do-command nil 0 "svnadmin" '("create" "SVN"))
243 (vc-do-command nil 0 "svn" '(".")
244 "checkout" (concat "file://" default-directory "SVN")))
245
246 (defun vc-svn-register (files &optional rev comment)
247 "Register FILES into the SVN version-control system.
248 The COMMENT argument is ignored This does an add but not a commit.
249
250 `vc-register-switches' and `vc-svn-register-switches' are passed to
251 the SVN command (in that order)."
252 (apply 'vc-svn-command nil 0 files "add" (vc-switches 'SVN 'register)))
253
254 (defun vc-svn-responsible-p (file)
255 "Return non-nil if SVN thinks it is responsible for FILE."
256 (file-directory-p (expand-file-name vc-svn-admin-directory
257 (if (file-directory-p file)
258 file
259 (file-name-directory file)))))
260
261 (defalias 'vc-svn-could-register 'vc-svn-responsible-p
262 "Return non-nil if FILE could be registered in SVN.
263 This is only possible if SVN is responsible for FILE's directory.")
264
265 (defun vc-svn-checkin (files rev comment)
266 "SVN-specific version of `vc-backend-checkin'."
267 (if rev (error "Committing to a specific revision is unsupported in SVN"))
268 (let ((status (apply
269 'vc-svn-command nil 1 files "ci"
270 (nconc (list "-m" comment) (vc-switches 'SVN 'checkin)))))
271 (set-buffer "*vc*")
272 (goto-char (point-min))
273 (unless (equal status 0)
274 ;; Check checkin problem.
275 (cond
276 ((search-forward "Transaction is out of date" nil t)
277 (mapc (lambda (file) (vc-file-setprop file 'vc-state 'needs-merge))
278 files)
279 (error (substitute-command-keys
280 (concat "Up-to-date check failed: "
281 "type \\[vc-next-action] to merge in changes"))))
282 (t
283 (pop-to-buffer (current-buffer))
284 (goto-char (point-min))
285 (shrink-window-if-larger-than-buffer)
286 (error "Check-in failed"))))
287 ;; Update file properties
288 ;; (vc-file-setprop
289 ;; file 'vc-working-revision
290 ;; (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
291 ))
292
293 (defun vc-svn-find-revision (file rev buffer)
294 "SVN-specific retrieval of a specified version into a buffer."
295 (apply 'vc-svn-command
296 buffer 0 file
297 "cat"
298 (and rev (not (string= rev ""))
299 (concat "-r" rev))
300 (vc-switches 'SVN 'checkout)))
301
302 (defun vc-svn-checkout (file &optional editable rev)
303 (message "Checking out %s..." file)
304 (with-current-buffer (or (get-file-buffer file) (current-buffer))
305 (vc-call update file editable rev (vc-switches 'SVN 'checkout)))
306 (vc-mode-line file)
307 (message "Checking out %s...done" file))
308
309 (defun vc-svn-update (file editable rev switches)
310 (if (and (file-exists-p file) (not rev))
311 ;; If no revision was specified, there's nothing to do.
312 nil
313 ;; Check out a particular version (or recreate the file).
314 (vc-file-setprop file 'vc-working-revision nil)
315 (apply 'vc-svn-command nil 0 file
316 "update"
317 ;; default for verbose checkout: clear the sticky tag so
318 ;; that the actual update will get the head of the trunk
319 (cond
320 ((null rev) "-rBASE")
321 ((or (eq rev t) (equal rev "")) nil)
322 (t (concat "-r" rev)))
323 switches)))
324
325 (defun vc-svn-delete-file (file)
326 (vc-svn-command nil 0 file "remove"))
327
328 (defun vc-svn-rename-file (old new)
329 (vc-svn-command nil 0 new "move" (file-relative-name old)))
330
331 (defun vc-svn-revert (file &optional contents-done)
332 "Revert FILE to the version it was based on."
333 (unless contents-done
334 (vc-svn-command nil 0 file "revert")))
335
336 (defun vc-svn-merge (file first-version &optional second-version)
337 "Merge changes into current working copy of FILE.
338 The changes are between FIRST-VERSION and SECOND-VERSION."
339 (vc-svn-command nil 0 file
340 "merge"
341 "-r" (if second-version
342 (concat first-version ":" second-version)
343 first-version))
344 (vc-file-setprop file 'vc-state 'edited)
345 (with-current-buffer (get-buffer "*vc*")
346 (goto-char (point-min))
347 (if (looking-at "C ")
348 1 ; signal conflict
349 0))) ; signal success
350
351 (defun vc-svn-merge-news (file)
352 "Merge in any new changes made to FILE."
353 (message "Merging changes into %s..." file)
354 ;; (vc-file-setprop file 'vc-working-revision nil)
355 (vc-file-setprop file 'vc-checkout-time 0)
356 (vc-svn-command nil 0 file "update")
357 ;; Analyze the merge result reported by SVN, and set
358 ;; file properties accordingly.
359 (with-current-buffer (get-buffer "*vc*")
360 (goto-char (point-min))
361 ;; get new working revision
362 (if (re-search-forward
363 "^\\(Updated to\\|At\\) revision \\([0-9]+\\)" nil t)
364 (vc-file-setprop file 'vc-working-revision (match-string 2))
365 (vc-file-setprop file 'vc-working-revision nil))
366 ;; get file status
367 (goto-char (point-min))
368 (prog1
369 (if (looking-at "At revision")
370 0 ;; there were no news; indicate success
371 (if (re-search-forward
372 ;; Newer SVN clients have 3 columns of chars (one for the
373 ;; file's contents, then second for its properties, and the
374 ;; third for lock-grabbing info), before the 2 spaces.
375 ;; We also used to match the filename in column 0 without any
376 ;; meta-info before it, but I believe this can never happen.
377 (concat "^\\(\\([ACGDU]\\)\\(.[B ]\\)? \\)"
378 (regexp-quote (file-name-nondirectory file)))
379 nil t)
380 (cond
381 ;; Merge successful, we are in sync with repository now
382 ((string= (match-string 2) "U")
383 (vc-file-setprop file 'vc-state 'up-to-date)
384 (vc-file-setprop file 'vc-checkout-time
385 (nth 5 (file-attributes file)))
386 0);; indicate success to the caller
387 ;; Merge successful, but our own changes are still in the file
388 ((string= (match-string 2) "G")
389 (vc-file-setprop file 'vc-state 'edited)
390 0);; indicate success to the caller
391 ;; Conflicts detected!
392 (t
393 (vc-file-setprop file 'vc-state 'edited)
394 1);; signal the error to the caller
395 )
396 (pop-to-buffer "*vc*")
397 (error "Couldn't analyze svn update result")))
398 (message "Merging changes into %s...done" file))))
399
400 (defun vc-svn-modify-change-comment (files rev comment)
401 "Modify the change comments for a specified REV.
402 You must have ssh access to the repository host, and the directory Emacs
403 uses locally for temp files must also be writeable by you on that host."
404 (vc-do-command nil 0 "svn" nil "info")
405 (set-buffer "*vc*")
406 (goto-char (point-min))
407 (unless (re-search-forward "Repository Root: svn\\+ssh://\\([^/]+\\)\\(/.*\\)" nil t)
408 (error "Repository information is unavailable."))
409 (let* ((tempfile (make-temp-file user-mail-address))
410 (host (match-string 1))
411 (directory (match-string 2))
412 (remotefile (concat host ":" tempfile)))
413 (with-temp-buffer
414 (insert comment)
415 (write-region (point-min) (point-max) tempfile))
416 (unless (vc-do-command nil 0 "scp" nil "-q" tempfile remotefile)
417 (error "Copy of comment to %s failed" remotefile))
418 (unless (vc-do-command nil 0 "ssh" nil
419 "-q" host
420 (format "svnadmin setlog --bypass-hooks %s -r %s %s; rm %s"
421 directory rev tempfile tempfile))
422 (error "Log edit failed"))
423 ))
424
425 ;;;
426 ;;; History functions
427 ;;;
428
429 (defun vc-svn-print-log (files &optional buffer)
430 "Get change log(s) associated with FILES."
431 (save-current-buffer
432 (vc-setup-buffer buffer)
433 (let ((inhibit-read-only t))
434 (goto-char (point-min))
435 (if files
436 (dolist (file files)
437 (insert "Working file: " file "\n")
438 (vc-svn-command
439 buffer
440 'async
441 ;; (if (and (= (length files) 1) (vc-stay-local-p file)) 'async 0)
442 (list file)
443 "log"
444 ;; By default Subversion only shows the log up to the
445 ;; working revision, whereas we also want the log of the
446 ;; subsequent commits. At least that's what the
447 ;; vc-cvs.el code does.
448 "-rHEAD:0"))
449 ;; Dump log for the entire directory.
450 (vc-svn-command buffer 0 nil "log" "-rHEAD:0")))))
451
452 (defun vc-svn-wash-log ()
453 "Remove all non-comment information from log output."
454 ;; FIXME: not implemented for SVN
455 nil)
456
457 (defun vc-svn-diff (files &optional oldvers newvers buffer)
458 "Get a difference report using SVN between two revisions of fileset FILES."
459 (and oldvers
460 (catch 'no
461 (dolist (f files)
462 (or (equal oldvers (vc-working-revision f))
463 (throw 'no nil)))
464 t)
465 ;; Use nil rather than the current revision because svn handles
466 ;; it better (i.e. locally). Note that if _any_ of the files
467 ;; has a different revision, we fetch the lot, which is
468 ;; obviously sub-optimal.
469 (setq oldvers nil))
470 (let* ((switches
471 (if vc-svn-diff-switches
472 (vc-switches 'SVN 'diff)
473 (list "-x" (mapconcat 'identity (vc-switches nil 'diff) " "))))
474 (async (and (not vc-disable-async-diff)
475 (vc-stay-local-p files)
476 (or oldvers newvers)))) ; Svn diffs those locally.
477 (apply 'vc-svn-command buffer
478 (if async 'async 0)
479 files "diff"
480 (append
481 switches
482 (when oldvers
483 (list "-r" (if newvers (concat oldvers ":" newvers)
484 oldvers)))))
485 (if async 1 ; async diff => pessimistic assumption
486 ;; For some reason `svn diff' does not return a useful
487 ;; status w.r.t whether the diff was empty or not.
488 (buffer-size (get-buffer buffer)))))
489
490 ;;;
491 ;;; Snapshot system
492 ;;;
493
494 (defun vc-svn-create-snapshot (dir name branchp)
495 "Assign to DIR's current revision a given NAME.
496 If BRANCHP is non-nil, the name is created as a branch (and the current
497 workspace is immediately moved to that new branch).
498 NAME is assumed to be a URL."
499 (vc-svn-command nil 0 dir "copy" name)
500 (when branchp (vc-svn-retrieve-snapshot dir name nil)))
501
502 (defun vc-svn-retrieve-snapshot (dir name update)
503 "Retrieve a snapshot at and below DIR.
504 NAME is the name of the snapshot; if it is empty, do a `svn update'.
505 If UPDATE is non-nil, then update (resynch) any affected buffers.
506 NAME is assumed to be a URL."
507 (vc-svn-command nil 0 dir "switch" name)
508 ;; FIXME: parse the output and obey `update'.
509 )
510
511 ;;;
512 ;;; Miscellaneous
513 ;;;
514
515 ;; Subversion makes backups for us, so don't bother.
516 ;; (defalias 'vc-svn-make-version-backups-p 'vc-stay-local-p
517 ;; "Return non-nil if version backups should be made for FILE.")
518
519 (defun vc-svn-check-headers ()
520 "Check if the current file has any headers in it."
521 (save-excursion
522 (goto-char (point-min))
523 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
524 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
525
526
527 ;;;
528 ;;; Internal functions
529 ;;;
530
531 (defcustom vc-svn-program "svn"
532 "Name of the SVN executable."
533 :type 'string
534 :group 'vc)
535
536 (defun vc-svn-root (dir)
537 (vc-find-root dir vc-svn-admin-directory t))
538
539 (defun vc-svn-command (buffer okstatus file-or-list &rest flags)
540 "A wrapper around `vc-do-command' for use in vc-svn.el.
541 The difference to vc-do-command is that this function always invokes `svn',
542 and that it passes `vc-svn-global-switches' to it before FLAGS."
543 (apply 'vc-do-command buffer okstatus vc-svn-program file-or-list
544 (if (stringp vc-svn-global-switches)
545 (cons vc-svn-global-switches flags)
546 (append vc-svn-global-switches
547 flags))))
548
549 (defun vc-svn-repository-hostname (dirname)
550 (with-temp-buffer
551 (let ((coding-system-for-read
552 (or file-name-coding-system
553 default-file-name-coding-system)))
554 (vc-insert-file (expand-file-name (concat vc-svn-admin-directory
555 "/entries")
556 dirname)))
557 (goto-char (point-min))
558 (when (re-search-forward
559 ;; Old `svn' used name="svn:this_dir", newer use just name="".
560 (concat "name=\"\\(?:svn:this_dir\\)?\"[\n\t ]*"
561 "\\(?:[-a-z]+=\"[^\"]*\"[\n\t ]*\\)*?"
562 "url=\"\\(?1:[^\"]+\\)\""
563 ;; Yet newer ones don't use XML any more.
564 "\\|^\ndir\n[0-9]+\n\\(?1:.*\\)") nil t)
565 ;; This is not a hostname but a URL. This may actually be considered
566 ;; as a feature since it allows vc-svn-stay-local to specify different
567 ;; behavior for different modules on the same server.
568 (match-string 1))))
569
570 (defun vc-svn-resolve-when-done ()
571 "Call \"svn resolved\" if the conflict markers have been removed."
572 (save-excursion
573 (goto-char (point-min))
574 (unless (re-search-forward "^<<<<<<< " nil t)
575 (vc-svn-command nil 0 buffer-file-name "resolved")
576 ;; Remove the hook so that it is not called multiple times.
577 (remove-hook 'after-save-hook 'vc-svn-resolve-when-done t))))
578
579 ;; Inspired by vc-arch-find-file-hook.
580 (defun vc-svn-find-file-hook ()
581 (when (eq ?C (vc-file-getprop buffer-file-name 'vc-svn-status))
582 ;; If the file is marked as "conflicted", then we should try and call
583 ;; "svn resolved" when applicable.
584 (if (save-excursion
585 (goto-char (point-min))
586 (re-search-forward "^<<<<<<< " nil t))
587 ;; There are conflict markers.
588 (progn
589 (smerge-start-session)
590 (add-hook 'after-save-hook 'vc-svn-resolve-when-done nil t))
591 ;; There are no conflict markers. This is problematic: maybe it means
592 ;; the conflict has been resolved and we should immediately call "svn
593 ;; resolved", or it means that the file's type does not allow Svn to
594 ;; use conflict markers in which case we don't really know what to do.
595 ;; So let's just punt for now.
596 nil)
597 (message "There are unresolved conflicts in this file")))
598
599 (defun vc-svn-parse-status (&optional filename)
600 "Parse output of \"svn status\" command in the current buffer.
601 Set file properties accordingly. Unless FILENAME is non-nil, parse only
602 information about FILENAME and return its status."
603 (let (file status)
604 (goto-char (point-min))
605 (while (re-search-forward
606 ;; Ignore the files with status X.
607 "^\\(\\?\\|[ ACDGIMR!~][ MC][ L][ +][ S]..\\([ *]\\) +\\([-0-9]+\\) +\\([0-9?]+\\) +\\([^ ]+\\)\\) +" nil t)
608 ;; If the username contains spaces, the output format is ambiguous,
609 ;; so don't trust the output's filename unless we have to.
610 (setq file (or filename
611 (expand-file-name
612 (buffer-substring (point) (line-end-position)))))
613 (setq status (char-after (line-beginning-position)))
614 (if (eq status ??)
615 (vc-file-setprop file 'vc-state 'unregistered)
616 ;; `vc-BACKEND-registered' must not set vc-backend,
617 ;; which is instead set in vc-registered.
618 (unless filename (vc-file-setprop file 'vc-backend 'SVN))
619 ;; Use the last-modified revision, so that searching in vc-print-log
620 ;; output works.
621 (vc-file-setprop file 'vc-working-revision (match-string 3))
622 ;; Remember Svn's own status.
623 (vc-file-setprop file 'vc-svn-status status)
624 (vc-file-setprop
625 file 'vc-state
626 (cond
627 ((eq status ?\ )
628 (if (eq (char-after (match-beginning 1)) ?*)
629 'needs-patch
630 (vc-file-setprop file 'vc-checkout-time
631 (nth 5 (file-attributes file)))
632 'up-to-date))
633 ((eq status ?A)
634 ;; If the file was actually copied, (match-string 2) is "-".
635 (vc-file-setprop file 'vc-working-revision "0")
636 (vc-file-setprop file 'vc-checkout-time 0)
637 'added)
638 ((memq status '(?M ?C))
639 (if (eq (char-after (match-beginning 1)) ?*)
640 'needs-merge
641 'edited))
642 ((eq status ?I)
643 (vc-file-setprop file 'vc-state 'ignored))
644 ((eq status ?R)
645 (vc-file-setprop file 'vc-state 'removed))
646 (t 'edited)))))
647 (if filename (vc-file-getprop filename 'vc-state))))
648
649 (defun vc-svn-dir-state-heuristic (dir)
650 "Find the SVN state of all files in DIR, using only local information."
651 (vc-svn-dir-state dir 'local))
652
653 (defun vc-svn-valid-symbolic-tag-name-p (tag)
654 "Return non-nil if TAG is a valid symbolic tag name."
655 ;; According to the SVN manual, a valid symbolic tag must start with
656 ;; an uppercase or lowercase letter and can contain uppercase and
657 ;; lowercase letters, digits, `-', and `_'.
658 (and (string-match "^[a-zA-Z]" tag)
659 (not (string-match "[^a-z0-9A-Z-_]" tag))))
660
661 (defun vc-svn-valid-revision-number-p (tag)
662 "Return non-nil if TAG is a valid revision number."
663 (and (string-match "^[0-9]" tag)
664 (not (string-match "[^0-9]" tag))))
665
666 ;; Support for `svn annotate'
667
668 (defun vc-svn-annotate-command (file buf &optional rev)
669 (vc-svn-command buf 0 file "annotate" (if rev (concat "-r" rev))))
670
671 (defun vc-svn-annotate-time-of-rev (rev)
672 ;; Arbitrarily assume 10 commmits per day.
673 (/ (string-to-number rev) 10.0))
674
675 (defun vc-svn-annotate-current-time ()
676 (vc-svn-annotate-time-of-rev vc-annotate-parent-rev))
677
678 (defconst vc-svn-annotate-re "[ \t]*\\([0-9]+\\)[ \t]+[^\t ]+ ")
679
680 (defun vc-svn-annotate-time ()
681 (when (looking-at vc-svn-annotate-re)
682 (goto-char (match-end 0))
683 (vc-svn-annotate-time-of-rev (match-string 1))))
684
685 (defun vc-svn-annotate-extract-revision-at-line ()
686 (save-excursion
687 (beginning-of-line)
688 (if (looking-at vc-svn-annotate-re) (match-string 1))))
689
690 (provide 'vc-svn)
691
692 ;; arch-tag: 02f10c68-2b4d-453a-90fc-1eee6cfb268d
693 ;;; vc-svn.el ends here