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