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