Merge from origin/emacs-24
[emacs.git] / lisp / vc / vc-svn.el
blobd74daf9c36fac3fb2f7d30373fa87a5bfe479304
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>
7 ;; Package: vc
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/>.
24 ;;; Commentary:
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.
29 ;;; Code:
31 (eval-when-compile
32 (require 'vc))
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)
38 ;;;
39 ;;; Customization options
40 ;;;
42 (defgroup vc-svn nil
43 "VC Subversion (svn) backend."
44 :version "24.1"
45 :group 'vc)
47 ;; FIXME there is also svnadmin.
48 (defcustom vc-svn-program "svn"
49 "Name of the SVN executable."
50 :type 'string
51 :group 'vc-svn)
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"
65 :value ("")
66 string))
67 :version "24.4"
68 :group 'vc-svn)
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)
76 (const :tag "None" t)
77 (string :tag "Argument String")
78 (repeat :tag "Argument List" :value ("") string))
79 :version "22.1"
80 :group 'vc-svn)
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)
90 (const :tag "None" t)
91 (string :tag "Argument String")
92 (repeat :tag "Argument List"
93 :value ("")
94 string))
95 :version "22.1"
96 :group 'vc-svn)
98 (defcustom vc-svn-header '("\$Id\$")
99 "Header keywords to be inserted by `vc-insert-headers'."
100 :version "24.1" ; no longer consult the obsolete vc-header-alist
101 :type '(repeat string)
102 :group 'vc-svn)
104 ;; We want to autoload it for use by the autoloaded version of
105 ;; vc-svn-registered, but we want the value to be compiled at startup, not
106 ;; at dump time.
107 ;; ;;;###autoload
108 (defconst vc-svn-admin-directory
109 (cond ((and (memq system-type '(cygwin windows-nt ms-dos))
110 (getenv "SVN_ASP_DOT_NET_HACK"))
111 "_svn")
112 (t ".svn"))
113 "The name of the \".svn\" subdirectory or its equivalent.")
115 ;;; Properties of the backend
117 (defun vc-svn-revision-granularity () 'repository)
118 (defun vc-svn-checkout-model (_files) 'implicit)
121 ;;; State-querying functions
124 ;;; vc-svn-admin-directory is generally not defined when the
125 ;;; autoloaded function is called.
127 ;;;###autoload (defun vc-svn-registered (f)
128 ;;;###autoload (let ((admin-dir (cond ((and (eq system-type 'windows-nt)
129 ;;;###autoload (getenv "SVN_ASP_DOT_NET_HACK"))
130 ;;;###autoload "_svn")
131 ;;;###autoload (t ".svn"))))
132 ;;;###autoload (when (vc-find-root f admin-dir)
133 ;;;###autoload (load "vc-svn" nil t)
134 ;;;###autoload (vc-svn-registered f))))
136 (defun vc-svn-registered (file)
137 "Check if FILE is SVN registered."
138 (setq file (expand-file-name file))
139 (when (vc-svn-root file)
140 (with-temp-buffer
141 (cd (file-name-directory file))
142 (let* (process-file-side-effects
143 (status
144 (condition-case nil
145 ;; Ignore all errors.
146 (vc-svn-command t t file "status" "-v")
147 ;; Some problem happened. E.g. We can't find an `svn'
148 ;; executable. We used to only catch `file-error' but when
149 ;; the process is run on a remote host via Tramp, the error
150 ;; is only reported via the exit status which is turned into
151 ;; an `error' by vc-do-command.
152 (error nil))))
153 (when (eq 0 status)
154 (let ((parsed (vc-svn-parse-status file)))
155 (and parsed (not (memq parsed '(ignored unregistered))))))))))
157 (defun vc-svn-state (file)
158 "SVN-specific version of `vc-state'."
159 (let (process-file-side-effects)
160 (with-temp-buffer
161 (cd (file-name-directory file))
162 (vc-svn-command t 0 file "status" "-v")
163 (vc-svn-parse-status file))))
165 ;; FIXME it would be better not to have the "remote" argument,
166 ;; but to distinguish the two output formats based on content.
167 ;; FIXME: the local format isn't used by the (sole) caller anymore.
168 (defun vc-svn-after-dir-status (callback &optional remote)
169 (let ((state-map '((?A . added)
170 (?C . conflict)
171 (?I . ignored)
172 (?M . edited)
173 (?D . removed)
174 (?R . removed)
175 (?? . unregistered)
176 ;; This is what vc-svn-parse-status does.
177 (?~ . edited)))
178 (re (if remote "^\\(.\\)\\(.\\).....? \\([ *]\\) +\\(?:[-0-9]+\\)? \\(.*\\)$"
179 ;; Subexp 3 is a dummy in this case, so the numbers match.
180 "^\\(.\\)\\(.\\)...\\(.\\).? \\(.*\\)$"))
181 result)
182 (goto-char (point-min))
183 (while (re-search-forward re nil t)
184 (let ((state (cdr (assq (aref (match-string 1) 0) state-map)))
185 (propstat (cdr (assq (aref (match-string 2) 0) state-map)))
186 (filename (if (memq system-type '(windows-nt ms-dos))
187 (replace-regexp-in-string "\\\\" "/" (match-string 4))
188 (match-string 4))))
189 (and (memq propstat '(conflict edited))
190 (not (eq state 'conflict)) ; conflict always wins
191 (setq state propstat))
192 (and remote (string-equal (match-string 3) "*")
193 ;; FIXME are there other possible combinations?
194 (cond ((eq state 'edited) (setq state 'needs-merge))
195 ((not state) (setq state 'needs-update))))
196 (when (and state (not (string= "." filename)))
197 (setq result (cons (list filename state) result)))))
198 (funcall callback result)))
200 ;; dir-status-files called from vc-dir, which loads vc,
201 ;; which loads vc-dispatcher.
202 (declare-function vc-exec-after "vc-dispatcher" (code))
204 (autoload 'vc-expand-dirs "vc")
206 (defun vc-svn-dir-status-files (_dir files callback)
207 "Run 'svn status' for DIR and update BUFFER via CALLBACK.
208 CALLBACK is called as (CALLBACK RESULT BUFFER), where
209 RESULT is a list of conses (FILE . STATE) for directory DIR."
210 ;; FIXME shouldn't this rather default to all the files in dir?
211 (apply #'vc-svn-command (current-buffer) 'async nil "status" "-u" files)
212 (vc-run-delayed (vc-svn-after-dir-status callback t)))
214 (defun vc-svn-dir-extra-headers (_dir)
215 "Generate extra status headers for a Subversion working copy."
216 (let (process-file-side-effects)
217 (vc-svn-command "*vc*" 0 nil "info"))
218 (let ((repo
219 (save-excursion
220 (and (progn
221 (set-buffer "*vc*")
222 (goto-char (point-min))
223 (re-search-forward "Repository Root: *\\(.*\\)" nil t))
224 (match-string 1)))))
225 (concat
226 (cond (repo
227 (concat
228 (propertize "Repository : " 'face 'font-lock-type-face)
229 (propertize repo 'face 'font-lock-variable-name-face)))
230 (t "")))))
232 (defun vc-svn-working-revision (file)
233 "SVN-specific version of `vc-working-revision'."
234 ;; There is no need to consult RCS headers under SVN, because we
235 ;; get the workfile version for free when we recognize that a file
236 ;; is registered in SVN.
237 (vc-svn-registered file)
238 (vc-file-getprop file 'vc-working-revision))
240 ;; vc-svn-mode-line-string doesn't exist because the default implementation
241 ;; works just fine.
243 (defun vc-svn-previous-revision (_file rev)
244 (let ((newrev (1- (string-to-number rev))))
245 (when (< 0 newrev)
246 (number-to-string newrev))))
248 (defun vc-svn-next-revision (file rev)
249 (let ((newrev (1+ (string-to-number rev))))
250 ;; The "working revision" is an uneasy conceptual fit under Subversion;
251 ;; we use it as the upper bound until a better idea comes along. If the
252 ;; workfile version W coincides with the tree's latest revision R, then
253 ;; this check prevents a "no such revision: R+1" error. Otherwise, it
254 ;; inhibits showing of W+1 through R, which could be considered anywhere
255 ;; from gracious to impolite.
256 (unless (< (string-to-number (vc-file-getprop file 'vc-working-revision))
257 newrev)
258 (number-to-string newrev))))
262 ;;; State-changing functions
265 (defun vc-svn-create-repo ()
266 "Create a new SVN repository."
267 (vc-do-command "*vc*" 0 "svnadmin" '("create" "SVN"))
268 ;; Expand default-directory because svn gets confused by eg
269 ;; file://~/path/to/file. (Bug#15446).
270 (vc-svn-command "*vc*" 0 "." "checkout"
271 (concat "file://" (expand-file-name default-directory) "SVN")))
273 (autoload 'vc-switches "vc")
275 (defun vc-svn-register (files &optional _comment)
276 "Register FILES into the SVN version-control system.
277 The COMMENT argument is ignored This does an add but not a commit.
278 Passes either `vc-svn-register-switches' or `vc-register-switches'
279 to the SVN command."
280 (apply 'vc-svn-command nil 0 files "add" (vc-switches 'SVN 'register)))
282 (defun vc-svn-root (file)
283 (vc-find-root file vc-svn-admin-directory))
285 (defalias 'vc-svn-responsible-p 'vc-svn-root)
287 (defun vc-svn-checkin (files comment &optional _extra-args-ignored)
288 "SVN-specific version of `vc-backend-checkin'."
289 (let ((status (apply
290 'vc-svn-command nil 1 files "ci"
291 (nconc (list "-m" comment) (vc-switches 'SVN 'checkin)))))
292 (set-buffer "*vc*")
293 (goto-char (point-min))
294 (unless (equal status 0)
295 ;; Check checkin problem.
296 (cond
297 ((search-forward "Transaction is out of date" nil t)
298 (mapc (lambda (file) (vc-file-setprop file 'vc-state 'needs-merge))
299 files)
300 (error (substitute-command-keys
301 (concat "Up-to-date check failed: "
302 "type \\[vc-next-action] to merge in changes"))))
304 (pop-to-buffer (current-buffer))
305 (goto-char (point-min))
306 (shrink-window-if-larger-than-buffer)
307 (error "Check-in failed"))))
308 ;; Update file properties
309 ;; (vc-file-setprop
310 ;; file 'vc-working-revision
311 ;; (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
314 (defun vc-svn-find-revision (file rev buffer)
315 "SVN-specific retrieval of a specified version into a buffer."
316 (let (process-file-side-effects)
317 (apply 'vc-svn-command
318 buffer 0 file
319 "cat"
320 (and rev (not (string= rev ""))
321 (concat "-r" rev))
322 (vc-switches 'SVN 'checkout))))
324 (defun vc-svn-ignore (file &optional directory remove)
325 "Ignore FILE under Subversion.
326 FILE is a file wildcard, relative to the root directory of DIRECTORY."
327 (let* ((ignores (vc-svn-ignore-completion-table directory))
328 (file (file-relative-name file directory))
329 (ignores (if remove
330 (delete file ignores)
331 (push file ignores))))
332 (vc-svn-command nil 0 nil nil "propset" "svn:ignore"
333 (mapconcat #'identity ignores "\n")
334 (expand-file-name directory))))
336 (defun vc-svn-ignore-completion-table (directory)
337 "Return the list of ignored files in DIRECTORY."
338 (with-temp-buffer
339 (vc-svn-command t t nil "propget" "svn:ignore" (expand-file-name directory))
340 (split-string (buffer-string))))
342 (defun vc-svn-find-admin-dir (file)
343 "Return the administrative directory of FILE."
344 (expand-file-name vc-svn-admin-directory (vc-svn-root file)))
346 (defun vc-svn-checkout (file &optional rev)
347 (message "Checking out %s..." file)
348 (with-current-buffer (or (get-file-buffer file) (current-buffer))
349 (vc-svn-update file rev (vc-switches 'SVN 'checkout)))
350 (vc-mode-line file 'SVN)
351 (message "Checking out %s...done" file))
353 (defun vc-svn-update (file rev switches)
354 (if (and (file-exists-p file) (not rev))
355 ;; If no revision was specified, there's nothing to do.
357 ;; Check out a particular version (or recreate the file).
358 (vc-file-setprop file 'vc-working-revision nil)
359 (apply 'vc-svn-command nil 0 file
360 "update"
361 (cond
362 ((null rev) "-rBASE")
363 ((or (eq rev t) (equal rev "")) nil)
364 (t (concat "-r" rev)))
365 switches)))
367 (defun vc-svn-delete-file (file)
368 (vc-svn-command nil 0 file "remove"))
370 (defun vc-svn-rename-file (old new)
371 (vc-svn-command nil 0 new "move" (file-relative-name old)))
373 (defun vc-svn-revert (file &optional contents-done)
374 "Revert FILE to the version it was based on."
375 (unless contents-done
376 (vc-svn-command nil 0 file "revert")))
378 (defun vc-svn-merge-file (file)
379 "Accept a file merge request, prompting for revisions."
380 (let* ((first-revision
381 (vc-read-revision
382 (concat "Merge " file
383 " from SVN revision "
384 "(default news on current branch): ")
385 (list file)
386 'SVN))
387 second-revision
388 status)
389 (cond
390 ((string= first-revision "")
391 (setq status (vc-svn-merge-news file)))
393 (setq second-revision
394 (vc-read-revision
395 "Second SVN revision: "
396 (list file) 'SVN nil
397 first-revision))
398 (setq status (vc-svn-merge file first-revision second-revision))))
399 status))
401 (defun vc-svn-merge (file first-version &optional second-version)
402 "Merge changes into current working copy of FILE.
403 The changes are between FIRST-VERSION and SECOND-VERSION."
404 (vc-svn-command nil 0 file
405 "merge"
406 "-r" (if second-version
407 (concat first-version ":" second-version)
408 first-version))
409 (vc-file-setprop file 'vc-state 'edited)
410 (with-current-buffer (get-buffer "*vc*")
411 (goto-char (point-min))
412 (if (looking-at "C ")
413 1 ; signal conflict
414 0))) ; signal success
416 (defun vc-svn-merge-news (file)
417 "Merge in any new changes made to FILE."
418 (message "Merging changes into %s..." file)
419 ;; (vc-file-setprop file 'vc-working-revision nil)
420 (vc-file-setprop file 'vc-checkout-time 0)
421 (vc-svn-command nil 0 file "update")
422 ;; Analyze the merge result reported by SVN, and set
423 ;; file properties accordingly.
424 (with-current-buffer (get-buffer "*vc*")
425 (goto-char (point-min))
426 ;; get new working revision
427 (if (re-search-forward
428 "^\\(Updated to\\|At\\) revision \\([0-9]+\\)" nil t)
429 (vc-file-setprop file 'vc-working-revision (match-string 2))
430 (vc-file-setprop file 'vc-working-revision nil))
431 ;; get file status
432 (goto-char (point-min))
433 (prog1
434 (if (looking-at "At revision")
435 0 ;; there were no news; indicate success
436 (if (re-search-forward
437 ;; Newer SVN clients have 3 columns of chars (one for the
438 ;; file's contents, then second for its properties, and the
439 ;; third for lock-grabbing info), before the 2 spaces.
440 ;; We also used to match the filename in column 0 without any
441 ;; meta-info before it, but I believe this can never happen.
442 (concat "^\\(\\([ACGDU]\\)\\(.[B ]\\)? \\)"
443 (regexp-quote (file-relative-name file)))
444 nil t)
445 (cond
446 ;; Merge successful, we are in sync with repository now
447 ((string= (match-string 2) "U")
448 (vc-file-setprop file 'vc-state 'up-to-date)
449 (vc-file-setprop file 'vc-checkout-time
450 (nth 5 (file-attributes file)))
451 0);; indicate success to the caller
452 ;; Merge successful, but our own changes are still in the file
453 ((string= (match-string 2) "G")
454 (vc-file-setprop file 'vc-state 'edited)
455 0);; indicate success to the caller
456 ;; Conflicts detected!
458 (vc-file-setprop file 'vc-state 'edited)
459 1);; signal the error to the caller
461 (pop-to-buffer "*vc*")
462 (error "Couldn't analyze svn update result")))
463 (message "Merging changes into %s...done" file))))
465 (defun vc-svn-modify-change-comment (_files rev comment)
466 "Modify the change comments for a specified REV.
467 You must have ssh access to the repository host, and the directory Emacs
468 uses locally for temp files must also be writable by you on that host.
469 This is only supported if the repository access method is either file://
470 or svn+ssh://."
471 (let (tempfile host remotefile directory fileurl-p)
472 (with-temp-buffer
473 (vc-svn-command (current-buffer) 0 nil "info")
474 (goto-char (point-min))
475 (unless (re-search-forward "Repository Root: \\(file://\\(/.*\\)\\)\\|\\(svn\\+ssh://\\([^/]+\\)\\(/.*\\)\\)" nil t)
476 (error "Repository information is unavailable"))
477 (if (match-string 1)
478 (progn
479 (setq fileurl-p t)
480 (setq directory (match-string 2)))
481 (setq host (match-string 4))
482 (setq directory (match-string 5))
483 (setq remotefile (concat host ":" tempfile))))
484 (with-temp-file (setq tempfile (make-temp-file user-mail-address))
485 (insert comment))
486 (if fileurl-p
487 ;; Repository Root is a local file.
488 (progn
489 (unless (vc-do-command
490 "*vc*" 0 "svnadmin" nil
491 "setlog" "--bypass-hooks" directory
492 "-r" rev (format "%s" tempfile))
493 (error "Log edit failed"))
494 (delete-file tempfile))
496 ;; Remote repository, using svn+ssh.
497 (unless (vc-do-command "*vc*" 0 "scp" nil "-q" tempfile remotefile)
498 (error "Copy of comment to %s failed" remotefile))
499 (unless (vc-do-command
500 "*vc*" 0 "ssh" nil "-q" host
501 (format "svnadmin setlog --bypass-hooks %s -r %s %s; rm %s"
502 directory rev tempfile tempfile))
503 (error "Log edit failed")))))
506 ;;; History functions
509 (defvar log-view-per-file-logs)
511 (define-derived-mode vc-svn-log-view-mode log-view-mode "SVN-Log-View"
512 (require 'add-log)
513 (set (make-local-variable 'log-view-per-file-logs) nil))
515 (autoload 'vc-setup-buffer "vc-dispatcher")
517 (defun vc-svn-print-log (files buffer &optional _shortlog start-revision limit)
518 "Print commit log associated with FILES into specified BUFFER.
519 SHORTLOG is ignored.
520 If START-REVISION is non-nil, it is the newest revision to show.
521 If LIMIT is non-nil, show no more than this many entries."
522 (save-current-buffer
523 (vc-setup-buffer buffer)
524 (let ((inhibit-read-only t))
525 (goto-char (point-min))
526 (if files
527 (dolist (file files)
528 (insert "Working file: " file "\n")
529 (apply
530 'vc-svn-command
531 buffer
532 'async
533 (list file)
534 "log"
535 (append
536 (list
537 (if start-revision
538 (format "-r%s:1" start-revision)
539 ;; By default Subversion only shows the log up to the
540 ;; working revision, whereas we also want the log of the
541 ;; subsequent commits. At least that's what the
542 ;; vc-cvs.el code does.
543 "-rHEAD:0"))
544 (when limit (list "--limit" (format "%s" limit))))))
545 ;; Dump log for the entire directory.
546 (apply 'vc-svn-command buffer 0 nil "log"
547 (append
548 (list
549 (if start-revision (format "-r%s" start-revision) "-rHEAD:0"))
550 (when limit (list "--limit" (format "%s" limit)))))))))
552 (defun vc-svn-diff (files &optional oldvers newvers buffer async)
553 "Get a difference report using SVN between two revisions of fileset FILES."
554 (and oldvers
555 (not newvers)
556 files
557 (catch 'no
558 (dolist (f files)
559 (or (equal oldvers (vc-working-revision f))
560 (throw 'no nil)))
562 ;; Use nil rather than the current revision because svn handles
563 ;; it better (i.e. locally). Note that if _any_ of the files
564 ;; has a different revision, we fetch the lot, which is
565 ;; obviously sub-optimal.
566 (setq oldvers nil))
567 (setq async (and async (or oldvers newvers))) ; Svn diffs those locally.
568 (let* ((switches
569 (if vc-svn-diff-switches
570 (vc-switches 'SVN 'diff)
571 (list (concat "--diff-cmd=" diff-command) "-x"
572 (mapconcat 'identity (vc-switches nil 'diff) " ")))))
573 (apply 'vc-svn-command buffer
574 (if async 'async 0)
575 files "diff"
576 (append
577 switches
578 (when oldvers
579 (list "-r" (if newvers (concat oldvers ":" newvers)
580 oldvers)))))
581 (if async 1 ; async diff => pessimistic assumption
582 ;; For some reason `svn diff' does not return a useful
583 ;; status w.r.t whether the diff was empty or not.
584 (buffer-size (get-buffer buffer)))))
587 ;;; Tag system
590 (defun vc-svn-create-tag (dir name branchp)
591 "Assign to DIR's current revision a given NAME.
592 If BRANCHP is non-nil, the name is created as a branch (and the current
593 workspace is immediately moved to that new branch).
594 NAME is assumed to be a URL."
595 (vc-svn-command nil 0 dir "copy" name)
596 (when branchp (vc-svn-retrieve-tag dir name nil)))
598 (defun vc-svn-retrieve-tag (dir name _update)
599 "Retrieve a tag at and below DIR.
600 NAME is the name of the tag; if it is empty, do a `svn update'.
601 If UPDATE is non-nil, then update (resynch) any affected buffers.
602 NAME is assumed to be a URL."
603 (vc-svn-command nil 0 dir "switch" name)
604 ;; FIXME: parse the output and obey `update'.
608 ;;; Miscellaneous
611 ;; Subversion makes backups for us, so don't bother.
612 ;; (defun vc-svn-make-version-backups-p (file)
613 ;; "Return non-nil if version backups should be made for FILE."
614 ;; nil)
616 (defun vc-svn-check-headers ()
617 "Check if the current file has any headers in it."
618 (save-excursion
619 (goto-char (point-min))
620 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
621 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
625 ;;; Internal functions
628 (defun vc-svn-command (buffer okstatus file-or-list &rest flags)
629 "A wrapper around `vc-do-command' for use in vc-svn.el.
630 The difference to vc-do-command is that this function always invokes `svn',
631 and that it passes `vc-svn-global-switches' to it before FLAGS."
632 (apply 'vc-do-command (or buffer "*vc*") okstatus vc-svn-program file-or-list
633 (if (stringp vc-svn-global-switches)
634 (cons vc-svn-global-switches flags)
635 (append vc-svn-global-switches flags))))
637 (defun vc-svn-resolve-when-done ()
638 "Call \"svn resolved\" if the conflict markers have been removed."
639 (save-excursion
640 (goto-char (point-min))
641 (unless (re-search-forward "^<<<<<<< " nil t)
642 (vc-svn-command nil 0 buffer-file-name "resolved")
643 ;; Remove the hook so that it is not called multiple times.
644 (remove-hook 'after-save-hook 'vc-svn-resolve-when-done t))))
646 ;; Inspired by vc-arch-find-file-hook.
647 (defun vc-svn-find-file-hook ()
648 (when (eq ?C (vc-file-getprop buffer-file-name 'vc-svn-status))
649 ;; If the file is marked as "conflicted", then we should try and call
650 ;; "svn resolved" when applicable.
651 (if (save-excursion
652 (goto-char (point-min))
653 (re-search-forward "^<<<<<<< " nil t))
654 ;; There are conflict markers.
655 (progn
656 (smerge-start-session)
657 (add-hook 'after-save-hook 'vc-svn-resolve-when-done nil t))
658 ;; There are no conflict markers. This is problematic: maybe it means
659 ;; the conflict has been resolved and we should immediately call "svn
660 ;; resolved", or it means that the file's type does not allow Svn to
661 ;; use conflict markers in which case we don't really know what to do.
662 ;; So let's just punt for now.
663 nil)
664 (message "There are unresolved conflicts in this file")))
666 (defun vc-svn-parse-status (&optional filename)
667 "Parse output of \"svn status\" command in the current buffer.
668 Set file properties accordingly. If FILENAME is non-nil, return its status."
669 (let (multifile file status propstat)
670 (goto-char (point-min))
671 (while (re-search-forward
672 ;; Ignore the files with status X.
673 "^\\(?:\\?\\|[ ACDGIMR!~][ MC][ L][ +][ S]..\\([ *]\\) +\\([-0-9]+\\) +\\([0-9?]+\\) +\\([^ ]+\\)\\) +" nil t)
674 ;; If the username contains spaces, the output format is ambiguous,
675 ;; so don't trust the output's filename unless we have to.
676 (setq file (or (unless multifile filename)
677 (expand-file-name
678 (buffer-substring (point) (line-end-position))))
679 ;; If we are parsing the result of running status on a directory,
680 ;; there could be multiple files in the output.
681 ;; We assume that filename, if supplied, applies to the first
682 ;; listed file (ie, the directory). Bug#15322.
683 multifile t
684 status (char-after (line-beginning-position))
685 ;; Status of the item's properties ([ MC]).
686 propstat (char-after (1+ (line-beginning-position))))
687 (if (eq status ??)
688 (vc-file-setprop file 'vc-state 'unregistered)
689 ;; Use the last-modified revision, so that searching in vc-print-log
690 ;; output works.
691 (vc-file-setprop file 'vc-working-revision (match-string 3))
692 ;; Remember Svn's own status.
693 (vc-file-setprop file 'vc-svn-status status)
694 (vc-file-setprop
695 file 'vc-state
696 (cond
697 ((and (eq status ?\ ) (eq propstat ?\ ))
698 (if (eq (char-after (match-beginning 1)) ?*)
699 'needs-update
700 (vc-file-setprop file 'vc-checkout-time
701 (nth 5 (file-attributes file)))
702 'up-to-date))
703 ((eq status ?A)
704 ;; If the file was actually copied, (match-string 2) is "-".
705 (vc-file-setprop file 'vc-working-revision "0")
706 (vc-file-setprop file 'vc-checkout-time 0)
707 'added)
708 ;; Conflict in contents or properties.
709 ((or (eq status ?C) (eq propstat ?C))
710 (vc-file-setprop file 'vc-state 'conflict))
711 ;; Modified contents or properties.
712 ((or (eq status ?M) (eq propstat ?M))
713 (if (eq (char-after (match-beginning 1)) ?*)
714 'needs-merge
715 'edited))
716 ((eq status ?I)
717 (vc-file-setprop file 'vc-state 'ignored))
718 ((memq status '(?D ?R))
719 (vc-file-setprop file 'vc-state 'removed))
720 (t 'edited)))))
721 (when filename (vc-file-getprop filename 'vc-state))))
723 (defun vc-svn-valid-symbolic-tag-name-p (tag)
724 "Return non-nil if TAG is a valid symbolic tag name."
725 ;; According to the SVN manual, a valid symbolic tag must start with
726 ;; an uppercase or lowercase letter and can contain uppercase and
727 ;; lowercase letters, digits, `-', and `_'.
728 (and (string-match "^[a-zA-Z]" tag)
729 (not (string-match "[^a-z0-9A-Z-_]" tag))))
731 (defun vc-svn-valid-revision-number-p (tag)
732 "Return non-nil if TAG is a valid revision number."
733 (and (string-match "^[0-9]" tag)
734 (not (string-match "[^0-9]" tag))))
736 ;; Support for `svn annotate'
738 (defun vc-svn-annotate-command (file buf &optional rev)
739 (vc-svn-command buf 'async file "annotate" (if rev (concat "-r" rev))))
741 (defun vc-svn-annotate-time-of-rev (rev)
742 ;; Arbitrarily assume 10 commits per day.
743 (/ (string-to-number rev) 10.0))
745 (defvar vc-annotate-parent-rev)
747 (defun vc-svn-annotate-current-time ()
748 (vc-svn-annotate-time-of-rev vc-annotate-parent-rev))
750 (defconst vc-svn-annotate-re "[ \t]*\\([0-9]+\\)[ \t]+[^\t ]+ ")
752 (defun vc-svn-annotate-time ()
753 (when (looking-at vc-svn-annotate-re)
754 (goto-char (match-end 0))
755 (vc-svn-annotate-time-of-rev (match-string 1))))
757 (defun vc-svn-annotate-extract-revision-at-line ()
758 (save-excursion
759 (beginning-of-line)
760 (if (looking-at vc-svn-annotate-re) (match-string 1))))
762 (defun vc-svn-revision-table (files)
763 (let ((vc-svn-revisions '()))
764 (with-current-buffer "*vc*"
765 (vc-svn-command nil 0 files "log" "-q")
766 (goto-char (point-min))
767 (forward-line)
768 (let ((start (point-min))
769 (loglines (buffer-substring-no-properties (point-min)
770 (point-max))))
771 (while (string-match "^r\\([0-9]+\\) " loglines)
772 (push (match-string 1 loglines) vc-svn-revisions)
773 (setq start (+ start (match-end 0)))
774 (setq loglines (buffer-substring-no-properties start (point-max)))))
775 vc-svn-revisions)))
777 (provide 'vc-svn)
779 ;;; vc-svn.el ends here