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