Add "Package:" file headers to denote built-in packages.
[emacs.git] / lisp / vc / vc-svn.el
blob3af6842ab443766bf9504924c3ab29b69fd1caf6
1 ;;; vc-svn.el --- non-resident support for Subversion version-control
3 ;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: FSF (see vc.el for full credits)
7 ;; Maintainer: Stefan Monnier <monnier@gnu.org>
8 ;; Package: vc
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; Sync'd with Subversion's vc-svn.el as of revision 5801. but this version
28 ;; has been extensively modified since to handle filesets.
30 ;;; Code:
32 (eval-when-compile
33 (require 'vc))
35 ;; Clear up the cache to force vc-call to check again and discover
36 ;; new functions when we reload this file.
37 (put 'SVN 'vc-functions nil)
39 ;;;
40 ;;; Customization options
41 ;;;
43 ;; FIXME there is also svnadmin.
44 (defcustom vc-svn-program "svn"
45 "Name of the SVN executable."
46 :type 'string
47 :group 'vc)
49 (defcustom vc-svn-global-switches nil
50 "Global switches to pass to any SVN command."
51 :type '(choice (const :tag "None" nil)
52 (string :tag "Argument String")
53 (repeat :tag "Argument List"
54 :value ("")
55 string))
56 :version "22.1"
57 :group 'vc)
59 (defcustom vc-svn-register-switches nil
60 "Switches for registering a file into SVN.
61 A string or list of strings passed to the checkin program by
62 \\[vc-register]. If nil, use the value of `vc-register-switches'.
63 If t, use no switches."
64 :type '(choice (const :tag "Unspecified" nil)
65 (const :tag "None" t)
66 (string :tag "Argument String")
67 (repeat :tag "Argument List" :value ("") string))
68 :version "22.1"
69 :group 'vc)
71 (defcustom vc-svn-diff-switches
72 t ;`svn' doesn't support common args like -c or -b.
73 "String or list of strings specifying extra switches for svn diff under VC.
74 If nil, use the value of `vc-diff-switches' (or `diff-switches'),
75 together with \"-x --diff-cmd=diff\" (since svn diff does not
76 support the default \"-c\" value of `diff-switches'). If you
77 want to force an empty list of arguments, use t."
78 :type '(choice (const :tag "Unspecified" nil)
79 (const :tag "None" t)
80 (string :tag "Argument String")
81 (repeat :tag "Argument List"
82 :value ("")
83 string))
84 :version "22.1"
85 :group 'vc)
87 (defcustom vc-svn-header (or (cdr (assoc 'SVN vc-header-alist)) '("\$Id\$"))
88 "Header keywords to be inserted by `vc-insert-headers'."
89 :version "22.1"
90 :type '(repeat string)
91 :group 'vc)
93 ;; We want to autoload it for use by the autoloaded version of
94 ;; vc-svn-registered, but we want the value to be compiled at startup, not
95 ;; at dump time.
96 ;; ;;;###autoload
97 (defconst vc-svn-admin-directory
98 (cond ((and (memq system-type '(cygwin windows-nt ms-dos))
99 (getenv "SVN_ASP_DOT_NET_HACK"))
100 "_svn")
101 (t ".svn"))
102 "The name of the \".svn\" subdirectory or its equivalent.")
104 ;;; Properties of the backend
106 (defun vc-svn-revision-granularity () 'repository)
107 (defun vc-svn-checkout-model (files) 'implicit)
110 ;;; State-querying functions
113 ;;; vc-svn-admin-directory is generally not defined when the
114 ;;; autoloaded function is called.
116 ;;;###autoload (defun vc-svn-registered (f)
117 ;;;###autoload (let ((admin-dir (cond ((and (eq system-type 'windows-nt)
118 ;;;###autoload (getenv "SVN_ASP_DOT_NET_HACK"))
119 ;;;###autoload "_svn")
120 ;;;###autoload (t ".svn"))))
121 ;;;###autoload (when (file-readable-p (expand-file-name
122 ;;;###autoload (concat admin-dir "/entries")
123 ;;;###autoload (file-name-directory f)))
124 ;;;###autoload (load "vc-svn")
125 ;;;###autoload (vc-svn-registered f))))
127 (defun vc-svn-registered (file)
128 "Check if FILE is SVN registered."
129 (when (file-readable-p (expand-file-name (concat vc-svn-admin-directory
130 "/entries")
131 (file-name-directory 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 2 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 (filename (match-string 3)))
182 (and remote (string-equal (match-string 2) "*")
183 ;; FIXME are there other possible combinations?
184 (cond ((eq state 'edited) (setq state 'needs-merge))
185 ((not state) (setq state 'needs-update))))
186 (when (and state (not (string= "." filename)))
187 (setq result (cons (list filename state) result)))))
188 (funcall callback result)))
190 (defun vc-svn-dir-status (dir callback)
191 "Run 'svn status' for DIR and update BUFFER via CALLBACK.
192 CALLBACK is called as (CALLBACK RESULT BUFFER), where
193 RESULT is a list of conses (FILE . STATE) for directory DIR."
194 ;; FIXME should this rather be all the files in dir?
195 ;; FIXME: the vc-stay-local-p logic below is disabled, it ends up
196 ;; calling synchronously (vc-svn-registered DIR) => calling svn status -v DIR
197 ;; which is VERY SLOW for big trees and it makes emacs
198 ;; completely unresponsive during that time.
199 (let* ((local (and nil (vc-stay-local-p dir 'SVN)))
200 (remote (or t (not local) (eq local 'only-file))))
201 (vc-svn-command (current-buffer) 'async nil "status"
202 (if remote "-u"))
203 (vc-exec-after
204 `(vc-svn-after-dir-status (quote ,callback) ,remote))))
206 (defun vc-svn-dir-status-files (dir files default-state callback)
207 (apply 'vc-svn-command (current-buffer) 'async nil "status" files)
208 (vc-exec-after
209 `(vc-svn-after-dir-status (quote ,callback))))
211 (defun vc-svn-dir-extra-headers (dir)
212 "Generate extra status headers for a Subversion working copy."
213 (let (process-file-side-effects)
214 (vc-svn-command "*vc*" 0 nil "info"))
215 (let ((repo
216 (save-excursion
217 (and (progn
218 (set-buffer "*vc*")
219 (goto-char (point-min))
220 (re-search-forward "Repository Root: *\\(.*\\)" nil t))
221 (match-string 1)))))
222 (concat
223 (cond (repo
224 (concat
225 (propertize "Repository : " 'face 'font-lock-type-face)
226 (propertize repo 'face 'font-lock-variable-name-face)))
227 (t "")))))
229 (defun vc-svn-working-revision (file)
230 "SVN-specific version of `vc-working-revision'."
231 ;; There is no need to consult RCS headers under SVN, because we
232 ;; get the workfile version for free when we recognize that a file
233 ;; is registered in SVN.
234 (vc-svn-registered file)
235 (vc-file-getprop file 'vc-working-revision))
237 ;; vc-svn-mode-line-string doesn't exist because the default implementation
238 ;; works just fine.
240 (defun vc-svn-previous-revision (file rev)
241 (let ((newrev (1- (string-to-number rev))))
242 (when (< 0 newrev)
243 (number-to-string newrev))))
245 (defun vc-svn-next-revision (file rev)
246 (let ((newrev (1+ (string-to-number rev))))
247 ;; The "working revision" is an uneasy conceptual fit under Subversion;
248 ;; we use it as the upper bound until a better idea comes along. If the
249 ;; workfile version W coincides with the tree's latest revision R, then
250 ;; this check prevents a "no such revision: R+1" error. Otherwise, it
251 ;; inhibits showing of W+1 through R, which could be considered anywhere
252 ;; from gracious to impolite.
253 (unless (< (string-to-number (vc-file-getprop file 'vc-working-revision))
254 newrev)
255 (number-to-string newrev))))
259 ;;; State-changing functions
262 (defun vc-svn-create-repo ()
263 "Create a new SVN repository."
264 (vc-do-command "*vc*" 0 "svnadmin" '("create" "SVN"))
265 (vc-do-command "*vc*" 0 vc-svn-program '(".")
266 "checkout" (concat "file://" default-directory "SVN")))
268 (defun vc-svn-register (files &optional rev comment)
269 "Register FILES into the SVN version-control system.
270 The COMMENT argument is ignored This does an add but not a commit.
271 Passes either `vc-svn-register-switches' or `vc-register-switches'
272 to the SVN command."
273 (apply 'vc-svn-command nil 0 files "add" (vc-switches 'SVN 'register)))
275 (defun vc-svn-responsible-p (file)
276 "Return non-nil if SVN thinks it is responsible for FILE."
277 (file-directory-p (expand-file-name vc-svn-admin-directory
278 (if (file-directory-p file)
279 file
280 (file-name-directory file)))))
282 (defalias 'vc-svn-could-register 'vc-svn-responsible-p
283 "Return non-nil if FILE could be registered in SVN.
284 This is only possible if SVN is responsible for FILE's directory.")
286 (defun vc-svn-checkin (files rev comment &optional extra-args-ignored)
287 "SVN-specific version of `vc-backend-checkin'."
288 (if rev (error "Committing to a specific revision is unsupported in SVN"))
289 (let ((status (apply
290 'vc-svn-command nil 1 files "ci"
291 (nconc (list "-m" comment) (vc-switches 'SVN 'checkin)))))
292 (set-buffer "*vc*")
293 (goto-char (point-min))
294 (unless (equal status 0)
295 ;; Check checkin problem.
296 (cond
297 ((search-forward "Transaction is out of date" nil t)
298 (mapc (lambda (file) (vc-file-setprop file 'vc-state 'needs-merge))
299 files)
300 (error (substitute-command-keys
301 (concat "Up-to-date check failed: "
302 "type \\[vc-next-action] to merge in changes"))))
304 (pop-to-buffer (current-buffer))
305 (goto-char (point-min))
306 (shrink-window-if-larger-than-buffer)
307 (error "Check-in failed"))))
308 ;; Update file properties
309 ;; (vc-file-setprop
310 ;; file 'vc-working-revision
311 ;; (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
314 (defun vc-svn-find-revision (file rev buffer)
315 "SVN-specific retrieval of a specified version into a buffer."
316 (let (process-file-side-effects)
317 (apply 'vc-svn-command
318 buffer 0 file
319 "cat"
320 (and rev (not (string= rev ""))
321 (concat "-r" rev))
322 (vc-switches 'SVN 'checkout))))
324 (defun vc-svn-checkout (file &optional editable rev)
325 (message "Checking out %s..." file)
326 (with-current-buffer (or (get-file-buffer file) (current-buffer))
327 (vc-svn-update file editable rev (vc-switches 'SVN 'checkout)))
328 (vc-mode-line file 'SVN)
329 (message "Checking out %s...done" file))
331 (defun vc-svn-update (file editable rev switches)
332 (if (and (file-exists-p file) (not rev))
333 ;; If no revision was specified, there's nothing to do.
335 ;; Check out a particular version (or recreate the file).
336 (vc-file-setprop file 'vc-working-revision nil)
337 (apply 'vc-svn-command nil 0 file
338 "--non-interactive" ; bug#4280
339 "update"
340 (cond
341 ((null rev) "-rBASE")
342 ((or (eq rev t) (equal rev "")) nil)
343 (t (concat "-r" rev)))
344 switches)))
346 (defun vc-svn-delete-file (file)
347 (vc-svn-command nil 0 file "remove"))
349 (defun vc-svn-rename-file (old new)
350 (vc-svn-command nil 0 new "move" (file-relative-name old)))
352 (defun vc-svn-revert (file &optional contents-done)
353 "Revert FILE to the version it was based on."
354 (unless contents-done
355 (vc-svn-command nil 0 file "revert")))
357 (defun vc-svn-merge (file first-version &optional second-version)
358 "Merge changes into current working copy of FILE.
359 The changes are between FIRST-VERSION and SECOND-VERSION."
360 (vc-svn-command nil 0 file
361 "merge"
362 "-r" (if second-version
363 (concat first-version ":" second-version)
364 first-version))
365 (vc-file-setprop file 'vc-state 'edited)
366 (with-current-buffer (get-buffer "*vc*")
367 (goto-char (point-min))
368 (if (looking-at "C ")
369 1 ; signal conflict
370 0))) ; signal success
372 (defun vc-svn-merge-news (file)
373 "Merge in any new changes made to FILE."
374 (message "Merging changes into %s..." file)
375 ;; (vc-file-setprop file 'vc-working-revision nil)
376 (vc-file-setprop file 'vc-checkout-time 0)
377 (vc-svn-command nil 0 file "update")
378 ;; Analyze the merge result reported by SVN, and set
379 ;; file properties accordingly.
380 (with-current-buffer (get-buffer "*vc*")
381 (goto-char (point-min))
382 ;; get new working revision
383 (if (re-search-forward
384 "^\\(Updated to\\|At\\) revision \\([0-9]+\\)" nil t)
385 (vc-file-setprop file 'vc-working-revision (match-string 2))
386 (vc-file-setprop file 'vc-working-revision nil))
387 ;; get file status
388 (goto-char (point-min))
389 (prog1
390 (if (looking-at "At revision")
391 0 ;; there were no news; indicate success
392 (if (re-search-forward
393 ;; Newer SVN clients have 3 columns of chars (one for the
394 ;; file's contents, then second for its properties, and the
395 ;; third for lock-grabbing info), before the 2 spaces.
396 ;; We also used to match the filename in column 0 without any
397 ;; meta-info before it, but I believe this can never happen.
398 (concat "^\\(\\([ACGDU]\\)\\(.[B ]\\)? \\)"
399 (regexp-quote (file-name-nondirectory file)))
400 nil t)
401 (cond
402 ;; Merge successful, we are in sync with repository now
403 ((string= (match-string 2) "U")
404 (vc-file-setprop file 'vc-state 'up-to-date)
405 (vc-file-setprop file 'vc-checkout-time
406 (nth 5 (file-attributes file)))
407 0);; indicate success to the caller
408 ;; Merge successful, but our own changes are still in the file
409 ((string= (match-string 2) "G")
410 (vc-file-setprop file 'vc-state 'edited)
411 0);; indicate success to the caller
412 ;; Conflicts detected!
414 (vc-file-setprop file 'vc-state 'edited)
415 1);; signal the error to the caller
417 (pop-to-buffer "*vc*")
418 (error "Couldn't analyze svn update result")))
419 (message "Merging changes into %s...done" file))))
421 (defun vc-svn-modify-change-comment (files rev comment)
422 "Modify the change comments for a specified REV.
423 You must have ssh access to the repository host, and the directory Emacs
424 uses locally for temp files must also be writable by you on that host.
425 This is only supported if the repository access method is either file://
426 or svn+ssh://."
427 (let (tempfile host remotefile directory fileurl-p)
428 (with-temp-buffer
429 (vc-do-command (current-buffer) 0 vc-svn-program nil "info")
430 (goto-char (point-min))
431 (unless (re-search-forward "Repository Root: \\(file://\\(/.*\\)\\)\\|\\(svn\\+ssh://\\([^/]+\\)\\(/.*\\)\\)" nil t)
432 (error "Repository information is unavailable"))
433 (if (match-string 1)
434 (progn
435 (setq fileurl-p t)
436 (setq directory (match-string 2)))
437 (setq host (match-string 4))
438 (setq directory (match-string 5))
439 (setq remotefile (concat host ":" tempfile))))
440 (with-temp-file (setq tempfile (make-temp-file user-mail-address))
441 (insert comment))
442 (if fileurl-p
443 ;; Repository Root is a local file.
444 (progn
445 (unless (vc-do-command
446 "*vc*" 0 "svnadmin" nil
447 "setlog" "--bypass-hooks" directory
448 "-r" rev (format "%s" tempfile))
449 (error "Log edit failed"))
450 (delete-file tempfile))
452 ;; Remote repository, using svn+ssh.
453 (unless (vc-do-command "*vc*" 0 "scp" nil "-q" tempfile remotefile)
454 (error "Copy of comment to %s failed" remotefile))
455 (unless (vc-do-command
456 "*vc*" 0 "ssh" nil "-q" host
457 (format "svnadmin setlog --bypass-hooks %s -r %s %s; rm %s"
458 directory rev tempfile tempfile))
459 (error "Log edit failed")))))
462 ;;; History functions
465 (defvar log-view-per-file-logs)
467 (define-derived-mode vc-svn-log-view-mode log-view-mode "SVN-Log-View"
468 (require 'add-log)
469 (set (make-local-variable 'log-view-per-file-logs) nil))
471 (defun vc-svn-print-log (files buffer &optional shortlog start-revision limit)
472 "Get change log(s) associated with FILES."
473 (save-current-buffer
474 (vc-setup-buffer buffer)
475 (let ((inhibit-read-only t))
476 (goto-char (point-min))
477 (if files
478 (dolist (file files)
479 (insert "Working file: " file "\n")
480 (apply
481 'vc-svn-command
482 buffer
483 'async
484 ;; (if (and (= (length files) 1) (vc-stay-local-p file 'SVN)) 'async 0)
485 (list file)
486 "log"
487 (append
488 (list
489 (if start-revision
490 (format "-r%s" start-revision)
491 ;; By default Subversion only shows the log up to the
492 ;; working revision, whereas we also want the log of the
493 ;; subsequent commits. At least that's what the
494 ;; vc-cvs.el code does.
495 "-rHEAD:0"))
496 (when limit (list "--limit" (format "%s" limit))))))
497 ;; Dump log for the entire directory.
498 (apply 'vc-svn-command buffer 0 nil "log"
499 (append
500 (list
501 (if start-revision (format "-r%s" start-revision) "-rHEAD:0"))
502 (when limit (list "--limit" (format "%s" limit)))))))))
504 (defun vc-svn-diff (files &optional oldvers newvers buffer)
505 "Get a difference report using SVN between two revisions of fileset FILES."
506 (and oldvers
507 (not newvers)
508 files
509 (catch 'no
510 (dolist (f files)
511 (or (equal oldvers (vc-working-revision f))
512 (throw 'no nil)))
514 ;; Use nil rather than the current revision because svn handles
515 ;; it better (i.e. locally). Note that if _any_ of the files
516 ;; has a different revision, we fetch the lot, which is
517 ;; obviously sub-optimal.
518 (setq oldvers nil))
519 (let* ((switches
520 (if vc-svn-diff-switches
521 (vc-switches 'SVN 'diff)
522 (list "--diff-cmd=diff" "-x"
523 (mapconcat 'identity (vc-switches nil 'diff) " "))))
524 (async (and (not vc-disable-async-diff)
525 (vc-stay-local-p files 'SVN)
526 (or oldvers newvers)))) ; Svn diffs those locally.
527 (apply 'vc-svn-command buffer
528 (if async 'async 0)
529 files "diff"
530 (append
531 switches
532 (when oldvers
533 (list "-r" (if newvers (concat oldvers ":" newvers)
534 oldvers)))))
535 (if async 1 ; async diff => pessimistic assumption
536 ;; For some reason `svn diff' does not return a useful
537 ;; status w.r.t whether the diff was empty or not.
538 (buffer-size (get-buffer buffer)))))
541 ;;; Tag system
544 (defun vc-svn-create-tag (dir name branchp)
545 "Assign to DIR's current revision a given NAME.
546 If BRANCHP is non-nil, the name is created as a branch (and the current
547 workspace is immediately moved to that new branch).
548 NAME is assumed to be a URL."
549 (vc-svn-command nil 0 dir "copy" name)
550 (when branchp (vc-svn-retrieve-tag dir name nil)))
552 (defun vc-svn-retrieve-tag (dir name update)
553 "Retrieve a tag at and below DIR.
554 NAME is the name of the tag; if it is empty, do a `svn update'.
555 If UPDATE is non-nil, then update (resynch) any affected buffers.
556 NAME is assumed to be a URL."
557 (vc-svn-command nil 0 dir "switch" name)
558 ;; FIXME: parse the output and obey `update'.
562 ;;; Miscellaneous
565 ;; Subversion makes backups for us, so don't bother.
566 ;; (defun vc-svn-make-version-backups-p (file)
567 ;; "Return non-nil if version backups should be made for FILE."
568 ;; (vc-stay-local-p file 'SVN))
570 (defun vc-svn-check-headers ()
571 "Check if the current file has any headers in it."
572 (save-excursion
573 (goto-char (point-min))
574 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
575 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
579 ;;; Internal functions
582 (defun vc-svn-command (buffer okstatus file-or-list &rest flags)
583 "A wrapper around `vc-do-command' for use in vc-svn.el.
584 The difference to vc-do-command is that this function always invokes `svn',
585 and that it passes `vc-svn-global-switches' to it before FLAGS."
586 (apply 'vc-do-command (or buffer "*vc*") okstatus vc-svn-program file-or-list
587 (if (stringp vc-svn-global-switches)
588 (cons vc-svn-global-switches flags)
589 (append vc-svn-global-switches
590 flags))))
592 (defun vc-svn-repository-hostname (dirname)
593 (with-temp-buffer
594 (let ((coding-system-for-read
595 (or file-name-coding-system
596 default-file-name-coding-system)))
597 (vc-insert-file (expand-file-name (concat vc-svn-admin-directory
598 "/entries")
599 dirname)))
600 (goto-char (point-min))
601 (when (re-search-forward
602 ;; Old `svn' used name="svn:this_dir", newer use just name="".
603 (concat "name=\"\\(?:svn:this_dir\\)?\"[\n\t ]*"
604 "\\(?:[-a-z]+=\"[^\"]*\"[\n\t ]*\\)*?"
605 "url=\"\\(?1:[^\"]+\\)\""
606 ;; Yet newer ones don't use XML any more.
607 "\\|^\ndir\n[0-9]+\n\\(?1:.*\\)") 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)
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 (if (eq status ??)
658 (vc-file-setprop file 'vc-state 'unregistered)
659 ;; Use the last-modified revision, so that searching in vc-print-log
660 ;; output works.
661 (vc-file-setprop file 'vc-working-revision (match-string 3))
662 ;; Remember Svn's own status.
663 (vc-file-setprop file 'vc-svn-status status)
664 (vc-file-setprop
665 file 'vc-state
666 (cond
667 ((eq status ?\ )
668 (if (eq (char-after (match-beginning 1)) ?*)
669 'needs-update
670 (vc-file-setprop file 'vc-checkout-time
671 (nth 5 (file-attributes file)))
672 'up-to-date))
673 ((eq status ?A)
674 ;; If the file was actually copied, (match-string 2) is "-".
675 (vc-file-setprop file 'vc-working-revision "0")
676 (vc-file-setprop file 'vc-checkout-time 0)
677 'added)
678 ((eq status ?C)
679 (vc-file-setprop file 'vc-state 'conflict))
680 ((eq status '?M)
681 (if (eq (char-after (match-beginning 1)) ?*)
682 'needs-merge
683 'edited))
684 ((eq status ?I)
685 (vc-file-setprop file 'vc-state 'ignored))
686 ((memq status '(?D ?R))
687 (vc-file-setprop file 'vc-state 'removed))
688 (t 'edited)))))
689 (when filename (vc-file-getprop filename 'vc-state))))
691 (defun vc-svn-valid-symbolic-tag-name-p (tag)
692 "Return non-nil if TAG is a valid symbolic tag name."
693 ;; According to the SVN manual, a valid symbolic tag must start with
694 ;; an uppercase or lowercase letter and can contain uppercase and
695 ;; lowercase letters, digits, `-', and `_'.
696 (and (string-match "^[a-zA-Z]" tag)
697 (not (string-match "[^a-z0-9A-Z-_]" tag))))
699 (defun vc-svn-valid-revision-number-p (tag)
700 "Return non-nil if TAG is a valid revision number."
701 (and (string-match "^[0-9]" tag)
702 (not (string-match "[^0-9]" tag))))
704 ;; Support for `svn annotate'
706 (defun vc-svn-annotate-command (file buf &optional rev)
707 (vc-svn-command buf 'async file "annotate" (if rev (concat "-r" rev))))
709 (defun vc-svn-annotate-time-of-rev (rev)
710 ;; Arbitrarily assume 10 commmits per day.
711 (/ (string-to-number rev) 10.0))
713 (defvar vc-annotate-parent-rev)
715 (defun vc-svn-annotate-current-time ()
716 (vc-svn-annotate-time-of-rev vc-annotate-parent-rev))
718 (defconst vc-svn-annotate-re "[ \t]*\\([0-9]+\\)[ \t]+[^\t ]+ ")
720 (defun vc-svn-annotate-time ()
721 (when (looking-at vc-svn-annotate-re)
722 (goto-char (match-end 0))
723 (vc-svn-annotate-time-of-rev (match-string 1))))
725 (defun vc-svn-annotate-extract-revision-at-line ()
726 (save-excursion
727 (beginning-of-line)
728 (if (looking-at vc-svn-annotate-re) (match-string 1))))
730 (defun vc-svn-revision-table (files)
731 (let ((vc-svn-revisions '()))
732 (with-current-buffer "*vc*"
733 (vc-svn-command nil 0 files "log" "-q")
734 (goto-char (point-min))
735 (forward-line)
736 (let ((start (point-min))
737 (loglines (buffer-substring-no-properties (point-min)
738 (point-max))))
739 (while (string-match "^r\\([0-9]+\\) " loglines)
740 (push (match-string 1 loglines) vc-svn-revisions)
741 (setq start (+ start (match-end 0)))
742 (setq loglines (buffer-substring-no-properties start (point-max)))))
743 vc-svn-revisions)))
745 (provide 'vc-svn)
747 ;; arch-tag: 02f10c68-2b4d-453a-90fc-1eee6cfb268d
748 ;;; vc-svn.el ends here