1 ;;; vc-svn.el --- non-resident support for Subversion version-control -*- lexical-binding:t -*-
3 ;; Copyright (C) 2003-2015 Free Software Foundation, Inc.
5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: Stefan Monnier <monnier@gnu.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; Sync'd with Subversion's vc-svn.el as of revision 5801. but this version
27 ;; has been extensively modified since to handle filesets.
34 ;; Clear up the cache to force vc-call to check again and discover
35 ;; new functions when we reload this file.
36 (put 'SVN
'vc-functions nil
)
39 ;;; Customization options
43 "VC Subversion (svn) backend."
47 ;; FIXME there is also svnadmin.
48 (defcustom vc-svn-program
"svn"
49 "Name of the SVN executable."
53 ;; Might be nice if svn defaulted to non-interactive if stdin not tty.
54 ;; http://svn.haxx.se/dev/archive-2008-05/0762.shtml
55 ;; http://svn.haxx.se/dev/archive-2009-04/0094.shtml
56 ;; Maybe newer ones do?
57 (defcustom vc-svn-global-switches
(unless (eq system-type
'darwin
) ; bug#13513
58 '("--non-interactive"))
59 "Global switches to pass to any SVN command.
60 The option \"--non-interactive\" is often needed to prevent SVN
61 hanging while prompting for authorization."
62 :type
'(choice (const :tag
"None" nil
)
63 (string :tag
"Argument String")
64 (repeat :tag
"Argument List"
70 (defcustom vc-svn-register-switches nil
71 "Switches for registering a file into SVN.
72 A string or list of strings passed to the checkin program by
73 \\[vc-register]. If nil, use the value of `vc-register-switches'.
74 If t, use no switches."
75 :type
'(choice (const :tag
"Unspecified" nil
)
77 (string :tag
"Argument String")
78 (repeat :tag
"Argument List" :value
("") string
))
82 (defcustom vc-svn-diff-switches
83 t
;`svn' doesn't support common args like -c or -b.
84 "String or list of strings specifying extra switches for svn diff under VC.
85 If nil, use the value of `vc-diff-switches' (or `diff-switches'),
86 together with \"-x --diff-cmd=\"`diff-command' (since `svn diff'
87 does not support the default \"-c\" value of `diff-switches').
88 If you want to force an empty list of arguments, use t."
89 :type
'(choice (const :tag
"Unspecified" nil
)
91 (string :tag
"Argument String")
92 (repeat :tag
"Argument List"
98 (defcustom vc-svn-annotate-switches nil
99 "String or list of strings specifying switches for svn annotate under VC.
100 If nil, use the value of `vc-annotate-switches'. If t, use no
102 :type
'(choice (const :tag
"Unspecified" nil
)
103 (const :tag
"None" t
)
104 (string :tag
"Argument String")
105 (repeat :tag
"Argument List" :value
("") string
))
109 (defcustom vc-svn-header
'("$Id\ $")
110 "Header keywords to be inserted by `vc-insert-headers'."
111 :version
"24.1" ; no longer consult the obsolete vc-header-alist
112 :type
'(repeat string
)
115 ;; We want to autoload it for use by the autoloaded version of
116 ;; vc-svn-registered, but we want the value to be compiled at startup, not
119 (defconst vc-svn-admin-directory
120 (cond ((and (memq system-type
'(cygwin windows-nt ms-dos
))
121 (getenv "SVN_ASP_DOT_NET_HACK"))
124 "The name of the \".svn\" subdirectory or its equivalent.")
126 ;;; Properties of the backend
128 (defun vc-svn-revision-granularity () 'repository
)
129 (defun vc-svn-checkout-model (_files) 'implicit
)
132 ;;; State-querying functions
135 ;;; vc-svn-admin-directory is generally not defined when the
136 ;;; autoloaded function is called.
138 ;;;###autoload (defun vc-svn-registered (f)
139 ;;;###autoload (let ((admin-dir (cond ((and (eq system-type 'windows-nt)
140 ;;;###autoload (getenv "SVN_ASP_DOT_NET_HACK"))
141 ;;;###autoload "_svn")
142 ;;;###autoload (t ".svn"))))
143 ;;;###autoload (when (vc-find-root f admin-dir)
144 ;;;###autoload (load "vc-svn" nil t)
145 ;;;###autoload (vc-svn-registered f))))
147 (defun vc-svn-registered (file)
148 "Check if FILE is SVN registered."
149 (setq file
(expand-file-name file
))
150 (when (vc-svn-root file
)
152 (cd (file-name-directory file
))
153 (let* (process-file-side-effects
156 ;; Ignore all errors.
157 (vc-svn-command t t file
"status" "-v")
158 ;; Some problem happened. E.g. We can't find an `svn'
159 ;; executable. We used to only catch `file-error' but when
160 ;; the process is run on a remote host via Tramp, the error
161 ;; is only reported via the exit status which is turned into
162 ;; an `error' by vc-do-command.
165 (let ((parsed (vc-svn-parse-status file
)))
166 (and parsed
(not (memq parsed
'(ignored unregistered
))))))))))
168 (defun vc-svn-state (file)
169 "SVN-specific version of `vc-state'."
170 (let (process-file-side-effects)
172 (cd (file-name-directory file
))
173 (vc-svn-command t
0 file
"status" "-v")
174 (vc-svn-parse-status file
))))
176 ;; FIXME it would be better not to have the "remote" argument,
177 ;; but to distinguish the two output formats based on content.
178 ;; FIXME: the local format isn't used by the (sole) caller anymore.
179 (defun vc-svn-after-dir-status (callback &optional remote
)
180 (let ((state-map '((?A . added
)
187 ;; This is what vc-svn-parse-status does.
189 (re (if remote
"^\\(.\\)\\(.\\).....? \\([ *]\\) +\\(?:[-0-9]+\\)? \\(.*\\)$"
190 ;; Subexp 3 is a dummy in this case, so the numbers match.
191 "^\\(.\\)\\(.\\)...\\(.\\).? \\(.*\\)$"))
193 (goto-char (point-min))
194 (while (re-search-forward re nil t
)
195 (let ((state (cdr (assq (aref (match-string 1) 0) state-map
)))
196 (propstat (cdr (assq (aref (match-string 2) 0) state-map
)))
197 (filename (if (memq system-type
'(windows-nt ms-dos
))
198 (replace-regexp-in-string "\\\\" "/" (match-string 4))
200 (and (memq propstat
'(conflict edited
))
201 (not (eq state
'conflict
)) ; conflict always wins
202 (setq state propstat
))
203 (and remote
(string-equal (match-string 3) "*")
204 ;; FIXME are there other possible combinations?
205 (cond ((eq state
'edited
) (setq state
'needs-merge
))
206 ((not state
) (setq state
'needs-update
))))
207 (when (and state
(not (string= "." filename
)))
208 (setq result
(cons (list filename state
) result
)))))
209 (funcall callback result
)))
211 (autoload 'vc-expand-dirs
"vc")
213 (defun vc-svn-dir-status-files (_dir files callback
)
214 "Run 'svn status' for DIR and update BUFFER via CALLBACK.
215 CALLBACK is called as (CALLBACK RESULT BUFFER), where
216 RESULT is a list of conses (FILE . STATE) for directory DIR."
217 ;; FIXME shouldn't this rather default to all the files in dir?
218 (apply #'vc-svn-command
(current-buffer) 'async nil
"status" "-u" files
)
219 (vc-run-delayed (vc-svn-after-dir-status callback t
)))
221 (defun vc-svn-dir-extra-headers (_dir)
222 "Generate extra status headers for a Subversion working copy."
223 (let (process-file-side-effects)
224 (vc-svn-command "*vc*" 0 nil
"info"))
229 (goto-char (point-min))
230 (re-search-forward "Repository Root: *\\(.*\\)" nil t
))
235 (propertize "Repository : " 'face
'font-lock-type-face
)
236 (propertize repo
'face
'font-lock-variable-name-face
)))
239 (defun vc-svn-working-revision (file)
240 "SVN-specific version of `vc-working-revision'."
241 ;; There is no need to consult RCS headers under SVN, because we
242 ;; get the workfile version for free when we recognize that a file
243 ;; is registered in SVN.
244 (vc-svn-registered file
)
245 (vc-file-getprop file
'vc-working-revision
))
247 ;; vc-svn-mode-line-string doesn't exist because the default implementation
250 (defun vc-svn-previous-revision (_file rev
)
251 (let ((newrev (1- (string-to-number rev
))))
253 (number-to-string newrev
))))
255 (defun vc-svn-next-revision (file rev
)
256 (let ((newrev (1+ (string-to-number rev
))))
257 ;; The "working revision" is an uneasy conceptual fit under Subversion;
258 ;; we use it as the upper bound until a better idea comes along. If the
259 ;; workfile version W coincides with the tree's latest revision R, then
260 ;; this check prevents a "no such revision: R+1" error. Otherwise, it
261 ;; inhibits showing of W+1 through R, which could be considered anywhere
262 ;; from gracious to impolite.
263 (unless (< (string-to-number (vc-file-getprop file
'vc-working-revision
))
265 (number-to-string newrev
))))
269 ;;; State-changing functions
272 (defun vc-svn-create-repo ()
273 "Create a new SVN repository."
274 (vc-do-command "*vc*" 0 "svnadmin" '("create" "SVN"))
275 ;; Expand default-directory because svn gets confused by eg
276 ;; file://~/path/to/file. (Bug#15446).
277 (vc-svn-command "*vc*" 0 "." "checkout"
278 (let ((defdir (expand-file-name default-directory
))
279 (svn-prog (executable-find "svn")))
280 (when (and (fboundp 'w32-application-type
)
281 (eq (w32-application-type svn-prog
) 'msys
))
283 (replace-regexp-in-string "^\\(.\\):/" "/\\1/"
285 (concat (if (and (stringp defdir
)
286 (eq (aref defdir
0) ?
/))
288 ;; MS-Windows files d:/foo/bar need to
289 ;; begin with 3 leading slashes.
294 (autoload 'vc-switches
"vc")
296 (defun vc-svn-register (files &optional _comment
)
297 "Register FILES into the SVN version-control system.
298 The COMMENT argument is ignored This does an add but not a commit.
299 Passes either `vc-svn-register-switches' or `vc-register-switches'
301 (apply 'vc-svn-command nil
0 files
"add" (vc-switches 'SVN
'register
)))
303 (defun vc-svn-root (file)
304 (vc-find-root file vc-svn-admin-directory
))
306 (defalias 'vc-svn-responsible-p
'vc-svn-root
)
308 (defun vc-svn-checkin (files comment
&optional _extra-args-ignored
)
309 "SVN-specific version of `vc-backend-checkin'."
311 'vc-svn-command nil
1 files
"ci"
312 (nconc (list "-m" comment
) (vc-switches 'SVN
'checkin
)))))
314 (goto-char (point-min))
315 (unless (equal status
0)
316 ;; Check checkin problem.
318 ((search-forward "Transaction is out of date" nil t
)
319 (mapc (lambda (file) (vc-file-setprop file
'vc-state
'needs-merge
))
321 (error (substitute-command-keys
322 (concat "Up-to-date check failed: "
323 "type \\[vc-next-action] to merge in changes"))))
325 (pop-to-buffer (current-buffer))
326 (goto-char (point-min))
327 (shrink-window-if-larger-than-buffer)
328 (error "Check-in failed"))))
329 ;; Update file properties
331 ;; file 'vc-working-revision
332 ;; (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
335 (defun vc-svn-find-revision (file rev buffer
)
336 "SVN-specific retrieval of a specified version into a buffer."
337 (let (process-file-side-effects)
338 (apply 'vc-svn-command
341 (and rev
(not (string= rev
""))
343 (vc-switches 'SVN
'checkout
))))
345 (defun vc-svn-ignore (file &optional directory remove
)
346 "Ignore FILE under Subversion.
347 FILE is a file wildcard, relative to the root directory of DIRECTORY."
348 (let* ((ignores (vc-svn-ignore-completion-table directory
))
349 (file (file-relative-name file directory
))
351 (delete file ignores
)
352 (push file ignores
))))
353 (vc-svn-command nil
0 nil nil
"propset" "svn:ignore"
354 (mapconcat #'identity ignores
"\n")
355 (expand-file-name directory
))))
357 (defun vc-svn-ignore-completion-table (directory)
358 "Return the list of ignored files in DIRECTORY."
360 (vc-svn-command t t nil
"propget" "svn:ignore" (expand-file-name directory
))
361 (split-string (buffer-string))))
363 (defun vc-svn-find-admin-dir (file)
364 "Return the administrative directory of FILE."
365 (expand-file-name vc-svn-admin-directory
(vc-svn-root file
)))
367 (defun vc-svn-checkout (file &optional rev
)
368 (message "Checking out %s..." file
)
369 (with-current-buffer (or (get-file-buffer file
) (current-buffer))
370 (vc-svn-update file rev
(vc-switches 'SVN
'checkout
)))
371 (vc-mode-line file
'SVN
)
372 (message "Checking out %s...done" file
))
374 (defun vc-svn-update (file rev switches
)
375 (if (and (file-exists-p file
) (not rev
))
376 ;; If no revision was specified, there's nothing to do.
378 ;; Check out a particular version (or recreate the file).
379 (vc-file-setprop file
'vc-working-revision nil
)
380 (apply 'vc-svn-command nil
0 file
383 ((null rev
) "-rBASE")
384 ((or (eq rev t
) (equal rev
"")) nil
)
385 (t (concat "-r" rev
)))
388 (defun vc-svn-delete-file (file)
389 (vc-svn-command nil
0 file
"remove"))
391 (defun vc-svn-rename-file (old new
)
392 (vc-svn-command nil
0 new
"move" (file-relative-name old
)))
394 (defun vc-svn-revert (file &optional contents-done
)
395 "Revert FILE to the version it was based on."
396 (unless contents-done
397 (vc-svn-command nil
0 file
"revert")))
399 (defun vc-svn-merge-file (file)
400 "Accept a file merge request, prompting for revisions."
401 (let* ((first-revision
403 (concat "Merge " file
404 " from SVN revision "
405 "(default news on current branch): ")
411 ((string= first-revision
"")
412 (setq status
(vc-svn-merge-news file
)))
414 (setq second-revision
416 "Second SVN revision: "
419 (setq status
(vc-svn-merge file first-revision second-revision
))))
422 (defun vc-svn-merge (file first-version
&optional second-version
)
423 "Merge changes into current working copy of FILE.
424 The changes are between FIRST-VERSION and SECOND-VERSION."
425 (vc-svn-command nil
0 file
427 "-r" (if second-version
428 (concat first-version
":" second-version
)
430 (vc-file-setprop file
'vc-state
'edited
)
431 (with-current-buffer (get-buffer "*vc*")
432 (goto-char (point-min))
433 (if (looking-at "C ")
435 0))) ; signal success
437 (defun vc-svn-merge-news (file)
438 "Merge in any new changes made to FILE."
439 (message "Merging changes into %s..." file
)
440 ;; (vc-file-setprop file 'vc-working-revision nil)
441 (vc-file-setprop file
'vc-checkout-time
0)
442 (vc-svn-command nil
0 file
"update")
443 ;; Analyze the merge result reported by SVN, and set
444 ;; file properties accordingly.
445 (with-current-buffer (get-buffer "*vc*")
446 (goto-char (point-min))
447 ;; get new working revision
448 (if (re-search-forward
449 "^\\(Updated to\\|At\\) revision \\([0-9]+\\)" nil t
)
450 (vc-file-setprop file
'vc-working-revision
(match-string 2))
451 (vc-file-setprop file
'vc-working-revision nil
))
453 (goto-char (point-min))
455 (if (looking-at "At revision")
456 0 ;; there were no news; indicate success
457 (if (re-search-forward
458 ;; Newer SVN clients have 3 columns of chars (one for the
459 ;; file's contents, then second for its properties, and the
460 ;; third for lock-grabbing info), before the 2 spaces.
461 ;; We also used to match the filename in column 0 without any
462 ;; meta-info before it, but I believe this can never happen.
463 (concat "^\\(\\([ACGDU]\\)\\(.[B ]\\)? \\)"
464 (regexp-quote (file-relative-name file
)))
467 ;; Merge successful, we are in sync with repository now
468 ((string= (match-string 2) "U")
469 (vc-file-setprop file
'vc-state
'up-to-date
)
470 (vc-file-setprop file
'vc-checkout-time
471 (nth 5 (file-attributes file
)))
472 0);; indicate success to the caller
473 ;; Merge successful, but our own changes are still in the file
474 ((string= (match-string 2) "G")
475 (vc-file-setprop file
'vc-state
'edited
)
476 0);; indicate success to the caller
477 ;; Conflicts detected!
479 (vc-file-setprop file
'vc-state
'edited
)
480 1);; signal the error to the caller
482 (pop-to-buffer "*vc*")
483 (error "Couldn't analyze svn update result")))
484 (message "Merging changes into %s...done" file
))))
486 (defun vc-svn-modify-change-comment (_files rev comment
)
487 "Modify the change comments for a specified REV.
488 You must have ssh access to the repository host, and the directory Emacs
489 uses locally for temp files must also be writable by you on that host.
490 This is only supported if the repository access method is either file://
492 (let (tempfile host remotefile directory fileurl-p
)
494 (vc-svn-command (current-buffer) 0 nil
"info")
495 (goto-char (point-min))
496 (unless (re-search-forward "Repository Root: \\(file://\\(/.*\\)\\)\\|\\(svn\\+ssh://\\([^/]+\\)\\(/.*\\)\\)" nil t
)
497 (error "Repository information is unavailable"))
501 (setq directory
(match-string 2)))
502 (setq host
(match-string 4))
503 (setq directory
(match-string 5))
504 (setq remotefile
(concat host
":" tempfile
))))
505 (with-temp-file (setq tempfile
(make-temp-file user-mail-address
))
508 ;; Repository Root is a local file.
510 (unless (vc-do-command
511 "*vc*" 0 "svnadmin" nil
512 "setlog" "--bypass-hooks" directory
513 "-r" rev
(format "%s" tempfile
))
514 (error "Log edit failed"))
515 (delete-file tempfile
))
517 ;; Remote repository, using svn+ssh.
518 (unless (vc-do-command "*vc*" 0 "scp" nil
"-q" tempfile remotefile
)
519 (error "Copy of comment to %s failed" remotefile
))
520 (unless (vc-do-command
521 "*vc*" 0 "ssh" nil
"-q" host
522 (format "svnadmin setlog --bypass-hooks %s -r %s %s; rm %s"
523 directory rev tempfile tempfile
))
524 (error "Log edit failed")))))
527 ;;; History functions
530 (defvar log-view-per-file-logs
)
532 (define-derived-mode vc-svn-log-view-mode log-view-mode
"SVN-Log-View"
534 (set (make-local-variable 'log-view-per-file-logs
) nil
))
536 (autoload 'vc-setup-buffer
"vc-dispatcher")
538 (defun vc-svn-print-log (files buffer
&optional _shortlog start-revision limit
)
539 "Print commit log associated with FILES into specified BUFFER.
541 If START-REVISION is non-nil, it is the newest revision to show.
542 If LIMIT is non-nil, show no more than this many entries."
544 (vc-setup-buffer buffer
)
545 (let ((inhibit-read-only t
))
546 (goto-char (point-min))
549 (insert "Working file: " file
"\n")
559 (format "-r%s:1" start-revision
)
560 ;; By default Subversion only shows the log up to the
561 ;; working revision, whereas we also want the log of the
562 ;; subsequent commits. At least that's what the
563 ;; vc-cvs.el code does.
565 (when limit
(list "--limit" (format "%s" limit
))))))
566 ;; Dump log for the entire directory.
567 (apply 'vc-svn-command buffer
0 nil
"log"
570 (if start-revision
(format "-r%s" start-revision
) "-rHEAD:0"))
571 (when limit
(list "--limit" (format "%s" limit
)))))))))
573 (defun vc-svn-diff (files &optional oldvers newvers buffer async
)
574 "Get a difference report using SVN between two revisions of fileset FILES."
580 (or (equal oldvers
(vc-working-revision f
))
583 ;; Use nil rather than the current revision because svn handles
584 ;; it better (i.e. locally). Note that if _any_ of the files
585 ;; has a different revision, we fetch the lot, which is
586 ;; obviously sub-optimal.
588 (setq async
(and async
(or oldvers newvers
))) ; Svn diffs those locally.
590 (if vc-svn-diff-switches
591 (vc-switches 'SVN
'diff
)
592 (list (concat "--diff-cmd=" diff-command
) "-x"
593 (mapconcat 'identity
(vc-switches nil
'diff
) " ")))))
594 (apply 'vc-svn-command buffer
600 (list "-r" (if newvers
(concat oldvers
":" newvers
)
602 (if async
1 ; async diff => pessimistic assumption
603 ;; For some reason `svn diff' does not return a useful
604 ;; status w.r.t whether the diff was empty or not.
605 (buffer-size (get-buffer buffer
)))))
611 (defun vc-svn-create-tag (dir name branchp
)
612 "Assign to DIR's current revision a given NAME.
613 If BRANCHP is non-nil, the name is created as a branch (and the current
614 workspace is immediately moved to that new branch).
615 NAME is assumed to be a URL."
616 (vc-svn-command nil
0 dir
"copy" name
)
617 (when branchp
(vc-svn-retrieve-tag dir name nil
)))
619 (defun vc-svn-retrieve-tag (dir name _update
)
620 "Retrieve a tag at and below DIR.
621 NAME is the name of the tag; if it is empty, do a `svn update'.
622 If UPDATE is non-nil, then update (resynch) any affected buffers.
623 NAME is assumed to be a URL."
624 (vc-svn-command nil
0 dir
"switch" name
)
625 ;; FIXME: parse the output and obey `update'.
632 ;; Subversion makes backups for us, so don't bother.
633 ;; (defun vc-svn-make-version-backups-p (file)
634 ;; "Return non-nil if version backups should be made for FILE."
637 (defun vc-svn-check-headers ()
638 "Check if the current file has any headers in it."
640 (goto-char (point-min))
641 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
642 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
646 ;;; Internal functions
649 (defun vc-svn-command (buffer okstatus file-or-list
&rest flags
)
650 "A wrapper around `vc-do-command' for use in vc-svn.el.
651 The difference to vc-do-command is that this function always invokes `svn',
652 and that it passes `vc-svn-global-switches' to it before FLAGS."
653 (apply 'vc-do-command
(or buffer
"*vc*") okstatus vc-svn-program file-or-list
654 (if (stringp vc-svn-global-switches
)
655 (cons vc-svn-global-switches flags
)
656 (append vc-svn-global-switches flags
))))
658 (defun vc-svn-resolve-when-done ()
659 "Call \"svn resolved\" if the conflict markers have been removed."
661 (goto-char (point-min))
662 (unless (re-search-forward "^<<<<<<< " nil t
)
663 (vc-svn-command nil
0 buffer-file-name
"resolved")
664 ;; Remove the hook so that it is not called multiple times.
665 (remove-hook 'after-save-hook
'vc-svn-resolve-when-done t
))))
667 ;; Inspired by vc-arch-find-file-hook.
668 (defun vc-svn-find-file-hook ()
669 (when (eq ?C
(vc-file-getprop buffer-file-name
'vc-svn-status
))
670 ;; If the file is marked as "conflicted", then we should try and call
671 ;; "svn resolved" when applicable.
673 (goto-char (point-min))
674 (re-search-forward "^<<<<<<< " nil t
))
675 ;; There are conflict markers.
677 (smerge-start-session)
678 (add-hook 'after-save-hook
'vc-svn-resolve-when-done nil t
))
679 ;; There are no conflict markers. This is problematic: maybe it means
680 ;; the conflict has been resolved and we should immediately call "svn
681 ;; resolved", or it means that the file's type does not allow Svn to
682 ;; use conflict markers in which case we don't really know what to do.
683 ;; So let's just punt for now.
685 (message "There are unresolved conflicts in this file")))
687 (defun vc-svn-parse-status (&optional filename
)
688 "Parse output of \"svn status\" command in the current buffer.
689 Set file properties accordingly. If FILENAME is non-nil, return its status."
690 (let (multifile file status propstat
)
691 (goto-char (point-min))
692 (while (re-search-forward
693 ;; Ignore the files with status X.
694 "^\\(?:\\?\\|[ ACDGIMR!~][ MC][ L][ +][ S]..\\([ *]\\) +\\([-0-9]+\\) +\\([0-9?]+\\) +\\([^ ]+\\)\\) +" nil t
)
695 ;; If the username contains spaces, the output format is ambiguous,
696 ;; so don't trust the output's filename unless we have to.
697 (setq file
(or (unless multifile filename
)
699 (buffer-substring (point) (line-end-position))))
700 ;; If we are parsing the result of running status on a directory,
701 ;; there could be multiple files in the output.
702 ;; We assume that filename, if supplied, applies to the first
703 ;; listed file (ie, the directory). Bug#15322.
705 status
(char-after (line-beginning-position))
706 ;; Status of the item's properties ([ MC]).
707 propstat
(char-after (1+ (line-beginning-position))))
709 (vc-file-setprop file
'vc-state
'unregistered
)
710 ;; Use the last-modified revision, so that searching in vc-print-log
712 (vc-file-setprop file
'vc-working-revision
(match-string 3))
713 ;; Remember Svn's own status.
714 (vc-file-setprop file
'vc-svn-status status
)
718 ((and (eq status ?\
) (eq propstat ?\
))
719 (if (eq (char-after (match-beginning 1)) ?
*)
721 (vc-file-setprop file
'vc-checkout-time
722 (nth 5 (file-attributes file
)))
725 ;; If the file was actually copied, (match-string 2) is "-".
726 (vc-file-setprop file
'vc-working-revision
"0")
727 (vc-file-setprop file
'vc-checkout-time
0)
729 ;; Conflict in contents or properties.
730 ((or (eq status ?C
) (eq propstat ?C
))
731 (vc-file-setprop file
'vc-state
'conflict
))
732 ;; Modified contents or properties.
733 ((or (eq status ?M
) (eq propstat ?M
))
734 (if (eq (char-after (match-beginning 1)) ?
*)
738 (vc-file-setprop file
'vc-state
'ignored
))
739 ((memq status
'(?D ?R
))
740 (vc-file-setprop file
'vc-state
'removed
))
742 (when filename
(vc-file-getprop filename
'vc-state
))))
744 (defun vc-svn-valid-symbolic-tag-name-p (tag)
745 "Return non-nil if TAG is a valid symbolic tag name."
746 ;; According to the SVN manual, a valid symbolic tag must start with
747 ;; an uppercase or lowercase letter and can contain uppercase and
748 ;; lowercase letters, digits, `-', and `_'.
749 (and (string-match "^[a-zA-Z]" tag
)
750 (not (string-match "[^a-z0-9A-Z-_]" tag
))))
752 (defun vc-svn-valid-revision-number-p (tag)
753 "Return non-nil if TAG is a valid revision number."
754 (and (string-match "^[0-9]" tag
)
755 (not (string-match "[^0-9]" tag
))))
757 ;; Support for `svn annotate'
759 (defun vc-svn-annotate-command (file buf
&optional rev
)
760 (apply #'vc-svn-command buf
'async file
"annotate"
761 (append (vc-switches 'svn
'annotate
)
762 (if rev
(list (concat "-r" rev
))))))
764 (defun vc-svn-annotate-time-of-rev (rev)
765 ;; Arbitrarily assume 10 commits per day.
766 (/ (string-to-number rev
) 10.0))
768 (defvar vc-annotate-parent-rev
)
770 (defun vc-svn-annotate-current-time ()
771 (vc-svn-annotate-time-of-rev vc-annotate-parent-rev
))
773 (defconst vc-svn-annotate-re
"[ \t]*\\([0-9]+\\)[ \t]+[^\t ]+ ")
775 (defun vc-svn-annotate-time ()
776 (when (looking-at vc-svn-annotate-re
)
777 (goto-char (match-end 0))
778 (vc-svn-annotate-time-of-rev (match-string 1))))
780 (defun vc-svn-annotate-extract-revision-at-line ()
783 (if (looking-at vc-svn-annotate-re
) (match-string 1))))
785 (defun vc-svn-revision-table (files)
786 (let ((vc-svn-revisions '()))
787 (with-current-buffer "*vc*"
788 (vc-svn-command nil
0 files
"log" "-q")
789 (goto-char (point-min))
791 (let ((start (point-min))
792 (loglines (buffer-substring-no-properties (point-min)
794 (while (string-match "^r\\([0-9]+\\) " loglines
)
795 (push (match-string 1 loglines
) vc-svn-revisions
)
796 (setq start
(+ start
(match-end 0)))
797 (setq loglines
(buffer-substring-no-properties start
(point-max)))))
802 ;;; vc-svn.el ends here