Try to let it compile on other platforms
[emacs.git] / lisp / vc / vc-svn.el
blob6c2367c7ba6853ef5833e8bb0baa71be10a454dd
1 ;;; vc-svn.el --- non-resident support for Subversion version-control
3 ;; Copyright (C) 2003-2012 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 (defcustom vc-svn-global-switches nil
54 "Global switches to pass to any SVN command."
55 :type '(choice (const :tag "None" nil)
56 (string :tag "Argument String")
57 (repeat :tag "Argument List"
58 :value ("")
59 string))
60 :version "22.1"
61 :group 'vc-svn)
63 (defcustom vc-svn-register-switches nil
64 "Switches for registering a file into SVN.
65 A string or list of strings passed to the checkin program by
66 \\[vc-register]. If nil, use the value of `vc-register-switches'.
67 If t, use no switches."
68 :type '(choice (const :tag "Unspecified" nil)
69 (const :tag "None" t)
70 (string :tag "Argument String")
71 (repeat :tag "Argument List" :value ("") string))
72 :version "22.1"
73 :group 'vc-svn)
75 (defcustom vc-svn-diff-switches
76 t ;`svn' doesn't support common args like -c or -b.
77 "String or list of strings specifying extra switches for svn diff under VC.
78 If nil, use the value of `vc-diff-switches' (or `diff-switches'),
79 together with \"-x --diff-cmd=\"`diff-command' (since 'svn diff'
80 does not support the default \"-c\" value of `diff-switches').
81 If you want to force an empty list of arguments, use t."
82 :type '(choice (const :tag "Unspecified" nil)
83 (const :tag "None" t)
84 (string :tag "Argument String")
85 (repeat :tag "Argument List"
86 :value ("")
87 string))
88 :version "22.1"
89 :group 'vc-svn)
91 (defcustom vc-svn-header '("\$Id\$")
92 "Header keywords to be inserted by `vc-insert-headers'."
93 :version "24.1" ; no longer consult the obsolete vc-header-alist
94 :type '(repeat string)
95 :group 'vc-svn)
97 ;; We want to autoload it for use by the autoloaded version of
98 ;; vc-svn-registered, but we want the value to be compiled at startup, not
99 ;; at dump time.
100 ;; ;;;###autoload
101 (defconst vc-svn-admin-directory
102 (cond ((and (memq system-type '(cygwin windows-nt ms-dos))
103 (getenv "SVN_ASP_DOT_NET_HACK"))
104 "_svn")
105 (t ".svn"))
106 "The name of the \".svn\" subdirectory or its equivalent.")
108 ;;; Properties of the backend
110 (defun vc-svn-revision-granularity () 'repository)
111 (defun vc-svn-checkout-model (files) 'implicit)
114 ;;; State-querying functions
117 ;;; vc-svn-admin-directory is generally not defined when the
118 ;;; autoloaded function is called.
120 ;;;###autoload (defun vc-svn-registered (f)
121 ;;;###autoload (let ((admin-dir (cond ((and (eq system-type 'windows-nt)
122 ;;;###autoload (getenv "SVN_ASP_DOT_NET_HACK"))
123 ;;;###autoload "_svn")
124 ;;;###autoload (t ".svn"))))
125 ;;;###autoload (when (vc-find-root f admin-dir)
126 ;;;###autoload (load "vc-svn")
127 ;;;###autoload (vc-svn-registered f))))
129 (defun vc-svn-registered (file)
130 "Check if FILE is SVN registered."
131 (when (vc-svn-root file)
132 (with-temp-buffer
133 (cd (file-name-directory file))
134 (let* (process-file-side-effects
135 (status
136 (condition-case nil
137 ;; Ignore all errors.
138 (vc-svn-command t t file "status" "-v")
139 ;; Some problem happened. E.g. We can't find an `svn'
140 ;; executable. We used to only catch `file-error' but when
141 ;; the process is run on a remote host via Tramp, the error
142 ;; is only reported via the exit status which is turned into
143 ;; an `error' by vc-do-command.
144 (error nil))))
145 (when (eq 0 status)
146 (let ((parsed (vc-svn-parse-status file)))
147 (and parsed (not (memq parsed '(ignored unregistered))))))))))
149 (defun vc-svn-state (file &optional localp)
150 "SVN-specific version of `vc-state'."
151 (let (process-file-side-effects)
152 (setq localp (or localp (vc-stay-local-p file 'SVN)))
153 (with-temp-buffer
154 (cd (file-name-directory file))
155 (vc-svn-command t 0 file "status" (if localp "-v" "-u"))
156 (vc-svn-parse-status file))))
158 (defun vc-svn-state-heuristic (file)
159 "SVN-specific state heuristic."
160 (vc-svn-state file 'local))
162 ;; FIXME it would be better not to have the "remote" argument,
163 ;; but to distinguish the two output formats based on content.
164 (defun vc-svn-after-dir-status (callback &optional remote)
165 (let ((state-map '((?A . added)
166 (?C . conflict)
167 (?I . ignored)
168 (?M . edited)
169 (?D . removed)
170 (?R . removed)
171 (?? . unregistered)
172 ;; This is what vc-svn-parse-status does.
173 (?~ . edited)))
174 (re (if remote "^\\(.\\)\\(.\\).....? \\([ *]\\) +\\(?:[-0-9]+\\)? \\(.*\\)$"
175 ;; Subexp 3 is a dummy in this case, so the numbers match.
176 "^\\(.\\)\\(.\\)...\\(.\\) \\(.*\\)$"))
177 result)
178 (goto-char (point-min))
179 (while (re-search-forward re nil t)
180 (let ((state (cdr (assq (aref (match-string 1) 0) state-map)))
181 (propstat (cdr (assq (aref (match-string 2) 0) state-map)))
182 (filename (if (memq system-type '(windows-nt ms-dos))
183 (replace-regexp-in-string "\\\\" "/" (match-string 4))
184 (match-string 4))))
185 (and (memq propstat '(conflict edited))
186 (not (eq state 'conflict)) ; conflict always wins
187 (setq state propstat))
188 (and remote (string-equal (match-string 3) "*")
189 ;; FIXME are there other possible combinations?
190 (cond ((eq state 'edited) (setq state 'needs-merge))
191 ((not state) (setq state 'needs-update))))
192 (when (and state (not (string= "." filename)))
193 (setq result (cons (list filename state) result)))))
194 (funcall callback result)))
196 (defun vc-svn-dir-status (dir callback)
197 "Run 'svn status' for DIR and update BUFFER via CALLBACK.
198 CALLBACK is called as (CALLBACK RESULT BUFFER), where
199 RESULT is a list of conses (FILE . STATE) for directory DIR."
200 ;; FIXME should this rather be all the files in dir?
201 ;; FIXME: the vc-stay-local-p logic below is disabled, it ends up
202 ;; calling synchronously (vc-svn-registered DIR) => calling svn status -v DIR
203 ;; which is VERY SLOW for big trees and it makes emacs
204 ;; completely unresponsive during that time.
205 (let* ((local (and nil (vc-stay-local-p dir 'SVN)))
206 (remote (or t (not local) (eq local 'only-file))))
207 (vc-svn-command (current-buffer) 'async nil "status"
208 (if remote "-u"))
209 (vc-exec-after
210 `(vc-svn-after-dir-status (quote ,callback) ,remote))))
212 (defun vc-svn-dir-status-files (dir files default-state callback)
213 (apply 'vc-svn-command (current-buffer) 'async nil "status" files)
214 (vc-exec-after
215 `(vc-svn-after-dir-status (quote ,callback))))
217 (defun vc-svn-dir-extra-headers (dir)
218 "Generate extra status headers for a Subversion working copy."
219 (let (process-file-side-effects)
220 (vc-svn-command "*vc*" 0 nil "info"))
221 (let ((repo
222 (save-excursion
223 (and (progn
224 (set-buffer "*vc*")
225 (goto-char (point-min))
226 (re-search-forward "Repository Root: *\\(.*\\)" nil t))
227 (match-string 1)))))
228 (concat
229 (cond (repo
230 (concat
231 (propertize "Repository : " 'face 'font-lock-type-face)
232 (propertize repo 'face 'font-lock-variable-name-face)))
233 (t "")))))
235 (defun vc-svn-working-revision (file)
236 "SVN-specific version of `vc-working-revision'."
237 ;; There is no need to consult RCS headers under SVN, because we
238 ;; get the workfile version for free when we recognize that a file
239 ;; is registered in SVN.
240 (vc-svn-registered file)
241 (vc-file-getprop file 'vc-working-revision))
243 ;; vc-svn-mode-line-string doesn't exist because the default implementation
244 ;; works just fine.
246 (defun vc-svn-previous-revision (file rev)
247 (let ((newrev (1- (string-to-number rev))))
248 (when (< 0 newrev)
249 (number-to-string newrev))))
251 (defun vc-svn-next-revision (file rev)
252 (let ((newrev (1+ (string-to-number rev))))
253 ;; The "working revision" is an uneasy conceptual fit under Subversion;
254 ;; we use it as the upper bound until a better idea comes along. If the
255 ;; workfile version W coincides with the tree's latest revision R, then
256 ;; this check prevents a "no such revision: R+1" error. Otherwise, it
257 ;; inhibits showing of W+1 through R, which could be considered anywhere
258 ;; from gracious to impolite.
259 (unless (< (string-to-number (vc-file-getprop file 'vc-working-revision))
260 newrev)
261 (number-to-string newrev))))
265 ;;; State-changing functions
268 (defun vc-svn-create-repo ()
269 "Create a new SVN repository."
270 (vc-do-command "*vc*" 0 "svnadmin" '("create" "SVN"))
271 (vc-svn-command "*vc*" 0 "." "checkout"
272 (concat "file://" default-directory "SVN")))
274 (defun vc-svn-register (files &optional rev comment)
275 "Register FILES into the SVN version-control system.
276 The COMMENT argument is ignored This does an add but not a commit.
277 Passes either `vc-svn-register-switches' or `vc-register-switches'
278 to the SVN command."
279 (apply 'vc-svn-command nil 0 files "add" (vc-switches 'SVN 'register)))
281 (defun vc-svn-root (file)
282 (vc-find-root file vc-svn-admin-directory))
284 (defalias 'vc-svn-responsible-p 'vc-svn-root)
286 (defalias 'vc-svn-could-register 'vc-svn-root
287 "Return non-nil if FILE could be registered in SVN.
288 This is only possible if SVN is responsible for FILE's directory.")
290 (defun vc-svn-checkin (files rev comment &optional extra-args-ignored)
291 "SVN-specific version of `vc-backend-checkin'."
292 (if rev (error "Committing to a specific revision is unsupported in SVN"))
293 (let ((status (apply
294 'vc-svn-command nil 1 files "ci"
295 (nconc (list "-m" comment) (vc-switches 'SVN 'checkin)))))
296 (set-buffer "*vc*")
297 (goto-char (point-min))
298 (unless (equal status 0)
299 ;; Check checkin problem.
300 (cond
301 ((search-forward "Transaction is out of date" nil t)
302 (mapc (lambda (file) (vc-file-setprop file 'vc-state 'needs-merge))
303 files)
304 (error (substitute-command-keys
305 (concat "Up-to-date check failed: "
306 "type \\[vc-next-action] to merge in changes"))))
308 (pop-to-buffer (current-buffer))
309 (goto-char (point-min))
310 (shrink-window-if-larger-than-buffer)
311 (error "Check-in failed"))))
312 ;; Update file properties
313 ;; (vc-file-setprop
314 ;; file 'vc-working-revision
315 ;; (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
318 (defun vc-svn-find-revision (file rev buffer)
319 "SVN-specific retrieval of a specified version into a buffer."
320 (let (process-file-side-effects)
321 (apply 'vc-svn-command
322 buffer 0 file
323 "cat"
324 (and rev (not (string= rev ""))
325 (concat "-r" rev))
326 (vc-switches 'SVN 'checkout))))
328 (defun vc-svn-checkout (file &optional editable rev)
329 (message "Checking out %s..." file)
330 (with-current-buffer (or (get-file-buffer file) (current-buffer))
331 (vc-svn-update file editable rev (vc-switches 'SVN 'checkout)))
332 (vc-mode-line file 'SVN)
333 (message "Checking out %s...done" file))
335 (defun vc-svn-update (file editable rev switches)
336 (if (and (file-exists-p file) (not rev))
337 ;; If no revision was specified, there's nothing to do.
339 ;; Check out a particular version (or recreate the file).
340 (vc-file-setprop file 'vc-working-revision nil)
341 (apply 'vc-svn-command nil 0 file
342 "update"
343 (cond
344 ((null rev) "-rBASE")
345 ((or (eq rev t) (equal rev "")) nil)
346 (t (concat "-r" rev)))
347 switches)))
349 (defun vc-svn-delete-file (file)
350 (vc-svn-command nil 0 file "remove"))
352 (defun vc-svn-rename-file (old new)
353 (vc-svn-command nil 0 new "move" (file-relative-name old)))
355 (defun vc-svn-revert (file &optional contents-done)
356 "Revert FILE to the version it was based on."
357 (unless contents-done
358 (vc-svn-command nil 0 file "revert")))
360 (defun vc-svn-merge (file first-version &optional second-version)
361 "Merge changes into current working copy of FILE.
362 The changes are between FIRST-VERSION and SECOND-VERSION."
363 (vc-svn-command nil 0 file
364 "merge"
365 "-r" (if second-version
366 (concat first-version ":" second-version)
367 first-version))
368 (vc-file-setprop file 'vc-state 'edited)
369 (with-current-buffer (get-buffer "*vc*")
370 (goto-char (point-min))
371 (if (looking-at "C ")
372 1 ; signal conflict
373 0))) ; signal success
375 (defun vc-svn-merge-news (file)
376 "Merge in any new changes made to FILE."
377 (message "Merging changes into %s..." file)
378 ;; (vc-file-setprop file 'vc-working-revision nil)
379 (vc-file-setprop file 'vc-checkout-time 0)
380 (vc-svn-command nil 0 file "update")
381 ;; Analyze the merge result reported by SVN, and set
382 ;; file properties accordingly.
383 (with-current-buffer (get-buffer "*vc*")
384 (goto-char (point-min))
385 ;; get new working revision
386 (if (re-search-forward
387 "^\\(Updated to\\|At\\) revision \\([0-9]+\\)" nil t)
388 (vc-file-setprop file 'vc-working-revision (match-string 2))
389 (vc-file-setprop file 'vc-working-revision nil))
390 ;; get file status
391 (goto-char (point-min))
392 (prog1
393 (if (looking-at "At revision")
394 0 ;; there were no news; indicate success
395 (if (re-search-forward
396 ;; Newer SVN clients have 3 columns of chars (one for the
397 ;; file's contents, then second for its properties, and the
398 ;; third for lock-grabbing info), before the 2 spaces.
399 ;; We also used to match the filename in column 0 without any
400 ;; meta-info before it, but I believe this can never happen.
401 (concat "^\\(\\([ACGDU]\\)\\(.[B ]\\)? \\)"
402 (regexp-quote (file-name-nondirectory file)))
403 nil t)
404 (cond
405 ;; Merge successful, we are in sync with repository now
406 ((string= (match-string 2) "U")
407 (vc-file-setprop file 'vc-state 'up-to-date)
408 (vc-file-setprop file 'vc-checkout-time
409 (nth 5 (file-attributes file)))
410 0);; indicate success to the caller
411 ;; Merge successful, but our own changes are still in the file
412 ((string= (match-string 2) "G")
413 (vc-file-setprop file 'vc-state 'edited)
414 0);; indicate success to the caller
415 ;; Conflicts detected!
417 (vc-file-setprop file 'vc-state 'edited)
418 1);; signal the error to the caller
420 (pop-to-buffer "*vc*")
421 (error "Couldn't analyze svn update result")))
422 (message "Merging changes into %s...done" file))))
424 (defun vc-svn-modify-change-comment (files rev comment)
425 "Modify the change comments for a specified REV.
426 You must have ssh access to the repository host, and the directory Emacs
427 uses locally for temp files must also be writable by you on that host.
428 This is only supported if the repository access method is either file://
429 or svn+ssh://."
430 (let (tempfile host remotefile directory fileurl-p)
431 (with-temp-buffer
432 (vc-svn-command (current-buffer) 0 nil "info")
433 (goto-char (point-min))
434 (unless (re-search-forward "Repository Root: \\(file://\\(/.*\\)\\)\\|\\(svn\\+ssh://\\([^/]+\\)\\(/.*\\)\\)" nil t)
435 (error "Repository information is unavailable"))
436 (if (match-string 1)
437 (progn
438 (setq fileurl-p t)
439 (setq directory (match-string 2)))
440 (setq host (match-string 4))
441 (setq directory (match-string 5))
442 (setq remotefile (concat host ":" tempfile))))
443 (with-temp-file (setq tempfile (make-temp-file user-mail-address))
444 (insert comment))
445 (if fileurl-p
446 ;; Repository Root is a local file.
447 (progn
448 (unless (vc-do-command
449 "*vc*" 0 "svnadmin" nil
450 "setlog" "--bypass-hooks" directory
451 "-r" rev (format "%s" tempfile))
452 (error "Log edit failed"))
453 (delete-file tempfile))
455 ;; Remote repository, using svn+ssh.
456 (unless (vc-do-command "*vc*" 0 "scp" nil "-q" tempfile remotefile)
457 (error "Copy of comment to %s failed" remotefile))
458 (unless (vc-do-command
459 "*vc*" 0 "ssh" nil "-q" host
460 (format "svnadmin setlog --bypass-hooks %s -r %s %s; rm %s"
461 directory rev tempfile tempfile))
462 (error "Log edit failed")))))
465 ;;; History functions
468 (defvar log-view-per-file-logs)
470 (define-derived-mode vc-svn-log-view-mode log-view-mode "SVN-Log-View"
471 (require 'add-log)
472 (set (make-local-variable 'log-view-per-file-logs) nil))
474 (defun vc-svn-print-log (files buffer &optional shortlog start-revision limit)
475 "Get change log(s) associated with FILES."
476 (save-current-buffer
477 (vc-setup-buffer buffer)
478 (let ((inhibit-read-only t))
479 (goto-char (point-min))
480 (if files
481 (dolist (file files)
482 (insert "Working file: " file "\n")
483 (apply
484 'vc-svn-command
485 buffer
486 'async
487 ;; (if (and (= (length files) 1) (vc-stay-local-p file 'SVN)) 'async 0)
488 (list file)
489 "log"
490 (append
491 (list
492 (if start-revision
493 (format "-r%s" start-revision)
494 ;; By default Subversion only shows the log up to the
495 ;; working revision, whereas we also want the log of the
496 ;; subsequent commits. At least that's what the
497 ;; vc-cvs.el code does.
498 "-rHEAD:0"))
499 (when limit (list "--limit" (format "%s" limit))))))
500 ;; Dump log for the entire directory.
501 (apply 'vc-svn-command buffer 0 nil "log"
502 (append
503 (list
504 (if start-revision (format "-r%s" start-revision) "-rHEAD:0"))
505 (when limit (list "--limit" (format "%s" limit)))))))))
507 (defun vc-svn-diff (files &optional oldvers newvers buffer)
508 "Get a difference report using SVN between two revisions of fileset FILES."
509 (and oldvers
510 (not newvers)
511 files
512 (catch 'no
513 (dolist (f files)
514 (or (equal oldvers (vc-working-revision f))
515 (throw 'no nil)))
517 ;; Use nil rather than the current revision because svn handles
518 ;; it better (i.e. locally). Note that if _any_ of the files
519 ;; has a different revision, we fetch the lot, which is
520 ;; obviously sub-optimal.
521 (setq oldvers nil))
522 (let* ((switches
523 (if vc-svn-diff-switches
524 (vc-switches 'SVN 'diff)
525 (list (concat "--diff-cmd=" diff-command) "-x"
526 (mapconcat 'identity (vc-switches nil 'diff) " "))))
527 (async (and (not vc-disable-async-diff)
528 (vc-stay-local-p files 'SVN)
529 (or oldvers newvers)))) ; Svn diffs those locally.
530 (apply 'vc-svn-command buffer
531 (if async 'async 0)
532 files "diff"
533 (append
534 switches
535 (when oldvers
536 (list "-r" (if newvers (concat oldvers ":" newvers)
537 oldvers)))))
538 (if async 1 ; async diff => pessimistic assumption
539 ;; For some reason `svn diff' does not return a useful
540 ;; status w.r.t whether the diff was empty or not.
541 (buffer-size (get-buffer buffer)))))
544 ;;; Tag system
547 (defun vc-svn-create-tag (dir name branchp)
548 "Assign to DIR's current revision a given NAME.
549 If BRANCHP is non-nil, the name is created as a branch (and the current
550 workspace is immediately moved to that new branch).
551 NAME is assumed to be a URL."
552 (vc-svn-command nil 0 dir "copy" name)
553 (when branchp (vc-svn-retrieve-tag dir name nil)))
555 (defun vc-svn-retrieve-tag (dir name update)
556 "Retrieve a tag at and below DIR.
557 NAME is the name of the tag; if it is empty, do a `svn update'.
558 If UPDATE is non-nil, then update (resynch) any affected buffers.
559 NAME is assumed to be a URL."
560 (vc-svn-command nil 0 dir "switch" name)
561 ;; FIXME: parse the output and obey `update'.
565 ;;; Miscellaneous
568 ;; Subversion makes backups for us, so don't bother.
569 ;; (defun vc-svn-make-version-backups-p (file)
570 ;; "Return non-nil if version backups should be made for FILE."
571 ;; (vc-stay-local-p file 'SVN))
573 (defun vc-svn-check-headers ()
574 "Check if the current file has any headers in it."
575 (save-excursion
576 (goto-char (point-min))
577 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
578 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
582 ;;; Internal functions
585 (defun vc-svn-command (buffer okstatus file-or-list &rest flags)
586 "A wrapper around `vc-do-command' for use in vc-svn.el.
587 The difference to vc-do-command is that this function always invokes `svn',
588 and that it passes \"--non-interactive\" and `vc-svn-global-switches' to
589 it before FLAGS."
590 ;; Might be nice if svn defaulted to non-interactive if stdin not tty.
591 ;; http://svn.haxx.se/dev/archive-2008-05/0762.shtml
592 ;; http://svn.haxx.se/dev/archive-2009-04/0094.shtml
593 ;; Maybe newer ones do?
594 (or (member "--non-interactive"
595 (setq flags (if (stringp vc-svn-global-switches)
596 (cons vc-svn-global-switches flags)
597 (append vc-svn-global-switches flags))))
598 (setq flags (cons "--non-interactive" flags)))
599 (apply 'vc-do-command (or buffer "*vc*") okstatus vc-svn-program file-or-list
600 flags))
602 (defun vc-svn-repository-hostname (dirname)
603 (with-temp-buffer
604 (let (process-file-side-effects)
605 (vc-svn-command t t dirname "info" "--xml"))
606 (goto-char (point-min))
607 (when (re-search-forward "<url>\\(.*\\)</url>" nil t)
608 ;; This is not a hostname but a URL. This may actually be considered
609 ;; as a feature since it allows vc-svn-stay-local to specify different
610 ;; behavior for different modules on the same server.
611 (match-string 1))))
613 (defun vc-svn-resolve-when-done ()
614 "Call \"svn resolved\" if the conflict markers have been removed."
615 (save-excursion
616 (goto-char (point-min))
617 (unless (re-search-forward "^<<<<<<< " nil t)
618 (vc-svn-command nil 0 buffer-file-name "resolved")
619 ;; Remove the hook so that it is not called multiple times.
620 (remove-hook 'after-save-hook 'vc-svn-resolve-when-done t))))
622 ;; Inspired by vc-arch-find-file-hook.
623 (defun vc-svn-find-file-hook ()
624 (when (eq ?C (vc-file-getprop buffer-file-name 'vc-svn-status))
625 ;; If the file is marked as "conflicted", then we should try and call
626 ;; "svn resolved" when applicable.
627 (if (save-excursion
628 (goto-char (point-min))
629 (re-search-forward "^<<<<<<< " nil t))
630 ;; There are conflict markers.
631 (progn
632 (smerge-start-session)
633 (add-hook 'after-save-hook 'vc-svn-resolve-when-done nil t))
634 ;; There are no conflict markers. This is problematic: maybe it means
635 ;; the conflict has been resolved and we should immediately call "svn
636 ;; resolved", or it means that the file's type does not allow Svn to
637 ;; use conflict markers in which case we don't really know what to do.
638 ;; So let's just punt for now.
639 nil)
640 (message "There are unresolved conflicts in this file")))
642 (defun vc-svn-parse-status (&optional filename)
643 "Parse output of \"svn status\" command in the current buffer.
644 Set file properties accordingly. Unless FILENAME is non-nil, parse only
645 information about FILENAME and return its status."
646 (let (file status propstat)
647 (goto-char (point-min))
648 (while (re-search-forward
649 ;; Ignore the files with status X.
650 "^\\(?:\\?\\|[ ACDGIMR!~][ MC][ L][ +][ S]..\\([ *]\\) +\\([-0-9]+\\) +\\([0-9?]+\\) +\\([^ ]+\\)\\) +" nil t)
651 ;; If the username contains spaces, the output format is ambiguous,
652 ;; so don't trust the output's filename unless we have to.
653 (setq file (or filename
654 (expand-file-name
655 (buffer-substring (point) (line-end-position)))))
656 (setq status (char-after (line-beginning-position))
657 ;; Status of the item's properties ([ MC]).
658 propstat (char-after (1+ (line-beginning-position))))
659 (if (eq status ??)
660 (vc-file-setprop file 'vc-state 'unregistered)
661 ;; Use the last-modified revision, so that searching in vc-print-log
662 ;; output works.
663 (vc-file-setprop file 'vc-working-revision (match-string 3))
664 ;; Remember Svn's own status.
665 (vc-file-setprop file 'vc-svn-status status)
666 (vc-file-setprop
667 file 'vc-state
668 (cond
669 ((and (eq status ?\ ) (eq propstat ?\ ))
670 (if (eq (char-after (match-beginning 1)) ?*)
671 'needs-update
672 (vc-file-setprop file 'vc-checkout-time
673 (nth 5 (file-attributes file)))
674 'up-to-date))
675 ((eq status ?A)
676 ;; If the file was actually copied, (match-string 2) is "-".
677 (vc-file-setprop file 'vc-working-revision "0")
678 (vc-file-setprop file 'vc-checkout-time 0)
679 'added)
680 ;; Conflict in contents or properties.
681 ((or (eq status ?C) (eq propstat ?C))
682 (vc-file-setprop file 'vc-state 'conflict))
683 ;; Modified contents or properties.
684 ((or (eq status ?M) (eq propstat ?M))
685 (if (eq (char-after (match-beginning 1)) ?*)
686 'needs-merge
687 'edited))
688 ((eq status ?I)
689 (vc-file-setprop file 'vc-state 'ignored))
690 ((memq status '(?D ?R))
691 (vc-file-setprop file 'vc-state 'removed))
692 (t 'edited)))))
693 (when filename (vc-file-getprop filename 'vc-state))))
695 (defun vc-svn-valid-symbolic-tag-name-p (tag)
696 "Return non-nil if TAG is a valid symbolic tag name."
697 ;; According to the SVN manual, a valid symbolic tag must start with
698 ;; an uppercase or lowercase letter and can contain uppercase and
699 ;; lowercase letters, digits, `-', and `_'.
700 (and (string-match "^[a-zA-Z]" tag)
701 (not (string-match "[^a-z0-9A-Z-_]" tag))))
703 (defun vc-svn-valid-revision-number-p (tag)
704 "Return non-nil if TAG is a valid revision number."
705 (and (string-match "^[0-9]" tag)
706 (not (string-match "[^0-9]" tag))))
708 ;; Support for `svn annotate'
710 (defun vc-svn-annotate-command (file buf &optional rev)
711 (vc-svn-command buf 'async file "annotate" (if rev (concat "-r" rev))))
713 (defun vc-svn-annotate-time-of-rev (rev)
714 ;; Arbitrarily assume 10 commits per day.
715 (/ (string-to-number rev) 10.0))
717 (defvar vc-annotate-parent-rev)
719 (defun vc-svn-annotate-current-time ()
720 (vc-svn-annotate-time-of-rev vc-annotate-parent-rev))
722 (defconst vc-svn-annotate-re "[ \t]*\\([0-9]+\\)[ \t]+[^\t ]+ ")
724 (defun vc-svn-annotate-time ()
725 (when (looking-at vc-svn-annotate-re)
726 (goto-char (match-end 0))
727 (vc-svn-annotate-time-of-rev (match-string 1))))
729 (defun vc-svn-annotate-extract-revision-at-line ()
730 (save-excursion
731 (beginning-of-line)
732 (if (looking-at vc-svn-annotate-re) (match-string 1))))
734 (defun vc-svn-revision-table (files)
735 (let ((vc-svn-revisions '()))
736 (with-current-buffer "*vc*"
737 (vc-svn-command nil 0 files "log" "-q")
738 (goto-char (point-min))
739 (forward-line)
740 (let ((start (point-min))
741 (loglines (buffer-substring-no-properties (point-min)
742 (point-max))))
743 (while (string-match "^r\\([0-9]+\\) " loglines)
744 (push (match-string 1 loglines) vc-svn-revisions)
745 (setq start (+ start (match-end 0)))
746 (setq loglines (buffer-substring-no-properties start (point-max)))))
747 vc-svn-revisions)))
749 (provide 'vc-svn)
751 ;;; vc-svn.el ends here