(eval-defun): Don't change defvar to defconst
[bpt/emacs.git] / lisp / vc.el
1 ;;; vc.el --- drive a version-control system from within Emacs
2
3 ;; Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
4
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
6 ;; Modified by:
7 ;; ttn@netcom.com
8 ;; Per Cederqvist <ceder@lysator.liu.edu>
9 ;; Andre Spiegel <spiegel@berlin.informatik.uni-stuttgart.de>
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to
25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26
27 ;;; Commentary:
28
29 ;; This mode is fully documented in the Emacs user's manual.
30 ;;
31 ;; This was designed and implemented by Eric Raymond <esr@snark.thyrsus.com>.
32 ;; Paul Eggert <eggert@twinsun.com>, Sebastian Kremer <sk@thp.uni-koeln.de>,
33 ;; and Richard Stallman contributed valuable criticism, support, and testing.
34 ;; CVS support was added by Per Cederqvist <ceder@lysator.liu.se>
35 ;; in Jan-Feb 1994.
36 ;;
37 ;; Supported version-control systems presently include SCCS, RCS, and CVS.
38 ;; The RCS lock-stealing code doesn't work right unless you use RCS 5.6.2
39 ;; or newer. Currently (January 1994) that is only a beta test release.
40 ;; Even initial checkins will fail if your RCS version is so old that ci
41 ;; doesn't understand -t-; this has been known to happen to people running
42 ;; NExTSTEP 3.0.
43 ;;
44 ;; The RCS code assumes strict locking. You can support the RCS -x option
45 ;; by adding pairs to the vc-master-templates list.
46 ;;
47 ;; Proper function of the SCCS diff commands requires the shellscript vcdiff
48 ;; to be installed somewhere on Emacs's path for executables.
49 ;;
50 ;; If your site uses the ChangeLog convention supported by Emacs, the
51 ;; function vc-comment-to-change-log should prove a useful checkin hook.
52 ;;
53 ;; This code depends on call-process passing back the subprocess exit
54 ;; status. Thus, you need Emacs 18.58 or later to run it. For the
55 ;; vc-directory command to work properly as documented, you need 19.
56 ;; You also need Emacs 19's ring.el.
57 ;;
58 ;; The vc code maintains some internal state in order to reduce expensive
59 ;; version-control operations to a minimum. Some names are only computed
60 ;; once. If you perform version control operations with RCS/SCCS/CVS while
61 ;; vc's back is turned, or move/rename master files while vc is running,
62 ;; vc may get seriously confused. Don't do these things!
63 ;;
64 ;; Developer's notes on some concurrency issues are included at the end of
65 ;; the file.
66
67 ;;; Code:
68
69 (require 'vc-hooks)
70 (require 'ring)
71 (eval-when-compile (require 'dired)) ; for dired-map-over-marks macro
72
73 (if (not (assoc 'vc-parent-buffer minor-mode-alist))
74 (setq minor-mode-alist
75 (cons '(vc-parent-buffer vc-parent-buffer-name)
76 minor-mode-alist)))
77
78 ;; To implement support for a new version-control system, add another
79 ;; branch to the vc-backend-dispatch macro and fill it in in each
80 ;; call. The variable vc-master-templates in vc-hooks.el will also
81 ;; have to change.
82
83 (defmacro vc-backend-dispatch (f s r c)
84 "Execute FORM1, FORM2 or FORM3 for SCCS, RCS or CVS respectively.
85 If FORM3 is `RCS', use FORM2 for CVS as well as RCS.
86 \(CVS shares some code with RCS)."
87 (list 'let (list (list 'type (list 'vc-backend f)))
88 (list 'cond
89 (list (list 'eq 'type (quote 'SCCS)) s) ;; SCCS
90 (list (list 'eq 'type (quote 'RCS)) r) ;; RCS
91 (list (list 'eq 'type (quote 'CVS)) ;; CVS
92 (if (eq c 'RCS) r c))
93 )))
94
95 ;; General customization
96
97 (defvar vc-suppress-confirm nil
98 "*If non-nil, treat user as expert; suppress yes-no prompts on some things.")
99 (defvar vc-initial-comment nil
100 "*Prompt for initial comment when a file is registered.")
101 (defvar vc-command-messages nil
102 "*Display run messages from back-end commands.")
103 (defvar vc-checkin-switches nil
104 "*Extra switches passed to the checkin program by \\[vc-checkin].")
105 (defvar vc-checkout-switches nil
106 "*Extra switches passed to the checkout program by \\[vc-checkout].")
107 (defvar vc-directory-exclusion-list '("SCCS" "RCS" "CVS")
108 "*Directory names ignored by functions that recursively walk file trees.")
109
110 (defconst vc-maximum-comment-ring-size 32
111 "Maximum number of saved comments in the comment ring.")
112
113 ;;; This is duplicated in diff.el.
114 (defvar diff-switches "-c"
115 "*A string or list of strings specifying switches to be be passed to diff.")
116
117 ;;;###autoload
118 (defvar vc-checkin-hook nil
119 "*List of functions called after a checkin is done. See `run-hooks'.")
120
121 (defvar vc-make-buffer-writable-hook nil
122 "*List of functions called when a buffer is made writable. See `run-hooks.'
123 This hook is only used when the version control system is CVS. It
124 might be useful for sites who uses locking with CVS, or who uses link
125 farms to gold trees.")
126
127 ;; Header-insertion hair
128
129 (defvar vc-header-alist
130 '((SCCS "\%W\%") (RCS "\$Id\$") (CVS "\$Id\$"))
131 "*Header keywords to be inserted when `vc-insert-headers' is executed.")
132 (defvar vc-static-header-alist
133 '(("\\.c$" .
134 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
135 "*Associate static header string templates with file types. A \%s in the
136 template is replaced with the first string associated with the file's
137 version-control type in `vc-header-alist'.")
138
139 (defvar vc-comment-alist
140 '((nroff-mode ".\\\"" ""))
141 "*Special comment delimiters to be used in generating vc headers only.
142 Add an entry in this list if you need to override the normal comment-start
143 and comment-end variables. This will only be necessary if the mode language
144 is sensitive to blank lines.")
145
146 ;; Default is to be extra careful for super-user.
147 (defvar vc-checkout-carefully (= (user-uid) 0)
148 "*Non-nil means be extra-careful in checkout.
149 Verify that the file really is not locked
150 and that its contents match what the master file says.")
151
152 ;; Variables the user doesn't need to know about.
153 (defvar vc-log-entry-mode nil)
154 (defvar vc-log-operation nil)
155 (defvar vc-log-after-operation-hook nil)
156 (defvar vc-checkout-writable-buffer-hook 'vc-checkout-writable-buffer)
157 ;; In a log entry buffer, this is a local variable
158 ;; that points to the buffer for which it was made
159 ;; (either a file, or a VC dired buffer).
160 (defvar vc-parent-buffer nil)
161 (defvar vc-parent-buffer-name nil)
162
163 (defvar vc-log-file)
164 (defvar vc-log-version)
165
166 (defconst vc-name-assoc-file "VC-names")
167
168 (defvar vc-dired-mode nil)
169 (make-variable-buffer-local 'vc-dired-mode)
170
171 (defvar vc-comment-ring nil)
172 (defvar vc-comment-ring-index nil)
173 (defvar vc-last-comment-match nil)
174
175 ;; Back-portability to Emacs 18
176
177 (defun file-executable-p-18 (f)
178 (let ((modes (file-modes f)))
179 (and modes (not (zerop (logand 292))))))
180
181 (defun file-regular-p-18 (f)
182 (let ((attributes (file-attributes f)))
183 (and attributes (not (car attributes)))))
184
185 ; Conditionally rebind some things for Emacs 18 compatibility
186 (if (not (boundp 'minor-mode-map-alist))
187 (progn
188 (setq compilation-old-error-list nil)
189 (fset 'file-executable-p 'file-executable-p-18)
190 (fset 'shrink-window-if-larger-than-buffer 'beginning-of-buffer)
191 ))
192
193 (if (not (boundp 'file-regular-p))
194 (fset 'file-regular-p 'file-regular-p-18))
195
196 ;; File property caching
197
198 (defun vc-clear-context ()
199 "Clear all cached file properties and the comment ring."
200 (interactive)
201 (fillarray vc-file-prop-obarray nil)
202 ;; Note: there is potential for minor lossage here if there is an open
203 ;; log buffer with a nonzero local value of vc-comment-ring-index.
204 (setq vc-comment-ring nil))
205
206 (defun vc-file-clear-masterprops (file)
207 ;; clear all properties of FILE that were retrieved
208 ;; from the master file
209 (vc-file-setprop file 'vc-latest-version nil)
210 (vc-file-setprop file 'vc-your-latest-version nil)
211 (vc-backend-dispatch file
212 (progn ;; SCCS
213 (vc-file-setprop file 'vc-master-locks nil))
214 (progn ;; RCS
215 (vc-file-setprop file 'vc-default-branch nil)
216 (vc-file-setprop file 'vc-head-version nil)
217 (vc-file-setprop file 'vc-top-version nil)
218 (vc-file-setprop file 'vc-master-locks nil))
219 (progn
220 (vc-file-setprop file 'vc-cvs-status nil))))
221
222 ;;; functions that operate on RCS revision numbers
223
224 (defun vc-trunk-p (rev)
225 ;; return t if REV is a revision on the trunk
226 (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev))))
227
228 (defun vc-branch-part (rev)
229 ;; return the branch part of a revision number REV
230 (substring rev 0 (string-match "\\.[0-9]+\\'" rev)))
231
232 ;; Random helper functions
233
234 (defun vc-registration-error (file)
235 (if file
236 (error "File %s is not under version control" file)
237 (error "Buffer %s is not associated with a file" (buffer-name))))
238
239 (defvar vc-binary-assoc nil)
240
241 (defun vc-find-binary (name)
242 "Look for a command anywhere on the subprocess-command search path."
243 (or (cdr (assoc name vc-binary-assoc))
244 (catch 'found
245 (mapcar
246 (function
247 (lambda (s)
248 (if s
249 (let ((full (concat s "/" name)))
250 (if (file-executable-p full)
251 (progn
252 (setq vc-binary-assoc
253 (cons (cons name full) vc-binary-assoc))
254 (throw 'found full)))))))
255 exec-path)
256 nil)))
257
258 (defun vc-do-command (okstatus command file last &rest flags)
259 "Execute a version-control command, notifying user and checking for errors.
260 The command is successful if its exit status does not exceed OKSTATUS.
261 Output from COMMAND goes to buffer *vc*. The last argument of the command is
262 the master name of FILE if LAST is 'MASTER, or the workfile of FILE if LAST is
263 'WORKFILE; this is appended to an optional list of FLAGS."
264 (setq file (expand-file-name file))
265 (if vc-command-messages
266 (message "Running %s on %s..." command file))
267 (let ((obuf (current-buffer)) (camefrom (current-buffer))
268 (squeezed nil)
269 (vc-file (and file (vc-name file)))
270 (olddir default-directory)
271 status)
272 (set-buffer (get-buffer-create "*vc*"))
273 (set (make-local-variable 'vc-parent-buffer) camefrom)
274 (set (make-local-variable 'vc-parent-buffer-name)
275 (concat " from " (buffer-name camefrom)))
276 (setq default-directory olddir)
277
278 (erase-buffer)
279
280 (mapcar
281 (function (lambda (s) (and s (setq squeezed (append squeezed (list s))))))
282 flags)
283 (if (and vc-file (eq last 'MASTER))
284 (setq squeezed (append squeezed (list vc-file))))
285 (if (eq last 'WORKFILE)
286 (progn
287 (let* ((pwd (expand-file-name default-directory))
288 (preflen (length pwd)))
289 (if (string= (substring file 0 preflen) pwd)
290 (setq file (substring file preflen))))
291 (setq squeezed (append squeezed (list file)))))
292 (let ((exec-path (append vc-path exec-path))
293 ;; Add vc-path to PATH for the execution of this command.
294 (process-environment
295 (cons (concat "PATH=" (getenv "PATH")
296 path-separator
297 (mapconcat 'identity vc-path path-separator))
298 process-environment)))
299 (setq status (apply 'call-process command nil t nil squeezed)))
300 (goto-char (point-max))
301 (set-buffer-modified-p nil)
302 (forward-line -1)
303 (if (or (not (integerp status)) (< okstatus status))
304 (progn
305 (pop-to-buffer "*vc*")
306 (goto-char (point-min))
307 (shrink-window-if-larger-than-buffer)
308 (error "Running %s...FAILED (%s)" command
309 (if (integerp status)
310 (format "status %d" status)
311 status))
312 )
313 (if vc-command-messages
314 (message "Running %s...OK" command))
315 )
316 (set-buffer obuf)
317 status)
318 )
319
320 ;;; Save a bit of the text around POSN in the current buffer, to help
321 ;;; us find the corresponding position again later. This works even
322 ;;; if all markers are destroyed or corrupted.
323 (defun vc-position-context (posn)
324 (list posn
325 (buffer-size)
326 (buffer-substring posn
327 (min (point-max) (+ posn 100)))))
328
329 ;;; Return the position of CONTEXT in the current buffer, or nil if we
330 ;;; couldn't find it.
331 (defun vc-find-position-by-context (context)
332 (let ((context-string (nth 2 context)))
333 (if (equal "" context-string)
334 (point-max)
335 (save-excursion
336 (let ((diff (- (nth 1 context) (buffer-size))))
337 (if (< diff 0) (setq diff (- diff)))
338 (goto-char (nth 0 context))
339 (if (or (search-forward context-string nil t)
340 ;; Can't use search-backward since the match may continue
341 ;; after point.
342 (progn (goto-char (- (point) diff (length context-string)))
343 ;; goto-char doesn't signal an error at
344 ;; beginning of buffer like backward-char would
345 (search-forward context-string nil t)))
346 ;; to beginning of OSTRING
347 (- (point) (length context-string))))))))
348
349 (defun vc-revert-buffer1 (&optional arg no-confirm)
350 ;; Most of this was shamelessly lifted from Sebastian Kremer's rcs.el mode.
351 ;; Revert buffer, try to keep point and mark where user expects them in spite
352 ;; of changes because of expanded version-control key words.
353 ;; This is quite important since otherwise typeahead won't work as expected.
354 (interactive "P")
355 (widen)
356 (let ((point-context (vc-position-context (point)))
357 ;; Use mark-marker to avoid confusion in transient-mark-mode.
358 (mark-context (if (eq (marker-buffer (mark-marker)) (current-buffer))
359 (vc-position-context (mark-marker))))
360 ;; Make the right thing happen in transient-mark-mode.
361 (mark-active nil)
362 ;; We may want to reparse the compilation buffer after revert
363 (reparse (and (boundp 'compilation-error-list) ;compile loaded
364 (let ((curbuf (current-buffer)))
365 ;; Construct a list; each elt is nil or a buffer
366 ;; iff that buffer is a compilation output buffer
367 ;; that contains markers into the current buffer.
368 (save-excursion
369 (mapcar (function
370 (lambda (buffer)
371 (set-buffer buffer)
372 (let ((errors (or
373 compilation-old-error-list
374 compilation-error-list))
375 (buffer-error-marked-p nil))
376 (while (and (consp errors)
377 (not buffer-error-marked-p))
378 (and (markerp (cdr (car errors)))
379 (eq buffer
380 (marker-buffer
381 (cdr (car errors))))
382 (setq buffer-error-marked-p t))
383 (setq errors (cdr errors)))
384 (if buffer-error-marked-p buffer))))
385 (buffer-list)))))))
386
387 (revert-buffer arg no-confirm)
388
389 ;; Reparse affected compilation buffers.
390 (while reparse
391 (if (car reparse)
392 (save-excursion
393 (set-buffer (car reparse))
394 (let ((compilation-last-buffer (current-buffer)) ;select buffer
395 ;; Record the position in the compilation buffer of
396 ;; the last error next-error went to.
397 (error-pos (marker-position
398 (car (car-safe compilation-error-list)))))
399 ;; Reparse the error messages as far as they were parsed before.
400 (compile-reinitialize-errors '(4) compilation-parsing-end)
401 ;; Move the pointer up to find the error we were at before
402 ;; reparsing. Now next-error should properly go to the next one.
403 (while (and compilation-error-list
404 (/= error-pos (car (car compilation-error-list))))
405 (setq compilation-error-list (cdr compilation-error-list))))))
406 (setq reparse (cdr reparse)))
407
408 ;; Restore point and mark
409 (let ((new-point (vc-find-position-by-context point-context)))
410 (if new-point (goto-char new-point)))
411 (if mark-context
412 (let ((new-mark (vc-find-position-by-context mark-context)))
413 (if new-mark (set-mark new-mark))))))
414
415
416 (defun vc-buffer-sync (&optional not-urgent)
417 ;; Make sure the current buffer and its working file are in sync
418 ;; NOT-URGENT means it is ok to continue if the user says not to save.
419 (if (buffer-modified-p)
420 (if (or vc-suppress-confirm
421 (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name))))
422 (save-buffer)
423 (if not-urgent
424 nil
425 (error "Aborted")))))
426
427
428 (defun vc-workfile-unchanged-p (file &optional want-differences-if-changed)
429 ;; Has the given workfile changed since last checkout?
430 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time))
431 (lastmod (nth 5 (file-attributes file))))
432 (or (equal checkout-time lastmod)
433 (and (or (not checkout-time) want-differences-if-changed)
434 (let ((unchanged (zerop (vc-backend-diff file nil nil
435 (not want-differences-if-changed)))))
436 ;; 0 stands for an unknown time; it can't match any mod time.
437 (vc-file-setprop file 'vc-checkout-time (if unchanged lastmod 0))
438 unchanged)))))
439
440 (defun vc-next-action-on-file (file verbose &optional comment)
441 ;;; If comment is specified, it will be used as an admin or checkin comment.
442 (let ((vc-file (vc-name file))
443 (vc-type (vc-backend file))
444 owner version)
445 (cond
446
447 ;; if there is no master file corresponding, create one
448 ((not vc-file)
449 (vc-register verbose comment)
450 (if vc-initial-comment
451 (setq vc-log-after-operation-hook
452 'vc-checkout-writable-buffer-hook)
453 (vc-checkout-writable-buffer file)))
454
455 ;; if there is no lock on the file, assert one and get it
456 ((and (not (eq vc-type 'CVS)) ;There are no locks in CVS.
457 (not (setq owner (vc-locking-user file))))
458 (if (and vc-checkout-carefully
459 (not (vc-workfile-unchanged-p file t)))
460 (if (save-window-excursion
461 (pop-to-buffer "*vc*")
462 (goto-char (point-min))
463 (insert-string (format "Changes to %s since last lock:\n\n"
464 file))
465 (not (beep))
466 (yes-or-no-p
467 (concat "File has unlocked changes, "
468 "claim lock retaining changes? ")))
469 (progn (vc-backend-steal file)
470 (vc-mode-line file))
471 (if (not (yes-or-no-p "Revert to checked-in version, instead? "))
472 (error "Checkout aborted.")
473 (vc-revert-buffer1 t t)
474 (vc-checkout-writable-buffer file))
475 )
476 (if verbose
477 (if (not (eq vc-type 'SCCS))
478 (let ((rev (read-string "Branch or version to move to: ")))
479 (if (eq vc-type 'RCS)
480 (vc-do-command 0 "rcs" file 'MASTER (concat "-b" rev)))
481 (vc-checkout file nil rev))
482 (error "Sorry, this is not implemented for SCCS."))
483 (vc-checkout-writable-buffer file))))
484
485 ;; a checked-out version exists, but the user may not own the lock
486 ((and (not (eq vc-type 'CVS)) ;There are no locks in CVS.
487 (not (string-equal owner (user-login-name))))
488 (if comment
489 (error "Sorry, you can't steal the lock on %s this way" file))
490 (vc-steal-lock
491 file
492 (if verbose (read-string "Version to steal: ")
493 (vc-workfile-version file))
494 owner))
495
496 ;; CVS: changes to the master file need to be
497 ;; merged back into the working file
498 ((and (eq vc-type 'CVS)
499 ;; "0" means "added, but not yet committed"
500 (not (string= (vc-workfile-version file) "0"))
501 (not (string= (vc-workfile-version file)
502 (vc-latest-version file))))
503 (vc-buffer-sync)
504 (if (yes-or-no-p (format "%s is not up-to-date. Merge in changes now? "
505 (buffer-name)))
506 (progn
507 (if (and (buffer-modified-p)
508 (not (yes-or-no-p
509 "Buffer %s modified; merge file on disc anyhow? "
510 (buffer-name))))
511 (error "Merge aborted"))
512 (if (not (zerop (vc-backend-merge-news file)))
513 ;; Overlaps detected - what now? Should use some
514 ;; fancy RCS conflict resolving package, or maybe
515 ;; emerge, but for now, simply warn the user with a
516 ;; message.
517 (message "Conflicts detected!"))
518 (vc-resynch-window file t (not (buffer-modified-p))))
519
520 (error "%s needs update" (buffer-name))))
521
522 ;; CVS: Buffer is read-only. Make the file "locked", i.e.
523 ;; make the buffer writable, and assert the user to be the locker
524 ((and (eq vc-type 'CVS) buffer-read-only)
525 (if verbose
526 (let ((rev (read-string "Trunk version to move to: ")))
527 (if (not (string= rev ""))
528 (vc-checkout file nil rev)
529 (vc-do-command 0 "cvs" file 'WORKFILE "update" "-A")
530 (vc-checkout file)))
531 (setq buffer-read-only nil)
532 (vc-file-setprop file 'vc-locking-user (user-login-name))
533 (vc-mode-line file)
534 ;; Sites who make link farms to a read-only gold tree (or
535 ;; something similar) can use the hook below to break the
536 ;; sym-link.
537 (run-hooks 'vc-make-buffer-writable-hook)))
538
539 ;; OK, user owns the lock on the file
540 (t
541 (find-file file)
542
543 ;; give luser a chance to save before checking in.
544 (vc-buffer-sync)
545
546 ;; Revert if file is unchanged and buffer is too.
547 ;; If buffer is modified, that means the user just said no
548 ;; to saving it; in that case, don't revert,
549 ;; because the user might intend to save
550 ;; after finishing the log entry.
551 (if (and (vc-workfile-unchanged-p file)
552 (not (buffer-modified-p)))
553 ;; DO NOT revert the file without asking the user!
554 (cond
555 ((yes-or-no-p "Revert to master version? ")
556 (vc-backend-revert file)
557 (vc-resynch-window file t t)))
558
559 ;; user may want to set nonstandard parameters
560 (if verbose
561 (setq version (read-string "New version level: ")))
562
563 ;; OK, let's do the checkin
564 (vc-checkin file version comment)
565 )))))
566
567 (defun vc-next-action-dired (file rev comment)
568 ;; We've accepted a log comment, now do a vc-next-action using it on all
569 ;; marked files.
570 (set-buffer vc-parent-buffer)
571 (let ((configuration (current-window-configuration)))
572 (dired-map-over-marks
573 (save-window-excursion
574 (let ((file (dired-get-filename)))
575 (message "Processing %s..." file)
576 (vc-next-action-on-file file nil comment)
577 (message "Processing %s...done" file)))
578 nil t)
579 (set-window-configuration configuration))
580 )
581
582 ;; Here's the major entry point.
583
584 ;;;###autoload
585 (defun vc-next-action (verbose)
586 "Do the next logical checkin or checkout operation on the current file.
587 If you call this from within a VC dired buffer with no files marked,
588 it will operate on the file in the current line.
589 If you call this from within a VC dired buffer, and one or more
590 files are marked, it will accept a log message and then operate on
591 each one. The log message will be used as a comment for any register
592 or checkin operations, but ignored when doing checkouts. Attempted
593 lock steals will raise an error.
594 A prefix argument lets you specify the version number to use.
595
596 For RCS and SCCS files:
597 If the file is not already registered, this registers it for version
598 control and then retrieves a writable, locked copy for editing.
599 If the file is registered and not locked by anyone, this checks out
600 a writable and locked file ready for editing.
601 If the file is checked out and locked by the calling user, this
602 first checks to see if the file has changed since checkout. If not,
603 it performs a revert.
604 If the file has been changed, this pops up a buffer for entry
605 of a log message; when the message has been entered, it checks in the
606 resulting changes along with the log message as change commentary. If
607 the variable `vc-keep-workfiles' is non-nil (which is its default), a
608 read-only copy of the changed file is left in place afterwards.
609 If the file is registered and locked by someone else, you are given
610 the option to steal the lock.
611
612 For CVS files:
613 If the file is not already registered, this registers it for version
614 control. This does a \"cvs add\", but no \"cvs commit\".
615 If the file is added but not committed, it is committed.
616 If the file has not been changed, neither in your working area or
617 in the repository, a message is printed and nothing is done.
618 If your working file is changed, but the repository file is
619 unchanged, this pops up a buffer for entry of a log message; when the
620 message has been entered, it checks in the resulting changes along
621 with the logmessage as change commentary. A writable file is retained.
622 If the repository file is changed, you are asked if you want to
623 merge in the changes into your working copy."
624
625 (interactive "P")
626 (catch 'nogo
627 (if vc-dired-mode
628 (let ((files (dired-get-marked-files)))
629 (if (= (length files) 1)
630 (find-file-other-window (car files))
631 (vc-start-entry nil nil nil
632 "Enter a change comment for the marked files."
633 'vc-next-action-dired)
634 (throw 'nogo nil))))
635 (while vc-parent-buffer
636 (pop-to-buffer vc-parent-buffer))
637 (if buffer-file-name
638 (vc-next-action-on-file buffer-file-name verbose)
639 (vc-registration-error nil))))
640
641 ;;; These functions help the vc-next-action entry point
642
643 (defun vc-checkout-writable-buffer (&optional file rev)
644 "Retrieve a writable copy of the latest version of the current buffer's file."
645 (vc-checkout (or file (buffer-file-name)) t rev)
646 )
647
648 ;;;###autoload
649 (defun vc-register (&optional override comment)
650 "Register the current file into your version-control system."
651 (interactive "P")
652 (or buffer-file-name
653 (error "No visited file"))
654 (let ((master (vc-name buffer-file-name)))
655 (and master (file-exists-p master)
656 (error "This file is already registered"))
657 (and master
658 (not (y-or-n-p "Previous master file has vanished. Make a new one? "))
659 (error "This file is already registered")))
660 ;; Watch out for new buffers of size 0: the corresponding file
661 ;; does not exist yet, even though buffer-modified-p is nil.
662 (if (and (not (buffer-modified-p))
663 (zerop (buffer-size))
664 (not (file-exists-p buffer-file-name)))
665 (set-buffer-modified-p t))
666 (vc-buffer-sync)
667 (cond ((not vc-make-backup-files)
668 ;; inhibit backup for this buffer
669 (make-local-variable 'backup-inhibited)
670 (setq backup-inhibited t)))
671 (vc-admin
672 buffer-file-name
673 (and override
674 (read-string
675 (format "Initial version level for %s: " buffer-file-name))))
676 )
677
678 (defun vc-resynch-window (file &optional keep noquery)
679 ;; If the given file is in the current buffer,
680 ;; either revert on it so we see expanded keyworks,
681 ;; or unvisit it (depending on vc-keep-workfiles)
682 ;; NOQUERY if non-nil inhibits confirmation for reverting.
683 ;; NOQUERY should be t *only* if it is known the only difference
684 ;; between the buffer and the file is due to RCS rather than user editing!
685 (and (string= buffer-file-name file)
686 (if keep
687 (progn
688 ;; temporarily remove vc-find-file-hook, so that
689 ;; we don't lose the properties
690 (remove-hook 'find-file-hooks 'vc-find-file-hook)
691 (vc-revert-buffer1 t noquery)
692 (add-hook 'find-file-hooks 'vc-find-file-hook)
693 (vc-mode-line buffer-file-name))
694 (kill-buffer (current-buffer)))))
695
696 (defun vc-start-entry (file rev comment msg action &optional after-hook)
697 ;; Accept a comment for an operation on FILE revision REV. If COMMENT
698 ;; is nil, pop up a VC-log buffer, emit MSG, and set the
699 ;; action on close to ACTION; otherwise, do action immediately.
700 ;; Remember the file's buffer in vc-parent-buffer (current one if no file).
701 ;; AFTER-HOOK specifies the local value for vc-log-operation-hook.
702 (let ((parent (if file (find-file-noselect file) (current-buffer))))
703 (if comment
704 (set-buffer (get-buffer-create "*VC-log*"))
705 (pop-to-buffer (get-buffer-create "*VC-log*")))
706 (set (make-local-variable 'vc-parent-buffer) parent)
707 (set (make-local-variable 'vc-parent-buffer-name)
708 (concat " from " (buffer-name vc-parent-buffer)))
709 (vc-mode-line (or file " (no file)"))
710 (vc-log-mode)
711 (make-local-variable 'vc-log-after-operation-hook)
712 (if after-hook
713 (setq vc-log-after-operation-hook after-hook))
714 (setq vc-log-operation action)
715 (setq vc-log-file file)
716 (setq vc-log-version rev)
717 (if comment
718 (progn
719 (erase-buffer)
720 (if (eq comment t)
721 (vc-finish-logentry t)
722 (insert comment)
723 (vc-finish-logentry nil)))
724 (message "%s Type C-c C-c when done." msg))))
725
726 (defun vc-admin (file rev &optional comment)
727 "Check a file into your version-control system.
728 FILE is the unmodified name of the file. REV should be the base version
729 level to check it in under. COMMENT, if specified, is the checkin comment."
730 (vc-start-entry file rev
731 (or comment (not vc-initial-comment))
732 "Enter initial comment." 'vc-backend-admin
733 nil))
734
735 (defun vc-checkout (file &optional writable rev)
736 "Retrieve a copy of the latest version of the given file."
737 ;; If ftp is on this system and the name matches the ange-ftp format
738 ;; for a remote file, the user is trying something that won't work.
739 (if (and (string-match "^/[^/:]+:" file) (vc-find-binary "ftp"))
740 (error "Sorry, you can't check out files over FTP"))
741 (vc-backend-checkout file writable rev)
742 (if (string-equal file buffer-file-name)
743 (vc-resynch-window file t t))
744 )
745
746 (defun vc-steal-lock (file rev &optional owner)
747 "Steal the lock on the current workfile."
748 (let (file-description)
749 (if (not owner)
750 (setq owner (vc-locking-user file)))
751 (if rev
752 (setq file-description (format "%s:%s" file rev))
753 (setq file-description file))
754 (if (not (y-or-n-p (format "Take the lock on %s from %s? "
755 file-description owner)))
756 (error "Steal cancelled"))
757 (pop-to-buffer (get-buffer-create "*VC-mail*"))
758 (setq default-directory (expand-file-name "~/"))
759 (auto-save-mode auto-save-default)
760 (mail-mode)
761 (erase-buffer)
762 (mail-setup owner (format "Stolen lock on %s" file-description) nil nil nil
763 (list (list 'vc-finish-steal file rev)))
764 (goto-char (point-max))
765 (insert
766 (format "I stole the lock on %s, " file-description)
767 (current-time-string)
768 ".\n")
769 (message "Please explain why you stole the lock. Type C-c C-c when done.")))
770
771 ;; This is called when the notification has been sent.
772 (defun vc-finish-steal (file version)
773 (vc-backend-steal file version)
774 (if (get-file-buffer file)
775 (save-excursion
776 (set-buffer (get-file-buffer file))
777 (vc-resynch-window file t t))))
778
779 (defun vc-checkin (file &optional rev comment)
780 "Check in the file specified by FILE.
781 The optional argument REV may be a string specifying the new version level
782 \(if nil increment the current level). The file is either retained with write
783 permissions zeroed, or deleted (according to the value of `vc-keep-workfiles').
784 If the back-end is CVS, a writable workfile is always kept.
785 COMMENT is a comment string; if omitted, a buffer is
786 popped up to accept a comment."
787 (vc-start-entry file rev comment
788 "Enter a change comment." 'vc-backend-checkin
789 'vc-checkin-hook))
790
791 ;;; Here is a checkin hook that may prove useful to sites using the
792 ;;; ChangeLog facility supported by Emacs.
793 (defun vc-comment-to-change-log (&optional whoami file-name)
794 "Enter last VC comment into change log file for current buffer's file.
795 Optional arg (interactive prefix) non-nil means prompt for user name and site.
796 Second arg is file name of change log. \
797 If nil, uses `change-log-default-name'."
798 (interactive (if current-prefix-arg
799 (list current-prefix-arg
800 (prompt-for-change-log-name))))
801 ;; Make sure the defvar for add-log-current-defun-function has been executed
802 ;; before binding it.
803 (require 'add-log)
804 (let (;; Extract the comment first so we get any error before doing anything.
805 (comment (ring-ref vc-comment-ring 0))
806 ;; Don't let add-change-log-entry insert a defun name.
807 (add-log-current-defun-function 'ignore)
808 end)
809 ;; Call add-log to do half the work.
810 (add-change-log-entry whoami file-name t t)
811 ;; Insert the VC comment, leaving point before it.
812 (setq end (save-excursion (insert comment) (point-marker)))
813 (if (looking-at "\\s *\\s(")
814 ;; It starts with an open-paren, as in "(foo): Frobbed."
815 ;; So remove the ": " add-log inserted.
816 (delete-char -2))
817 ;; Canonicalize the white space between the file name and comment.
818 (just-one-space)
819 ;; Indent rest of the text the same way add-log indented the first line.
820 (let ((indentation (current-indentation)))
821 (save-excursion
822 (while (< (point) end)
823 (forward-line 1)
824 (indent-to indentation))
825 (setq end (point))))
826 ;; Fill the inserted text, preserving open-parens at bol.
827 (let ((paragraph-separate (concat paragraph-separate "\\|\\s *\\s("))
828 (paragraph-start (concat paragraph-start "\\|\\s *\\s(")))
829 (beginning-of-line)
830 (fill-region (point) end))
831 ;; Canonicalize the white space at the end of the entry so it is
832 ;; separated from the next entry by a single blank line.
833 (skip-syntax-forward " " end)
834 (delete-char (- (skip-syntax-backward " ")))
835 (or (eobp) (looking-at "\n\n")
836 (insert "\n"))))
837
838
839 (defun vc-finish-logentry (&optional nocomment)
840 "Complete the operation implied by the current log entry."
841 (interactive)
842 ;; Check and record the comment, if any.
843 (if (not nocomment)
844 (progn
845 (goto-char (point-max))
846 (if (not (bolp))
847 (newline))
848 ;; Comment too long?
849 (vc-backend-logentry-check vc-log-file)
850 ;; Record the comment in the comment ring
851 (if (null vc-comment-ring)
852 (setq vc-comment-ring (make-ring vc-maximum-comment-ring-size)))
853 (ring-insert vc-comment-ring (buffer-string))
854 ))
855 ;; Sync parent buffer in case the user modified it while editing the comment.
856 ;; But not if it is a vc-dired buffer.
857 (save-excursion
858 (set-buffer vc-parent-buffer)
859 (or vc-dired-mode
860 (vc-buffer-sync)))
861 ;; OK, do it to it
862 (if vc-log-operation
863 (save-excursion
864 (funcall vc-log-operation
865 vc-log-file
866 vc-log-version
867 (buffer-string)))
868 (error "No log operation is pending"))
869 ;; save the vc-log-after-operation-hook of log buffer
870 (let ((after-hook vc-log-after-operation-hook))
871 ;; Return to "parent" buffer of this checkin and remove checkin window
872 (pop-to-buffer vc-parent-buffer)
873 (let ((logbuf (get-buffer "*VC-log*")))
874 (delete-windows-on logbuf)
875 (kill-buffer logbuf))
876 ;; Now make sure we see the expanded headers
877 (if buffer-file-name
878 (vc-resynch-window buffer-file-name vc-keep-workfiles t))
879 (run-hooks after-hook)))
880
881 ;; Code for access to the comment ring
882
883 (defun vc-previous-comment (arg)
884 "Cycle backwards through comment history."
885 (interactive "*p")
886 (let ((len (ring-length vc-comment-ring)))
887 (cond ((<= len 0)
888 (message "Empty comment ring")
889 (ding))
890 (t
891 (erase-buffer)
892 ;; Initialize the index on the first use of this command
893 ;; so that the first M-p gets index 0, and the first M-n gets
894 ;; index -1.
895 (if (null vc-comment-ring-index)
896 (setq vc-comment-ring-index
897 (if (> arg 0) -1
898 (if (< arg 0) 1 0))))
899 (setq vc-comment-ring-index
900 (mod (+ vc-comment-ring-index arg) len))
901 (message "%d" (1+ vc-comment-ring-index))
902 (insert (ring-ref vc-comment-ring vc-comment-ring-index))))))
903
904 (defun vc-next-comment (arg)
905 "Cycle forwards through comment history."
906 (interactive "*p")
907 (vc-previous-comment (- arg)))
908
909 (defun vc-comment-search-reverse (str)
910 "Searches backwards through comment history for substring match."
911 (interactive "sComment substring: ")
912 (if (string= str "")
913 (setq str vc-last-comment-match)
914 (setq vc-last-comment-match str))
915 (if (null vc-comment-ring-index)
916 (setq vc-comment-ring-index -1))
917 (let ((str (regexp-quote str))
918 (len (ring-length vc-comment-ring))
919 (n (1+ vc-comment-ring-index)))
920 (while (and (< n len) (not (string-match str (ring-ref vc-comment-ring n))))
921 (setq n (+ n 1)))
922 (cond ((< n len)
923 (vc-previous-comment (- n vc-comment-ring-index)))
924 (t (error "Not found")))))
925
926 (defun vc-comment-search-forward (str)
927 "Searches forwards through comment history for substring match."
928 (interactive "sComment substring: ")
929 (if (string= str "")
930 (setq str vc-last-comment-match)
931 (setq vc-last-comment-match str))
932 (if (null vc-comment-ring-index)
933 (setq vc-comment-ring-index 0))
934 (let ((str (regexp-quote str))
935 (len (ring-length vc-comment-ring))
936 (n vc-comment-ring-index))
937 (while (and (>= n 0) (not (string-match str (ring-ref vc-comment-ring n))))
938 (setq n (- n 1)))
939 (cond ((>= n 0)
940 (vc-next-comment (- n vc-comment-ring-index)))
941 (t (error "Not found")))))
942
943 ;; Additional entry points for examining version histories
944
945 ;;;###autoload
946 (defun vc-diff (historic &optional not-urgent)
947 "Display diffs between file versions.
948 Normally this compares the current file and buffer with the most recent
949 checked in version of that file. This uses no arguments.
950 With a prefix argument, it reads the file name to use
951 and two version designators specifying which versions to compare."
952 (interactive "P")
953 (if vc-dired-mode
954 (set-buffer (find-file-noselect (dired-get-filename))))
955 (while vc-parent-buffer
956 (pop-to-buffer vc-parent-buffer))
957 (if historic
958 (call-interactively 'vc-version-diff)
959 (if (or (null buffer-file-name) (null (vc-name buffer-file-name)))
960 (error
961 "There is no version-control master associated with this buffer"))
962 (let ((file buffer-file-name)
963 unchanged)
964 (or (and file (vc-name file))
965 (vc-registration-error file))
966 (vc-buffer-sync not-urgent)
967 (setq unchanged (vc-workfile-unchanged-p buffer-file-name))
968 (if unchanged
969 (message "No changes to %s since latest version." file)
970 (vc-backend-diff file)
971 ;; Ideally, we'd like at this point to parse the diff so that
972 ;; the buffer effectively goes into compilation mode and we
973 ;; can visit the old and new change locations via next-error.
974 ;; Unfortunately, this is just too painful to do. The basic
975 ;; problem is that the `old' file doesn't exist to be
976 ;; visited. This plays hell with numerous assumptions in
977 ;; the diff.el and compile.el machinery.
978 (pop-to-buffer "*vc*")
979 (setq default-directory (file-name-directory file))
980 (if (= 0 (buffer-size))
981 (progn
982 (setq unchanged t)
983 (message "No changes to %s since latest version." file))
984 (goto-char (point-min))
985 (shrink-window-if-larger-than-buffer)))
986 (not unchanged))))
987
988 (defun vc-version-diff (file rel1 rel2)
989 "For FILE, report diffs between two stored versions REL1 and REL2 of it.
990 If FILE is a directory, generate diffs between versions for all registered
991 files in or below it."
992 (interactive "FFile or directory to diff: \nsOlder version: \nsNewer version: ")
993 (if (string-equal rel1 "") (setq rel1 nil))
994 (if (string-equal rel2 "") (setq rel2 nil))
995 (if (file-directory-p file)
996 (let ((camefrom (current-buffer)))
997 (set-buffer (get-buffer-create "*vc-status*"))
998 (set (make-local-variable 'vc-parent-buffer) camefrom)
999 (set (make-local-variable 'vc-parent-buffer-name)
1000 (concat " from " (buffer-name camefrom)))
1001 (erase-buffer)
1002 (insert "Diffs between "
1003 (or rel1 "last version checked in")
1004 " and "
1005 (or rel2 "current workfile(s)")
1006 ":\n\n")
1007 (set-buffer (get-buffer-create "*vc*"))
1008 (cd file)
1009 (vc-file-tree-walk
1010 (function (lambda (f)
1011 (message "Looking at %s" f)
1012 (and
1013 (not (file-directory-p f))
1014 (vc-registered f)
1015 (vc-backend-diff f rel1 rel2)
1016 (append-to-buffer "*vc-status*" (point-min) (point-max)))
1017 )))
1018 (pop-to-buffer "*vc-status*")
1019 (insert "\nEnd of diffs.\n")
1020 (goto-char (point-min))
1021 (set-buffer-modified-p nil)
1022 )
1023 (if (zerop (vc-backend-diff file rel1 rel2))
1024 (message "No changes to %s between %s and %s." file rel1 rel2)
1025 (pop-to-buffer "*vc*"))))
1026
1027 ;;;###autoload
1028 (defun vc-version-other-window (rev)
1029 "Visit version REV of the current buffer in another window.
1030 If the current buffer is named `F', the version is named `F.~REV~'.
1031 If `F.~REV~' already exists, it is used instead of being re-created."
1032 (interactive "sVersion to visit (default is latest version): ")
1033 (if vc-dired-mode
1034 (set-buffer (find-file-noselect (dired-get-filename))))
1035 (while vc-parent-buffer
1036 (pop-to-buffer vc-parent-buffer))
1037 (if (and buffer-file-name (vc-name buffer-file-name))
1038 (let* ((version (if (string-equal rev "")
1039 (vc-latest-version buffer-file-name)
1040 rev))
1041 (filename (concat buffer-file-name ".~" version "~")))
1042 (or (file-exists-p filename)
1043 (vc-backend-checkout buffer-file-name nil version filename))
1044 (find-file-other-window filename))
1045 (vc-registration-error buffer-file-name)))
1046
1047 ;; Header-insertion code
1048
1049 ;;;###autoload
1050 (defun vc-insert-headers ()
1051 "Insert headers in a file for use with your version-control system.
1052 Headers desired are inserted at the start of the buffer, and are pulled from
1053 the variable `vc-header-alist'."
1054 (interactive)
1055 (if vc-dired-mode
1056 (find-file-other-window (dired-get-filename)))
1057 (while vc-parent-buffer
1058 (pop-to-buffer vc-parent-buffer))
1059 (save-excursion
1060 (save-restriction
1061 (widen)
1062 (if (or (not (vc-check-headers))
1063 (y-or-n-p "Version headers already exist. Insert another set? "))
1064 (progn
1065 (let* ((delims (cdr (assq major-mode vc-comment-alist)))
1066 (comment-start-vc (or (car delims) comment-start "#"))
1067 (comment-end-vc (or (car (cdr delims)) comment-end ""))
1068 (hdstrings (cdr (assoc (vc-backend (buffer-file-name)) vc-header-alist))))
1069 (mapcar (function (lambda (s)
1070 (insert comment-start-vc "\t" s "\t"
1071 comment-end-vc "\n")))
1072 hdstrings)
1073 (if vc-static-header-alist
1074 (mapcar (function (lambda (f)
1075 (if (string-match (car f) buffer-file-name)
1076 (insert (format (cdr f) (car hdstrings))))))
1077 vc-static-header-alist))
1078 )
1079 )))))
1080
1081 ;; The VC directory submode. Coopt Dired for this.
1082 ;; All VC commands get mapped into logical equivalents.
1083
1084 (defvar vc-dired-prefix-map (make-sparse-keymap))
1085 (define-key vc-dired-prefix-map "\C-xv" vc-prefix-map)
1086
1087 (or (not (boundp 'minor-mode-map-alist))
1088 (assq 'vc-dired-mode minor-mode-map-alist)
1089 (setq minor-mode-map-alist
1090 (cons (cons 'vc-dired-mode vc-dired-prefix-map)
1091 minor-mode-map-alist)))
1092
1093 (defun vc-dired-mode ()
1094 "The augmented Dired minor mode used in VC directory buffers.
1095 All Dired commands operate normally. Users currently locking listed files
1096 are listed in place of the file's owner and group.
1097 Keystrokes bound to VC commands will execute as though they had been called
1098 on a buffer attached to the file named in the current Dired buffer line."
1099 (setq vc-dired-mode t)
1100 (setq vc-mode " under VC"))
1101
1102 (defun vc-dired-reformat-line (x)
1103 ;; Hack a directory-listing line, plugging in locking-user info in
1104 ;; place of the user and group info. Should have the beneficial
1105 ;; side-effect of shortening the listing line. Each call starts with
1106 ;; point immediately following the dired mark area on the line to be
1107 ;; hacked.
1108 ;;
1109 ;; Simplest possible one:
1110 ;; (insert (concat x "\t")))
1111 ;;
1112 ;; This code, like dired, assumes UNIX -l format.
1113 (forward-word 1) ;; skip over any extra field due to -ibs options
1114 (cond
1115 ;; This hack is used by the CVS code. See vc-locking-user.
1116 ((numberp x)
1117 (cond
1118 ((re-search-forward "\\([0-9]+ \\)\\([^ ]+\\)\\( .*\\)" nil 0)
1119 (save-excursion
1120 (goto-char (match-beginning 2))
1121 (insert "(")
1122 (goto-char (1+ (match-end 2)))
1123 (insert ")")
1124 (delete-char (- 17 (- (match-end 2) (match-beginning 2))))
1125 (insert (substring " " 0
1126 (- 7 (- (match-end 2) (match-beginning 2)))))))))
1127 (t
1128 (if x (setq x (concat "(" x ")")))
1129 (if (re-search-forward "\\([0-9]+ \\).................\\( .*\\)" nil 0)
1130 (let ((rep (substring (concat x " ") 0 9)))
1131 (replace-match (concat "\\1" rep "\\2") t)))
1132 )))
1133
1134 ;;; Note in Emacs 18 the following defun gets overridden
1135 ;;; with the symbol 'vc-directory-18. See below.
1136 ;;;###autoload
1137 (defun vc-directory (verbose)
1138 "Show version-control status of the current directory and subdirectories.
1139 Normally it creates a Dired buffer that lists only the locked files
1140 in all these directories. With a prefix argument, it lists all files."
1141 (interactive "P")
1142 (let (nonempty
1143 (dl (length (expand-file-name default-directory)))
1144 (filelist nil) (userlist nil)
1145 dired-buf
1146 dired-buf-mod-count)
1147 (vc-file-tree-walk
1148 (function (lambda (f)
1149 (if (vc-registered f)
1150 (let ((user (vc-locking-user f)))
1151 (and (or verbose user)
1152 (setq filelist (cons (substring f dl) filelist))
1153 (setq userlist (cons user userlist))))))))
1154 (save-excursion
1155 ;; This uses a semi-documented feature of dired; giving a switch
1156 ;; argument forces the buffer to refresh each time.
1157 (dired
1158 (cons default-directory (nreverse filelist))
1159 dired-listing-switches)
1160 (setq dired-buf (current-buffer))
1161 (setq nonempty (not (zerop (buffer-size)))))
1162 (if nonempty
1163 (progn
1164 (pop-to-buffer dired-buf)
1165 (vc-dired-mode)
1166 (goto-char (point-min))
1167 (setq buffer-read-only nil)
1168 (forward-line 1) ;; Skip header line
1169 (mapcar
1170 (function
1171 (lambda (x)
1172 (forward-char 2) ;; skip dired's mark area
1173 (vc-dired-reformat-line x)
1174 (forward-line 1))) ;; go to next line
1175 (nreverse userlist))
1176 (setq buffer-read-only t)
1177 (goto-char (point-min))
1178 )
1179 (message "No files are currently %s under %s"
1180 (if verbose "registered" "locked") default-directory))
1181 ))
1182
1183 ;; Emacs 18 version
1184 (defun vc-directory-18 (verbose)
1185 "Show version-control status of all files under the current directory."
1186 (interactive "P")
1187 (let (nonempty (dir default-directory))
1188 (save-excursion
1189 (set-buffer (get-buffer-create "*vc-status*"))
1190 (erase-buffer)
1191 (cd dir)
1192 (vc-file-tree-walk
1193 (function (lambda (f)
1194 (if (vc-registered f)
1195 (let ((user (vc-locking-user f)))
1196 (if (or user verbose)
1197 (insert (format
1198 "%s %s\n"
1199 (concat user) f))))))))
1200 (setq nonempty (not (zerop (buffer-size)))))
1201 (if nonempty
1202 (progn
1203 (pop-to-buffer "*vc-status*" t)
1204 (goto-char (point-min))
1205 (shrink-window-if-larger-than-buffer)))
1206 (message "No files are currently %s under %s"
1207 (if verbose "registered" "locked") default-directory))
1208 )
1209
1210 (or (boundp 'minor-mode-map-alist)
1211 (fset 'vc-directory 'vc-directory-18))
1212
1213 ;; Named-configuration support for SCCS
1214
1215 (defun vc-add-triple (name file rev)
1216 (save-excursion
1217 (find-file (expand-file-name
1218 vc-name-assoc-file
1219 (file-name-as-directory
1220 (expand-file-name (vc-backend-subdirectory-name file)
1221 (file-name-directory file)))))
1222 (goto-char (point-max))
1223 (insert name "\t:\t" file "\t" rev "\n")
1224 (basic-save-buffer)
1225 (kill-buffer (current-buffer))
1226 ))
1227
1228 (defun vc-record-rename (file newname)
1229 (save-excursion
1230 (find-file
1231 (expand-file-name
1232 vc-name-assoc-file
1233 (file-name-as-directory
1234 (expand-file-name (vc-backend-subdirectory-name file)
1235 (file-name-directory file)))))
1236 (goto-char (point-min))
1237 ;; (replace-regexp (concat ":" (regexp-quote file) "$") (concat ":" newname))
1238 (while (re-search-forward (concat ":" (regexp-quote file) "$") nil t)
1239 (replace-match (concat ":" newname) nil nil))
1240 (basic-save-buffer)
1241 (kill-buffer (current-buffer))
1242 ))
1243
1244 (defun vc-lookup-triple (file name)
1245 ;; Return the numeric version corresponding to a named snapshot of file
1246 ;; If name is nil or a version number string it's just passed through
1247 (cond ((null name) name)
1248 ((let ((firstchar (aref name 0)))
1249 (and (>= firstchar ?0) (<= firstchar ?9)))
1250 name)
1251 (t
1252 (save-excursion
1253 (set-buffer (get-buffer-create "*vc-info*"))
1254 (vc-insert-file
1255 (expand-file-name
1256 vc-name-assoc-file
1257 (file-name-as-directory
1258 (expand-file-name (vc-backend-subdirectory-name file)
1259 (file-name-directory file)))))
1260 (prog1
1261 (car (vc-parse-buffer
1262 (list (list (concat name "\t:\t" file "\t\\(.+\\)") 1))))
1263 (kill-buffer "*vc-info*"))))
1264 ))
1265
1266 ;; Named-configuration entry points
1267
1268 (defun vc-locked-example ()
1269 ;; Return an example of why the current directory is not ready to be snapshot
1270 ;; or nil if no such example exists.
1271 (catch 'vc-locked-example
1272 (vc-file-tree-walk
1273 (function (lambda (f)
1274 (if (and (vc-registered f) (vc-locking-user f))
1275 (throw 'vc-locked-example f)))))
1276 nil))
1277
1278 ;;;###autoload
1279 (defun vc-create-snapshot (name)
1280 "Make a snapshot called NAME.
1281 The snapshot is made from all registered files at or below the current
1282 directory. For each file, the version level of its latest
1283 version becomes part of the named configuration."
1284 (interactive "sNew snapshot name: ")
1285 (let ((locked (vc-locked-example)))
1286 (if locked
1287 (error "File %s is locked" locked)
1288 (vc-file-tree-walk
1289 (function (lambda (f) (and
1290 (vc-name f)
1291 (vc-backend-assign-name f name)))))
1292 )))
1293
1294 ;;;###autoload
1295 (defun vc-retrieve-snapshot (name)
1296 "Retrieve the snapshot called NAME.
1297 This function fails if any files are locked at or below the current directory
1298 Otherwise, all registered files are checked out (unlocked) at their version
1299 levels in the snapshot."
1300 (interactive "sSnapshot name to retrieve: ")
1301 (let ((locked (vc-locked-example)))
1302 (if locked
1303 (error "File %s is locked" locked)
1304 (vc-file-tree-walk
1305 (function (lambda (f) (and
1306 (vc-name f)
1307 (vc-error-occurred
1308 (vc-checkout f nil name))))))
1309 )))
1310
1311 ;; Miscellaneous other entry points
1312
1313 ;;;###autoload
1314 (defun vc-print-log ()
1315 "List the change log of the current buffer in a window."
1316 (interactive)
1317 (if vc-dired-mode
1318 (set-buffer (find-file-noselect (dired-get-filename))))
1319 (while vc-parent-buffer
1320 (pop-to-buffer vc-parent-buffer))
1321 (if (and buffer-file-name (vc-name buffer-file-name))
1322 (let ((file buffer-file-name))
1323 (vc-backend-print-log file)
1324 (pop-to-buffer (get-buffer-create "*vc*"))
1325 (setq default-directory (file-name-directory file))
1326 (while (looking-at "=*\n")
1327 (delete-char (- (match-end 0) (match-beginning 0)))
1328 (forward-line -1))
1329 (goto-char (point-min))
1330 (if (looking-at "[\b\t\n\v\f\r ]+")
1331 (delete-char (- (match-end 0) (match-beginning 0))))
1332 (shrink-window-if-larger-than-buffer)
1333 )
1334 (vc-registration-error buffer-file-name)
1335 )
1336 )
1337
1338 ;;;###autoload
1339 (defun vc-revert-buffer ()
1340 "Revert the current buffer's file back to the latest checked-in version.
1341 This asks for confirmation if the buffer contents are not identical
1342 to that version.
1343 If the back-end is CVS, this will give you the most recent revision of
1344 the file on the branch you are editing."
1345 (interactive)
1346 (if vc-dired-mode
1347 (find-file-other-window (dired-get-filename)))
1348 (while vc-parent-buffer
1349 (pop-to-buffer vc-parent-buffer))
1350 (let ((file buffer-file-name)
1351 (obuf (current-buffer)) (changed (vc-diff nil t)))
1352 (if (and changed (or vc-suppress-confirm
1353 (not (yes-or-no-p "Discard changes? "))))
1354 (progn
1355 (delete-window)
1356 (error "Revert cancelled"))
1357 (set-buffer obuf))
1358 (if changed
1359 (delete-window))
1360 (vc-backend-revert file)
1361 (vc-resynch-window file t t)
1362 )
1363 )
1364
1365 ;;;###autoload
1366 (defun vc-cancel-version (norevert)
1367 "Get rid of most recently checked in version of this file.
1368 A prefix argument means do not revert the buffer afterwards."
1369 (interactive "P")
1370 (if vc-dired-mode
1371 (find-file-other-window (dired-get-filename)))
1372 (while vc-parent-buffer
1373 (pop-to-buffer vc-parent-buffer))
1374 (if (eq (vc-backend (buffer-file-name)) 'CVS)
1375 (error "Unchecking files under CVS is dangerous and not supported in VC"))
1376 (let* ((target (concat (vc-latest-version (buffer-file-name))))
1377 (yours (concat (vc-your-latest-version (buffer-file-name))))
1378 (prompt (if (string-equal yours target)
1379 "Remove your version %s from master? "
1380 "Version %s was not your change. Remove it anyway? ")))
1381 (if (null (yes-or-no-p (format prompt target)))
1382 nil
1383 (vc-backend-uncheck (buffer-file-name) target)
1384 (if (or norevert
1385 (not (yes-or-no-p "Revert buffer to most recent remaining version? ")))
1386 (vc-mode-line (buffer-file-name))
1387 (vc-checkout (buffer-file-name) nil)))
1388 ))
1389
1390 ;;;###autoload
1391 (defun vc-rename-file (old new)
1392 "Rename file OLD to NEW, and rename its master file likewise."
1393 (interactive "fVC rename file: \nFRename to: ")
1394 ;; There are several ways of renaming files under CVS 1.3, but they all
1395 ;; have serious disadvantages. See the FAQ (available from think.com in
1396 ;; pub/cvs/). I'd rather send the user an error, than do something he might
1397 ;; consider to be wrong. When the famous, long-awaited rename database is
1398 ;; implemented things might change for the better. This is unlikely to occur
1399 ;; until CVS 2.0 is released. --ceder 1994-01-23 21:27:51
1400 (if (eq (vc-backend old) 'CVS)
1401 (error "Renaming files under CVS is dangerous and not supported in VC."))
1402 (let ((oldbuf (get-file-buffer old)))
1403 (if (and oldbuf (buffer-modified-p oldbuf))
1404 (error "Please save files before moving them"))
1405 (if (get-file-buffer new)
1406 (error "Already editing new file name"))
1407 (if (file-exists-p new)
1408 (error "New file already exists"))
1409 (let ((oldmaster (vc-name old)))
1410 (if oldmaster
1411 (progn
1412 (if (vc-locking-user old)
1413 (error "Please check in files before moving them"))
1414 (if (or (file-symlink-p oldmaster)
1415 ;; This had FILE, I changed it to OLD. -- rms.
1416 (file-symlink-p (vc-backend-subdirectory-name old)))
1417 (error "This is not a safe thing to do in the presence of symbolic links"))
1418 (rename-file
1419 oldmaster
1420 (let ((backend (vc-backend old))
1421 (newdir (or (file-name-directory new) ""))
1422 (newbase (file-name-nondirectory new)))
1423 (catch 'found
1424 (mapcar
1425 (function
1426 (lambda (s)
1427 (if (eq backend (cdr s))
1428 (let* ((newmaster (format (car s) newdir newbase))
1429 (newmasterdir (file-name-directory newmaster)))
1430 (if (or (not newmasterdir)
1431 (file-directory-p newmasterdir))
1432 (throw 'found newmaster))))))
1433 vc-master-templates)
1434 (error "New file lacks a version control directory"))))))
1435 (if (or (not oldmaster) (file-exists-p old))
1436 (rename-file old new)))
1437 ; ?? Renaming a file might change its contents due to keyword expansion.
1438 ; We should really check out a new copy if the old copy was precisely equal
1439 ; to some checked in version. However, testing for this is tricky....
1440 (if oldbuf
1441 (save-excursion
1442 (set-buffer oldbuf)
1443 (set-visited-file-name new)
1444 (set-buffer-modified-p nil))))
1445 ;; This had FILE, I changed it to OLD. -- rms.
1446 (vc-backend-dispatch old
1447 (vc-record-rename old new) ;SCCS
1448 nil ;RCS
1449 nil ;CVS
1450 )
1451 )
1452
1453 ;;;###autoload
1454 (defun vc-update-change-log (&rest args)
1455 "Find change log file and add entries from recent RCS logs.
1456 The mark is left at the end of the text prepended to the change log.
1457 With prefix arg of C-u, only find log entries for the current buffer's file.
1458 With any numeric prefix arg, find log entries for all files currently visited.
1459 Otherwise, find log entries for all registered files in the default directory.
1460 From a program, any arguments are passed to the `rcs2log' script."
1461 (interactive
1462 (cond ((consp current-prefix-arg) ;C-u
1463 (list buffer-file-name))
1464 (current-prefix-arg ;Numeric argument.
1465 (let ((files nil)
1466 (buffers (buffer-list))
1467 file)
1468 (while buffers
1469 (setq file (buffer-file-name (car buffers)))
1470 (and file (vc-backend file)
1471 (setq files (cons file files)))
1472 (setq buffers (cdr buffers)))
1473 files))
1474 (t
1475 (let ((RCS (concat default-directory "RCS")))
1476 (and (file-directory-p RCS)
1477 (mapcar (function
1478 (lambda (f)
1479 (if (string-match "\\(.*\\),v$" f)
1480 (substring f 0 (match-end 1))
1481 f)))
1482 (directory-files RCS nil "...\\|^[^.]\\|^.[^.]")))))))
1483 (let ((odefault default-directory))
1484 (find-file-other-window (find-change-log))
1485 (barf-if-buffer-read-only)
1486 (vc-buffer-sync)
1487 (undo-boundary)
1488 (goto-char (point-min))
1489 (push-mark)
1490 (message "Computing change log entries...")
1491 (message "Computing change log entries... %s"
1492 (if (or (null args)
1493 (eq 0 (apply 'call-process "rcs2log" nil t nil
1494 "-u"
1495 (concat (user-login-name)
1496 "\t"
1497 (user-full-name)
1498 "\t"
1499 user-mail-address)
1500 (mapcar (function
1501 (lambda (f)
1502 (file-relative-name
1503 (if (file-name-absolute-p f)
1504 f
1505 (concat odefault f)))))
1506 args))))
1507 "done" "failed"))))
1508
1509 ;; Collect back-end-dependent stuff here
1510
1511 (defun vc-backend-admin (file &optional rev comment)
1512 ;; Register a file into the version-control system
1513 ;; Automatically retrieves a read-only version of the file with
1514 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
1515 ;; it deletes the workfile.
1516 (vc-file-clearprops file)
1517 (or vc-default-back-end
1518 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))
1519 (message "Registering %s..." file)
1520 (let ((backend
1521 (cond
1522 ((file-exists-p (vc-backend-subdirectory-name)) vc-default-back-end)
1523 ((file-exists-p "RCS") 'RCS)
1524 ((file-exists-p "SCCS") 'SCCS)
1525 ((file-exists-p "CVS") 'CVS)
1526 (t vc-default-back-end))))
1527 (cond ((eq backend 'SCCS)
1528 (vc-do-command 0 "admin" file 'MASTER ;; SCCS
1529 (and rev (concat "-r" rev))
1530 "-fb"
1531 (concat "-i" file)
1532 (and comment (concat "-y" comment))
1533 (format
1534 (car (rassq 'SCCS vc-master-templates))
1535 (or (file-name-directory file) "")
1536 (file-name-nondirectory file)))
1537 (delete-file file)
1538 (if vc-keep-workfiles
1539 (vc-do-command 0 "get" file 'MASTER)))
1540 ((eq backend 'RCS)
1541 (vc-do-command 0 "ci" file 'MASTER ;; RCS
1542 (concat (if vc-keep-workfiles "-u" "-r") rev)
1543 (and comment (concat "-t-" comment))
1544 file))
1545 ((eq backend 'CVS)
1546 (vc-do-command 0 "cvs" file 'WORKFILE ;; CVS
1547 "add"
1548 (and comment (not (string= comment ""))
1549 (concat "-m" comment)))
1550 )))
1551 (message "Registering %s...done" file)
1552 )
1553
1554 (defun vc-backend-checkout (file &optional writable rev workfile)
1555 ;; Retrieve a copy of a saved version into a workfile
1556 (let ((filename (or workfile file)))
1557 (message "Checking out %s..." filename)
1558 (save-excursion
1559 ;; Change buffers to get local value of vc-checkin-switches.
1560 (set-buffer (or (get-file-buffer file) (current-buffer)))
1561 (vc-backend-dispatch file
1562 (if workfile;; SCCS
1563 ;; Some SCCS implementations allow checking out directly to a
1564 ;; file using the -G option, but then some don't so use the
1565 ;; least common denominator approach and use the -p option
1566 ;; ala RCS.
1567 (let ((vc-modes (logior (file-modes (vc-name file))
1568 (if writable 128 0)))
1569 (failed t))
1570 (unwind-protect
1571 (progn
1572 (apply 'vc-do-command
1573 0 "/bin/sh" file 'MASTER "-c"
1574 ;; Some shells make the "" dummy argument into $0
1575 ;; while others use the shell's name as $0 and
1576 ;; use the "" as $1. The if-statement
1577 ;; converts the latter case to the former.
1578 (format "if [ x\"$1\" = x ]; then shift; fi; \
1579 umask %o; exec >\"$1\" || exit; \
1580 shift; umask %o; exec get \"$@\""
1581 (logand 511 (lognot vc-modes))
1582 (logand 511 (lognot (default-file-modes))))
1583 "" ; dummy argument for shell's $0
1584 filename
1585 (if writable "-e")
1586 "-p" (and rev
1587 (concat "-r" (vc-lookup-triple file rev)))
1588 vc-checkout-switches)
1589 (setq failed nil))
1590 (and failed (file-exists-p filename) (delete-file filename))))
1591 (apply 'vc-do-command 0 "get" file 'MASTER;; SCCS
1592 (if writable "-e")
1593 (and rev (concat "-r" (vc-lookup-triple file rev)))
1594 vc-checkout-switches)
1595 (vc-file-setprop file 'vc-workfile-version nil))
1596 (if workfile;; RCS
1597 ;; RCS doesn't let us check out into arbitrary file names directly.
1598 ;; Use `co -p' and make stdout point to the correct file.
1599 (let ((vc-modes (logior (file-modes (vc-name file))
1600 (if writable 128 0)))
1601 (failed t))
1602 (unwind-protect
1603 (progn
1604 (apply 'vc-do-command
1605 0 "/bin/sh" file 'MASTER "-c"
1606 ;; See the SCCS case, above, regarding the
1607 ;; if-statement.
1608 (format "if [ x\"$1\" = x ]; then shift; fi; \
1609 umask %o; exec >\"$1\" || exit; \
1610 shift; umask %o; exec co \"$@\""
1611 (logand 511 (lognot vc-modes))
1612 (logand 511 (lognot (default-file-modes))))
1613 "" ; dummy argument for shell's $0
1614 filename
1615 (if writable "-l")
1616 (concat "-p" rev)
1617 vc-checkout-switches)
1618 (setq failed nil))
1619 (and failed (file-exists-p filename) (delete-file filename))))
1620 (progn
1621 (apply 'vc-do-command
1622 0 "co" file 'MASTER
1623 (if writable "-l")
1624 (if rev (concat "-r" rev)
1625 ;; if no explicit revision was specified,
1626 ;; check out that of the working file
1627 (let ((workrev (vc-workfile-version file)))
1628 (if workrev (concat "-r" workrev)
1629 nil)))
1630 vc-checkout-switches)
1631 (save-excursion
1632 (set-buffer "*vc*")
1633 (goto-char (point-min))
1634 (if (re-search-forward "^revision \\([0-9.]+\\).*\n" nil t)
1635 (vc-file-setprop file 'vc-workfile-version
1636 (buffer-substring (match-beginning 1)
1637 (match-end 1)))
1638 (vc-file-setprop file 'vc-workfile-version nil)))))
1639 (if workfile;; CVS
1640 ;; CVS is much like RCS
1641 (let ((failed t))
1642 (unwind-protect
1643 (progn
1644 (apply 'vc-do-command
1645 0 "/bin/sh" file 'WORKFILE "-c"
1646 "exec >\"$1\" || exit; shift; exec cvs update \"$@\""
1647 "" ; dummy argument for shell's $0
1648 workfile
1649 (concat "-r" rev)
1650 "-p"
1651 vc-checkout-switches)
1652 (setq failed nil))
1653 (and failed (file-exists-p filename) (delete-file filename))))
1654 (apply 'vc-do-command 0 "cvs" file 'WORKFILE
1655 "update"
1656 (and rev (concat "-r" rev))
1657 vc-checkout-switches)
1658 (vc-file-setprop file 'vc-workfile-version nil))
1659 ))
1660 (cond
1661 ((not workfile)
1662 (vc-file-clear-masterprops file)
1663 (if writable
1664 (vc-file-setprop file 'vc-locking-user (user-login-name)))
1665 (vc-file-setprop file
1666 'vc-checkout-time (nth 5 (file-attributes file)))))
1667 (message "Checking out %s...done" filename))
1668 )
1669
1670 (defun vc-backend-logentry-check (file)
1671 (vc-backend-dispatch file
1672 (if (>= (buffer-size) 512) ;; SCCS
1673 (progn
1674 (goto-char 512)
1675 (error
1676 "Log must be less than 512 characters; point is now at pos 512")))
1677 nil ;; RCS
1678 nil) ;; CVS
1679 )
1680
1681 (defun vc-backend-checkin (file rev comment)
1682 ;; Register changes to FILE as level REV with explanatory COMMENT.
1683 ;; Automatically retrieves a read-only version of the file with
1684 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
1685 ;; it deletes the workfile.
1686 ;; Adaption for RCS branch support: if this is an explicit checkin,
1687 ;; or if the checkin creates a new branch, set the master file branch
1688 ;; accordingly.
1689 (message "Checking in %s..." file)
1690 ;; "This log message intentionally left almost blank".
1691 (and (or (not comment) (string= comment ""))
1692 (setq comment "*** empty log message ***"))
1693 (save-excursion
1694 ;; Change buffers to get local value of vc-checkin-switches.
1695 (set-buffer (or (get-file-buffer file) (current-buffer)))
1696 (vc-backend-dispatch file
1697 ;; SCCS
1698 (progn
1699 (apply 'vc-do-command 0 "delta" file 'MASTER
1700 (if rev (concat "-r" rev))
1701 (concat "-y" comment)
1702 vc-checkin-switches)
1703 (vc-file-setprop file 'vc-locking-user 'none)
1704 (vc-file-setprop file 'vc-workfile-version nil)
1705 (if vc-keep-workfiles
1706 (vc-do-command 0 "get" file 'MASTER))
1707 )
1708 ;; RCS
1709 (let ((old-version (vc-workfile-version file)) new-version)
1710 (apply 'vc-do-command 0 "ci" file 'MASTER
1711 (concat (if vc-keep-workfiles "-u" "-r") rev)
1712 (concat "-m" comment)
1713 vc-checkin-switches)
1714 (vc-file-setprop file 'vc-locking-user 'none)
1715 (vc-file-setprop file 'vc-workfile-version nil)
1716
1717 ;; determine the new workfile version
1718 (set-buffer "*vc*")
1719 (goto-char (point-min))
1720 (if (or (re-search-forward
1721 "new revision: \\([0-9.]+\\);" nil t)
1722 (re-search-forward
1723 "reverting to previous revision \\([0-9.]+\\)" nil t))
1724 (progn (setq new-version (buffer-substring (match-beginning 1)
1725 (match-end 1)))
1726 (vc-file-setprop file 'vc-workfile-version new-version)))
1727
1728 ;; if we got to a different branch, adjust the default
1729 ;; branch accordingly, and remove any remaining
1730 ;; lock on the old version.
1731 (cond
1732 ((and old-version new-version
1733 (not (string= (vc-branch-part old-version)
1734 (vc-branch-part new-version))))
1735 (vc-do-command 0 "rcs" file 'MASTER
1736 (if (vc-trunk-p new-version) "-b"
1737 (concat "-b" (vc-branch-part new-version))))
1738 ;; exit status of 1 is also accepted.
1739 ;; It means that the lock was removed before.
1740 (vc-do-command 1 "rcs" file 'MASTER
1741 (concat "-u" old-version)))))
1742 ;; CVS
1743 (progn
1744 ;; explicit check-in to the trunk requires a
1745 ;; double check-in (first unexplicit) (CVS-1.3)
1746 (if (and rev (vc-trunk-p rev))
1747 (apply 'vc-do-command 0 "cvs" file 'WORKFILE
1748 "ci" "-m" "intermediate"
1749 vc-checkin-switches))
1750 (apply 'vc-do-command 0 "cvs" file 'WORKFILE
1751 "ci" (if rev (concat "-r" rev))
1752 (concat "-m" comment)
1753 vc-checkin-switches)
1754 ;; determine and store the new workfile version
1755 (set-buffer "*vc*")
1756 (goto-char (point-min))
1757 (if (re-search-forward
1758 "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" nil t)
1759 (vc-file-setprop file 'vc-workfile-version
1760 (buffer-substring (match-beginning 2)
1761 (match-end 2)))
1762 (vc-file-setprop file 'vc-workfile-version nil))
1763 ;; if this was an explicit check-in, remove the sticky tag
1764 (if rev
1765 (vc-do-command 0 "cvs" file 'WORKFILE "update" "-A"))
1766 (vc-file-setprop file 'vc-locking-user 'none)
1767 (vc-file-setprop file 'vc-checkout-time
1768 (nth 5 (file-attributes file))))))
1769 (vc-file-clear-masterprops file)
1770 (message "Checking in %s...done" file))
1771
1772 (defun vc-backend-revert (file)
1773 ;; Revert file to latest checked-in version.
1774 ;; (for RCS, to workfile version)
1775 (message "Reverting %s..." file)
1776 (vc-backend-dispatch
1777 file
1778 ;; SCCS
1779 (progn
1780 (vc-do-command 0 "unget" file 'MASTER nil)
1781 (vc-do-command 0 "get" file 'MASTER nil))
1782 ;; RCS
1783 (vc-do-command 0 "co" file 'MASTER
1784 "-f" (concat "-u" (vc-workfile-version file)))
1785 ;; CVS
1786 (progn
1787 (delete-file file)
1788 (vc-do-command 0 "cvs" file 'WORKFILE "update")))
1789 (vc-file-setprop file 'vc-locking-user 'none)
1790 (vc-file-setprop file 'vc-checkout-time (nth 5 (file-attributes file)))
1791 (message "Reverting %s...done" file)
1792 )
1793
1794 (defun vc-backend-steal (file &optional rev)
1795 ;; Steal the lock on the current workfile. Needs RCS 5.6.2 or later for -M.
1796 (message "Stealing lock on %s..." file)
1797 (vc-backend-dispatch file
1798 (progn ;SCCS
1799 (vc-do-command 0 "unget" file 'MASTER "-n" (if rev (concat "-r" rev)))
1800 (vc-do-command 0 "get" file 'MASTER "-g" (if rev (concat "-r" rev)))
1801 )
1802 (vc-do-command 0 "rcs" file 'MASTER ;RCS
1803 "-M" (concat "-u" rev) (concat "-l" rev))
1804 (error "You cannot steal a CVS lock; there are no CVS locks to steal.") ;CVS
1805 )
1806 (vc-file-setprop file 'vc-locking-user (user-login-name))
1807 (message "Stealing lock on %s...done" file)
1808 )
1809
1810 (defun vc-backend-uncheck (file target)
1811 ;; Undo the latest checkin. Note: this code will have to get a lot
1812 ;; smarter when we support multiple branches.
1813 (message "Removing last change from %s..." file)
1814 (vc-backend-dispatch file
1815 (vc-do-command 0 "rmdel" file 'MASTER (concat "-r" target))
1816 (vc-do-command 0 "rcs" file 'MASTER (concat "-o" target))
1817 nil ;; this is never reached under CVS
1818 )
1819 (message "Removing last change from %s...done" file)
1820 )
1821
1822 (defun vc-backend-print-log (file)
1823 ;; Print change log associated with FILE to buffer *vc*.
1824 (vc-backend-dispatch
1825 file
1826 (vc-do-command 0 "prs" file 'MASTER)
1827 (vc-do-command 0 "rlog" file 'MASTER)
1828 (vc-do-command 0 "cvs" file 'WORKFILE "rlog")))
1829
1830 (defun vc-backend-assign-name (file name)
1831 ;; Assign to a FILE's latest version a given NAME.
1832 (vc-backend-dispatch file
1833 (vc-add-triple name file (vc-latest-version file)) ;; SCCS
1834 (vc-do-command 0 "rcs" file 'MASTER (concat "-n" name ":")) ;; RCS
1835 (vc-do-command 0 "cvs" file 'WORKFILE "tag" name) ;; CVS
1836 )
1837 )
1838
1839 (defun vc-backend-diff (file &optional oldvers newvers cmp)
1840 ;; Get a difference report between two versions of FILE.
1841 ;; Get only a brief comparison report if CMP, a difference report otherwise.
1842 (let ((backend (vc-backend file)))
1843 (cond
1844 ((eq backend 'SCCS)
1845 (setq oldvers (vc-lookup-triple file oldvers))
1846 (setq newvers (vc-lookup-triple file newvers)))
1847 ((eq backend 'RCS)
1848 (if (not oldvers) (setq oldvers (vc-workfile-version file)))))
1849 ;; SCCS and RCS shares a lot of code.
1850 (cond
1851 ((or (eq backend 'SCCS) (eq backend 'RCS))
1852 (let* ((command (if (eq backend 'SCCS)
1853 "vcdiff"
1854 "rcsdiff"))
1855 (mode (if (eq backend 'RCS) 'WORKFILE 'MASTER))
1856 (options (append (list (and cmp "--brief")
1857 "-q"
1858 (and oldvers (concat "-r" oldvers))
1859 (and newvers (concat "-r" newvers)))
1860 (and (not cmp)
1861 (if (listp diff-switches)
1862 diff-switches
1863 (list diff-switches)))))
1864 (status (apply 'vc-do-command 2 command file mode options)))
1865 ;; Some RCS versions don't understand "--brief"; work around this.
1866 (if (eq status 2)
1867 (apply 'vc-do-command 1 command file 'WORKFILE
1868 (if cmp (cdr options) options))
1869 status)))
1870 ;; CVS is different.
1871 ;; cmp is not yet implemented -- we always do a full diff.
1872 ((eq backend 'CVS)
1873 (if (string= (vc-workfile-version file) "0") ;CVS
1874 ;; This file is added but not yet committed; there is no master file.
1875 ;; diff it against /dev/null.
1876 (if (or oldvers newvers)
1877 (error "No revisions of %s exists" file)
1878 (apply 'vc-do-command
1879 1 "diff" file 'WORKFILE "/dev/null"
1880 (if (listp diff-switches)
1881 diff-switches
1882 (list diff-switches))))
1883 (apply 'vc-do-command
1884 1 "cvs" file 'WORKFILE "diff"
1885 (and oldvers (concat "-r" oldvers))
1886 (and newvers (concat "-r" newvers))
1887 (if (listp diff-switches)
1888 diff-switches
1889 (list diff-switches)))))
1890 (t
1891 (vc-registration-error file)))))
1892
1893 (defun vc-backend-merge-news (file)
1894 ;; Merge in any new changes made to FILE.
1895 (vc-backend-dispatch
1896 file
1897 (error "vc-backend-merge-news not meaningful for SCCS files") ;SCCS
1898 (error "vc-backend-merge-news not meaningful for RCS files") ;RCS
1899 (vc-do-command 1 "cvs" file 'WORKFILE "update") ;CVS
1900 ))
1901
1902 (defun vc-check-headers ()
1903 "Check if the current file has any headers in it."
1904 (interactive)
1905 (save-excursion
1906 (goto-char (point-min))
1907 (vc-backend-dispatch buffer-file-name
1908 (re-search-forward "%[MIRLBSDHTEGUYFPQCZWA]%" nil t) ;; SCCS
1909 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t) ;; RCS
1910 'RCS ;; CVS works like RCS in this regard.
1911 )
1912 ))
1913
1914 ;; Back-end-dependent stuff ends here.
1915
1916 ;; Set up key bindings for use while editing log messages
1917
1918 (defun vc-log-mode ()
1919 "Minor mode for driving version-control tools.
1920 These bindings are added to the global keymap when you enter this mode:
1921 \\[vc-next-action] perform next logical version-control operation on current file
1922 \\[vc-register] register current file
1923 \\[vc-toggle-read-only] like next-action, but won't register files
1924 \\[vc-insert-headers] insert version-control headers in current file
1925 \\[vc-print-log] display change history of current file
1926 \\[vc-revert-buffer] revert buffer to latest version
1927 \\[vc-cancel-version] undo latest checkin
1928 \\[vc-diff] show diffs between file versions
1929 \\[vc-version-other-window] visit old version in another window
1930 \\[vc-directory] show all files locked by any user in or below .
1931 \\[vc-update-change-log] add change log entry from recent checkins
1932
1933 While you are entering a change log message for a version, the following
1934 additional bindings will be in effect.
1935
1936 \\[vc-finish-logentry] proceed with check in, ending log message entry
1937
1938 Whenever you do a checkin, your log comment is added to a ring of
1939 saved comments. These can be recalled as follows:
1940
1941 \\[vc-next-comment] replace region with next message in comment ring
1942 \\[vc-previous-comment] replace region with previous message in comment ring
1943 \\[vc-comment-search-reverse] search backward for regexp in the comment ring
1944 \\[vc-comment-search-forward] search backward for regexp in the comment ring
1945
1946 Entry to the change-log submode calls the value of text-mode-hook, then
1947 the value of vc-log-mode-hook.
1948
1949 Global user options:
1950 vc-initial-comment If non-nil, require user to enter a change
1951 comment upon first checkin of the file.
1952
1953 vc-keep-workfiles Non-nil value prevents workfiles from being
1954 deleted when changes are checked in
1955
1956 vc-suppress-confirm Suppresses some confirmation prompts,
1957 notably for reversions.
1958
1959 vc-header-alist Which keywords to insert when adding headers
1960 with \\[vc-insert-headers]. Defaults to
1961 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under
1962 RCS and CVS.
1963
1964 vc-static-header-alist By default, version headers inserted in C files
1965 get stuffed in a static string area so that
1966 ident(RCS/CVS) or what(SCCS) can see them in
1967 the compiled object code. You can override
1968 this by setting this variable to nil, or change
1969 the header template by changing it.
1970
1971 vc-command-messages if non-nil, display run messages from the
1972 actual version-control utilities (this is
1973 intended primarily for people hacking vc
1974 itself).
1975 "
1976 (interactive)
1977 (set-syntax-table text-mode-syntax-table)
1978 (use-local-map vc-log-entry-mode)
1979 (setq local-abbrev-table text-mode-abbrev-table)
1980 (setq major-mode 'vc-log-mode)
1981 (setq mode-name "VC-Log")
1982 (make-local-variable 'vc-log-file)
1983 (make-local-variable 'vc-log-version)
1984 (make-local-variable 'vc-comment-ring-index)
1985 (set-buffer-modified-p nil)
1986 (setq buffer-file-name nil)
1987 (run-hooks 'text-mode-hook 'vc-log-mode-hook)
1988 )
1989
1990 ;; Initialization code, to be done just once at load-time
1991 (if vc-log-entry-mode
1992 nil
1993 (setq vc-log-entry-mode (make-sparse-keymap))
1994 (define-key vc-log-entry-mode "\M-n" 'vc-next-comment)
1995 (define-key vc-log-entry-mode "\M-p" 'vc-previous-comment)
1996 (define-key vc-log-entry-mode "\M-r" 'vc-comment-search-reverse)
1997 (define-key vc-log-entry-mode "\M-s" 'vc-comment-search-forward)
1998 (define-key vc-log-entry-mode "\C-c\C-c" 'vc-finish-logentry)
1999 )
2000
2001 ;;; These things should probably be generally available
2002
2003 (defun vc-file-tree-walk (func &rest args)
2004 "Walk recursively through default directory.
2005 Invoke FUNC f ARGS on each non-directory file f underneath it."
2006 (vc-file-tree-walk-internal (expand-file-name default-directory) func args)
2007 (message "Traversing directory %s...done" default-directory))
2008
2009 (defun vc-file-tree-walk-internal (file func args)
2010 (if (not (file-directory-p file))
2011 (apply func file args)
2012 (message "Traversing directory %s..." (abbreviate-file-name file))
2013 (let ((dir (file-name-as-directory file)))
2014 (mapcar
2015 (function
2016 (lambda (f) (or
2017 (string-equal f ".")
2018 (string-equal f "..")
2019 (member f vc-directory-exclusion-list)
2020 (let ((dirf (concat dir f)))
2021 (or
2022 (file-symlink-p dirf) ;; Avoid possible loops
2023 (vc-file-tree-walk-internal dirf func args))))))
2024 (directory-files dir)))))
2025
2026 (provide 'vc)
2027
2028 ;;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
2029 ;;;
2030 ;;; These may be useful to anyone who has to debug or extend the package.
2031 ;;; (Note that this information corresponds to versions 5.x. Some of it
2032 ;;; might have been invalidated by the additions to support branching
2033 ;;; and RCS keyword lookup. AS, 1995/03/24)
2034 ;;;
2035 ;;; A fundamental problem in VC is that there are time windows between
2036 ;;; vc-next-action's computations of the file's version-control state and
2037 ;;; the actions that change it. This is a window open to lossage in a
2038 ;;; multi-user environment; someone else could nip in and change the state
2039 ;;; of the master during it.
2040 ;;;
2041 ;;; The performance problem is that rlog/prs calls are very expensive; we want
2042 ;;; to avoid them as much as possible.
2043 ;;;
2044 ;;; ANALYSIS:
2045 ;;;
2046 ;;; The performance problem, it turns out, simplifies in practice to the
2047 ;;; problem of making vc-locking-user fast. The two other functions that call
2048 ;;; prs/rlog will not be so commonly used that the slowdown is a problem; one
2049 ;;; makes snapshots, the other deletes the calling user's last change in the
2050 ;;; master.
2051 ;;;
2052 ;;; The race condition implies that we have to either (a) lock the master
2053 ;;; during the entire execution of vc-next-action, or (b) detect and
2054 ;;; recover from errors resulting from dispatch on an out-of-date state.
2055 ;;;
2056 ;;; Alternative (a) appears to be unfeasible. The problem is that we can't
2057 ;;; guarantee that the lock will ever be removed. Suppose a user starts a
2058 ;;; checkin, the change message buffer pops up, and the user, having wandered
2059 ;;; off to do something else, simply forgets about it?
2060 ;;;
2061 ;;; Alternative (b), on the other hand, works well with a cheap way to speed up
2062 ;;; vc-locking-user. Usually, if a file is registered, we can read its locked/
2063 ;;; unlocked state and its current owner from its permissions.
2064 ;;;
2065 ;;; This shortcut will fail if someone has manually changed the workfile's
2066 ;;; permissions; also if developers are munging the workfile in several
2067 ;;; directories, with symlinks to a master (in this latter case, the
2068 ;;; permissions shortcut will fail to detect a lock asserted from another
2069 ;;; directory).
2070 ;;;
2071 ;;; Note that these cases correspond exactly to the errors which could happen
2072 ;;; because of a competing checkin/checkout race in between two instances of
2073 ;;; vc-next-action.
2074 ;;;
2075 ;;; For VC's purposes, a workfile/master pair may have the following states:
2076 ;;;
2077 ;;; A. Unregistered. There is a workfile, there is no master.
2078 ;;;
2079 ;;; B. Registered and not locked by anyone.
2080 ;;;
2081 ;;; C. Locked by calling user and unchanged.
2082 ;;;
2083 ;;; D. Locked by the calling user and changed.
2084 ;;;
2085 ;;; E. Locked by someone other than the calling user.
2086 ;;;
2087 ;;; This makes for 25 states and 20 error conditions. Here's the matrix:
2088 ;;;
2089 ;;; VC's idea of state
2090 ;;; |
2091 ;;; V Actual state RCS action SCCS action Effect
2092 ;;; A B C D E
2093 ;;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
2094 ;;; B 5 . 6 7 8 co -l get -e checkout
2095 ;;; C 9 10 . 11 12 co -u unget; get revert
2096 ;;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
2097 ;;; E 17 18 19 20 . rcs -u -M ; rcs -l unget -n ; get -g steal lock
2098 ;;;
2099 ;;; All commands take the master file name as a last argument (not shown).
2100 ;;;
2101 ;;; In the discussion below, a "self-race" is a pathological situation in
2102 ;;; which VC operations are being attempted simultaneously by two or more
2103 ;;; Emacsen running under the same username.
2104 ;;;
2105 ;;; The vc-next-action code has the following windows:
2106 ;;;
2107 ;;; Window P:
2108 ;;; Between the check for existence of a master file and the call to
2109 ;;; admin/checkin in vc-buffer-admin (apparent state A). This window may
2110 ;;; never close if the initial-comment feature is on.
2111 ;;;
2112 ;;; Window Q:
2113 ;;; Between the call to vc-workfile-unchanged-p in and the immediately
2114 ;;; following revert (apparent state C).
2115 ;;;
2116 ;;; Window R:
2117 ;;; Between the call to vc-workfile-unchanged-p in and the following
2118 ;;; checkin (apparent state D). This window may never close.
2119 ;;;
2120 ;;; Window S:
2121 ;;; Between the unlock and the immediately following checkout during a
2122 ;;; revert operation (apparent state C). Included in window Q.
2123 ;;;
2124 ;;; Window T:
2125 ;;; Between vc-locking-user and the following checkout (apparent state B).
2126 ;;;
2127 ;;; Window U:
2128 ;;; Between vc-locking-user and the following revert (apparent state C).
2129 ;;; Includes windows Q and S.
2130 ;;;
2131 ;;; Window V:
2132 ;;; Between vc-locking-user and the following checkin (apparent state
2133 ;;; D). This window may never be closed if the user fails to complete the
2134 ;;; checkin message. Includes window R.
2135 ;;;
2136 ;;; Window W:
2137 ;;; Between vc-locking-user and the following steal-lock (apparent
2138 ;;; state E). This window may never close if the user fails to complete
2139 ;;; the steal-lock message. Includes window X.
2140 ;;;
2141 ;;; Window X:
2142 ;;; Between the unlock and the immediately following re-lock during a
2143 ;;; steal-lock operation (apparent state E). This window may never cloce
2144 ;;; if the user fails to complete the steal-lock message.
2145 ;;;
2146 ;;; Errors:
2147 ;;;
2148 ;;; Apparent state A ---
2149 ;;;
2150 ;;; 1. File looked unregistered but is actually registered and not locked.
2151 ;;;
2152 ;;; Potential cause: someone else's admin during window P, with
2153 ;;; caller's admin happening before their checkout.
2154 ;;;
2155 ;;; RCS: ci will fail with a "no lock set by <user>" message.
2156 ;;; SCCS: admin will fail with error (ad19).
2157 ;;;
2158 ;;; We can let these errors be passed up to the user.
2159 ;;;
2160 ;;; 2. File looked unregistered but is actually locked by caller, unchanged.
2161 ;;;
2162 ;;; Potential cause: self-race during window P.
2163 ;;;
2164 ;;; RCS: will revert the file to the last saved version and unlock it.
2165 ;;; SCCS: will fail with error (ad19).
2166 ;;;
2167 ;;; Either of these consequences is acceptable.
2168 ;;;
2169 ;;; 3. File looked unregistered but is actually locked by caller, changed.
2170 ;;;
2171 ;;; Potential cause: self-race during window P.
2172 ;;;
2173 ;;; RCS: will register the caller's workfile as a delta with a
2174 ;;; null change comment (the -t- switch will be ignored).
2175 ;;; SCCS: will fail with error (ad19).
2176 ;;;
2177 ;;; 4. File looked unregistered but is locked by someone else.
2178 ;;;
2179 ;;; Potential cause: someone else's admin during window P, with
2180 ;;; caller's admin happening *after* their checkout.
2181 ;;;
2182 ;;; RCS: will fail with a "no lock set by <user>" message.
2183 ;;; SCCS: will fail with error (ad19).
2184 ;;;
2185 ;;; We can let these errors be passed up to the user.
2186 ;;;
2187 ;;; Apparent state B ---
2188 ;;;
2189 ;;; 5. File looked registered and not locked, but is actually unregistered.
2190 ;;;
2191 ;;; Potential cause: master file got nuked during window P.
2192 ;;;
2193 ;;; RCS: will fail with "RCS/<file>: No such file or directory"
2194 ;;; SCCS: will fail with error ut4.
2195 ;;;
2196 ;;; We can let these errors be passed up to the user.
2197 ;;;
2198 ;;; 6. File looked registered and not locked, but is actually locked by the
2199 ;;; calling user and unchanged.
2200 ;;;
2201 ;;; Potential cause: self-race during window T.
2202 ;;;
2203 ;;; RCS: in the same directory as the previous workfile, co -l will fail
2204 ;;; with "co error: writable foo exists; checkout aborted". In any other
2205 ;;; directory, checkout will succeed.
2206 ;;; SCCS: will fail with ge17.
2207 ;;;
2208 ;;; Either of these consequences is acceptable.
2209 ;;;
2210 ;;; 7. File looked registered and not locked, but is actually locked by the
2211 ;;; calling user and changed.
2212 ;;;
2213 ;;; As case 6.
2214 ;;;
2215 ;;; 8. File looked registered and not locked, but is actually locked by another
2216 ;;; user.
2217 ;;;
2218 ;;; Potential cause: someone else checks it out during window T.
2219 ;;;
2220 ;;; RCS: co error: revision 1.3 already locked by <user>
2221 ;;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
2222 ;;;
2223 ;;; We can let these errors be passed up to the user.
2224 ;;;
2225 ;;; Apparent state C ---
2226 ;;;
2227 ;;; 9. File looks locked by calling user and unchanged, but is unregistered.
2228 ;;;
2229 ;;; As case 5.
2230 ;;;
2231 ;;; 10. File looks locked by calling user and unchanged, but is actually not
2232 ;;; locked.
2233 ;;;
2234 ;;; Potential cause: a self-race in window U, or by the revert's
2235 ;;; landing during window X of some other user's steal-lock or window S
2236 ;;; of another user's revert.
2237 ;;;
2238 ;;; RCS: succeeds, refreshing the file from the identical version in
2239 ;;; the master.
2240 ;;; SCCS: fails with error ut4 (p file nonexistent).
2241 ;;;
2242 ;;; Either of these consequences is acceptable.
2243 ;;;
2244 ;;; 11. File is locked by calling user. It looks unchanged, but is actually
2245 ;;; changed.
2246 ;;;
2247 ;;; Potential cause: the file would have to be touched by a self-race
2248 ;;; during window Q.
2249 ;;;
2250 ;;; The revert will succeed, removing whatever changes came with
2251 ;;; the touch. It is theoretically possible that work could be lost.
2252 ;;;
2253 ;;; 12. File looks like it's locked by the calling user and unchanged, but
2254 ;;; it's actually locked by someone else.
2255 ;;;
2256 ;;; Potential cause: a steal-lock in window V.
2257 ;;;
2258 ;;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
2259 ;;; SCCS: fails with error un2
2260 ;;;
2261 ;;; We can pass these errors up to the user.
2262 ;;;
2263 ;;; Apparent state D ---
2264 ;;;
2265 ;;; 13. File looks like it's locked by the calling user and changed, but it's
2266 ;;; actually unregistered.
2267 ;;;
2268 ;;; Potential cause: master file got nuked during window P.
2269 ;;;
2270 ;;; RCS: Checks in the user's version as an initial delta.
2271 ;;; SCCS: will fail with error ut4.
2272 ;;;
2273 ;;; This case is kind of nasty. It means VC may fail to detect the
2274 ;;; loss of previous version information.
2275 ;;;
2276 ;;; 14. File looks like it's locked by the calling user and changed, but it's
2277 ;;; actually unlocked.
2278 ;;;
2279 ;;; Potential cause: self-race in window V, or the checkin happening
2280 ;;; during the window X of someone else's steal-lock or window S of
2281 ;;; someone else's revert.
2282 ;;;
2283 ;;; RCS: ci will fail with "no lock set by <user>".
2284 ;;; SCCS: delta will fail with error ut4.
2285 ;;;
2286 ;;; 15. File looks like it's locked by the calling user and changed, but it's
2287 ;;; actually locked by the calling user and unchanged.
2288 ;;;
2289 ;;; Potential cause: another self-race --- a whole checkin/checkout
2290 ;;; sequence by the calling user would have to land in window R.
2291 ;;;
2292 ;;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
2293 ;;; RCS: reverts to the file state as of the second user's checkin, leaving
2294 ;;; the file unlocked.
2295 ;;;
2296 ;;; It is theoretically possible that work could be lost under RCS.
2297 ;;;
2298 ;;; 16. File looks like it's locked by the calling user and changed, but it's
2299 ;;; actually locked by a different user.
2300 ;;;
2301 ;;; RCS: ci error: no lock set by <user>
2302 ;;; SCCS: unget will fail with error un2
2303 ;;;
2304 ;;; We can pass these errors up to the user.
2305 ;;;
2306 ;;; Apparent state E ---
2307 ;;;
2308 ;;; 17. File looks like it's locked by some other user, but it's actually
2309 ;;; unregistered.
2310 ;;;
2311 ;;; As case 13.
2312 ;;;
2313 ;;; 18. File looks like it's locked by some other user, but it's actually
2314 ;;; unlocked.
2315 ;;;
2316 ;;; Potential cause: someone released a lock during window W.
2317 ;;;
2318 ;;; RCS: The calling user will get the lock on the file.
2319 ;;; SCCS: unget -n will fail with cm4.
2320 ;;;
2321 ;;; Either of these consequences will be OK.
2322 ;;;
2323 ;;; 19. File looks like it's locked by some other user, but it's actually
2324 ;;; locked by the calling user and unchanged.
2325 ;;;
2326 ;;; Potential cause: the other user relinquishing a lock followed by
2327 ;;; a self-race, both in window W.
2328 ;;;
2329 ;;; Under both RCS and SCCS, both unlock and lock will succeed, making
2330 ;;; the sequence a no-op.
2331 ;;;
2332 ;;; 20. File looks like it's locked by some other user, but it's actually
2333 ;;; locked by the calling user and changed.
2334 ;;;
2335 ;;; As case 19.
2336 ;;;
2337 ;;; PROBLEM CASES:
2338 ;;;
2339 ;;; In order of decreasing severity:
2340 ;;;
2341 ;;; Cases 11 and 15 under RCS are the only one that potentially lose work.
2342 ;;; They would require a self-race for this to happen.
2343 ;;;
2344 ;;; Case 13 in RCS loses information about previous deltas, retaining
2345 ;;; only the information in the current workfile. This can only happen
2346 ;;; if the master file gets nuked in window P.
2347 ;;;
2348 ;;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
2349 ;;; no change comment in the master. This would require a self-race in
2350 ;;; window P or R respectively.
2351 ;;;
2352 ;;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
2353 ;;;
2354 ;;; Unfortunately, it appears to me that no recovery is possible in these
2355 ;;; cases. They don't yield error messages, so there's no way to tell that
2356 ;;; a race condition has occurred.
2357 ;;;
2358 ;;; All other cases don't change either the workfile or the master, and
2359 ;;; trigger command errors which the user will see.
2360 ;;;
2361 ;;; Thus, there is no explicit recovery code.
2362
2363 ;;; vc.el ends here