Commit | Line | Data |
---|---|---|
1fd3454a SM |
1 | ;;; vc-svn.el --- non-resident support for Subversion version-control |
2 | ||
c45b3be3 | 3 | ;; Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
1fd3454a SM |
4 | |
5 | ;; Author: FSF (see vc.el for full credits) | |
6 | ;; Maintainer: Stefan Monnier <monnier@gnu.org> | |
7 | ||
8 | ;; This file is part of GNU Emacs. | |
9 | ||
10 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 | ;; it under the terms of the GNU General Public License as published by | |
b4aa6026 | 12 | ;; the Free Software Foundation; either version 3, or (at your option) |
1fd3454a SM |
13 | ;; any later version. |
14 | ||
15 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
21 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
086add15 LK |
22 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 | ;; Boston, MA 02110-1301, USA. | |
1fd3454a SM |
24 | |
25 | ;;; Commentary: | |
26 | ||
f9914e54 ER |
27 | ;; Sync'd with Subversion's vc-svn.el as of revision 5801. but this version |
28 | ;; has been extensively modified since to handle filesets. | |
1fd3454a | 29 | |
1fd3454a SM |
30 | ;;; Code: |
31 | ||
32 | (eval-when-compile | |
33 | (require 'vc)) | |
34 | ||
35 | ;;; | |
36 | ;;; Customization options | |
37 | ;;; | |
38 | ||
39 | (defcustom vc-svn-global-switches nil | |
40 | "*Global switches to pass to any SVN command." | |
41 | :type '(choice (const :tag "None" nil) | |
42 | (string :tag "Argument String") | |
43 | (repeat :tag "Argument List" | |
44 | :value ("") | |
45 | string)) | |
bf247b6e | 46 | :version "22.1" |
1fd3454a SM |
47 | :group 'vc) |
48 | ||
49 | (defcustom vc-svn-register-switches nil | |
50 | "*Extra switches for registering a file into SVN. | |
51 | A string or list of strings passed to the checkin program by | |
52 | \\[vc-register]." | |
53 | :type '(choice (const :tag "None" nil) | |
54 | (string :tag "Argument String") | |
55 | (repeat :tag "Argument List" | |
56 | :value ("") | |
57 | string)) | |
bf247b6e | 58 | :version "22.1" |
1fd3454a SM |
59 | :group 'vc) |
60 | ||
8462aca5 SM |
61 | (defcustom vc-svn-diff-switches |
62 | t ;`svn' doesn't support common args like -c or -b. | |
63 | "String or list of strings specifying extra switches for svn diff under VC. | |
64 | If nil, use the value of `vc-diff-switches'. | |
65 | If you want to force an empty list of arguments, use t." | |
66 | :type '(choice (const :tag "Unspecified" nil) | |
67 | (const :tag "None" t) | |
1fd3454a SM |
68 | (string :tag "Argument String") |
69 | (repeat :tag "Argument List" | |
70 | :value ("") | |
71 | string)) | |
bf247b6e | 72 | :version "22.1" |
1fd3454a SM |
73 | :group 'vc) |
74 | ||
75 | (defcustom vc-svn-header (or (cdr (assoc 'SVN vc-header-alist)) '("\$Id\$")) | |
76 | "*Header keywords to be inserted by `vc-insert-headers'." | |
bf247b6e | 77 | :version "22.1" |
1fd3454a SM |
78 | :type '(repeat string) |
79 | :group 'vc) | |
80 | ||
fc2fb30c SM |
81 | ;; We want to autoload it for use by the autoloaded version of |
82 | ;; vc-svn-registered, but we want the value to be compiled at startup, not | |
83 | ;; at dump time. | |
84 | ;; ;;;###autoload | |
85 | (defconst vc-svn-admin-directory | |
86 | (cond ((and (memq system-type '(cygwin windows-nt ms-dos)) | |
ace2fad9 CY |
87 | (getenv "SVN_ASP_DOT_NET_HACK")) |
88 | "_svn") | |
89 | (t ".svn")) | |
90 | "The name of the \".svn\" subdirectory or its equivalent.") | |
91 | ||
8cdd17b4 ER |
92 | ;;; Properties of the backend |
93 | ||
94 | (defun vc-svn-revision-granularity () | |
95 | 'repository) | |
1fd3454a SM |
96 | ;;; |
97 | ;;; State-querying functions | |
98 | ;;; | |
99 | ||
ace2fad9 CY |
100 | ;;; vc-svn-admin-directory is generally not defined when the |
101 | ;;; autoloaded function is called. | |
102 | ||
1fd3454a | 103 | ;;;###autoload (defun vc-svn-registered (f) |
ace2fad9 | 104 | ;;;###autoload (let ((admin-dir (cond ((and (eq system-type 'windows-nt) |
fc2fb30c SM |
105 | ;;;###autoload (getenv "SVN_ASP_DOT_NET_HACK")) |
106 | ;;;###autoload "_svn") | |
107 | ;;;###autoload (t ".svn")))) | |
ace2fad9 | 108 | ;;;###autoload (when (file-readable-p (expand-file-name |
fc2fb30c SM |
109 | ;;;###autoload (concat admin-dir "/entries") |
110 | ;;;###autoload (file-name-directory f))) | |
1fd3454a | 111 | ;;;###autoload (load "vc-svn") |
ace2fad9 | 112 | ;;;###autoload (vc-svn-registered f)))) |
1fd3454a | 113 | |
3bdc13e4 SM |
114 | ;;;###autoload |
115 | (add-to-list 'completion-ignored-extensions ".svn/") | |
116 | ||
1fd3454a SM |
117 | (defun vc-svn-registered (file) |
118 | "Check if FILE is SVN registered." | |
ace2fad9 CY |
119 | (when (file-readable-p (expand-file-name (concat vc-svn-admin-directory |
120 | "/entries") | |
1fd3454a SM |
121 | (file-name-directory file))) |
122 | (with-temp-buffer | |
123 | (cd (file-name-directory file)) | |
aaef169d | 124 | (let ((status |
df4da7f4 SM |
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) | |
bc8c1bb4 | 135 | (vc-svn-parse-status file)))))) |
1fd3454a SM |
136 | |
137 | (defun vc-svn-state (file &optional localp) | |
138 | "SVN-specific version of `vc-state'." | |
7ffc77d3 | 139 | (setq localp (or localp (vc-stay-local-p file))) |
1fd3454a SM |
140 | (with-temp-buffer |
141 | (cd (file-name-directory file)) | |
142 | (vc-svn-command t 0 file "status" (if localp "-v" "-u")) | |
bc8c1bb4 | 143 | (vc-svn-parse-status file))) |
1fd3454a SM |
144 | |
145 | (defun vc-svn-state-heuristic (file) | |
146 | "SVN-specific state heuristic." | |
147 | (vc-svn-state file 'local)) | |
148 | ||
149 | (defun vc-svn-dir-state (dir &optional localp) | |
cdce374a | 150 | "Find the SVN state of all files in DIR and its subdirectories." |
7ffc77d3 | 151 | (setq localp (or localp (vc-stay-local-p dir))) |
1fd3454a SM |
152 | (let ((default-directory dir)) |
153 | ;; Don't specify DIR in this command, the default-directory is | |
154 | ;; enough. Otherwise it might fail with remote repositories. | |
155 | (with-temp-buffer | |
156 | (vc-svn-command t 0 nil "status" (if localp "-v" "-u")) | |
bc8c1bb4 | 157 | (vc-svn-parse-status)))) |
1fd3454a | 158 | |
ac3f4c6f ER |
159 | (defun vc-svn-working-revision (file) |
160 | "SVN-specific version of `vc-working-revision'." | |
1fd3454a SM |
161 | ;; There is no need to consult RCS headers under SVN, because we |
162 | ;; get the workfile version for free when we recognize that a file | |
163 | ;; is registered in SVN. | |
164 | (vc-svn-registered file) | |
ac3f4c6f | 165 | (vc-file-getprop file 'vc-working-revision)) |
1fd3454a SM |
166 | |
167 | (defun vc-svn-checkout-model (file) | |
168 | "SVN-specific version of `vc-checkout-model'." | |
169 | ;; It looks like Subversion has no equivalent of CVSREAD. | |
170 | 'implicit) | |
171 | ||
5cc7cb96 SM |
172 | ;; vc-svn-mode-line-string doesn't exist because the default implementation |
173 | ;; works just fine. | |
174 | ||
1fd3454a SM |
175 | (defun vc-svn-dired-state-info (file) |
176 | "SVN-specific version of `vc-dired-state-info'." | |
fd140743 SM |
177 | (let ((svn-state (vc-state file))) |
178 | (cond ((eq svn-state 'edited) | |
ac3f4c6f | 179 | (if (equal (vc-working-revision file) "0") |
fd140743 SM |
180 | "(added)" "(modified)")) |
181 | ((eq svn-state 'needs-patch) "(patch)") | |
182 | ((eq svn-state 'needs-merge) "(merge)")))) | |
1fd3454a | 183 | |
5b5afd50 | 184 | (defun vc-svn-previous-revision (file rev) |
cbbd2cd3 TTN |
185 | (let ((newrev (1- (string-to-number rev)))) |
186 | (when (< 0 newrev) | |
187 | (number-to-string newrev)))) | |
188 | ||
5b5afd50 | 189 | (defun vc-svn-next-revision (file rev) |
cbbd2cd3 | 190 | (let ((newrev (1+ (string-to-number rev)))) |
5b5afd50 | 191 | ;; The "working revision" is an uneasy conceptual fit under Subversion; |
cbbd2cd3 TTN |
192 | ;; we use it as the upper bound until a better idea comes along. If the |
193 | ;; workfile version W coincides with the tree's latest revision R, then | |
194 | ;; this check prevents a "no such revision: R+1" error. Otherwise, it | |
195 | ;; inhibits showing of W+1 through R, which could be considered anywhere | |
196 | ;; from gracious to impolite. | |
ac3f4c6f | 197 | (unless (< (string-to-number (vc-file-getprop file 'vc-working-revision)) |
cbbd2cd3 TTN |
198 | newrev) |
199 | (number-to-string newrev)))) | |
200 | ||
1fd3454a SM |
201 | |
202 | ;;; | |
203 | ;;; State-changing functions | |
204 | ;;; | |
205 | ||
8cdd17b4 ER |
206 | (defun vc-svn-create-repo () |
207 | "Create a new SVN repository." | |
208 | (vc-do-command nil 0 "svnadmin" '("create" "SVN")) | |
209 | (vc-do-command nil 0 "svn" '(".") | |
210 | "checkout" (concat "file://" default-directory "SVN"))) | |
211 | ||
212 | (defun vc-svn-register (files &optional rev comment) | |
213 | "Register FILES into the SVN version-control system. | |
214 | The COMMENT argument is ignored This does an add but not a commit. | |
1fd3454a SM |
215 | |
216 | `vc-register-switches' and `vc-svn-register-switches' are passed to | |
217 | the SVN command (in that order)." | |
8cdd17b4 | 218 | (apply 'vc-svn-command nil 0 files "add" (vc-switches 'SVN 'register))) |
1fd3454a SM |
219 | |
220 | (defun vc-svn-responsible-p (file) | |
221 | "Return non-nil if SVN thinks it is responsible for FILE." | |
ace2fad9 | 222 | (file-directory-p (expand-file-name vc-svn-admin-directory |
1fd3454a SM |
223 | (if (file-directory-p file) |
224 | file | |
225 | (file-name-directory file))))) | |
226 | ||
227 | (defalias 'vc-svn-could-register 'vc-svn-responsible-p | |
228 | "Return non-nil if FILE could be registered in SVN. | |
229 | This is only possible if SVN is responsible for FILE's directory.") | |
230 | ||
8cdd17b4 | 231 | (defun vc-svn-checkin (files rev comment) |
1fd3454a | 232 | "SVN-specific version of `vc-backend-checkin'." |
8cdd17b4 | 233 | (if rev (error "Committing to a specific revision is unsupported in SVN.")) |
5129f10c | 234 | (let ((status (apply |
8cdd17b4 | 235 | 'vc-svn-command nil 1 files "ci" |
5129f10c | 236 | (nconc (list "-m" comment) (vc-switches 'SVN 'checkin))))) |
1fd3454a SM |
237 | (set-buffer "*vc*") |
238 | (goto-char (point-min)) | |
239 | (unless (equal status 0) | |
240 | ;; Check checkin problem. | |
241 | (cond | |
fd140743 | 242 | ((search-forward "Transaction is out of date" nil t) |
8cdd17b4 ER |
243 | (mapc (lambda (file) (vc-file-setprop file 'vc-state 'needs-merge)) |
244 | files) | |
1fd3454a SM |
245 | (error (substitute-command-keys |
246 | (concat "Up-to-date check failed: " | |
247 | "type \\[vc-next-action] to merge in changes")))) | |
248 | (t | |
249 | (pop-to-buffer (current-buffer)) | |
250 | (goto-char (point-min)) | |
251 | (shrink-window-if-larger-than-buffer) | |
252 | (error "Check-in failed")))) | |
253 | ;; Update file properties | |
254 | ;; (vc-file-setprop | |
ac3f4c6f | 255 | ;; file 'vc-working-revision |
1fd3454a SM |
256 | ;; (vc-parse-buffer "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" 2)) |
257 | )) | |
258 | ||
ac3f4c6f | 259 | (defun vc-svn-find-revision (file rev buffer) |
8cdd17b4 | 260 | "SVN-specific retrieval of a specified version into a buffer." |
1fd3454a SM |
261 | (apply 'vc-svn-command |
262 | buffer 0 file | |
263 | "cat" | |
264 | (and rev (not (string= rev "")) | |
265 | (concat "-r" rev)) | |
fd140743 | 266 | (vc-switches 'SVN 'checkout))) |
1fd3454a SM |
267 | |
268 | (defun vc-svn-checkout (file &optional editable rev) | |
269 | (message "Checking out %s..." file) | |
270 | (with-current-buffer (or (get-file-buffer file) (current-buffer)) | |
fd140743 | 271 | (vc-call update file editable rev (vc-switches 'SVN 'checkout))) |
1fd3454a SM |
272 | (vc-mode-line file) |
273 | (message "Checking out %s...done" file)) | |
274 | ||
275 | (defun vc-svn-update (file editable rev switches) | |
276 | (if (and (file-exists-p file) (not rev)) | |
fc2fb30c SM |
277 | ;; If no revision was specified, there's nothing to do. |
278 | nil | |
1fd3454a | 279 | ;; Check out a particular version (or recreate the file). |
ac3f4c6f | 280 | (vc-file-setprop file 'vc-working-revision nil) |
1fd3454a | 281 | (apply 'vc-svn-command nil 0 file |
1fd3454a SM |
282 | "update" |
283 | ;; default for verbose checkout: clear the sticky tag so | |
284 | ;; that the actual update will get the head of the trunk | |
5cc7cb96 SM |
285 | (cond |
286 | ((null rev) "-rBASE") | |
287 | ((or (eq rev t) (equal rev "")) nil) | |
288 | (t (concat "-r" rev))) | |
1fd3454a SM |
289 | switches))) |
290 | ||
3bdc13e4 SM |
291 | (defun vc-svn-delete-file (file) |
292 | (vc-svn-command nil 0 file "remove")) | |
293 | ||
2766aaaf SM |
294 | (defun vc-svn-rename-file (old new) |
295 | (vc-svn-command nil 0 new "move" (file-relative-name old))) | |
296 | ||
1fd3454a SM |
297 | (defun vc-svn-revert (file &optional contents-done) |
298 | "Revert FILE to the version it was based on." | |
299 | (unless contents-done | |
fc2fb30c | 300 | (vc-svn-command nil 0 file "revert"))) |
1fd3454a SM |
301 | |
302 | (defun vc-svn-merge (file first-version &optional second-version) | |
303 | "Merge changes into current working copy of FILE. | |
304 | The changes are between FIRST-VERSION and SECOND-VERSION." | |
305 | (vc-svn-command nil 0 file | |
c217cb04 | 306 | "merge" |
02610d0e | 307 | "-r" (if second-version |
c217cb04 SM |
308 | (concat first-version ":" second-version) |
309 | first-version)) | |
1fd3454a SM |
310 | (vc-file-setprop file 'vc-state 'edited) |
311 | (with-current-buffer (get-buffer "*vc*") | |
312 | (goto-char (point-min)) | |
c217cb04 SM |
313 | (if (looking-at "C ") |
314 | 1 ; signal conflict | |
1fd3454a SM |
315 | 0))) ; signal success |
316 | ||
317 | (defun vc-svn-merge-news (file) | |
318 | "Merge in any new changes made to FILE." | |
319 | (message "Merging changes into %s..." file) | |
ac3f4c6f | 320 | ;; (vc-file-setprop file 'vc-working-revision nil) |
1fd3454a SM |
321 | (vc-file-setprop file 'vc-checkout-time 0) |
322 | (vc-svn-command nil 0 file "update") | |
323 | ;; Analyze the merge result reported by SVN, and set | |
324 | ;; file properties accordingly. | |
325 | (with-current-buffer (get-buffer "*vc*") | |
326 | (goto-char (point-min)) | |
5b5afd50 | 327 | ;; get new working revision |
1fd3454a | 328 | (if (re-search-forward |
1468d754 | 329 | "^\\(Updated to\\|At\\) revision \\([0-9]+\\)" nil t) |
ac3f4c6f ER |
330 | (vc-file-setprop file 'vc-working-revision (match-string 2)) |
331 | (vc-file-setprop file 'vc-working-revision nil)) | |
1fd3454a | 332 | ;; get file status |
1468d754 | 333 | (goto-char (point-min)) |
1fd3454a | 334 | (prog1 |
1468d754 | 335 | (if (looking-at "At revision") |
1fd3454a SM |
336 | 0 ;; there were no news; indicate success |
337 | (if (re-search-forward | |
459b1fe4 SM |
338 | ;; Newer SVN clients have 3 columns of chars (one for the |
339 | ;; file's contents, then second for its properties, and the | |
340 | ;; third for lock-grabbing info), before the 2 spaces. | |
341 | ;; We also used to match the filename in column 0 without any | |
342 | ;; meta-info before it, but I believe this can never happen. | |
343 | (concat "^\\(\\([ACGDU]\\)\\(.[B ]\\)? \\)" | |
1468d754 | 344 | (regexp-quote (file-name-nondirectory file))) |
1fd3454a SM |
345 | nil t) |
346 | (cond | |
347 | ;; Merge successful, we are in sync with repository now | |
459b1fe4 | 348 | ((string= (match-string 2) "U") |
1fd3454a SM |
349 | (vc-file-setprop file 'vc-state 'up-to-date) |
350 | (vc-file-setprop file 'vc-checkout-time | |
351 | (nth 5 (file-attributes file))) | |
352 | 0);; indicate success to the caller | |
353 | ;; Merge successful, but our own changes are still in the file | |
459b1fe4 | 354 | ((string= (match-string 2) "G") |
1fd3454a SM |
355 | (vc-file-setprop file 'vc-state 'edited) |
356 | 0);; indicate success to the caller | |
357 | ;; Conflicts detected! | |
358 | (t | |
359 | (vc-file-setprop file 'vc-state 'edited) | |
360 | 1);; signal the error to the caller | |
361 | ) | |
362 | (pop-to-buffer "*vc*") | |
363 | (error "Couldn't analyze svn update result"))) | |
364 | (message "Merging changes into %s...done" file)))) | |
365 | ||
366 | ||
367 | ;;; | |
368 | ;;; History functions | |
369 | ;;; | |
370 | ||
8cdd17b4 ER |
371 | (defun vc-svn-print-log (files &optional buffer) |
372 | "Get change log(s) associated with FILES." | |
1fd3454a | 373 | (save-current-buffer |
b349012b | 374 | (vc-setup-buffer buffer) |
1fd3454a SM |
375 | (let ((inhibit-read-only t)) |
376 | (goto-char (point-min)) | |
377 | ;; Add a line to tell log-view-mode what file this is. | |
ad70e472 GM |
378 | ;; FIXME if there are multiple files, log-view-current-file |
379 | ;; breaks. It's trivial to adapt log-view-file-re for the | |
380 | ;; changed prefix, but less trivial to make | |
381 | ;; log-view-current-file actually do the right thing in the | |
382 | ;; multiple file case. | |
383 | (insert (format "Working file%s: " | |
384 | (if (= (length files) 1) | |
385 | "" | |
386 | "s")) | |
387 | (vc-delistify (mapcar 'file-relative-name files)) "\n")) | |
1fd3454a | 388 | (vc-svn-command |
b349012b | 389 | buffer |
fe1919ab | 390 | (if (and (= (length files) 1) (vc-stay-local-p (car files))) 'async 0) |
8cdd17b4 | 391 | files "log" |
5b5afd50 | 392 | ;; By default Subversion only shows the log upto the working revision, |
bf54d814 SM |
393 | ;; whereas we also want the log of the subsequent commits. At least |
394 | ;; that's what the vc-cvs.el code does. | |
2b330cb8 | 395 | "-rHEAD:0"))) |
8cdd17b4 ER |
396 | |
397 | (defun vc-svn-wash-log () | |
398 | "Remove all non-comment information from log output." | |
399 | ;; FIXME: not implemented for SVN | |
400 | nil) | |
401 | ||
402 | (defun vc-svn-diff (files &optional oldvers newvers buffer) | |
5b5afd50 | 403 | "Get a difference report using SVN between two revisions of fileset FILES." |
c62a495a GM |
404 | (and oldvers |
405 | (catch 'no | |
406 | (dolist (f files) | |
ac3f4c6f | 407 | (or (equal oldvers (vc-working-revision f)) |
c62a495a GM |
408 | (throw 'no nil))) |
409 | t) | |
410 | ;; Use nil rather than the current revision because svn handles | |
411 | ;; it better (i.e. locally). Note that if _any_ of the files | |
412 | ;; has a different revision, we fetch the lot, which is | |
413 | ;; obviously sub-optimal. | |
414 | (setq oldvers nil)) | |
8cdd17b4 | 415 | (let* ((switches |
f9d1f3be SM |
416 | (if vc-svn-diff-switches |
417 | (vc-switches 'SVN 'diff) | |
418 | (list "-x" (mapconcat 'identity (vc-switches nil 'diff) " ")))) | |
2d4e93b9 | 419 | (async (and (not vc-disable-async-diff) |
8cdd17b4 | 420 | (vc-stay-local-p files) |
fe1919ab | 421 | (or oldvers newvers)))) ; Svn diffs those locally. |
b349012b | 422 | (apply 'vc-svn-command buffer |
2766aaaf | 423 | (if async 'async 0) |
8cdd17b4 | 424 | files "diff" |
2766aaaf | 425 | (append |
f9d1f3be | 426 | switches |
2766aaaf SM |
427 | (when oldvers |
428 | (list "-r" (if newvers (concat oldvers ":" newvers) | |
429 | oldvers))))) | |
fd140743 SM |
430 | (if async 1 ; async diff => pessimistic assumption |
431 | ;; For some reason `svn diff' does not return a useful | |
432 | ;; status w.r.t whether the diff was empty or not. | |
8cdd17b4 | 433 | (buffer-size (get-buffer buffer))))) |
1fd3454a | 434 | |
1fd3454a SM |
435 | ;;; |
436 | ;;; Snapshot system | |
437 | ;;; | |
438 | ||
439 | (defun vc-svn-create-snapshot (dir name branchp) | |
5b5afd50 | 440 | "Assign to DIR's current revision a given NAME. |
1fd3454a | 441 | If BRANCHP is non-nil, the name is created as a branch (and the current |
5cc7cb96 SM |
442 | workspace is immediately moved to that new branch). |
443 | NAME is assumed to be a URL." | |
444 | (vc-svn-command nil 0 dir "copy" name) | |
445 | (when branchp (vc-svn-retrieve-snapshot dir name nil))) | |
1fd3454a SM |
446 | |
447 | (defun vc-svn-retrieve-snapshot (dir name update) | |
448 | "Retrieve a snapshot at and below DIR. | |
449 | NAME is the name of the snapshot; if it is empty, do a `svn update'. | |
5cc7cb96 SM |
450 | If UPDATE is non-nil, then update (resynch) any affected buffers. |
451 | NAME is assumed to be a URL." | |
452 | (vc-svn-command nil 0 dir "switch" name) | |
453 | ;; FIXME: parse the output and obey `update'. | |
454 | ) | |
1fd3454a SM |
455 | |
456 | ;;; | |
457 | ;;; Miscellaneous | |
458 | ;;; | |
459 | ||
460 | ;; Subversion makes backups for us, so don't bother. | |
7ffc77d3 | 461 | ;; (defalias 'vc-svn-make-version-backups-p 'vc-stay-local-p |
1fd3454a SM |
462 | ;; "Return non-nil if version backups should be made for FILE.") |
463 | ||
464 | (defun vc-svn-check-headers () | |
465 | "Check if the current file has any headers in it." | |
466 | (save-excursion | |
467 | (goto-char (point-min)) | |
468 | (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\ | |
469 | \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t))) | |
470 | ||
471 | ||
472 | ;;; | |
473 | ;;; Internal functions | |
474 | ;;; | |
475 | ||
e4cc3f57 SM |
476 | (defcustom vc-svn-program "svn" |
477 | "Name of the svn executable." | |
478 | :type 'string | |
479 | :group 'vc) | |
480 | ||
8cdd17b4 | 481 | (defun vc-svn-command (buffer okstatus file-or-list &rest flags) |
1fd3454a SM |
482 | "A wrapper around `vc-do-command' for use in vc-svn.el. |
483 | The difference to vc-do-command is that this function always invokes `svn', | |
484 | and that it passes `vc-svn-global-switches' to it before FLAGS." | |
8cdd17b4 | 485 | (apply 'vc-do-command buffer okstatus vc-svn-program file-or-list |
1fd3454a SM |
486 | (if (stringp vc-svn-global-switches) |
487 | (cons vc-svn-global-switches flags) | |
488 | (append vc-svn-global-switches | |
489 | flags)))) | |
490 | ||
7ffc77d3 SM |
491 | (defun vc-svn-repository-hostname (dirname) |
492 | (with-temp-buffer | |
493 | (let ((coding-system-for-read | |
494 | (or file-name-coding-system | |
495 | default-file-name-coding-system))) | |
ace2fad9 CY |
496 | (vc-insert-file (expand-file-name (concat vc-svn-admin-directory |
497 | "/entries") | |
498 | dirname))) | |
7ffc77d3 SM |
499 | (goto-char (point-min)) |
500 | (when (re-search-forward | |
c45b3be3 | 501 | ;; Old `svn' used name="svn:this_dir", newer use just name="". |
17a5a301 SM |
502 | (concat "name=\"\\(?:svn:this_dir\\)?\"[\n\t ]*" |
503 | "\\(?:[-a-z]+=\"[^\"]*\"[\n\t ]*\\)*?" | |
0b0dad41 SM |
504 | "url=\"\\(?1:[^\"]+\\)\"" |
505 | ;; Yet newer ones don't use XML any more. | |
506 | "\\|^\ndir\n[0-9]+\n\\(?1:.*\\)") nil t) | |
17a5a301 SM |
507 | ;; This is not a hostname but a URL. This may actually be considered |
508 | ;; as a feature since it allows vc-svn-stay-local to specify different | |
509 | ;; behavior for different modules on the same server. | |
510 | (match-string 1)))) | |
1fd3454a | 511 | |
1c67a814 SM |
512 | (defun vc-svn-resolve-when-done () |
513 | "Call \"svn resolved\" if the conflict markers have been removed." | |
514 | (save-excursion | |
515 | (goto-char (point-min)) | |
516 | (if (not (re-search-forward "^<<<<<<< " nil t)) | |
517 | (vc-svn-command nil 0 buffer-file-name "resolved")))) | |
518 | ||
519 | ;; Inspired by vc-arch-find-file-hook. | |
520 | (defun vc-svn-find-file-hook () | |
521 | (when (eq ?C (vc-file-getprop buffer-file-name 'vc-svn-status)) | |
522 | ;; If the file is marked as "conflicted", then we should try and call | |
523 | ;; "svn resolved" when applicable. | |
524 | (if (save-excursion | |
525 | (goto-char (point-min)) | |
526 | (re-search-forward "^<<<<<<< " nil t)) | |
527 | ;; There are conflict markers. | |
528 | (progn | |
529 | (smerge-mode 1) | |
530 | (add-hook 'after-save-hook 'vc-svn-resolve-when-done nil t)) | |
531 | ;; There are no conflict markers. This is problematic: maybe it means | |
532 | ;; the conflict has been resolved and we should immediately call "svn | |
533 | ;; resolved", or it means that the file's type does not allow Svn to | |
534 | ;; use conflict markers in which case we don't really know what to do. | |
535 | ;; So let's just punt for now. | |
536 | nil) | |
537 | (message "There are unresolved conflicts in this file"))) | |
538 | ||
bc8c1bb4 | 539 | (defun vc-svn-parse-status (&optional filename) |
1fd3454a | 540 | "Parse output of \"svn status\" command in the current buffer. |
bc8c1bb4 SM |
541 | Set file properties accordingly. Unless FILENAME is non-nil, parse only |
542 | information about FILENAME and return its status." | |
1fd3454a SM |
543 | (let (file status) |
544 | (goto-char (point-min)) | |
545 | (while (re-search-forward | |
c45b3be3 SM |
546 | ;; Ignore the files with status in [IX?]. |
547 | "^[ ACDGMR!~][ MC][ L][ +][ S]..\\([ *]\\) +\\([-0-9]+\\) +\\([0-9?]+\\) +\\([^ ]+\\) +" nil t) | |
548 | ;; If the username contains spaces, the output format is ambiguous, | |
549 | ;; so don't trust the output's filename unless we have to. | |
550 | (setq file (or filename | |
551 | (expand-file-name | |
552 | (buffer-substring (point) (line-end-position))))) | |
1fd3454a SM |
553 | (setq status (char-after (line-beginning-position))) |
554 | (unless (eq status ??) | |
bc8c1bb4 SM |
555 | ;; `vc-BACKEND-registered' must not set vc-backend, |
556 | ;; which is instead set in vc-registered. | |
557 | (unless filename (vc-file-setprop file 'vc-backend 'SVN)) | |
fd140743 SM |
558 | ;; Use the last-modified revision, so that searching in vc-print-log |
559 | ;; output works. | |
ac3f4c6f | 560 | (vc-file-setprop file 'vc-working-revision (match-string 3)) |
1c67a814 SM |
561 | ;; Remember Svn's own status. |
562 | (vc-file-setprop file 'vc-svn-status status) | |
1fd3454a SM |
563 | (vc-file-setprop |
564 | file 'vc-state | |
565 | (cond | |
566 | ((eq status ?\ ) | |
567 | (if (eq (char-after (match-beginning 1)) ?*) | |
568 | 'needs-patch | |
569 | (vc-file-setprop file 'vc-checkout-time | |
570 | (nth 5 (file-attributes file))) | |
571 | 'up-to-date)) | |
572 | ((eq status ?A) | |
fd140743 | 573 | ;; If the file was actually copied, (match-string 2) is "-". |
ac3f4c6f | 574 | (vc-file-setprop file 'vc-working-revision "0") |
1fd3454a SM |
575 | (vc-file-setprop file 'vc-checkout-time 0) |
576 | 'edited) | |
577 | ((memq status '(?M ?C)) | |
578 | (if (eq (char-after (match-beginning 1)) ?*) | |
579 | 'needs-merge | |
580 | 'edited)) | |
bc8c1bb4 SM |
581 | (t 'edited))))) |
582 | (if filename (vc-file-getprop filename 'vc-state)))) | |
1fd3454a SM |
583 | |
584 | (defun vc-svn-dir-state-heuristic (dir) | |
585 | "Find the SVN state of all files in DIR, using only local information." | |
586 | (vc-svn-dir-state dir 'local)) | |
587 | ||
588 | (defun vc-svn-valid-symbolic-tag-name-p (tag) | |
589 | "Return non-nil if TAG is a valid symbolic tag name." | |
590 | ;; According to the SVN manual, a valid symbolic tag must start with | |
591 | ;; an uppercase or lowercase letter and can contain uppercase and | |
592 | ;; lowercase letters, digits, `-', and `_'. | |
593 | (and (string-match "^[a-zA-Z]" tag) | |
594 | (not (string-match "[^a-z0-9A-Z-_]" tag)))) | |
595 | ||
5b5afd50 ER |
596 | (defun vc-svn-valid-revision-number-p (tag) |
597 | "Return non-nil if TAG is a valid revision number." | |
1fd3454a SM |
598 | (and (string-match "^[0-9]" tag) |
599 | (not (string-match "[^0-9]" tag)))) | |
600 | ||
17a5a301 SM |
601 | ;; Support for `svn annotate' |
602 | ||
603 | (defun vc-svn-annotate-command (file buf &optional rev) | |
604 | (vc-svn-command buf 0 file "annotate" (if rev (concat "-r" rev)))) | |
605 | ||
606 | (defun vc-svn-annotate-time-of-rev (rev) | |
607 | ;; Arbitrarily assume 10 commmits per day. | |
608 | (/ (string-to-number rev) 10.0)) | |
609 | ||
610 | (defun vc-svn-annotate-current-time () | |
611 | (vc-svn-annotate-time-of-rev vc-annotate-parent-rev)) | |
612 | ||
613 | (defconst vc-svn-annotate-re "[ \t]*\\([0-9]+\\)[ \t]+[^\t ]+ ") | |
614 | ||
615 | (defun vc-svn-annotate-time () | |
616 | (when (looking-at vc-svn-annotate-re) | |
617 | (goto-char (match-end 0)) | |
618 | (vc-svn-annotate-time-of-rev (match-string 1)))) | |
619 | ||
620 | (defun vc-svn-annotate-extract-revision-at-line () | |
621 | (save-excursion | |
622 | (beginning-of-line) | |
623 | (if (looking-at vc-svn-annotate-re) (match-string 1)))) | |
624 | ||
1fd3454a SM |
625 | (provide 'vc-svn) |
626 | ||
f9d1f3be | 627 | ;; arch-tag: 02f10c68-2b4d-453a-90fc-1eee6cfb268d |
1fd3454a | 628 | ;;; vc-svn.el ends here |