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