Merge from origin/emacs-24
[emacs.git] / lisp / vc / vc-svn.el
blob5c87cab2d923ca82869d58532fbe44070168bdcc
1 ;;; vc-svn.el --- non-resident support for Subversion version-control -*- lexical-binding:t -*-
3 ;; Copyright (C) 2003-2014 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 (defun vc-svn-after-dir-status (callback &optional remote)
168 (let ((state-map '((?A . added)
169 (?C . conflict)
170 (?I . ignored)
171 (?M . edited)
172 (?D . removed)
173 (?R . removed)
174 (?? . unregistered)
175 ;; This is what vc-svn-parse-status does.
176 (?~ . edited)))
177 (re (if remote "^\\(.\\)\\(.\\).....? \\([ *]\\) +\\(?:[-0-9]+\\)? \\(.*\\)$"
178 ;; Subexp 3 is a dummy in this case, so the numbers match.
179 "^\\(.\\)\\(.\\)...\\(.\\).? \\(.*\\)$"))
180 result)
181 (goto-char (point-min))
182 (while (re-search-forward re nil t)
183 (let ((state (cdr (assq (aref (match-string 1) 0) state-map)))
184 (propstat (cdr (assq (aref (match-string 2) 0) state-map)))
185 (filename (if (memq system-type '(windows-nt ms-dos))
186 (replace-regexp-in-string "\\\\" "/" (match-string 4))
187 (match-string 4))))
188 (and (memq propstat '(conflict edited))
189 (not (eq state 'conflict)) ; conflict always wins
190 (setq state propstat))
191 (and remote (string-equal (match-string 3) "*")
192 ;; FIXME are there other possible combinations?
193 (cond ((eq state 'edited) (setq state 'needs-merge))
194 ((not state) (setq state 'needs-update))))
195 (when (and state (not (string= "." filename)))
196 (setq result (cons (list filename state) result)))))
197 (funcall callback result)))
199 ;; dir-status-files called from vc-dir, which loads vc,
200 ;; which loads vc-dispatcher.
201 (declare-function vc-exec-after "vc-dispatcher" (code))
203 (autoload 'vc-expand-dirs "vc")
205 (defun vc-svn-dir-status-files (_dir files callback)
206 "Run 'svn status' for DIR and update BUFFER via CALLBACK.
207 CALLBACK is called as (CALLBACK RESULT BUFFER), where
208 RESULT is a list of conses (FILE . STATE) for directory DIR."
209 ;; FIXME shouldn't this rather default to all the files in dir?
210 (apply #'vc-svn-command (current-buffer) 'async nil "status" "-u" files)
211 (vc-run-delayed (vc-svn-after-dir-status callback)))
213 (defun vc-svn-dir-extra-headers (_dir)
214 "Generate extra status headers for a Subversion working copy."
215 (let (process-file-side-effects)
216 (vc-svn-command "*vc*" 0 nil "info"))
217 (let ((repo
218 (save-excursion
219 (and (progn
220 (set-buffer "*vc*")
221 (goto-char (point-min))
222 (re-search-forward "Repository Root: *\\(.*\\)" nil t))
223 (match-string 1)))))
224 (concat
225 (cond (repo
226 (concat
227 (propertize "Repository : " 'face 'font-lock-type-face)
228 (propertize repo 'face 'font-lock-variable-name-face)))
229 (t "")))))
231 (defun vc-svn-working-revision (file)
232 "SVN-specific version of `vc-working-revision'."
233 ;; There is no need to consult RCS headers under SVN, because we
234 ;; get the workfile version for free when we recognize that a file
235 ;; is registered in SVN.
236 (vc-svn-registered file)
237 (vc-file-getprop file 'vc-working-revision))
239 ;; vc-svn-mode-line-string doesn't exist because the default implementation
240 ;; works just fine.
242 (defun vc-svn-previous-revision (_file rev)
243 (let ((newrev (1- (string-to-number rev))))
244 (when (< 0 newrev)
245 (number-to-string newrev))))
247 (defun vc-svn-next-revision (file rev)
248 (let ((newrev (1+ (string-to-number rev))))
249 ;; The "working revision" is an uneasy conceptual fit under Subversion;
250 ;; we use it as the upper bound until a better idea comes along. If the
251 ;; workfile version W coincides with the tree's latest revision R, then
252 ;; this check prevents a "no such revision: R+1" error. Otherwise, it
253 ;; inhibits showing of W+1 through R, which could be considered anywhere
254 ;; from gracious to impolite.
255 (unless (< (string-to-number (vc-file-getprop file 'vc-working-revision))
256 newrev)
257 (number-to-string newrev))))
261 ;;; State-changing functions
264 (defun vc-svn-create-repo ()
265 "Create a new SVN repository."
266 (vc-do-command "*vc*" 0 "svnadmin" '("create" "SVN"))
267 ;; Expand default-directory because svn gets confused by eg
268 ;; file://~/path/to/file. (Bug#15446).
269 (vc-svn-command "*vc*" 0 "." "checkout"
270 (concat "file://" (expand-file-name default-directory) "SVN")))
272 (autoload 'vc-switches "vc")
274 (defun vc-svn-register (files &optional _comment)
275 "Register FILES into the SVN version-control system.
276 The COMMENT argument is ignored This does an add but not a commit.
277 Passes either `vc-svn-register-switches' or `vc-register-switches'
278 to the SVN command."
279 (apply 'vc-svn-command nil 0 files "add" (vc-switches 'SVN 'register)))
281 (defun vc-svn-root (file)
282 (vc-find-root file vc-svn-admin-directory))
284 (defalias 'vc-svn-responsible-p 'vc-svn-root)
286 (defun vc-svn-checkin (files comment &optional _extra-args-ignored)
287 "SVN-specific version of `vc-backend-checkin'."
288 (let ((status (apply
289 'vc-svn-command nil 1 files "ci"
290 (nconc (list "-m" comment) (vc-switches 'SVN 'checkin)))))
291 (set-buffer "*vc*")
292 (goto-char (point-min))
293 (unless (equal status 0)
294 ;; Check checkin problem.
295 (cond
296 ((search-forward "Transaction is out of date" nil t)
297 (mapc (lambda (file) (vc-file-setprop file 'vc-state 'needs-merge))
298 files)
299 (error (substitute-command-keys
300 (concat "Up-to-date check failed: "
301 "type \\[vc-next-action] to merge in changes"))))
303 (pop-to-buffer (current-buffer))
304 (goto-char (point-min))
305 (shrink-window-if-larger-than-buffer)
306 (error "Check-in failed"))))
307 ;; Update file properties
308 ;; (vc-file-setprop
309 ;; file 'vc-working-revision
310 ;; (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
313 (defun vc-svn-find-revision (file rev buffer)
314 "SVN-specific retrieval of a specified version into a buffer."
315 (let (process-file-side-effects)
316 (apply 'vc-svn-command
317 buffer 0 file
318 "cat"
319 (and rev (not (string= rev ""))
320 (concat "-r" rev))
321 (vc-switches 'SVN 'checkout))))
323 (defun vc-svn-ignore (file &optional directory remove)
324 "Ignore FILE under Subversion.
325 FILE is a file wildcard, relative to the root directory of DIRECTORY."
326 (let* ((ignores (vc-svn-ignore-completion-table directory))
327 (file (file-relative-name file directory))
328 (ignores (if remove
329 (delete file ignores)
330 (push file ignores))))
331 (vc-svn-command nil 0 nil nil "propset" "svn:ignore"
332 (mapconcat #'identity ignores "\n")
333 (expand-file-name directory))))
335 (defun vc-svn-ignore-completion-table (directory)
336 "Return the list of ignored files in DIRECTORY."
337 (with-temp-buffer
338 (vc-svn-command t t nil "propget" "svn:ignore" (expand-file-name directory))
339 (split-string (buffer-string))))
341 (defun vc-svn-find-admin-dir (file)
342 "Return the administrative directory of FILE."
343 (expand-file-name vc-svn-admin-directory (vc-svn-root file)))
345 (defun vc-svn-checkout (file &optional rev)
346 (message "Checking out %s..." file)
347 (with-current-buffer (or (get-file-buffer file) (current-buffer))
348 (vc-svn-update file rev (vc-switches 'SVN 'checkout)))
349 (vc-mode-line file 'SVN)
350 (message "Checking out %s...done" file))
352 (defun vc-svn-update (file rev switches)
353 (if (and (file-exists-p file) (not rev))
354 ;; If no revision was specified, there's nothing to do.
356 ;; Check out a particular version (or recreate the file).
357 (vc-file-setprop file 'vc-working-revision nil)
358 (apply 'vc-svn-command nil 0 file
359 "update"
360 (cond
361 ((null rev) "-rBASE")
362 ((or (eq rev t) (equal rev "")) nil)
363 (t (concat "-r" rev)))
364 switches)))
366 (defun vc-svn-delete-file (file)
367 (vc-svn-command nil 0 file "remove"))
369 (defun vc-svn-rename-file (old new)
370 (vc-svn-command nil 0 new "move" (file-relative-name old)))
372 (defun vc-svn-revert (file &optional contents-done)
373 "Revert FILE to the version it was based on."
374 (unless contents-done
375 (vc-svn-command nil 0 file "revert")))
377 (defun vc-svn-merge-file (file)
378 "Accept a file merge request, prompting for revisions."
379 (let* ((first-revision
380 (vc-read-revision
381 (concat "Merge " file
382 " from SVN revision "
383 "(default news on current branch): ")
384 (list file)
385 'SVN))
386 second-revision
387 status)
388 (cond
389 ((string= first-revision "")
390 (setq status (vc-svn-merge-news file)))
392 (setq second-revision
393 (vc-read-revision
394 "Second SVN revision: "
395 (list file) 'SVN nil
396 first-revision))
397 (setq status (vc-svn-merge file first-revision second-revision))))
398 status))
400 (defun vc-svn-merge (file first-version &optional second-version)
401 "Merge changes into current working copy of FILE.
402 The changes are between FIRST-VERSION and SECOND-VERSION."
403 (vc-svn-command nil 0 file
404 "merge"
405 "-r" (if second-version
406 (concat first-version ":" second-version)
407 first-version))
408 (vc-file-setprop file 'vc-state 'edited)
409 (with-current-buffer (get-buffer "*vc*")
410 (goto-char (point-min))
411 (if (looking-at "C ")
412 1 ; signal conflict
413 0))) ; signal success
415 (defun vc-svn-merge-news (file)
416 "Merge in any new changes made to FILE."
417 (message "Merging changes into %s..." file)
418 ;; (vc-file-setprop file 'vc-working-revision nil)
419 (vc-file-setprop file 'vc-checkout-time 0)
420 (vc-svn-command nil 0 file "update")
421 ;; Analyze the merge result reported by SVN, and set
422 ;; file properties accordingly.
423 (with-current-buffer (get-buffer "*vc*")
424 (goto-char (point-min))
425 ;; get new working revision
426 (if (re-search-forward
427 "^\\(Updated to\\|At\\) revision \\([0-9]+\\)" nil t)
428 (vc-file-setprop file 'vc-working-revision (match-string 2))
429 (vc-file-setprop file 'vc-working-revision nil))
430 ;; get file status
431 (goto-char (point-min))
432 (prog1
433 (if (looking-at "At revision")
434 0 ;; there were no news; indicate success
435 (if (re-search-forward
436 ;; Newer SVN clients have 3 columns of chars (one for the
437 ;; file's contents, then second for its properties, and the
438 ;; third for lock-grabbing info), before the 2 spaces.
439 ;; We also used to match the filename in column 0 without any
440 ;; meta-info before it, but I believe this can never happen.
441 (concat "^\\(\\([ACGDU]\\)\\(.[B ]\\)? \\)"
442 (regexp-quote (file-relative-name file)))
443 nil t)
444 (cond
445 ;; Merge successful, we are in sync with repository now
446 ((string= (match-string 2) "U")
447 (vc-file-setprop file 'vc-state 'up-to-date)
448 (vc-file-setprop file 'vc-checkout-time
449 (nth 5 (file-attributes file)))
450 0);; indicate success to the caller
451 ;; Merge successful, but our own changes are still in the file
452 ((string= (match-string 2) "G")
453 (vc-file-setprop file 'vc-state 'edited)
454 0);; indicate success to the caller
455 ;; Conflicts detected!
457 (vc-file-setprop file 'vc-state 'edited)
458 1);; signal the error to the caller
460 (pop-to-buffer "*vc*")
461 (error "Couldn't analyze svn update result")))
462 (message "Merging changes into %s...done" file))))
464 (defun vc-svn-modify-change-comment (_files rev comment)
465 "Modify the change comments for a specified REV.
466 You must have ssh access to the repository host, and the directory Emacs
467 uses locally for temp files must also be writable by you on that host.
468 This is only supported if the repository access method is either file://
469 or svn+ssh://."
470 (let (tempfile host remotefile directory fileurl-p)
471 (with-temp-buffer
472 (vc-svn-command (current-buffer) 0 nil "info")
473 (goto-char (point-min))
474 (unless (re-search-forward "Repository Root: \\(file://\\(/.*\\)\\)\\|\\(svn\\+ssh://\\([^/]+\\)\\(/.*\\)\\)" nil t)
475 (error "Repository information is unavailable"))
476 (if (match-string 1)
477 (progn
478 (setq fileurl-p t)
479 (setq directory (match-string 2)))
480 (setq host (match-string 4))
481 (setq directory (match-string 5))
482 (setq remotefile (concat host ":" tempfile))))
483 (with-temp-file (setq tempfile (make-temp-file user-mail-address))
484 (insert comment))
485 (if fileurl-p
486 ;; Repository Root is a local file.
487 (progn
488 (unless (vc-do-command
489 "*vc*" 0 "svnadmin" nil
490 "setlog" "--bypass-hooks" directory
491 "-r" rev (format "%s" tempfile))
492 (error "Log edit failed"))
493 (delete-file tempfile))
495 ;; Remote repository, using svn+ssh.
496 (unless (vc-do-command "*vc*" 0 "scp" nil "-q" tempfile remotefile)
497 (error "Copy of comment to %s failed" remotefile))
498 (unless (vc-do-command
499 "*vc*" 0 "ssh" nil "-q" host
500 (format "svnadmin setlog --bypass-hooks %s -r %s %s; rm %s"
501 directory rev tempfile tempfile))
502 (error "Log edit failed")))))
505 ;;; History functions
508 (defvar log-view-per-file-logs)
510 (define-derived-mode vc-svn-log-view-mode log-view-mode "SVN-Log-View"
511 (require 'add-log)
512 (set (make-local-variable 'log-view-per-file-logs) nil))
514 (autoload 'vc-setup-buffer "vc-dispatcher")
516 (defun vc-svn-print-log (files buffer &optional _shortlog start-revision limit)
517 "Print commit log associated with FILES into specified BUFFER.
518 SHORTLOG is ignored.
519 If START-REVISION is non-nil, it is the newest revision to show.
520 If LIMIT is non-nil, show no more than this many entries."
521 (save-current-buffer
522 (vc-setup-buffer buffer)
523 (let ((inhibit-read-only t))
524 (goto-char (point-min))
525 (if files
526 (dolist (file files)
527 (insert "Working file: " file "\n")
528 (apply
529 'vc-svn-command
530 buffer
531 'async
532 (list file)
533 "log"
534 (append
535 (list
536 (if start-revision
537 (format "-r%s:1" start-revision)
538 ;; By default Subversion only shows the log up to the
539 ;; working revision, whereas we also want the log of the
540 ;; subsequent commits. At least that's what the
541 ;; vc-cvs.el code does.
542 "-rHEAD:0"))
543 (when limit (list "--limit" (format "%s" limit))))))
544 ;; Dump log for the entire directory.
545 (apply 'vc-svn-command buffer 0 nil "log"
546 (append
547 (list
548 (if start-revision (format "-r%s" start-revision) "-rHEAD:0"))
549 (when limit (list "--limit" (format "%s" limit)))))))))
551 (defun vc-svn-diff (files &optional oldvers newvers buffer async)
552 "Get a difference report using SVN between two revisions of fileset FILES."
553 (and oldvers
554 (not newvers)
555 files
556 (catch 'no
557 (dolist (f files)
558 (or (equal oldvers (vc-working-revision f))
559 (throw 'no nil)))
561 ;; Use nil rather than the current revision because svn handles
562 ;; it better (i.e. locally). Note that if _any_ of the files
563 ;; has a different revision, we fetch the lot, which is
564 ;; obviously sub-optimal.
565 (setq oldvers nil))
566 (setq async (and async (or oldvers newvers))) ; Svn diffs those locally.
567 (let* ((switches
568 (if vc-svn-diff-switches
569 (vc-switches 'SVN 'diff)
570 (list (concat "--diff-cmd=" diff-command) "-x"
571 (mapconcat 'identity (vc-switches nil 'diff) " ")))))
572 (apply 'vc-svn-command buffer
573 (if async 'async 0)
574 files "diff"
575 (append
576 switches
577 (when oldvers
578 (list "-r" (if newvers (concat oldvers ":" newvers)
579 oldvers)))))
580 (if async 1 ; async diff => pessimistic assumption
581 ;; For some reason `svn diff' does not return a useful
582 ;; status w.r.t whether the diff was empty or not.
583 (buffer-size (get-buffer buffer)))))
586 ;;; Tag system
589 (defun vc-svn-create-tag (dir name branchp)
590 "Assign to DIR's current revision a given NAME.
591 If BRANCHP is non-nil, the name is created as a branch (and the current
592 workspace is immediately moved to that new branch).
593 NAME is assumed to be a URL."
594 (vc-svn-command nil 0 dir "copy" name)
595 (when branchp (vc-svn-retrieve-tag dir name nil)))
597 (defun vc-svn-retrieve-tag (dir name _update)
598 "Retrieve a tag at and below DIR.
599 NAME is the name of the tag; if it is empty, do a `svn update'.
600 If UPDATE is non-nil, then update (resynch) any affected buffers.
601 NAME is assumed to be a URL."
602 (vc-svn-command nil 0 dir "switch" name)
603 ;; FIXME: parse the output and obey `update'.
607 ;;; Miscellaneous
610 ;; Subversion makes backups for us, so don't bother.
611 ;; (defun vc-svn-make-version-backups-p (file)
612 ;; "Return non-nil if version backups should be made for FILE."
613 ;; nil)
615 (defun vc-svn-check-headers ()
616 "Check if the current file has any headers in it."
617 (save-excursion
618 (goto-char (point-min))
619 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
620 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
624 ;;; Internal functions
627 (defun vc-svn-command (buffer okstatus file-or-list &rest flags)
628 "A wrapper around `vc-do-command' for use in vc-svn.el.
629 The difference to vc-do-command is that this function always invokes `svn',
630 and that it passes `vc-svn-global-switches' to it before FLAGS."
631 (apply 'vc-do-command (or buffer "*vc*") okstatus vc-svn-program file-or-list
632 (if (stringp vc-svn-global-switches)
633 (cons vc-svn-global-switches flags)
634 (append vc-svn-global-switches flags))))
636 (defun vc-svn-resolve-when-done ()
637 "Call \"svn resolved\" if the conflict markers have been removed."
638 (save-excursion
639 (goto-char (point-min))
640 (unless (re-search-forward "^<<<<<<< " nil t)
641 (vc-svn-command nil 0 buffer-file-name "resolved")
642 ;; Remove the hook so that it is not called multiple times.
643 (remove-hook 'after-save-hook 'vc-svn-resolve-when-done t))))
645 ;; Inspired by vc-arch-find-file-hook.
646 (defun vc-svn-find-file-hook ()
647 (when (eq ?C (vc-file-getprop buffer-file-name 'vc-svn-status))
648 ;; If the file is marked as "conflicted", then we should try and call
649 ;; "svn resolved" when applicable.
650 (if (save-excursion
651 (goto-char (point-min))
652 (re-search-forward "^<<<<<<< " nil t))
653 ;; There are conflict markers.
654 (progn
655 (smerge-start-session)
656 (add-hook 'after-save-hook 'vc-svn-resolve-when-done nil t))
657 ;; There are no conflict markers. This is problematic: maybe it means
658 ;; the conflict has been resolved and we should immediately call "svn
659 ;; resolved", or it means that the file's type does not allow Svn to
660 ;; use conflict markers in which case we don't really know what to do.
661 ;; So let's just punt for now.
662 nil)
663 (message "There are unresolved conflicts in this file")))
665 (defun vc-svn-parse-status (&optional filename)
666 "Parse output of \"svn status\" command in the current buffer.
667 Set file properties accordingly. If FILENAME is non-nil, return its status."
668 (let (multifile file status propstat)
669 (goto-char (point-min))
670 (while (re-search-forward
671 ;; Ignore the files with status X.
672 "^\\(?:\\?\\|[ ACDGIMR!~][ MC][ L][ +][ S]..\\([ *]\\) +\\([-0-9]+\\) +\\([0-9?]+\\) +\\([^ ]+\\)\\) +" nil t)
673 ;; If the username contains spaces, the output format is ambiguous,
674 ;; so don't trust the output's filename unless we have to.
675 (setq file (or (unless multifile filename)
676 (expand-file-name
677 (buffer-substring (point) (line-end-position))))
678 ;; If we are parsing the result of running status on a directory,
679 ;; there could be multiple files in the output.
680 ;; We assume that filename, if supplied, applies to the first
681 ;; listed file (ie, the directory). Bug#15322.
682 multifile t
683 status (char-after (line-beginning-position))
684 ;; Status of the item's properties ([ MC]).
685 propstat (char-after (1+ (line-beginning-position))))
686 (if (eq status ??)
687 (vc-file-setprop file 'vc-state 'unregistered)
688 ;; Use the last-modified revision, so that searching in vc-print-log
689 ;; output works.
690 (vc-file-setprop file 'vc-working-revision (match-string 3))
691 ;; Remember Svn's own status.
692 (vc-file-setprop file 'vc-svn-status status)
693 (vc-file-setprop
694 file 'vc-state
695 (cond
696 ((and (eq status ?\ ) (eq propstat ?\ ))
697 (if (eq (char-after (match-beginning 1)) ?*)
698 'needs-update
699 (vc-file-setprop file 'vc-checkout-time
700 (nth 5 (file-attributes file)))
701 'up-to-date))
702 ((eq status ?A)
703 ;; If the file was actually copied, (match-string 2) is "-".
704 (vc-file-setprop file 'vc-working-revision "0")
705 (vc-file-setprop file 'vc-checkout-time 0)
706 'added)
707 ;; Conflict in contents or properties.
708 ((or (eq status ?C) (eq propstat ?C))
709 (vc-file-setprop file 'vc-state 'conflict))
710 ;; Modified contents or properties.
711 ((or (eq status ?M) (eq propstat ?M))
712 (if (eq (char-after (match-beginning 1)) ?*)
713 'needs-merge
714 'edited))
715 ((eq status ?I)
716 (vc-file-setprop file 'vc-state 'ignored))
717 ((memq status '(?D ?R))
718 (vc-file-setprop file 'vc-state 'removed))
719 (t 'edited)))))
720 (when filename (vc-file-getprop filename 'vc-state))))
722 (defun vc-svn-valid-symbolic-tag-name-p (tag)
723 "Return non-nil if TAG is a valid symbolic tag name."
724 ;; According to the SVN manual, a valid symbolic tag must start with
725 ;; an uppercase or lowercase letter and can contain uppercase and
726 ;; lowercase letters, digits, `-', and `_'.
727 (and (string-match "^[a-zA-Z]" tag)
728 (not (string-match "[^a-z0-9A-Z-_]" tag))))
730 (defun vc-svn-valid-revision-number-p (tag)
731 "Return non-nil if TAG is a valid revision number."
732 (and (string-match "^[0-9]" tag)
733 (not (string-match "[^0-9]" tag))))
735 ;; Support for `svn annotate'
737 (defun vc-svn-annotate-command (file buf &optional rev)
738 (vc-svn-command buf 'async file "annotate" (if rev (concat "-r" rev))))
740 (defun vc-svn-annotate-time-of-rev (rev)
741 ;; Arbitrarily assume 10 commits per day.
742 (/ (string-to-number rev) 10.0))
744 (defvar vc-annotate-parent-rev)
746 (defun vc-svn-annotate-current-time ()
747 (vc-svn-annotate-time-of-rev vc-annotate-parent-rev))
749 (defconst vc-svn-annotate-re "[ \t]*\\([0-9]+\\)[ \t]+[^\t ]+ ")
751 (defun vc-svn-annotate-time ()
752 (when (looking-at vc-svn-annotate-re)
753 (goto-char (match-end 0))
754 (vc-svn-annotate-time-of-rev (match-string 1))))
756 (defun vc-svn-annotate-extract-revision-at-line ()
757 (save-excursion
758 (beginning-of-line)
759 (if (looking-at vc-svn-annotate-re) (match-string 1))))
761 (defun vc-svn-revision-table (files)
762 (let ((vc-svn-revisions '()))
763 (with-current-buffer "*vc*"
764 (vc-svn-command nil 0 files "log" "-q")
765 (goto-char (point-min))
766 (forward-line)
767 (let ((start (point-min))
768 (loglines (buffer-substring-no-properties (point-min)
769 (point-max))))
770 (while (string-match "^r\\([0-9]+\\) " loglines)
771 (push (match-string 1 loglines) vc-svn-revisions)
772 (setq start (+ start (match-end 0)))
773 (setq loglines (buffer-substring-no-properties start (point-max)))))
774 vc-svn-revisions)))
776 (provide 'vc-svn)
778 ;;; vc-svn.el ends here