Fix frame geometry related text
[emacs.git] / lisp / vc / vc-svn.el
blob8d6eae58d25feea9745c4b85b01886034d1dee29
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)
132 ;;; State-querying functions
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))))
273 ;;; State-changing functions
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 (svn-prog (executable-find "svn")))
284 (when (and (fboundp 'w32-application-type)
285 (eq (w32-application-type svn-prog) 'msys))
286 (setq defdir
287 (replace-regexp-in-string "^\\(.\\):/" "/\\1/"
288 defdir)))
289 (concat (if (and (stringp defdir)
290 (eq (aref defdir 0) ?/))
291 "file://"
292 ;; MS-Windows files d:/foo/bar need to
293 ;; begin with 3 leading slashes.
294 "file:///")
295 defdir
296 "SVN"))))
298 (autoload 'vc-switches "vc")
300 (defun vc-svn-register (files &optional _comment)
301 "Register FILES into the SVN version-control system.
302 The COMMENT argument is ignored This does an add but not a commit.
303 Passes either `vc-svn-register-switches' or `vc-register-switches'
304 to the SVN command."
305 (apply 'vc-svn-command nil 0 files "add" (vc-switches 'SVN 'register)))
307 (defun vc-svn-root (file)
308 (vc-find-root file vc-svn-admin-directory))
310 (defalias 'vc-svn-responsible-p 'vc-svn-root)
312 (defun vc-svn-checkin (files comment &optional _extra-args-ignored)
313 "SVN-specific version of `vc-backend-checkin'."
314 (let ((status (apply
315 'vc-svn-command nil 1 files "ci"
316 (nconc (list "-m" comment) (vc-switches 'SVN 'checkin)))))
317 (set-buffer "*vc*")
318 (goto-char (point-min))
319 (unless (equal status 0)
320 ;; Check checkin problem.
321 (cond
322 ((search-forward "Transaction is out of date" nil t)
323 (mapc (lambda (file) (vc-file-setprop file 'vc-state 'needs-merge))
324 files)
325 (error (substitute-command-keys
326 (concat "Up-to-date check failed: "
327 "type \\[vc-next-action] to merge in changes"))))
329 (pop-to-buffer (current-buffer))
330 (goto-char (point-min))
331 (shrink-window-if-larger-than-buffer)
332 (error "Check-in failed"))))
333 ;; Update file properties
334 ;; (vc-file-setprop
335 ;; file 'vc-working-revision
336 ;; (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
339 (defun vc-svn-find-revision (file rev buffer)
340 "SVN-specific retrieval of a specified version into a buffer."
341 (let (process-file-side-effects)
342 (apply 'vc-svn-command
343 buffer 0 file
344 "cat"
345 (and rev (not (string= rev ""))
346 (concat "-r" rev))
347 (vc-switches 'SVN 'checkout))))
349 (defun vc-svn-ignore (file &optional directory remove)
350 "Ignore FILE under Subversion.
351 FILE is a file wildcard, relative to the root directory of DIRECTORY."
352 (let* ((ignores (vc-svn-ignore-completion-table directory))
353 (file (file-relative-name file directory))
354 (ignores (if remove
355 (delete file ignores)
356 (push file ignores))))
357 (vc-svn-command nil 0 nil nil "propset" "svn:ignore"
358 (mapconcat #'identity ignores "\n")
359 (expand-file-name directory))))
361 (defun vc-svn-ignore-completion-table (directory)
362 "Return the list of ignored files in DIRECTORY."
363 (with-temp-buffer
364 (vc-svn-command t t nil "propget" "svn:ignore" (expand-file-name directory))
365 (split-string (buffer-string))))
367 (defun vc-svn-find-admin-dir (file)
368 "Return the administrative directory of FILE."
369 (expand-file-name vc-svn-admin-directory (vc-svn-root file)))
371 (defun vc-svn-checkout (file &optional rev)
372 (message "Checking out %s..." file)
373 (with-current-buffer (or (get-file-buffer file) (current-buffer))
374 (vc-svn-update file rev (vc-switches 'SVN 'checkout)))
375 (vc-mode-line file 'SVN)
376 (message "Checking out %s...done" file))
378 (defun vc-svn-update (file rev switches)
379 (if (and (file-exists-p file) (not rev))
380 ;; If no revision was specified, there's nothing to do.
382 ;; Check out a particular version (or recreate the file).
383 (vc-file-setprop file 'vc-working-revision nil)
384 (apply 'vc-svn-command nil 0 file
385 "update"
386 (cond
387 ((null rev) "-rBASE")
388 ((or (eq rev t) (equal rev "")) nil)
389 (t (concat "-r" rev)))
390 switches)))
392 (defun vc-svn-delete-file (file)
393 (vc-svn-command nil 0 file "remove"))
395 (defun vc-svn-rename-file (old new)
396 (vc-svn-command nil 0 new "move" (file-relative-name old)))
398 (defun vc-svn-revert (file &optional contents-done)
399 "Revert FILE to the version it was based on."
400 (unless contents-done
401 (vc-svn-command nil 0 file "revert")))
403 (defun vc-svn-merge-file (file)
404 "Accept a file merge request, prompting for revisions."
405 (let* ((first-revision
406 (vc-read-revision
407 (concat "Merge " file
408 " from SVN revision "
409 "(default news on current branch): ")
410 (list file)
411 'SVN))
412 second-revision
413 status)
414 (cond
415 ((string= first-revision "")
416 (setq status (vc-svn-merge-news file)))
418 (setq second-revision
419 (vc-read-revision
420 "Second SVN revision: "
421 (list file) 'SVN nil
422 first-revision))
423 (setq status (vc-svn-merge file first-revision second-revision))))
424 status))
426 (defun vc-svn-merge (file first-version &optional second-version)
427 "Merge changes into current working copy of FILE.
428 The changes are between FIRST-VERSION and SECOND-VERSION."
429 (vc-svn-command nil 0 file
430 "merge"
431 "-r" (if second-version
432 (concat first-version ":" second-version)
433 first-version))
434 (vc-file-setprop file 'vc-state 'edited)
435 (with-current-buffer (get-buffer "*vc*")
436 (goto-char (point-min))
437 (if (looking-at "C ")
438 1 ; signal conflict
439 0))) ; signal success
441 (defun vc-svn-merge-news (file)
442 "Merge in any new changes made to FILE."
443 (message "Merging changes into %s..." file)
444 ;; (vc-file-setprop file 'vc-working-revision nil)
445 (vc-file-setprop file 'vc-checkout-time 0)
446 (vc-svn-command nil 0 file "update")
447 ;; Analyze the merge result reported by SVN, and set
448 ;; file properties accordingly.
449 (with-current-buffer (get-buffer "*vc*")
450 (goto-char (point-min))
451 ;; get new working revision
452 (if (re-search-forward
453 "^\\(Updated to\\|At\\) revision \\([0-9]+\\)" nil t)
454 (vc-file-setprop file 'vc-working-revision (match-string 2))
455 (vc-file-setprop file 'vc-working-revision nil))
456 ;; get file status
457 (goto-char (point-min))
458 (prog1
459 (if (looking-at "At revision")
460 0 ;; there were no news; indicate success
461 (if (re-search-forward
462 ;; Newer SVN clients have 3 columns of chars (one for the
463 ;; file's contents, then second for its properties, and the
464 ;; third for lock-grabbing info), before the 2 spaces.
465 ;; We also used to match the filename in column 0 without any
466 ;; meta-info before it, but I believe this can never happen.
467 (concat "^\\(\\([ACGDU]\\)\\(.[B ]\\)? \\)"
468 (regexp-quote (file-relative-name file)))
469 nil t)
470 (cond
471 ;; Merge successful, we are in sync with repository now
472 ((string= (match-string 2) "U")
473 (vc-file-setprop file 'vc-state 'up-to-date)
474 (vc-file-setprop file 'vc-checkout-time
475 (nth 5 (file-attributes file)))
476 0);; indicate success to the caller
477 ;; Merge successful, but our own changes are still in the file
478 ((string= (match-string 2) "G")
479 (vc-file-setprop file 'vc-state 'edited)
480 0);; indicate success to the caller
481 ;; Conflicts detected!
483 (vc-file-setprop file 'vc-state 'edited)
484 1);; signal the error to the caller
486 (pop-to-buffer "*vc*")
487 (error "Couldn't analyze svn update result")))
488 (message "Merging changes into %s...done" file))))
490 (defun vc-svn-modify-change-comment (_files rev comment)
491 "Modify the change comments for a specified REV.
492 You must have ssh access to the repository host, and the directory Emacs
493 uses locally for temp files must also be writable by you on that host.
494 This is only supported if the repository access method is either file://
495 or svn+ssh://."
496 (let (tempfile host remotefile directory fileurl-p)
497 (with-temp-buffer
498 (vc-svn-command (current-buffer) 0 nil "info")
499 (goto-char (point-min))
500 (unless (re-search-forward "Repository Root: \\(file://\\(/.*\\)\\)\\|\\(svn\\+ssh://\\([^/]+\\)\\(/.*\\)\\)" nil t)
501 (error "Repository information is unavailable"))
502 (if (match-string 1)
503 (progn
504 (setq fileurl-p t)
505 (setq directory (match-string 2)))
506 (setq host (match-string 4))
507 (setq directory (match-string 5))
508 (setq remotefile (concat host ":" tempfile))))
509 (with-temp-file (setq tempfile (make-temp-file user-mail-address))
510 (insert comment))
511 (if fileurl-p
512 ;; Repository Root is a local file.
513 (progn
514 (unless (vc-do-command
515 "*vc*" 0 "svnadmin" nil
516 "setlog" "--bypass-hooks" directory
517 "-r" rev (format "%s" tempfile))
518 (error "Log edit failed"))
519 (delete-file tempfile))
521 ;; Remote repository, using svn+ssh.
522 (unless (vc-do-command "*vc*" 0 "scp" nil "-q" tempfile remotefile)
523 (error "Copy of comment to %s failed" remotefile))
524 (unless (vc-do-command
525 "*vc*" 0 "ssh" nil "-q" host
526 (format "svnadmin setlog --bypass-hooks %s -r %s %s; rm %s"
527 directory rev tempfile tempfile))
528 (error "Log edit failed")))))
531 ;;; History functions
534 (defvar log-view-per-file-logs)
536 (define-derived-mode vc-svn-log-view-mode log-view-mode "SVN-Log-View"
537 (require 'add-log)
538 (set (make-local-variable 'log-view-per-file-logs) nil))
540 (autoload 'vc-setup-buffer "vc-dispatcher")
542 (defun vc-svn-print-log (files buffer &optional _shortlog start-revision limit)
543 "Print commit log associated with FILES into specified BUFFER.
544 SHORTLOG is ignored.
545 If START-REVISION is non-nil, it is the newest revision to show.
546 If LIMIT is non-nil, show no more than this many entries."
547 (save-current-buffer
548 (vc-setup-buffer buffer)
549 (let ((inhibit-read-only t))
550 (goto-char (point-min))
551 (if files
552 (dolist (file files)
553 (insert "Working file: " file "\n")
554 (apply
555 'vc-svn-command
556 buffer
557 'async
558 (list file)
559 "log"
560 (append
561 (list
562 (if start-revision
563 (format "-r%s:1" start-revision)
564 ;; By default Subversion only shows the log up to the
565 ;; working revision, whereas we also want the log of the
566 ;; subsequent commits. At least that's what the
567 ;; vc-cvs.el code does.
568 "-rHEAD:0"))
569 (when limit (list "--limit" (format "%s" limit))))))
570 ;; Dump log for the entire directory.
571 (apply 'vc-svn-command buffer 0 nil "log"
572 (append
573 (list
574 (if start-revision (format "-r%s" start-revision) "-rHEAD:0"))
575 (when limit (list "--limit" (format "%s" limit)))))))))
577 (defun vc-svn-diff (files &optional oldvers newvers buffer async)
578 "Get a difference report using SVN between two revisions of fileset FILES."
579 (and oldvers
580 (not newvers)
581 files
582 (catch 'no
583 (dolist (f files)
584 (or (equal oldvers (vc-working-revision f))
585 (throw 'no nil)))
587 ;; Use nil rather than the current revision because svn handles
588 ;; it better (i.e. locally). Note that if _any_ of the files
589 ;; has a different revision, we fetch the lot, which is
590 ;; obviously sub-optimal.
591 (setq oldvers nil))
592 (setq async (and async (or oldvers newvers))) ; Svn diffs those locally.
593 (let* ((switches
594 (if vc-svn-diff-switches
595 (vc-switches 'SVN 'diff)
596 (list (concat "--diff-cmd=" diff-command) "-x"
597 (mapconcat 'identity (vc-switches nil 'diff) " ")))))
598 (apply 'vc-svn-command buffer
599 (if async 'async 0)
600 files "diff"
601 (append
602 switches
603 (when oldvers
604 (list "-r" (if newvers (concat oldvers ":" newvers)
605 oldvers)))))
606 (if async 1 ; async diff => pessimistic assumption
607 ;; For some reason `svn diff' does not return a useful
608 ;; status w.r.t whether the diff was empty or not.
609 (buffer-size (get-buffer buffer)))))
612 ;;; Tag system
615 (defun vc-svn-create-tag (dir name branchp)
616 "Assign to DIR's current revision a given NAME.
617 If BRANCHP is non-nil, the name is created as a branch (and the current
618 workspace is immediately moved to that new branch).
619 NAME is assumed to be a URL."
620 (vc-svn-command nil 0 dir "copy" name)
621 (when branchp (vc-svn-retrieve-tag dir name nil)))
623 (defun vc-svn-retrieve-tag (dir name _update)
624 "Retrieve a tag at and below DIR.
625 NAME is the name of the tag; if it is empty, do a `svn update'.
626 If UPDATE is non-nil, then update (resynch) any affected buffers.
627 NAME is assumed to be a URL."
628 (vc-svn-command nil 0 dir "switch" name)
629 ;; FIXME: parse the output and obey `update'.
633 ;;; Miscellaneous
636 ;; Subversion makes backups for us, so don't bother.
637 ;; (defun vc-svn-make-version-backups-p (file)
638 ;; "Return non-nil if version backups should be made for FILE."
639 ;; nil)
641 (defun vc-svn-check-headers ()
642 "Check if the current file has any headers in it."
643 (save-excursion
644 (goto-char (point-min))
645 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
646 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
650 ;;; Internal functions
653 (defun vc-svn-command (buffer okstatus file-or-list &rest flags)
654 "A wrapper around `vc-do-command' for use in vc-svn.el.
655 The difference to vc-do-command is that this function always invokes `svn',
656 and that it passes `vc-svn-global-switches' to it before FLAGS."
657 (apply 'vc-do-command (or buffer "*vc*") okstatus vc-svn-program file-or-list
658 (if (stringp vc-svn-global-switches)
659 (cons vc-svn-global-switches flags)
660 (append vc-svn-global-switches flags))))
662 (defun vc-svn-resolve-when-done ()
663 "Call \"svn resolved\" if the conflict markers have been removed."
664 (save-excursion
665 (goto-char (point-min))
666 (unless (re-search-forward "^<<<<<<< " nil t)
667 (vc-svn-command nil 0 buffer-file-name "resolved")
668 ;; Remove the hook so that it is not called multiple times.
669 (remove-hook 'after-save-hook 'vc-svn-resolve-when-done t))))
671 ;; Inspired by vc-arch-find-file-hook.
672 (defun vc-svn-find-file-hook ()
673 (when (eq ?C (vc-file-getprop buffer-file-name 'vc-svn-status))
674 ;; If the file is marked as "conflicted", then we should try and call
675 ;; "svn resolved" when applicable.
676 (if (save-excursion
677 (goto-char (point-min))
678 (re-search-forward "^<<<<<<< " nil t))
679 ;; There are conflict markers.
680 (progn
681 (smerge-start-session)
682 (add-hook 'after-save-hook 'vc-svn-resolve-when-done nil t))
683 ;; There are no conflict markers. This is problematic: maybe it means
684 ;; the conflict has been resolved and we should immediately call "svn
685 ;; resolved", or it means that the file's type does not allow Svn to
686 ;; use conflict markers in which case we don't really know what to do.
687 ;; So let's just punt for now.
688 nil)
689 (message "There are unresolved conflicts in this file")))
691 (defun vc-svn-parse-status (&optional filename)
692 "Parse output of \"svn status\" command in the current buffer.
693 Set file properties accordingly. If FILENAME is non-nil, return its status."
694 (let (multifile file status propstat)
695 (goto-char (point-min))
696 (while (re-search-forward
697 ;; Ignore the files with status X.
698 "^\\(?:\\?\\|[ ACDGIMR!~][ MC][ L][ +][ S]..\\([ *]\\) +\\([-0-9]+\\) +\\([0-9?]+\\) +\\([^ ]+\\)\\) +" nil t)
699 ;; If the username contains spaces, the output format is ambiguous,
700 ;; so don't trust the output's filename unless we have to.
701 (setq file (or (unless multifile filename)
702 (expand-file-name
703 (buffer-substring (point) (line-end-position))))
704 ;; If we are parsing the result of running status on a directory,
705 ;; there could be multiple files in the output.
706 ;; We assume that filename, if supplied, applies to the first
707 ;; listed file (ie, the directory). Bug#15322.
708 multifile t
709 status (char-after (line-beginning-position))
710 ;; Status of the item's properties ([ MC]).
711 propstat (char-after (1+ (line-beginning-position))))
712 (if (eq status ??)
713 (vc-file-setprop file 'vc-state 'unregistered)
714 ;; Use the last-modified revision, so that searching in vc-print-log
715 ;; output works.
716 (vc-file-setprop file 'vc-working-revision (match-string 3))
717 ;; Remember Svn's own status.
718 (vc-file-setprop file 'vc-svn-status status)
719 (vc-file-setprop
720 file 'vc-state
721 (cond
722 ((and (eq status ?\ ) (eq propstat ?\ ))
723 (if (eq (char-after (match-beginning 1)) ?*)
724 'needs-update
725 (vc-file-setprop file 'vc-checkout-time
726 (nth 5 (file-attributes file)))
727 'up-to-date))
728 ((eq status ?A)
729 ;; If the file was actually copied, (match-string 2) is "-".
730 (vc-file-setprop file 'vc-working-revision "0")
731 (vc-file-setprop file 'vc-checkout-time 0)
732 'added)
733 ;; Conflict in contents or properties.
734 ((or (eq status ?C) (eq propstat ?C))
735 (vc-file-setprop file 'vc-state 'conflict))
736 ;; Modified contents or properties.
737 ((or (eq status ?M) (eq propstat ?M))
738 (if (eq (char-after (match-beginning 1)) ?*)
739 'needs-merge
740 'edited))
741 ((eq status ?I)
742 (vc-file-setprop file 'vc-state 'ignored))
743 ((memq status '(?D ?R))
744 (vc-file-setprop file 'vc-state 'removed))
745 (t 'edited)))))
746 (when filename (vc-file-getprop filename 'vc-state))))
748 (defun vc-svn-valid-symbolic-tag-name-p (tag)
749 "Return non-nil if TAG is a valid symbolic tag name."
750 ;; According to the SVN manual, a valid symbolic tag must start with
751 ;; an uppercase or lowercase letter and can contain uppercase and
752 ;; lowercase letters, digits, `-', and `_'.
753 (and (string-match "^[a-zA-Z]" tag)
754 (not (string-match "[^a-z0-9A-Z-_]" tag))))
756 (defun vc-svn-valid-revision-number-p (tag)
757 "Return non-nil if TAG is a valid revision number."
758 (and (string-match "^[0-9]" tag)
759 (not (string-match "[^0-9]" tag))))
761 ;; Support for `svn annotate'
763 (defun vc-svn-annotate-command (file buf &optional rev)
764 (apply #'vc-svn-command buf 'async file "annotate"
765 (append (vc-switches 'svn 'annotate)
766 (if rev (list (concat "-r" rev))))))
768 (defun vc-svn-annotate-time-of-rev (rev)
769 ;; Arbitrarily assume 10 commits per day.
770 (/ (string-to-number rev) 10.0))
772 (defvar vc-annotate-parent-rev)
774 (defun vc-svn-annotate-current-time ()
775 (vc-svn-annotate-time-of-rev vc-annotate-parent-rev))
777 (defconst vc-svn-annotate-re "[ \t]*\\([0-9]+\\)[ \t]+[^\t ]+ ")
779 (defun vc-svn-annotate-time ()
780 (when (looking-at vc-svn-annotate-re)
781 (goto-char (match-end 0))
782 (vc-svn-annotate-time-of-rev (match-string 1))))
784 (defun vc-svn-annotate-extract-revision-at-line ()
785 (save-excursion
786 (beginning-of-line)
787 (if (looking-at vc-svn-annotate-re) (match-string 1))))
789 (defun vc-svn-revision-table (files)
790 (let ((vc-svn-revisions '()))
791 (with-current-buffer "*vc*"
792 (vc-svn-command nil 0 files "log" "-q")
793 (goto-char (point-min))
794 (forward-line)
795 (let ((start (point-min))
796 (loglines (buffer-substring-no-properties (point-min)
797 (point-max))))
798 (while (string-match "^r\\([0-9]+\\) " loglines)
799 (push (match-string 1 loglines) vc-svn-revisions)
800 (setq start (+ start (match-end 0)))
801 (setq loglines (buffer-substring-no-properties start (point-max)))))
802 vc-svn-revisions)))
804 (provide 'vc-svn)
806 ;;; vc-svn.el ends here