Mercurial > emacs
annotate lisp/vc.el @ 1398:70d0cd4c5bff
mem_limits.h is now called mem-limits.h.
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Mon, 12 Oct 1992 18:55:05 +0000 |
parents | a8623439066b |
children | 429e23e87072 |
rev | line source |
---|---|
904 | 1 ;;; vc.el --- drive a version-control system from within Emacs |
2 | |
3 ;; Copyright (C) 1992 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> | |
6 ;; Version: 4.0 | |
7 | |
1352
a8623439066b
(vc-backend-steal): Delete the workfile after the rcs -M -u.
Richard M. Stallman <rms@gnu.org>
parents:
1344
diff
changeset
|
8 ;; $Id: vc.el,v 1.12 1992/10/05 22:03:53 rms Exp rms $ |
904 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; This was designed and implemented by Eric Raymond <esr@snark.thyrsus.com>. | |
29 ;; Paul Eggert <eggert@twinsun.com>, Sebastian Kremer <sk@thp.uni-koeln.de>, | |
30 ;; and Richard Stallman contributed valuable criticism, support, and testing. | |
31 ;; | |
32 ;; Supported version-control systems presently include SCCS and RCS; | |
33 ;; your RCS version should be 5.6.2 or later for proper operation of | |
34 ;; the lock-breaking code. | |
35 ;; | |
36 ;; The RCS code assumes strict locking. You can support the RCS -x option | |
37 ;; by adding pairs to the vc-master-templates list. | |
38 ;; | |
39 ;; Proper function of the SCCS diff commands requires the shellscript vcdiff | |
40 ;; to be installed somewhere on Emacs's path for executables. | |
41 ;; | |
42 ;; This code depends on call-process passing back the subprocess exit | |
43 ;; status. Thus, you need Emacs 18.58 or later to run it. | |
44 ;; | |
45 ;; The vc code maintains some internal state in order to reduce expensive | |
46 ;; version-control operations to a minimum. Some names are only computed | |
47 ;; once. If you perform version control operations with RCS/SCCS/CVS while | |
48 ;; vc's back is turned, or move/rename master files while vc is running, | |
49 ;; vc may get seriously confused. Don't do these things! | |
50 ;; | |
51 ;; Developer's notes on some concurrency issues are included at the end of | |
52 ;; the file. | |
53 | |
54 ;;; Code: | |
55 | |
56 (require 'vc-hooks) | |
57 | |
58 ;; General customization | |
59 | |
60 (defvar vc-default-back-end nil | |
61 "*Back-end actually used by this interface; may be SCCS or RCS. | |
62 The value is only computed when needed to avoid an expensive search.") | |
63 (defvar vc-diff-options '("-a" "-c1") | |
64 "*The command/flags list to be used in constructing diff commands.") | |
65 (defvar vc-suppress-confirm nil | |
66 "*If non-nil, reat user as expert; suppress yes-no prompts on some things.") | |
67 (defvar vc-keep-workfiles t | |
68 "*If non-nil, don't delete working files after registering changes.") | |
69 (defvar vc-initial-comment nil | |
70 "*Prompt for initial comment when a file is registered.") | |
71 (defvar vc-command-messages nil | |
72 "*Display run messages from back-end commands.") | |
73 (defvar vc-mistrust-permissions 'file-symlink-p | |
74 "*Don't assume that permissions and ownership track version-control status.") | |
75 | |
1335
d649d430148d
(vc-checkin-switches): New defvar.
Roland McGrath <roland@gnu.org>
parents:
1243
diff
changeset
|
76 (defvar vc-checkin-switches nil |
d649d430148d
(vc-checkin-switches): New defvar.
Roland McGrath <roland@gnu.org>
parents:
1243
diff
changeset
|
77 "*Extra switches passed to the checkin program by \\[vc-checkin].") |
d649d430148d
(vc-checkin-switches): New defvar.
Roland McGrath <roland@gnu.org>
parents:
1243
diff
changeset
|
78 |
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
79 ;;;###autoload |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
80 (defvar vc-checkin-hook nil |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
81 "*List of functions called after a vc-checkin is done. See `runs-hooks'.") |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
82 |
904 | 83 ;; Header-insertion hair |
84 | |
85 (defvar vc-header-alist | |
86 '((SCCS "\%W\%") (RCS "\$Id\$")) | |
87 "*Header keywords to be inserted when vc-insert-header is executed.") | |
88 (defconst vc-static-header-alist | |
89 '(("\\.c$" . | |
90 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n")) | |
91 "*Associate static header string templates with file types. A \%s in the | |
92 template is replaced with the first string associated with the file's | |
93 verson-control type in vc-header-strings.") | |
94 (defvar vc-comment-alist | |
95 '((nroff-mode ".\\\"" "")) | |
96 "*Special comment delimiters to be used in generating vc headers only. | |
97 Add an entry in this list if you need to override the normal comment-start | |
98 and comment-end variables. This will only be necessary if the mode language | |
99 is sensitive to blank lines.") | |
100 | |
101 ;; Variables the user doesn't need to know about. | |
102 (defvar vc-log-entry-mode nil) | |
103 (defvar vc-log-operation nil) | |
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
104 (defvar vc-log-after-operation-hook nil) |
904 | 105 |
106 (defconst vc-name-assoc-file "VC-names") | |
107 | |
108 (defmacro vc-error-occurred (&rest body) | |
109 (list 'condition-case nil (cons 'progn (append body '(nil))) '(error t))) | |
110 | |
111 ;; File property caching | |
112 | |
113 (defun vc-file-clearprops (file) | |
114 ;; clear all properties of a given file | |
115 (setplist (intern file vc-file-prop-obarray) nil)) | |
116 | |
117 ;; Random helper functions | |
118 | |
119 (defun vc-name (file) | |
120 "Return the master name of a file, nil if it is not registered" | |
121 (or (vc-file-getprop file 'vc-name) | |
122 (vc-file-setprop file 'vc-name | |
123 (let ((name-and-type (vc-registered file))) | |
124 (and name-and-type (car name-and-type)))))) | |
125 | |
126 (defvar vc-binary-assoc nil) | |
127 | |
128 (defun vc-find-binary (name) | |
129 "Look for a command anywhere on the subprocess-command search path." | |
130 (or (cdr (assoc name vc-binary-assoc)) | |
131 (let ((full nil)) | |
132 (catch 'found | |
133 (mapcar | |
134 (function (lambda (s) | |
135 (if (and s (file-exists-p (setq full (concat s "/" name)))) | |
136 (throw 'found nil)))) | |
137 exec-path)) | |
138 (if full | |
139 (setq vc-binary-assoc (cons (cons name full) vc-binary-assoc))) | |
140 full))) | |
141 | |
142 (defun vc-do-command (okstatus command file &rest flags) | |
143 "Execute a version-control command, notifying user and checking for errors. | |
144 The command is successful if its exit status does not exceed OKSTATUS. | |
145 Output from COMMAND goes to buffer *vc*. The last argument of the command is | |
146 the master name of FILE; this is appended to an optional list of FLAGS." | |
147 (setq file (expand-file-name file)) | |
148 (if vc-command-messages | |
149 (message (format "Running %s on %s..." command file))) | |
150 (let ((obuf (current-buffer)) | |
151 (squeezed nil) | |
152 (vc-file (and file (vc-name file))) | |
153 status) | |
154 (set-buffer (get-buffer-create "*vc*")) | |
155 (erase-buffer) | |
156 (mapcar | |
157 (function (lambda (s) (and s (setq squeezed (append squeezed (list s)))))) | |
158 flags) | |
159 (if vc-file | |
160 (setq squeezed (append squeezed (list vc-file)))) | |
161 (let | |
162 ((default-directory (file-name-directory (or file "./")))) | |
163 (setq status (apply 'call-process command nil t nil squeezed)) | |
164 ) | |
165 (goto-char (point-max)) | |
166 (previous-line 1) | |
167 (if (or (not (integerp status)) (< okstatus status)) | |
168 (progn | |
169 (previous-line 1) | |
170 (print (cons command squeezed)) | |
171 (next-line 1) | |
172 (pop-to-buffer "*vc*") | |
173 (vc-shrink-to-fit) | |
174 (goto-char (point-min)) | |
175 (error (format "Running %s...FAILED (%s)" command | |
176 (if (integerp status) | |
177 (format "status %d" status) | |
178 status))) | |
179 ) | |
180 (if vc-command-messages | |
181 (message (format "Running %s...OK" command))) | |
182 ) | |
183 (set-buffer obuf) | |
184 status) | |
185 ) | |
186 | |
187 (defun vc-revert-buffer1 (&optional arg no-confirm) | |
188 ;; This code was shamelessly lifted from Sebastian Kremer's rcs.el mode. | |
189 ;; Revert buffer, try to keep point where user expects it in spite | |
190 ;; of changes because of expanded version-control key words. | |
191 ;; This is quite important since otherwise typeahead won't work as expected. | |
192 (interactive "P") | |
193 (widen) | |
194 (let* ((opoint (point)) | |
195 (osize (buffer-size)) | |
196 diff | |
197 (context 100) | |
198 (ostring (buffer-substring (point) | |
199 (min (point-max) | |
200 (+ (point) context)))) | |
201 (l (length ostring))) | |
202 (revert-buffer arg no-confirm) | |
203 (setq diff (- osize (buffer-size))) | |
204 (if (< diff 0) (setq diff (- diff))) | |
205 (goto-char opoint) | |
206 (cond ((equal "" ostring) | |
207 (goto-char (point-max))) | |
208 ((or (search-forward ostring nil t) | |
209 ;; Can't use search-backward since the match may continue | |
210 ;; after point. | |
211 (progn (goto-char (- (point) diff l)) | |
212 ;; goto-char doesn't signal an error at | |
213 ;; beginning of buffer like backward-char would | |
214 (search-forward ostring nil t))) | |
215 ;; to beginning of OSTRING | |
216 (backward-char l))))) | |
217 | |
218 (defun vc-buffer-sync () | |
219 ;; Make sure the current buffer and its working file are in sync | |
220 (if (and (buffer-modified-p) | |
221 (or | |
222 vc-suppress-confirm | |
223 (y-or-n-p (format "%s has been modified. Write it out? " | |
224 (buffer-name))))) | |
225 (save-buffer))) | |
226 | |
227 (defun vc-workfile-unchanged-p (file) | |
228 ;; Has the given workfile changed since last checkout? | |
229 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time)) | |
230 (lastmod (nth 5 (file-attributes file)))) | |
231 (if checkout-time | |
232 (equal lastmod checkout-time) | |
233 (if (zerop (vc-backend-diff file nil)) | |
234 (progn | |
235 (vc-file-setprop file 'vc-checkout-time lastmod) | |
236 t) | |
237 (progn | |
238 (vc-file-setprop file 'vc-checkout-time '(0 . 0)) | |
239 nil | |
240 )) | |
241 ))) | |
242 | |
927 | 243 ;; Here's the major entry point. |
904 | 244 |
927 | 245 ;;;###autoload |
904 | 246 (defun vc-next-action (verbose) |
247 "Do the next logical checkin or checkout operation on the current file. | |
248 If the file is not already registered, this registers it for version | |
249 control and then retrieves a writeable, locked copy for editing. | |
250 If the file is registered and not locked by anyone, this checks out | |
251 a writeable and locked file ready for editing. | |
252 If the file is checked out and locked by the calling user, this | |
253 first checks to see if the file has changed since checkout. If not, | |
254 it performs a revert. | |
255 If the file has been changed, this pops up a buffer for creation of | |
256 a log message; when the message has been entered, it checks in the | |
257 resulting changes along with the log message as change commentary. If | |
258 the variable vc-keep-workfiles is non-nil (which is its default), a | |
259 read-only copy of the changed file is left in place afterwards. | |
260 If the file is registered and locked by someone else, you are given | |
261 the option to steal the lock." | |
262 (interactive "P") | |
263 (if buffer-file-name | |
264 (let | |
265 (do-update owner version | |
266 (file buffer-file-name) | |
267 (vc-file (vc-name buffer-file-name)) | |
268 (err-msg nil) | |
269 owner) | |
270 | |
271 (cond | |
272 | |
273 ;; if there is no master file corresponding, create one | |
274 ((not vc-file) | |
275 (vc-register verbose) | |
276 (vc-next-action verbose)) | |
277 | |
278 ;; if there is no lock on the file, assert one and get it | |
279 ((not (setq owner (vc-locking-user file))) | |
280 (vc-checkout file t)) | |
281 | |
282 ;; a checked-out version exists, but the user may not own the lock | |
283 ((not (string-equal owner (user-login-name))) | |
284 (vc-steal-lock | |
285 file | |
286 (and verbose (read-string "Version to steal: ")) | |
287 owner)) | |
288 | |
289 ;; OK, user owns the lock on the file | |
290 (t (progn | |
291 | |
292 ;; give luser a chance to save before checking in. | |
293 (vc-buffer-sync) | |
294 | |
295 ;; revert if file is unchanged | |
296 (if (vc-workfile-unchanged-p file) | |
297 (progn | |
298 (vc-backend-revert file) | |
299 (vc-resynch-window file t)) | |
300 | |
301 ;; user may want to set nonstandard parameters | |
302 (if verbose | |
303 (setq version (read-string "New version level: "))) | |
304 | |
305 ;; OK, let's do the checkin | |
306 (vc-checkin file version)))))) | |
307 (error "There is no file associated with buffer %s" (buffer-name)))) | |
308 | |
309 ;;; These functions help the vc-next-action entry point | |
310 | |
927 | 311 ;;;###autoload |
904 | 312 (defun vc-register (&optional override) |
313 "Register the current file into your version-control system." | |
314 (interactive "P") | |
315 (if (vc-name buffer-file-name) | |
316 (error "This file is already registered.")) | |
317 (vc-buffer-sync) | |
318 (vc-admin | |
319 buffer-file-name | |
320 (and override (read-string "Initial version level: "))) | |
321 ) | |
322 | |
323 (defun vc-resynch-window (file &optional keep) | |
324 ;; If the given file is in the current buffer, | |
325 ;; either revert on it so we see expanded keyworks, | |
326 ;; or unvisit it (depending on vc-keep-workfiles) | |
327 (and (string= buffer-file-name file) | |
328 (if keep | |
329 (progn | |
330 (vc-revert-buffer1 nil t) | |
331 (vc-mode-line buffer-file-name)) | |
332 (progn | |
333 (delete-window) | |
334 (kill-buffer (current-buffer)))))) | |
335 | |
336 | |
337 (defun vc-admin (file rev) | |
338 "Checks a file into your version-control system. | |
339 FILE is the unmodified name of the file. REV should be the base version | |
340 level to check it in under." | |
341 (if vc-initial-comment | |
342 (progn | |
343 (pop-to-buffer (get-buffer-create "*VC-log*")) | |
344 (vc-log-mode) | |
345 (narrow-to-region (point-max) (point-max)) | |
346 (vc-mode-line file (file-name-nondirectory file)) | |
347 (setq vc-log-operation 'vc-backend-admin) | |
348 (setq vc-log-file file) | |
349 (setq vc-log-version rev) | |
350 (message "Enter initial comment. Type C-c C-c when done.")) | |
351 (progn | |
352 (vc-backend-admin file rev) | |
353 (vc-resynch-window file vc-keep-workfiles)))) | |
354 | |
355 (defun vc-steal-lock (file rev &optional owner) | |
356 "Steal the lock on the current workfile." | |
357 (interactive) | |
358 (if (not owner) | |
359 (setq owner (vc-locking-user file))) | |
360 (if (not (y-or-n-p (format "Take the lock on %s:%s from %s?" file rev owner))) | |
361 (error "Steal cancelled.")) | |
1343
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
362 (require 'sendmail) |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
363 (pop-to-buffer (get-buffer-create "*VC-mail*")) |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
364 (setq default-directory (expand-file-name "~/")) |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
365 (auto-save-mode auto-save-default) |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
366 (mail-mode) |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
367 (erase-buffer) |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
368 (mail-setup owner (format "%s:%s" file rev) nil nil nil |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
369 (list (list 'vc-finish-steal file rev))) |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
370 (goto-char (point-max)) |
904 | 371 (insert |
1343
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
372 (format "I stole the lock on %s:%s, " file rev) |
904 | 373 (current-time-string) |
1343
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
374 ".\n") |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
375 (message "Please explain why you stole the lock. Type C-c C-c when done.")) |
904 | 376 |
1343
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
377 ;; This is called when the notification has been sent. |
904 | 378 (defun vc-finish-steal (file version) |
379 (vc-backend-steal file version) | |
1343
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
380 (vc-resynch-window file t)) |
904 | 381 |
382 (defun vc-checkout (file &optional writeable) | |
383 "Retrieve a copy of the latest version of the given file." | |
384 (vc-backend-checkout file writeable) | |
385 (if (string-equal file buffer-file-name) | |
386 (vc-resynch-window file t)) | |
387 ) | |
388 | |
389 (defun vc-checkin (file &optional rev comment) | |
390 "Check in the file specified by FILE. | |
391 The optional argument REV may be a string specifying the new version level | |
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
392 \(if nil increment the current level). The file is either retained with write |
904 | 393 permissions zeroed, or deleted (according to the value of vc-keep-workfiles). |
394 COMMENT is a comment string; if omitted, a buffer is | |
395 popped up to accept a comment." | |
396 (pop-to-buffer (get-buffer-create "*VC-log*")) | |
397 (vc-log-mode) | |
398 (narrow-to-region (point-max) (point-max)) | |
399 (vc-mode-line file (file-name-nondirectory file)) | |
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
400 (setq vc-log-operation 'vc-backend-checkin |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
401 vc-log-file file |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
402 vc-log-version rev |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
403 vc-log-after-operation-hook 'vc-checkin-hook) |
904 | 404 (message "Enter log message. Type C-c C-c when done.") |
405 (if comment | |
406 (progn | |
407 (insert comment) | |
408 (vc-finish-logentry)))) | |
409 | |
410 (defun vc-finish-logentry () | |
411 "Complete the operation implied by the current log entry." | |
412 (interactive) | |
413 (goto-char (point-max)) | |
414 (if (not (bolp)) (newline)) | |
415 ;; delimit current page | |
416 (save-excursion | |
417 (widen) | |
418 (goto-char (point-max)) | |
419 (if (and (not (bobp)) (not (= (char-after (1- (point))) ?\f))) | |
420 (insert-char ?\f 1))) | |
421 (if (not (bobp)) | |
422 (forward-char -1)) | |
423 (mark-page) | |
424 ;; Check for errors | |
425 (vc-backend-logentry-check vc-log-file) | |
426 ;; OK, do it to it | |
427 (if vc-log-operation | |
428 (funcall vc-log-operation | |
429 vc-log-file | |
430 vc-log-version | |
431 (buffer-substring (region-beginning) (1- (region-end)))) | |
432 (error "No log operation is pending.")) | |
433 ;; Return to "parent" buffer of this checkin and remove checkin window | |
434 (pop-to-buffer (get-file-buffer vc-log-file)) | |
435 (delete-window (get-buffer-window "*VC-log*")) | |
436 (bury-buffer "*VC-log*") | |
437 ;; Now make sure we see the expanded headers | |
438 (vc-resynch-window buffer-file-name vc-keep-workfiles) | |
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
439 (run-hooks vc-log-after-operation-hook) |
904 | 440 ) |
441 | |
442 ;; Code for access to the comment ring | |
443 | |
444 (defun vc-next-comment () | |
445 "Fill the log buffer with the next message in the msg ring." | |
446 (interactive) | |
447 (widen) | |
448 (forward-page) | |
449 (if (= (point) (point-max)) | |
450 (goto-char (point-min))) | |
451 (mark-page) | |
452 (narrow-to-page)) | |
453 | |
454 (defun vc-previous-comment () | |
455 "Fill the log buffer with the previous message in the msg ring." | |
456 (interactive) | |
457 (widen) | |
458 (if (= (point) (point-min)) | |
459 (goto-char (point-max))) | |
460 (backward-page) | |
461 (mark-page) | |
462 (narrow-to-page)) | |
463 | |
464 (defun vc-comment-search-backward (regexp) | |
465 "Fill the log buffer with the last message in the msg ring matching REGEXP." | |
466 (interactive "sSearch backward for: ") | |
467 (widen) | |
468 (if (= (point) (point-min)) | |
469 (goto-char (point-max))) | |
470 (re-search-backward regexp nil t) | |
471 (mark-page) | |
472 (narrow-to-page)) | |
473 | |
474 (defun vc-comment-search-forward (regexp) | |
475 "Fill the log buffer with the next message in the msg ring matching REGEXP." | |
476 (interactive "sSearch forward for: ") | |
477 (widen) | |
478 (if (= (point) (point-min)) | |
479 (goto-char (point-max))) | |
480 (re-search-forward regexp nil t) | |
481 (mark-page) | |
482 (narrow-to-page)) | |
483 | |
484 ;; Additional entry points for examining version histories | |
485 | |
927 | 486 ;;;###autoload |
904 | 487 (defun vc-diff (historic) |
488 "Display diffs between file versions." | |
489 (interactive "P") | |
490 (if historic | |
491 (call-interactively 'vc-version-diff) | |
492 (let ((old | |
493 (and | |
494 current-prefix-arg | |
495 (read-string "Version to compare against: "))) | |
496 (file buffer-file-name) | |
497 unchanged) | |
498 (vc-buffer-sync) | |
499 (setq unchanged (vc-workfile-unchanged-p buffer-file-name)) | |
500 (if unchanged | |
501 (message (format "No changes to %s since latest version." file)) | |
502 (pop-to-buffer "*vc*") | |
503 (vc-backend-diff file nil) | |
504 (goto-char (point-min)) | |
505 ) | |
506 (not unchanged) | |
507 ) | |
508 ) | |
509 ) | |
510 | |
511 (defun vc-version-diff (file rel1 rel2) | |
512 "For FILE, report diffs between two stored versions REL1 and REL2 of it. | |
513 If FILE is a directory, generate diffs between versions for all registered | |
514 files in or below it." | |
515 (interactive "FFile or directory: \nsOlder version: \nsNewer version: ") | |
516 (if (string-equal rel1 "") (setq rel1 nil)) | |
517 (if (string-equal rel2 "") (setq rel2 nil)) | |
518 (if (file-directory-p file) | |
519 (progn | |
520 (set-buffer (get-buffer-create "*vc-status*")) | |
521 (erase-buffer) | |
522 (insert "Diffs between " rel1 " and " rel2 ":\n\n") | |
523 (set-buffer (get-buffer-create "*vc*")) | |
524 (vc-file-tree-walk | |
525 (function (lambda (f) | |
526 (and | |
527 (not (file-directory-p f)) | |
528 (vc-name f) | |
529 (vc-backend-diff f rel1 rel2)) | |
530 (append-to-buffer "*vc-status*" (point-min) (point-max)) | |
531 )) | |
532 default-directory) | |
533 (pop-to-buffer "*vc-status*") | |
534 (insert "\nEnd of diffs.\n") | |
535 (goto-char (point-min)) | |
536 (set-buffer-modified-p nil) | |
537 ) | |
538 (progn | |
539 (vc-backend-diff file rel1 rel2) | |
540 (goto-char (point-min)) | |
541 (if (equal (point-min) (point-max)) | |
542 (message (format "No changes to %s between %s and %s." file rel1 rel2)) | |
543 (pop-to-buffer "*vc*") | |
544 (goto-char (point-min)) | |
545 ) | |
546 ) | |
547 ) | |
548 ) | |
549 | |
550 ;; Header-insertion code | |
551 | |
927 | 552 ;;;###autoload |
904 | 553 (defun vc-insert-headers () |
554 "Insert headers in a file for use with your version-control system. | |
555 Headers desired are inserted at the start of the buffer, and are pulled from | |
556 the variable vc-header-strings" | |
557 (interactive) | |
558 (save-excursion | |
559 (save-restriction | |
560 (widen) | |
561 (if (or (not (vc-check-headers)) | |
562 (y-or-n-p "Version headers already exist. Insert another set?")) | |
563 (progn | |
564 (let* ((delims (cdr (assq major-mode vc-comment-alist))) | |
565 (comment-start-vc (or (car delims) comment-start "#")) | |
566 (comment-end-vc (or (car (cdr delims)) comment-end "")) | |
567 (hdstrings (cdr (assoc (vc-backend-deduce (buffer-file-name)) vc-header-alist)))) | |
568 (mapcar (function (lambda (s) | |
569 (insert comment-start-vc "\t" s "\t" | |
570 comment-end-vc "\n"))) | |
571 hdstrings) | |
572 (if vc-static-header-alist | |
573 (mapcar (function (lambda (f) | |
574 (if (string-match (car f) buffer-file-name) | |
575 (insert (format (cdr f) (car hdstrings)))))) | |
576 vc-static-header-alist)) | |
577 ) | |
578 ))))) | |
579 | |
580 ;; Status-checking functions | |
581 | |
927 | 582 ;;;###autoload |
904 | 583 (defun vc-directory (verbose) |
584 "Show version-control status of all files under the current directory." | |
585 (interactive "P") | |
586 (let ((dir (substring default-directory 0 (1- (length default-directory)))) | |
587 nonempty) | |
588 (save-excursion | |
589 (set-buffer (get-buffer-create "*vc-status*")) | |
590 (erase-buffer) | |
591 (vc-file-tree-walk | |
592 (function (lambda (f) | |
593 (if (vc-registered f) | |
594 (let ((user (vc-locking-user f))) | |
595 (if (or user verbose) | |
596 (insert (format | |
597 "%s %s\n" | |
598 (concat user) f))))))) | |
599 dir) | |
600 (setq nonempty (not (zerop (buffer-size))))) | |
601 (if nonempty | |
602 (progn | |
603 (pop-to-buffer "*vc-status*" t) | |
604 (vc-shrink-to-fit) | |
605 (goto-char (point-min))) | |
606 (message "No files are currently registered under %s" dir)) | |
607 )) | |
608 | |
609 ;; Named-configuration support for SCCS | |
610 | |
611 (defun vc-add-triple (name file rev) | |
612 (save-excursion | |
613 (find-file (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file)) | |
614 (goto-char (point-max)) | |
615 (insert name "\t:\t" file "\t" rev "\n") | |
616 (basic-save-buffer) | |
617 (kill-buffer (current-buffer)) | |
618 )) | |
619 | |
620 (defun vc-record-rename (file newname) | |
621 (save-excursion | |
622 (find-file (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file)) | |
623 (goto-char (point-min)) | |
624 (replace-regexp (concat ":" (regexp-quote file) "$") (concat ":" newname)) | |
625 (basic-save-buffer) | |
626 (kill-buffer (current-buffer)) | |
627 )) | |
628 | |
629 (defun vc-lookup-triple (file name) | |
630 (or | |
631 name | |
632 (let ((firstchar (aref name 0))) | |
633 (and (>= firstchar ?0) (<= firstchar ?9) name)) | |
634 (car (vc-master-info | |
635 (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file) | |
636 (list (concat name "\t:\t" file "\t\\(.+\\)")))) | |
637 )) | |
638 | |
639 ;; Named-configuration entry points | |
640 | |
641 (defun vc-quiescent-p () | |
642 ;; Is the current directory ready to be snapshot? | |
643 (let ((dir (substring default-directory 0 (1- (length default-directory))))) | |
644 (catch 'quiet | |
645 (vc-file-tree-walk | |
646 (function (lambda (f) | |
647 (if (and (vc-registered f) (vc-locking-user f)) | |
648 (throw 'quiet nil)))) | |
649 dir) | |
650 t))) | |
651 | |
927 | 652 ;;;###autoload |
904 | 653 (defun vc-create-snapshot (name) |
654 "Make a snapshot called NAME. | |
655 The snapshot is made from all registered files at or below the current | |
656 directory. For each file, the version level of its latest | |
657 version becomes part of the named configuration." | |
658 (interactive "sNew snapshot name: ") | |
659 (if (not (vc-quiescent-p)) | |
660 (error "Can't make a snapshot, locked files are in the way.") | |
661 (vc-file-tree-walk | |
662 (function (lambda (f) (and | |
663 (not (file-directory-p f)) | |
664 (vc-name f) | |
665 (vc-backend-assign-name f name)))) | |
666 default-directory) | |
667 )) | |
668 | |
927 | 669 ;;;###autoload |
904 | 670 (defun vc-retrieve-snapshot (name) |
671 "Retrieve the snapshot called NAME. | |
672 This function fails if any files are locked at or below the current directory | |
673 Otherwise, all registered files are checked out (unlocked) at their version | |
674 levels in the snapshot." | |
675 (interactive "sSnapshot name to retrieve: ") | |
676 (if (not (vc-quiescent-p)) | |
677 (error "Can't retrieve a snapshot, locked files are in the way.") | |
678 (vc-file-tree-walk | |
679 (function (lambda (f) (and | |
680 (not (file-directory-p f)) | |
681 (vc-name f) | |
682 (vc-error-occurred (vc-backend-checkout f nil name))))) | |
683 default-directory) | |
684 )) | |
685 | |
686 ;; Miscellaneous other entry points | |
687 | |
927 | 688 ;;;###autoload |
904 | 689 (defun vc-print-log () |
690 "List the change log of the current buffer in a window." | |
691 (interactive) | |
692 (if (and buffer-file-name (vc-name buffer-file-name)) | |
693 (progn | |
694 (vc-backend-print-log buffer-file-name) | |
695 (pop-to-buffer (get-buffer-create "*vc*")) | |
696 (goto-char (point-min)) | |
697 ) | |
698 (error "There is no version-control master associated with this buffer") | |
699 ) | |
700 ) | |
701 | |
927 | 702 ;;;###autoload |
904 | 703 (defun vc-revert-buffer () |
952 | 704 "Revert the current buffer's file back to the latest checked-in version. |
705 This asks for confirmation if the buffer contents are not identical | |
706 to that version." | |
904 | 707 (interactive) |
708 (let ((file buffer-file-name) | |
709 (obuf (current-buffer)) (changed (vc-diff nil))) | |
952 | 710 (if (and changed (or vc-suppress-confirm |
711 (not (yes-or-no-p "Discard changes? ")))) | |
904 | 712 (progn |
713 (delete-window) | |
714 (error "Revert cancelled.")) | |
715 (set-buffer obuf)) | |
716 (if changed | |
717 (delete-window)) | |
718 (vc-backend-revert file) | |
719 (vc-resynch-window file t) | |
720 ) | |
721 ) | |
722 | |
927 | 723 ;;;###autoload |
904 | 724 (defun vc-cancel-version (norevert) |
725 "Undo your latest checkin." | |
726 (interactive "P") | |
727 (let ((target (vc-your-latest-version (buffer-file-name)))) | |
728 (if (null target) | |
729 (error "You didn't check in the last change.")) | |
730 (and (y-or-n-p (format "Remove version %s from master? " target)) | |
731 (vc-backend-uncheck (buffer-file-name) target))) | |
732 (if norevert | |
733 (vc-mode-line (buffer-file-name)) | |
734 (vc-checkout (buffer-file-name) nil)) | |
735 ) | |
736 | |
737 (defun vc-rename-file (old new) | |
738 "Rename a file, taking its master files with it." | |
739 (interactive "fOld name: \nFNew name: ") | |
740 (let ((oldbuf (get-file-buffer old))) | |
741 (if (buffer-modified-p oldbuf) | |
742 (error "Please save files before moving them.")) | |
743 (if (get-file-buffer new) | |
744 (error "Already editing new file name.")) | |
745 (let ((oldmaster (vc-name old))) | |
746 (if oldmaster | |
747 (if (vc-locking-user old) | |
748 (error "Please check in files before moving them.")) | |
749 (if (or (file-symlink-p oldmaster) | |
1243
de79e26e67cf
(vc-rename-file): Use OLD, not FILE which is unbound.
Richard M. Stallman <rms@gnu.org>
parents:
1232
diff
changeset
|
750 ;; This had FILE, I changed it to OLD. -- rms. |
de79e26e67cf
(vc-rename-file): Use OLD, not FILE which is unbound.
Richard M. Stallman <rms@gnu.org>
parents:
1232
diff
changeset
|
751 (file-symlink-p (vc-backend-subdirectory-name old))) |
904 | 752 (error "This is not a safe thing to do in the presence of symbolic links.")) |
753 (rename-file oldmaster (vc-name new))) | |
754 (if (or (not oldmaster) (file-exists-p old)) | |
755 (rename-file old new))) | |
756 ; ?? Renaming a file might change its contents due to keyword expansion. | |
757 ; We should really check out a new copy if the old copy was precisely equal | |
758 ; to some checked in version. However, testing for this is tricky.... | |
759 (if oldbuf | |
760 (save-excursion | |
761 (set-buffer oldbuf) | |
762 (set-visited-file-name new) | |
763 (set-buffer-modified-p nil)))) | |
1243
de79e26e67cf
(vc-rename-file): Use OLD, not FILE which is unbound.
Richard M. Stallman <rms@gnu.org>
parents:
1232
diff
changeset
|
764 ;; This had FILE, I changed it to OLD. -- rms. |
de79e26e67cf
(vc-rename-file): Use OLD, not FILE which is unbound.
Richard M. Stallman <rms@gnu.org>
parents:
1232
diff
changeset
|
765 (vc-backend-dispatch old |
904 | 766 (vc-record-rename old new) |
767 nil) | |
768 ) | |
769 | |
927 | 770 ;;;###autoload |
1226
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
771 (defun vc-update-change-log (&rest args) |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
772 "Find change log file and add entries from recent RCS logs. |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
773 The mark is left at the end of the text prepended to the change log. |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
774 With prefix arg of C-u, only find log entries for the current buffer's file. |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
775 With any numeric prefix arg, find log entries for all files currently visited. |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
776 From a program, any arguments are passed to the `rcs2log' script." |
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
777 (interactive |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
778 (cond ((consp current-prefix-arg) ;C-u |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
779 (list buffer-file-name)) |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
780 (current-prefix-arg ;Numeric argument. |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
781 (let ((files nil) |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
782 (buffers (buffer-list)) |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
783 file) |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
784 (while buffers |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
785 (setq file (buffer-file-name (car buffers))) |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
786 (and file (vc-backend-deduce file) |
1232
2c56a159c9b6
(vc-update-change-log): Use file-relative-name.
Roland McGrath <roland@gnu.org>
parents:
1227
diff
changeset
|
787 (setq files (cons (file-relative-name file) files))) |
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
788 (setq buffers (cdr buffers))) |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
789 files)))) |
1226
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
790 (find-file-other-window "ChangeLog") |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
791 (vc-buffer-sync) |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
792 (undo-boundary) |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
793 (goto-char (point-min)) |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
794 (message "Computing change log entries...") |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
795 (shell-command (mapconcat 'identity (cons "rcs2log" args) " ") t) |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
796 (message "Computing change log entries... done")) |
904 | 797 |
798 ;; Functions for querying the master and lock files. | |
799 | |
800 (defun match-substring (bn) | |
801 (buffer-substring (match-beginning bn) (match-end bn))) | |
802 | |
803 (defun vc-parse-buffer (patterns &optional file properties) | |
804 ;; Use PATTERNS to parse information out of the current buffer | |
805 ;; by matching each regular expression in the list and returning \\1. | |
806 ;; If a regexp has two tag brackets, assume the second is a date | |
807 ;; field and we want the most recent entry matching the template. | |
808 ;; If FILE and PROPERTIES are given, the latter must be a list of | |
809 ;; properties of the same length as PATTERNS; each property is assigned | |
810 ;; the corresponding value. | |
811 (mapcar (function (lambda (p) | |
812 (goto-char (point-min)) | |
813 (if (string-match "\\\\(.*\\\\(" p) | |
814 (let ((latest-date "") (latest-val)) | |
815 (while (re-search-forward p nil t) | |
816 (let ((date (match-substring 2))) | |
817 (if (string< latest-date date) | |
818 (progn | |
819 (setq latest-date date) | |
820 (setq latest-val | |
821 (match-substring 1)))))) | |
822 latest-val)) | |
823 (prog1 | |
824 (and (re-search-forward p nil t) | |
825 (let ((value (match-substring 1))) | |
826 (if file | |
827 (vc-file-setprop file (car properties) value)) | |
828 value)) | |
829 (setq properties (cdr properties))))) | |
830 patterns) | |
831 ) | |
832 | |
833 (defun vc-master-info (file fields &optional rfile properties) | |
834 ;; Search for information in a master file. | |
835 (if (and file (file-exists-p file)) | |
836 (save-excursion | |
837 (let ((buf)) | |
838 (setq buf (create-file-buffer file)) | |
839 (set-buffer buf)) | |
840 (erase-buffer) | |
841 (insert-file-contents file nil) | |
842 (set-buffer-modified-p nil) | |
843 (auto-save-mode nil) | |
844 (prog1 | |
845 (vc-parse-buffer fields rfile properties) | |
846 (kill-buffer (current-buffer))) | |
847 ) | |
848 (if rfile | |
849 (mapcar | |
850 (function (lambda (p) (vc-file-setprop rfile p nil))) | |
851 properties)) | |
852 ) | |
853 ) | |
854 | |
855 (defun vc-log-info (command file patterns &optional properties) | |
856 ;; Search for information in log program output | |
857 (if (and file (file-exists-p file)) | |
858 (save-excursion | |
859 (let ((buf)) | |
860 (setq buf (get-buffer-create "*vc*")) | |
861 (set-buffer buf)) | |
862 (apply 'vc-do-command 0 command file nil) | |
863 (set-buffer-modified-p nil) | |
864 (prog1 | |
865 (vc-parse-buffer patterns file properties) | |
866 (kill-buffer (current-buffer)) | |
867 ) | |
868 ) | |
869 (if file | |
870 (mapcar | |
871 (function (lambda (p) (vc-file-setprop file p nil))) | |
872 properties)) | |
873 ) | |
874 ) | |
875 | |
876 (defun vc-locking-user (file) | |
877 "Return the name of the person currently holding a lock on FILE. | |
878 Return nil if there is no such person." | |
879 (if (or (not vc-keep-workfiles) | |
880 (eq vc-mistrust-permissions 't) | |
881 (and vc-mistrust-permissions | |
882 (funcall vc-mistrust-permissions (vc-backend-subdirectory-name file)))) | |
883 (vc-true-locking-user file) | |
884 ;; This implementation assumes that any file which is under version | |
885 ;; control and has -rw-r--r-- is locked by its owner. This is true | |
886 ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--. | |
887 ;; We have to be careful not to exclude files with execute bits on; | |
888 ;; scripts can be under version control too. The advantage of this | |
889 ;; hack is that calls to the very expensive vc-fetch-properties | |
890 ;; function only have to be made if (a) the file is locked by someone | |
891 ;; other than the current user, or (b) some untoward manipulation | |
892 ;; behind vc's back has twiddled the `group' or `other' write bits. | |
893 (let ((attributes (file-attributes file))) | |
894 (cond ((string-match ".r-.r-.r-." (nth 8 attributes)) | |
895 nil) | |
896 ((and (= (nth 2 attributes) (user-uid)) | |
897 (string-match ".rw.r-.r-." (nth 8 attributes))) | |
898 (user-login-name)) | |
899 (t | |
900 (vc-true-locking-user file)))))) | |
901 | |
902 (defun vc-true-locking-user (file) | |
903 ;; The slow but reliable version | |
904 (vc-fetch-properties file) | |
905 (vc-file-getprop file 'vc-locking-user)) | |
906 | |
907 (defun vc-latest-version (file) | |
908 ;; Return version level of the latest version of FILE | |
909 (vc-fetch-properties file) | |
910 (vc-file-getprop file 'vc-latest-version)) | |
911 | |
912 (defun vc-your-latest-version (file) | |
913 ;; Return version level of the latest version of FILE checked in by you | |
914 (vc-fetch-properties file) | |
915 (vc-file-getprop file 'vc-your-latest-version)) | |
916 | |
917 ;; Collect back-end-dependent stuff here | |
918 ;; | |
919 ;; Everything eventually funnels through these functions. To implement | |
920 ;; support for a new version-control system, add another branch to the | |
921 ;; vc-backend-dispatch macro (in vc-hooks.el) and fill it in in each call. | |
922 | |
923 (defmacro vc-backend-dispatch (f s r) | |
924 "Execute FORM1 or FORM2 depending on whether we're using SCCS or RCS." | |
925 (list 'let (list (list 'type (list 'vc-backend-deduce f))) | |
926 (list 'cond | |
927 (list (list 'eq 'type (quote 'SCCS)) s) ;; SCCS | |
928 (list (list 'eq 'type (quote 'RCS)) r) ;; RCS | |
929 ))) | |
930 | |
931 (defun vc-lock-file (file) | |
932 ;; Generate lock file name corresponding to FILE | |
933 (let ((master (vc-name file))) | |
934 (and | |
935 master | |
936 (string-match "\\(.*/\\)s\\.\\(.*\\)" master) | |
937 (concat | |
938 (substring master (match-beginning 1) (match-end 1)) | |
939 "p." | |
940 (substring master (match-beginning 2) (match-end 2)))))) | |
941 | |
942 | |
943 (defun vc-fetch-properties (file) | |
944 ;; Re-fetch all properties associated with the given file. | |
945 ;; Currently these properties are: | |
946 ;; vc-locking-user | |
947 ;; vc-locked-version | |
948 ;; vc-latest-version | |
949 ;; vc-your-latest-version | |
950 (vc-backend-dispatch | |
951 file | |
952 ;; SCCS | |
953 (progn | |
954 (vc-master-info (vc-lock-file file) | |
955 (list | |
956 "^[^ ]+ [^ ]+ \\([^ ]+\\)" | |
957 "^\\([^ ]+\\)") | |
958 file | |
959 '(vc-locking-user vc-locked-version)) | |
960 (vc-master-info (vc-name file) | |
961 (list | |
962 "^\001d D \\([^ ]+\\)" | |
963 (concat "^\001d D \\([^ ]+\\) .* " | |
964 (regexp-quote (user-login-name)) " ") | |
965 ) | |
966 file | |
967 '(vc-latest-version vc-your-latest-version)) | |
968 ) | |
969 ;; RCS | |
970 (vc-log-info "rlog" file | |
971 (list | |
972 "^locks: strict\n\t\\([^:]+\\)" | |
973 "^locks: strict\n\t[^:]+: \\(.+\\)" | |
974 "^revision[\t ]+\\([0-9.]+\\).*\ndate: \\([ /0-9:]+\\);" | |
975 (concat | |
976 "^revision[\t ]+\\([0-9.]+\\).*locked by: " | |
977 (regexp-quote (user-login-name)) | |
978 ";\ndate: \\([ /0-9:]+\\);")) | |
979 '(vc-locking-user vc-locked-version | |
980 vc-latest-version vc-your-latest-version)) | |
981 )) | |
982 | |
983 (defun vc-backend-subdirectory-name (&optional file) | |
984 ;; Where the master and lock files for the current directory are kept | |
985 (symbol-name | |
986 (or | |
987 (and file (vc-backend-deduce file)) | |
988 vc-default-back-end | |
989 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS))))) | |
990 | |
991 (defun vc-backend-admin (file &optional rev comment) | |
992 ;; Register a file into the version-control system | |
993 ;; Automatically retrieves a read-only version of the file with | |
994 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise | |
995 ;; it deletes the workfile. | |
996 (vc-file-clearprops file) | |
997 (or vc-default-back-end | |
998 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS))) | |
999 (message "Registering %s..." file) | |
1000 (let ((backend | |
1001 (cond | |
1002 ((file-exists-p (vc-backend-subdirectory-name)) vc-default-back-end) | |
1003 ((file-exists-p "RCS") 'RCS) | |
1004 ((file-exists-p "SCCS") 'SCCS) | |
1005 (t vc-default-back-end)))) | |
1006 (cond ((eq backend 'SCCS) | |
1007 (vc-do-command 0 "admin" file ;; SCCS | |
1008 (and rev (concat "-r" rev)) | |
1009 "-fb" | |
1010 (concat "-i" file) | |
1011 (and comment (concat "-y" comment)) | |
1012 (format | |
1013 (car (rassq 'SCCS vc-master-templates)) | |
1014 (or (file-name-directory file) "") | |
1015 (file-name-nondirectory file))) | |
1016 (delete-file file) | |
1017 (if vc-keep-workfiles | |
1018 (vc-do-command 0 "get" file))) | |
1019 ((eq backend 'RCS) | |
1020 (vc-do-command 0 "ci" file ;; RCS | |
1021 (concat (if vc-keep-workfiles "-u" "-r") rev) | |
1022 (and comment (concat "-t-" comment)) | |
1023 file) | |
1024 ))) | |
1025 (message "Registering %s...done" file) | |
1026 ) | |
1027 | |
1028 (defun vc-backend-checkout (file &optional writeable rev) | |
1029 ;; Retrieve a copy of a saved version into a workfile | |
1030 (message "Checking out %s..." file) | |
1031 (vc-backend-dispatch file | |
1032 (progn | |
1033 (vc-do-command 0 "get" file ;; SCCS | |
1034 (if writeable "-e") | |
1035 (and rev (concat "-r" (vc-lookup-triple file rev)))) | |
1036 ) | |
1037 (vc-do-command 0 "co" file ;; RCS | |
1038 (if writeable "-l") | |
1039 (and rev (concat "-r" rev))) | |
1040 ) | |
1041 (vc-file-setprop file 'vc-checkout-time (nth 5 (file-attributes file))) | |
1042 (message "Checking out %s...done" file) | |
1043 ) | |
1044 | |
1045 (defun vc-backend-logentry-check (file) | |
1046 (vc-backend-dispatch file | |
1047 (if (>= (- (region-end) (region-beginning)) 512) ;; SCCS | |
1048 (progn | |
1049 (goto-char 512) | |
1050 (error | |
1051 "Log must be less than 512 characters. Point is now at char 512."))) | |
1052 nil) | |
1053 ) | |
1054 | |
1055 (defun vc-backend-checkin (file &optional rev comment) | |
1056 ;; Register changes to FILE as level REV with explanatory COMMENT. | |
1057 ;; Automatically retrieves a read-only version of the file with | |
1058 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise | |
1059 ;; it deletes the workfile. | |
1060 (message "Checking in %s..." file) | |
1337
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1061 (save-excursion |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1062 ;; Change buffers to get local value of vc-checkin-switches. |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1063 (set-buffer (or (get-file-buffer file) (current-buffer))) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1064 (vc-backend-dispatch file |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1065 (progn |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1066 (apply 'vc-do-command 0 "delta" file |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1067 (if rev (concat "-r" rev)) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1068 (concat "-y" comment) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1069 vc-checkin-switches) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1070 (if vc-keep-workfiles |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1071 (vc-do-command 0 "get" file)) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1072 ) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1073 (apply 'vc-do-command 0 "ci" file |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1074 (concat (if vc-keep-workfiles "-u" "-r") rev) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1075 (concat "-m" comment) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1076 vc-checkin-switches) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1077 )) |
904 | 1078 (vc-file-setprop file 'vc-locking-user nil) |
1079 (message "Checking in %s...done" file) | |
1080 ) | |
1081 | |
1082 (defun vc-backend-revert (file) | |
1083 ;; Revert file to latest checked-in version. | |
1084 (message "Reverting %s..." file) | |
1085 (vc-backend-dispatch | |
1086 file | |
1087 (progn ;; SCCS | |
1088 (vc-do-command 0 "unget" file nil) | |
1089 (vc-do-command 0 "get" file nil)) | |
1090 (progn | |
1091 (delete-file file) ;; RCS | |
1092 (vc-do-command 0 "co" file "-u"))) | |
1093 (vc-file-setprop file 'vc-locking-user nil) | |
1094 (message "Reverting %s...done" file) | |
1095 ) | |
1096 | |
1097 (defun vc-backend-steal (file &optional rev) | |
1098 ;; Steal the lock on the current workfile. Needs RCS 5.6.2 or later for -M. | |
1099 (message "Stealing lock on %s..." file) | |
1100 (progn | |
1101 (vc-do-command 0 "unget" file "-n" (if rev (concat "-r" rev))) | |
1102 (vc-do-command 0 "get" file "-g" (if rev (concat "-r" rev))) | |
1103 ) | |
1104 (progn | |
1344
8d047d2d2592
(vc-backend-steal): Put filename after options in rcs commands.
Richard M. Stallman <rms@gnu.org>
parents:
1343
diff
changeset
|
1105 (vc-do-command 0 "rcs" "-M" (concat "-u" rev) file) |
1352
a8623439066b
(vc-backend-steal): Delete the workfile after the rcs -M -u.
Richard M. Stallman <rms@gnu.org>
parents:
1344
diff
changeset
|
1106 (delete-file file) |
1344
8d047d2d2592
(vc-backend-steal): Put filename after options in rcs commands.
Richard M. Stallman <rms@gnu.org>
parents:
1343
diff
changeset
|
1107 (vc-do-command 0 "rcs" (concat "-l" rev) file) |
904 | 1108 ) |
1109 (vc-file-setprop file 'vc-locking-user (user-login-name)) | |
1110 (message "Stealing lock on %s...done" file) | |
1111 ) | |
1112 | |
1113 (defun vc-backend-uncheck (file target) | |
1114 ;; Undo the latest checkin. Note: this code will have to get a lot | |
1115 ;; smarter when we support multiple branches. | |
1116 (message "Removing last change from %s..." file) | |
1117 (vc-backend-dispatch file | |
1118 (vc-do-command 0 "rmdel" file (concat "-r" target)) | |
1119 (vc-do-command 0 "rcs" file (concat "-o" target)) | |
1120 ) | |
1121 (message "Removing last change from %s...done" file) | |
1122 ) | |
1123 | |
1124 (defun vc-backend-print-log (file) | |
1125 ;; Print change log associated with FILE to buffer *vc*. | |
1126 (vc-do-command 0 | |
1127 (vc-backend-dispatch file "prs" "rlog") | |
1128 file) | |
1129 ) | |
1130 | |
1131 (defun vc-backend-assign-name (file name) | |
1132 ;; Assign to a FILE's latest version a given NAME. | |
1133 (vc-backend-dispatch file | |
1134 (vc-add-triple name file (vc-latest-version file)) ;; SCCS | |
1135 (vc-do-command 0 "rcs" file (concat "-n" name ":")) ;; RCS | |
1136 )) | |
1137 | |
1138 (defun vc-backend-diff (file oldvers &optional newvers) | |
1139 ;; Get a difference report between two versions | |
1140 (apply 'vc-do-command 1 | |
1141 (or (vc-backend-dispatch file "vcdiff" "rcsdiff") | |
1142 (error (format "File %s is not under version control." file))) | |
1143 file | |
1144 (and oldvers (concat "-r" oldvers)) | |
1145 (and newvers (concat "-r" newvers)) | |
1146 vc-diff-options | |
1147 )) | |
1148 | |
1149 (defun vc-check-headers () | |
1150 "Check if the current file has any headers in it." | |
1151 (interactive) | |
1152 (save-excursion | |
1153 (goto-char (point-min)) | |
1154 (vc-backend-dispatch buffer-file-name | |
1155 (re-search-forward "%[MIRLBSDHTEGUYFPQCZWA]%" nil t) ;; SCCS | |
1156 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t) ;; RCS | |
1157 ) | |
1158 )) | |
1159 | |
1160 ;; Back-end-dependent stuff ends here. | |
1161 | |
1162 ;; Set up key bindings for use while editing log messages | |
1163 | |
1164 (defun vc-log-mode () | |
1165 "Minor mode for driving version-control tools. | |
1166 These bindings are added to the global keymap when you enter this mode: | |
1167 \\[vc-next-action] perform next logical version-control operation on current file | |
1168 \\[vc-register] register current file | |
1169 \\[vc-toggle-read-only] like next-action, but won't register files | |
1170 \\[vc-insert-headers] insert version-control headers in current file | |
1171 \\[vc-print-log] display change history of current file | |
1172 \\[vc-revert-buffer] revert buffer to latest version | |
1173 \\[vc-cancel-version] undo latest checkin | |
1174 \\[vc-diff] show diffs between file versions | |
1175 \\[vc-directory] show all files locked by any user in or below . | |
1176 \\[vc-update-change-log] add change log entry from recent checkins | |
1177 | |
1178 While you are entering a change log message for a version, the following | |
1179 additional bindings will be in effect. | |
1180 | |
1181 \\[vc-finish-logentry] proceed with check in, ending log message entry | |
1182 | |
1183 Whenever you do a checkin, your log comment is added to a ring of | |
1184 saved comments. These can be recalled as follows: | |
1185 | |
1186 \\[vc-next-comment] replace region with next message in comment ring | |
1187 \\[vc-previous-comment] replace region with previous message in comment ring | |
1188 \\[vc-search-comment-reverse] search backward for regexp in the comment ring | |
1189 \\[vc-search-comment-forward] search backward for regexp in the comment ring | |
1190 | |
1191 Entry to the change-log submode calls the value of text-mode-hook, then | |
1192 the value of vc-log-mode-hook. | |
1193 | |
1194 Global user options: | |
1195 vc-initial-comment If non-nil, require user to enter a change | |
1196 comment upon first checkin of the file. | |
1197 | |
1198 vc-keep-workfiles Non-nil value prevents workfiles from being | |
1199 deleted when changes are checked in | |
1200 | |
1201 vc-suppress-confirm Suppresses some confirmation prompts, | |
1202 notably for reversions. | |
1203 | |
1204 vc-diff-options A list consisting of the flags | |
1205 to be used for generating context diffs. | |
1206 | |
1207 vc-header-strings Which keywords to insert when adding headers | |
1208 with \\[vc-insert-headers]. Defaults to | |
1209 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under RCS. | |
1210 | |
1211 vc-static-header-alist By default, version headers inserted in C files | |
1212 get stuffed in a static string area so that | |
1213 ident(RCS) or what(SCCS) can see them in the | |
1214 compiled object code. You can override this | |
1215 by setting this variable to nil, or change | |
1216 the header template by changing it. | |
1217 | |
1218 vc-command-messages if non-nil, display run messages from the | |
1219 actual version-control utilities (this is | |
1220 intended primarily for people hacking vc | |
1221 itself). | |
1222 " | |
1223 (interactive) | |
1224 (set-syntax-table text-mode-syntax-table) | |
1225 (use-local-map vc-log-entry-mode) | |
1226 (setq local-abbrev-table text-mode-abbrev-table) | |
1227 (setq major-mode 'vc-log-mode) | |
1228 (setq mode-name "VC-Log") | |
1229 (make-local-variable 'vc-log-file) | |
1230 (make-local-variable 'vc-log-version) | |
1231 (set-buffer-modified-p nil) | |
1232 (setq buffer-file-name nil) | |
1233 (run-hooks 'text-mode-hook 'vc-log-mode-hook) | |
1234 ) | |
1235 | |
1236 ;; Initialization code, to be done just once at load-time | |
1237 (if vc-log-entry-mode | |
1238 nil | |
1239 (setq vc-log-entry-mode (make-sparse-keymap)) | |
1240 (define-key vc-log-entry-mode "\M-n" 'vc-next-comment) | |
1241 (define-key vc-log-entry-mode "\M-p" 'vc-previous-comment) | |
1242 (define-key vc-log-entry-mode "\M-r" 'vc-comment-search-backward) | |
1243 (define-key vc-log-entry-mode "\M-s" 'vc-comment-search-forward) | |
1244 (define-key vc-log-entry-mode "\C-c\C-c" 'vc-finish-logentry) | |
1245 ) | |
1246 | |
1247 ;;; These things should probably be generally available | |
1248 | |
1249 (defun vc-shrink-to-fit () | |
1250 "Shrink a window vertically until it's just large enough to contain its text" | |
1251 (let ((minsize (1+ (count-lines (point-min) (point-max))))) | |
1252 (if (< minsize (window-height)) | |
1253 (let ((window-min-height 2)) | |
1254 (shrink-window (- (window-height) minsize)))))) | |
1255 | |
1256 (defun vc-file-tree-walk (func dir &rest args) | |
1257 "Apply a given function to dir and all files underneath it, recursively." | |
1258 (apply 'funcall func dir args) | |
1259 (and (file-directory-p dir) | |
1260 (mapcar | |
1261 (function (lambda (f) (or | |
1262 (string-equal f ".") | |
1263 (string-equal f "..") | |
1264 (file-symlink-p f) ;; Avoid possible loops | |
1265 (apply 'vc-file-tree-walk | |
1266 func | |
1267 (if (= (aref dir (1- (length dir))) ?/) | |
1268 (concat dir f) | |
1269 (concat dir "/" f)) | |
1270 args)))) | |
1271 (directory-files dir)))) | |
1272 | |
1273 (provide 'vc) | |
1274 | |
1275 ;;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE | |
1276 ;;; | |
1277 ;;; These may be useful to anyone who has to debug or extend the package. | |
1278 ;;; | |
1279 ;;; A fundamental problem in VC is that there are time windows between | |
1280 ;;; vc-next-action's computations of the file's version-control state and | |
1281 ;;; the actions that change it. This is a window open to lossage in a | |
1282 ;;; multi-user environment; someone else could nip in and change the state | |
1283 ;;; of the master during it. | |
1284 ;;; | |
1285 ;;; The performance problem is that rlog/prs calls are very expensive; we want | |
1286 ;;; to avoid them as much as possible. | |
1287 ;;; | |
1288 ;;; ANALYSIS: | |
1289 ;;; | |
1290 ;;; The performance problem, it turns out, simplifies in practice to the | |
1291 ;;; problem of making vc-locking-user fast. The two other functions that call | |
1292 ;;; prs/rlog will not be so commonly used that the slowdown is a problem; one | |
1293 ;;; makes snapshots, the other deletes the calling user's last change in the | |
1294 ;;; master. | |
1295 ;;; | |
1296 ;;; The race condition implies that we have to either (a) lock the master | |
1297 ;;; during the entire execution of vc-next-action, or (b) detect and | |
1298 ;;; recover from errors resulting from dispatch on an out-of-date state. | |
1299 ;;; | |
1300 ;;; Alternative (a) appears to be unfeasible. The problem is that we can't | |
1301 ;;; guarantee that the lock will ever be removed. Suppose a user starts a | |
1302 ;;; checkin, the change message buffer pops up, and the user, having wandered | |
1303 ;;; off to do something else, simply forgets about it? | |
1304 ;;; | |
1305 ;;; Alternative (b), on the other hand, works well with a cheap way to speed up | |
1306 ;;; vc-locking-user. Usually, if a file is registered, we can read its locked/ | |
1307 ;;; unlocked state and its current owner from its permissions. | |
1308 ;;; | |
1309 ;;; This shortcut will fail if someone has manually changed the workfile's | |
1310 ;;; permissions; also if developers are munging the workfile in several | |
1311 ;;; directories, with symlinks to a master (in this latter case, the | |
1312 ;;; permissions shortcut will fail to detect a lock asserted from another | |
1313 ;;; directory). | |
1314 ;;; | |
1315 ;;; Note that these cases correspond exactly to the errors which could happen | |
1316 ;;; because of a competing checkin/checkout race in between two instances of | |
1317 ;;; vc-next-action. | |
1318 ;;; | |
1319 ;;; For VC's purposes, a workfile/master pair may have the following states: | |
1320 ;;; | |
1321 ;;; A. Unregistered. There is a workfile, there is no master. | |
1322 ;;; | |
1323 ;;; B. Registered and not locked by anyone. | |
1324 ;;; | |
1325 ;;; C. Locked by calling user and unchanged. | |
1326 ;;; | |
1327 ;;; D. Locked by the calling user and changed. | |
1328 ;;; | |
1329 ;;; E. Locked by someone other than the calling user. | |
1330 ;;; | |
1331 ;;; This makes for 25 states and 20 error conditions. Here's the matrix: | |
1332 ;;; | |
1333 ;;; VC's idea of state | |
1334 ;;; | | |
1335 ;;; V Actual state RCS action SCCS action Effect | |
1336 ;;; A B C D E | |
1337 ;;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin | |
1338 ;;; B 5 . 6 7 8 co -l get -e checkout | |
1339 ;;; C 9 10 . 11 12 co -u unget; get revert | |
1340 ;;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin | |
1341 ;;; E 17 18 19 20 . rcs -u -M ; rcs -l unget -n ; get -g steal lock | |
1342 ;;; | |
1343 ;;; All commands take the master file name as a last argument (not shown). | |
1344 ;;; | |
1345 ;;; In the discussion below, a "self-race" is a pathological situation in | |
1346 ;;; which VC operations are being attempted simultaneously by two or more | |
1347 ;;; Emacsen running under the same username. | |
1348 ;;; | |
1349 ;;; The vc-next-action code has the following windows: | |
1350 ;;; | |
1351 ;;; Window P: | |
1352 ;;; Between the check for existence of a master file and the call to | |
1353 ;;; admin/checkin in vc-buffer-admin (apparent state A). This window may | |
1354 ;;; never close if the initial-comment feature is on. | |
1355 ;;; | |
1356 ;;; Window Q: | |
1357 ;;; Between the call to vc-workfile-unchanged-p in and the immediately | |
1358 ;;; following revert (apparent state C). | |
1359 ;;; | |
1360 ;;; Window R: | |
1361 ;;; Between the call to vc-workfile-unchanged-p in and the following | |
1362 ;;; checkin (apparent state D). This window may never close. | |
1363 ;;; | |
1364 ;;; Window S: | |
1365 ;;; Between the unlock and the immediately following checkout during a | |
1366 ;;; revert operation (apparent state C). Included in window Q. | |
1367 ;;; | |
1368 ;;; Window T: | |
1369 ;;; Between vc-locking-user and the following checkout (apparent state B). | |
1370 ;;; | |
1371 ;;; Window U: | |
1372 ;;; Between vc-locking-user and the following revert (apparent state C). | |
1373 ;;; Includes windows Q and S. | |
1374 ;;; | |
1375 ;;; Window V: | |
1376 ;;; Between vc-locking-user and the following checkin (apparent state | |
1377 ;;; D). This window may never be closed if the user fails to complete the | |
1378 ;;; checkin message. Includes window R. | |
1379 ;;; | |
1380 ;;; Window W: | |
1381 ;;; Between vc-locking-user and the following steal-lock (apparent | |
1382 ;;; state E). This window may never cloce if the user fails to complete | |
1383 ;;; the steal-lock message. Includes window X. | |
1384 ;;; | |
1385 ;;; Window X: | |
1386 ;;; Between the unlock and the immediately following re-lock during a | |
1387 ;;; steal-lock operation (apparent state E). This window may never cloce | |
1388 ;;; if the user fails to complete the steal-lock message. | |
1389 ;;; | |
1390 ;;; Errors: | |
1391 ;;; | |
1392 ;;; Apparent state A --- | |
1393 ;;; | |
1394 ;;; 1. File looked unregistered but is actually registered and not locked. | |
1395 ;;; | |
1396 ;;; Potential cause: someone else's admin during window P, with | |
1397 ;;; caller's admin happening before their checkout. | |
1398 ;;; | |
1399 ;;; RCS: ci will fail with a "no lock set by <user>" message. | |
1400 ;;; SCCS: admin will fail with error (ad19). | |
1401 ;;; | |
1402 ;;; We can let these errors be passed up to the user. | |
1403 ;;; | |
1404 ;;; 2. File looked unregistered but is actually locked by caller, unchanged. | |
1405 ;;; | |
1406 ;;; Potential cause: self-race during window P. | |
1407 ;;; | |
1408 ;;; RCS: will revert the file to the last saved version and unlock it. | |
1409 ;;; SCCS: will fail with error (ad19). | |
1410 ;;; | |
1411 ;;; Either of these consequences is acceptable. | |
1412 ;;; | |
1413 ;;; 3. File looked unregistered but is actually locked by caller, changed. | |
1414 ;;; | |
1415 ;;; Potential cause: self-race during window P. | |
1416 ;;; | |
1417 ;;; RCS: will register the caller's workfile as a delta with a | |
1418 ;;; null change comment (the -t- switch will be ignored). | |
1419 ;;; SCCS: will fail with error (ad19). | |
1420 ;;; | |
1421 ;;; 4. File looked unregistered but is locked by someone else. | |
1422 ;;; | |
1423 ;;; Potential cause: someone else's admin during window P, with | |
1424 ;;; caller's admin happening *after* their checkout. | |
1425 ;;; | |
1426 ;;; RCS: will fail with a "no lock set by <user>" message. | |
1427 ;;; SCCS: will fail with error (ad19). | |
1428 ;;; | |
1429 ;;; We can let these errors be passed up to the user. | |
1430 ;;; | |
1431 ;;; Apparent state B --- | |
1432 ;;; | |
1433 ;;; 5. File looked registered and not locked, but is actually unregistered. | |
1434 ;;; | |
1435 ;;; Potential cause: master file got nuked during window P. | |
1436 ;;; | |
1437 ;;; RCS: will fail with "RCS/<file>: No such file or directory" | |
1438 ;;; SCCS: will fail with error ut4. | |
1439 ;;; | |
1440 ;;; We can let these errors be passed up to the user. | |
1441 ;;; | |
1442 ;;; 6. File looked registered and not locked, but is actually locked by the | |
1443 ;;; calling user and unchanged. | |
1444 ;;; | |
1445 ;;; Potential cause: self-race during window T. | |
1446 ;;; | |
1447 ;;; RCS: in the same directory as the previous workfile, co -l will fail | |
1448 ;;; with "co error: writable foo exists; checkout aborted". In any other | |
1449 ;;; directory, checkout will succeed. | |
1450 ;;; SCCS: will fail with ge17. | |
1451 ;;; | |
1452 ;;; Either of these consequences is acceptable. | |
1453 ;;; | |
1454 ;;; 7. File looked registered and not locked, but is actually locked by the | |
1455 ;;; calling user and changed. | |
1456 ;;; | |
1457 ;;; As case 6. | |
1458 ;;; | |
1459 ;;; 8. File looked registered and not locked, but is actually locked by another | |
1460 ;;; user. | |
1461 ;;; | |
1462 ;;; Potential cause: someone else checks it out during window T. | |
1463 ;;; | |
1464 ;;; RCS: co error: revision 1.3 already locked by <user> | |
1465 ;;; SCCS: fails with ge4 (in directory) or ut7 (outside it). | |
1466 ;;; | |
1467 ;;; We can let these errors be passed up to the user. | |
1468 ;;; | |
1469 ;;; Apparent state C --- | |
1470 ;;; | |
1471 ;;; 9. File looks locked by calling user and unchanged, but is unregistered. | |
1472 ;;; | |
1473 ;;; As case 5. | |
1474 ;;; | |
1475 ;;; 10. File looks locked by calling user and unchanged, but is actually not | |
1476 ;;; locked. | |
1477 ;;; | |
1478 ;;; Potential cause: a self-race in window U, or by the revert's | |
1479 ;;; landing during window X of some other user's steal-lock or window S | |
1480 ;;; of another user's revert. | |
1481 ;;; | |
1482 ;;; RCS: succeeds, refreshing the file from the identical version in | |
1483 ;;; the master. | |
1484 ;;; SCCS: fails with error ut4 (p file nonexistent). | |
1485 ;;; | |
1486 ;;; Either of these consequences is acceptable. | |
1487 ;;; | |
1488 ;;; 11. File is locked by calling user. It looks unchanged, but is actually | |
1489 ;;; changed. | |
1490 ;;; | |
1491 ;;; Potential cause: the file would have to be touched by a self-race | |
1492 ;;; during window Q. | |
1493 ;;; | |
1494 ;;; The revert will succeed, removing whatever changes came with | |
1495 ;;; the touch. It is theoretically possible that work could be lost. | |
1496 ;;; | |
1497 ;;; 12. File looks like it's locked by the calling user and unchanged, but | |
1498 ;;; it's actually locked by someone else. | |
1499 ;;; | |
1500 ;;; Potential cause: a steal-lock in window V. | |
1501 ;;; | |
1502 ;;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u | |
1503 ;;; SCCS: fails with error un2 | |
1504 ;;; | |
1505 ;;; We can pass these errors up to the user. | |
1506 ;;; | |
1507 ;;; Apparent state D --- | |
1508 ;;; | |
1509 ;;; 13. File looks like it's locked by the calling user and changed, but it's | |
1510 ;;; actually unregistered. | |
1511 ;;; | |
1512 ;;; Potential cause: master file got nuked during window P. | |
1513 ;;; | |
1514 ;;; RCS: Checks in the user's version as an initial delta. | |
1515 ;;; SCCS: will fail with error ut4. | |
1516 ;;; | |
1517 ;;; This case is kind of nasty. It means VC may fail to detect the | |
1518 ;;; loss of previous version information. | |
1519 ;;; | |
1520 ;;; 14. File looks like it's locked by the calling user and changed, but it's | |
1521 ;;; actually unlocked. | |
1522 ;;; | |
1523 ;;; Potential cause: self-race in window V, or the checkin happening | |
1524 ;;; during the window X of someone else's steal-lock or window S of | |
1525 ;;; someone else's revert. | |
1526 ;;; | |
1527 ;;; RCS: ci will fail with "no lock set by <user>". | |
1528 ;;; SCCS: delta will fail with error ut4. | |
1529 ;;; | |
1530 ;;; 15. File looks like it's locked by the calling user and changed, but it's | |
1531 ;;; actually locked by the calling user and unchanged. | |
1532 ;;; | |
1533 ;;; Potential cause: another self-race --- a whole checkin/checkout | |
1534 ;;; sequence by the calling user would have to land in window R. | |
1535 ;;; | |
1536 ;;; SCCS: checks in a redundant delta and leaves the file unlocked as usual. | |
1537 ;;; RCS: reverts to the file state as of the second user's checkin, leaving | |
1538 ;;; the file unlocked. | |
1539 ;;; | |
1540 ;;; It is theoretically possible that work could be lost under RCS. | |
1541 ;;; | |
1542 ;;; 16. File looks like it's locked by the calling user and changed, but it's | |
1543 ;;; actually locked by a different user. | |
1544 ;;; | |
1545 ;;; RCS: ci error: no lock set by <user> | |
1546 ;;; SCCS: unget will fail with error un2 | |
1547 ;;; | |
1548 ;;; We can pass these errors up to the user. | |
1549 ;;; | |
1550 ;;; Apparent state E --- | |
1551 ;;; | |
1552 ;;; 17. File looks like it's locked by some other user, but it's actually | |
1553 ;;; unregistered. | |
1554 ;;; | |
1555 ;;; As case 13. | |
1556 ;;; | |
1557 ;;; 18. File looks like it's locked by some other user, but it's actually | |
1558 ;;; unlocked. | |
1559 ;;; | |
1560 ;;; Potential cause: someone released a lock during window W. | |
1561 ;;; | |
1562 ;;; RCS: The calling user will get the lock on the file. | |
1563 ;;; SCCS: unget -n will fail with cm4. | |
1564 ;;; | |
1565 ;;; Either of these consequences will be OK. | |
1566 ;;; | |
1567 ;;; 19. File looks like it's locked by some other user, but it's actually | |
1568 ;;; locked by the calling user and unchanged. | |
1569 ;;; | |
1570 ;;; Potential cause: the other user relinquishing a lock followed by | |
1571 ;;; a self-race, both in window W. | |
1572 ;;; | |
1573 ;;; Under both RCS and SCCS, both unlock and lock will succeed, making | |
1574 ;;; the sequence a no-op. | |
1575 ;;; | |
1576 ;;; 20. File looks like it's locked by some other user, but it's actually | |
1577 ;;; locked by the calling user and changed. | |
1578 ;;; | |
1579 ;;; As case 19. | |
1580 ;;; | |
1581 ;;; PROBLEM CASES: | |
1582 ;;; | |
1583 ;;; In order of decreasing severity: | |
1584 ;;; | |
1585 ;;; Cases 11 and 15 under RCS are the only one that potentially lose work. | |
1586 ;;; They would require a self-race for this to happen. | |
1587 ;;; | |
1588 ;;; Case 13 in RCS loses information about previous deltas, retaining | |
1589 ;;; only the information in the current workfile. This can only happen | |
1590 ;;; if the master file gets nuked in window P. | |
1591 ;;; | |
1592 ;;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with | |
1593 ;;; no change comment in the master. This would require a self-race in | |
1594 ;;; window P or R respectively. | |
1595 ;;; | |
1596 ;;; Cases 2, 10, 19 and 20 do extra work, but make no changes. | |
1597 ;;; | |
1598 ;;; Unfortunately, it appears to me that no recovery is possible in these | |
1599 ;;; cases. They don't yield error messages, so there's no way to tell that | |
1600 ;;; a race condition has occurred. | |
1601 ;;; | |
1602 ;;; All other cases don't change either the workfile or the master, and | |
1603 ;;; trigger command errors which the user will see. | |
1604 ;;; | |
1605 ;;; Thus, there is no explicit recovery code. | |
1606 | |
1607 ;;; vc.el ends here |