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