1 ;;; vc-svn.el --- non-resident support for Subversion version-control
3 ;; Copyright (C) 2003-2013 Free Software Foundation, Inc.
5 ;; Author: FSF (see vc.el for full credits)
6 ;; 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/>.
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.
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
)
39 ;;; Customization options
43 "VC Subversion (svn) backend."
47 ;; FIXME there is also svnadmin.
48 (defcustom vc-svn-program
"svn"
49 "Name of the SVN executable."
53 ;; Might be nice if svn defaulted to non-interactive if stdin not tty.
54 ;; http://svn.haxx.se/dev/archive-2008-05/0762.shtml
55 ;; http://svn.haxx.se/dev/archive-2009-04/0094.shtml
56 ;; Maybe newer ones do?
57 (defcustom vc-svn-global-switches
(unless (eq system-type
'darwin
) ; bug#13513
58 '("--non-interactive"))
59 "Global switches to pass to any SVN command.
60 The option \"--non-interactive\" is often needed to prevent SVN
61 hanging while prompting for authorization."
62 :type
'(choice (const :tag
"None" nil
)
63 (string :tag
"Argument String")
64 (repeat :tag
"Argument List"
70 (defcustom vc-svn-register-switches nil
71 "Switches for registering a file into SVN.
72 A string or list of strings passed to the checkin program by
73 \\[vc-register]. If nil, use the value of `vc-register-switches'.
74 If t, use no switches."
75 :type
'(choice (const :tag
"Unspecified" nil
)
77 (string :tag
"Argument String")
78 (repeat :tag
"Argument List" :value
("") string
))
82 (defcustom vc-svn-diff-switches
83 t
;`svn' doesn't support common args like -c or -b.
84 "String or list of strings specifying extra switches for svn diff under VC.
85 If nil, use the value of `vc-diff-switches' (or `diff-switches'),
86 together with \"-x --diff-cmd=\"`diff-command' (since 'svn diff'
87 does not support the default \"-c\" value of `diff-switches').
88 If you want to force an empty list of arguments, use t."
89 :type
'(choice (const :tag
"Unspecified" nil
)
91 (string :tag
"Argument String")
92 (repeat :tag
"Argument List"
98 (defcustom vc-svn-header
'("\$Id\$")
99 "Header keywords to be inserted by `vc-insert-headers'."
100 :version
"24.1" ; no longer consult the obsolete vc-header-alist
101 :type
'(repeat string
)
104 ;; We want to autoload it for use by the autoloaded version of
105 ;; vc-svn-registered, but we want the value to be compiled at startup, not
108 (defconst vc-svn-admin-directory
109 (cond ((and (memq system-type
'(cygwin windows-nt ms-dos
))
110 (getenv "SVN_ASP_DOT_NET_HACK"))
113 "The name of the \".svn\" subdirectory or its equivalent.")
115 ;;; Properties of the backend
117 (defun vc-svn-revision-granularity () 'repository
)
118 (defun vc-svn-checkout-model (files) 'implicit
)
121 ;;; State-querying functions
124 ;;; vc-svn-admin-directory is generally not defined when the
125 ;;; autoloaded function is called.
127 ;;;###autoload (defun vc-svn-registered (f)
128 ;;;###autoload (let ((admin-dir (cond ((and (eq system-type 'windows-nt)
129 ;;;###autoload (getenv "SVN_ASP_DOT_NET_HACK"))
130 ;;;###autoload "_svn")
131 ;;;###autoload (t ".svn"))))
132 ;;;###autoload (when (vc-find-root f admin-dir)
133 ;;;###autoload (load "vc-svn" nil t)
134 ;;;###autoload (vc-svn-registered f))))
136 (defun vc-svn-registered (file)
137 "Check if FILE is SVN registered."
138 (when (vc-svn-root file
)
140 (cd (file-name-directory file
))
141 (let* (process-file-side-effects
144 ;; Ignore all errors.
145 (vc-svn-command t t file
"status" "-v")
146 ;; Some problem happened. E.g. We can't find an `svn'
147 ;; executable. We used to only catch `file-error' but when
148 ;; the process is run on a remote host via Tramp, the error
149 ;; is only reported via the exit status which is turned into
150 ;; an `error' by vc-do-command.
153 (let ((parsed (vc-svn-parse-status file
)))
154 (and parsed
(not (memq parsed
'(ignored unregistered
))))))))))
156 (defun vc-svn-state (file &optional localp
)
157 "SVN-specific version of `vc-state'."
158 (let (process-file-side-effects)
159 (setq localp
(or localp
(vc-stay-local-p file
'SVN
)))
161 (cd (file-name-directory file
))
162 (vc-svn-command t
0 file
"status" (if localp
"-v" "-u"))
163 (vc-svn-parse-status file
))))
165 ;; NB this does not handle svn properties, which can be changed
166 ;; without changing the file timestamp.
167 ;; Note that unlike vc-cvs-state-heuristic, this is not called from
168 ;; vc-svn-state. AFAICS, it is only called from vc-state-refresh via
169 ;; vc-after-save (bug#7850). Therefore the fact that it ignores
170 ;; properties is irrelevant. If you want to make vc-svn-state call
171 ;; this, it should be extended to handle svn properties.
172 (defun vc-svn-state-heuristic (file)
173 "SVN-specific state heuristic."
174 ;; If the file has not changed since checkout, consider it `up-to-date'.
175 ;; Otherwise consider it `edited'. Copied from vc-cvs-state-heuristic.
176 (let ((checkout-time (vc-file-getprop file
'vc-checkout-time
))
177 (lastmod (nth 5 (file-attributes file
))))
179 ((equal checkout-time lastmod
) 'up-to-date
)
180 ((string= (vc-working-revision file
) "0") 'added
)
181 ((null checkout-time
) 'unregistered
)
184 ;; FIXME it would be better not to have the "remote" argument,
185 ;; but to distinguish the two output formats based on content.
186 (defun vc-svn-after-dir-status (callback &optional remote
)
187 (let ((state-map '((?A . added
)
194 ;; This is what vc-svn-parse-status does.
196 (re (if remote
"^\\(.\\)\\(.\\).....? \\([ *]\\) +\\(?:[-0-9]+\\)? \\(.*\\)$"
197 ;; Subexp 3 is a dummy in this case, so the numbers match.
198 "^\\(.\\)\\(.\\)...\\(.\\) \\(.*\\)$"))
200 (goto-char (point-min))
201 (while (re-search-forward re nil t
)
202 (let ((state (cdr (assq (aref (match-string 1) 0) state-map
)))
203 (propstat (cdr (assq (aref (match-string 2) 0) state-map
)))
204 (filename (if (memq system-type
'(windows-nt ms-dos
))
205 (replace-regexp-in-string "\\\\" "/" (match-string 4))
207 (and (memq propstat
'(conflict edited
))
208 (not (eq state
'conflict
)) ; conflict always wins
209 (setq state propstat
))
210 (and remote
(string-equal (match-string 3) "*")
211 ;; FIXME are there other possible combinations?
212 (cond ((eq state
'edited
) (setq state
'needs-merge
))
213 ((not state
) (setq state
'needs-update
))))
214 (when (and state
(not (string= "." filename
)))
215 (setq result
(cons (list filename state
) result
)))))
216 (funcall callback result
)))
218 ;; -dir-status called from vc-dir, which loads vc, which loads vc-dispatcher.
219 (declare-function vc-exec-after
"vc-dispatcher" (code))
221 (defun vc-svn-dir-status (dir callback
)
222 "Run 'svn status' for DIR and update BUFFER via CALLBACK.
223 CALLBACK is called as (CALLBACK RESULT BUFFER), where
224 RESULT is a list of conses (FILE . STATE) for directory DIR."
225 ;; FIXME should this rather be all the files in dir?
226 ;; FIXME: the vc-stay-local-p logic below is disabled, it ends up
227 ;; calling synchronously (vc-svn-registered DIR) => calling svn status -v DIR
228 ;; which is VERY SLOW for big trees and it makes emacs
229 ;; completely unresponsive during that time.
230 (let* ((local (and nil
(vc-stay-local-p dir
'SVN
)))
231 (remote (or t
(not local
) (eq local
'only-file
))))
232 (vc-svn-command (current-buffer) 'async nil
"status"
235 `(vc-svn-after-dir-status (quote ,callback
) ,remote
))))
237 (defun vc-svn-dir-status-files (dir files default-state callback
)
238 (apply 'vc-svn-command
(current-buffer) 'async nil
"status" files
)
240 `(vc-svn-after-dir-status (quote ,callback
))))
242 (defun vc-svn-dir-extra-headers (dir)
243 "Generate extra status headers for a Subversion working copy."
244 (let (process-file-side-effects)
245 (vc-svn-command "*vc*" 0 nil
"info"))
250 (goto-char (point-min))
251 (re-search-forward "Repository Root: *\\(.*\\)" nil t
))
256 (propertize "Repository : " 'face
'font-lock-type-face
)
257 (propertize repo
'face
'font-lock-variable-name-face
)))
260 (defun vc-svn-working-revision (file)
261 "SVN-specific version of `vc-working-revision'."
262 ;; There is no need to consult RCS headers under SVN, because we
263 ;; get the workfile version for free when we recognize that a file
264 ;; is registered in SVN.
265 (vc-svn-registered file
)
266 (vc-file-getprop file
'vc-working-revision
))
268 ;; vc-svn-mode-line-string doesn't exist because the default implementation
271 (defun vc-svn-previous-revision (file rev
)
272 (let ((newrev (1- (string-to-number rev
))))
274 (number-to-string newrev
))))
276 (defun vc-svn-next-revision (file rev
)
277 (let ((newrev (1+ (string-to-number rev
))))
278 ;; The "working revision" is an uneasy conceptual fit under Subversion;
279 ;; we use it as the upper bound until a better idea comes along. If the
280 ;; workfile version W coincides with the tree's latest revision R, then
281 ;; this check prevents a "no such revision: R+1" error. Otherwise, it
282 ;; inhibits showing of W+1 through R, which could be considered anywhere
283 ;; from gracious to impolite.
284 (unless (< (string-to-number (vc-file-getprop file
'vc-working-revision
))
286 (number-to-string newrev
))))
290 ;;; State-changing functions
293 (defun vc-svn-create-repo ()
294 "Create a new SVN repository."
295 (vc-do-command "*vc*" 0 "svnadmin" '("create" "SVN"))
296 (vc-svn-command "*vc*" 0 "." "checkout"
297 (concat "file://" default-directory
"SVN")))
299 (autoload 'vc-switches
"vc")
301 (defun vc-svn-register (files &optional rev comment
)
302 "Register FILES into the SVN version-control system.
303 The COMMENT argument is ignored This does an add but not a commit.
304 Passes either `vc-svn-register-switches' or `vc-register-switches'
306 (apply 'vc-svn-command nil
0 files
"add" (vc-switches 'SVN
'register
)))
308 (defun vc-svn-root (file)
309 (vc-find-root file vc-svn-admin-directory
))
311 (defalias 'vc-svn-responsible-p
'vc-svn-root
)
313 (defalias 'vc-svn-could-register
'vc-svn-root
314 "Return non-nil if FILE could be registered in SVN.
315 This is only possible if SVN is responsible for FILE's directory.")
317 (defun vc-svn-checkin (files rev comment
&optional extra-args-ignored
)
318 "SVN-specific version of `vc-backend-checkin'."
319 (if rev
(error "Committing to a specific revision is unsupported in SVN"))
321 'vc-svn-command nil
1 files
"ci"
322 (nconc (list "-m" comment
) (vc-switches 'SVN
'checkin
)))))
324 (goto-char (point-min))
325 (unless (equal status
0)
326 ;; Check checkin problem.
328 ((search-forward "Transaction is out of date" nil t
)
329 (mapc (lambda (file) (vc-file-setprop file
'vc-state
'needs-merge
))
331 (error (substitute-command-keys
332 (concat "Up-to-date check failed: "
333 "type \\[vc-next-action] to merge in changes"))))
335 (pop-to-buffer (current-buffer))
336 (goto-char (point-min))
337 (shrink-window-if-larger-than-buffer)
338 (error "Check-in failed"))))
339 ;; Update file properties
341 ;; file 'vc-working-revision
342 ;; (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2))
345 (defun vc-svn-find-revision (file rev buffer
)
346 "SVN-specific retrieval of a specified version into a buffer."
347 (let (process-file-side-effects)
348 (apply 'vc-svn-command
351 (and rev
(not (string= rev
""))
353 (vc-switches 'SVN
'checkout
))))
355 (defun vc-svn-ignore (file)
356 "Ignore FILE under Subversion."
357 (vc-svn-command t
0 file
"propedit" "svn:ignore"))
359 (defun vc-svn-checkout (file &optional editable rev
)
360 (message "Checking out %s..." file
)
361 (with-current-buffer (or (get-file-buffer file
) (current-buffer))
362 (vc-svn-update file editable rev
(vc-switches 'SVN
'checkout
)))
363 (vc-mode-line file
'SVN
)
364 (message "Checking out %s...done" file
))
366 (defun vc-svn-update (file editable rev switches
)
367 (if (and (file-exists-p file
) (not rev
))
368 ;; If no revision was specified, there's nothing to do.
370 ;; Check out a particular version (or recreate the file).
371 (vc-file-setprop file
'vc-working-revision nil
)
372 (apply 'vc-svn-command nil
0 file
375 ((null rev
) "-rBASE")
376 ((or (eq rev t
) (equal rev
"")) nil
)
377 (t (concat "-r" rev
)))
380 (defun vc-svn-delete-file (file)
381 (vc-svn-command nil
0 file
"remove"))
383 (defun vc-svn-rename-file (old new
)
384 (vc-svn-command nil
0 new
"move" (file-relative-name old
)))
386 (defun vc-svn-revert (file &optional contents-done
)
387 "Revert FILE to the version it was based on."
388 (unless contents-done
389 (vc-svn-command nil
0 file
"revert")))
391 (defun vc-svn-merge (file first-version
&optional second-version
)
392 "Merge changes into current working copy of FILE.
393 The changes are between FIRST-VERSION and SECOND-VERSION."
394 (vc-svn-command nil
0 file
396 "-r" (if second-version
397 (concat first-version
":" second-version
)
399 (vc-file-setprop file
'vc-state
'edited
)
400 (with-current-buffer (get-buffer "*vc*")
401 (goto-char (point-min))
402 (if (looking-at "C ")
404 0))) ; signal success
406 (defun vc-svn-merge-news (file)
407 "Merge in any new changes made to FILE."
408 (message "Merging changes into %s..." file
)
409 ;; (vc-file-setprop file 'vc-working-revision nil)
410 (vc-file-setprop file
'vc-checkout-time
0)
411 (vc-svn-command nil
0 file
"update")
412 ;; Analyze the merge result reported by SVN, and set
413 ;; file properties accordingly.
414 (with-current-buffer (get-buffer "*vc*")
415 (goto-char (point-min))
416 ;; get new working revision
417 (if (re-search-forward
418 "^\\(Updated to\\|At\\) revision \\([0-9]+\\)" nil t
)
419 (vc-file-setprop file
'vc-working-revision
(match-string 2))
420 (vc-file-setprop file
'vc-working-revision nil
))
422 (goto-char (point-min))
424 (if (looking-at "At revision")
425 0 ;; there were no news; indicate success
426 (if (re-search-forward
427 ;; Newer SVN clients have 3 columns of chars (one for the
428 ;; file's contents, then second for its properties, and the
429 ;; third for lock-grabbing info), before the 2 spaces.
430 ;; We also used to match the filename in column 0 without any
431 ;; meta-info before it, but I believe this can never happen.
432 (concat "^\\(\\([ACGDU]\\)\\(.[B ]\\)? \\)"
433 (regexp-quote (file-relative-name file
)))
436 ;; Merge successful, we are in sync with repository now
437 ((string= (match-string 2) "U")
438 (vc-file-setprop file
'vc-state
'up-to-date
)
439 (vc-file-setprop file
'vc-checkout-time
440 (nth 5 (file-attributes file
)))
441 0);; indicate success to the caller
442 ;; Merge successful, but our own changes are still in the file
443 ((string= (match-string 2) "G")
444 (vc-file-setprop file
'vc-state
'edited
)
445 0);; indicate success to the caller
446 ;; Conflicts detected!
448 (vc-file-setprop file
'vc-state
'edited
)
449 1);; signal the error to the caller
451 (pop-to-buffer "*vc*")
452 (error "Couldn't analyze svn update result")))
453 (message "Merging changes into %s...done" file
))))
455 (defun vc-svn-modify-change-comment (files rev comment
)
456 "Modify the change comments for a specified REV.
457 You must have ssh access to the repository host, and the directory Emacs
458 uses locally for temp files must also be writable by you on that host.
459 This is only supported if the repository access method is either file://
461 (let (tempfile host remotefile directory fileurl-p
)
463 (vc-svn-command (current-buffer) 0 nil
"info")
464 (goto-char (point-min))
465 (unless (re-search-forward "Repository Root: \\(file://\\(/.*\\)\\)\\|\\(svn\\+ssh://\\([^/]+\\)\\(/.*\\)\\)" nil t
)
466 (error "Repository information is unavailable"))
470 (setq directory
(match-string 2)))
471 (setq host
(match-string 4))
472 (setq directory
(match-string 5))
473 (setq remotefile
(concat host
":" tempfile
))))
474 (with-temp-file (setq tempfile
(make-temp-file user-mail-address
))
477 ;; Repository Root is a local file.
479 (unless (vc-do-command
480 "*vc*" 0 "svnadmin" nil
481 "setlog" "--bypass-hooks" directory
482 "-r" rev
(format "%s" tempfile
))
483 (error "Log edit failed"))
484 (delete-file tempfile
))
486 ;; Remote repository, using svn+ssh.
487 (unless (vc-do-command "*vc*" 0 "scp" nil
"-q" tempfile remotefile
)
488 (error "Copy of comment to %s failed" remotefile
))
489 (unless (vc-do-command
490 "*vc*" 0 "ssh" nil
"-q" host
491 (format "svnadmin setlog --bypass-hooks %s -r %s %s; rm %s"
492 directory rev tempfile tempfile
))
493 (error "Log edit failed")))))
496 ;;; History functions
499 (defvar log-view-per-file-logs
)
501 (define-derived-mode vc-svn-log-view-mode log-view-mode
"SVN-Log-View"
503 (set (make-local-variable 'log-view-per-file-logs
) nil
))
505 (autoload 'vc-setup-buffer
"vc-dispatcher")
507 (defun vc-svn-print-log (files buffer
&optional shortlog start-revision limit
)
508 "Print commit log associated with FILES into specified BUFFER.
510 If START-REVISION is non-nil, it is the newest revision to show.
511 If LIMIT is non-nil, show no more than this many entries."
513 (vc-setup-buffer buffer
)
514 (let ((inhibit-read-only t
))
515 (goto-char (point-min))
518 (insert "Working file: " file
"\n")
523 ;; (if (and (= (length files) 1) (vc-stay-local-p file 'SVN)) 'async 0)
529 (format "-r%s:1" start-revision
)
530 ;; By default Subversion only shows the log up to the
531 ;; working revision, whereas we also want the log of the
532 ;; subsequent commits. At least that's what the
533 ;; vc-cvs.el code does.
535 (when limit
(list "--limit" (format "%s" limit
))))))
536 ;; Dump log for the entire directory.
537 (apply 'vc-svn-command buffer
0 nil
"log"
540 (if start-revision
(format "-r%s" start-revision
) "-rHEAD:0"))
541 (when limit
(list "--limit" (format "%s" limit
)))))))))
543 (defun vc-svn-diff (files &optional oldvers newvers buffer
)
544 "Get a difference report using SVN between two revisions of fileset FILES."
550 (or (equal oldvers
(vc-working-revision f
))
553 ;; Use nil rather than the current revision because svn handles
554 ;; it better (i.e. locally). Note that if _any_ of the files
555 ;; has a different revision, we fetch the lot, which is
556 ;; obviously sub-optimal.
559 (if vc-svn-diff-switches
560 (vc-switches 'SVN
'diff
)
561 (list (concat "--diff-cmd=" diff-command
) "-x"
562 (mapconcat 'identity
(vc-switches nil
'diff
) " "))))
563 (async (and (not vc-disable-async-diff
)
564 (vc-stay-local-p files
'SVN
)
565 (or oldvers newvers
)))) ; Svn diffs those locally.
566 (apply 'vc-svn-command buffer
572 (list "-r" (if newvers
(concat oldvers
":" newvers
)
574 (if async
1 ; async diff => pessimistic assumption
575 ;; For some reason `svn diff' does not return a useful
576 ;; status w.r.t whether the diff was empty or not.
577 (buffer-size (get-buffer buffer
)))))
583 (defun vc-svn-create-tag (dir name branchp
)
584 "Assign to DIR's current revision a given NAME.
585 If BRANCHP is non-nil, the name is created as a branch (and the current
586 workspace is immediately moved to that new branch).
587 NAME is assumed to be a URL."
588 (vc-svn-command nil
0 dir
"copy" name
)
589 (when branchp
(vc-svn-retrieve-tag dir name nil
)))
591 (defun vc-svn-retrieve-tag (dir name update
)
592 "Retrieve a tag at and below DIR.
593 NAME is the name of the tag; if it is empty, do a `svn update'.
594 If UPDATE is non-nil, then update (resynch) any affected buffers.
595 NAME is assumed to be a URL."
596 (vc-svn-command nil
0 dir
"switch" name
)
597 ;; FIXME: parse the output and obey `update'.
604 ;; Subversion makes backups for us, so don't bother.
605 ;; (defun vc-svn-make-version-backups-p (file)
606 ;; "Return non-nil if version backups should be made for FILE."
607 ;; (vc-stay-local-p file 'SVN))
609 (defun vc-svn-check-headers ()
610 "Check if the current file has any headers in it."
612 (goto-char (point-min))
613 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
614 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
618 ;;; Internal functions
621 (defun vc-svn-command (buffer okstatus file-or-list
&rest flags
)
622 "A wrapper around `vc-do-command' for use in vc-svn.el.
623 The difference to vc-do-command is that this function always invokes `svn',
624 and that it passes `vc-svn-global-switches' to it before FLAGS."
625 (apply 'vc-do-command
(or buffer
"*vc*") okstatus vc-svn-program file-or-list
626 (if (stringp vc-svn-global-switches
)
627 (cons vc-svn-global-switches flags
)
628 (append vc-svn-global-switches flags
))))
630 (defun vc-svn-repository-hostname (dirname)
632 (let (process-file-side-effects)
633 (vc-svn-command t t dirname
"info" "--xml"))
634 (goto-char (point-min))
635 (when (re-search-forward "<url>\\(.*\\)</url>" nil t
)
636 ;; This is not a hostname but a URL. This may actually be considered
637 ;; as a feature since it allows vc-svn-stay-local to specify different
638 ;; behavior for different modules on the same server.
641 (defun vc-svn-resolve-when-done ()
642 "Call \"svn resolved\" if the conflict markers have been removed."
644 (goto-char (point-min))
645 (unless (re-search-forward "^<<<<<<< " nil t
)
646 (vc-svn-command nil
0 buffer-file-name
"resolved")
647 ;; Remove the hook so that it is not called multiple times.
648 (remove-hook 'after-save-hook
'vc-svn-resolve-when-done t
))))
650 ;; Inspired by vc-arch-find-file-hook.
651 (defun vc-svn-find-file-hook ()
652 (when (eq ?C
(vc-file-getprop buffer-file-name
'vc-svn-status
))
653 ;; If the file is marked as "conflicted", then we should try and call
654 ;; "svn resolved" when applicable.
656 (goto-char (point-min))
657 (re-search-forward "^<<<<<<< " nil t
))
658 ;; There are conflict markers.
660 (smerge-start-session)
661 (add-hook 'after-save-hook
'vc-svn-resolve-when-done nil t
))
662 ;; There are no conflict markers. This is problematic: maybe it means
663 ;; the conflict has been resolved and we should immediately call "svn
664 ;; resolved", or it means that the file's type does not allow Svn to
665 ;; use conflict markers in which case we don't really know what to do.
666 ;; So let's just punt for now.
668 (message "There are unresolved conflicts in this file")))
670 (defun vc-svn-parse-status (&optional filename
)
671 "Parse output of \"svn status\" command in the current buffer.
672 Set file properties accordingly. Unless FILENAME is non-nil, parse only
673 information about FILENAME and return its status."
674 (let (file status propstat
)
675 (goto-char (point-min))
676 (while (re-search-forward
677 ;; Ignore the files with status X.
678 "^\\(?:\\?\\|[ ACDGIMR!~][ MC][ L][ +][ S]..\\([ *]\\) +\\([-0-9]+\\) +\\([0-9?]+\\) +\\([^ ]+\\)\\) +" nil t
)
679 ;; If the username contains spaces, the output format is ambiguous,
680 ;; so don't trust the output's filename unless we have to.
681 (setq file
(or filename
683 (buffer-substring (point) (line-end-position)))))
684 (setq status
(char-after (line-beginning-position))
685 ;; Status of the item's properties ([ MC]).
686 propstat
(char-after (1+ (line-beginning-position))))
688 (vc-file-setprop file
'vc-state
'unregistered
)
689 ;; Use the last-modified revision, so that searching in vc-print-log
691 (vc-file-setprop file
'vc-working-revision
(match-string 3))
692 ;; Remember Svn's own status.
693 (vc-file-setprop file
'vc-svn-status status
)
697 ((and (eq status ?\
) (eq propstat ?\
))
698 (if (eq (char-after (match-beginning 1)) ?
*)
700 (vc-file-setprop file
'vc-checkout-time
701 (nth 5 (file-attributes file
)))
704 ;; If the file was actually copied, (match-string 2) is "-".
705 (vc-file-setprop file
'vc-working-revision
"0")
706 (vc-file-setprop file
'vc-checkout-time
0)
708 ;; Conflict in contents or properties.
709 ((or (eq status ?C
) (eq propstat ?C
))
710 (vc-file-setprop file
'vc-state
'conflict
))
711 ;; Modified contents or properties.
712 ((or (eq status ?M
) (eq propstat ?M
))
713 (if (eq (char-after (match-beginning 1)) ?
*)
717 (vc-file-setprop file
'vc-state
'ignored
))
718 ((memq status
'(?D ?R
))
719 (vc-file-setprop file
'vc-state
'removed
))
721 (when filename
(vc-file-getprop filename
'vc-state
))))
723 (defun vc-svn-valid-symbolic-tag-name-p (tag)
724 "Return non-nil if TAG is a valid symbolic tag name."
725 ;; According to the SVN manual, a valid symbolic tag must start with
726 ;; an uppercase or lowercase letter and can contain uppercase and
727 ;; lowercase letters, digits, `-', and `_'.
728 (and (string-match "^[a-zA-Z]" tag
)
729 (not (string-match "[^a-z0-9A-Z-_]" tag
))))
731 (defun vc-svn-valid-revision-number-p (tag)
732 "Return non-nil if TAG is a valid revision number."
733 (and (string-match "^[0-9]" tag
)
734 (not (string-match "[^0-9]" tag
))))
736 ;; Support for `svn annotate'
738 (defun vc-svn-annotate-command (file buf
&optional rev
)
739 (vc-svn-command buf
'async file
"annotate" (if rev
(concat "-r" rev
))))
741 (defun vc-svn-annotate-time-of-rev (rev)
742 ;; Arbitrarily assume 10 commits per day.
743 (/ (string-to-number rev
) 10.0))
745 (defvar vc-annotate-parent-rev
)
747 (defun vc-svn-annotate-current-time ()
748 (vc-svn-annotate-time-of-rev vc-annotate-parent-rev
))
750 (defconst vc-svn-annotate-re
"[ \t]*\\([0-9]+\\)[ \t]+[^\t ]+ ")
752 (defun vc-svn-annotate-time ()
753 (when (looking-at vc-svn-annotate-re
)
754 (goto-char (match-end 0))
755 (vc-svn-annotate-time-of-rev (match-string 1))))
757 (defun vc-svn-annotate-extract-revision-at-line ()
760 (if (looking-at vc-svn-annotate-re
) (match-string 1))))
762 (defun vc-svn-revision-table (files)
763 (let ((vc-svn-revisions '()))
764 (with-current-buffer "*vc*"
765 (vc-svn-command nil
0 files
"log" "-q")
766 (goto-char (point-min))
768 (let ((start (point-min))
769 (loglines (buffer-substring-no-properties (point-min)
771 (while (string-match "^r\\([0-9]+\\) " loglines
)
772 (push (match-string 1 loglines
) vc-svn-revisions
)
773 (setq start
(+ start
(match-end 0)))
774 (setq loglines
(buffer-substring-no-properties start
(point-max)))))
779 ;;; vc-svn.el ends here