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