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