]> code.delx.au - gnu-emacs/blob - lisp/vc-svn.el
* completion.el (add-completion-to-head, add-completion): Doc fixes.
[gnu-emacs] / lisp / vc-svn.el
1 ;;; vc-svn.el --- non-resident support for Subversion version-control
2
3 ;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
4 ;; Free Software Foundation, Inc.
5
6 ;; Author: FSF (see vc.el for full credits)
7 ;; Maintainer: Stefan Monnier <monnier@gnu.org>
8
9 ;; This file is part of GNU Emacs.
10
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.
15
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.
20
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/>.
23
24 ;;; Commentary:
25
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.
28
29 ;;; Code:
30
31 (eval-when-compile
32 (require 'vc))
33
34 ;;;
35 ;;; Customization options
36 ;;;
37
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)
47
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)
59
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)
73
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)
79
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.")
90
91 ;;; Properties of the backend
92
93 (defun vc-svn-revision-granularity () 'repository)
94 (defun vc-svn-checkout-model (files) 'implicit)
95
96 ;;;
97 ;;; State-querying functions
98 ;;;
99
100 ;;; vc-svn-admin-directory is generally not defined when the
101 ;;; autoloaded function is called.
102
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))))
113
114 ;;;###autoload
115 (add-to-list 'completion-ignored-extensions ".svn/")
116
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))))))))))
137
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)))
145
146 (defun vc-svn-state-heuristic (file)
147 "SVN-specific state heuristic."
148 (vc-svn-state file 'local))
149
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)))
177
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))))
189
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))))
194
195 (defun vc-svn-status-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 "")))))
211
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))
219
220 ;; vc-svn-mode-line-string doesn't exist because the default implementation
221 ;; works just fine.
222
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))))
227
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))))
239
240
241 ;;;
242 ;;; State-changing functions
243 ;;;
244
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")))
250
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.
254
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)))
258
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)))))
265
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.")
269
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"))))
287 (t
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))
296 ))
297
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)))
306
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))
313
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.
317 nil
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)))
327
328 (defun vc-svn-delete-file (file)
329 (vc-svn-command nil 0 file "remove"))
330
331 (defun vc-svn-rename-file (old new)
332 (vc-svn-command nil 0 new "move" (file-relative-name old)))
333
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")))
338
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
353
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!
395 (t
396 (vc-file-setprop file 'vc-state 'edited)
397 1);; signal the error to the caller
398 )
399 (pop-to-buffer "*vc*")
400 (error "Couldn't analyze svn update result")))
401 (message "Merging changes into %s...done" file))))
402
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))
433
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")))))
442
443 ;;;
444 ;;; History functions
445 ;;;
446
447 (defvar log-view-per-file-logs)
448
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))
452
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")))))
475
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 (catch 'no
480 (dolist (f files)
481 (or (equal oldvers (vc-working-revision f))
482 (throw 'no nil)))
483 t)
484 ;; Use nil rather than the current revision because svn handles
485 ;; it better (i.e. locally). Note that if _any_ of the files
486 ;; has a different revision, we fetch the lot, which is
487 ;; obviously sub-optimal.
488 (setq oldvers nil))
489 (let* ((switches
490 (if vc-svn-diff-switches
491 (vc-switches 'SVN 'diff)
492 (list "-x" (mapconcat 'identity (vc-switches nil 'diff) " "))))
493 (async (and (not vc-disable-async-diff)
494 (vc-stay-local-p files)
495 (or oldvers newvers)))) ; Svn diffs those locally.
496 (apply 'vc-svn-command buffer
497 (if async 'async 0)
498 files "diff"
499 (append
500 switches
501 (when oldvers
502 (list "-r" (if newvers (concat oldvers ":" newvers)
503 oldvers)))))
504 (if async 1 ; async diff => pessimistic assumption
505 ;; For some reason `svn diff' does not return a useful
506 ;; status w.r.t whether the diff was empty or not.
507 (buffer-size (get-buffer buffer)))))
508
509 ;;;
510 ;;; Tag system
511 ;;;
512
513 (defun vc-svn-create-tag (dir name branchp)
514 "Assign to DIR's current revision a given NAME.
515 If BRANCHP is non-nil, the name is created as a branch (and the current
516 workspace is immediately moved to that new branch).
517 NAME is assumed to be a URL."
518 (vc-svn-command nil 0 dir "copy" name)
519 (when branchp (vc-svn-retrieve-tag dir name nil)))
520
521 (defun vc-svn-retrieve-tag (dir name update)
522 "Retrieve a tag at and below DIR.
523 NAME is the name of the tag; if it is empty, do a `svn update'.
524 If UPDATE is non-nil, then update (resynch) any affected buffers.
525 NAME is assumed to be a URL."
526 (vc-svn-command nil 0 dir "switch" name)
527 ;; FIXME: parse the output and obey `update'.
528 )
529
530 ;;;
531 ;;; Miscellaneous
532 ;;;
533
534 ;; Subversion makes backups for us, so don't bother.
535 ;; (defalias 'vc-svn-make-version-backups-p 'vc-stay-local-p
536 ;; "Return non-nil if version backups should be made for FILE.")
537
538 (defun vc-svn-check-headers ()
539 "Check if the current file has any headers in it."
540 (save-excursion
541 (goto-char (point-min))
542 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
543 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
544
545
546 ;;;
547 ;;; Internal functions
548 ;;;
549
550 (defcustom vc-svn-program "svn"
551 "Name of the SVN executable."
552 :type 'string
553 :group 'vc)
554
555 (defun vc-svn-command (buffer okstatus file-or-list &rest flags)
556 "A wrapper around `vc-do-command' for use in vc-svn.el.
557 The difference to vc-do-command is that this function always invokes `svn',
558 and that it passes `vc-svn-global-switches' to it before FLAGS."
559 (apply 'vc-do-command (or buffer "*vc*") okstatus vc-svn-program file-or-list
560 (if (stringp vc-svn-global-switches)
561 (cons vc-svn-global-switches flags)
562 (append vc-svn-global-switches
563 flags))))
564
565 (defun vc-svn-repository-hostname (dirname)
566 (with-temp-buffer
567 (let ((coding-system-for-read
568 (or file-name-coding-system
569 default-file-name-coding-system)))
570 (vc-insert-file (expand-file-name (concat vc-svn-admin-directory
571 "/entries")
572 dirname)))
573 (goto-char (point-min))
574 (when (re-search-forward
575 ;; Old `svn' used name="svn:this_dir", newer use just name="".
576 (concat "name=\"\\(?:svn:this_dir\\)?\"[\n\t ]*"
577 "\\(?:[-a-z]+=\"[^\"]*\"[\n\t ]*\\)*?"
578 "url=\"\\(?1:[^\"]+\\)\""
579 ;; Yet newer ones don't use XML any more.
580 "\\|^\ndir\n[0-9]+\n\\(?1:.*\\)") nil t)
581 ;; This is not a hostname but a URL. This may actually be considered
582 ;; as a feature since it allows vc-svn-stay-local to specify different
583 ;; behavior for different modules on the same server.
584 (match-string 1))))
585
586 (defun vc-svn-resolve-when-done ()
587 "Call \"svn resolved\" if the conflict markers have been removed."
588 (save-excursion
589 (goto-char (point-min))
590 (unless (re-search-forward "^<<<<<<< " nil t)
591 (vc-svn-command nil 0 buffer-file-name "resolved")
592 ;; Remove the hook so that it is not called multiple times.
593 (remove-hook 'after-save-hook 'vc-svn-resolve-when-done t))))
594
595 ;; Inspired by vc-arch-find-file-hook.
596 (defun vc-svn-find-file-hook ()
597 (when (eq ?C (vc-file-getprop buffer-file-name 'vc-svn-status))
598 ;; If the file is marked as "conflicted", then we should try and call
599 ;; "svn resolved" when applicable.
600 (if (save-excursion
601 (goto-char (point-min))
602 (re-search-forward "^<<<<<<< " nil t))
603 ;; There are conflict markers.
604 (progn
605 (smerge-start-session)
606 (add-hook 'after-save-hook 'vc-svn-resolve-when-done nil t))
607 ;; There are no conflict markers. This is problematic: maybe it means
608 ;; the conflict has been resolved and we should immediately call "svn
609 ;; resolved", or it means that the file's type does not allow Svn to
610 ;; use conflict markers in which case we don't really know what to do.
611 ;; So let's just punt for now.
612 nil)
613 (message "There are unresolved conflicts in this file")))
614
615 (defun vc-svn-parse-status (&optional filename)
616 "Parse output of \"svn status\" command in the current buffer.
617 Set file properties accordingly. Unless FILENAME is non-nil, parse only
618 information about FILENAME and return its status."
619 (let (file status)
620 (goto-char (point-min))
621 (while (re-search-forward
622 ;; Ignore the files with status X.
623 "^\\(?:\\?\\|[ ACDGIMR!~][ MC][ L][ +][ S]..\\([ *]\\) +\\([-0-9]+\\) +\\([0-9?]+\\) +\\([^ ]+\\)\\) +" nil t)
624 ;; If the username contains spaces, the output format is ambiguous,
625 ;; so don't trust the output's filename unless we have to.
626 (setq file (or filename
627 (expand-file-name
628 (buffer-substring (point) (line-end-position)))))
629 (setq status (char-after (line-beginning-position)))
630 (if (eq status ??)
631 (vc-file-setprop file 'vc-state 'unregistered)
632 ;; Use the last-modified revision, so that searching in vc-print-log
633 ;; output works.
634 (vc-file-setprop file 'vc-working-revision (match-string 3))
635 ;; Remember Svn's own status.
636 (vc-file-setprop file 'vc-svn-status status)
637 (vc-file-setprop
638 file 'vc-state
639 (cond
640 ((eq status ?\ )
641 (if (eq (char-after (match-beginning 1)) ?*)
642 'needs-update
643 (vc-file-setprop file 'vc-checkout-time
644 (nth 5 (file-attributes file)))
645 'up-to-date))
646 ((eq status ?A)
647 ;; If the file was actually copied, (match-string 2) is "-".
648 (vc-file-setprop file 'vc-working-revision "0")
649 (vc-file-setprop file 'vc-checkout-time 0)
650 'added)
651 ((eq status ?C)
652 (vc-file-setprop file 'vc-state 'conflict))
653 ((eq status '?M)
654 (if (eq (char-after (match-beginning 1)) ?*)
655 'needs-merge
656 'edited))
657 ((eq status ?I)
658 (vc-file-setprop file 'vc-state 'ignored))
659 ((eq status ?R)
660 (vc-file-setprop file 'vc-state 'removed))
661 (t 'edited)))))
662 (when filename (vc-file-getprop filename 'vc-state))))
663
664 (defun vc-svn-valid-symbolic-tag-name-p (tag)
665 "Return non-nil if TAG is a valid symbolic tag name."
666 ;; According to the SVN manual, a valid symbolic tag must start with
667 ;; an uppercase or lowercase letter and can contain uppercase and
668 ;; lowercase letters, digits, `-', and `_'.
669 (and (string-match "^[a-zA-Z]" tag)
670 (not (string-match "[^a-z0-9A-Z-_]" tag))))
671
672 (defun vc-svn-valid-revision-number-p (tag)
673 "Return non-nil if TAG is a valid revision number."
674 (and (string-match "^[0-9]" tag)
675 (not (string-match "[^0-9]" tag))))
676
677 ;; Support for `svn annotate'
678
679 (defun vc-svn-annotate-command (file buf &optional rev)
680 (vc-svn-command buf 0 file "annotate" (if rev (concat "-r" rev))))
681
682 (defun vc-svn-annotate-time-of-rev (rev)
683 ;; Arbitrarily assume 10 commmits per day.
684 (/ (string-to-number rev) 10.0))
685
686 (defvar vc-annotate-parent-rev)
687
688 (defun vc-svn-annotate-current-time ()
689 (vc-svn-annotate-time-of-rev vc-annotate-parent-rev))
690
691 (defconst vc-svn-annotate-re "[ \t]*\\([0-9]+\\)[ \t]+[^\t ]+ ")
692
693 (defun vc-svn-annotate-time ()
694 (when (looking-at vc-svn-annotate-re)
695 (goto-char (match-end 0))
696 (vc-svn-annotate-time-of-rev (match-string 1))))
697
698 (defun vc-svn-annotate-extract-revision-at-line ()
699 (save-excursion
700 (beginning-of-line)
701 (if (looking-at vc-svn-annotate-re) (match-string 1))))
702
703 (provide 'vc-svn)
704
705 ;; arch-tag: 02f10c68-2b4d-453a-90fc-1eee6cfb268d
706 ;;; vc-svn.el ends here