1 ;;; vc.el --- drive a version-control system from within Emacs
3 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
6 ;; Maintainer: eggert@twinsun.com
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 ;; This mode is fully documented in the Emacs user's manual.
29 ;; This was designed and implemented by Eric Raymond <esr@snark.thyrsus.com>.
30 ;; Paul Eggert <eggert@twinsun.com>, Sebastian Kremer <sk@thp.uni-koeln.de>,
31 ;; and Richard Stallman contributed valuable criticism, support, and testing.
33 ;; Supported version-control systems presently include SCCS and RCS;
34 ;; the RCS lock-stealing code doesn't work right unless you use RCS 5.6.2
35 ;; or newer. Currently (January 1994) that is only a beta test release.
37 ;; The RCS code assumes strict locking. You can support the RCS -x option
38 ;; by adding pairs to the vc-master-templates list.
40 ;; Proper function of the SCCS diff commands requires the shellscript vcdiff
41 ;; to be installed somewhere on Emacs's path for executables.
43 ;; If your site uses the ChangeLog convention supported by Emacs, the
44 ;; function vc-comment-to-change-log should prove a useful checkin hook.
46 ;; This code depends on call-process passing back the subprocess exit
47 ;; status. Thus, you need Emacs 18.58 or later to run it. For the
48 ;; vc-directory command to work properly as documented, you need 19.
49 ;; You also need Emacs 19's ring.el.
51 ;; The vc code maintains some internal state in order to reduce expensive
52 ;; version-control operations to a minimum. Some names are only computed
53 ;; once. If you perform version control operations with RCS/SCCS/CVS while
54 ;; vc's back is turned, or move/rename master files while vc is running,
55 ;; vc may get seriously confused. Don't do these things!
57 ;; Developer's notes on some concurrency issues are included at the end of
65 (if (not (assoc 'vc-parent-buffer minor-mode-alist))
66 (setq minor-mode-alist
67 (cons '(vc-parent-buffer vc-parent-buffer-name)
70 ;; General customization
72 (defvar vc-default-back-end nil
73 "*Back-end actually used by this interface; may be SCCS or RCS.
74 The value is only computed when needed to avoid an expensive search.")
75 (defvar vc-suppress-confirm nil
76 "*If non-nil, treat user as expert; suppress yes-no prompts on some things.")
77 (defvar vc-keep-workfiles t
78 "*If non-nil, don't delete working files after registering changes.")
79 (defvar vc-initial-comment nil
80 "*Prompt for initial comment when a file is registered.")
81 (defvar vc-command-messages nil
82 "*Display run messages from back-end commands.")
83 (defvar vc-mistrust-permissions 'file-symlink-p
84 "*Don't assume that permissions and ownership track version-control status.")
85 (defvar vc-checkin-switches nil
86 "*Extra switches passed to the checkin program by \\[vc-checkin].")
88 (if (file-exists-p "/usr/sccs")
90 "*List of extra directories to search for version control commands.")
92 (defconst vc-maximum-comment-ring-size 32
93 "Maximum number of saved comments in the comment ring.")
95 ;;; This is duplicated in diff.el.
96 (defvar diff-switches "-c"
97 "*A string or list of strings specifying switches to be be passed to diff.")
100 (defvar vc-checkin-hook nil
101 "*List of functions called after a checkin is done. See `run-hooks'.")
103 ;; Header-insertion hair
105 (defvar vc-header-alist
106 '((SCCS "\%W\%") (RCS "\$Id\$"))
107 "*Header keywords to be inserted when `vc-insert-headers' is executed.")
108 (defvar vc-static-header-alist
110 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
111 "*Associate static header string templates with file types. A \%s in the
112 template is replaced with the first string associated with the file's
113 version-control type in `vc-header-alist'.")
115 (defvar vc-comment-alist
116 '((nroff-mode ".\\\"" ""))
117 "*Special comment delimiters to be used in generating vc headers only.
118 Add an entry in this list if you need to override the normal comment-start
119 and comment-end variables. This will only be necessary if the mode language
120 is sensitive to blank lines.")
122 ;; Default is to be extra careful for super-user.
123 (defvar vc-checkout-carefully (= (user-uid) 0)
124 "*Non-nil means be extra-careful in checkout.
125 Verify that the file really is not locked
126 and that its contents match what the master file says.")
128 ;; Variables the user doesn't need to know about.
129 (defvar vc-log-entry-mode nil)
130 (defvar vc-log-operation nil)
131 (defvar vc-log-after-operation-hook nil)
132 (defvar vc-checkout-writable-buffer-hook 'vc-checkout-writable-buffer)
133 (defvar vc-parent-buffer nil)
134 (defvar vc-parent-buffer-name nil)
137 (defvar vc-log-version)
139 (defconst vc-name-assoc-file "VC-names")
141 (defvar vc-dired-mode nil)
142 (make-variable-buffer-local 'vc-dired-mode)
144 (defvar vc-comment-ring nil)
145 (defvar vc-comment-ring-index nil)
146 (defvar vc-last-comment-match nil)
148 ;; File property caching
150 (defun vc-file-clearprops (file)
151 ;; clear all properties of a given file
152 (setplist (intern file vc-file-prop-obarray) nil))
154 (defun vc-clear-context ()
155 "Clear all cached file properties and the comment ring."
157 (fillarray vc-file-prop-obarray nil)
158 ;; Note: there is potential for minor lossage here if there is an open
159 ;; log buffer with a nonzero local value of vc-comment-ring-index.
160 (setq vc-comment-ring nil))
162 ;; Random helper functions
164 (defun vc-registration-error (file)
166 (error "File %s is not under version control" file)
167 (error "Buffer %s is not associated with a file" (buffer-name))))
169 (defvar vc-binary-assoc nil)
171 (defun vc-find-binary (name)
172 "Look for a command anywhere on the subprocess-command search path."
173 (or (cdr (assoc name vc-binary-assoc))
179 (let ((full (concat s "/" name)))
180 (if (file-executable-p full)
182 (setq vc-binary-assoc
183 (cons (cons name full) vc-binary-assoc))
184 (throw 'found full)))))))
188 (defun vc-do-command (okstatus command file &rest flags)
189 "Execute a version-control command, notifying user and checking for errors.
190 The command is successful if its exit status does not exceed OKSTATUS.
191 Output from COMMAND goes to buffer *vc*. The last argument of the command is
192 the master name of FILE; this is appended to an optional list of FLAGS."
193 (setq file (expand-file-name file))
194 (if vc-command-messages
195 (message "Running %s on %s..." command file))
196 (let ((obuf (current-buffer)) (camefrom (current-buffer))
198 (vc-file (and file (vc-name file)))
200 (set-buffer (get-buffer-create "*vc*"))
201 (set (make-local-variable 'vc-parent-buffer) camefrom)
202 (set (make-local-variable 'vc-parent-buffer-name)
203 (concat " from " (buffer-name camefrom)))
207 ;; This is so that command arguments typed in the *vc* buffer will
208 ;; have reasonable defaults.
209 (setq default-directory (file-name-directory file))
212 (function (lambda (s) (and s (setq squeezed (append squeezed (list s))))))
215 (setq squeezed (append squeezed (list vc-file))))
216 (let ((default-directory (file-name-directory (or file "./")))
217 (exec-path (if vc-path (append exec-path vc-path) exec-path)))
218 (setq status (apply 'call-process command nil t nil squeezed)))
219 (goto-char (point-max))
221 (if (or (not (integerp status)) (< okstatus status))
223 (pop-to-buffer "*vc*")
224 (goto-char (point-min))
225 (shrink-window-if-larger-than-buffer)
226 (error "Running %s...FAILED (%s)" command
227 (if (integerp status)
228 (format "status %d" status)
231 (if vc-command-messages
232 (message "Running %s...OK" command))
238 ;;; Save a bit of the text around POSN in the current buffer, to help
239 ;;; us find the corresponding position again later. This works even
240 ;;; if all markers are destroyed or corrupted.
241 (defun vc-position-context (posn)
244 (buffer-substring posn
245 (min (point-max) (+ posn 100)))))
247 ;;; Return the position of CONTEXT in the current buffer, or nil if we
248 ;;; couldn't find it.
249 (defun vc-find-position-by-context (context)
250 (let ((context-string (nth 2 context)))
251 (if (equal "" context-string)
254 (let ((diff (- (nth 1 context) (buffer-size))))
255 (if (< diff 0) (setq diff (- diff)))
256 (goto-char (nth 0 context))
257 (if (or (search-forward context-string nil t)
258 ;; Can't use search-backward since the match may continue
260 (progn (goto-char (- (point) diff (length context-string)))
261 ;; goto-char doesn't signal an error at
262 ;; beginning of buffer like backward-char would
263 (search-forward context-string nil t)))
264 ;; to beginning of OSTRING
265 (- (point) (length context-string))))))))
267 (defun vc-revert-buffer1 (&optional arg no-confirm)
268 ;; Most of this was shamelessly lifted from Sebastian Kremer's rcs.el mode.
269 ;; Revert buffer, try to keep point and mark where user expects them in spite
270 ;; of changes because of expanded version-control key words.
271 ;; This is quite important since otherwise typeahead won't work as expected.
274 (let ((point-context (vc-position-context (point)))
275 ;; Use mark-marker to avoid confusion in transient-mark-mode.
276 (mark-context (if (eq (marker-buffer (mark-marker)) (current-buffer))
277 (vc-position-context (mark-marker))))
278 ;; Make the right thing happen in transient-mark-mode.
280 ;; We may want to reparse the compilation buffer after revert
281 (reparse (and (boundp 'compilation-error-list) ;compile loaded
282 (let ((curbuf (current-buffer)))
283 ;; Construct a list; each elt is nil or a buffer
284 ;; iff that buffer is a compilation output buffer
285 ;; that contains markers into the current buffer.
291 compilation-old-error-list
292 compilation-error-list))
293 (buffer-error-marked-p nil))
294 (while (and (consp errors)
295 (not buffer-error-marked-p))
296 (and (markerp (cdr (car errors)))
300 (setq buffer-error-marked-p t))
301 (setq errors (cdr errors)))
302 (if buffer-error-marked-p buffer))))
305 ;; the actual revisit
306 (revert-buffer arg no-confirm)
308 ;; Reparse affected compilation buffers.
312 (set-buffer (car reparse))
313 (let ((compilation-last-buffer (current-buffer)) ;select buffer
314 ;; Record the position in the compilation buffer of
315 ;; the last error next-error went to.
316 (error-pos (marker-position
317 (car (car-safe compilation-error-list)))))
318 ;; Reparse the error messages as far as they were parsed before.
319 (compile-reinitialize-errors '(4) compilation-parsing-end)
320 ;; Move the pointer up to find the error we were at before
321 ;; reparsing. Now next-error should properly go to the next one.
322 (while (and compilation-error-list
323 (/= error-pos (car (car compilation-error-list))))
324 (setq compilation-error-list (cdr compilation-error-list))))))
325 (setq reparse (cdr reparse)))
327 ;; Restore point and mark
328 (let ((new-point (vc-find-position-by-context point-context)))
329 (if new-point (goto-char new-point)))
331 (let ((new-mark (vc-find-position-by-context mark-context)))
332 (if new-mark (set-mark new-mark))))))
335 (defun vc-buffer-sync (&optional not-urgent)
336 ;; Make sure the current buffer and its working file are in sync
337 ;; NOT-URGENT means it is ok to continue if the user says not to save.
338 (if (buffer-modified-p)
339 (if (or vc-suppress-confirm
340 (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name))))
344 (error "Aborted")))))
347 (defun vc-workfile-unchanged-p (file &optional want-differences-if-changed)
348 ;; Has the given workfile changed since last checkout?
349 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time))
350 (lastmod (nth 5 (file-attributes file))))
351 (or (equal checkout-time lastmod)
352 (and (or (not checkout-time) want-differences-if-changed)
353 (let ((unchanged (zerop (vc-backend-diff file nil nil
354 (not want-differences-if-changed)))))
355 ;; 0 stands for an unknown time; it can't match any mod time.
356 (vc-file-setprop file 'vc-checkout-time (if unchanged lastmod 0))
359 (defun vc-next-action-on-file (file verbose &optional comment)
360 ;;; If comment is specified, it will be used as an admin or checkin comment.
361 (let (owner version (vc-file (vc-name file)))
364 ;; if there is no master file corresponding, create one
366 (vc-register verbose comment))
368 ;; if there is no lock on the file, assert one and get it
369 ((not (setq owner (vc-locking-user file)))
370 (if (and vc-checkout-carefully
371 (not (vc-workfile-unchanged-p file t)))
372 (if (save-window-excursion
373 (pop-to-buffer "*vc*")
374 (goto-char (point-min))
375 (insert-string (format "Changes to %s since last lock:\n\n"
379 (concat "File has unlocked changes, "
380 "claim lock retaining changes? ")))
381 (progn (vc-backend-steal file)
383 (if (not (yes-or-no-p "Revert to checked-in version, instead? "))
384 (error "Checkout aborted.")
385 (vc-revert-buffer1 t t)
386 (vc-checkout-writable-buffer file))
388 (vc-checkout-writable-buffer file)))
390 ;; a checked-out version exists, but the user may not own the lock
391 ((not (string-equal owner (user-login-name)))
393 (error "Sorry, you can't steal the lock on %s this way" file))
396 (and verbose (read-string "Version to steal: "))
399 ;; OK, user owns the lock on the file
403 ;; give luser a chance to save before checking in.
406 ;; Revert if file is unchanged and buffer is too.
407 ;; If buffer is modified, that means the user just said no
408 ;; to saving it; in that case, don't revert,
409 ;; because the user might intend to save
410 ;; after finishing the log entry.
411 (if (and (vc-workfile-unchanged-p file)
412 (not (buffer-modified-p)))
414 (vc-backend-revert file)
415 ;; DO NOT revert the file without asking the user!
416 (vc-resynch-window file t nil))
418 ;; user may want to set nonstandard parameters
420 (setq version (read-string "New version level: ")))
422 ;; OK, let's do the checkin
423 (vc-checkin file version comment)
426 (defun vc-next-action-dired (file rev comment)
427 ;; We've accepted a log comment, now do a vc-next-action using it on all
429 (set-buffer vc-parent-buffer)
430 (dired-map-over-marks
431 (save-window-excursion
432 (let ((file (dired-get-filename)))
433 (message "Processing %s..." file)
434 (vc-next-action-on-file file nil comment)
435 (message "Processing %s...done" file)))
439 ;; Here's the major entry point.
442 (defun vc-next-action (verbose)
443 "Do the next logical checkin or checkout operation on the current file.
444 If the file is not already registered, this registers it for version
445 control and then retrieves a writable, locked copy for editing.
446 If the file is registered and not locked by anyone, this checks out
447 a writable and locked file ready for editing.
448 If the file is checked out and locked by the calling user, this
449 first checks to see if the file has changed since checkout. If not,
450 it performs a revert.
451 If the file has been changed, this pops up a buffer for entry
452 of a log message; when the message has been entered, it checks in the
453 resulting changes along with the log message as change commentary. If
454 the variable `vc-keep-workfiles' is non-nil (which is its default), a
455 read-only copy of the changed file is left in place afterwards.
456 If the file is registered and locked by someone else, you are given
457 the option to steal the lock.
458 If you call this from within a VC dired buffer with no files marked,
459 it will operate on the file in the current line.
460 If you call this from within a VC dired buffer, and one or more
461 files are marked, it will accept a log message and then operate on
462 each one. The log message will be used as a comment for any register
463 or checkin operations, but ignored when doing checkouts. Attempted
464 lock steals will raise an error.
466 For checkin, a prefix argument lets you specify the version number to use."
470 (let ((files (dired-get-marked-files)))
471 (if (= (length files) 1)
472 (find-file-other-window (dired-get-filename))
473 (vc-start-entry nil nil nil
474 "Enter a change comment for the marked files."
475 'vc-next-action-dired)
477 (while vc-parent-buffer
478 (pop-to-buffer vc-parent-buffer))
480 (vc-next-action-on-file buffer-file-name verbose)
481 (vc-registration-error nil))))
483 ;;; These functions help the vc-next-action entry point
485 (defun vc-checkout-writable-buffer (&optional file)
486 "Retrieve a writable copy of the latest version of the current buffer's file."
487 (vc-checkout (or file (buffer-file-name)) t)
491 (defun vc-register (&optional override comment)
492 "Register the current file into your version-control system."
494 (if (vc-name buffer-file-name)
495 (error "This file is already registered"))
496 ;; Watch out for new buffers of size 0: the corresponding file
497 ;; does not exist yet, even though buffer-modified-p is nil.
498 (if (and (not (buffer-modified-p))
499 (zerop (buffer-size))
500 (not (file-exists-p buffer-file-name)))
501 (set-buffer-modified-p t))
507 (format "Initial version level for %s: " buffer-file-name))))
510 (defun vc-resynch-window (file &optional keep noquery)
511 ;; If the given file is in the current buffer,
512 ;; either revert on it so we see expanded keyworks,
513 ;; or unvisit it (depending on vc-keep-workfiles)
514 ;; NOQUERY if non-nil inhibits confirmation for reverting.
515 ;; NOQUERY should be t *only* if it is known the only difference
516 ;; between the buffer and the file is due to RCS rather than user editing!
517 (and (string= buffer-file-name file)
520 (vc-revert-buffer1 t noquery)
521 (vc-mode-line buffer-file-name))
524 (kill-buffer (current-buffer))))))
526 (defun vc-start-entry (file rev comment msg action &optional after-hook)
527 ;; Accept a comment for an operation on FILE revision REV. If COMMENT
528 ;; is nil, pop up a VC-log buffer, emit MSG, and set the
529 ;; action on close to ACTION; otherwise, do action immediately.
530 ;; Remember the file's buffer in parent-buffer (current one if no file).
531 ;; AFTER-HOOK specifies the local value for vc-log-operation-hook.
532 (let ((parent (if file (find-file-noselect file) (current-buffer))))
534 (set-buffer (get-buffer-create "*VC-log*"))
535 (pop-to-buffer (get-buffer-create "*VC-log*")))
536 (set (make-local-variable 'vc-parent-buffer) parent)
537 (set (make-local-variable 'vc-parent-buffer-name)
538 (concat " from " (buffer-name vc-parent-buffer)))
539 (vc-mode-line (or file " (no file)"))
541 (make-local-variable 'vc-log-after-operation-hook)
543 (setq vc-log-after-operation-hook after-hook))
544 (setq vc-log-operation action)
545 (setq vc-log-file file)
546 (setq vc-log-version rev)
551 (vc-finish-logentry t)
553 (vc-finish-logentry nil)))
554 (message "%s Type C-c C-c when done." msg))))
556 (defun vc-admin (file rev &optional comment)
557 "Check a file into your version-control system.
558 FILE is the unmodified name of the file. REV should be the base version
559 level to check it in under. COMMENT, if specified, is the checkin comment."
560 (vc-start-entry file rev
561 (or comment (not vc-initial-comment))
562 "Enter initial comment." 'vc-backend-admin
563 'vc-checkout-writable-buffer-hook))
565 (defun vc-checkout (file &optional writable)
566 "Retrieve a copy of the latest version of the given file."
567 ;; If ftp is on this system and the name matches the ange-ftp format
568 ;; for a remote file, the user is trying something that won't work.
569 (if (and (string-match "^/[^/:]+:" file) (vc-find-binary "ftp"))
570 (error "Sorry, you can't check out files over FTP"))
571 (vc-backend-checkout file writable)
572 (if (string-equal file buffer-file-name)
573 (vc-resynch-window file t t))
576 (defun vc-steal-lock (file rev &optional owner)
577 "Steal the lock on the current workfile."
580 (setq owner (vc-locking-user file)))
581 (if (not (y-or-n-p (format "Take the lock on %s:%s from %s? " file rev owner)))
582 (error "Steal cancelled"))
583 (pop-to-buffer (get-buffer-create "*VC-mail*"))
584 (setq default-directory (expand-file-name "~/"))
585 (auto-save-mode auto-save-default)
588 (mail-setup owner (format "%s:%s" file rev) nil nil nil
589 (list (list 'vc-finish-steal file rev)))
590 (goto-char (point-max))
592 (format "I stole the lock on %s:%s, " file rev)
593 (current-time-string)
595 (message "Please explain why you stole the lock. Type C-c C-c when done."))
597 ;; This is called when the notification has been sent.
598 (defun vc-finish-steal (file version)
599 (vc-backend-steal file version)
600 (vc-resynch-window file t t))
602 (defun vc-checkin (file &optional rev comment)
603 "Check in the file specified by FILE.
604 The optional argument REV may be a string specifying the new version level
605 \(if nil increment the current level). The file is either retained with write
606 permissions zeroed, or deleted (according to the value of `vc-keep-workfiles').
607 COMMENT is a comment string; if omitted, a buffer is
608 popped up to accept a comment."
609 (vc-start-entry file rev comment
610 "Enter a change comment." 'vc-backend-checkin
613 ;;; Here is a checkin hook that may prove useful to sites using the
614 ;;; ChangeLog facility supported by Emacs.
615 (defun vc-comment-to-change-log (&optional whoami file-name)
616 "Enter last VC comment into change log file for current buffer's file.
617 Optional arg (interactive prefix) non-nil means prompt for user name and site.
618 Second arg is file name of change log. \
619 If nil, uses `change-log-default-name'."
620 (interactive (if current-prefix-arg
621 (list current-prefix-arg
622 (prompt-for-change-log-name))))
623 ;; Make sure the defvar for add-log-current-defun-function has been executed
624 ;; before binding it.
626 (let (;; Extract the comment first so we get any error before doing anything.
627 (comment (ring-ref vc-comment-ring 0))
628 ;; Don't let add-change-log-entry insert a defun name.
629 (add-log-current-defun-function 'ignore)
631 ;; Call add-log to do half the work.
632 (add-change-log-entry whoami file-name t t)
633 ;; Insert the VC comment, leaving point before it.
634 (setq end (save-excursion (insert comment) (point-marker)))
635 (if (looking-at "\\s *\\s(")
636 ;; It starts with an open-paren, as in "(foo): Frobbed."
637 ;; So remove the ": " add-log inserted.
639 ;; Canonicalize the white space between the file name and comment.
641 ;; Indent rest of the text the same way add-log indented the first line.
642 (let ((indentation (current-indentation)))
644 (while (< (point) end)
646 (indent-to indentation))
648 ;; Fill the inserted text, preserving open-parens at bol.
649 (let ((paragraph-separate (concat paragraph-separate "\\|^\\s *\\s("))
650 (paragraph-start (concat paragraph-start "\\|^\\s *\\s(")))
652 (fill-region (point) end))
653 ;; Canonicalize the white space at the end of the entry so it is
654 ;; separated from the next entry by a single blank line.
655 (skip-syntax-forward " " end)
656 (delete-char (- (skip-syntax-backward " ")))
657 (or (eobp) (looking-at "\n\n")
661 (defun vc-finish-logentry (&optional nocomment)
662 "Complete the operation implied by the current log entry."
664 ;; Check and record the comment, if any.
667 (goto-char (point-max))
671 (vc-backend-logentry-check vc-log-file)
672 ;; Record the comment in the comment ring
673 (if (null vc-comment-ring)
674 (setq vc-comment-ring (make-ring vc-maximum-comment-ring-size)))
675 (ring-insert vc-comment-ring (buffer-string))
677 ;; Sync parent buffer in case the user modified it while editing the comment.
679 (set-buffer vc-parent-buffer)
684 (funcall vc-log-operation
688 (error "No log operation is pending"))
689 ;; Return to "parent" buffer of this checkin and remove checkin window
690 (pop-to-buffer vc-parent-buffer)
691 (let ((logbuf (get-buffer "*VC-log*")))
692 (delete-windows-on logbuf)
693 (kill-buffer logbuf))
694 ;; Now make sure we see the expanded headers
696 (vc-resynch-window buffer-file-name vc-keep-workfiles t))
697 (run-hooks vc-log-after-operation-hook))
699 ;; Code for access to the comment ring
701 (defun vc-previous-comment (arg)
702 "Cycle backwards through comment history."
704 (let ((len (ring-length vc-comment-ring)))
706 (message "Empty comment ring")
710 ;; Initialize the index on the first use of this command
711 ;; so that the first M-p gets index 0, and the first M-n gets
713 (if (null vc-comment-ring-index)
714 (setq vc-comment-ring-index
716 (if (< arg 0) 1 0))))
717 (setq vc-comment-ring-index
718 (mod (+ vc-comment-ring-index arg) len))
719 (message "%d" (1+ vc-comment-ring-index))
720 (insert (ring-ref vc-comment-ring vc-comment-ring-index))))))
722 (defun vc-next-comment (arg)
723 "Cycle forwards through comment history."
725 (vc-previous-comment (- arg)))
727 (defun vc-comment-search-reverse (str)
728 "Searches backwards through comment history for substring match."
729 (interactive "sComment substring: ")
731 (setq str vc-last-comment-match)
732 (setq vc-last-comment-match str))
733 (if (null vc-comment-ring-index)
734 (setq vc-comment-ring-index -1))
735 (let ((str (regexp-quote str))
736 (len (ring-length vc-comment-ring))
737 (n (1+ vc-comment-ring-index)))
738 (while (and (< n len) (not (string-match str (ring-ref vc-comment-ring n))))
741 (vc-previous-comment (- n vc-comment-ring-index)))
742 (t (error "Not found")))))
744 (defun vc-comment-search-forward (str)
745 "Searches forwards through comment history for substring match."
746 (interactive "sComment substring: ")
748 (setq str vc-last-comment-match)
749 (setq vc-last-comment-match str))
750 (if (null vc-comment-ring-index)
751 (setq vc-comment-ring-index 0))
752 (let ((str (regexp-quote str))
753 (len (ring-length vc-comment-ring))
754 (n vc-comment-ring-index))
755 (while (and (>= n 0) (not (string-match str (ring-ref vc-comment-ring n))))
758 (vc-next-comment (- n vc-comment-ring-index)))
759 (t (error "Not found")))))
761 ;; Additional entry points for examining version histories
764 (defun vc-diff (historic &optional not-urgent)
765 "Display diffs between file versions.
766 Normally this compares the current file and buffer with the most recent
767 checked in version of that file. This uses no arguments.
768 With a prefix argument, it reads the file name to use
769 and two version designators specifying which versions to compare."
772 (set-buffer (find-file-noselect (dired-get-filename))))
773 (while vc-parent-buffer
774 (pop-to-buffer vc-parent-buffer))
776 (call-interactively 'vc-version-diff)
777 (if (or (null buffer-file-name) (null (vc-name buffer-file-name)))
779 "There is no version-control master associated with this buffer"))
780 (let ((file buffer-file-name)
782 (or (and file (vc-name file))
783 (vc-registration-error file))
784 (vc-buffer-sync not-urgent)
785 (setq unchanged (vc-workfile-unchanged-p buffer-file-name))
787 (message "No changes to %s since latest version." file)
788 (vc-backend-diff file)
789 ;; Ideally, we'd like at this point to parse the diff so that
790 ;; the buffer effectively goes into compilation mode and we
791 ;; can visit the old and new change locations via next-error.
792 ;; Unfortunately, this is just too painful to do. The basic
793 ;; problem is that the `old' file doesn't exist to be
794 ;; visited. This plays hell with numerous assumptions in
795 ;; the diff.el and compile.el machinery.
796 (pop-to-buffer "*vc*")
797 (pop-to-buffer "*vc*")
798 (if (= 0 (buffer-size))
801 (message "No changes to %s since latest version." file))
802 (goto-char (point-min))
803 (shrink-window-if-larger-than-buffer)))
806 (defun vc-version-diff (file rel1 rel2)
807 "For FILE, report diffs between two stored versions REL1 and REL2 of it.
808 If FILE is a directory, generate diffs between versions for all registered
809 files in or below it."
810 (interactive "FFile or directory to diff: \nsOlder version: \nsNewer version: ")
811 (if (string-equal rel1 "") (setq rel1 nil))
812 (if (string-equal rel2 "") (setq rel2 nil))
813 (if (file-directory-p file)
814 (let ((camefrom (current-buffer)))
815 (set-buffer (get-buffer-create "*vc-status*"))
816 (set (make-local-variable 'vc-parent-buffer) camefrom)
817 (set (make-local-variable 'vc-parent-buffer-name)
818 (concat " from " (buffer-name camefrom)))
820 (insert "Diffs between "
821 (or rel1 "last version checked in")
823 (or rel2 "current workfile(s)")
825 (set-buffer (get-buffer-create "*vc*"))
828 (function (lambda (f)
829 (message "Looking at %s" f)
831 (not (file-directory-p f))
833 (vc-backend-diff f rel1 rel2)
834 (append-to-buffer "*vc-status*" (point-min) (point-max)))
836 (pop-to-buffer "*vc-status*")
837 (insert "\nEnd of diffs.\n")
838 (goto-char (point-min))
839 (set-buffer-modified-p nil)
841 (if (zerop (vc-backend-diff file rel1 rel2))
842 (message "No changes to %s between %s and %s." file rel1 rel2)
843 (pop-to-buffer "*vc*"))))
846 (defun vc-version-other-window (rev)
847 "Visit version REV of the current buffer in another window.
848 If the current buffer is named `F', the version is named `F.~REV~'.
849 If `F.~REV~' already exists, it is used instead of being re-created."
850 (interactive "sVersion to visit (default is latest version): ")
852 (set-buffer (find-file-noselect (dired-get-filename))))
853 (while vc-parent-buffer
854 (pop-to-buffer vc-parent-buffer))
855 (if (and buffer-file-name (vc-name buffer-file-name))
856 (let* ((version (if (string-equal rev "")
857 (vc-latest-version buffer-file-name)
859 (filename (concat buffer-file-name ".~" version "~")))
860 (or (file-exists-p filename)
861 (vc-backend-checkout buffer-file-name nil version filename))
862 (find-file-other-window filename))
863 (vc-registration-error buffer-file-name)))
865 ;; Header-insertion code
868 (defun vc-insert-headers ()
869 "Insert headers in a file for use with your version-control system.
870 Headers desired are inserted at the start of the buffer, and are pulled from
871 the variable `vc-header-alist'."
874 (find-file-other-window (dired-get-filename)))
875 (while vc-parent-buffer
876 (pop-to-buffer vc-parent-buffer))
880 (if (or (not (vc-check-headers))
881 (y-or-n-p "Version headers already exist. Insert another set? "))
883 (let* ((delims (cdr (assq major-mode vc-comment-alist)))
884 (comment-start-vc (or (car delims) comment-start "#"))
885 (comment-end-vc (or (car (cdr delims)) comment-end ""))
886 (hdstrings (cdr (assoc (vc-backend-deduce (buffer-file-name)) vc-header-alist))))
887 (mapcar (function (lambda (s)
888 (insert comment-start-vc "\t" s "\t"
889 comment-end-vc "\n")))
891 (if vc-static-header-alist
892 (mapcar (function (lambda (f)
893 (if (string-match (car f) buffer-file-name)
894 (insert (format (cdr f) (car hdstrings))))))
895 vc-static-header-alist))
899 ;; The VC directory submode. Coopt Dired for this.
900 ;; All VC commands get mapped into logical equivalents.
902 (defvar vc-dired-prefix-map (make-sparse-keymap))
903 (define-key vc-dired-prefix-map "\C-xv" vc-prefix-map)
905 (or (not (boundp 'minor-mode-map-alist))
906 (assq 'vc-dired-mode minor-mode-map-alist)
907 (setq minor-mode-map-alist
908 (cons (cons 'vc-dired-mode vc-dired-prefix-map)
909 minor-mode-map-alist)))
911 (defun vc-dired-mode ()
912 "The augmented Dired minor mode used in VC directory buffers.
913 All Dired commands operate normally. Users currently locking listed files
914 are listed in place of the file's owner and group.
915 Keystrokes bound to VC commands will execute as though they had been called
916 on a buffer attached to the file named in the current Dired buffer line."
917 (setq vc-dired-mode t)
918 (setq vc-mode " under VC"))
920 (defun vc-dired-reformat-line (x)
921 ;; Hack a directory-listing line, plugging in locking-user info in
922 ;; place of the user and group info. Should have the beneficial
923 ;; side-effect of shortening the listing line. Each call starts with
924 ;; point immediately following the dired mark area on the line to be
927 ;; Simplest possible one:
928 ;; (insert (concat x "\t")))
930 ;; This code, like dired, assumes UNIX -l format.
931 (forward-word 1) ;; skip over any extra field due to -ibs options
932 (if x (setq x (concat "(" x ")")))
933 (if (re-search-forward "\\([0-9]+ \\).................\\( .*\\)" nil 0)
934 (let ((rep (substring (concat x " ") 0 9)))
935 (replace-match (concat "\\1" rep "\\2") t)))
938 ;;; Note in Emacs 18 the following defun gets overridden
939 ;;; with the symbol 'vc-directory-18. See below.
941 (defun vc-directory (verbose)
942 "Show version-control status of all files under the current directory."
945 (dl (length default-directory))
946 (filelist nil) (userlist nil)
950 (function (lambda (f)
951 (if (vc-registered f)
952 (let ((user (vc-locking-user f)))
953 (and (or verbose user)
954 (setq filelist (cons (substring f dl) filelist))
955 (setq userlist (cons user userlist))))))))
957 ;; This uses a semi-documented feature of dired; giving a switch
958 ;; argument forces the buffer to refresh each time.
960 (cons default-directory (nreverse filelist))
961 dired-listing-switches)
962 (setq dired-buf (current-buffer))
963 (setq nonempty (not (zerop (buffer-size)))))
966 (pop-to-buffer dired-buf)
968 (goto-char (point-min))
969 (setq buffer-read-only nil)
970 (forward-line 1) ;; Skip header line
974 (forward-char 2) ;; skip dired's mark area
975 (vc-dired-reformat-line x)
976 (forward-line 1))) ;; go to next line
978 (setq buffer-read-only t)
979 (goto-char (point-min))
981 (message "No files are currently %s under %s"
982 (if verbose "registered" "locked") default-directory))
986 (defun vc-directory-18 (verbose)
987 "Show version-control status of all files under the current directory."
989 (let (nonempty (dir default-directory))
991 (set-buffer (get-buffer-create "*vc-status*"))
995 (function (lambda (f)
996 (if (vc-registered f)
997 (let ((user (vc-locking-user f)))
998 (if (or user verbose)
1001 (concat user) f))))))))
1002 (setq nonempty (not (zerop (buffer-size)))))
1005 (pop-to-buffer "*vc-status*" t)
1006 (goto-char (point-min))
1007 (shrink-window-if-larger-than-buffer)))
1008 (message "No files are currently %s under %s"
1009 (if verbose "registered" "locked") default-directory))
1012 (or (boundp 'minor-mode-map-alist)
1013 (fset 'vc-directory 'vc-directory-18))
1015 ; Emacs 18 also lacks these.
1016 (or (boundp 'compilation-old-error-list)
1017 (setq compilation-old-error-list nil))
1019 ;; Named-configuration support for SCCS
1021 (defun vc-add-triple (name file rev)
1023 (find-file (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file))
1024 (goto-char (point-max))
1025 (insert name "\t:\t" file "\t" rev "\n")
1027 (kill-buffer (current-buffer))
1030 (defun vc-record-rename (file newname)
1032 (find-file (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file))
1033 (goto-char (point-min))
1034 ;; (replace-regexp (concat ":" (regexp-quote file) "$") (concat ":" newname))
1035 (while (re-search-forward (concat ":" (regexp-quote file) "$") nil t)
1036 (replace-match (concat ":" newname) nil nil))
1038 (kill-buffer (current-buffer))
1041 (defun vc-lookup-triple (file name)
1042 ;; Return the numeric version corresponding to a named snapshot of file
1043 ;; If name is nil or a version number string it's just passed through
1044 (cond ((null name) name)
1045 ((let ((firstchar (aref name 0)))
1046 (and (>= firstchar ?0) (<= firstchar ?9)))
1049 (car (vc-master-info
1050 (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file)
1051 (list (concat name "\t:\t" file "\t\\(.+\\)"))))
1054 ;; Named-configuration entry points
1056 (defun vc-locked-example ()
1057 ;; Return an example of why the current directory is not ready to be snapshot
1058 ;; or nil if no such example exists.
1059 (catch 'vc-locked-example
1061 (function (lambda (f)
1062 (if (and (vc-registered f) (vc-locking-user f))
1063 (throw 'vc-locked-example f)))))
1067 (defun vc-create-snapshot (name)
1068 "Make a snapshot called NAME.
1069 The snapshot is made from all registered files at or below the current
1070 directory. For each file, the version level of its latest
1071 version becomes part of the named configuration."
1072 (interactive "sNew snapshot name: ")
1073 (let ((locked (vc-locked-example)))
1075 (error "File %s is locked" locked)
1077 (function (lambda (f) (and
1079 (vc-backend-assign-name f name)))))
1083 (defun vc-retrieve-snapshot (name)
1084 "Retrieve the snapshot called NAME.
1085 This function fails if any files are locked at or below the current directory
1086 Otherwise, all registered files are checked out (unlocked) at their version
1087 levels in the snapshot."
1088 (interactive "sSnapshot name to retrieve: ")
1089 (let ((locked (vc-locked-example)))
1091 (error "File %s is locked" locked)
1093 (function (lambda (f) (and
1096 (vc-backend-checkout f nil name))))))
1099 ;; Miscellaneous other entry points
1102 (defun vc-print-log ()
1103 "List the change log of the current buffer in a window."
1106 (set-buffer (find-file-noselect (dired-get-filename))))
1107 (while vc-parent-buffer
1108 (pop-to-buffer vc-parent-buffer))
1109 (if (and buffer-file-name (vc-name buffer-file-name))
1111 (vc-backend-print-log buffer-file-name)
1112 (pop-to-buffer (get-buffer-create "*vc*"))
1113 (while (looking-at "=*\n")
1114 (delete-char (- (match-end 0) (match-beginning 0)))
1116 (goto-char (point-min))
1117 (if (looking-at "[\b\t\n\v\f\r ]+")
1118 (delete-char (- (match-end 0) (match-beginning 0))))
1119 (shrink-window-if-larger-than-buffer)
1121 (vc-registration-error buffer-file-name)
1126 (defun vc-revert-buffer ()
1127 "Revert the current buffer's file back to the latest checked-in version.
1128 This asks for confirmation if the buffer contents are not identical
1132 (find-file-other-window (dired-get-filename)))
1133 (while vc-parent-buffer
1134 (pop-to-buffer vc-parent-buffer))
1135 (let ((file buffer-file-name)
1136 (obuf (current-buffer)) (changed (vc-diff nil t)))
1137 (if (and changed (or vc-suppress-confirm
1138 (not (yes-or-no-p "Discard changes? "))))
1141 (error "Revert cancelled"))
1145 (vc-backend-revert file)
1146 (vc-resynch-window file t t)
1151 (defun vc-cancel-version (norevert)
1152 "Get rid of most recently checked in version of this file.
1153 A prefix argument means do not revert the buffer afterwards."
1156 (find-file-other-window (dired-get-filename)))
1157 (while vc-parent-buffer
1158 (pop-to-buffer vc-parent-buffer))
1159 (let* ((target (concat (vc-latest-version (buffer-file-name))))
1160 (yours (concat (vc-your-latest-version (buffer-file-name))))
1161 (prompt (if (string-equal yours target)
1162 "Remove your version %s from master? "
1163 "Version %s was not your change. Remove it anyway? ")))
1164 (if (null (yes-or-no-p (format prompt target)))
1166 (vc-backend-uncheck (buffer-file-name) target)
1168 (not (yes-or-no-p "Revert buffer to most recent remaining version? ")))
1169 (vc-mode-line (buffer-file-name))
1170 (vc-checkout (buffer-file-name) nil)))
1173 (defun vc-rename-file (old new)
1174 "Rename file OLD to NEW, and rename its master file likewise."
1175 (interactive "fVC rename file: \nFRename to: ")
1176 (let ((oldbuf (get-file-buffer old)))
1177 (if (and oldbuf (buffer-modified-p oldbuf))
1178 (error "Please save files before moving them"))
1179 (if (get-file-buffer new)
1180 (error "Already editing new file name"))
1181 (if (file-exists-p new)
1182 (error "New file already exists"))
1183 (let ((oldmaster (vc-name old)))
1186 (if (vc-locking-user old)
1187 (error "Please check in files before moving them"))
1188 (if (or (file-symlink-p oldmaster)
1189 ;; This had FILE, I changed it to OLD. -- rms.
1190 (file-symlink-p (vc-backend-subdirectory-name old)))
1191 (error "This is not a safe thing to do in the presence of symbolic links"))
1194 (let ((backend (vc-backend-deduce old))
1195 (newdir (or (file-name-directory new) ""))
1196 (newbase (file-name-nondirectory new)))
1201 (if (eq backend (cdr s))
1202 (let* ((newmaster (format (car s) newdir newbase))
1203 (newmasterdir (file-name-directory newmaster)))
1204 (if (or (not newmasterdir)
1205 (file-directory-p newmasterdir))
1206 (throw 'found newmaster))))))
1207 vc-master-templates)
1208 (error "New file lacks a version control directory"))))))
1209 (if (or (not oldmaster) (file-exists-p old))
1210 (rename-file old new)))
1211 ; ?? Renaming a file might change its contents due to keyword expansion.
1212 ; We should really check out a new copy if the old copy was precisely equal
1213 ; to some checked in version. However, testing for this is tricky....
1217 (set-visited-file-name new)
1218 (set-buffer-modified-p nil))))
1219 ;; This had FILE, I changed it to OLD. -- rms.
1220 (vc-backend-dispatch old
1221 (vc-record-rename old new)
1226 (defun vc-update-change-log (&rest args)
1227 "Find change log file and add entries from recent RCS logs.
1228 The mark is left at the end of the text prepended to the change log.
1229 With prefix arg of C-u, only find log entries for the current buffer's file.
1230 With any numeric prefix arg, find log entries for all files currently visited.
1231 Otherwise, find log entries for all registered files in the default directory.
1232 From a program, any arguments are passed to the `rcs2log' script."
1234 (cond ((consp current-prefix-arg) ;C-u
1235 (list buffer-file-name))
1236 (current-prefix-arg ;Numeric argument.
1238 (buffers (buffer-list))
1241 (setq file (buffer-file-name (car buffers)))
1242 (and file (vc-backend-deduce file)
1243 (setq files (cons file files)))
1244 (setq buffers (cdr buffers)))
1247 (let ((RCS (concat default-directory "RCS")))
1248 (and (file-directory-p RCS)
1251 (if (string-match "\\(.*\\),v$" f)
1252 (substring f 0 (match-end 1))
1254 (directory-files RCS nil "...\\|^[^.]\\|^.[^.]")))))))
1255 (let ((odefault default-directory))
1256 (find-file-other-window (find-change-log))
1257 (barf-if-buffer-read-only)
1260 (goto-char (point-min))
1262 (message "Computing change log entries...")
1263 (message "Computing change log entries... %s"
1265 (eq 0 (apply 'call-process "rcs2log" nil t nil
1273 (if (file-name-absolute-p f)
1275 (concat odefault f)))))
1279 ;; Functions for querying the master and lock files.
1281 (defun vc-match-substring (bn)
1282 (buffer-substring (match-beginning bn) (match-end bn)))
1284 (defun vc-parse-buffer (patterns &optional file properties)
1285 ;; Use PATTERNS to parse information out of the current buffer
1286 ;; by matching each regular expression in the list and returning \\1.
1287 ;; If a regexp has two tag brackets, assume the second is a date
1288 ;; field and we want the most recent entry matching the template.
1289 ;; If FILE and PROPERTIES are given, the latter must be a list of
1290 ;; properties of the same length as PATTERNS; each property is assigned
1291 ;; the corresponding value.
1292 (mapcar (function (lambda (p)
1293 (goto-char (point-min))
1294 (if (string-match "\\\\(.*\\\\(" p)
1295 (let ((latest-date "") (latest-val))
1296 (while (re-search-forward p nil t)
1297 (let ((date (vc-match-substring 2)))
1298 (if (string< latest-date date)
1300 (setq latest-date date)
1302 (vc-match-substring 1))))))
1306 (if (re-search-forward p nil t)
1307 (setq value (vc-match-substring 1)))
1309 (vc-file-setprop file (car properties) value))
1311 (setq properties (cdr properties)))))
1315 (defun vc-master-info (file fields &optional rfile properties)
1316 ;; Search for information in a master file.
1317 (if (and file (file-exists-p file))
1320 (setq buf (create-file-buffer file))
1323 (insert-file-contents file nil)
1324 (set-buffer-modified-p nil)
1325 (auto-save-mode nil)
1327 (vc-parse-buffer fields rfile properties)
1328 (kill-buffer (current-buffer)))
1332 (function (lambda (p) (vc-file-setprop rfile p nil)))
1337 (defun vc-log-info (command file patterns &optional properties)
1338 ;; Search for information in log program output
1339 (if (and file (file-exists-p file))
1342 (setq buf (get-buffer-create "*vc*"))
1344 (apply 'vc-do-command 0 command file nil)
1345 (set-buffer-modified-p nil)
1347 (vc-parse-buffer patterns file properties)
1348 (kill-buffer (current-buffer))
1353 (function (lambda (p) (vc-file-setprop file p nil)))
1358 (defun vc-locking-user (file)
1359 "Return the name of the person currently holding a lock on FILE.
1360 Return nil if there is no such person."
1361 (setq file (expand-file-name file)) ;; ??? Work around bug in 19.0.4
1362 (if (or (not vc-keep-workfiles)
1363 (eq vc-mistrust-permissions 't)
1364 (and vc-mistrust-permissions
1365 (funcall vc-mistrust-permissions (vc-backend-subdirectory-name file))))
1366 (vc-true-locking-user file)
1367 ;; This implementation assumes that any file which is under version
1368 ;; control and has -rw-r--r-- is locked by its owner. This is true
1369 ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--.
1370 ;; We have to be careful not to exclude files with execute bits on;
1371 ;; scripts can be under version control too. Also, we must ignore
1372 ;; the group-read and other-read bits, since paranoid users turn them off.
1373 ;; This hack wins because calls to the very expensive vc-fetch-properties
1374 ;; function only have to be made if (a) the file is locked by someone
1375 ;; other than the current user, or (b) some untoward manipulation
1376 ;; behind vc's back has changed the owner or the `group' or `other'
1378 (let ((attributes (file-attributes file)))
1379 (cond ((string-match ".r-..-..-." (nth 8 attributes))
1381 ((and (= (nth 2 attributes) (user-uid))
1382 (string-match ".rw..-..-." (nth 8 attributes)))
1385 (vc-true-locking-user file))))))
1387 (defun vc-true-locking-user (file)
1388 ;; The slow but reliable version
1389 (vc-fetch-properties file)
1390 (vc-file-getprop file 'vc-locking-user))
1392 (defun vc-latest-version (file)
1393 ;; Return version level of the latest version of FILE
1394 (vc-fetch-properties file)
1395 (vc-file-getprop file 'vc-latest-version))
1397 (defun vc-your-latest-version (file)
1398 ;; Return version level of the latest version of FILE checked in by you
1399 (vc-fetch-properties file)
1400 (vc-file-getprop file 'vc-your-latest-version))
1402 ;; Collect back-end-dependent stuff here
1404 ;; Everything eventually funnels through these functions. To implement
1405 ;; support for a new version-control system, add another branch to the
1406 ;; vc-backend-dispatch macro and fill it in in each call. The variable
1407 ;; vc-master-templates in vc-hooks.el will also have to change.
1409 (defmacro vc-backend-dispatch (f s r)
1410 "Execute FORM1 or FORM2 depending on whether we're using SCCS or RCS."
1411 (list 'let (list (list 'type (list 'vc-backend-deduce f)))
1413 (list (list 'eq 'type (quote 'SCCS)) s) ;; SCCS
1414 (list (list 'eq 'type (quote 'RCS)) r) ;; RCS
1417 (defun vc-lock-file (file)
1418 ;; Generate lock file name corresponding to FILE
1419 (let ((master (vc-name file)))
1422 (string-match "\\(.*/\\)s\\.\\(.*\\)" master)
1424 (substring master (match-beginning 1) (match-end 1))
1426 (substring master (match-beginning 2) (match-end 2))))))
1429 (defun vc-fetch-properties (file)
1430 ;; Re-fetch all properties associated with the given file.
1431 ;; Currently these properties are:
1433 ;; vc-locked-version
1434 ;; vc-latest-version
1435 ;; vc-your-latest-version
1436 (vc-backend-dispatch
1440 (vc-master-info (vc-lock-file file)
1442 "^[^ ]+ [^ ]+ \\([^ ]+\\)"
1445 '(vc-locking-user vc-locked-version))
1446 (vc-master-info (vc-name file)
1448 "^\001d D \\([^ ]+\\)"
1449 (concat "^\001d D \\([^ ]+\\) .* "
1450 (regexp-quote (user-login-name)) " ")
1453 '(vc-latest-version vc-your-latest-version))
1456 (vc-log-info "rlog" file
1458 "^locks: strict\n\t\\([^:]+\\)"
1459 "^locks: strict\n\t[^:]+: \\(.+\\)"
1460 "^revision[\t ]+\\([0-9.]+\\).*\ndate: \\([ /0-9:]+\\);"
1462 "^revision[\t ]+\\([0-9.]+\\)\n.*author: "
1463 (regexp-quote (user-login-name))
1465 '(vc-locking-user vc-locked-version
1466 vc-latest-version vc-your-latest-version))
1469 (defun vc-backend-subdirectory-name (&optional file)
1470 ;; Where the master and lock files for the current directory are kept
1473 (and file (vc-backend-deduce file))
1475 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))))
1477 (defun vc-backend-admin (file &optional rev comment)
1478 ;; Register a file into the version-control system
1479 ;; Automatically retrieves a read-only version of the file with
1480 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
1481 ;; it deletes the workfile.
1482 (vc-file-clearprops file)
1483 (or vc-default-back-end
1484 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))
1485 (message "Registering %s..." file)
1488 ((file-exists-p (vc-backend-subdirectory-name)) vc-default-back-end)
1489 ((file-exists-p "RCS") 'RCS)
1490 ((file-exists-p "SCCS") 'SCCS)
1491 (t vc-default-back-end))))
1492 (cond ((eq backend 'SCCS)
1493 (vc-do-command 0 "admin" file ;; SCCS
1494 (and rev (concat "-r" rev))
1497 (and comment (concat "-y" comment))
1499 (car (rassq 'SCCS vc-master-templates))
1500 (or (file-name-directory file) "")
1501 (file-name-nondirectory file)))
1503 (if vc-keep-workfiles
1504 (vc-do-command 0 "get" file)))
1506 (vc-do-command 0 "ci" file ;; RCS
1507 (concat (if vc-keep-workfiles "-u" "-r") rev)
1508 (and comment (concat "-t-" comment))
1511 (message "Registering %s...done" file)
1514 (defun vc-backend-checkout (file &optional writable rev workfile)
1515 ;; Retrieve a copy of a saved version into a workfile
1516 (let ((filename (or workfile file)))
1517 (message "Checking out %s..." filename)
1518 (vc-backend-dispatch file
1519 (vc-do-command 0 "get" file ;; SCCS
1521 (if workfile (concat "-G" workfile))
1522 (and rev (concat "-r" (vc-lookup-triple file rev))))
1524 ;; RCS doesn't let us check out into arbitrary file names directly.
1525 ;; Use `co -p' and make stdout point to the correct file.
1526 (let ((vc-modes (logior (file-modes (vc-name file))
1527 (if writable 128 0)))
1532 0 "/bin/sh" file "-c"
1533 (format "umask %o; exec >\"$1\" || exit; shift; umask %o; exec co \"$@\""
1534 (logand 511 (lognot vc-modes))
1535 (logand 511 (lognot (default-file-modes))))
1536 "" ; dummy argument for shell's $0
1541 (and failed (file-exists-p filename) (delete-file filename))))
1542 (vc-do-command 0 "co" file
1544 (and rev (concat "-r" rev))))
1547 (vc-file-setprop file 'vc-checkout-time (nth 5 (file-attributes file))))
1548 (message "Checking out %s...done" filename))
1551 (defun vc-backend-logentry-check (file)
1552 (vc-backend-dispatch file
1553 (if (>= (buffer-size) 512) ;; SCCS
1557 "Log must be less than 512 characters; point is now at pos 512")))
1561 (defun vc-backend-checkin (file &optional rev comment)
1562 ;; Register changes to FILE as level REV with explanatory COMMENT.
1563 ;; Automatically retrieves a read-only version of the file with
1564 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
1565 ;; it deletes the workfile.
1566 (message "Checking in %s..." file)
1568 ;; Change buffers to get local value of vc-checkin-switches.
1569 (set-buffer (or (get-file-buffer file) (current-buffer)))
1570 (vc-backend-dispatch file
1572 (apply 'vc-do-command 0 "delta" file
1573 (if rev (concat "-r" rev))
1574 (concat "-y" comment)
1575 vc-checkin-switches)
1576 (if vc-keep-workfiles
1577 (vc-do-command 0 "get" file))
1579 (apply 'vc-do-command 0 "ci" file
1580 (concat (if vc-keep-workfiles "-u" "-r") rev)
1581 (concat "-m" comment)
1582 vc-checkin-switches)
1584 (vc-file-setprop file 'vc-locking-user nil)
1585 (message "Checking in %s...done" file)
1588 (defun vc-backend-revert (file)
1589 ;; Revert file to latest checked-in version.
1590 (message "Reverting %s..." file)
1591 (vc-backend-dispatch
1594 (vc-do-command 0 "unget" file nil)
1595 (vc-do-command 0 "get" file nil))
1596 (vc-do-command 0 "co" file "-f" "-u")) ;; RCS. This deletes the work file.
1597 (vc-file-setprop file 'vc-locking-user nil)
1598 (message "Reverting %s...done" file)
1601 (defun vc-backend-steal (file &optional rev)
1602 ;; Steal the lock on the current workfile. Needs RCS 5.6.2 or later for -M.
1603 (message "Stealing lock on %s..." file)
1604 (vc-backend-dispatch file
1606 (vc-do-command 0 "unget" file "-n" (if rev (concat "-r" rev)))
1607 (vc-do-command 0 "get" file "-g" (if rev (concat "-r" rev)))
1609 (vc-do-command 0 "rcs" file "-M" (concat "-u" rev) (concat "-l" rev)))
1610 (vc-file-setprop file 'vc-locking-user (user-login-name))
1611 (message "Stealing lock on %s...done" file)
1614 (defun vc-backend-uncheck (file target)
1615 ;; Undo the latest checkin. Note: this code will have to get a lot
1616 ;; smarter when we support multiple branches.
1617 (message "Removing last change from %s..." file)
1618 (vc-backend-dispatch file
1619 (vc-do-command 0 "rmdel" file (concat "-r" target))
1620 (vc-do-command 0 "rcs" file (concat "-o" target))
1622 (message "Removing last change from %s...done" file)
1625 (defun vc-backend-print-log (file)
1626 ;; Print change log associated with FILE to buffer *vc*.
1628 (vc-backend-dispatch file "prs" "rlog")
1632 (defun vc-backend-assign-name (file name)
1633 ;; Assign to a FILE's latest version a given NAME.
1634 (vc-backend-dispatch file
1635 (vc-add-triple name file (vc-latest-version file)) ;; SCCS
1636 (vc-do-command 0 "rcs" file (concat "-n" name ":")) ;; RCS
1640 (defun vc-backend-diff (file &optional oldvers newvers cmp)
1641 ;; Get a difference report between two versions of FILE.
1642 ;; Get only a brief comparison report if CMP, a difference report otherwise.
1643 (if (eq (vc-backend-deduce file) 'SCCS)
1644 (setq oldvers (vc-lookup-triple file oldvers))
1645 (setq newvers (vc-lookup-triple file newvers)))
1646 (let* ((command (or (vc-backend-dispatch file "vcdiff" "rcsdiff")
1647 (vc-registration-error file)))
1648 (options (append (list (and cmp "--brief")
1650 (and oldvers (concat "-r" oldvers))
1651 (and newvers (concat "-r" newvers)))
1653 (if (listp diff-switches)
1655 (list diff-switches)))))
1656 (status (apply 'vc-do-command 2 command file options)))
1657 ;; Some RCS versions don't understand "--brief"; work around this.
1659 (apply 'vc-do-command 1 command file (if cmp (cdr options) options))
1662 (defun vc-check-headers ()
1663 "Check if the current file has any headers in it."
1666 (goto-char (point-min))
1667 (vc-backend-dispatch buffer-file-name
1668 (re-search-forward "%[MIRLBSDHTEGUYFPQCZWA]%" nil t) ;; SCCS
1669 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t) ;; RCS
1673 ;; Back-end-dependent stuff ends here.
1675 ;; Set up key bindings for use while editing log messages
1677 (defun vc-log-mode ()
1678 "Minor mode for driving version-control tools.
1679 These bindings are added to the global keymap when you enter this mode:
1680 \\[vc-next-action] perform next logical version-control operation on current file
1681 \\[vc-register] register current file
1682 \\[vc-toggle-read-only] like next-action, but won't register files
1683 \\[vc-insert-headers] insert version-control headers in current file
1684 \\[vc-print-log] display change history of current file
1685 \\[vc-revert-buffer] revert buffer to latest version
1686 \\[vc-cancel-version] undo latest checkin
1687 \\[vc-diff] show diffs between file versions
1688 \\[vc-version-other-window] visit old version in another window
1689 \\[vc-directory] show all files locked by any user in or below .
1690 \\[vc-update-change-log] add change log entry from recent checkins
1692 While you are entering a change log message for a version, the following
1693 additional bindings will be in effect.
1695 \\[vc-finish-logentry] proceed with check in, ending log message entry
1697 Whenever you do a checkin, your log comment is added to a ring of
1698 saved comments. These can be recalled as follows:
1700 \\[vc-next-comment] replace region with next message in comment ring
1701 \\[vc-previous-comment] replace region with previous message in comment ring
1702 \\[vc-comment-search-reverse] search backward for regexp in the comment ring
1703 \\[vc-comment-search-forward] search backward for regexp in the comment ring
1705 Entry to the change-log submode calls the value of text-mode-hook, then
1706 the value of vc-log-mode-hook.
1708 Global user options:
1709 vc-initial-comment If non-nil, require user to enter a change
1710 comment upon first checkin of the file.
1712 vc-keep-workfiles Non-nil value prevents workfiles from being
1713 deleted when changes are checked in
1715 vc-suppress-confirm Suppresses some confirmation prompts,
1716 notably for reversions.
1718 vc-header-alist Which keywords to insert when adding headers
1719 with \\[vc-insert-headers]. Defaults to
1720 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under RCS.
1722 vc-static-header-alist By default, version headers inserted in C files
1723 get stuffed in a static string area so that
1724 ident(RCS) or what(SCCS) can see them in the
1725 compiled object code. You can override this
1726 by setting this variable to nil, or change
1727 the header template by changing it.
1729 vc-command-messages if non-nil, display run messages from the
1730 actual version-control utilities (this is
1731 intended primarily for people hacking vc
1735 (set-syntax-table text-mode-syntax-table)
1736 (use-local-map vc-log-entry-mode)
1737 (setq local-abbrev-table text-mode-abbrev-table)
1738 (setq major-mode 'vc-log-mode)
1739 (setq mode-name "VC-Log")
1740 (make-local-variable 'vc-log-file)
1741 (make-local-variable 'vc-log-version)
1742 (make-local-variable 'vc-comment-ring-index)
1743 (set-buffer-modified-p nil)
1744 (setq buffer-file-name nil)
1745 (run-hooks 'text-mode-hook 'vc-log-mode-hook)
1748 ;; Initialization code, to be done just once at load-time
1749 (if vc-log-entry-mode
1751 (setq vc-log-entry-mode (make-sparse-keymap))
1752 (define-key vc-log-entry-mode "\M-n" 'vc-next-comment)
1753 (define-key vc-log-entry-mode "\M-p" 'vc-previous-comment)
1754 (define-key vc-log-entry-mode "\M-r" 'vc-comment-search-reverse)
1755 (define-key vc-log-entry-mode "\M-s" 'vc-comment-search-forward)
1756 (define-key vc-log-entry-mode "\C-c\C-c" 'vc-finish-logentry)
1759 ;;; These things should probably be generally available
1761 (defun vc-file-tree-walk (func &rest args)
1762 "Walk recursively through default directory.
1763 Invoke FUNC f ARGS on each non-directory file f underneath it."
1764 (vc-file-tree-walk-internal default-directory func args)
1765 (message "Traversing directory %s...done" default-directory))
1767 (defun vc-file-tree-walk-internal (file func args)
1768 (if (not (file-directory-p file))
1769 (apply func file args)
1770 (message "Traversing directory %s..." file)
1771 (let ((dir (file-name-as-directory file)))
1775 (string-equal f ".")
1776 (string-equal f "..")
1777 (let ((dirf (concat dir f)))
1779 (file-symlink-p dirf) ;; Avoid possible loops
1780 (vc-file-tree-walk-internal dirf func args))))))
1781 (directory-files dir)))))
1785 ;;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
1787 ;;; These may be useful to anyone who has to debug or extend the package.
1789 ;;; A fundamental problem in VC is that there are time windows between
1790 ;;; vc-next-action's computations of the file's version-control state and
1791 ;;; the actions that change it. This is a window open to lossage in a
1792 ;;; multi-user environment; someone else could nip in and change the state
1793 ;;; of the master during it.
1795 ;;; The performance problem is that rlog/prs calls are very expensive; we want
1796 ;;; to avoid them as much as possible.
1800 ;;; The performance problem, it turns out, simplifies in practice to the
1801 ;;; problem of making vc-locking-user fast. The two other functions that call
1802 ;;; prs/rlog will not be so commonly used that the slowdown is a problem; one
1803 ;;; makes snapshots, the other deletes the calling user's last change in the
1806 ;;; The race condition implies that we have to either (a) lock the master
1807 ;;; during the entire execution of vc-next-action, or (b) detect and
1808 ;;; recover from errors resulting from dispatch on an out-of-date state.
1810 ;;; Alternative (a) appears to be unfeasible. The problem is that we can't
1811 ;;; guarantee that the lock will ever be removed. Suppose a user starts a
1812 ;;; checkin, the change message buffer pops up, and the user, having wandered
1813 ;;; off to do something else, simply forgets about it?
1815 ;;; Alternative (b), on the other hand, works well with a cheap way to speed up
1816 ;;; vc-locking-user. Usually, if a file is registered, we can read its locked/
1817 ;;; unlocked state and its current owner from its permissions.
1819 ;;; This shortcut will fail if someone has manually changed the workfile's
1820 ;;; permissions; also if developers are munging the workfile in several
1821 ;;; directories, with symlinks to a master (in this latter case, the
1822 ;;; permissions shortcut will fail to detect a lock asserted from another
1825 ;;; Note that these cases correspond exactly to the errors which could happen
1826 ;;; because of a competing checkin/checkout race in between two instances of
1829 ;;; For VC's purposes, a workfile/master pair may have the following states:
1831 ;;; A. Unregistered. There is a workfile, there is no master.
1833 ;;; B. Registered and not locked by anyone.
1835 ;;; C. Locked by calling user and unchanged.
1837 ;;; D. Locked by the calling user and changed.
1839 ;;; E. Locked by someone other than the calling user.
1841 ;;; This makes for 25 states and 20 error conditions. Here's the matrix:
1843 ;;; VC's idea of state
1845 ;;; V Actual state RCS action SCCS action Effect
1847 ;;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
1848 ;;; B 5 . 6 7 8 co -l get -e checkout
1849 ;;; C 9 10 . 11 12 co -u unget; get revert
1850 ;;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
1851 ;;; E 17 18 19 20 . rcs -u -M ; rcs -l unget -n ; get -g steal lock
1853 ;;; All commands take the master file name as a last argument (not shown).
1855 ;;; In the discussion below, a "self-race" is a pathological situation in
1856 ;;; which VC operations are being attempted simultaneously by two or more
1857 ;;; Emacsen running under the same username.
1859 ;;; The vc-next-action code has the following windows:
1862 ;;; Between the check for existence of a master file and the call to
1863 ;;; admin/checkin in vc-buffer-admin (apparent state A). This window may
1864 ;;; never close if the initial-comment feature is on.
1867 ;;; Between the call to vc-workfile-unchanged-p in and the immediately
1868 ;;; following revert (apparent state C).
1871 ;;; Between the call to vc-workfile-unchanged-p in and the following
1872 ;;; checkin (apparent state D). This window may never close.
1875 ;;; Between the unlock and the immediately following checkout during a
1876 ;;; revert operation (apparent state C). Included in window Q.
1879 ;;; Between vc-locking-user and the following checkout (apparent state B).
1882 ;;; Between vc-locking-user and the following revert (apparent state C).
1883 ;;; Includes windows Q and S.
1886 ;;; Between vc-locking-user and the following checkin (apparent state
1887 ;;; D). This window may never be closed if the user fails to complete the
1888 ;;; checkin message. Includes window R.
1891 ;;; Between vc-locking-user and the following steal-lock (apparent
1892 ;;; state E). This window may never close if the user fails to complete
1893 ;;; the steal-lock message. Includes window X.
1896 ;;; Between the unlock and the immediately following re-lock during a
1897 ;;; steal-lock operation (apparent state E). This window may never cloce
1898 ;;; if the user fails to complete the steal-lock message.
1902 ;;; Apparent state A ---
1904 ;;; 1. File looked unregistered but is actually registered and not locked.
1906 ;;; Potential cause: someone else's admin during window P, with
1907 ;;; caller's admin happening before their checkout.
1909 ;;; RCS: ci will fail with a "no lock set by <user>" message.
1910 ;;; SCCS: admin will fail with error (ad19).
1912 ;;; We can let these errors be passed up to the user.
1914 ;;; 2. File looked unregistered but is actually locked by caller, unchanged.
1916 ;;; Potential cause: self-race during window P.
1918 ;;; RCS: will revert the file to the last saved version and unlock it.
1919 ;;; SCCS: will fail with error (ad19).
1921 ;;; Either of these consequences is acceptable.
1923 ;;; 3. File looked unregistered but is actually locked by caller, changed.
1925 ;;; Potential cause: self-race during window P.
1927 ;;; RCS: will register the caller's workfile as a delta with a
1928 ;;; null change comment (the -t- switch will be ignored).
1929 ;;; SCCS: will fail with error (ad19).
1931 ;;; 4. File looked unregistered but is locked by someone else.
1933 ;;; Potential cause: someone else's admin during window P, with
1934 ;;; caller's admin happening *after* their checkout.
1936 ;;; RCS: will fail with a "no lock set by <user>" message.
1937 ;;; SCCS: will fail with error (ad19).
1939 ;;; We can let these errors be passed up to the user.
1941 ;;; Apparent state B ---
1943 ;;; 5. File looked registered and not locked, but is actually unregistered.
1945 ;;; Potential cause: master file got nuked during window P.
1947 ;;; RCS: will fail with "RCS/<file>: No such file or directory"
1948 ;;; SCCS: will fail with error ut4.
1950 ;;; We can let these errors be passed up to the user.
1952 ;;; 6. File looked registered and not locked, but is actually locked by the
1953 ;;; calling user and unchanged.
1955 ;;; Potential cause: self-race during window T.
1957 ;;; RCS: in the same directory as the previous workfile, co -l will fail
1958 ;;; with "co error: writable foo exists; checkout aborted". In any other
1959 ;;; directory, checkout will succeed.
1960 ;;; SCCS: will fail with ge17.
1962 ;;; Either of these consequences is acceptable.
1964 ;;; 7. File looked registered and not locked, but is actually locked by the
1965 ;;; calling user and changed.
1969 ;;; 8. File looked registered and not locked, but is actually locked by another
1972 ;;; Potential cause: someone else checks it out during window T.
1974 ;;; RCS: co error: revision 1.3 already locked by <user>
1975 ;;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
1977 ;;; We can let these errors be passed up to the user.
1979 ;;; Apparent state C ---
1981 ;;; 9. File looks locked by calling user and unchanged, but is unregistered.
1985 ;;; 10. File looks locked by calling user and unchanged, but is actually not
1988 ;;; Potential cause: a self-race in window U, or by the revert's
1989 ;;; landing during window X of some other user's steal-lock or window S
1990 ;;; of another user's revert.
1992 ;;; RCS: succeeds, refreshing the file from the identical version in
1994 ;;; SCCS: fails with error ut4 (p file nonexistent).
1996 ;;; Either of these consequences is acceptable.
1998 ;;; 11. File is locked by calling user. It looks unchanged, but is actually
2001 ;;; Potential cause: the file would have to be touched by a self-race
2002 ;;; during window Q.
2004 ;;; The revert will succeed, removing whatever changes came with
2005 ;;; the touch. It is theoretically possible that work could be lost.
2007 ;;; 12. File looks like it's locked by the calling user and unchanged, but
2008 ;;; it's actually locked by someone else.
2010 ;;; Potential cause: a steal-lock in window V.
2012 ;;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
2013 ;;; SCCS: fails with error un2
2015 ;;; We can pass these errors up to the user.
2017 ;;; Apparent state D ---
2019 ;;; 13. File looks like it's locked by the calling user and changed, but it's
2020 ;;; actually unregistered.
2022 ;;; Potential cause: master file got nuked during window P.
2024 ;;; RCS: Checks in the user's version as an initial delta.
2025 ;;; SCCS: will fail with error ut4.
2027 ;;; This case is kind of nasty. It means VC may fail to detect the
2028 ;;; loss of previous version information.
2030 ;;; 14. File looks like it's locked by the calling user and changed, but it's
2031 ;;; actually unlocked.
2033 ;;; Potential cause: self-race in window V, or the checkin happening
2034 ;;; during the window X of someone else's steal-lock or window S of
2035 ;;; someone else's revert.
2037 ;;; RCS: ci will fail with "no lock set by <user>".
2038 ;;; SCCS: delta will fail with error ut4.
2040 ;;; 15. File looks like it's locked by the calling user and changed, but it's
2041 ;;; actually locked by the calling user and unchanged.
2043 ;;; Potential cause: another self-race --- a whole checkin/checkout
2044 ;;; sequence by the calling user would have to land in window R.
2046 ;;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
2047 ;;; RCS: reverts to the file state as of the second user's checkin, leaving
2048 ;;; the file unlocked.
2050 ;;; It is theoretically possible that work could be lost under RCS.
2052 ;;; 16. File looks like it's locked by the calling user and changed, but it's
2053 ;;; actually locked by a different user.
2055 ;;; RCS: ci error: no lock set by <user>
2056 ;;; SCCS: unget will fail with error un2
2058 ;;; We can pass these errors up to the user.
2060 ;;; Apparent state E ---
2062 ;;; 17. File looks like it's locked by some other user, but it's actually
2067 ;;; 18. File looks like it's locked by some other user, but it's actually
2070 ;;; Potential cause: someone released a lock during window W.
2072 ;;; RCS: The calling user will get the lock on the file.
2073 ;;; SCCS: unget -n will fail with cm4.
2075 ;;; Either of these consequences will be OK.
2077 ;;; 19. File looks like it's locked by some other user, but it's actually
2078 ;;; locked by the calling user and unchanged.
2080 ;;; Potential cause: the other user relinquishing a lock followed by
2081 ;;; a self-race, both in window W.
2083 ;;; Under both RCS and SCCS, both unlock and lock will succeed, making
2084 ;;; the sequence a no-op.
2086 ;;; 20. File looks like it's locked by some other user, but it's actually
2087 ;;; locked by the calling user and changed.
2093 ;;; In order of decreasing severity:
2095 ;;; Cases 11 and 15 under RCS are the only one that potentially lose work.
2096 ;;; They would require a self-race for this to happen.
2098 ;;; Case 13 in RCS loses information about previous deltas, retaining
2099 ;;; only the information in the current workfile. This can only happen
2100 ;;; if the master file gets nuked in window P.
2102 ;;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
2103 ;;; no change comment in the master. This would require a self-race in
2104 ;;; window P or R respectively.
2106 ;;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
2108 ;;; Unfortunately, it appears to me that no recovery is possible in these
2109 ;;; cases. They don't yield error messages, so there's no way to tell that
2110 ;;; a race condition has occurred.
2112 ;;; All other cases don't change either the workfile or the master, and
2113 ;;; trigger command errors which the user will see.
2115 ;;; Thus, there is no explicit recovery code.