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