1 ;;; vc.el --- drive a version-control system from within Emacs
3 ;; Copyright (C) 1992, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
6 ;; Maintainer: Andre Spiegel <spiegel@inf.fu-berlin.de>
8 ;; $Id: vc.el,v 1.242 1999/01/02 21:54:32 rms Exp spiegel $
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; This mode is fully documented in the Emacs user's manual.
31 ;; This was designed and implemented by Eric Raymond <esr@snark.thyrsus.com>.
32 ;; Paul Eggert <eggert@twinsun.com>, Sebastian Kremer <sk@thp.uni-koeln.de>,
33 ;; and Richard Stallman contributed valuable criticism, support, and testing.
34 ;; CVS support was added by Per Cederqvist <ceder@lysator.liu.se>
35 ;; in Jan-Feb 1994. Further enhancements came from ttn@netcom.com and
36 ;; Andre Spiegel <spiegel@inf.fu-berlin.de>.
38 ;; Supported version-control systems presently include SCCS, RCS, and CVS.
40 ;; Some features will not work with old RCS versions. Where
41 ;; appropriate, VC finds out which version you have, and allows or
42 ;; disallows those features (stealing locks, for example, works only
43 ;; from 5.6.2 onwards).
44 ;; Even initial checkins will fail if your RCS version is so old that ci
45 ;; doesn't understand -t-; this has been known to happen to people running
48 ;; You can support the RCS -x option by adding pairs to the
49 ;; vc-master-templates list.
51 ;; Proper function of the SCCS diff commands requires the shellscript vcdiff
52 ;; to be installed somewhere on Emacs's path for executables.
54 ;; If your site uses the ChangeLog convention supported by Emacs, the
55 ;; function vc-comment-to-change-log should prove a useful checkin hook.
57 ;; This code depends on call-process passing back the subprocess exit
58 ;; status. Thus, you need Emacs 18.58 or later to run it. For the
59 ;; vc-directory command to work properly as documented, you need 19.
60 ;; You also need Emacs 19's ring.el.
62 ;; The vc code maintains some internal state in order to reduce expensive
63 ;; version-control operations to a minimum. Some names are only computed
64 ;; once. If you perform version control operations with RCS/SCCS/CVS while
65 ;; vc's back is turned, or move/rename master files while vc is running,
66 ;; vc may get seriously confused. Don't do these things!
68 ;; Developer's notes on some concurrency issues are included at the end of
75 (eval-when-compile (require 'dired)) ; for dired-map-over-marks macro
77 (if (not (assoc 'vc-parent-buffer minor-mode-alist))
78 (setq minor-mode-alist
79 (cons '(vc-parent-buffer vc-parent-buffer-name)
82 ;; To implement support for a new version-control system, add another
83 ;; branch to the vc-backend-dispatch macro and fill it in in each
84 ;; call. The variable vc-master-templates in vc-hooks.el will also
87 (defmacro vc-backend-dispatch (f s r c)
88 "Execute FORM1, FORM2 or FORM3 for SCCS, RCS or CVS respectively.
89 If FORM3 is `RCS', use FORM2 for CVS as well as RCS.
90 \(CVS shares some code with RCS)."
91 (list 'let (list (list 'type (list 'vc-backend f)))
93 (list (list 'eq 'type (quote 'SCCS)) s) ;; SCCS
94 (list (list 'eq 'type (quote 'RCS)) r) ;; RCS
95 (list (list 'eq 'type (quote 'CVS)) ;; CVS
99 ;; General customization
102 "Version-control system in Emacs."
105 (defcustom vc-suppress-confirm nil
106 "*If non-nil, treat user as expert; suppress yes-no prompts on some things."
110 (defcustom vc-initial-comment nil
111 "*If non-nil, prompt for initial comment when a file is registered."
115 (defcustom vc-default-init-version "1.1"
116 "*A string used as the default version number when a new file is registered.
117 This can be overriden by giving a prefix argument to \\[vc-register]."
122 (defcustom vc-command-messages nil
123 "*If non-nil, display run messages from back-end commands."
127 (defcustom vc-checkin-switches nil
128 "*A string or list of strings specifying extra switches for checkin.
129 These are passed to the checkin program by \\[vc-checkin]."
130 :type '(choice (const :tag "None" nil)
131 (string :tag "Argument String")
132 (repeat :tag "Argument List"
137 (defcustom vc-checkout-switches nil
138 "*A string or list of strings specifying extra switches for checkout.
139 These are passed to the checkout program by \\[vc-checkout]."
140 :type '(choice (const :tag "None" nil)
141 (string :tag "Argument String")
142 (repeat :tag "Argument List"
147 (defcustom vc-register-switches nil
148 "*A string or list of strings; extra switches for registering a file.
149 These are passed to the checkin program by \\[vc-register]."
150 :type '(choice (const :tag "None" nil)
151 (string :tag "Argument String")
152 (repeat :tag "Argument List"
157 (defcustom vc-dired-recurse t
158 "*If non-nil, show directory trees recursively in VC Dired."
163 (defcustom vc-dired-terse-display t
164 "*If non-nil, show only locked files in VC Dired."
169 (defcustom vc-directory-exclusion-list '("SCCS" "RCS" "CVS")
170 "*List of directory names to be ignored while recursively walking file trees."
171 :type '(repeat string)
174 (defconst vc-maximum-comment-ring-size 32
175 "Maximum number of saved comments in the comment ring.")
177 ;;; This is duplicated in diff.el.
178 (defvar diff-switches "-c"
179 "*A string or list of strings specifying switches to be be passed to diff.")
181 (defcustom vc-annotate-color-map
182 '(( 26.3672 . "#FF0000")
183 ( 52.7344 . "#FF3800")
184 ( 79.1016 . "#FF7000")
185 (105.4688 . "#FFA800")
186 (131.8359 . "#FFE000")
187 (158.2031 . "#E7FF00")
188 (184.5703 . "#AFFF00")
189 (210.9375 . "#77FF00")
190 (237.3047 . "#3FFF00")
191 (263.6719 . "#07FF00")
192 (290.0391 . "#00FF31")
193 (316.4063 . "#00FF69")
194 (342.7734 . "#00FFA1")
195 (369.1406 . "#00FFD9")
196 (395.5078 . "#00EEFF")
197 (421.8750 . "#00B6FF")
198 (448.2422 . "#007EFF"))
199 "*Association list of age versus color, for \\[vc-annotate].
200 Ages are given in units of 2**-16 seconds.
201 Default is eighteen steps using a twenty day increment."
205 (defcustom vc-annotate-very-old-color "#0046FF"
206 "*Color for lines older than CAR of last cons in `vc-annotate-color-map'."
210 (defcustom vc-annotate-background "black"
211 "*Background color for \\[vc-annotate].
212 Default color is used if nil."
216 (defcustom vc-annotate-menu-elements '(2 0.5 0.1 0.01)
217 "*Menu elements for the mode-specific menu of VC-Annotate mode.
218 List of factors, used to expand/compress the time scale. See `vc-annotate'."
223 (defcustom vc-checkin-hook nil
224 "*Normal hook (list of functions) run after a checkin is done.
227 :options '(vc-comment-to-change-log)
231 (defcustom vc-before-checkin-hook nil
232 "*Normal hook (list of functions) run before a file gets checked in.
238 (defcustom vc-annotate-mode-hook nil
239 "*Hooks to run when VC-Annotate mode is turned on."
243 ;; Header-insertion hair
245 (defcustom vc-header-alist
246 '((SCCS "\%W\%") (RCS "\$Id\$") (CVS "\$Id\$"))
247 "*Header keywords to be inserted by `vc-insert-headers'.
248 Must be a list of two-element lists, the first element of each must
249 be `RCS', `CVS', or `SCCS'. The second element is the string to
250 be inserted for this particular backend."
251 :type '(repeat (list :format "%v"
252 (choice :tag "System"
256 (string :tag "Header")))
259 (defcustom vc-static-header-alist
261 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
262 "*Associate static header string templates with file types. A \%s in the
263 template is replaced with the first string associated with the file's
264 version-control type in `vc-header-alist'."
265 :type '(repeat (cons :format "%v"
266 (regexp :tag "File Type")
267 (string :tag "Header String")))
270 (defcustom vc-comment-alist
271 '((nroff-mode ".\\\"" ""))
272 "*Special comment delimiters to be used in generating vc headers only.
273 Add an entry in this list if you need to override the normal comment-start
274 and comment-end variables. This will only be necessary if the mode language
275 is sensitive to blank lines."
276 :type '(repeat (list :format "%v"
278 (string :tag "Comment Start")
279 (string :tag "Comment End")))
282 ;; Default is to be extra careful for super-user.
283 (defcustom vc-checkout-carefully (= (user-uid) 0)
284 "*Non-nil means be extra-careful in checkout.
285 Verify that the file really is not locked
286 and that its contents match what the master file says."
290 (defcustom vc-rcs-release nil
291 "*The release number of your RCS installation, as a string.
292 If nil, VC itself computes this value when it is first needed."
293 :type '(choice (const :tag "Auto" nil)
295 (const :tag "Unknown" unknown))
298 (defcustom vc-sccs-release nil
299 "*The release number of your SCCS installation, as a string.
300 If nil, VC itself computes this value when it is first needed."
301 :type '(choice (const :tag "Auto" nil)
303 (const :tag "Unknown" unknown))
306 (defcustom vc-cvs-release nil
307 "*The release number of your CVS installation, as a string.
308 If nil, VC itself computes this value when it is first needed."
309 :type '(choice (const :tag "Auto" nil)
311 (const :tag "Unknown" unknown))
314 ;; Variables the user doesn't need to know about.
315 (defvar vc-log-entry-mode nil)
316 (defvar vc-log-operation nil)
317 (defvar vc-log-after-operation-hook nil)
318 (defvar vc-checkout-writable-buffer-hook 'vc-checkout-writable-buffer)
319 ;; In a log entry buffer, this is a local variable
320 ;; that points to the buffer for which it was made
321 ;; (either a file, or a VC dired buffer).
322 (defvar vc-parent-buffer nil)
323 (defvar vc-parent-buffer-name nil)
326 (defvar vc-log-version)
328 (defconst vc-name-assoc-file "VC-names")
330 (defvar vc-dired-mode nil)
331 (make-variable-buffer-local 'vc-dired-mode)
333 (defvar vc-comment-ring (make-ring vc-maximum-comment-ring-size))
334 (defvar vc-comment-ring-index nil)
335 (defvar vc-last-comment-match nil)
337 ;;; Find and compare backend releases
339 (defun vc-backend-release (backend)
340 ;; Returns which backend release is installed on this system.
344 (and (zerop (vc-do-command nil nil "rcs" nil nil "-V"))
346 (set-buffer (get-buffer "*vc*"))
348 (car (vc-parse-buffer
349 '(("^RCS version \\([0-9.]+ *.*\\)" 1)))))))
350 (setq vc-rcs-release 'unknown)))
353 (and (zerop (vc-do-command nil 1 "cvs" nil nil "-v"))
355 (set-buffer (get-buffer "*vc*"))
357 (car (vc-parse-buffer
358 '(("^Concurrent Versions System (CVS) \\([0-9.]+\\)"
360 (setq vc-cvs-release 'unknown)))
364 (defun vc-release-greater-or-equal (r1 r2)
365 ;; Compare release numbers, represented as strings.
366 ;; Release components are assumed cardinal numbers, not decimal
367 ;; fractions (5.10 is a higher release than 5.9). Omitted fields
368 ;; are considered lower (5.6.7 is earlier than 5.6.7.1).
369 ;; Comparison runs till the end of the string is found, or a
370 ;; non-numeric component shows up (5.6.7 is earlier than "5.6.7 beta",
371 ;; which is probably not what you want in some cases).
372 ;; This code is suitable for existing RCS release numbers.
373 ;; CVS releases are handled reasonably, too (1.3 < 1.4* < 1.5).
376 (or (and (string-match "^\\.?\\([0-9]+\\)" r1)
377 (setq i1 (match-end 0))
378 (setq v1 (string-to-number (match-string 1 r1)))
379 (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
380 (setq i2 (match-end 0))
381 (setq v2 (string-to-number (match-string 1 r2)))
382 (if (> v1 v2) (throw 'done t)
383 (if (< v1 v2) (throw 'done nil)
385 (vc-release-greater-or-equal
387 (substring r2 i2)))))))
389 (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
393 (defun vc-backend-release-p (backend release)
394 ;; Return t if we have RELEASE of BACKEND or better
395 (let (i r (ri 0) (ii 0) is rs (installation (vc-backend-release backend)))
396 (if (not (eq installation 'unknown))
398 ((or (eq backend 'RCS) (eq backend 'CVS))
399 (vc-release-greater-or-equal installation release))))))
401 ;;; functions that operate on RCS revision numbers
403 (defun vc-trunk-p (rev)
404 ;; return t if REV is a revision on the trunk
405 (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev))))
407 (defun vc-branch-p (rev)
408 ;; return t if REV is a branch revision
409 (not (eq nil (string-match "\\`[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*\\'" rev))))
411 (defun vc-branch-part (rev)
412 ;; return the branch part of a revision number REV
413 (substring rev 0 (string-match "\\.[0-9]+\\'" rev)))
415 (defun vc-minor-part (rev)
416 ;; return the minor version number of a revision number REV
417 (string-match "[0-9]+\\'" rev)
418 (substring rev (match-beginning 0) (match-end 0)))
420 (defun vc-previous-version (rev)
421 ;; guess the previous version number
422 (let ((branch (vc-branch-part rev))
423 (minor-num (string-to-number (vc-minor-part rev))))
425 ;; version does probably not start a branch or release
426 (concat branch "." (number-to-string (1- minor-num)))
428 ;; we are at the beginning of the trunk --
429 ;; don't know anything to return here
431 ;; we are at the beginning of a branch --
432 ;; return version of starting point
433 (vc-branch-part branch)))))
435 ;; File property caching
437 (defun vc-clear-context ()
438 "Clear all cached file properties and the comment ring."
440 (fillarray vc-file-prop-obarray nil)
441 ;; Note: there is potential for minor lossage here if there is an open
442 ;; log buffer with a nonzero local value of vc-comment-ring-index.
443 (setq vc-comment-ring (make-ring vc-maximum-comment-ring-size)))
445 (defun vc-file-clear-masterprops (file)
446 ;; clear all properties of FILE that were retrieved
447 ;; from the master file
448 (vc-file-setprop file 'vc-latest-version nil)
449 (vc-file-setprop file 'vc-your-latest-version nil)
450 (vc-backend-dispatch file
452 (vc-file-setprop file 'vc-master-locks nil))
454 (vc-file-setprop file 'vc-default-branch nil)
455 (vc-file-setprop file 'vc-head-version nil)
456 (vc-file-setprop file 'vc-master-workfile-version nil)
457 (vc-file-setprop file 'vc-master-locks nil))
459 (vc-file-setprop file 'vc-cvs-status nil))))
461 (defun vc-head-version (file)
462 ;; Return the RCS head version of FILE
463 (cond ((vc-file-getprop file 'vc-head-version))
464 (t (vc-fetch-master-properties file)
465 (vc-file-getprop file 'vc-head-version))))
467 ;; Random helper functions
469 (defun vc-latest-on-branch-p (file)
470 ;; return t iff the current workfile version of FILE is
471 ;; the latest on its branch.
472 (vc-backend-dispatch file
474 (string= (vc-workfile-version file) (vc-latest-version file))
476 (let ((workfile-version (vc-workfile-version file)) tip-version)
477 (if (vc-trunk-p workfile-version)
479 ;; Re-fetch the head version number. This is to make
480 ;; sure that no-one has checked in a new version behind
482 (vc-fetch-master-properties file)
483 (string= (vc-file-getprop file 'vc-head-version)
485 ;; If we are not on the trunk, we need to examine the
486 ;; whole current branch. (vc-master-workfile-version
487 ;; is not what we need.)
489 (set-buffer (get-buffer-create "*vc-info*"))
490 (vc-insert-file (vc-name file) "^desc")
491 (setq tip-version (car (vc-parse-buffer (list (list
492 (concat "^\\(" (regexp-quote (vc-branch-part workfile-version))
493 "\\.[0-9]+\\)\ndate[ \t]+\\([0-9.]+\\);") 1 2)))))
494 (if (get-buffer "*vc-info*")
495 (kill-buffer (get-buffer "*vc-info*")))
496 (string= tip-version workfile-version))))
500 ;;; Two macros for elisp programming
502 (defmacro with-vc-file (file comment &rest body)
503 "Execute BODY, checking out a writable copy of FILE first if necessary.
504 After BODY has been executed, check-in FILE with COMMENT (a string).
505 FILE is passed through `expand-file-name'; BODY executed within
506 `save-excursion'. If FILE is not under version control, or locked by
507 somebody else, signal error."
508 `(let ((file (expand-file-name ,file)))
509 (or (vc-registered file)
510 (error (format "File not under version control: `%s'" file)))
511 (let ((locking-user (vc-locking-user file)))
512 (cond ((and (not locking-user)
513 (eq (vc-checkout-model file) 'manual))
514 (vc-checkout file t))
515 ((and (stringp locking-user)
516 (not (string= locking-user (vc-user-login-name))))
517 (error (format "`%s' is locking `%s'" locking-user file)))))
520 (vc-checkin file nil ,comment)))
523 (defmacro edit-vc-file (file comment &rest body)
524 "Edit FILE under version control, executing BODY. Checkin with COMMENT.
525 This macro uses `with-vc-file', passing args to it.
526 However, before executing BODY, find FILE, and after BODY, save buffer."
533 (defun vc-ensure-vc-buffer ()
534 ;; Make sure that the current buffer visits a version-controlled file.
536 (set-buffer (find-file-noselect (dired-get-filename)))
537 (while vc-parent-buffer
538 (pop-to-buffer vc-parent-buffer))
539 (if (not (buffer-file-name))
540 (error "Buffer %s is not associated with a file" (buffer-name))
541 (if (not (vc-backend (buffer-file-name)))
542 (error "File %s is not under version control" (buffer-file-name))))))
544 (defvar vc-binary-assoc nil)
545 (defvar vc-binary-suffixes
546 (if (memq system-type '(ms-dos windows-nt))
547 '(".exe" ".com" ".bat" ".cmd" ".btm" "")
549 (defun vc-find-binary (name)
550 "Look for a command anywhere on the subprocess-command search path."
551 (or (cdr (assoc name vc-binary-assoc))
557 (let ((full (concat s "/" name))
558 (suffixes vc-binary-suffixes)
561 (setq candidate (concat full (car suffixes)))
562 (if (and (file-executable-p candidate)
563 (not (file-directory-p candidate)))
565 (setq vc-binary-assoc
566 (cons (cons name candidate) vc-binary-assoc))
567 (throw 'found candidate))
568 (setq suffixes (cdr suffixes))))))))
572 (defun vc-do-command (buffer okstatus command file last &rest flags)
573 "Execute a version-control command, notifying user and checking for errors.
574 Output from COMMAND goes to BUFFER, or *vc* if BUFFER is nil. The
575 command is considered successful if its exit status does not exceed
576 OKSTATUS (if OKSTATUS is nil, that means to ignore errors). FILE is
577 the name of the working file (may also be nil, to execute commands
578 that don't expect a file name). If FILE is non-nil, the argument LAST
579 indicates what filename should actually be passed to the command: if
580 it is `MASTER', the name of FILE's master file is used, if it is
581 `WORKFILE', then FILE is passed through unchanged. If an optional
582 list of FLAGS is present, that is inserted into the command line
583 before the filename."
584 (and file (setq file (expand-file-name file)))
585 (if (not buffer) (setq buffer "*vc*"))
586 (if vc-command-messages
587 (message "Running %s on %s..." command file))
588 (let ((obuf (current-buffer)) (camefrom (current-buffer))
590 (olddir default-directory)
592 (set-buffer (get-buffer-create buffer))
593 (set (make-local-variable 'vc-parent-buffer) camefrom)
594 (set (make-local-variable 'vc-parent-buffer-name)
595 (concat " from " (buffer-name camefrom)))
596 (setq default-directory olddir)
601 (function (lambda (s) (and s (setq squeezed (append squeezed (list s))))))
603 (if (and (eq last 'MASTER) file (setq vc-file (vc-name file)))
604 (setq squeezed (append squeezed (list vc-file))))
605 (if (and file (eq last 'WORKFILE))
607 (let* ((pwd (expand-file-name default-directory))
608 (preflen (length pwd)))
609 (if (string= (substring file 0 preflen) pwd)
610 (setq file (substring file preflen))))
611 (setq squeezed (append squeezed (list file)))))
612 (let ((exec-path (append vc-path exec-path))
613 ;; Add vc-path to PATH for the execution of this command.
615 (cons (concat "PATH=" (getenv "PATH")
617 (mapconcat 'identity vc-path path-separator))
618 process-environment))
619 (w32-quote-process-args t))
620 (setq status (apply 'call-process command nil t nil squeezed)))
621 (goto-char (point-max))
622 (set-buffer-modified-p nil)
624 (if (or (not (integerp status)) (and okstatus (< okstatus status)))
626 (pop-to-buffer buffer)
627 (goto-char (point-min))
628 (shrink-window-if-larger-than-buffer)
629 (error "Running %s...FAILED (%s)" command
630 (if (integerp status)
631 (format "status %d" status)
634 (if vc-command-messages
635 (message "Running %s...OK" command))
641 ;;; Save a bit of the text around POSN in the current buffer, to help
642 ;;; us find the corresponding position again later. This works even
643 ;;; if all markers are destroyed or corrupted.
644 ;;; A lot of this was shamelessly lifted from Sebastian Kremer's rcs.el mode.
645 (defun vc-position-context (posn)
648 (buffer-substring posn
649 (min (point-max) (+ posn 100)))))
651 ;;; Return the position of CONTEXT in the current buffer, or nil if we
652 ;;; couldn't find it.
653 (defun vc-find-position-by-context (context)
654 (let ((context-string (nth 2 context)))
655 (if (equal "" context-string)
658 (let ((diff (- (nth 1 context) (buffer-size))))
659 (if (< diff 0) (setq diff (- diff)))
660 (goto-char (nth 0 context))
661 (if (or (search-forward context-string nil t)
662 ;; Can't use search-backward since the match may continue
664 (progn (goto-char (- (point) diff (length context-string)))
665 ;; goto-char doesn't signal an error at
666 ;; beginning of buffer like backward-char would
667 (search-forward context-string nil t)))
668 ;; to beginning of OSTRING
669 (- (point) (length context-string))))))))
671 (defun vc-context-matches-p (posn context)
672 ;; Returns t if POSN matches CONTEXT, nil otherwise.
673 (let* ((context-string (nth 2 context))
674 (len (length context-string))
676 (if (> end (1+ (buffer-size)))
678 (string= context-string (buffer-substring posn end)))))
680 (defun vc-buffer-context ()
681 ;; Return a list '(point-context mark-context reparse); from which
682 ;; vc-restore-buffer-context can later restore the context.
683 (let ((point-context (vc-position-context (point)))
684 ;; Use mark-marker to avoid confusion in transient-mark-mode.
685 (mark-context (if (eq (marker-buffer (mark-marker)) (current-buffer))
686 (vc-position-context (mark-marker))))
687 ;; Make the right thing happen in transient-mark-mode.
689 ;; We may want to reparse the compilation buffer after revert
690 (reparse (and (boundp 'compilation-error-list) ;compile loaded
691 (let ((curbuf (current-buffer)))
692 ;; Construct a list; each elt is nil or a buffer
693 ;; iff that buffer is a compilation output buffer
694 ;; that contains markers into the current buffer.
700 compilation-old-error-list
701 compilation-error-list))
702 (buffer-error-marked-p nil))
703 (while (and (consp errors)
704 (not buffer-error-marked-p))
705 (and (markerp (cdr (car errors)))
709 (setq buffer-error-marked-p t))
710 (setq errors (cdr errors)))
711 (if buffer-error-marked-p buffer))))
713 (list point-context mark-context reparse)))
715 (defun vc-restore-buffer-context (context)
716 ;; Restore point/mark, and reparse any affected compilation buffers.
717 ;; CONTEXT is that which vc-buffer-context returns.
718 (let ((point-context (nth 0 context))
719 (mark-context (nth 1 context))
720 (reparse (nth 2 context)))
721 ;; Reparse affected compilation buffers.
725 (set-buffer (car reparse))
726 (let ((compilation-last-buffer (current-buffer)) ;select buffer
727 ;; Record the position in the compilation buffer of
728 ;; the last error next-error went to.
729 (error-pos (marker-position
730 (car (car-safe compilation-error-list)))))
731 ;; Reparse the error messages as far as they were parsed before.
732 (compile-reinitialize-errors '(4) compilation-parsing-end)
733 ;; Move the pointer up to find the error we were at before
734 ;; reparsing. Now next-error should properly go to the next one.
735 (while (and compilation-error-list
736 (/= error-pos (car (car compilation-error-list))))
737 (setq compilation-error-list (cdr compilation-error-list))))))
738 (setq reparse (cdr reparse)))
740 ;; if necessary, restore point and mark
741 (if (not (vc-context-matches-p (point) point-context))
742 (let ((new-point (vc-find-position-by-context point-context)))
743 (if new-point (goto-char new-point))))
746 (not (vc-context-matches-p (mark) mark-context))
747 (let ((new-mark (vc-find-position-by-context mark-context)))
748 (if new-mark (set-mark new-mark))))))
750 (defun vc-revert-buffer1 (&optional arg no-confirm)
751 ;; Revert buffer, try to keep point and mark where user expects them in spite
752 ;; of changes because of expanded version-control key words.
753 ;; This is quite important since otherwise typeahead won't work as expected.
756 (let ((context (vc-buffer-context)))
757 ;; Use save-excursion here, because it may be able to restore point
758 ;; and mark properly even in cases where vc-restore-buffer-context
759 ;; would fail. However, save-excursion might also get it wrong --
760 ;; in this case, vc-restore-buffer-context gives it a second try.
762 ;; t means don't call normal-mode;
763 ;; that's to preserve various minor modes.
764 (revert-buffer arg no-confirm t))
765 (vc-restore-buffer-context context)))
768 (defun vc-buffer-sync (&optional not-urgent)
769 ;; Make sure the current buffer and its working file are in sync
770 ;; NOT-URGENT means it is ok to continue if the user says not to save.
771 (if (buffer-modified-p)
772 (if (or vc-suppress-confirm
773 (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name))))
777 (error "Aborted")))))
780 (defun vc-workfile-unchanged-p (file &optional want-differences-if-changed)
781 ;; Has the given workfile changed since last checkout?
782 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time))
783 (lastmod (nth 5 (file-attributes file))))
784 (or (equal checkout-time lastmod)
785 (and (or (not checkout-time) want-differences-if-changed)
786 (let ((unchanged (zerop (vc-backend-diff file nil nil
787 (not want-differences-if-changed)))))
788 ;; 0 stands for an unknown time; it can't match any mod time.
789 (vc-file-setprop file 'vc-checkout-time (if unchanged lastmod 0))
792 (defun vc-next-action-on-file (file verbose &optional comment)
793 ;;; If comment is specified, it will be used as an admin or checkin comment.
794 (let ((vc-type (vc-backend file))
795 owner version buffer)
798 ;; If the file is not under version control, register it
800 (vc-register verbose comment))
802 ;; CVS: changes to the master file need to be
803 ;; merged back into the working file
804 ((and (eq vc-type 'CVS)
805 (or (eq (vc-cvs-status file) 'needs-checkout)
806 (eq (vc-cvs-status file) 'needs-merge)))
807 (if (or vc-dired-mode
809 (format "%s is not up-to-date. Merge in changes now? "
813 (and (setq buffer (get-file-buffer file))
814 (buffer-modified-p buffer)
815 (switch-to-buffer-other-window buffer)
817 (setq buffer (current-buffer))
819 (if (and buffer (buffer-modified-p buffer)
822 "Buffer %s modified; merge file on disc anyhow? "
823 (buffer-name buffer)))))
824 (error "Merge aborted"))
825 (let ((status (vc-backend-merge-news file)))
827 (vc-resynch-buffer file t
828 (not (buffer-modified-p buffer))))
829 (if (not (zerop status))
830 (if (y-or-n-p "Conflicts detected. Resolve them now? ")
831 (vc-resolve-conflicts)))))
832 (error "%s needs update" (buffer-name))))
834 ;; For CVS files with implicit checkout: if unmodified, don't do anything
835 ((and (eq vc-type 'CVS)
836 (eq (vc-checkout-model file) 'implicit)
837 (not (vc-locking-user file))
839 (message "%s is up to date" (buffer-name)))
841 ;; If there is no lock on the file, assert one and get it.
842 ((not (setq owner (vc-locking-user file)))
843 ;; With implicit checkout, make sure not to lose unsaved changes.
844 (and (eq (vc-checkout-model file) 'implicit)
845 (buffer-modified-p buffer)
847 (if (and vc-checkout-carefully
848 (not (vc-workfile-unchanged-p file t)))
849 (if (save-window-excursion
850 (pop-to-buffer "*vc-diff*")
851 (goto-char (point-min))
852 (insert-string (format "Changes to %s since last lock:\n\n"
856 (concat "File has unlocked changes, "
857 "claim lock retaining changes? ")))
858 (progn (vc-backend-steal file)
860 (if (not (yes-or-no-p "Revert to checked-in version, instead? "))
861 (error "Checkout aborted")
862 (vc-revert-buffer1 t t)
863 (vc-checkout-writable-buffer file))
866 (if (not (eq vc-type 'SCCS))
867 (vc-checkout file nil
868 (read-string "Branch or version to move to: "))
869 (error "Sorry, this is not implemented for SCCS"))
870 (if (vc-latest-on-branch-p file)
871 (vc-checkout-writable-buffer file)
873 "This is not the latest version. Really lock it? ")
874 (vc-checkout-writable-buffer file)
875 (if (yes-or-no-p "Lock the latest version instead? ")
876 (vc-checkout-writable-buffer file
877 (if (vc-trunk-p (vc-workfile-version file))
878 "" ;; this means check out latest on trunk
879 (vc-branch-part (vc-workfile-version file)))))))
882 ;; a checked-out version exists, but the user may not own the lock
883 ((and (not (eq vc-type 'CVS))
884 (not (string-equal owner (vc-user-login-name))))
886 (error "Sorry, you can't steal the lock on %s this way" file))
887 (and (eq vc-type 'RCS)
888 (not (vc-backend-release-p 'RCS "5.6.2"))
889 (error "File is locked by %s" owner))
892 (if verbose (read-string "Version to steal: ")
893 (vc-workfile-version file))
896 ;; OK, user owns the lock on the file
899 (find-file-other-window file)
902 ;; If the file on disk is newer, then the user just
903 ;; said no to rereading it. So the user probably wishes to
904 ;; overwrite the file with the buffer's contents, and check
906 (if (not (verify-visited-file-modtime (current-buffer)))
907 (if (yes-or-no-p "Replace file on disk with buffer contents? ")
908 (write-file (buffer-file-name))
910 ;; if buffer is not saved, give user a chance to do it
913 ;; Revert if file is unchanged and buffer is too.
914 ;; If buffer is modified, that means the user just said no
915 ;; to saving it; in that case, don't revert,
916 ;; because the user might intend to save
917 ;; after finishing the log entry.
918 (if (and (vc-workfile-unchanged-p file)
919 (not (buffer-modified-p)))
920 ;; DO NOT revert the file without asking the user!
922 ((yes-or-no-p "Revert to master version? ")
923 (vc-backend-revert file)
924 (vc-resynch-window file t t)))
926 ;; user may want to set nonstandard parameters
928 (setq version (read-string "New version level: ")))
930 ;; OK, let's do the checkin
931 (vc-checkin file version comment)
934 (defvar vc-dired-window-configuration)
936 (defun vc-next-action-dired (file rev comment)
937 ;; Do a vc-next-action-on-file on all the marked files, possibly
938 ;; passing on the log comment we've just entered.
939 (let ((dired-buffer (current-buffer))
940 (dired-dir default-directory))
941 (dired-map-over-marks
942 (let ((file (dired-get-filename)))
943 (message "Processing %s..." file)
944 ;; Adjust the default directory so that checkouts
945 ;; go to the right place.
946 (let ((default-directory (file-name-directory file)))
947 (vc-next-action-on-file file nil comment)
948 (set-buffer dired-buffer))
949 ;; Make sure that files don't vanish
950 ;; after they are checked in.
951 (let ((vc-dired-terse-mode nil))
952 (dired-do-redisplay file))
953 (set-window-configuration vc-dired-window-configuration)
954 (message "Processing %s...done" file))
956 (dired-move-to-filename))
958 ;; Here's the major entry point.
961 (defun vc-next-action (verbose)
962 "Do the next logical checkin or checkout operation on the current file.
963 If you call this from within a VC dired buffer with no files marked,
964 it will operate on the file in the current line.
965 If you call this from within a VC dired buffer, and one or more
966 files are marked, it will accept a log message and then operate on
967 each one. The log message will be used as a comment for any register
968 or checkin operations, but ignored when doing checkouts. Attempted
969 lock steals will raise an error.
970 A prefix argument lets you specify the version number to use.
972 For RCS and SCCS files:
973 If the file is not already registered, this registers it for version
975 If the file is registered and not locked by anyone, this checks out
976 a writable and locked file ready for editing.
977 If the file is checked out and locked by the calling user, this
978 first checks to see if the file has changed since checkout. If not,
979 it performs a revert.
980 If the file has been changed, this pops up a buffer for entry
981 of a log message; when the message has been entered, it checks in the
982 resulting changes along with the log message as change commentary. If
983 the variable `vc-keep-workfiles' is non-nil (which is its default), a
984 read-only copy of the changed file is left in place afterwards.
985 If the file is registered and locked by someone else, you are given
986 the option to steal the lock.
989 If the file is not already registered, this registers it for version
990 control. This does a \"cvs add\", but no \"cvs commit\".
991 If the file is added but not committed, it is committed.
992 If your working file is changed, but the repository file is
993 unchanged, this pops up a buffer for entry of a log message; when the
994 message has been entered, it checks in the resulting changes along
995 with the logmessage as change commentary. A writable file is retained.
996 If the repository file is changed, you are asked if you want to
997 merge in the changes into your working copy."
1002 (let ((files (dired-get-marked-files)))
1003 (set (make-local-variable 'vc-dired-window-configuration)
1004 (current-window-configuration))
1007 (function (lambda (f)
1008 (if (eq (vc-backend f) 'CVS)
1009 (if (or (eq (vc-cvs-status f) 'locally-modified)
1010 (eq (vc-cvs-status f) 'locally-added))
1012 (if (vc-locking-user f) "@" ""))))
1014 (vc-next-action-dired nil nil "dummy")
1015 (vc-start-entry nil nil nil
1016 "Enter a change comment for the marked files."
1017 'vc-next-action-dired))
1019 (while vc-parent-buffer
1020 (pop-to-buffer vc-parent-buffer))
1021 (if buffer-file-name
1022 (vc-next-action-on-file buffer-file-name verbose)
1023 (error "Buffer %s is not associated with a file" (buffer-name)))))
1025 ;;; These functions help the vc-next-action entry point
1027 (defun vc-checkout-writable-buffer (&optional file rev)
1028 "Retrieve a writable copy of the latest version of the current buffer's file."
1029 (vc-checkout (or file (buffer-file-name)) t rev)
1033 (defun vc-register (&optional override comment)
1034 "Register the current file into your version-control system."
1036 (or buffer-file-name
1037 (error "No visited file"))
1038 (let ((master (vc-name buffer-file-name)))
1039 (and master (file-exists-p master)
1040 (error "This file is already registered"))
1042 (not (y-or-n-p "Previous master file has vanished. Make a new one? "))
1043 (error "This file is already registered")))
1044 ;; Watch out for new buffers of size 0: the corresponding file
1045 ;; does not exist yet, even though buffer-modified-p is nil.
1046 (if (and (not (buffer-modified-p))
1047 (zerop (buffer-size))
1048 (not (file-exists-p buffer-file-name)))
1049 (set-buffer-modified-p t))
1051 (cond ((not vc-make-backup-files)
1052 ;; inhibit backup for this buffer
1053 (make-local-variable 'backup-inhibited)
1054 (setq backup-inhibited t)))
1059 (format "Initial version level for %s: " buffer-file-name)))
1060 vc-default-init-version)
1062 ;; Recompute backend property (it may have been set to nil before).
1063 (setq vc-buffer-backend (vc-backend (buffer-file-name)))
1066 (defun vc-resynch-window (file &optional keep noquery)
1067 ;; If the given file is in the current buffer,
1068 ;; either revert on it so we see expanded keywords,
1069 ;; or unvisit it (depending on vc-keep-workfiles)
1070 ;; NOQUERY if non-nil inhibits confirmation for reverting.
1071 ;; NOQUERY should be t *only* if it is known the only difference
1072 ;; between the buffer and the file is due to RCS rather than user editing!
1073 (and (string= buffer-file-name file)
1076 (vc-revert-buffer1 t noquery)
1078 (if (file-writable-p file)
1080 (let ((view-old-buffer-read-only nil))
1082 (and (not view-mode)
1083 (not (eq (get major-mode 'mode-class) 'special))
1084 (view-mode-enter))))
1085 (vc-mode-line buffer-file-name))
1086 (kill-buffer (current-buffer)))))
1088 (defun vc-resynch-buffer (file &optional keep noquery)
1089 ;; if FILE is currently visited, resynch its buffer
1090 (if (string= buffer-file-name file)
1091 (vc-resynch-window file keep noquery)
1092 (let ((buffer (get-file-buffer file)))
1096 (vc-resynch-window file keep noquery))))))
1098 (defun vc-start-entry (file rev comment msg action &optional after-hook)
1099 ;; Accept a comment for an operation on FILE revision REV. If COMMENT
1100 ;; is nil, pop up a VC-log buffer, emit MSG, and set the
1101 ;; action on close to ACTION; otherwise, do action immediately.
1102 ;; Remember the file's buffer in vc-parent-buffer (current one if no file).
1103 ;; AFTER-HOOK specifies the local value for vc-log-operation-hook.
1104 (let ((parent (if file (find-file-noselect file) (current-buffer))))
1105 (if vc-before-checkin-hook
1109 (run-hooks 'vc-before-checkin-hook))
1110 (run-hooks 'vc-before-checkin-hook)))
1112 (set-buffer (get-buffer-create "*VC-log*"))
1113 (pop-to-buffer (get-buffer-create "*VC-log*")))
1114 (set (make-local-variable 'vc-parent-buffer) parent)
1115 (set (make-local-variable 'vc-parent-buffer-name)
1116 (concat " from " (buffer-name vc-parent-buffer)))
1117 (if file (vc-mode-line file))
1119 (make-local-variable 'vc-log-after-operation-hook)
1121 (setq vc-log-after-operation-hook after-hook))
1122 (setq vc-log-operation action)
1123 (setq vc-log-version rev)
1128 (vc-finish-logentry t)
1130 (vc-finish-logentry nil)))
1131 (message "%s Type C-c C-c when done." msg))))
1133 (defun vc-admin (file rev &optional comment)
1134 "Check a file into your version-control system.
1135 FILE is the unmodified name of the file. REV should be the base version
1136 level to check it in under. COMMENT, if specified, is the checkin comment."
1137 (vc-start-entry file rev
1138 (or comment (not vc-initial-comment))
1139 "Enter initial comment." 'vc-backend-admin
1142 (defun vc-checkout (file &optional writable rev)
1143 "Retrieve a copy of the latest version of the given file."
1144 ;; If ftp is on this system and the name matches the ange-ftp format
1145 ;; for a remote file, the user is trying something that won't work.
1146 (if (and (string-match "^/[^/:]+:" file) (vc-find-binary "ftp"))
1147 (error "Sorry, you can't check out files over FTP"))
1148 (vc-backend-checkout file writable rev)
1149 (vc-resynch-buffer file t t))
1151 (defun vc-steal-lock (file rev &optional owner)
1152 "Steal the lock on the current workfile."
1153 (let (file-description)
1155 (setq owner (vc-locking-user file)))
1157 (setq file-description (format "%s:%s" file rev))
1158 (setq file-description file))
1159 (if (not (yes-or-no-p (format "Steal the lock on %s from %s? "
1160 file-description owner)))
1161 (error "Steal cancelled"))
1162 (pop-to-buffer (get-buffer-create "*VC-mail*"))
1163 (setq default-directory (expand-file-name "~/"))
1164 (auto-save-mode auto-save-default)
1167 (mail-setup owner (format "Stolen lock on %s" file-description) nil nil nil
1168 (list (list 'vc-finish-steal file rev)))
1169 (goto-char (point-max))
1171 (format "I stole the lock on %s, " file-description)
1172 (current-time-string)
1174 (message "Please explain why you stole the lock. Type C-c C-c when done.")))
1176 ;; This is called when the notification has been sent.
1177 (defun vc-finish-steal (file version)
1178 (vc-backend-steal file version)
1179 (if (get-file-buffer file)
1181 (set-buffer (get-file-buffer file))
1182 (vc-resynch-window file t t))))
1184 (defun vc-checkin (file &optional rev comment)
1185 "Check in the file specified by FILE.
1186 The optional argument REV may be a string specifying the new version level
1187 \(if nil increment the current level). The file is either retained with write
1188 permissions zeroed, or deleted (according to the value of `vc-keep-workfiles').
1189 If the back-end is CVS, a writable workfile is always kept.
1190 COMMENT is a comment string; if omitted, a buffer is popped up to accept a
1193 Runs the normal hook `vc-checkin-hook'."
1194 (vc-start-entry file rev comment
1195 "Enter a change comment." 'vc-backend-checkin
1198 (defun vc-comment-to-change-log (&optional whoami file-name)
1199 "Enter last VC comment into change log file for current buffer's file.
1200 Optional arg (interactive prefix) non-nil means prompt for user name and site.
1201 Second arg is file name of change log. \
1202 If nil, uses `change-log-default-name'.
1204 May be useful as a `vc-checkin-hook' to update change logs automatically."
1205 (interactive (if current-prefix-arg
1206 (list current-prefix-arg
1207 (prompt-for-change-log-name))))
1208 ;; Make sure the defvar for add-log-current-defun-function has been executed
1209 ;; before binding it.
1211 (let (;; Extract the comment first so we get any error before doing anything.
1212 (comment (ring-ref vc-comment-ring 0))
1213 ;; Don't let add-change-log-entry insert a defun name.
1214 (add-log-current-defun-function 'ignore)
1216 ;; Call add-log to do half the work.
1217 (add-change-log-entry whoami file-name t t)
1218 ;; Insert the VC comment, leaving point before it.
1219 (setq end (save-excursion (insert comment) (point-marker)))
1220 (if (looking-at "\\s *\\s(")
1221 ;; It starts with an open-paren, as in "(foo): Frobbed."
1222 ;; So remove the ": " add-log inserted.
1224 ;; Canonicalize the white space between the file name and comment.
1226 ;; Indent rest of the text the same way add-log indented the first line.
1227 (let ((indentation (current-indentation)))
1229 (while (< (point) end)
1231 (indent-to indentation))
1232 (setq end (point))))
1233 ;; Fill the inserted text, preserving open-parens at bol.
1234 (let ((paragraph-separate (concat paragraph-separate "\\|\\s *\\s("))
1235 (paragraph-start (concat paragraph-start "\\|\\s *\\s(")))
1237 (fill-region (point) end))
1238 ;; Canonicalize the white space at the end of the entry so it is
1239 ;; separated from the next entry by a single blank line.
1240 (skip-syntax-forward " " end)
1241 (delete-char (- (skip-syntax-backward " ")))
1242 (or (eobp) (looking-at "\n\n")
1246 (defun vc-finish-logentry (&optional nocomment)
1247 "Complete the operation implied by the current log entry."
1249 ;; Check and record the comment, if any.
1252 ;; Comment too long?
1253 (vc-backend-logentry-check vc-log-file)
1254 ;; Record the comment in the comment ring
1255 (ring-insert vc-comment-ring (buffer-string))
1257 ;; Sync parent buffer in case the user modified it while editing the comment.
1258 ;; But not if it is a vc-dired buffer.
1260 (set-buffer vc-parent-buffer)
1263 (if (not vc-log-operation) (error "No log operation is pending"))
1264 ;; save the parameters held in buffer-local variables
1265 (let ((log-operation vc-log-operation)
1266 (log-file vc-log-file)
1267 (log-version vc-log-version)
1268 (log-entry (buffer-string))
1269 (after-hook vc-log-after-operation-hook))
1270 (pop-to-buffer vc-parent-buffer)
1273 (funcall log-operation
1277 ;; Remove checkin window (after the checkin so that if that fails
1278 ;; we don't zap the *VC-log* buffer and the typing therein).
1279 (let ((logbuf (get-buffer "*VC-log*")))
1281 (delete-windows-on logbuf (selected-frame))
1282 ;; Kill buffer and delete any other dedicated windows/frames.
1283 (kill-buffer logbuf))))
1284 ;; Now make sure we see the expanded headers
1285 (if buffer-file-name
1286 (vc-resynch-window buffer-file-name vc-keep-workfiles t))
1288 (dired-move-to-filename))
1289 (run-hooks after-hook 'vc-finish-logentry-hook)))
1291 ;; Code for access to the comment ring
1293 (defun vc-previous-comment (arg)
1294 "Cycle backwards through comment history."
1296 (let ((len (ring-length vc-comment-ring)))
1298 (message "Empty comment ring")
1302 ;; Initialize the index on the first use of this command
1303 ;; so that the first M-p gets index 0, and the first M-n gets
1305 (if (null vc-comment-ring-index)
1306 (setq vc-comment-ring-index
1308 (if (< arg 0) 1 0))))
1309 (setq vc-comment-ring-index
1310 (mod (+ vc-comment-ring-index arg) len))
1311 (message "%d" (1+ vc-comment-ring-index))
1312 (insert (ring-ref vc-comment-ring vc-comment-ring-index))))))
1314 (defun vc-next-comment (arg)
1315 "Cycle forwards through comment history."
1317 (vc-previous-comment (- arg)))
1319 (defun vc-comment-search-reverse (str)
1320 "Searches backwards through comment history for substring match."
1321 (interactive "sComment substring: ")
1322 (if (string= str "")
1323 (setq str vc-last-comment-match)
1324 (setq vc-last-comment-match str))
1325 (if (null vc-comment-ring-index)
1326 (setq vc-comment-ring-index -1))
1327 (let ((str (regexp-quote str))
1328 (len (ring-length vc-comment-ring))
1329 (n (1+ vc-comment-ring-index)))
1330 (while (and (< n len) (not (string-match str (ring-ref vc-comment-ring n))))
1333 (vc-previous-comment (- n vc-comment-ring-index)))
1334 (t (error "Not found")))))
1336 (defun vc-comment-search-forward (str)
1337 "Searches forwards through comment history for substring match."
1338 (interactive "sComment substring: ")
1339 (if (string= str "")
1340 (setq str vc-last-comment-match)
1341 (setq vc-last-comment-match str))
1342 (if (null vc-comment-ring-index)
1343 (setq vc-comment-ring-index 0))
1344 (let ((str (regexp-quote str))
1345 (len (ring-length vc-comment-ring))
1346 (n vc-comment-ring-index))
1347 (while (and (>= n 0) (not (string-match str (ring-ref vc-comment-ring n))))
1350 (vc-next-comment (- n vc-comment-ring-index)))
1351 (t (error "Not found")))))
1353 ;; Additional entry points for examining version histories
1356 (defun vc-diff (historic &optional not-urgent)
1357 "Display diffs between file versions.
1358 Normally this compares the current file and buffer with the most recent
1359 checked in version of that file. This uses no arguments.
1360 With a prefix argument, it reads the file name to use
1361 and two version designators specifying which versions to compare."
1362 (interactive (list current-prefix-arg t))
1363 (vc-ensure-vc-buffer)
1365 (call-interactively 'vc-version-diff)
1366 (let ((file buffer-file-name)
1368 (vc-buffer-sync not-urgent)
1369 (setq unchanged (vc-workfile-unchanged-p buffer-file-name))
1371 (message "No changes to %s since latest version" file)
1372 (vc-backend-diff file)
1373 ;; Ideally, we'd like at this point to parse the diff so that
1374 ;; the buffer effectively goes into compilation mode and we
1375 ;; can visit the old and new change locations via next-error.
1376 ;; Unfortunately, this is just too painful to do. The basic
1377 ;; problem is that the `old' file doesn't exist to be
1378 ;; visited. This plays hell with numerous assumptions in
1379 ;; the diff.el and compile.el machinery.
1380 (set-buffer "*vc-diff*")
1381 (setq default-directory (file-name-directory file))
1382 (if (= 0 (buffer-size))
1385 (message "No changes to %s since latest version" file))
1386 (pop-to-buffer "*vc-diff*")
1387 (goto-char (point-min))
1388 (shrink-window-if-larger-than-buffer)))
1391 (defun vc-version-diff (file rel1 rel2)
1392 "For FILE, report diffs between two stored versions REL1 and REL2 of it.
1393 If FILE is a directory, generate diffs between versions for all registered
1394 files in or below it."
1396 (let ((file (read-file-name (if buffer-file-name
1397 "File or dir to diff: (default visited file) "
1398 "File or dir to diff: ")
1399 default-directory buffer-file-name t))
1400 (rel1-default nil) (rel2-default nil))
1401 ;; compute default versions based on the file state
1403 ;; if it's a directory, don't supply any version defauolt
1404 ((file-directory-p file)
1406 ;; if the file is locked, use current version as older version
1407 ((vc-locking-user file)
1408 (setq rel1-default (vc-workfile-version file)))
1409 ;; if the file is not locked, use last and previous version as default
1411 (setq rel1-default (vc-previous-version (vc-workfile-version file)))
1412 (setq rel2-default (vc-workfile-version file))))
1413 ;; construct argument list
1415 (read-string (if rel1-default
1416 (concat "Older version: (default "
1419 nil nil rel1-default)
1420 (read-string (if rel2-default
1421 (concat "Newer version: (default "
1423 "Newer version (default: current source): ")
1424 nil nil rel2-default))))
1425 (if (string-equal rel1 "") (setq rel1 nil))
1426 (if (string-equal rel2 "") (setq rel2 nil))
1427 (if (file-directory-p file)
1428 (let ((camefrom (current-buffer)))
1429 (set-buffer (get-buffer-create "*vc-status*"))
1430 (set (make-local-variable 'vc-parent-buffer) camefrom)
1431 (set (make-local-variable 'vc-parent-buffer-name)
1432 (concat " from " (buffer-name camefrom)))
1434 (insert "Diffs between "
1435 (or rel1 "last version checked in")
1437 (or rel2 "current workfile(s)")
1439 (set-buffer (get-buffer-create "*vc-diff*"))
1443 (function (lambda (f)
1444 (message "Looking at %s" f)
1446 (not (file-directory-p f))
1448 (vc-backend-diff f rel1 rel2)
1449 (append-to-buffer "*vc-status*" (point-min) (point-max)))
1451 (pop-to-buffer "*vc-status*")
1452 (insert "\nEnd of diffs.\n")
1453 (goto-char (point-min))
1454 (set-buffer-modified-p nil)
1456 (if (zerop (vc-backend-diff file rel1 rel2))
1457 (message "No changes to %s between %s and %s." file rel1 rel2)
1458 (pop-to-buffer "*vc-diff*"))))
1461 (defun vc-version-other-window (rev)
1462 "Visit version REV of the current buffer in another window.
1463 If the current buffer is named `F', the version is named `F.~REV~'.
1464 If `F.~REV~' already exists, it is used instead of being re-created."
1465 (interactive "sVersion to visit (default is latest version): ")
1466 (vc-ensure-vc-buffer)
1467 (let* ((version (if (string-equal rev "")
1468 (vc-latest-version buffer-file-name)
1470 (filename (concat buffer-file-name ".~" version "~")))
1471 (or (file-exists-p filename)
1472 (vc-backend-checkout buffer-file-name nil version filename))
1473 (find-file-other-window filename)))
1475 ;; Header-insertion code
1478 (defun vc-insert-headers ()
1479 "Insert headers in a file for use with your version-control system.
1480 Headers desired are inserted at point, and are pulled from
1481 the variable `vc-header-alist'."
1483 (vc-ensure-vc-buffer)
1487 (if (or (not (vc-check-headers))
1488 (y-or-n-p "Version headers already exist. Insert another set? "))
1490 (let* ((delims (cdr (assq major-mode vc-comment-alist)))
1491 (comment-start-vc (or (car delims) comment-start "#"))
1492 (comment-end-vc (or (car (cdr delims)) comment-end ""))
1493 (hdstrings (cdr (assoc (vc-backend (buffer-file-name)) vc-header-alist))))
1494 (mapcar (function (lambda (s)
1495 (insert comment-start-vc "\t" s "\t"
1496 comment-end-vc "\n")))
1498 (if vc-static-header-alist
1499 (mapcar (function (lambda (f)
1500 (if (string-match (car f) buffer-file-name)
1501 (insert (format (cdr f) (car hdstrings))))))
1502 vc-static-header-alist))
1506 (defun vc-clear-headers ()
1507 ;; Clear all version headers in the current buffer, i.e. reset them
1508 ;; to the nonexpanded form. Only implemented for RCS, yet.
1509 ;; Don't lose point and mark during this.
1510 (let ((context (vc-buffer-context))
1511 (case-fold-search nil))
1512 ;; save-excursion may be able to relocate point and mark properly.
1513 ;; If it fails, vc-restore-buffer-context will give it a second try.
1515 (goto-char (point-min))
1516 (while (re-search-forward
1517 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
1518 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
1520 (replace-match "$\\1$")))
1521 (vc-restore-buffer-context context)))
1526 (vc-ensure-vc-buffer)
1528 (let* ((file buffer-file-name)
1529 (backend (vc-backend file))
1530 first-version second-version locking-user)
1531 (if (eq backend 'SCCS)
1532 (error "Sorry, merging is not implemented for SCCS")
1533 (setq locking-user (vc-locking-user file))
1534 (if (eq (vc-checkout-model file) 'manual)
1535 (if (not locking-user)
1537 (format "File must be %s for merging. %s now? "
1538 (if (eq backend 'RCS) "locked" "writable")
1539 (if (eq backend 'RCS) "Lock" "Check out"))))
1540 (error "Merge aborted")
1541 (vc-checkout file t))
1542 (if (not (string= locking-user (vc-user-login-name)))
1543 (error "File is locked by %s" locking-user))))
1544 (setq first-version (read-string "Branch or version to merge from: "))
1545 (if (and (>= (elt first-version 0) ?0)
1546 (<= (elt first-version 0) ?9))
1547 (if (not (vc-branch-p first-version))
1548 (setq second-version
1549 (read-string "Second version: "
1550 (concat (vc-branch-part first-version) ".")))
1551 ;; We want to merge an entire branch. Set versions
1552 ;; accordingly, so that vc-backend-merge understands us.
1553 (setq second-version first-version)
1554 ;; first-version must be the starting point of the branch
1555 (setq first-version (vc-branch-part first-version))))
1556 (let ((status (vc-backend-merge file first-version second-version)))
1557 (if (and (eq (vc-checkout-model file) 'implicit)
1558 (not (vc-locking-user file)))
1559 (vc-file-setprop file 'vc-locking-user nil))
1560 (vc-resynch-buffer file t t)
1561 (if (not (zerop status))
1562 (if (y-or-n-p "Conflicts detected. Resolve them now? ")
1563 (vc-resolve-conflicts "WORKFILE" "MERGE SOURCE")
1564 (message "File contains conflict markers"))
1565 (message "Merge successful"))))))
1567 (defvar vc-ediff-windows)
1568 (defvar vc-ediff-result)
1571 (defun vc-resolve-conflicts (&optional name-A name-B)
1572 "Invoke ediff to resolve conflicts in the current buffer.
1573 The conflicts must be marked with rcsmerge conflict markers."
1575 (vc-ensure-vc-buffer)
1577 (file-name (file-name-nondirectory buffer-file-name))
1578 (your-buffer (generate-new-buffer
1579 (concat "*" file-name
1580 " " (or name-A "WORKFILE") "*")))
1581 (other-buffer (generate-new-buffer
1582 (concat "*" file-name
1583 " " (or name-B "CHECKED-IN") "*")))
1584 (result-buffer (current-buffer)))
1586 (set-buffer your-buffer)
1588 (insert-buffer result-buffer)
1589 (goto-char (point-min))
1590 (while (re-search-forward (concat "^<<<<<<< "
1591 (regexp-quote file-name) "\n") nil t)
1594 (if (not (re-search-forward "^=======\n" nil t))
1595 (error "Malformed conflict marker"))
1597 (let ((start (point)))
1598 (if (not (re-search-forward "^>>>>>>> [0-9.]+\n" nil t))
1599 (error "Malformed conflict marker"))
1600 (delete-region start (point))))
1603 (kill-buffer your-buffer)
1604 (kill-buffer other-buffer)
1605 (error "No conflict markers found")))
1606 (set-buffer other-buffer)
1608 (insert-buffer result-buffer)
1609 (goto-char (point-min))
1610 (while (re-search-forward (concat "^<<<<<<< "
1611 (regexp-quote file-name) "\n") nil t)
1612 (let ((start (match-beginning 0)))
1613 (if (not (re-search-forward "^=======\n" nil t))
1614 (error "Malformed conflict marker"))
1615 (delete-region start (point))
1616 (if (not (re-search-forward "^>>>>>>> [0-9.]+\n" nil t))
1617 (error "Malformed conflict marker"))
1618 (replace-match "")))
1619 (let ((config (current-window-configuration))
1620 (ediff-default-variant 'default-B))
1624 (set-buffer (ediff-merge-buffers your-buffer other-buffer))
1626 ;; Ediff is now set up, and we are in the control buffer.
1627 ;; Do a few further adjustments and take precautions for exit.
1629 (make-local-variable 'vc-ediff-windows)
1630 (setq vc-ediff-windows config)
1631 (make-local-variable 'vc-ediff-result)
1632 (setq vc-ediff-result result-buffer)
1633 (make-local-variable 'ediff-quit-hook)
1634 (setq ediff-quit-hook
1637 (let ((buffer-A ediff-buffer-A)
1638 (buffer-B ediff-buffer-B)
1639 (buffer-C ediff-buffer-C)
1640 (result vc-ediff-result)
1641 (windows vc-ediff-windows))
1642 (ediff-cleanup-mess)
1645 (insert-buffer buffer-C)
1646 (kill-buffer buffer-A)
1647 (kill-buffer buffer-B)
1648 (kill-buffer buffer-C)
1649 (set-window-configuration windows)
1650 (message "Conflict resolution finished; you may save the buffer")))))
1651 (message "Please resolve conflicts now; exit ediff when done")
1654 ;; The VC directory major mode. Coopt Dired for this.
1655 ;; All VC commands get mapped into logical equivalents.
1657 (defvar vc-dired-switches)
1658 (defvar vc-dired-terse-mode)
1660 (define-derived-mode vc-dired-mode dired-mode "Dired under VC"
1661 "The major mode used in VC directory buffers. It works like Dired,
1662 but lists only files under version control, with the current VC state of
1663 each file being indicated in the place of the file's link count, owner,
1664 group and size. Subdirectories are also listed, and you may insert them
1665 into the buffer as desired, like in Dired.
1666 All Dired commands operate normally, with the exception of `v', which
1667 is redefined as the version control prefix, so that you can type
1668 `vl', `v=' etc. to invoke `vc-print-log', `vc-diff', and the like on
1669 the file named in the current Dired buffer line. `vv' invokes
1670 `vc-next-action' on this file, or on all files currently marked.
1671 There is a special command, `*l', to mark all files currently locked."
1672 (make-local-hook 'dired-after-readin-hook)
1673 (add-hook 'dired-after-readin-hook 'vc-dired-hook nil t)
1674 ;; The following is slightly modified from dired.el,
1675 ;; because file lines look a bit different in vc-dired-mode.
1676 (set (make-local-variable 'dired-move-to-filename-regexp)
1678 ((l "\\([A-Za-z]\\|[^\0-\177]\\)")
1679 ;; In some locales, month abbreviations are as short as 2 letters,
1680 ;; and they can be padded on the right with spaces.
1681 (month (concat l l "+ *"))
1682 ;; Recognize any non-ASCII character.
1683 ;; The purpose is to match a Kanji character.
1685 ;; (k "[^\x00-\x7f\x80-\xff]")
1687 (yyyy "[0-9][0-9][0-9][0-9]")
1690 (HH:MM "[ 0-2][0-9]:[0-5][0-9]")
1691 (western (concat "\\(" month s dd "\\|" dd s month "\\)"
1692 s "\\(" HH:MM "\\|" s yyyy "\\)"))
1693 (japanese (concat mm k s dd k s "\\(" s HH:MM "\\|" yyyy k "\\)")))
1694 (concat s "\\(" western "\\|" japanese "\\)" s)))
1695 (and (boundp 'vc-dired-switches)
1697 (set (make-local-variable 'dired-actual-switches)
1699 (set (make-local-variable 'vc-dired-terse-mode) vc-dired-terse-display)
1700 (setq vc-dired-mode t))
1702 (define-key vc-dired-mode-map "\C-xv" vc-prefix-map)
1703 (define-key vc-dired-mode-map "v" vc-prefix-map)
1705 (defun vc-dired-toggle-terse-mode ()
1706 "Toggle terse display in VC Dired."
1708 (if (not vc-dired-mode)
1710 (setq vc-dired-terse-mode (not vc-dired-terse-mode))
1711 (if vc-dired-terse-mode
1715 (define-key vc-dired-mode-map "vt" 'vc-dired-toggle-terse-mode)
1717 (defun vc-dired-mark-locked ()
1718 "Mark all files currently locked."
1720 (dired-mark-if (let ((f (dired-get-filename nil t)))
1722 (not (file-directory-p f))
1723 (vc-locking-user f)))
1726 (define-key vc-dired-mode-map "*l" 'vc-dired-mark-locked)
1728 (defun vc-fetch-cvs-status (dir)
1729 (let ((default-directory dir))
1730 ;; Don't specify DIR in this command, the default-directory is
1731 ;; enough. Otherwise it might fail with remote repositories.
1732 (vc-do-command "*vc-info*" 0 "cvs" nil nil "status")
1734 (set-buffer (get-buffer "*vc-info*"))
1735 (goto-char (point-min))
1736 (while (re-search-forward "^=+\n\\([^=\n].*\n\\|\n\\)+" nil t)
1737 (narrow-to-region (match-beginning 0) (match-end 0))
1738 (vc-parse-cvs-status)
1739 (goto-char (point-max))
1742 (defun vc-dired-state-info (file)
1743 ;; Return the string that indicates the version control status
1744 ;; on a VC dired line.
1745 (let* ((cvs-state (and (eq (vc-backend file) 'CVS)
1746 (vc-cvs-status file)))
1749 (cond ((eq cvs-state 'up-to-date) nil)
1750 ((eq cvs-state 'needs-checkout) "patch")
1751 ((eq cvs-state 'locally-modified) "modified")
1752 ((eq cvs-state 'needs-merge) "merge")
1753 ((eq cvs-state 'unresolved-conflict) "conflict")
1754 ((eq cvs-state 'locally-added) "added"))
1755 (vc-locking-user file))))
1756 (if state (concat "(" state ")"))))
1758 (defun vc-dired-reformat-line (x)
1759 ;; Reformat a directory-listing line, replacing various columns with
1760 ;; version control information.
1761 ;; This code, like dired, assumes UNIX -l format.
1763 (let ((pos (point)) limit perm date-and-file)
1765 (setq limit (point))
1769 (re-search-forward ;; owner and group
1770 "^\\(..[drwxlts-]+ \\) *[0-9]+ [^ ]+ +[^ ]+ +[0-9]+\\( .*\\)"
1772 (re-search-forward ;; only owner displayed
1773 "^\\(..[drwxlts-]+ \\) *[0-9]+ [^ ]+ +[0-9]+\\( .*\\)"
1775 (re-search-forward ;; OS/2 -l format, no links, owner, group
1776 "^\\(..[drwxlts-]+ \\) *[0-9]+\\( .*\\)"
1778 (setq perm (match-string 1)
1779 date-and-file (match-string 2))
1780 (setq x (substring (concat x " ") 0 10))
1781 (replace-match (concat perm x date-and-file)))))
1783 (defun vc-dired-hook ()
1784 ;; Called by dired after any portion of a vc-dired buffer has been read in.
1785 ;; Reformat the listing according to version control.
1786 (message "Getting version information... ")
1787 (let (subdir filename (buffer-read-only nil) cvs-dir)
1788 (goto-char (point-min))
1789 (while (not (eq (point) (point-max)))
1791 ;; subdir header line
1792 ((setq subdir (dired-get-subdir))
1793 (if (file-directory-p (concat subdir "/CVS"))
1795 (vc-fetch-cvs-status (file-name-as-directory subdir))
1799 ;; erase (but don't remove) the "total" line
1800 (let ((start (point)))
1802 (delete-region start (point))
1806 ((setq filename (dired-get-filename nil t))
1809 ((file-directory-p filename)
1811 ((member (file-name-nondirectory filename)
1812 vc-directory-exclusion-list)
1813 (let ((pos (point)))
1814 (dired-kill-tree filename)
1817 (vc-dired-terse-mode
1818 ;; Don't show directories in terse mode. Don't use
1819 ;; dired-kill-line to remove it, because in recursive listings,
1820 ;; that would remove the directory contents as well.
1821 (delete-region (progn (beginning-of-line) (point))
1822 (progn (forward-line 1) (point))))
1823 ((string-match "\\`\\.\\.?\\'" (file-name-nondirectory filename))
1826 (vc-dired-reformat-line nil)
1830 (and (eq (vc-file-getprop filename 'vc-backend) 'CVS)
1831 (or (not vc-dired-terse-mode)
1832 (not (eq (vc-cvs-status filename) 'up-to-date))))
1833 (and (vc-backend filename)
1834 (or (not vc-dired-terse-mode)
1835 (vc-locking-user filename))))
1836 (vc-dired-reformat-line (vc-dired-state-info filename))
1839 (dired-kill-line))))
1841 (t (forward-line 1))))
1843 (message "Getting version information... done")
1846 (cond ((eq (count-lines (point-min) (point-max)) 1)
1847 (goto-char (point-min))
1848 (message "No files locked under %s" default-directory)))))
1850 (defun vc-dired-purge ()
1851 ;; Remove empty subdirs
1853 (goto-char (point-min))
1854 (while (setq subdir (dired-get-subdir))
1856 (if (dired-get-filename nil t)
1857 (if (not (dired-next-subdir 1 t))
1858 (goto-char (point-max)))
1860 (if (not (string= (dired-current-directory) default-directory))
1861 (dired-do-kill-lines t "")
1862 ;; We cannot remove the top level directory.
1863 ;; Just make it look a little nicer.
1866 (if (not (dired-next-subdir 1 t))
1867 (goto-char (point-max))))))
1868 (goto-char (point-min))))
1871 (defun vc-directory (dirname read-switches)
1872 (interactive "DDired under VC (directory): \nP")
1873 (let ((vc-dired-switches (concat dired-listing-switches
1874 (if vc-dired-recurse "R" ""))))
1876 (setq vc-dired-switches
1877 (read-string "Dired listing switches: "
1878 vc-dired-switches)))
1880 (require 'dired-aux)
1881 ;; force a trailing slash
1882 (if (not (eq (elt dirname (1- (length dirname))) ?/))
1883 (setq dirname (concat dirname "/")))
1885 (dired-internal-noselect (expand-file-name dirname)
1886 (or vc-dired-switches dired-listing-switches)
1889 ;; Named-configuration support for SCCS
1891 (defun vc-add-triple (name file rev)
1893 (find-file (expand-file-name
1895 (file-name-directory (vc-name file))))
1896 (goto-char (point-max))
1897 (insert name "\t:\t" file "\t" rev "\n")
1899 (kill-buffer (current-buffer))
1902 (defun vc-record-rename (file newname)
1907 (file-name-directory (vc-name file))))
1908 (goto-char (point-min))
1909 ;; (replace-regexp (concat ":" (regexp-quote file) "$") (concat ":" newname))
1910 (while (re-search-forward (concat ":" (regexp-quote file) "$") nil t)
1911 (replace-match (concat ":" newname) nil nil))
1913 (kill-buffer (current-buffer))
1916 (defun vc-lookup-triple (file name)
1917 ;; Return the numeric version corresponding to a named snapshot of file
1918 ;; If name is nil or a version number string it's just passed through
1919 (cond ((null name) name)
1920 ((let ((firstchar (aref name 0)))
1921 (and (>= firstchar ?0) (<= firstchar ?9)))
1925 (set-buffer (get-buffer-create "*vc-info*"))
1929 (file-name-directory (vc-name file))))
1931 (car (vc-parse-buffer
1932 (list (list (concat name "\t:\t" file "\t\\(.+\\)") 1))))
1933 (kill-buffer "*vc-info*"))))
1936 ;; Named-configuration entry points
1938 (defun vc-snapshot-precondition ()
1939 ;; Scan the tree below the current directory.
1940 ;; If any files are locked, return the name of the first such file.
1941 ;; (This means, neither snapshot creation nor retrieval is allowed.)
1942 ;; If one or more of the files are currently visited, return `visited'.
1943 ;; Otherwise, return nil.
1945 (catch 'vc-locked-example
1948 (function (lambda (f)
1949 (and (vc-registered f)
1950 (if (vc-locking-user f) (throw 'vc-locked-example f)
1951 (if (get-file-buffer f) (setq status 'visited)))))))
1955 (defun vc-create-snapshot (name)
1956 "Make a snapshot called NAME.
1957 The snapshot is made from all registered files at or below the current
1958 directory. For each file, the version level of its latest
1959 version becomes part of the named configuration."
1960 (interactive "sNew snapshot name: ")
1961 (let ((result (vc-snapshot-precondition)))
1962 (if (stringp result)
1963 (error "File %s is locked" result)
1966 (function (lambda (f) (and
1968 (vc-backend-assign-name f name)))))
1972 (defun vc-retrieve-snapshot (name)
1973 "Retrieve the snapshot called NAME, or latest versions if NAME is empty.
1974 When retrieving a snapshot, there must not be any locked files at or below
1975 the current directory. If none are locked, all registered files are
1976 checked out (unlocked) at their version levels in the snapshot NAME.
1977 If NAME is the empty string, all registered files that are not currently
1978 locked are updated to the latest versions."
1979 (interactive "sSnapshot name to retrieve (default latest versions): ")
1980 (let ((update (yes-or-no-p "Update any affected buffers? ")))
1981 (if (string= name "")
1985 (function (lambda (f) (and
1987 (not (vc-locking-user f))
1989 (vc-backend-checkout f nil "")
1990 (if update (vc-resynch-buffer f t t))))))))
1991 (let ((result (vc-snapshot-precondition)))
1992 (if (stringp result)
1993 (error "File %s is locked" result)
1994 (setq update (and (eq result 'visited) update))
1997 (function (lambda (f) (and
2000 (vc-backend-checkout f nil name)
2001 (if update (vc-resynch-buffer f t t)))))))
2004 ;; Miscellaneous other entry points
2007 (defun vc-print-log ()
2008 "List the change log of the current buffer in a window."
2010 (vc-ensure-vc-buffer)
2011 (let ((file buffer-file-name))
2012 (vc-backend-print-log file)
2013 (pop-to-buffer (get-buffer-create "*vc*"))
2014 (setq default-directory (file-name-directory file))
2015 (goto-char (point-max)) (forward-line -1)
2016 (while (looking-at "=*\n")
2017 (delete-char (- (match-end 0) (match-beginning 0)))
2019 (goto-char (point-min))
2020 (if (looking-at "[\b\t\n\v\f\r ]+")
2021 (delete-char (- (match-end 0) (match-beginning 0))))
2022 (shrink-window-if-larger-than-buffer)
2023 ;; move point to the log entry for the current version
2024 (and (not (eq (vc-backend file) 'SCCS))
2026 ;; also match some context, for safety
2027 (concat "----\nrevision " (vc-workfile-version file)
2028 "\\(\tlocked by:.*\n\\|\n\\)date: ") nil t)
2029 ;; set the display window so that
2030 ;; the whole log entry is displayed
2031 (let (start end lines)
2032 (beginning-of-line) (forward-line -1) (setq start (point))
2033 (if (not (re-search-forward "^----*\nrevision" nil t))
2034 (setq end (point-max))
2035 (beginning-of-line) (forward-line -1) (setq end (point)))
2036 (setq lines (count-lines start end))
2038 ;; if the global information and this log entry fit
2039 ;; into the window, display from the beginning
2040 ((< (count-lines (point-min) end) (window-height))
2041 (goto-char (point-min))
2044 ;; if the whole entry fits into the window,
2045 ;; display it centered
2046 ((< (1+ lines) (window-height))
2048 (recenter (1- (- (/ (window-height) 2) (/ lines 2)))))
2049 ;; otherwise (the entry is too large for the window),
2050 ;; display from the start
2056 (defun vc-revert-buffer ()
2057 "Revert the current buffer's file back to the version it was based on.
2058 This asks for confirmation if the buffer contents are not identical
2059 to that version. Note that for RCS and CVS, this function does not
2060 automatically pick up newer changes found in the master file;
2061 use C-u \\[vc-next-action] RET to do so."
2063 (vc-ensure-vc-buffer)
2064 (let ((file buffer-file-name)
2065 ;; This operation should always ask for confirmation.
2066 (vc-suppress-confirm nil)
2067 (obuf (current-buffer)) (changed (vc-diff nil t)))
2070 (if (not (yes-or-no-p "Discard changes? "))
2071 (error "Revert cancelled"))
2072 (if (and (window-dedicated-p (selected-window))
2073 (one-window-p t 'selected-frame))
2074 (make-frame-invisible (selected-frame))
2077 (vc-backend-revert file)
2078 (vc-resynch-window file t t)))
2081 (defun vc-cancel-version (norevert)
2082 "Get rid of most recently checked in version of this file.
2083 A prefix argument means do not revert the buffer afterwards."
2085 (vc-ensure-vc-buffer)
2087 ((eq (vc-backend (buffer-file-name)) 'CVS)
2088 (error "Unchecking files under CVS is dangerous and not supported in VC"))
2089 ((vc-locking-user (buffer-file-name))
2090 (error "This version is locked; use vc-revert-buffer to discard changes"))
2091 ((not (vc-latest-on-branch-p (buffer-file-name)))
2092 (error "This is not the latest version--VC cannot cancel it")))
2093 (let* ((target (vc-workfile-version (buffer-file-name)))
2094 (recent (if (vc-trunk-p target) "" (vc-branch-part target)))
2095 (config (current-window-configuration)) done)
2096 (if (null (yes-or-no-p (format "Remove version %s from master? " target)))
2098 (setq norevert (or norevert (not
2099 (yes-or-no-p "Revert buffer to most recent remaining version? "))))
2100 (vc-backend-uncheck (buffer-file-name) target)
2101 ;; Check out the most recent remaining version. If it fails, because
2102 ;; the whole branch got deleted, do a double-take and check out the
2103 ;; version where the branch started.
2108 ;; Check out locked, but only to disc, and keep
2109 ;; modifications in the buffer.
2110 (vc-backend-checkout (buffer-file-name) t recent)
2111 ;; Check out unlocked, and revert buffer.
2112 (vc-checkout (buffer-file-name) nil recent))
2114 ;; If the checkout fails, vc-do-command signals an error.
2115 ;; We catch this error, check the reason, correct the
2116 ;; version number, and try a second time.
2117 (error (set-buffer "*vc*")
2118 (goto-char (point-min))
2119 (if (search-forward "no side branches present for" nil t)
2120 (progn (setq recent (vc-branch-part recent))
2121 ;; vc-do-command popped up a window with
2122 ;; the error message. Get rid of it, by
2123 ;; restoring the old window configuration.
2124 (set-window-configuration config))
2125 ;; No, it was some other error: re-signal it.
2126 (signal (car err) (cdr err))))))
2127 ;; If norevert, clear version headers and mark the buffer modified.
2130 (set-visited-file-name (buffer-file-name))
2131 (if (not vc-make-backup-files)
2132 ;; inhibit backup for this buffer
2133 (progn (make-local-variable 'backup-inhibited)
2134 (setq backup-inhibited t)))
2135 (if (eq (vc-backend (buffer-file-name)) 'RCS)
2136 (progn (setq buffer-read-only nil)
2137 (vc-clear-headers)))
2138 (vc-mode-line (buffer-file-name))))
2139 (message "Version %s has been removed from the master" target)
2143 (defun vc-rename-file (old new)
2144 "Rename file OLD to NEW, and rename its master file likewise."
2145 (interactive "fVC rename file: \nFRename to: ")
2146 ;; There are several ways of renaming files under CVS 1.3, but they all
2147 ;; have serious disadvantages. See the FAQ (available from think.com in
2148 ;; pub/cvs/). I'd rather send the user an error, than do something he might
2149 ;; consider to be wrong. When the famous, long-awaited rename database is
2150 ;; implemented things might change for the better. This is unlikely to occur
2151 ;; until CVS 2.0 is released. --ceder 1994-01-23 21:27:51
2152 (if (eq (vc-backend old) 'CVS)
2153 (error "Renaming files under CVS is dangerous and not supported in VC"))
2154 (let ((oldbuf (get-file-buffer old)))
2155 (if (and oldbuf (buffer-modified-p oldbuf))
2156 (error "Please save files before moving them"))
2157 (if (get-file-buffer new)
2158 (error "Already editing new file name"))
2159 (if (file-exists-p new)
2160 (error "New file already exists"))
2161 (let ((oldmaster (vc-name old)) newmaster)
2164 (if (vc-locking-user old)
2165 (error "Please check in files before moving them"))
2166 (if (or (file-symlink-p oldmaster)
2167 ;; This had FILE, I changed it to OLD. -- rms.
2168 (file-symlink-p (vc-backend-subdirectory-name old)))
2169 (error "This is not a safe thing to do in the presence of symbolic links"))
2171 (let ((backend (vc-backend old))
2172 (newdir (or (file-name-directory new) ""))
2173 (newbase (file-name-nondirectory new)))
2178 (if (eq backend (cdr s))
2179 (let* ((newmaster (format (car s) newdir newbase))
2180 (newmasterdir (file-name-directory newmaster)))
2181 (if (or (not newmasterdir)
2182 (file-directory-p newmasterdir))
2183 (throw 'found newmaster))))))
2184 vc-master-templates)
2185 (error "New file lacks a version control directory"))))
2186 ;; Handle the SCCS PROJECTDIR feature. It is odd that this
2187 ;; is a special case, but a more elegant solution would require
2188 ;; significant changes in other parts of VC.
2189 (if (eq (vc-backend old) 'SCCS)
2190 (let ((project-dir (vc-sccs-project-dir)))
2194 (file-name-nondirectory newmaster))))))
2195 (rename-file oldmaster newmaster)))
2196 (if (or (not oldmaster) (file-exists-p old))
2197 (rename-file old new)))
2198 ; ?? Renaming a file might change its contents due to keyword expansion.
2199 ; We should really check out a new copy if the old copy was precisely equal
2200 ; to some checked in version. However, testing for this is tricky....
2204 (let ((buffer-read-only buffer-read-only))
2205 (set-visited-file-name new))
2208 (set-buffer-modified-p nil))))
2209 ;; This had FILE, I changed it to OLD. -- rms.
2210 (vc-backend-dispatch old
2211 (vc-record-rename old new) ;SCCS
2218 (defun vc-update-change-log (&rest args)
2219 "Find change log file and add entries from recent RCS/CVS logs.
2220 Normally, find log entries for all registered files in the default
2221 directory using `rcs2log', which finds CVS logs preferentially.
2222 The mark is left at the end of the text prepended to the change log.
2224 With prefix arg of C-u, only find log entries for the current buffer's file.
2226 With any numeric prefix arg, find log entries for all currently visited
2227 files that are under version control. This puts all the entries in the
2228 log for the default directory, which may not be appropriate.
2230 From a program, any arguments are assumed to be filenames and are
2231 passed to the `rcs2log' script after massaging to be relative to the
2234 (cond ((consp current-prefix-arg) ;C-u
2235 (list buffer-file-name))
2236 (current-prefix-arg ;Numeric argument.
2238 (buffers (buffer-list))
2241 (setq file (buffer-file-name (car buffers)))
2242 (and file (vc-backend file)
2243 (setq files (cons file files)))
2244 (setq buffers (cdr buffers)))
2247 ;; `rcs2log' will find the relevant RCS or CVS files
2248 ;; relative to the curent directory if none supplied.
2250 (let ((odefault default-directory)
2251 (changelog (find-change-log))
2252 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
2253 (tempfile (make-temp-name
2254 (expand-file-name "vc" temporary-file-directory)))
2255 (full-name (or add-log-full-name
2258 (format "uid%d" (number-to-string (user-uid)))))
2259 (mailing-address (or add-log-mailing-address
2260 user-mail-address)))
2261 (find-file-other-window changelog)
2262 (barf-if-buffer-read-only)
2265 (goto-char (point-min))
2267 (message "Computing change log entries...")
2268 (message "Computing change log entries... %s"
2272 (if (eq 0 (apply 'call-process "rcs2log" nil
2273 (list t tempfile) nil
2275 "-u" (concat (vc-user-login-name)
2277 "\t" mailing-address)
2282 (if (file-name-absolute-p f)
2284 (concat odefault f)))))
2288 (set-buffer (get-buffer-create "*vc*")))
2290 (insert-file tempfile)
2292 (cd (file-name-directory changelog))
2293 (delete-file tempfile)))))
2295 ;; vc-annotate functionality (CVS only).
2296 (defvar vc-annotate-mode-map nil
2297 "Local keymap used for VC-Annotate mode.")
2299 (defvar vc-annotate-mode-menu nil
2300 "Local keymap used for VC-Annotate mode's menu bar menu.")
2303 (defvar vc-annotate-mode-syntax-table nil
2304 "Syntax table used in VC-Annotate mode buffers.")
2306 ;; Declare globally instead of additional parameter to
2307 ;; temp-buffer-show-function (not possible to pass more than one
2309 (defvar vc-annotate-ratio nil)
2311 (defun vc-annotate-mode-variables ()
2312 (if (not vc-annotate-mode-syntax-table)
2313 (progn (setq vc-annotate-mode-syntax-table (make-syntax-table))
2314 (set-syntax-table vc-annotate-mode-syntax-table)))
2315 (if (not vc-annotate-mode-map)
2316 (setq vc-annotate-mode-map (make-sparse-keymap)))
2317 (setq vc-annotate-mode-menu (make-sparse-keymap "Annotate"))
2318 (define-key vc-annotate-mode-map [menu-bar]
2319 (make-sparse-keymap "VC-Annotate"))
2320 (define-key vc-annotate-mode-map [menu-bar vc-annotate-mode]
2321 (cons "VC-Annotate" vc-annotate-mode-menu)))
2323 (defun vc-annotate-mode ()
2324 "Major mode for buffers displaying output from the CVS `annotate' command.
2326 You can use the mode-specific menu to alter the time-span of the used
2327 colors. See variable `vc-annotate-menu-elements' for customizing the
2330 (kill-all-local-variables) ; Recommended by RMS.
2331 (vc-annotate-mode-variables) ; This defines various variables.
2332 (use-local-map vc-annotate-mode-map) ; This provides the local keymap.
2333 (set-syntax-table vc-annotate-mode-syntax-table)
2334 (setq major-mode 'vc-annotate-mode) ; This is how `describe-mode'
2335 ; finds out what to describe.
2336 (setq mode-name "Annotate") ; This goes into the mode line.
2337 (run-hooks 'vc-annotate-mode-hook)
2338 (vc-annotate-add-menu))
2340 (defun vc-annotate-display-default (&optional event)
2341 "Use the default color spectrum for VC Annotate mode."
2343 (message "Redisplaying annotation...")
2344 (vc-annotate-display (get-buffer (buffer-name)))
2345 (message "Redisplaying annotation...done"))
2347 (defun vc-annotate-add-menu ()
2348 "Adds the menu 'Annotate' to the menu bar in VC-Annotate mode."
2349 (define-key vc-annotate-mode-menu [default]
2350 '("Default" . vc-annotate-display-default))
2351 (let ((menu-elements vc-annotate-menu-elements))
2352 (while menu-elements
2353 (let* ((element (car menu-elements))
2354 (days (round (* element
2355 (vc-annotate-car-last-cons vc-annotate-color-map)
2357 (setq menu-elements (cdr menu-elements))
2358 (define-key vc-annotate-mode-menu
2360 (cons (format "Span %d days"
2363 ,(format "Use colors spanning %d days" days)
2365 (message "Redisplaying annotation...")
2366 (vc-annotate-display
2367 (get-buffer (buffer-name))
2368 (vc-annotate-time-span vc-annotate-color-map ,element))
2369 (message "Redisplaying annotation...done"))))))))
2372 (defun vc-annotate (ratio)
2373 "Display the result of the CVS `annotate' command using colors.
2374 New lines are displayed in red, old in blue.
2375 A prefix argument specifies a factor for stretching the time scale.
2377 `vc-annotate-menu-elements' customizes the menu elements of the
2378 mode-specific menu. `vc-annotate-color-map' and
2379 `vc-annotate-very-old-color' defines the mapping of time to
2380 colors. `vc-annotate-background' specifies the background color."
2382 (vc-ensure-vc-buffer)
2383 (if (not (eq (vc-backend (buffer-file-name)) 'CVS))
2384 (error "Sorry, vc-annotate is only implemented for CVS"))
2385 (message "Annotating...")
2386 (let ((temp-buffer-name (concat "*cvs annotate " (buffer-name) "*"))
2387 (temp-buffer-show-function 'vc-annotate-display)
2388 (vc-annotate-ratio ratio))
2389 (with-output-to-temp-buffer temp-buffer-name
2390 (call-process "cvs" nil (get-buffer temp-buffer-name) nil
2391 "annotate" (file-name-nondirectory (buffer-file-name)))))
2392 (message "Annotating... done"))
2394 (defun vc-annotate-car-last-cons (a-list)
2395 "Return car of last cons in association list A-LIST."
2396 (if (not (eq nil (cdr a-list)))
2397 (vc-annotate-car-last-cons (cdr a-list))
2398 (car (car a-list))))
2400 (defun vc-annotate-time-span (a-list span &optional quantize)
2401 "Return an association list with factor SPAN applied to the time-span
2402 of association list A-LIST. Optionaly quantize to the factor of
2404 ;; Apply span to each car of every cons
2405 (if (not (eq nil a-list))
2406 (append (list (cons (* (car (car a-list)) span)
2407 (cdr (car a-list))))
2408 (vc-annotate-time-span (nthcdr (cond (quantize) ; optional
2409 (1)) ; Default to cdr
2410 a-list) span quantize))))
2412 (defun vc-annotate-compcar (threshold a-list)
2413 "Test successive cons cells of association list A-LIST against
2414 THRESHOLD. Return the first cons cell which car is not less than
2415 THRESHOLD, nil otherwise"
2417 (tmp-cons (car a-list)))
2418 (while (and tmp-cons (< (car tmp-cons) threshold))
2419 (setq tmp-cons (car (nthcdr i a-list)))
2421 tmp-cons)) ; Return the appropriate value
2424 (defun vc-annotate-display (buffer &optional color-map)
2425 "Do the VC-Annotate display in BUFFER using COLOR-MAP."
2427 ;; Handle the case of the global variable vc-annotate-ratio being
2428 ;; set. This variable is used to pass information from function
2429 ;; vc-annotate since it is not possible to use another parameter
2430 ;; (see temp-buffer-show-function).
2431 (if (and (not color-map) vc-annotate-ratio)
2432 ;; This will only be true if called from vc-annotate with ratio
2434 (setq color-map (vc-annotate-time-span vc-annotate-color-map
2435 vc-annotate-ratio)))
2437 ;; We need a list of months and their corresponding numbers.
2438 (let* ((local-month-numbers
2439 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4)
2440 ("May" . 5) ("Jun" . 6) ("Jul" . 7) ("Aug" . 8)
2441 ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12))))
2443 (display-buffer buffer)
2444 (or (eq major-mode 'vc-annotate-mode) ; Turn on vc-annotate-mode if not done
2446 ;; Delete old overlays
2449 (if (overlay-get overlay 'vc-annotation)
2450 (delete-overlay overlay)))
2451 (overlays-in (point-min) (point-max)))
2452 (goto-char (point-min)) ; Position at the top of the buffer.
2453 (while (re-search-forward
2454 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): "
2455 ;; "^[0-9]+\\(\.[0-9]+\\)*\\s-+(\\sw+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): "
2458 (let* (;; Unfortunately, order is important. match-string will
2459 ;; be corrupted by extent functions in XEmacs. Access
2460 ;; string-matches first.
2461 (day (string-to-number (match-string 1)))
2462 (month (cdr (assoc (match-string 2) local-month-numbers)))
2463 (year-tmp (string-to-number (match-string 3)))
2464 (year (+ (if (> 100 year-tmp) 1900 0) year-tmp)) ; Possible millenium problem
2465 (high (- (car (current-time))
2466 (car (encode-time 0 0 0 day month year))))
2467 (color (cond ((vc-annotate-compcar high (cond (color-map)
2468 (vc-annotate-color-map))))
2469 ((cons nil vc-annotate-very-old-color))))
2470 ;; substring from index 1 to remove any leading `#' in the name
2471 (face-name (concat "vc-annotate-face-" (substring (cdr color) 1)))
2472 ;; Make the face if not done.
2473 (face (cond ((intern-soft face-name))
2474 ((let ((tmp-face (make-face (intern face-name))))
2475 (set-face-foreground tmp-face (cdr color))
2476 (if vc-annotate-background
2477 (set-face-background tmp-face vc-annotate-background))
2478 tmp-face)))) ; Return the face
2483 (setq overlay (make-overlay point (point)))
2484 (overlay-put overlay 'face face)
2485 (overlay-put overlay 'vc-annotation t)))))
2488 ;; Collect back-end-dependent stuff here
2490 (defun vc-backend-admin (file &optional rev comment)
2491 ;; Register a file into the version-control system
2492 ;; Automatically retrieves a read-only version of the file with
2493 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
2494 ;; it deletes the workfile.
2495 (vc-file-clearprops file)
2496 (or vc-default-back-end
2497 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))
2498 (message "Registering %s..." file)
2500 (if (stringp vc-register-switches)
2501 (list vc-register-switches)
2502 vc-register-switches))
2506 ((file-exists-p (vc-backend-subdirectory-name)) vc-default-back-end)
2507 ((file-exists-p "RCS") 'RCS)
2508 ((file-exists-p "CVS") 'CVS)
2509 ((file-exists-p "SCCS") 'SCCS)
2510 ((setq project-dir (vc-sccs-project-dir)) 'SCCS)
2511 (t vc-default-back-end))))
2512 (cond ((eq backend 'SCCS)
2514 (if project-dir (concat project-dir
2515 "s." (file-name-nondirectory file))
2517 (car (rassq 'SCCS vc-master-templates))
2518 (or (file-name-directory file) "")
2519 (file-name-nondirectory file)))))
2520 (apply 'vc-do-command nil 0 "admin" nil nil ;; SCCS
2521 (and rev (concat "-r" rev))
2524 (and comment (concat "-y" comment))
2528 (if vc-keep-workfiles
2529 (vc-do-command nil 0 "get" file 'MASTER)))
2531 (apply 'vc-do-command nil 0 "ci" file 'WORKFILE ;; RCS
2532 ;; if available, use the secure registering option
2533 (and (vc-backend-release-p 'RCS "5.6.4") "-i")
2534 (concat (if vc-keep-workfiles "-u" "-r") rev)
2535 (and comment (concat "-t-" comment))
2538 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE ;; CVS
2540 (and comment (string-match "[^\t\n ]" comment)
2541 (concat "-m" comment))
2544 (message "Registering %s...done" file)
2547 (defun vc-backend-checkout (file &optional writable rev workfile)
2548 ;; Retrieve a copy of a saved version into a workfile
2549 (let ((filename (or workfile file))
2550 (file-buffer (get-file-buffer file))
2552 (message "Checking out %s..." filename)
2554 ;; Change buffers to get local value of vc-checkout-switches.
2555 (if file-buffer (set-buffer file-buffer))
2556 (setq switches (if (stringp vc-checkout-switches)
2557 (list vc-checkout-switches)
2558 vc-checkout-switches))
2559 ;; Save this buffer's default-directory
2560 ;; and use save-excursion to make sure it is restored
2561 ;; in the same buffer it was saved in.
2562 (let ((default-directory default-directory))
2564 ;; Adjust the default-directory so that the check-out creates
2565 ;; the file in the right place.
2566 (setq default-directory (file-name-directory filename))
2567 (vc-backend-dispatch file
2569 (and rev (string= rev "") (setq rev nil))
2571 ;; Some SCCS implementations allow checking out directly to a
2572 ;; file using the -G option, but then some don't so use the
2573 ;; least common denominator approach and use the -p option
2575 (let ((vc-modes (logior (file-modes (vc-name file))
2576 (if writable 128 0)))
2580 (apply 'vc-do-command
2581 nil 0 "/bin/sh" file 'MASTER "-c"
2582 ;; Some shells make the "" dummy argument into $0
2583 ;; while others use the shell's name as $0 and
2584 ;; use the "" as $1. The if-statement
2585 ;; converts the latter case to the former.
2586 (format "if [ x\"$1\" = x ]; then shift; fi; \
2587 umask %o; exec >\"$1\" || exit; \
2588 shift; umask %o; exec get \"$@\""
2589 (logand 511 (lognot vc-modes))
2590 (logand 511 (lognot (default-file-modes))))
2591 "" ; dummy argument for shell's $0
2596 (concat "-r" (vc-lookup-triple file rev)))
2599 (and failed (file-exists-p filename)
2600 (delete-file filename))))
2601 (apply 'vc-do-command nil 0 "get" file 'MASTER ;; SCCS
2603 (and rev (concat "-r" (vc-lookup-triple file rev)))
2605 (vc-file-setprop file 'vc-workfile-version nil)))
2607 ;; RCS doesn't let us check out into arbitrary file names directly.
2608 ;; Use `co -p' and make stdout point to the correct file.
2609 (let ((vc-modes (logior (file-modes (vc-name file))
2610 (if writable 128 0)))
2614 (apply 'vc-do-command
2615 nil 0 "/bin/sh" file 'MASTER "-c"
2616 ;; See the SCCS case, above, regarding the
2618 (format "if [ x\"$1\" = x ]; then shift; fi; \
2619 umask %o; exec >\"$1\" || exit; \
2620 shift; umask %o; exec co \"$@\""
2621 (logand 511 (lognot vc-modes))
2622 (logand 511 (lognot (default-file-modes))))
2623 "" ; dummy argument for shell's $0
2629 (and failed (file-exists-p filename) (delete-file filename))))
2631 ;; if we should go to the head of the trunk,
2632 ;; clear the default branch first
2633 (and rev (string= rev "")
2634 (vc-do-command nil 0 "rcs" file 'MASTER "-b"))
2635 ;; now do the checkout
2636 (apply 'vc-do-command
2637 nil 0 "co" file 'MASTER
2638 ;; If locking is not strict, force to overwrite
2639 ;; the writable workfile.
2640 (if (eq (vc-checkout-model file) 'implicit) "-f")
2642 (if rev (concat "-r" rev)
2643 ;; if no explicit revision was specified,
2644 ;; check out that of the working file
2645 (let ((workrev (vc-workfile-version file)))
2646 (if workrev (concat "-r" workrev)
2649 ;; determine the new workfile version
2652 (goto-char (point-min))
2654 (if (re-search-forward "^revision \\([0-9.]+\\).*\n" nil t)
2655 (buffer-substring (match-beginning 1) (match-end 1)))))
2656 (vc-file-setprop file 'vc-workfile-version new-version)
2657 ;; if necessary, adjust the default branch
2658 (and rev (not (string= rev ""))
2659 (vc-do-command nil 0 "rcs" file 'MASTER
2660 (concat "-b" (if (vc-latest-on-branch-p file)
2661 (if (vc-trunk-p new-version) nil
2662 (vc-branch-part new-version))
2665 ;; CVS is much like RCS
2669 (apply 'vc-do-command
2670 nil 0 "/bin/sh" file 'WORKFILE "-c"
2671 "exec >\"$1\" || exit; shift; exec cvs update \"$@\""
2672 "" ; dummy argument for shell's $0
2678 (and failed (file-exists-p filename) (delete-file filename))))
2679 ;; default for verbose checkout: clear the sticky tag
2680 ;; so that the actual update will get the head of the trunk
2681 (and rev (string= rev "")
2682 (vc-do-command nil 0 "cvs" file 'WORKFILE "update" "-A"))
2683 ;; If a revision was specified, check that out.
2685 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE
2686 (and writable (eq (vc-checkout-model file) 'manual) "-w")
2688 (and rev (not (string= rev ""))
2691 ;; If no revision was specified, call "cvs edit" to make
2692 ;; the file writeable.
2693 (and writable (eq (vc-checkout-model file) 'manual)
2694 (vc-do-command nil 0 "cvs" file 'WORKFILE "edit")))
2695 (if rev (vc-file-setprop file 'vc-workfile-version nil))))
2698 (vc-file-clear-masterprops file)
2700 (vc-file-setprop file 'vc-locking-user (vc-user-login-name)))
2701 (vc-file-setprop file
2702 'vc-checkout-time (nth 5 (file-attributes file)))))
2703 (message "Checking out %s...done" filename))))))
2705 (defun vc-backend-logentry-check (file)
2706 (vc-backend-dispatch file
2707 (if (>= (buffer-size) 512) ;; SCCS
2711 "Log must be less than 512 characters; point is now at pos 512")))
2716 (defun vc-backend-checkin (file rev comment)
2717 ;; Register changes to FILE as level REV with explanatory COMMENT.
2718 ;; Automatically retrieves a read-only version of the file with
2719 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
2720 ;; it deletes the workfile.
2721 ;; Adaptation for RCS branch support: if this is an explicit checkin,
2722 ;; or if the checkin creates a new branch, set the master file branch
2724 (message "Checking in %s..." file)
2725 ;; "This log message intentionally left almost blank".
2726 ;; RCS 5.7 gripes about white-space-only comments too.
2727 (or (and comment (string-match "[^\t\n ]" comment))
2728 (setq comment "*** empty log message ***"))
2730 ;; Change buffers to get local value of vc-checkin-switches.
2731 (set-buffer (or (get-file-buffer file) (current-buffer)))
2733 (if (stringp vc-checkin-switches)
2734 (list vc-checkin-switches)
2735 vc-checkin-switches)))
2736 ;; Clear the master-properties. Do that here, not at the
2737 ;; end, because if the check-in fails we want them to get
2738 ;; re-computed before the next try.
2739 (vc-file-clear-masterprops file)
2740 (vc-backend-dispatch file
2743 (apply 'vc-do-command nil 0 "delta" file 'MASTER
2744 (if rev (concat "-r" rev))
2745 (concat "-y" comment)
2747 (vc-file-setprop file 'vc-locking-user 'none)
2748 (vc-file-setprop file 'vc-workfile-version nil)
2749 (if vc-keep-workfiles
2750 (vc-do-command nil 0 "get" file 'MASTER))
2753 (let ((old-version (vc-workfile-version file)) new-version)
2754 (apply 'vc-do-command nil 0 "ci" file 'MASTER
2755 ;; if available, use the secure check-in option
2756 (and (vc-backend-release-p 'RCS "5.6.4") "-j")
2757 (concat (if vc-keep-workfiles "-u" "-r") rev)
2758 (concat "-m" comment)
2760 (vc-file-setprop file 'vc-locking-user 'none)
2761 (vc-file-setprop file 'vc-workfile-version nil)
2763 ;; determine the new workfile version
2765 (goto-char (point-min))
2766 (if (or (re-search-forward
2767 "new revision: \\([0-9.]+\\);" nil t)
2769 "reverting to previous revision \\([0-9.]+\\)" nil t))
2770 (progn (setq new-version (buffer-substring (match-beginning 1)
2772 (vc-file-setprop file 'vc-workfile-version new-version)))
2774 ;; if we got to a different branch, adjust the default
2775 ;; branch accordingly
2777 ((and old-version new-version
2778 (not (string= (vc-branch-part old-version)
2779 (vc-branch-part new-version))))
2780 (vc-do-command nil 0 "rcs" file 'MASTER
2781 (if (vc-trunk-p new-version) "-b"
2782 (concat "-b" (vc-branch-part new-version))))
2783 ;; If this is an old RCS release, we might have
2784 ;; to remove a remaining lock.
2785 (if (not (vc-backend-release-p 'RCS "5.6.2"))
2786 ;; exit status of 1 is also accepted.
2787 ;; It means that the lock was removed before.
2788 (vc-do-command nil 1 "rcs" file 'MASTER
2789 (concat "-u" old-version))))))
2792 ;; explicit check-in to the trunk requires a
2793 ;; double check-in (first unexplicit) (CVS-1.3)
2796 (if (and rev (vc-trunk-p rev))
2797 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE
2798 "ci" "-m" "intermediate"
2800 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE
2801 "ci" (if rev (concat "-r" rev))
2802 (concat "-m" comment)
2804 (error (if (eq (vc-cvs-status file) 'needs-merge)
2805 ;; The CVS output will be on top of this message.
2806 (error "Type C-x 0 C-x C-q to merge in changes")
2807 (error "Check-in failed"))))
2808 ;; determine and store the new workfile version
2810 (goto-char (point-min))
2811 (if (re-search-forward
2812 "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" nil t)
2813 (vc-file-setprop file 'vc-workfile-version
2814 (buffer-substring (match-beginning 2)
2816 (vc-file-setprop file 'vc-workfile-version nil))
2817 ;; if this was an explicit check-in, remove the sticky tag
2819 (vc-do-command nil 0 "cvs" file 'WORKFILE "update" "-A"))
2820 ;; Forget the checkout model, because we might have assumed
2821 ;; a wrong one when we found the file. After commit, we can
2822 ;; tell it from the permissions of the file
2823 ;; (see vc-checkout-model).
2824 (vc-file-setprop file 'vc-checkout-model nil)
2825 (vc-file-setprop file 'vc-locking-user 'none)
2826 (vc-file-setprop file 'vc-checkout-time
2827 (nth 5 (file-attributes file)))))))
2828 (message "Checking in %s...done" file))
2830 (defun vc-backend-revert (file)
2831 ;; Revert file to the version it was based on.
2832 (message "Reverting %s..." file)
2833 (vc-file-clear-masterprops file)
2834 (vc-backend-dispatch
2838 (vc-do-command nil 0 "unget" file 'MASTER nil)
2839 (vc-do-command nil 0 "get" file 'MASTER nil)
2840 ;; Checking out explicit versions is not supported under SCCS, yet.
2841 ;; We always "revert" to the latest version; therefore
2842 ;; vc-workfile-version is cleared here so that it gets recomputed.
2843 (vc-file-setprop file 'vc-workfile-version nil))
2845 (vc-do-command nil 0 "co" file 'MASTER
2846 "-f" (concat "-u" (vc-workfile-version file)))
2848 ;; Check out via standard output (caused by the final argument
2849 ;; FILE below), so that no sticky tag is set.
2850 (vc-backend-checkout file nil (vc-workfile-version file) file))
2851 (vc-file-setprop file 'vc-locking-user 'none)
2852 (vc-file-setprop file 'vc-checkout-time (nth 5 (file-attributes file)))
2853 (message "Reverting %s...done" file)
2856 (defun vc-backend-steal (file &optional rev)
2857 ;; Steal the lock on the current workfile. Needs RCS 5.6.2 or later for -M.
2858 (message "Stealing lock on %s..." file)
2859 (vc-backend-dispatch file
2861 (vc-do-command nil 0 "unget" file 'MASTER "-n" (if rev (concat "-r" rev)))
2862 (vc-do-command nil 0 "get" file 'MASTER "-g" (if rev (concat "-r" rev)))
2864 (vc-do-command nil 0 "rcs" file 'MASTER ;RCS
2865 "-M" (concat "-u" rev) (concat "-l" rev))
2866 (error "You cannot steal a CVS lock; there are no CVS locks to steal") ;CVS
2868 (vc-file-setprop file 'vc-locking-user (vc-user-login-name))
2869 (message "Stealing lock on %s...done" file)
2872 (defun vc-backend-uncheck (file target)
2873 ;; Undo the latest checkin.
2874 (message "Removing last change from %s..." file)
2875 (vc-backend-dispatch file
2876 (vc-do-command nil 0 "rmdel" file 'MASTER (concat "-r" target))
2877 (vc-do-command nil 0 "rcs" file 'MASTER (concat "-o" target))
2878 nil ;; this is never reached under CVS
2880 (message "Removing last change from %s...done" file)
2883 (defun vc-backend-print-log (file)
2884 ;; Get change log associated with FILE.
2885 (vc-backend-dispatch
2887 (vc-do-command nil 0 "prs" file 'MASTER)
2888 (vc-do-command nil 0 "rlog" file 'MASTER)
2889 (vc-do-command nil 0 "cvs" file 'WORKFILE "log")))
2891 (defun vc-backend-assign-name (file name)
2892 ;; Assign to a FILE's latest version a given NAME.
2893 (vc-backend-dispatch file
2894 (vc-add-triple name file (vc-latest-version file)) ;; SCCS
2895 (vc-do-command nil 0 "rcs" file 'MASTER (concat "-n" name ":")) ;; RCS
2896 (vc-do-command nil 0 "cvs" file 'WORKFILE "tag" name) ;; CVS
2900 (defun vc-backend-diff (file &optional oldvers newvers cmp)
2901 ;; Get a difference report between two versions of FILE.
2902 ;; Get only a brief comparison report if CMP, a difference report otherwise.
2903 (let ((backend (vc-backend file)) options status
2904 (diff-switches-list (if (listp diff-switches)
2906 (list diff-switches))))
2909 (setq oldvers (vc-lookup-triple file oldvers))
2910 (setq newvers (vc-lookup-triple file newvers))
2911 (setq options (append (list (and cmp "--brief") "-q"
2912 (and oldvers (concat "-r" oldvers))
2913 (and newvers (concat "-r" newvers)))
2914 (and (not cmp) diff-switches-list)))
2915 (apply 'vc-do-command "*vc-diff*" 1 "vcdiff" file 'MASTER options))
2917 (if (not oldvers) (setq oldvers (vc-workfile-version file)))
2918 ;; If we know that --brief is not supported, don't try it.
2919 (setq cmp (and cmp (not (eq vc-rcsdiff-knows-brief 'no))))
2920 (setq options (append (list (and cmp "--brief") "-q"
2921 (concat "-r" oldvers)
2922 (and newvers (concat "-r" newvers)))
2923 (and (not cmp) diff-switches-list)))
2924 (setq status (apply 'vc-do-command "*vc-diff*" 2
2925 "rcsdiff" file 'WORKFILE options))
2926 ;; If --brief didn't work, do a double-take and remember it
2930 (apply 'vc-do-command "*vc-diff*" 1 "rcsdiff" file 'WORKFILE
2931 (if cmp (cdr options) options))
2932 (if cmp (setq vc-rcsdiff-knows-brief 'no)))
2933 ;; If --brief DID work, remember that, too.
2934 (and cmp (not vc-rcsdiff-knows-brief)
2935 (setq vc-rcsdiff-knows-brief 'yes))
2937 ;; CVS is different.
2939 (if (string= (vc-workfile-version file) "0")
2940 ;; This file is added but not yet committed; there is no master file.
2941 (if (or oldvers newvers)
2942 (error "No revisions of %s exist" file)
2943 (if cmp 1 ;; file is added but not committed,
2944 ;; we regard this as "changed".
2945 ;; diff it against /dev/null.
2946 (apply 'vc-do-command
2947 "*vc-diff*" 1 "diff" file 'WORKFILE
2948 (append diff-switches-list '("/dev/null")))))
2949 ;; cmp is not yet implemented -- we always do a full diff.
2950 (apply 'vc-do-command
2951 "*vc-diff*" 1 "cvs" file 'WORKFILE "diff"
2952 (and oldvers (concat "-r" oldvers))
2953 (and newvers (concat "-r" newvers))
2954 diff-switches-list))))))
2956 (defun vc-backend-merge-news (file)
2957 ;; Merge in any new changes made to FILE.
2958 (message "Merging changes into %s..." file)
2960 (vc-backend-dispatch
2962 (error "vc-backend-merge-news not meaningful for SCCS files") ;SCCS
2963 (error "vc-backend-merge-news not meaningful for RCS files") ;RCS
2964 (save-excursion ; CVS
2965 (vc-file-clear-masterprops file)
2966 (vc-file-setprop file 'vc-workfile-version nil)
2967 (vc-file-setprop file 'vc-locking-user nil)
2968 (vc-file-setprop file 'vc-checkout-time nil)
2969 (vc-do-command nil 0 "cvs" file 'WORKFILE "update")
2970 ;; Analyze the merge result reported by CVS, and set
2971 ;; file properties accordingly.
2972 (set-buffer (get-buffer "*vc*"))
2973 (goto-char (point-min))
2974 ;; get new workfile version
2975 (if (re-search-forward (concat "^Merging differences between "
2976 "[01234567890.]* and "
2977 "\\([01234567890.]*\\) into")
2979 (vc-file-setprop file 'vc-workfile-version (match-string 1)))
2981 (if (re-search-forward
2982 (concat "^\\(\\([CMU]\\) \\)?"
2983 (regexp-quote (file-name-nondirectory file))
2984 "\\( already contains the differences between \\)?")
2987 ;; Merge successful, we are in sync with repository now
2988 ((or (string= (match-string 2) "U")
2989 (string= (match-string 2) "P")
2990 ;; Special case: file contents in sync with
2991 ;; repository anyhow:
2993 (vc-file-setprop file 'vc-locking-user 'none)
2994 (vc-file-setprop file 'vc-checkout-time
2995 (nth 5 (file-attributes file)))
2996 0) ;; indicate success to the caller
2997 ;; Merge successful, but our own changes are still in the file
2998 ((string= (match-string 2) "M")
2999 (vc-file-setprop file 'vc-locking-user (vc-file-owner file))
3000 (vc-file-setprop file 'vc-checkout-time 0)
3001 0) ;; indicate success to the caller
3002 ;; Conflicts detected!
3003 ((string= (match-string 2) "C")
3004 (vc-file-setprop file 'vc-locking-user (vc-file-owner file))
3005 (vc-file-setprop file 'vc-checkout-time 0)
3006 1) ;; signal the error to the caller
3008 (pop-to-buffer "*vc*")
3009 (error "Couldn't analyze cvs update result"))))
3010 (message "Merging changes into %s...done" file)))
3012 (defun vc-backend-merge (file first-version &optional second-version)
3013 ;; Merge the changes between FIRST-VERSION and SECOND-VERSION into
3014 ;; the current working copy of FILE. It is assumed that FILE is
3015 ;; locked and writable (vc-merge ensures this).
3016 (vc-backend-dispatch file
3018 (error "Sorry, merging is not implemented for SCCS")
3020 (vc-do-command nil 1 "rcsmerge" file 'MASTER
3021 "-kk" ;; ignore keyword conflicts
3022 (concat "-r" first-version)
3023 (if second-version (concat "-r" second-version)))
3026 (vc-do-command nil 0 "cvs" file 'WORKFILE
3028 (concat "-j" first-version)
3029 (concat "-j" second-version))
3031 (set-buffer (get-buffer "*vc*"))
3032 (goto-char (point-min))
3033 (if (re-search-forward "conflicts during merge" nil t)
3038 (defun vc-check-headers ()
3039 "Check if the current file has any headers in it."
3042 (goto-char (point-min))
3043 (vc-backend-dispatch buffer-file-name
3044 (re-search-forward "%[MIRLBSDHTEGUYFPQCZWA]%" nil t) ;; SCCS
3045 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t) ;; RCS
3046 'RCS ;; CVS works like RCS in this regard.
3050 ;; Back-end-dependent stuff ends here.
3052 ;; Set up key bindings for use while editing log messages
3054 (defun vc-log-mode (&optional file)
3055 "Minor mode for driving version-control tools.
3056 These bindings are added to the global keymap when you enter this mode:
3057 \\[vc-next-action] perform next logical version-control operation on current file
3058 \\[vc-register] register current file
3059 \\[vc-toggle-read-only] like next-action, but won't register files
3060 \\[vc-insert-headers] insert version-control headers in current file
3061 \\[vc-print-log] display change history of current file
3062 \\[vc-revert-buffer] revert buffer to latest version
3063 \\[vc-cancel-version] undo latest checkin
3064 \\[vc-diff] show diffs between file versions
3065 \\[vc-version-other-window] visit old version in another window
3066 \\[vc-directory] show all files locked by any user in or below .
3067 \\[vc-annotate] colorful display of the cvs annotate command
3068 \\[vc-update-change-log] add change log entry from recent checkins
3070 While you are entering a change log message for a version, the following
3071 additional bindings will be in effect.
3073 \\[vc-finish-logentry] proceed with check in, ending log message entry
3075 Whenever you do a checkin, your log comment is added to a ring of
3076 saved comments. These can be recalled as follows:
3078 \\[vc-next-comment] replace region with next message in comment ring
3079 \\[vc-previous-comment] replace region with previous message in comment ring
3080 \\[vc-comment-search-reverse] search backward for regexp in the comment ring
3081 \\[vc-comment-search-forward] search backward for regexp in the comment ring
3083 Entry to the change-log submode calls the value of text-mode-hook, then
3084 the value of vc-log-mode-hook.
3086 Global user options:
3087 vc-initial-comment If non-nil, require user to enter a change
3088 comment upon first checkin of the file.
3090 vc-keep-workfiles Non-nil value prevents workfiles from being
3091 deleted when changes are checked in
3093 vc-suppress-confirm Suppresses some confirmation prompts,
3094 notably for reversions.
3096 vc-header-alist Which keywords to insert when adding headers
3097 with \\[vc-insert-headers]. Defaults to
3098 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under
3101 vc-static-header-alist By default, version headers inserted in C files
3102 get stuffed in a static string area so that
3103 ident(RCS/CVS) or what(SCCS) can see them in
3104 the compiled object code. You can override
3105 this by setting this variable to nil, or change
3106 the header template by changing it.
3108 vc-command-messages if non-nil, display run messages from the
3109 actual version-control utilities (this is
3110 intended primarily for people hacking vc
3114 (set-syntax-table text-mode-syntax-table)
3115 (use-local-map vc-log-entry-mode)
3116 (setq local-abbrev-table text-mode-abbrev-table)
3117 (setq major-mode 'vc-log-mode)
3118 (setq mode-name "VC-Log")
3119 (make-local-variable 'vc-log-file)
3120 (setq vc-log-file file)
3121 (make-local-variable 'vc-log-version)
3122 (make-local-variable 'vc-comment-ring-index)
3123 (set-buffer-modified-p nil)
3124 (setq buffer-file-name nil)
3125 (run-hooks 'text-mode-hook 'vc-log-mode-hook)
3128 ;; Initialization code, to be done just once at load-time
3129 (if vc-log-entry-mode
3131 (setq vc-log-entry-mode (make-sparse-keymap))
3132 (define-key vc-log-entry-mode "\M-n" 'vc-next-comment)
3133 (define-key vc-log-entry-mode "\M-p" 'vc-previous-comment)
3134 (define-key vc-log-entry-mode "\M-r" 'vc-comment-search-reverse)
3135 (define-key vc-log-entry-mode "\M-s" 'vc-comment-search-forward)
3136 (define-key vc-log-entry-mode "\C-c\C-c" 'vc-finish-logentry)
3139 ;;; These things should probably be generally available
3141 (defun vc-file-tree-walk (dirname func &rest args)
3142 "Walk recursively through DIRNAME.
3143 Invoke FUNC f ARGS on each non-directory file f underneath it."
3144 (vc-file-tree-walk-internal (expand-file-name dirname) func args)
3145 (message "Traversing directory %s...done" dirname))
3147 (defun vc-file-tree-walk-internal (file func args)
3148 (if (not (file-directory-p file))
3149 (apply func file args)
3150 (message "Traversing directory %s..." (abbreviate-file-name file))
3151 (let ((dir (file-name-as-directory file)))
3155 (string-equal f ".")
3156 (string-equal f "..")
3157 (member f vc-directory-exclusion-list)
3158 (let ((dirf (concat dir f)))
3160 (file-symlink-p dirf) ;; Avoid possible loops
3161 (vc-file-tree-walk-internal dirf func args))))))
3162 (directory-files dir)))))
3166 ;;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
3168 ;;; These may be useful to anyone who has to debug or extend the package.
3169 ;;; (Note that this information corresponds to versions 5.x. Some of it
3170 ;;; might have been invalidated by the additions to support branching
3171 ;;; and RCS keyword lookup. AS, 1995/03/24)
3173 ;;; A fundamental problem in VC is that there are time windows between
3174 ;;; vc-next-action's computations of the file's version-control state and
3175 ;;; the actions that change it. This is a window open to lossage in a
3176 ;;; multi-user environment; someone else could nip in and change the state
3177 ;;; of the master during it.
3179 ;;; The performance problem is that rlog/prs calls are very expensive; we want
3180 ;;; to avoid them as much as possible.
3184 ;;; The performance problem, it turns out, simplifies in practice to the
3185 ;;; problem of making vc-locking-user fast. The two other functions that call
3186 ;;; prs/rlog will not be so commonly used that the slowdown is a problem; one
3187 ;;; makes snapshots, the other deletes the calling user's last change in the
3190 ;;; The race condition implies that we have to either (a) lock the master
3191 ;;; during the entire execution of vc-next-action, or (b) detect and
3192 ;;; recover from errors resulting from dispatch on an out-of-date state.
3194 ;;; Alternative (a) appears to be infeasible. The problem is that we can't
3195 ;;; guarantee that the lock will ever be removed. Suppose a user starts a
3196 ;;; checkin, the change message buffer pops up, and the user, having wandered
3197 ;;; off to do something else, simply forgets about it?
3199 ;;; Alternative (b), on the other hand, works well with a cheap way to speed up
3200 ;;; vc-locking-user. Usually, if a file is registered, we can read its locked/
3201 ;;; unlocked state and its current owner from its permissions.
3203 ;;; This shortcut will fail if someone has manually changed the workfile's
3204 ;;; permissions; also if developers are munging the workfile in several
3205 ;;; directories, with symlinks to a master (in this latter case, the
3206 ;;; permissions shortcut will fail to detect a lock asserted from another
3209 ;;; Note that these cases correspond exactly to the errors which could happen
3210 ;;; because of a competing checkin/checkout race in between two instances of
3213 ;;; For VC's purposes, a workfile/master pair may have the following states:
3215 ;;; A. Unregistered. There is a workfile, there is no master.
3217 ;;; B. Registered and not locked by anyone.
3219 ;;; C. Locked by calling user and unchanged.
3221 ;;; D. Locked by the calling user and changed.
3223 ;;; E. Locked by someone other than the calling user.
3225 ;;; This makes for 25 states and 20 error conditions. Here's the matrix:
3227 ;;; VC's idea of state
3229 ;;; V Actual state RCS action SCCS action Effect
3231 ;;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
3232 ;;; B 5 . 6 7 8 co -l get -e checkout
3233 ;;; C 9 10 . 11 12 co -u unget; get revert
3234 ;;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
3235 ;;; E 17 18 19 20 . rcs -u -M -l unget -n ; get -g steal lock
3237 ;;; All commands take the master file name as a last argument (not shown).
3239 ;;; In the discussion below, a "self-race" is a pathological situation in
3240 ;;; which VC operations are being attempted simultaneously by two or more
3241 ;;; Emacsen running under the same username.
3243 ;;; The vc-next-action code has the following windows:
3246 ;;; Between the check for existence of a master file and the call to
3247 ;;; admin/checkin in vc-buffer-admin (apparent state A). This window may
3248 ;;; never close if the initial-comment feature is on.
3251 ;;; Between the call to vc-workfile-unchanged-p in and the immediately
3252 ;;; following revert (apparent state C).
3255 ;;; Between the call to vc-workfile-unchanged-p in and the following
3256 ;;; checkin (apparent state D). This window may never close.
3259 ;;; Between the unlock and the immediately following checkout during a
3260 ;;; revert operation (apparent state C). Included in window Q.
3263 ;;; Between vc-locking-user and the following checkout (apparent state B).
3266 ;;; Between vc-locking-user and the following revert (apparent state C).
3267 ;;; Includes windows Q and S.
3270 ;;; Between vc-locking-user and the following checkin (apparent state
3271 ;;; D). This window may never be closed if the user fails to complete the
3272 ;;; checkin message. Includes window R.
3275 ;;; Between vc-locking-user and the following steal-lock (apparent
3276 ;;; state E). This window may never close if the user fails to complete
3277 ;;; the steal-lock message. Includes window X.
3280 ;;; Between the unlock and the immediately following re-lock during a
3281 ;;; steal-lock operation (apparent state E). This window may never cloce
3282 ;;; if the user fails to complete the steal-lock message.
3286 ;;; Apparent state A ---
3288 ;;; 1. File looked unregistered but is actually registered and not locked.
3290 ;;; Potential cause: someone else's admin during window P, with
3291 ;;; caller's admin happening before their checkout.
3293 ;;; RCS: Prior to version 5.6.4, ci fails with message
3294 ;;; "no lock set by <user>". From 5.6.4 onwards, VC uses the new
3295 ;;; ci -i option and the message is "<file>,v: already exists".
3296 ;;; SCCS: admin will fail with error (ad19).
3298 ;;; We can let these errors be passed up to the user.
3300 ;;; 2. File looked unregistered but is actually locked by caller, unchanged.
3302 ;;; Potential cause: self-race during window P.
3304 ;;; RCS: Prior to version 5.6.4, reverts the file to the last saved
3305 ;;; version and unlocks it. From 5.6.4 onwards, VC uses the new
3306 ;;; ci -i option, failing with message "<file>,v: already exists".
3307 ;;; SCCS: will fail with error (ad19).
3309 ;;; Either of these consequences is acceptable.
3311 ;;; 3. File looked unregistered but is actually locked by caller, changed.
3313 ;;; Potential cause: self-race during window P.
3315 ;;; RCS: Prior to version 5.6.4, VC registers the caller's workfile as
3316 ;;; a delta with a null change comment (the -t- switch will be
3317 ;;; ignored). From 5.6.4 onwards, VC uses the new ci -i option,
3318 ;;; failing with message "<file>,v: already exists".
3319 ;;; SCCS: will fail with error (ad19).
3321 ;;; 4. File looked unregistered but is locked by someone else.
3323 ;;; Potential cause: someone else's admin during window P, with
3324 ;;; caller's admin happening *after* their checkout.
3326 ;;; RCS: Prior to version 5.6.4, ci fails with a
3327 ;;; "no lock set by <user>" message. From 5.6.4 onwards,
3328 ;;; VC uses the new ci -i option, failing with message
3329 ;;; "<file>,v: already exists".
3330 ;;; SCCS: will fail with error (ad19).
3332 ;;; We can let these errors be passed up to the user.
3334 ;;; Apparent state B ---
3336 ;;; 5. File looked registered and not locked, but is actually unregistered.
3338 ;;; Potential cause: master file got nuked during window P.
3340 ;;; RCS: will fail with "RCS/<file>: No such file or directory"
3341 ;;; SCCS: will fail with error ut4.
3343 ;;; We can let these errors be passed up to the user.
3345 ;;; 6. File looked registered and not locked, but is actually locked by the
3346 ;;; calling user and unchanged.
3348 ;;; Potential cause: self-race during window T.
3350 ;;; RCS: in the same directory as the previous workfile, co -l will fail
3351 ;;; with "co error: writable foo exists; checkout aborted". In any other
3352 ;;; directory, checkout will succeed.
3353 ;;; SCCS: will fail with ge17.
3355 ;;; Either of these consequences is acceptable.
3357 ;;; 7. File looked registered and not locked, but is actually locked by the
3358 ;;; calling user and changed.
3362 ;;; 8. File looked registered and not locked, but is actually locked by another
3365 ;;; Potential cause: someone else checks it out during window T.
3367 ;;; RCS: co error: revision 1.3 already locked by <user>
3368 ;;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
3370 ;;; We can let these errors be passed up to the user.
3372 ;;; Apparent state C ---
3374 ;;; 9. File looks locked by calling user and unchanged, but is unregistered.
3378 ;;; 10. File looks locked by calling user and unchanged, but is actually not
3381 ;;; Potential cause: a self-race in window U, or by the revert's
3382 ;;; landing during window X of some other user's steal-lock or window S
3383 ;;; of another user's revert.
3385 ;;; RCS: succeeds, refreshing the file from the identical version in
3387 ;;; SCCS: fails with error ut4 (p file nonexistent).
3389 ;;; Either of these consequences is acceptable.
3391 ;;; 11. File is locked by calling user. It looks unchanged, but is actually
3394 ;;; Potential cause: the file would have to be touched by a self-race
3395 ;;; during window Q.
3397 ;;; The revert will succeed, removing whatever changes came with
3398 ;;; the touch. It is theoretically possible that work could be lost.
3400 ;;; 12. File looks like it's locked by the calling user and unchanged, but
3401 ;;; it's actually locked by someone else.
3403 ;;; Potential cause: a steal-lock in window V.
3405 ;;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
3406 ;;; SCCS: fails with error un2
3408 ;;; We can pass these errors up to the user.
3410 ;;; Apparent state D ---
3412 ;;; 13. File looks like it's locked by the calling user and changed, but it's
3413 ;;; actually unregistered.
3415 ;;; Potential cause: master file got nuked during window P.
3417 ;;; RCS: Prior to version 5.6.4, checks in the user's version as an
3418 ;;; initial delta. From 5.6.4 onwards, VC uses the new ci -j
3419 ;;; option, failing with message "no such file or directory".
3420 ;;; SCCS: will fail with error ut4.
3422 ;;; This case is kind of nasty. Under RCS prior to version 5.6.4,
3423 ;;; VC may fail to detect the loss of previous version information.
3425 ;;; 14. File looks like it's locked by the calling user and changed, but it's
3426 ;;; actually unlocked.
3428 ;;; Potential cause: self-race in window V, or the checkin happening
3429 ;;; during the window X of someone else's steal-lock or window S of
3430 ;;; someone else's revert.
3432 ;;; RCS: ci will fail with "no lock set by <user>".
3433 ;;; SCCS: delta will fail with error ut4.
3435 ;;; 15. File looks like it's locked by the calling user and changed, but it's
3436 ;;; actually locked by the calling user and unchanged.
3438 ;;; Potential cause: another self-race --- a whole checkin/checkout
3439 ;;; sequence by the calling user would have to land in window R.
3441 ;;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
3442 ;;; RCS: reverts to the file state as of the second user's checkin, leaving
3443 ;;; the file unlocked.
3445 ;;; It is theoretically possible that work could be lost under RCS.
3447 ;;; 16. File looks like it's locked by the calling user and changed, but it's
3448 ;;; actually locked by a different user.
3450 ;;; RCS: ci error: no lock set by <user>
3451 ;;; SCCS: unget will fail with error un2
3453 ;;; We can pass these errors up to the user.
3455 ;;; Apparent state E ---
3457 ;;; 17. File looks like it's locked by some other user, but it's actually
3462 ;;; 18. File looks like it's locked by some other user, but it's actually
3465 ;;; Potential cause: someone released a lock during window W.
3467 ;;; RCS: The calling user will get the lock on the file.
3468 ;;; SCCS: unget -n will fail with cm4.
3470 ;;; Either of these consequences will be OK.
3472 ;;; 19. File looks like it's locked by some other user, but it's actually
3473 ;;; locked by the calling user and unchanged.
3475 ;;; Potential cause: the other user relinquishing a lock followed by
3476 ;;; a self-race, both in window W.
3478 ;;; Under both RCS and SCCS, both unlock and lock will succeed, making
3479 ;;; the sequence a no-op.
3481 ;;; 20. File looks like it's locked by some other user, but it's actually
3482 ;;; locked by the calling user and changed.
3488 ;;; In order of decreasing severity:
3490 ;;; Cases 11 and 15 are the only ones that potentially lose work.
3491 ;;; They would require a self-race for this to happen.
3493 ;;; Case 13 in RCS loses information about previous deltas, retaining
3494 ;;; only the information in the current workfile. This can only happen
3495 ;;; if the master file gets nuked in window P.
3497 ;;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
3498 ;;; no change comment in the master. This would require a self-race in
3499 ;;; window P or R respectively.
3501 ;;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
3503 ;;; Unfortunately, it appears to me that no recovery is possible in these
3504 ;;; cases. They don't yield error messages, so there's no way to tell that
3505 ;;; a race condition has occurred.
3507 ;;; All other cases don't change either the workfile or the master, and
3508 ;;; trigger command errors which the user will see.
3510 ;;; Thus, there is no explicit recovery code.