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