1 ;;; vc.el --- drive a version-control system from within Emacs
3 ;; Copyright (C) 1992, 1993 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
)
367 (if vc-initial-comment
368 (setq vc-log-after-operation-hook
369 'vc-checkout-writable-buffer-hook
)
370 (vc-checkout-writable-buffer file
)))
372 ;; if there is no lock on the file, assert one and get it
373 ((not (setq owner
(vc-locking-user file
)))
374 (if (and vc-checkout-carefully
375 (not (vc-workfile-unchanged-p file t
)))
376 (if (save-window-excursion
377 (pop-to-buffer "*vc*")
378 (goto-char (point-min))
379 (insert-string (format "Changes to %s since last lock:\n\n"
383 (concat "File has unlocked changes, "
384 "claim lock retaining changes? ")))
385 (progn (vc-backend-steal file
)
387 (if (not (yes-or-no-p "Revert to checked-in version, instead? "))
388 (error "Checkout aborted.")
389 (vc-revert-buffer1 t t
)
390 (vc-checkout-writable-buffer file
))
392 (vc-checkout-writable-buffer file
)))
394 ;; a checked-out version exists, but the user may not own the lock
395 ((not (string-equal owner
(user-login-name)))
397 (error "Sorry, you can't steal the lock on %s this way" file
))
400 (and verbose
(read-string "Version to steal: "))
403 ;; OK, user owns the lock on the file
407 ;; give luser a chance to save before checking in.
410 ;; Revert if file is unchanged and buffer is too.
411 ;; If buffer is modified, that means the user just said no
412 ;; to saving it; in that case, don't revert,
413 ;; because the user might intend to save
414 ;; after finishing the log entry.
415 (if (and (vc-workfile-unchanged-p file
)
416 (not (buffer-modified-p)))
418 (vc-backend-revert file
)
419 ;; DO NOT revert the file without asking the user!
420 (vc-resynch-window file t nil
))
422 ;; user may want to set nonstandard parameters
424 (setq version
(read-string "New version level: ")))
426 ;; OK, let's do the checkin
427 (vc-checkin file version comment
)
430 (defun vc-next-action-dired (file rev comment
)
431 ;; We've accepted a log comment, now do a vc-next-action using it on all
433 (set-buffer vc-parent-buffer
)
434 (dired-map-over-marks
435 (save-window-excursion
436 (let ((file (dired-get-filename)))
437 (message "Processing %s..." file
)
438 (vc-next-action-on-file file nil comment
)
439 (message "Processing %s...done" file
)))
443 ;; Here's the major entry point.
446 (defun vc-next-action (verbose)
447 "Do the next logical checkin or checkout operation on the current file.
448 If the file is not already registered, this registers it for version
449 control and then retrieves a writable, locked copy for editing.
450 If the file is registered and not locked by anyone, this checks out
451 a writable and locked file ready for editing.
452 If the file is checked out and locked by the calling user, this
453 first checks to see if the file has changed since checkout. If not,
454 it performs a revert.
455 If the file has been changed, this pops up a buffer for entry
456 of a log message; when the message has been entered, it checks in the
457 resulting changes along with the log message as change commentary. If
458 the variable `vc-keep-workfiles' is non-nil (which is its default), a
459 read-only copy of the changed file is left in place afterwards.
460 If the file is registered and locked by someone else, you are given
461 the option to steal the lock.
462 If you call this from within a VC dired buffer with no files marked,
463 it will operate on the file in the current line.
464 If you call this from within a VC dired buffer, and one or more
465 files are marked, it will accept a log message and then operate on
466 each one. The log message will be used as a comment for any register
467 or checkin operations, but ignored when doing checkouts. Attempted
468 lock steals will raise an error.
470 For checkin, a prefix argument lets you specify the version number to use."
474 (let ((files (dired-get-marked-files)))
475 (if (= (length files
) 1)
476 (find-file-other-window (dired-get-filename))
477 (vc-start-entry nil nil nil
478 "Enter a change comment for the marked files."
479 'vc-next-action-dired
)
481 (while vc-parent-buffer
482 (pop-to-buffer vc-parent-buffer
))
484 (vc-next-action-on-file buffer-file-name verbose
)
485 (vc-registration-error nil
))))
487 ;;; These functions help the vc-next-action entry point
489 (defun vc-checkout-writable-buffer (&optional file
)
490 "Retrieve a writable copy of the latest version of the current buffer's file."
491 (vc-checkout (or file
(buffer-file-name)) t
)
495 (defun vc-register (&optional override comment
)
496 "Register the current file into your version-control system."
498 (if (vc-name buffer-file-name
)
499 (error "This file is already registered"))
500 ;; Watch out for new buffers of size 0: the corresponding file
501 ;; does not exist yet, even though buffer-modified-p is nil.
502 (if (and (not (buffer-modified-p))
503 (zerop (buffer-size))
504 (not (file-exists-p buffer-file-name
)))
505 (set-buffer-modified-p t
))
511 (format "Initial version level for %s: " buffer-file-name
))))
514 (defun vc-resynch-window (file &optional keep noquery
)
515 ;; If the given file is in the current buffer,
516 ;; either revert on it so we see expanded keyworks,
517 ;; or unvisit it (depending on vc-keep-workfiles)
518 ;; NOQUERY if non-nil inhibits confirmation for reverting.
519 ;; NOQUERY should be t *only* if it is known the only difference
520 ;; between the buffer and the file is due to RCS rather than user editing!
521 (and (string= buffer-file-name file
)
524 (vc-revert-buffer1 t noquery
)
525 (vc-mode-line buffer-file-name
))
528 (kill-buffer (current-buffer))))))
530 (defun vc-start-entry (file rev comment msg action
)
531 ;; Accept a comment for an operation on FILE revision REV. If COMMENT
532 ;; is nil, pop up a VC-log buffer, emit MSG, and set the
533 ;; action on close to ACTION; otherwise, do action immediately.
534 ;; Remember the file's buffer in parent-buffer (current one if no file).
535 (let ((parent (if file
(find-file-noselect file
) (current-buffer))))
537 (set-buffer (get-buffer-create "*VC-log*"))
538 (pop-to-buffer (get-buffer-create "*VC-log*")))
539 (set (make-local-variable 'vc-parent-buffer
) parent
)
540 (set (make-local-variable 'vc-parent-buffer-name
)
541 (concat " from " (buffer-name vc-parent-buffer
)))
542 (vc-mode-line (or file
" (no file)"))
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
))
564 (defun vc-checkout (file &optional writable
)
565 "Retrieve a copy of the latest version of the given file."
566 ;; If ftp is on this system and the name matches the ange-ftp format
567 ;; for a remote file, the user is trying something that won't work.
568 (if (and (string-match "^/[^/:]+:" file
) (vc-find-binary "ftp"))
569 (error "Sorry, you can't check out files over FTP"))
570 (vc-backend-checkout file writable
)
571 (if (string-equal file buffer-file-name
)
572 (vc-resynch-window file t t
))
575 (defun vc-steal-lock (file rev
&optional owner
)
576 "Steal the lock on the current workfile."
579 (setq owner
(vc-locking-user file
)))
580 (if (not (y-or-n-p (format "Take the lock on %s:%s from %s? " file rev owner
)))
581 (error "Steal cancelled"))
582 (pop-to-buffer (get-buffer-create "*VC-mail*"))
583 (setq default-directory
(expand-file-name "~/"))
584 (auto-save-mode auto-save-default
)
587 (mail-setup owner
(format "%s:%s" file rev
) nil nil nil
588 (list (list 'vc-finish-steal file rev
)))
589 (goto-char (point-max))
591 (format "I stole the lock on %s:%s, " file rev
)
592 (current-time-string)
594 (message "Please explain why you stole the lock. Type C-c C-c when done."))
596 ;; This is called when the notification has been sent.
597 (defun vc-finish-steal (file version
)
598 (vc-backend-steal file version
)
599 (vc-resynch-window file t t
))
601 (defun vc-checkin (file &optional rev comment
)
602 "Check in the file specified by FILE.
603 The optional argument REV may be a string specifying the new version level
604 \(if nil increment the current level). The file is either retained with write
605 permissions zeroed, or deleted (according to the value of `vc-keep-workfiles').
606 COMMENT is a comment string; if omitted, a buffer is
607 popped up to accept a comment."
608 (setq vc-log-after-operation-hook
'vc-checkin-hook
)
609 (vc-start-entry file rev comment
610 "Enter a change comment." 'vc-backend-checkin
))
612 ;;; Here is a checkin hook that may prove useful to sites using the
613 ;;; ChangeLog facility supported by Emacs.
614 (defun vc-comment-to-change-log (&optional whoami file-name
)
615 "Enter last VC comment into change log file for current buffer's file.
616 Optional arg (interactive prefix) non-nil means prompt for user name and site.
617 Second arg is file name of change log. \
618 If nil, uses `change-log-default-name'."
619 (interactive (if current-prefix-arg
620 (list current-prefix-arg
621 (prompt-for-change-log-name))))
622 ;; Make sure the defvar for add-log-current-defun-function has been executed
623 ;; before binding it.
625 (let (;; Extract the comment first so we get any error before doing anything.
626 (comment (ring-ref vc-comment-ring
0))
627 ;; Don't let add-change-log-entry insert a defun name.
628 (add-log-current-defun-function 'ignore
)
630 ;; Call add-log to do half the work.
631 (add-change-log-entry whoami file-name t t
)
632 ;; Insert the VC comment, leaving point before it.
633 (setq end
(save-excursion (insert comment
) (point-marker)))
634 (if (looking-at "\\s *\\s(")
635 ;; It starts with an open-paren, as in "(foo): Frobbed."
636 ;; So remove the ": " add-log inserted.
638 ;; Canonicalize the white space between the file name and comment.
640 ;; Indent rest of the text the same way add-log indented the first line.
641 (let ((indentation (current-indentation)))
643 (while (< (point) end
)
645 (indent-to indentation
))
647 ;; Fill the inserted text, preserving open-parens at bol.
648 (let ((paragraph-separate (concat paragraph-separate
"\\|^\\s *\\s("))
649 (paragraph-start (concat paragraph-start
"\\|^\\s *\\s(")))
651 (fill-region (point) end
))
652 ;; Canonicalize the white space at the end of the entry so it is
653 ;; separated from the next entry by a single blank line.
654 (skip-syntax-forward " " end
)
655 (delete-char (- (skip-syntax-backward " ")))
656 (or (eobp) (looking-at "\n\n")
660 (defun vc-finish-logentry (&optional nocomment
)
661 "Complete the operation implied by the current log entry."
663 ;; Check and record the comment, if any.
666 (goto-char (point-max))
670 (vc-backend-logentry-check vc-log-file
)
671 ;; Record the comment in the comment ring
672 (if (null vc-comment-ring
)
673 (setq vc-comment-ring
(make-ring vc-maximum-comment-ring-size
)))
674 (ring-insert vc-comment-ring
(buffer-string))
676 ;; Sync parent buffer in case the user modified it while editing the comment.
678 (set-buffer vc-parent-buffer
)
683 (funcall vc-log-operation
687 (error "No log operation is pending"))
688 ;; Return to "parent" buffer of this checkin and remove checkin window
689 (pop-to-buffer vc-parent-buffer
)
690 (let ((logbuf (get-buffer "*VC-log*")))
691 (delete-windows-on logbuf
)
692 (kill-buffer logbuf
))
693 ;; Now make sure we see the expanded headers
695 (vc-resynch-window buffer-file-name vc-keep-workfiles t
))
696 (run-hooks vc-log-after-operation-hook
))
698 ;; Code for access to the comment ring
700 (defun vc-previous-comment (arg)
701 "Cycle backwards through comment history."
703 (let ((len (ring-length vc-comment-ring
)))
705 (message "Empty comment ring")
709 ;; Initialize the index on the first use of this command
710 ;; so that the first M-p gets index 0, and the first M-n gets
712 (if (null vc-comment-ring-index
)
713 (setq vc-comment-ring-index
715 (if (< arg
0) 1 0))))
716 (setq vc-comment-ring-index
717 (mod (+ vc-comment-ring-index arg
) len
))
718 (message "%d" (1+ vc-comment-ring-index
))
719 (insert (ring-ref vc-comment-ring vc-comment-ring-index
))))))
721 (defun vc-next-comment (arg)
722 "Cycle forwards through comment history."
724 (vc-previous-comment (- arg
)))
726 (defun vc-comment-search-reverse (str)
727 "Searches backwards through comment history for substring match."
728 (interactive "sComment substring: ")
730 (setq str vc-last-comment-match
)
731 (setq vc-last-comment-match str
))
732 (if (null vc-comment-ring-index
)
733 (setq vc-comment-ring-index -
1))
734 (let ((str (regexp-quote str
))
735 (len (ring-length vc-comment-ring
))
736 (n (1+ vc-comment-ring-index
)))
737 (while (and (< n len
) (not (string-match str
(ring-ref vc-comment-ring n
))))
740 (vc-previous-comment (- n vc-comment-ring-index
)))
741 (t (error "Not found")))))
743 (defun vc-comment-search-forward (str)
744 "Searches forwards through comment history for substring match."
745 (interactive "sComment substring: ")
747 (setq str vc-last-comment-match
)
748 (setq vc-last-comment-match str
))
749 (if (null vc-comment-ring-index
)
750 (setq vc-comment-ring-index
0))
751 (let ((str (regexp-quote str
))
752 (len (ring-length vc-comment-ring
))
753 (n vc-comment-ring-index
))
754 (while (and (>= n
0) (not (string-match str
(ring-ref vc-comment-ring n
))))
757 (vc-next-comment (- n vc-comment-ring-index
)))
758 (t (error "Not found")))))
760 ;; Additional entry points for examining version histories
763 (defun vc-diff (historic &optional not-urgent
)
764 "Display diffs between file versions.
765 Normally this compares the current file and buffer with the most recent
766 checked in version of that file. This uses no arguments.
767 With a prefix argument, it reads the file name to use
768 and two version designators specifying which versions to compare."
771 (set-buffer (find-file-noselect (dired-get-filename))))
772 (while vc-parent-buffer
773 (pop-to-buffer vc-parent-buffer
))
775 (call-interactively 'vc-version-diff
)
776 (if (or (null buffer-file-name
) (null (vc-name buffer-file-name
)))
778 "There is no version-control master associated with this buffer"))
779 (let ((file buffer-file-name
)
781 (or (and file
(vc-name file
))
782 (vc-registration-error file
))
783 (vc-buffer-sync not-urgent
)
784 (setq unchanged
(vc-workfile-unchanged-p buffer-file-name
))
786 (message "No changes to %s since latest version." file
)
787 (vc-backend-diff file
)
788 ;; Ideally, we'd like at this point to parse the diff so that
789 ;; the buffer effectively goes into compilation mode and we
790 ;; can visit the old and new change locations via next-error.
791 ;; Unfortunately, this is just too painful to do. The basic
792 ;; problem is that the `old' file doesn't exist to be
793 ;; visited. This plays hell with numerous assumptions in
794 ;; the diff.el and compile.el machinery.
795 (pop-to-buffer "*vc*")
796 (pop-to-buffer "*vc*")
797 (if (= 0 (buffer-size))
800 (message "No changes to %s since latest version." file
))
801 (goto-char (point-min))
802 (shrink-window-if-larger-than-buffer)))
805 (defun vc-version-diff (file rel1 rel2
)
806 "For FILE, report diffs between two stored versions REL1 and REL2 of it.
807 If FILE is a directory, generate diffs between versions for all registered
808 files in or below it."
809 (interactive "FFile or directory to diff: \nsOlder version: \nsNewer version: ")
810 (if (string-equal rel1
"") (setq rel1 nil
))
811 (if (string-equal rel2
"") (setq rel2 nil
))
812 (if (file-directory-p file
)
813 (let ((camefrom (current-buffer)))
814 (set-buffer (get-buffer-create "*vc-status*"))
815 (set (make-local-variable 'vc-parent-buffer
) camefrom
)
816 (set (make-local-variable 'vc-parent-buffer-name
)
817 (concat " from " (buffer-name camefrom
)))
819 (insert "Diffs between "
820 (or rel1
"last version checked in")
822 (or rel2
"current workfile(s)")
824 (set-buffer (get-buffer-create "*vc*"))
827 (function (lambda (f)
828 (message "Looking at %s" f
)
830 (not (file-directory-p f
))
832 (vc-backend-diff f rel1 rel2
)
833 (append-to-buffer "*vc-status*" (point-min) (point-max)))
835 (pop-to-buffer "*vc-status*")
836 (insert "\nEnd of diffs.\n")
837 (goto-char (point-min))
838 (set-buffer-modified-p nil
)
840 (if (zerop (vc-backend-diff file rel1 rel2
))
841 (message "No changes to %s between %s and %s." file rel1 rel2
)
842 (pop-to-buffer "*vc*"))))
845 (defun vc-version-other-window (rev)
846 "Visit version REV of the current buffer in another window.
847 If the current buffer is named `F', the version is named `F.~REV~'.
848 If `F.~REV~' already exists, it is used instead of being re-created."
849 (interactive "sVersion to visit (default is latest version): ")
851 (set-buffer (find-file-noselect (dired-get-filename))))
852 (while vc-parent-buffer
853 (pop-to-buffer vc-parent-buffer
))
854 (if (and buffer-file-name
(vc-name buffer-file-name
))
855 (let* ((version (if (string-equal rev
"")
856 (vc-latest-version buffer-file-name
)
858 (filename (concat buffer-file-name
".~" version
"~")))
859 (or (file-exists-p filename
)
860 (vc-backend-checkout buffer-file-name nil version filename
))
861 (find-file-other-window filename
))
862 (vc-registration-error buffer-file-name
)))
864 ;; Header-insertion code
867 (defun vc-insert-headers ()
868 "Insert headers in a file for use with your version-control system.
869 Headers desired are inserted at the start of the buffer, and are pulled from
870 the variable `vc-header-alist'."
873 (find-file-other-window (dired-get-filename)))
874 (while vc-parent-buffer
875 (pop-to-buffer vc-parent-buffer
))
879 (if (or (not (vc-check-headers))
880 (y-or-n-p "Version headers already exist. Insert another set? "))
882 (let* ((delims (cdr (assq major-mode vc-comment-alist
)))
883 (comment-start-vc (or (car delims
) comment-start
"#"))
884 (comment-end-vc (or (car (cdr delims
)) comment-end
""))
885 (hdstrings (cdr (assoc (vc-backend-deduce (buffer-file-name)) vc-header-alist
))))
886 (mapcar (function (lambda (s)
887 (insert comment-start-vc
"\t" s
"\t"
888 comment-end-vc
"\n")))
890 (if vc-static-header-alist
891 (mapcar (function (lambda (f)
892 (if (string-match (car f
) buffer-file-name
)
893 (insert (format (cdr f
) (car hdstrings
))))))
894 vc-static-header-alist
))
898 ;; The VC directory submode. Coopt Dired for this.
899 ;; All VC commands get mapped into logical equivalents.
901 (defvar vc-dired-prefix-map
(make-sparse-keymap))
902 (define-key vc-dired-prefix-map
"\C-xv" vc-prefix-map
)
904 (or (not (boundp 'minor-mode-map-alist
))
905 (assq 'vc-dired-mode minor-mode-map-alist
)
906 (setq minor-mode-map-alist
907 (cons (cons 'vc-dired-mode vc-dired-prefix-map
)
908 minor-mode-map-alist
)))
910 (defun vc-dired-mode ()
911 "The augmented Dired minor mode used in VC directory buffers.
912 All Dired commands operate normally. Users currently locking listed files
913 are listed in place of the file's owner and group.
914 Keystrokes bound to VC commands will execute as though they had been called
915 on a buffer attached to the file named in the current Dired buffer line."
916 (setq vc-dired-mode t
)
917 (setq vc-mode
" under VC"))
919 (defun vc-dired-reformat-line (x)
920 ;; Hack a directory-listing line, plugging in locking-user info in
921 ;; place of the user and group info. Should have the beneficial
922 ;; side-effect of shortening the listing line. Each call starts with
923 ;; point immediately following the dired mark area on the line to be
926 ;; Simplest possible one:
927 ;; (insert (concat x "\t")))
929 ;; This code, like dired, assumes UNIX -l format.
930 (forward-word 1) ;; skip over any extra field due to -ibs options
931 (if x
(setq x
(concat "(" x
")")))
932 (if (re-search-forward "\\([0-9]+ \\).................\\( .*\\)" nil
0)
933 (let ((rep (substring (concat x
" ") 0 9)))
934 (replace-match (concat "\\1" rep
"\\2") t
)))
937 ;;; Note in Emacs 18 the following defun gets overridden
938 ;;; with the symbol 'vc-directory-18. See below.
940 (defun vc-directory (verbose)
941 "Show version-control status of all files under the current directory."
944 (dl (length default-directory
))
945 (filelist nil
) (userlist nil
)
949 (function (lambda (f)
950 (if (vc-registered f
)
951 (let ((user (vc-locking-user f
)))
952 (and (or verbose user
)
953 (setq filelist
(cons (substring f dl
) filelist
))
954 (setq userlist
(cons user userlist
))))))))
956 ;; This uses a semi-documented feature of dired; giving a switch
957 ;; argument forces the buffer to refresh each time.
959 (cons default-directory
(nreverse filelist
))
960 dired-listing-switches
)
961 (setq dired-buf
(current-buffer))
962 (setq nonempty
(not (zerop (buffer-size)))))
965 (pop-to-buffer dired-buf
)
967 (goto-char (point-min))
968 (setq buffer-read-only nil
)
969 (forward-line 1) ;; Skip header line
973 (forward-char 2) ;; skip dired's mark area
974 (vc-dired-reformat-line x
)
975 (forward-line 1))) ;; go to next line
977 (setq buffer-read-only t
)
978 (goto-char (point-min))
980 (message "No files are currently %s under %s"
981 (if verbose
"registered" "locked") default-directory
))
985 (defun vc-directory-18 (verbose)
986 "Show version-control status of all files under the current directory."
988 (let (nonempty (dir default-directory
))
990 (set-buffer (get-buffer-create "*vc-status*"))
994 (function (lambda (f)
995 (if (vc-registered f
)
996 (let ((user (vc-locking-user f
)))
997 (if (or user verbose
)
1000 (concat user
) f
))))))))
1001 (setq nonempty
(not (zerop (buffer-size)))))
1004 (pop-to-buffer "*vc-status*" t
)
1005 (goto-char (point-min))
1006 (shrink-window-if-larger-than-buffer)))
1007 (message "No files are currently %s under %s"
1008 (if verbose
"registered" "locked") default-directory
))
1011 (or (boundp 'minor-mode-map-alist
)
1012 (fset 'vc-directory
'vc-directory-18
))
1014 ; Emacs 18 also lacks these.
1015 (or (boundp 'compilation-old-error-list
)
1016 (setq compilation-old-error-list nil
))
1018 ;; Named-configuration support for SCCS
1020 (defun vc-add-triple (name file rev
)
1022 (find-file (concat (vc-backend-subdirectory-name file
) "/" vc-name-assoc-file
))
1023 (goto-char (point-max))
1024 (insert name
"\t:\t" file
"\t" rev
"\n")
1026 (kill-buffer (current-buffer))
1029 (defun vc-record-rename (file newname
)
1031 (find-file (concat (vc-backend-subdirectory-name file
) "/" vc-name-assoc-file
))
1032 (goto-char (point-min))
1033 ;; (replace-regexp (concat ":" (regexp-quote file) "$") (concat ":" newname))
1034 (while (re-search-forward (concat ":" (regexp-quote file
) "$") nil t
)
1035 (replace-match (concat ":" newname
) nil nil
))
1037 (kill-buffer (current-buffer))
1040 (defun vc-lookup-triple (file name
)
1041 ;; Return the numeric version corresponding to a named snapshot of file
1042 ;; If name is nil or a version number string it's just passed through
1043 (cond ((null name
) name
)
1044 ((let ((firstchar (aref name
0)))
1045 (and (>= firstchar ?
0) (<= firstchar ?
9)))
1048 (car (vc-master-info
1049 (concat (vc-backend-subdirectory-name file
) "/" vc-name-assoc-file
)
1050 (list (concat name
"\t:\t" file
"\t\\(.+\\)"))))
1053 ;; Named-configuration entry points
1055 (defun vc-locked-example ()
1056 ;; Return an example of why the current directory is not ready to be snapshot
1057 ;; or nil if no such example exists.
1058 (catch 'vc-locked-example
1060 (function (lambda (f)
1061 (if (and (vc-registered f
) (vc-locking-user f
))
1062 (throw 'vc-locked-example f
)))))
1066 (defun vc-create-snapshot (name)
1067 "Make a snapshot called NAME.
1068 The snapshot is made from all registered files at or below the current
1069 directory. For each file, the version level of its latest
1070 version becomes part of the named configuration."
1071 (interactive "sNew snapshot name: ")
1072 (let ((locked (vc-locked-example)))
1074 (error "File %s is locked" locked
)
1076 (function (lambda (f) (and
1078 (vc-backend-assign-name f name
)))))
1082 (defun vc-retrieve-snapshot (name)
1083 "Retrieve the snapshot called NAME.
1084 This function fails if any files are locked at or below the current directory
1085 Otherwise, all registered files are checked out (unlocked) at their version
1086 levels in the snapshot."
1087 (interactive "sSnapshot name to retrieve: ")
1088 (let ((locked (vc-locked-example)))
1090 (error "File %s is locked" locked
)
1092 (function (lambda (f) (and
1095 (vc-backend-checkout f nil name
))))))
1098 ;; Miscellaneous other entry points
1101 (defun vc-print-log ()
1102 "List the change log of the current buffer in a window."
1105 (set-buffer (find-file-noselect (dired-get-filename))))
1106 (while vc-parent-buffer
1107 (pop-to-buffer vc-parent-buffer
))
1108 (if (and buffer-file-name
(vc-name buffer-file-name
))
1110 (vc-backend-print-log buffer-file-name
)
1111 (pop-to-buffer (get-buffer-create "*vc*"))
1112 (while (looking-at "=*\n")
1113 (delete-char (- (match-end 0) (match-beginning 0)))
1115 (goto-char (point-min))
1116 (if (looking-at "[\b\t\n\v\f\r ]+")
1117 (delete-char (- (match-end 0) (match-beginning 0))))
1118 (shrink-window-if-larger-than-buffer)
1120 (vc-registration-error buffer-file-name
)
1125 (defun vc-revert-buffer ()
1126 "Revert the current buffer's file back to the latest checked-in version.
1127 This asks for confirmation if the buffer contents are not identical
1131 (find-file-other-window (dired-get-filename)))
1132 (while vc-parent-buffer
1133 (pop-to-buffer vc-parent-buffer
))
1134 (let ((file buffer-file-name
)
1135 (obuf (current-buffer)) (changed (vc-diff nil t
)))
1136 (if (and changed
(or vc-suppress-confirm
1137 (not (yes-or-no-p "Discard changes? "))))
1140 (error "Revert cancelled"))
1144 (vc-backend-revert file
)
1145 (vc-resynch-window file t t
)
1150 (defun vc-cancel-version (norevert)
1151 "Get rid of most recently checked in version of this file.
1152 A prefix argument means do not revert the buffer afterwards."
1155 (find-file-other-window (dired-get-filename)))
1156 (while vc-parent-buffer
1157 (pop-to-buffer vc-parent-buffer
))
1158 (let* ((target (concat (vc-latest-version (buffer-file-name))))
1159 (yours (concat (vc-your-latest-version (buffer-file-name))))
1160 (prompt (if (string-equal yours target
)
1161 "Remove your version %s from master? "
1162 "Version %s was not your change. Remove it anyway? ")))
1163 (if (null (yes-or-no-p (format prompt target
)))
1165 (vc-backend-uncheck (buffer-file-name) target
)
1167 (not (yes-or-no-p "Revert buffer to most recent remaining version? ")))
1168 (vc-mode-line (buffer-file-name))
1169 (vc-checkout (buffer-file-name) nil
)))
1172 (defun vc-rename-file (old new
)
1173 "Rename file OLD to NEW, and rename its master file likewise."
1174 (interactive "fVC rename file: \nFRename to: ")
1175 (let ((oldbuf (get-file-buffer old
)))
1176 (if (and oldbuf
(buffer-modified-p oldbuf
))
1177 (error "Please save files before moving them"))
1178 (if (get-file-buffer new
)
1179 (error "Already editing new file name"))
1180 (if (file-exists-p new
)
1181 (error "New file already exists"))
1182 (let ((oldmaster (vc-name old
)))
1185 (if (vc-locking-user old
)
1186 (error "Please check in files before moving them"))
1187 (if (or (file-symlink-p oldmaster
)
1188 ;; This had FILE, I changed it to OLD. -- rms.
1189 (file-symlink-p (vc-backend-subdirectory-name old
)))
1190 (error "This is not a safe thing to do in the presence of symbolic links"))
1193 (let ((backend (vc-backend-deduce old
))
1194 (newdir (or (file-name-directory new
) ""))
1195 (newbase (file-name-nondirectory new
)))
1200 (if (eq backend
(cdr s
))
1201 (let* ((newmaster (format (car s
) newdir newbase
))
1202 (newmasterdir (file-name-directory newmaster
)))
1203 (if (or (not newmasterdir
)
1204 (file-directory-p newmasterdir
))
1205 (throw 'found newmaster
))))))
1206 vc-master-templates
)
1207 (error "New file lacks a version control directory"))))))
1208 (if (or (not oldmaster
) (file-exists-p old
))
1209 (rename-file old new
)))
1210 ; ?? Renaming a file might change its contents due to keyword expansion.
1211 ; We should really check out a new copy if the old copy was precisely equal
1212 ; to some checked in version. However, testing for this is tricky....
1216 (set-visited-file-name new
)
1217 (set-buffer-modified-p nil
))))
1218 ;; This had FILE, I changed it to OLD. -- rms.
1219 (vc-backend-dispatch old
1220 (vc-record-rename old new
)
1225 (defun vc-update-change-log (&rest args
)
1226 "Find change log file and add entries from recent RCS logs.
1227 The mark is left at the end of the text prepended to the change log.
1228 With prefix arg of C-u, only find log entries for the current buffer's file.
1229 With any numeric prefix arg, find log entries for all files currently visited.
1230 Otherwise, find log entries for all registered files in the default directory.
1231 From a program, any arguments are passed to the `rcs2log' script."
1233 (cond ((consp current-prefix-arg
) ;C-u
1234 (list buffer-file-name
))
1235 (current-prefix-arg ;Numeric argument.
1237 (buffers (buffer-list))
1240 (setq file
(buffer-file-name (car buffers
)))
1241 (and file
(vc-backend-deduce file
)
1242 (setq files
(cons file files
)))
1243 (setq buffers
(cdr buffers
)))
1246 (let ((RCS (concat default-directory
"RCS")))
1247 (and (file-directory-p RCS
)
1250 (if (string-match "\\(.*\\),v$" f
)
1251 (substring f
0 (match-end 1))
1253 (directory-files RCS nil
"...\\|^[^.]\\|^.[^.]")))))))
1254 (let ((odefault default-directory
))
1255 (find-file-other-window (find-change-log))
1256 (barf-if-buffer-read-only)
1259 (goto-char (point-min))
1261 (message "Computing change log entries...")
1262 (message "Computing change log entries... %s"
1264 (eq 0 (apply 'call-process
"rcs2log" nil t nil
1268 (if (file-name-absolute-p f
)
1270 (concat odefault f
)))))
1274 ;; Functions for querying the master and lock files.
1276 (defun vc-match-substring (bn)
1277 (buffer-substring (match-beginning bn
) (match-end bn
)))
1279 (defun vc-parse-buffer (patterns &optional file properties
)
1280 ;; Use PATTERNS to parse information out of the current buffer
1281 ;; by matching each regular expression in the list and returning \\1.
1282 ;; If a regexp has two tag brackets, assume the second is a date
1283 ;; field and we want the most recent entry matching the template.
1284 ;; If FILE and PROPERTIES are given, the latter must be a list of
1285 ;; properties of the same length as PATTERNS; each property is assigned
1286 ;; the corresponding value.
1287 (mapcar (function (lambda (p)
1288 (goto-char (point-min))
1289 (if (string-match "\\\\(.*\\\\(" p
)
1290 (let ((latest-date "") (latest-val))
1291 (while (re-search-forward p nil t
)
1292 (let ((date (vc-match-substring 2)))
1293 (if (string< latest-date date
)
1295 (setq latest-date date
)
1297 (vc-match-substring 1))))))
1301 (if (re-search-forward p nil t
)
1302 (setq value
(vc-match-substring 1)))
1304 (vc-file-setprop file
(car properties
) value
))
1306 (setq properties
(cdr properties
)))))
1310 (defun vc-master-info (file fields
&optional rfile properties
)
1311 ;; Search for information in a master file.
1312 (if (and file
(file-exists-p file
))
1315 (setq buf
(create-file-buffer file
))
1318 (insert-file-contents file nil
)
1319 (set-buffer-modified-p nil
)
1320 (auto-save-mode nil
)
1322 (vc-parse-buffer fields rfile properties
)
1323 (kill-buffer (current-buffer)))
1327 (function (lambda (p) (vc-file-setprop rfile p nil
)))
1332 (defun vc-log-info (command file patterns
&optional properties
)
1333 ;; Search for information in log program output
1334 (if (and file
(file-exists-p file
))
1337 (setq buf
(get-buffer-create "*vc*"))
1339 (apply 'vc-do-command
0 command file nil
)
1340 (set-buffer-modified-p nil
)
1342 (vc-parse-buffer patterns file properties
)
1343 (kill-buffer (current-buffer))
1348 (function (lambda (p) (vc-file-setprop file p nil
)))
1353 (defun vc-locking-user (file)
1354 "Return the name of the person currently holding a lock on FILE.
1355 Return nil if there is no such person."
1356 (setq file
(expand-file-name file
)) ;; ??? Work around bug in 19.0.4
1357 (if (or (not vc-keep-workfiles
)
1358 (eq vc-mistrust-permissions
't
)
1359 (and vc-mistrust-permissions
1360 (funcall vc-mistrust-permissions
(vc-backend-subdirectory-name file
))))
1361 (vc-true-locking-user file
)
1362 ;; This implementation assumes that any file which is under version
1363 ;; control and has -rw-r--r-- is locked by its owner. This is true
1364 ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--.
1365 ;; We have to be careful not to exclude files with execute bits on;
1366 ;; scripts can be under version control too. Also, we must ignore
1367 ;; the group-read and other-read bits, since paranoid users turn them off.
1368 ;; This hack wins because calls to the very expensive vc-fetch-properties
1369 ;; function only have to be made if (a) the file is locked by someone
1370 ;; other than the current user, or (b) some untoward manipulation
1371 ;; behind vc's back has changed the owner or the `group' or `other'
1373 (let ((attributes (file-attributes file
)))
1374 (cond ((string-match ".r-..-..-." (nth 8 attributes
))
1376 ((and (= (nth 2 attributes
) (user-uid))
1377 (string-match ".rw..-..-." (nth 8 attributes
)))
1380 (vc-true-locking-user file
))))))
1382 (defun vc-true-locking-user (file)
1383 ;; The slow but reliable version
1384 (vc-fetch-properties file
)
1385 (vc-file-getprop file
'vc-locking-user
))
1387 (defun vc-latest-version (file)
1388 ;; Return version level of the latest version of FILE
1389 (vc-fetch-properties file
)
1390 (vc-file-getprop file
'vc-latest-version
))
1392 (defun vc-your-latest-version (file)
1393 ;; Return version level of the latest version of FILE checked in by you
1394 (vc-fetch-properties file
)
1395 (vc-file-getprop file
'vc-your-latest-version
))
1397 ;; Collect back-end-dependent stuff here
1399 ;; Everything eventually funnels through these functions. To implement
1400 ;; support for a new version-control system, add another branch to the
1401 ;; vc-backend-dispatch macro and fill it in in each call. The variable
1402 ;; vc-master-templates in vc-hooks.el will also have to change.
1404 (defmacro vc-backend-dispatch
(f s r
)
1405 "Execute FORM1 or FORM2 depending on whether we're using SCCS or RCS."
1406 (list 'let
(list (list 'type
(list 'vc-backend-deduce f
)))
1408 (list (list 'eq
'type
(quote 'SCCS
)) s
) ;; SCCS
1409 (list (list 'eq
'type
(quote 'RCS
)) r
) ;; RCS
1412 (defun vc-lock-file (file)
1413 ;; Generate lock file name corresponding to FILE
1414 (let ((master (vc-name file
)))
1417 (string-match "\\(.*/\\)s\\.\\(.*\\)" master
)
1419 (substring master
(match-beginning 1) (match-end 1))
1421 (substring master
(match-beginning 2) (match-end 2))))))
1424 (defun vc-fetch-properties (file)
1425 ;; Re-fetch all properties associated with the given file.
1426 ;; Currently these properties are:
1428 ;; vc-locked-version
1429 ;; vc-latest-version
1430 ;; vc-your-latest-version
1431 (vc-backend-dispatch
1435 (vc-master-info (vc-lock-file file
)
1437 "^[^ ]+ [^ ]+ \\([^ ]+\\)"
1440 '(vc-locking-user vc-locked-version
))
1441 (vc-master-info (vc-name file
)
1443 "^\001d D \\([^ ]+\\)"
1444 (concat "^\001d D \\([^ ]+\\) .* "
1445 (regexp-quote (user-login-name)) " ")
1448 '(vc-latest-version vc-your-latest-version
))
1451 (vc-log-info "rlog" file
1453 "^locks: strict\n\t\\([^:]+\\)"
1454 "^locks: strict\n\t[^:]+: \\(.+\\)"
1455 "^revision[\t ]+\\([0-9.]+\\).*\ndate: \\([ /0-9:]+\\);"
1457 "^revision[\t ]+\\([0-9.]+\\)\n.*author: "
1458 (regexp-quote (user-login-name))
1460 '(vc-locking-user vc-locked-version
1461 vc-latest-version vc-your-latest-version
))
1464 (defun vc-backend-subdirectory-name (&optional file
)
1465 ;; Where the master and lock files for the current directory are kept
1468 (and file
(vc-backend-deduce file
))
1470 (setq vc-default-back-end
(if (vc-find-binary "rcs") 'RCS
'SCCS
)))))
1472 (defun vc-backend-admin (file &optional rev comment
)
1473 ;; Register a file into the version-control system
1474 ;; Automatically retrieves a read-only version of the file with
1475 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
1476 ;; it deletes the workfile.
1477 (vc-file-clearprops file
)
1478 (or vc-default-back-end
1479 (setq vc-default-back-end
(if (vc-find-binary "rcs") 'RCS
'SCCS
)))
1480 (message "Registering %s..." file
)
1483 ((file-exists-p (vc-backend-subdirectory-name)) vc-default-back-end
)
1484 ((file-exists-p "RCS") 'RCS
)
1485 ((file-exists-p "SCCS") 'SCCS
)
1486 (t vc-default-back-end
))))
1487 (cond ((eq backend
'SCCS
)
1488 (vc-do-command 0 "admin" file
;; SCCS
1489 (and rev
(concat "-r" rev
))
1492 (and comment
(concat "-y" comment
))
1494 (car (rassq 'SCCS vc-master-templates
))
1495 (or (file-name-directory file
) "")
1496 (file-name-nondirectory file
)))
1498 (if vc-keep-workfiles
1499 (vc-do-command 0 "get" file
)))
1501 (vc-do-command 0 "ci" file
;; RCS
1502 (concat (if vc-keep-workfiles
"-u" "-r") rev
)
1503 (and comment
(concat "-t-" comment
))
1506 (message "Registering %s...done" file
)
1509 (defun vc-backend-checkout (file &optional writable rev workfile
)
1510 ;; Retrieve a copy of a saved version into a workfile
1511 (let ((filename (or workfile file
)))
1512 (message "Checking out %s..." filename
)
1513 (vc-backend-dispatch file
1514 (vc-do-command 0 "get" file
;; SCCS
1516 (if workfile
(concat "-G" workfile
))
1517 (and rev
(concat "-r" (vc-lookup-triple file rev
))))
1519 ;; RCS doesn't let us check out into arbitrary file names directly.
1520 ;; Use `co -p' and make stdout point to the correct file.
1521 (let ((vc-modes (logior (file-modes (vc-name file
))
1522 (if writable
128 0)))
1527 0 "/bin/sh" file
"-c"
1528 (format "umask %o; exec >\"$1\" || exit; shift; umask %o; exec co \"$@\""
1529 (logand 511 (lognot vc-modes
))
1530 (logand 511 (lognot (default-file-modes))))
1531 "" ; dummy argument for shell's $0
1536 (and failed
(file-exists-p filename
) (delete-file filename
))))
1537 (vc-do-command 0 "co" file
1539 (and rev
(concat "-r" rev
))))
1542 (vc-file-setprop file
'vc-checkout-time
(nth 5 (file-attributes file
))))
1543 (message "Checking out %s...done" filename
))
1546 (defun vc-backend-logentry-check (file)
1547 (vc-backend-dispatch file
1548 (if (>= (buffer-size) 512) ;; SCCS
1552 "Log must be less than 512 characters; point is now at pos 512")))
1556 (defun vc-backend-checkin (file &optional rev comment
)
1557 ;; Register changes to FILE as level REV with explanatory COMMENT.
1558 ;; Automatically retrieves a read-only version of the file with
1559 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
1560 ;; it deletes the workfile.
1561 (message "Checking in %s..." file
)
1563 ;; Change buffers to get local value of vc-checkin-switches.
1564 (set-buffer (or (get-file-buffer file
) (current-buffer)))
1565 (vc-backend-dispatch file
1567 (apply 'vc-do-command
0 "delta" file
1568 (if rev
(concat "-r" rev
))
1569 (concat "-y" comment
)
1570 vc-checkin-switches
)
1571 (if vc-keep-workfiles
1572 (vc-do-command 0 "get" file
))
1574 (apply 'vc-do-command
0 "ci" file
1575 (concat (if vc-keep-workfiles
"-u" "-r") rev
)
1576 (concat "-m" comment
)
1577 vc-checkin-switches
)
1579 (vc-file-setprop file
'vc-locking-user nil
)
1580 (message "Checking in %s...done" file
)
1583 (defun vc-backend-revert (file)
1584 ;; Revert file to latest checked-in version.
1585 (message "Reverting %s..." file
)
1586 (vc-backend-dispatch
1589 (vc-do-command 0 "unget" file nil
)
1590 (vc-do-command 0 "get" file nil
))
1591 (vc-do-command 0 "co" file
"-f" "-u")) ;; RCS. This deletes the work file.
1592 (vc-file-setprop file
'vc-locking-user nil
)
1593 (message "Reverting %s...done" file
)
1596 (defun vc-backend-steal (file &optional rev
)
1597 ;; Steal the lock on the current workfile. Needs RCS 5.6.2 or later for -M.
1598 (message "Stealing lock on %s..." file
)
1599 (vc-backend-dispatch file
1601 (vc-do-command 0 "unget" file
"-n" (if rev
(concat "-r" rev
)))
1602 (vc-do-command 0 "get" file
"-g" (if rev
(concat "-r" rev
)))
1604 (vc-do-command 0 "rcs" file
"-M" (concat "-u" rev
) (concat "-l" rev
)))
1605 (vc-file-setprop file
'vc-locking-user
(user-login-name))
1606 (message "Stealing lock on %s...done" file
)
1609 (defun vc-backend-uncheck (file target
)
1610 ;; Undo the latest checkin. Note: this code will have to get a lot
1611 ;; smarter when we support multiple branches.
1612 (message "Removing last change from %s..." file
)
1613 (vc-backend-dispatch file
1614 (vc-do-command 0 "rmdel" file
(concat "-r" target
))
1615 (vc-do-command 0 "rcs" file
(concat "-o" target
))
1617 (message "Removing last change from %s...done" file
)
1620 (defun vc-backend-print-log (file)
1621 ;; Print change log associated with FILE to buffer *vc*.
1623 (vc-backend-dispatch file
"prs" "rlog")
1627 (defun vc-backend-assign-name (file name
)
1628 ;; Assign to a FILE's latest version a given NAME.
1629 (vc-backend-dispatch file
1630 (vc-add-triple name file
(vc-latest-version file
)) ;; SCCS
1631 (vc-do-command 0 "rcs" file
(concat "-n" name
":")) ;; RCS
1635 (defun vc-backend-diff (file &optional oldvers newvers cmp
)
1636 ;; Get a difference report between two versions of FILE.
1637 ;; Get only a brief comparison report if CMP, a difference report otherwise.
1638 (if (eq (vc-backend-deduce file
) 'SCCS
)
1639 (setq oldvers
(vc-lookup-triple file oldvers
))
1640 (setq newvers
(vc-lookup-triple file newvers
)))
1641 (let* ((command (or (vc-backend-dispatch file
"vcdiff" "rcsdiff")
1642 (vc-registration-error file
)))
1643 (options (append (list (and cmp
"--brief")
1645 (and oldvers
(concat "-r" oldvers
))
1646 (and newvers
(concat "-r" newvers
)))
1648 (if (listp diff-switches
)
1650 (list diff-switches
)))))
1651 (status (apply 'vc-do-command
2 command file options
)))
1652 ;; Some RCS versions don't understand "--brief"; work around this.
1654 (apply 'vc-do-command
1 command file
(if cmp options
(cdr options
)))
1657 (defun vc-check-headers ()
1658 "Check if the current file has any headers in it."
1661 (goto-char (point-min))
1662 (vc-backend-dispatch buffer-file-name
1663 (re-search-forward "%[MIRLBSDHTEGUYFPQCZWA]%" nil t
) ;; SCCS
1664 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
) ;; RCS
1668 ;; Back-end-dependent stuff ends here.
1670 ;; Set up key bindings for use while editing log messages
1672 (defun vc-log-mode ()
1673 "Minor mode for driving version-control tools.
1674 These bindings are added to the global keymap when you enter this mode:
1675 \\[vc-next-action] perform next logical version-control operation on current file
1676 \\[vc-register] register current file
1677 \\[vc-toggle-read-only] like next-action, but won't register files
1678 \\[vc-insert-headers] insert version-control headers in current file
1679 \\[vc-print-log] display change history of current file
1680 \\[vc-revert-buffer] revert buffer to latest version
1681 \\[vc-cancel-version] undo latest checkin
1682 \\[vc-diff] show diffs between file versions
1683 \\[vc-version-other-window] visit old version in another window
1684 \\[vc-directory] show all files locked by any user in or below .
1685 \\[vc-update-change-log] add change log entry from recent checkins
1687 While you are entering a change log message for a version, the following
1688 additional bindings will be in effect.
1690 \\[vc-finish-logentry] proceed with check in, ending log message entry
1692 Whenever you do a checkin, your log comment is added to a ring of
1693 saved comments. These can be recalled as follows:
1695 \\[vc-next-comment] replace region with next message in comment ring
1696 \\[vc-previous-comment] replace region with previous message in comment ring
1697 \\[vc-comment-search-reverse] search backward for regexp in the comment ring
1698 \\[vc-comment-search-forward] search backward for regexp in the comment ring
1700 Entry to the change-log submode calls the value of text-mode-hook, then
1701 the value of vc-log-mode-hook.
1703 Global user options:
1704 vc-initial-comment If non-nil, require user to enter a change
1705 comment upon first checkin of the file.
1707 vc-keep-workfiles Non-nil value prevents workfiles from being
1708 deleted when changes are checked in
1710 vc-suppress-confirm Suppresses some confirmation prompts,
1711 notably for reversions.
1713 vc-header-alist Which keywords to insert when adding headers
1714 with \\[vc-insert-headers]. Defaults to
1715 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under RCS.
1717 vc-static-header-alist By default, version headers inserted in C files
1718 get stuffed in a static string area so that
1719 ident(RCS) or what(SCCS) can see them in the
1720 compiled object code. You can override this
1721 by setting this variable to nil, or change
1722 the header template by changing it.
1724 vc-command-messages if non-nil, display run messages from the
1725 actual version-control utilities (this is
1726 intended primarily for people hacking vc
1730 (set-syntax-table text-mode-syntax-table
)
1731 (use-local-map vc-log-entry-mode
)
1732 (setq local-abbrev-table text-mode-abbrev-table
)
1733 (setq major-mode
'vc-log-mode
)
1734 (setq mode-name
"VC-Log")
1735 (make-local-variable 'vc-log-file
)
1736 (make-local-variable 'vc-log-version
)
1737 (make-local-variable 'vc-comment-ring-index
)
1738 (set-buffer-modified-p nil
)
1739 (setq buffer-file-name nil
)
1740 (run-hooks 'text-mode-hook
'vc-log-mode-hook
)
1743 ;; Initialization code, to be done just once at load-time
1744 (if vc-log-entry-mode
1746 (setq vc-log-entry-mode
(make-sparse-keymap))
1747 (define-key vc-log-entry-mode
"\M-n" 'vc-next-comment
)
1748 (define-key vc-log-entry-mode
"\M-p" 'vc-previous-comment
)
1749 (define-key vc-log-entry-mode
"\M-r" 'vc-comment-search-reverse
)
1750 (define-key vc-log-entry-mode
"\M-s" 'vc-comment-search-forward
)
1751 (define-key vc-log-entry-mode
"\C-c\C-c" 'vc-finish-logentry
)
1754 ;;; These things should probably be generally available
1756 (defun vc-file-tree-walk (func &rest args
)
1757 "Walk recursively through default directory.
1758 Invoke FUNC f ARGS on each non-directory file f underneath it."
1759 (vc-file-tree-walk-internal default-directory func args
)
1760 (message "Traversing directory %s...done" default-directory
))
1762 (defun vc-file-tree-walk-internal (file func args
)
1763 (if (not (file-directory-p file
))
1764 (apply func file args
)
1765 (message "Traversing directory %s..." file
)
1766 (let ((dir (file-name-as-directory file
)))
1770 (string-equal f
".")
1771 (string-equal f
"..")
1772 (let ((dirf (concat dir f
)))
1774 (file-symlink-p dirf
) ;; Avoid possible loops
1775 (vc-file-tree-walk-internal dirf func args
))))))
1776 (directory-files dir
)))))
1780 ;;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
1782 ;;; These may be useful to anyone who has to debug or extend the package.
1784 ;;; A fundamental problem in VC is that there are time windows between
1785 ;;; vc-next-action's computations of the file's version-control state and
1786 ;;; the actions that change it. This is a window open to lossage in a
1787 ;;; multi-user environment; someone else could nip in and change the state
1788 ;;; of the master during it.
1790 ;;; The performance problem is that rlog/prs calls are very expensive; we want
1791 ;;; to avoid them as much as possible.
1795 ;;; The performance problem, it turns out, simplifies in practice to the
1796 ;;; problem of making vc-locking-user fast. The two other functions that call
1797 ;;; prs/rlog will not be so commonly used that the slowdown is a problem; one
1798 ;;; makes snapshots, the other deletes the calling user's last change in the
1801 ;;; The race condition implies that we have to either (a) lock the master
1802 ;;; during the entire execution of vc-next-action, or (b) detect and
1803 ;;; recover from errors resulting from dispatch on an out-of-date state.
1805 ;;; Alternative (a) appears to be unfeasible. The problem is that we can't
1806 ;;; guarantee that the lock will ever be removed. Suppose a user starts a
1807 ;;; checkin, the change message buffer pops up, and the user, having wandered
1808 ;;; off to do something else, simply forgets about it?
1810 ;;; Alternative (b), on the other hand, works well with a cheap way to speed up
1811 ;;; vc-locking-user. Usually, if a file is registered, we can read its locked/
1812 ;;; unlocked state and its current owner from its permissions.
1814 ;;; This shortcut will fail if someone has manually changed the workfile's
1815 ;;; permissions; also if developers are munging the workfile in several
1816 ;;; directories, with symlinks to a master (in this latter case, the
1817 ;;; permissions shortcut will fail to detect a lock asserted from another
1820 ;;; Note that these cases correspond exactly to the errors which could happen
1821 ;;; because of a competing checkin/checkout race in between two instances of
1824 ;;; For VC's purposes, a workfile/master pair may have the following states:
1826 ;;; A. Unregistered. There is a workfile, there is no master.
1828 ;;; B. Registered and not locked by anyone.
1830 ;;; C. Locked by calling user and unchanged.
1832 ;;; D. Locked by the calling user and changed.
1834 ;;; E. Locked by someone other than the calling user.
1836 ;;; This makes for 25 states and 20 error conditions. Here's the matrix:
1838 ;;; VC's idea of state
1840 ;;; V Actual state RCS action SCCS action Effect
1842 ;;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
1843 ;;; B 5 . 6 7 8 co -l get -e checkout
1844 ;;; C 9 10 . 11 12 co -u unget; get revert
1845 ;;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
1846 ;;; E 17 18 19 20 . rcs -u -M ; rcs -l unget -n ; get -g steal lock
1848 ;;; All commands take the master file name as a last argument (not shown).
1850 ;;; In the discussion below, a "self-race" is a pathological situation in
1851 ;;; which VC operations are being attempted simultaneously by two or more
1852 ;;; Emacsen running under the same username.
1854 ;;; The vc-next-action code has the following windows:
1857 ;;; Between the check for existence of a master file and the call to
1858 ;;; admin/checkin in vc-buffer-admin (apparent state A). This window may
1859 ;;; never close if the initial-comment feature is on.
1862 ;;; Between the call to vc-workfile-unchanged-p in and the immediately
1863 ;;; following revert (apparent state C).
1866 ;;; Between the call to vc-workfile-unchanged-p in and the following
1867 ;;; checkin (apparent state D). This window may never close.
1870 ;;; Between the unlock and the immediately following checkout during a
1871 ;;; revert operation (apparent state C). Included in window Q.
1874 ;;; Between vc-locking-user and the following checkout (apparent state B).
1877 ;;; Between vc-locking-user and the following revert (apparent state C).
1878 ;;; Includes windows Q and S.
1881 ;;; Between vc-locking-user and the following checkin (apparent state
1882 ;;; D). This window may never be closed if the user fails to complete the
1883 ;;; checkin message. Includes window R.
1886 ;;; Between vc-locking-user and the following steal-lock (apparent
1887 ;;; state E). This window may never close if the user fails to complete
1888 ;;; the steal-lock message. Includes window X.
1891 ;;; Between the unlock and the immediately following re-lock during a
1892 ;;; steal-lock operation (apparent state E). This window may never cloce
1893 ;;; if the user fails to complete the steal-lock message.
1897 ;;; Apparent state A ---
1899 ;;; 1. File looked unregistered but is actually registered and not locked.
1901 ;;; Potential cause: someone else's admin during window P, with
1902 ;;; caller's admin happening before their checkout.
1904 ;;; RCS: ci will fail with a "no lock set by <user>" message.
1905 ;;; SCCS: admin will fail with error (ad19).
1907 ;;; We can let these errors be passed up to the user.
1909 ;;; 2. File looked unregistered but is actually locked by caller, unchanged.
1911 ;;; Potential cause: self-race during window P.
1913 ;;; RCS: will revert the file to the last saved version and unlock it.
1914 ;;; SCCS: will fail with error (ad19).
1916 ;;; Either of these consequences is acceptable.
1918 ;;; 3. File looked unregistered but is actually locked by caller, changed.
1920 ;;; Potential cause: self-race during window P.
1922 ;;; RCS: will register the caller's workfile as a delta with a
1923 ;;; null change comment (the -t- switch will be ignored).
1924 ;;; SCCS: will fail with error (ad19).
1926 ;;; 4. File looked unregistered but is locked by someone else.
1928 ;;; Potential cause: someone else's admin during window P, with
1929 ;;; caller's admin happening *after* their checkout.
1931 ;;; RCS: will fail with a "no lock set by <user>" message.
1932 ;;; SCCS: will fail with error (ad19).
1934 ;;; We can let these errors be passed up to the user.
1936 ;;; Apparent state B ---
1938 ;;; 5. File looked registered and not locked, but is actually unregistered.
1940 ;;; Potential cause: master file got nuked during window P.
1942 ;;; RCS: will fail with "RCS/<file>: No such file or directory"
1943 ;;; SCCS: will fail with error ut4.
1945 ;;; We can let these errors be passed up to the user.
1947 ;;; 6. File looked registered and not locked, but is actually locked by the
1948 ;;; calling user and unchanged.
1950 ;;; Potential cause: self-race during window T.
1952 ;;; RCS: in the same directory as the previous workfile, co -l will fail
1953 ;;; with "co error: writable foo exists; checkout aborted". In any other
1954 ;;; directory, checkout will succeed.
1955 ;;; SCCS: will fail with ge17.
1957 ;;; Either of these consequences is acceptable.
1959 ;;; 7. File looked registered and not locked, but is actually locked by the
1960 ;;; calling user and changed.
1964 ;;; 8. File looked registered and not locked, but is actually locked by another
1967 ;;; Potential cause: someone else checks it out during window T.
1969 ;;; RCS: co error: revision 1.3 already locked by <user>
1970 ;;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
1972 ;;; We can let these errors be passed up to the user.
1974 ;;; Apparent state C ---
1976 ;;; 9. File looks locked by calling user and unchanged, but is unregistered.
1980 ;;; 10. File looks locked by calling user and unchanged, but is actually not
1983 ;;; Potential cause: a self-race in window U, or by the revert's
1984 ;;; landing during window X of some other user's steal-lock or window S
1985 ;;; of another user's revert.
1987 ;;; RCS: succeeds, refreshing the file from the identical version in
1989 ;;; SCCS: fails with error ut4 (p file nonexistent).
1991 ;;; Either of these consequences is acceptable.
1993 ;;; 11. File is locked by calling user. It looks unchanged, but is actually
1996 ;;; Potential cause: the file would have to be touched by a self-race
1997 ;;; during window Q.
1999 ;;; The revert will succeed, removing whatever changes came with
2000 ;;; the touch. It is theoretically possible that work could be lost.
2002 ;;; 12. File looks like it's locked by the calling user and unchanged, but
2003 ;;; it's actually locked by someone else.
2005 ;;; Potential cause: a steal-lock in window V.
2007 ;;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
2008 ;;; SCCS: fails with error un2
2010 ;;; We can pass these errors up to the user.
2012 ;;; Apparent state D ---
2014 ;;; 13. File looks like it's locked by the calling user and changed, but it's
2015 ;;; actually unregistered.
2017 ;;; Potential cause: master file got nuked during window P.
2019 ;;; RCS: Checks in the user's version as an initial delta.
2020 ;;; SCCS: will fail with error ut4.
2022 ;;; This case is kind of nasty. It means VC may fail to detect the
2023 ;;; loss of previous version information.
2025 ;;; 14. File looks like it's locked by the calling user and changed, but it's
2026 ;;; actually unlocked.
2028 ;;; Potential cause: self-race in window V, or the checkin happening
2029 ;;; during the window X of someone else's steal-lock or window S of
2030 ;;; someone else's revert.
2032 ;;; RCS: ci will fail with "no lock set by <user>".
2033 ;;; SCCS: delta will fail with error ut4.
2035 ;;; 15. File looks like it's locked by the calling user and changed, but it's
2036 ;;; actually locked by the calling user and unchanged.
2038 ;;; Potential cause: another self-race --- a whole checkin/checkout
2039 ;;; sequence by the calling user would have to land in window R.
2041 ;;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
2042 ;;; RCS: reverts to the file state as of the second user's checkin, leaving
2043 ;;; the file unlocked.
2045 ;;; It is theoretically possible that work could be lost under RCS.
2047 ;;; 16. File looks like it's locked by the calling user and changed, but it's
2048 ;;; actually locked by a different user.
2050 ;;; RCS: ci error: no lock set by <user>
2051 ;;; SCCS: unget will fail with error un2
2053 ;;; We can pass these errors up to the user.
2055 ;;; Apparent state E ---
2057 ;;; 17. File looks like it's locked by some other user, but it's actually
2062 ;;; 18. File looks like it's locked by some other user, but it's actually
2065 ;;; Potential cause: someone released a lock during window W.
2067 ;;; RCS: The calling user will get the lock on the file.
2068 ;;; SCCS: unget -n will fail with cm4.
2070 ;;; Either of these consequences will be OK.
2072 ;;; 19. File looks like it's locked by some other user, but it's actually
2073 ;;; locked by the calling user and unchanged.
2075 ;;; Potential cause: the other user relinquishing a lock followed by
2076 ;;; a self-race, both in window W.
2078 ;;; Under both RCS and SCCS, both unlock and lock will succeed, making
2079 ;;; the sequence a no-op.
2081 ;;; 20. File looks like it's locked by some other user, but it's actually
2082 ;;; locked by the calling user and changed.
2088 ;;; In order of decreasing severity:
2090 ;;; Cases 11 and 15 under RCS are the only one that potentially lose work.
2091 ;;; They would require a self-race for this to happen.
2093 ;;; Case 13 in RCS loses information about previous deltas, retaining
2094 ;;; only the information in the current workfile. This can only happen
2095 ;;; if the master file gets nuked in window P.
2097 ;;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
2098 ;;; no change comment in the master. This would require a self-race in
2099 ;;; window P or R respectively.
2101 ;;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
2103 ;;; Unfortunately, it appears to me that no recovery is possible in these
2104 ;;; cases. They don't yield error messages, so there's no way to tell that
2105 ;;; a race condition has occurred.
2107 ;;; All other cases don't change either the workfile or the master, and
2108 ;;; trigger command errors which the user will see.
2110 ;;; Thus, there is no explicit recovery code.