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