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