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.236 1998/08/04 13:14:41 spiegel Exp fx $
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
)
297 (defcustom vc-sccs-release nil
298 "*The release number of your SCCS installation, as a string.
299 If nil, VC itself computes this value when it is first needed."
300 :type
'(choice (const :tag
"Auto" nil
)
304 (defcustom vc-cvs-release nil
305 "*The release number of your CVS installation, as a string.
306 If nil, VC itself computes this value when it is first needed."
307 :type
'(choice (const :tag
"Auto" nil
)
311 ;; Variables the user doesn't need to know about.
312 (defvar vc-log-entry-mode nil
)
313 (defvar vc-log-operation nil
)
314 (defvar vc-log-after-operation-hook nil
)
315 (defvar vc-checkout-writable-buffer-hook
'vc-checkout-writable-buffer
)
316 ;; In a log entry buffer, this is a local variable
317 ;; that points to the buffer for which it was made
318 ;; (either a file, or a VC dired buffer).
319 (defvar vc-parent-buffer nil
)
320 (defvar vc-parent-buffer-name nil
)
323 (defvar vc-log-version
)
325 (defconst vc-name-assoc-file
"VC-names")
327 (defvar vc-dired-mode nil
)
328 (make-variable-buffer-local 'vc-dired-mode
)
330 (defvar vc-comment-ring
(make-ring vc-maximum-comment-ring-size
))
331 (defvar vc-comment-ring-index nil
)
332 (defvar vc-last-comment-match nil
)
334 ;;; Find and compare backend releases
336 (defun vc-backend-release (backend)
337 ;; Returns which backend release is installed on this system.
341 (and (zerop (vc-do-command nil nil
"rcs" nil nil
"-V"))
343 (set-buffer (get-buffer "*vc*"))
345 (car (vc-parse-buffer
346 '(("^RCS version \\([0-9.]+ *.*\\)" 1)))))))
347 (setq vc-rcs-release
'unknown
)))
350 (and (zerop (vc-do-command nil
1 "cvs" nil nil
"-v"))
352 (set-buffer (get-buffer "*vc*"))
354 (car (vc-parse-buffer
355 '(("^Concurrent Versions System (CVS) \\([0-9.]+\\)"
357 (setq vc-cvs-release
'unknown
)))
361 (defun vc-release-greater-or-equal (r1 r2
)
362 ;; Compare release numbers, represented as strings.
363 ;; Release components are assumed cardinal numbers, not decimal
364 ;; fractions (5.10 is a higher release than 5.9). Omitted fields
365 ;; are considered lower (5.6.7 is earlier than 5.6.7.1).
366 ;; Comparison runs till the end of the string is found, or a
367 ;; non-numeric component shows up (5.6.7 is earlier than "5.6.7 beta",
368 ;; which is probably not what you want in some cases).
369 ;; This code is suitable for existing RCS release numbers.
370 ;; CVS releases are handled reasonably, too (1.3 < 1.4* < 1.5).
373 (or (and (string-match "^\\.?\\([0-9]+\\)" r1
)
374 (setq i1
(match-end 0))
375 (setq v1
(string-to-number (match-string 1 r1
)))
376 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
377 (setq i2
(match-end 0))
378 (setq v2
(string-to-number (match-string 1 r2
)))
379 (if (> v1 v2
) (throw 'done t
)
380 (if (< v1 v2
) (throw 'done nil
)
382 (vc-release-greater-or-equal
384 (substring r2 i2
)))))))
386 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
390 (defun vc-backend-release-p (backend release
)
391 ;; Return t if we have RELEASE of BACKEND or better
392 (let (i r
(ri 0) (ii 0) is rs
(installation (vc-backend-release backend
)))
393 (if (not (eq installation
'unknown
))
395 ((or (eq backend
'RCS
) (eq backend
'CVS
))
396 (vc-release-greater-or-equal installation release
))))))
398 ;;; functions that operate on RCS revision numbers
400 (defun vc-trunk-p (rev)
401 ;; return t if REV is a revision on the trunk
402 (not (eq nil
(string-match "\\`[0-9]+\\.[0-9]+\\'" rev
))))
404 (defun vc-branch-p (rev)
405 ;; return t if REV is a branch revision
406 (not (eq nil
(string-match "\\`[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*\\'" rev
))))
408 (defun vc-branch-part (rev)
409 ;; return the branch part of a revision number REV
410 (substring rev
0 (string-match "\\.[0-9]+\\'" rev
)))
412 (defun vc-minor-part (rev)
413 ;; return the minor version number of a revision number REV
414 (string-match "[0-9]+\\'" rev
)
415 (substring rev
(match-beginning 0) (match-end 0)))
417 (defun vc-previous-version (rev)
418 ;; guess the previous version number
419 (let ((branch (vc-branch-part rev
))
420 (minor-num (string-to-number (vc-minor-part rev
))))
422 ;; version does probably not start a branch or release
423 (concat branch
"." (number-to-string (1- minor-num
)))
425 ;; we are at the beginning of the trunk --
426 ;; don't know anything to return here
428 ;; we are at the beginning of a branch --
429 ;; return version of starting point
430 (vc-branch-part branch
)))))
432 ;; File property caching
434 (defun vc-clear-context ()
435 "Clear all cached file properties and the comment ring."
437 (fillarray vc-file-prop-obarray nil
)
438 ;; Note: there is potential for minor lossage here if there is an open
439 ;; log buffer with a nonzero local value of vc-comment-ring-index.
440 (setq vc-comment-ring
(make-ring vc-maximum-comment-ring-size
)))
442 (defun vc-file-clear-masterprops (file)
443 ;; clear all properties of FILE that were retrieved
444 ;; from the master file
445 (vc-file-setprop file
'vc-latest-version nil
)
446 (vc-file-setprop file
'vc-your-latest-version nil
)
447 (vc-backend-dispatch file
449 (vc-file-setprop file
'vc-master-locks nil
))
451 (vc-file-setprop file
'vc-default-branch nil
)
452 (vc-file-setprop file
'vc-head-version nil
)
453 (vc-file-setprop file
'vc-master-workfile-version nil
)
454 (vc-file-setprop file
'vc-master-locks nil
))
456 (vc-file-setprop file
'vc-cvs-status nil
))))
458 (defun vc-head-version (file)
459 ;; Return the RCS head version of FILE
460 (cond ((vc-file-getprop file
'vc-head-version
))
461 (t (vc-fetch-master-properties file
)
462 (vc-file-getprop file
'vc-head-version
))))
464 ;; Random helper functions
466 (defun vc-latest-on-branch-p (file)
467 ;; return t iff the current workfile version of FILE is
468 ;; the latest on its branch.
469 (vc-backend-dispatch file
471 (string= (vc-workfile-version file
) (vc-latest-version file
))
473 (let ((workfile-version (vc-workfile-version file
)) tip-version
)
474 (if (vc-trunk-p workfile-version
)
476 ;; Re-fetch the head version number. This is to make
477 ;; sure that no-one has checked in a new version behind
479 (vc-fetch-master-properties file
)
480 (string= (vc-file-getprop file
'vc-head-version
)
482 ;; If we are not on the trunk, we need to examine the
483 ;; whole current branch. (vc-master-workfile-version
484 ;; is not what we need.)
486 (set-buffer (get-buffer-create "*vc-info*"))
487 (vc-insert-file (vc-name file
) "^desc")
488 (setq tip-version
(car (vc-parse-buffer (list (list
489 (concat "^\\(" (regexp-quote (vc-branch-part workfile-version
))
490 "\\.[0-9]+\\)\ndate[ \t]+\\([0-9.]+\\);") 1 2)))))
491 (if (get-buffer "*vc-info*")
492 (kill-buffer (get-buffer "*vc-info*")))
493 (string= tip-version workfile-version
))))
497 (defun vc-ensure-vc-buffer ()
498 ;; Make sure that the current buffer visits a version-controlled file.
500 (set-buffer (find-file-noselect (dired-get-filename)))
501 (while vc-parent-buffer
502 (pop-to-buffer vc-parent-buffer
))
503 (if (not (buffer-file-name))
504 (error "Buffer %s is not associated with a file" (buffer-name))
505 (if (not (vc-backend (buffer-file-name)))
506 (error "File %s is not under version control" (buffer-file-name))))))
508 (defvar vc-binary-assoc nil
)
509 (defvar vc-binary-suffixes
510 (if (memq system-type
'(ms-dos windows-nt
))
511 '(".exe" ".com" ".bat" ".cmd" ".btm" "")
513 (defun vc-find-binary (name)
514 "Look for a command anywhere on the subprocess-command search path."
515 (or (cdr (assoc name vc-binary-assoc
))
521 (let ((full (concat s
"/" name
))
522 (suffixes vc-binary-suffixes
)
525 (setq candidate
(concat full
(car suffixes
)))
526 (if (and (file-executable-p candidate
)
527 (not (file-directory-p candidate
)))
529 (setq vc-binary-assoc
530 (cons (cons name candidate
) vc-binary-assoc
))
531 (throw 'found candidate
))
532 (setq suffixes
(cdr suffixes
))))))))
536 (defun vc-do-command (buffer okstatus command file last
&rest flags
)
537 "Execute a version-control command, notifying user and checking for errors.
538 Output from COMMAND goes to BUFFER, or *vc* if BUFFER is nil. The
539 command is considered successful if its exit status does not exceed
540 OKSTATUS (if OKSTATUS is nil, that means to ignore errors). FILE is
541 the name of the working file (may also be nil, to execute commands
542 that don't expect a file name). If FILE is non-nil, the argument LAST
543 indicates what filename should actually be passed to the command: if
544 it is `MASTER', the name of FILE's master file is used, if it is
545 `WORKFILE', then FILE is passed through unchanged. If an optional
546 list of FLAGS is present, that is inserted into the command line
547 before the filename."
548 (and file
(setq file
(expand-file-name file
)))
549 (if (not buffer
) (setq buffer
"*vc*"))
550 (if vc-command-messages
551 (message "Running %s on %s..." command file
))
552 (let ((obuf (current-buffer)) (camefrom (current-buffer))
554 (olddir default-directory
)
556 (set-buffer (get-buffer-create buffer
))
557 (set (make-local-variable 'vc-parent-buffer
) camefrom
)
558 (set (make-local-variable 'vc-parent-buffer-name
)
559 (concat " from " (buffer-name camefrom
)))
560 (setq default-directory olddir
)
565 (function (lambda (s) (and s
(setq squeezed
(append squeezed
(list s
))))))
567 (if (and (eq last
'MASTER
) file
(setq vc-file
(vc-name file
)))
568 (setq squeezed
(append squeezed
(list vc-file
))))
569 (if (and file
(eq last
'WORKFILE
))
571 (let* ((pwd (expand-file-name default-directory
))
572 (preflen (length pwd
)))
573 (if (string= (substring file
0 preflen
) pwd
)
574 (setq file
(substring file preflen
))))
575 (setq squeezed
(append squeezed
(list file
)))))
576 (let ((exec-path (append vc-path exec-path
))
577 ;; Add vc-path to PATH for the execution of this command.
579 (cons (concat "PATH=" (getenv "PATH")
581 (mapconcat 'identity vc-path path-separator
))
582 process-environment
))
583 (w32-quote-process-args t
))
584 (setq status
(apply 'call-process command nil t nil squeezed
)))
585 (goto-char (point-max))
586 (set-buffer-modified-p nil
)
588 (if (or (not (integerp status
)) (and okstatus
(< okstatus status
)))
590 (pop-to-buffer buffer
)
591 (goto-char (point-min))
592 (shrink-window-if-larger-than-buffer)
593 (error "Running %s...FAILED (%s)" command
594 (if (integerp status
)
595 (format "status %d" status
)
598 (if vc-command-messages
599 (message "Running %s...OK" command
))
605 ;;; Save a bit of the text around POSN in the current buffer, to help
606 ;;; us find the corresponding position again later. This works even
607 ;;; if all markers are destroyed or corrupted.
608 ;;; A lot of this was shamelessly lifted from Sebastian Kremer's rcs.el mode.
609 (defun vc-position-context (posn)
612 (buffer-substring posn
613 (min (point-max) (+ posn
100)))))
615 ;;; Return the position of CONTEXT in the current buffer, or nil if we
616 ;;; couldn't find it.
617 (defun vc-find-position-by-context (context)
618 (let ((context-string (nth 2 context
)))
619 (if (equal "" context-string
)
622 (let ((diff (- (nth 1 context
) (buffer-size))))
623 (if (< diff
0) (setq diff
(- diff
)))
624 (goto-char (nth 0 context
))
625 (if (or (search-forward context-string nil t
)
626 ;; Can't use search-backward since the match may continue
628 (progn (goto-char (- (point) diff
(length context-string
)))
629 ;; goto-char doesn't signal an error at
630 ;; beginning of buffer like backward-char would
631 (search-forward context-string nil t
)))
632 ;; to beginning of OSTRING
633 (- (point) (length context-string
))))))))
635 (defun vc-context-matches-p (posn context
)
636 ;; Returns t if POSN matches CONTEXT, nil otherwise.
637 (let* ((context-string (nth 2 context
))
638 (len (length context-string
))
640 (if (> end
(1+ (buffer-size)))
642 (string= context-string
(buffer-substring posn end
)))))
644 (defun vc-buffer-context ()
645 ;; Return a list '(point-context mark-context reparse); from which
646 ;; vc-restore-buffer-context can later restore the context.
647 (let ((point-context (vc-position-context (point)))
648 ;; Use mark-marker to avoid confusion in transient-mark-mode.
649 (mark-context (if (eq (marker-buffer (mark-marker)) (current-buffer))
650 (vc-position-context (mark-marker))))
651 ;; Make the right thing happen in transient-mark-mode.
653 ;; We may want to reparse the compilation buffer after revert
654 (reparse (and (boundp 'compilation-error-list
) ;compile loaded
655 (let ((curbuf (current-buffer)))
656 ;; Construct a list; each elt is nil or a buffer
657 ;; iff that buffer is a compilation output buffer
658 ;; that contains markers into the current buffer.
664 compilation-old-error-list
665 compilation-error-list
))
666 (buffer-error-marked-p nil
))
667 (while (and (consp errors
)
668 (not buffer-error-marked-p
))
669 (and (markerp (cdr (car errors
)))
673 (setq buffer-error-marked-p t
))
674 (setq errors
(cdr errors
)))
675 (if buffer-error-marked-p buffer
))))
677 (list point-context mark-context reparse
)))
679 (defun vc-restore-buffer-context (context)
680 ;; Restore point/mark, and reparse any affected compilation buffers.
681 ;; CONTEXT is that which vc-buffer-context returns.
682 (let ((point-context (nth 0 context
))
683 (mark-context (nth 1 context
))
684 (reparse (nth 2 context
)))
685 ;; Reparse affected compilation buffers.
689 (set-buffer (car reparse
))
690 (let ((compilation-last-buffer (current-buffer)) ;select buffer
691 ;; Record the position in the compilation buffer of
692 ;; the last error next-error went to.
693 (error-pos (marker-position
694 (car (car-safe compilation-error-list
)))))
695 ;; Reparse the error messages as far as they were parsed before.
696 (compile-reinitialize-errors '(4) compilation-parsing-end
)
697 ;; Move the pointer up to find the error we were at before
698 ;; reparsing. Now next-error should properly go to the next one.
699 (while (and compilation-error-list
700 (/= error-pos
(car (car compilation-error-list
))))
701 (setq compilation-error-list
(cdr compilation-error-list
))))))
702 (setq reparse
(cdr reparse
)))
704 ;; if necessary, restore point and mark
705 (if (not (vc-context-matches-p (point) point-context
))
706 (let ((new-point (vc-find-position-by-context point-context
)))
707 (if new-point
(goto-char new-point
))))
710 (not (vc-context-matches-p (mark) mark-context
))
711 (let ((new-mark (vc-find-position-by-context mark-context
)))
712 (if new-mark
(set-mark new-mark
))))))
714 (defun vc-revert-buffer1 (&optional arg no-confirm
)
715 ;; Revert buffer, try to keep point and mark where user expects them in spite
716 ;; of changes because of expanded version-control key words.
717 ;; This is quite important since otherwise typeahead won't work as expected.
720 (let ((context (vc-buffer-context)))
721 ;; Use save-excursion here, because it may be able to restore point
722 ;; and mark properly even in cases where vc-restore-buffer-context
723 ;; would fail. However, save-excursion might also get it wrong --
724 ;; in this case, vc-restore-buffer-context gives it a second try.
726 ;; t means don't call normal-mode;
727 ;; that's to preserve various minor modes.
728 (revert-buffer arg no-confirm t
))
729 (vc-restore-buffer-context context
)))
732 (defun vc-buffer-sync (&optional not-urgent
)
733 ;; Make sure the current buffer and its working file are in sync
734 ;; NOT-URGENT means it is ok to continue if the user says not to save.
735 (if (buffer-modified-p)
736 (if (or vc-suppress-confirm
737 (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name))))
741 (error "Aborted")))))
744 (defun vc-workfile-unchanged-p (file &optional want-differences-if-changed
)
745 ;; Has the given workfile changed since last checkout?
746 (let ((checkout-time (vc-file-getprop file
'vc-checkout-time
))
747 (lastmod (nth 5 (file-attributes file
))))
748 (or (equal checkout-time lastmod
)
749 (and (or (not checkout-time
) want-differences-if-changed
)
750 (let ((unchanged (zerop (vc-backend-diff file nil nil
751 (not want-differences-if-changed
)))))
752 ;; 0 stands for an unknown time; it can't match any mod time.
753 (vc-file-setprop file
'vc-checkout-time
(if unchanged lastmod
0))
756 (defun vc-next-action-on-file (file verbose
&optional comment
)
757 ;;; If comment is specified, it will be used as an admin or checkin comment.
758 (let ((vc-type (vc-backend file
))
759 owner version buffer
)
762 ;; If the file is not under version control, register it
764 (vc-register verbose comment
))
766 ;; CVS: changes to the master file need to be
767 ;; merged back into the working file
768 ((and (eq vc-type
'CVS
)
769 (or (eq (vc-cvs-status file
) 'needs-checkout
)
770 (eq (vc-cvs-status file
) 'needs-merge
)))
771 (if (or vc-dired-mode
773 (format "%s is not up-to-date. Merge in changes now? "
777 (and (setq buffer
(get-file-buffer file
))
778 (buffer-modified-p buffer
)
779 (switch-to-buffer-other-window buffer
)
781 (setq buffer
(current-buffer))
783 (if (and buffer
(buffer-modified-p buffer
)
786 "Buffer %s modified; merge file on disc anyhow? "
787 (buffer-name buffer
)))))
788 (error "Merge aborted"))
789 (let ((status (vc-backend-merge-news file
)))
791 (vc-resynch-buffer file t
792 (not (buffer-modified-p buffer
))))
793 (if (not (zerop status
))
794 (if (y-or-n-p "Conflicts detected. Resolve them now? ")
795 (vc-resolve-conflicts)))))
796 (error "%s needs update" (buffer-name))))
798 ;; For CVS files with implicit checkout: if unmodified, don't do anything
799 ((and (eq vc-type
'CVS
)
800 (eq (vc-checkout-model file
) 'implicit
)
801 (not (vc-locking-user file
))
803 (message "%s is up to date" (buffer-name)))
805 ;; If there is no lock on the file, assert one and get it.
806 ((not (setq owner
(vc-locking-user file
)))
807 ;; With implicit checkout, make sure not to lose unsaved changes.
808 (and (eq (vc-checkout-model file
) 'implicit
)
809 (buffer-modified-p buffer
)
811 (if (and vc-checkout-carefully
812 (not (vc-workfile-unchanged-p file t
)))
813 (if (save-window-excursion
814 (pop-to-buffer "*vc-diff*")
815 (goto-char (point-min))
816 (insert-string (format "Changes to %s since last lock:\n\n"
820 (concat "File has unlocked changes, "
821 "claim lock retaining changes? ")))
822 (progn (vc-backend-steal file
)
824 (if (not (yes-or-no-p "Revert to checked-in version, instead? "))
825 (error "Checkout aborted")
826 (vc-revert-buffer1 t t
)
827 (vc-checkout-writable-buffer file
))
830 (if (not (eq vc-type
'SCCS
))
831 (vc-checkout file nil
832 (read-string "Branch or version to move to: "))
833 (error "Sorry, this is not implemented for SCCS"))
834 (if (vc-latest-on-branch-p file
)
835 (vc-checkout-writable-buffer file
)
837 "This is not the latest version. Really lock it? ")
838 (vc-checkout-writable-buffer file
)
839 (if (yes-or-no-p "Lock the latest version instead? ")
840 (vc-checkout-writable-buffer file
841 (if (vc-trunk-p (vc-workfile-version file
))
842 "" ;; this means check out latest on trunk
843 (vc-branch-part (vc-workfile-version file
)))))))
846 ;; a checked-out version exists, but the user may not own the lock
847 ((and (not (eq vc-type
'CVS
))
848 (not (string-equal owner
(vc-user-login-name))))
850 (error "Sorry, you can't steal the lock on %s this way" file
))
851 (and (eq vc-type
'RCS
)
852 (not (vc-backend-release-p 'RCS
"5.6.2"))
853 (error "File is locked by %s" owner
))
856 (if verbose
(read-string "Version to steal: ")
857 (vc-workfile-version file
))
860 ;; OK, user owns the lock on the file
863 (find-file-other-window file
)
866 ;; If the file on disk is newer, then the user just
867 ;; said no to rereading it. So the user probably wishes to
868 ;; overwrite the file with the buffer's contents, and check
870 (if (not (verify-visited-file-modtime (current-buffer)))
871 (if (yes-or-no-p "Replace file on disk with buffer contents? ")
872 (write-file (buffer-file-name))
874 ;; if buffer is not saved, give user a chance to do it
877 ;; Revert if file is unchanged and buffer is too.
878 ;; If buffer is modified, that means the user just said no
879 ;; to saving it; in that case, don't revert,
880 ;; because the user might intend to save
881 ;; after finishing the log entry.
882 (if (and (vc-workfile-unchanged-p file
)
883 (not (buffer-modified-p)))
884 ;; DO NOT revert the file without asking the user!
886 ((yes-or-no-p "Revert to master version? ")
887 (vc-backend-revert file
)
888 (vc-resynch-window file t t
)))
890 ;; user may want to set nonstandard parameters
892 (setq version
(read-string "New version level: ")))
894 ;; OK, let's do the checkin
895 (vc-checkin file version comment
)
898 (defun vc-next-action-dired (file rev comment
)
899 ;; Do a vc-next-action-on-file on all the marked files, possibly
900 ;; passing on the log comment we've just entered.
901 (let ((dired-buffer (current-buffer))
902 (dired-dir default-directory
))
903 (dired-map-over-marks
904 (let ((file (dired-get-filename)))
905 (message "Processing %s..." file
)
906 ;; Adjust the default directory so that checkouts
907 ;; go to the right place.
908 (let ((default-directory (file-name-directory file
)))
909 (vc-next-action-on-file file nil comment
)
910 (set-buffer dired-buffer
))
911 ;; Make sure that files don't vanish
912 ;; after they are checked in.
913 (let ((vc-dired-terse-mode nil
))
914 (dired-do-redisplay file
))
915 (set-window-configuration vc-dired-window-configuration
)
916 (message "Processing %s...done" file
))
918 (dired-move-to-filename))
920 ;; Here's the major entry point.
923 (defun vc-next-action (verbose)
924 "Do the next logical checkin or checkout operation on the current file.
925 If you call this from within a VC dired buffer with no files marked,
926 it will operate on the file in the current line.
927 If you call this from within a VC dired buffer, and one or more
928 files are marked, it will accept a log message and then operate on
929 each one. The log message will be used as a comment for any register
930 or checkin operations, but ignored when doing checkouts. Attempted
931 lock steals will raise an error.
932 A prefix argument lets you specify the version number to use.
934 For RCS and SCCS files:
935 If the file is not already registered, this registers it for version
937 If the file is registered and not locked by anyone, this checks out
938 a writable and locked file ready for editing.
939 If the file is checked out and locked by the calling user, this
940 first checks to see if the file has changed since checkout. If not,
941 it performs a revert.
942 If the file has been changed, this pops up a buffer for entry
943 of a log message; when the message has been entered, it checks in the
944 resulting changes along with the log message as change commentary. If
945 the variable `vc-keep-workfiles' is non-nil (which is its default), a
946 read-only copy of the changed file is left in place afterwards.
947 If the file is registered and locked by someone else, you are given
948 the option to steal the lock.
951 If the file is not already registered, this registers it for version
952 control. This does a \"cvs add\", but no \"cvs commit\".
953 If the file is added but not committed, it is committed.
954 If your working file is changed, but the repository file is
955 unchanged, this pops up a buffer for entry of a log message; when the
956 message has been entered, it checks in the resulting changes along
957 with the logmessage as change commentary. A writable file is retained.
958 If the repository file is changed, you are asked if you want to
959 merge in the changes into your working copy."
964 (let ((files (dired-get-marked-files)))
965 (set (make-local-variable 'vc-dired-window-configuration
)
966 (current-window-configuration))
969 (function (lambda (f)
970 (if (eq (vc-backend f
) 'CVS
)
971 (if (or (eq (vc-cvs-status f
) 'locally-modified
)
972 (eq (vc-cvs-status f
) 'locally-added
))
974 (if (vc-locking-user f
) "@" ""))))
976 (vc-next-action-dired nil nil
"dummy")
977 (vc-start-entry nil nil nil
978 "Enter a change comment for the marked files."
979 'vc-next-action-dired
))
981 (while vc-parent-buffer
982 (pop-to-buffer vc-parent-buffer
))
984 (vc-next-action-on-file buffer-file-name verbose
)
985 (error "Buffer %s is not associated with a file" (buffer-name)))))
987 ;;; These functions help the vc-next-action entry point
989 (defun vc-checkout-writable-buffer (&optional file rev
)
990 "Retrieve a writable copy of the latest version of the current buffer's file."
991 (vc-checkout (or file
(buffer-file-name)) t rev
)
995 (defun vc-register (&optional override comment
)
996 "Register the current file into your version-control system."
999 (error "No visited file"))
1000 (let ((master (vc-name buffer-file-name
)))
1001 (and master
(file-exists-p master
)
1002 (error "This file is already registered"))
1004 (not (y-or-n-p "Previous master file has vanished. Make a new one? "))
1005 (error "This file is already registered")))
1006 ;; Watch out for new buffers of size 0: the corresponding file
1007 ;; does not exist yet, even though buffer-modified-p is nil.
1008 (if (and (not (buffer-modified-p))
1009 (zerop (buffer-size))
1010 (not (file-exists-p buffer-file-name
)))
1011 (set-buffer-modified-p t
))
1013 (cond ((not vc-make-backup-files
)
1014 ;; inhibit backup for this buffer
1015 (make-local-variable 'backup-inhibited
)
1016 (setq backup-inhibited t
)))
1021 (format "Initial version level for %s: " buffer-file-name
)))
1022 vc-default-init-version
)
1024 ;; Recompute backend property (it may have been set to nil before).
1025 (setq vc-buffer-backend
(vc-backend (buffer-file-name)))
1028 (defun vc-resynch-window (file &optional keep noquery
)
1029 ;; If the given file is in the current buffer,
1030 ;; either revert on it so we see expanded keywords,
1031 ;; or unvisit it (depending on vc-keep-workfiles)
1032 ;; NOQUERY if non-nil inhibits confirmation for reverting.
1033 ;; NOQUERY should be t *only* if it is known the only difference
1034 ;; between the buffer and the file is due to RCS rather than user editing!
1035 (and (string= buffer-file-name file
)
1038 (vc-revert-buffer1 t noquery
)
1040 (if (file-writable-p file
)
1042 (let ((view-old-buffer-read-only nil
))
1044 (and (not view-mode
)
1045 (not (eq (get major-mode
'mode-class
) 'special
))
1046 (view-mode-enter))))
1047 (vc-mode-line buffer-file-name
))
1048 (kill-buffer (current-buffer)))))
1050 (defun vc-resynch-buffer (file &optional keep noquery
)
1051 ;; if FILE is currently visited, resynch its buffer
1052 (if (string= buffer-file-name file
)
1053 (vc-resynch-window file keep noquery
)
1054 (let ((buffer (get-file-buffer file
)))
1058 (vc-resynch-window file keep noquery
))))))
1060 (defun vc-start-entry (file rev comment msg action
&optional after-hook
)
1061 ;; Accept a comment for an operation on FILE revision REV. If COMMENT
1062 ;; is nil, pop up a VC-log buffer, emit MSG, and set the
1063 ;; action on close to ACTION; otherwise, do action immediately.
1064 ;; Remember the file's buffer in vc-parent-buffer (current one if no file).
1065 ;; AFTER-HOOK specifies the local value for vc-log-operation-hook.
1066 (let ((parent (if file
(find-file-noselect file
) (current-buffer))))
1067 (if vc-before-checkin-hook
1071 (run-hooks 'vc-before-checkin-hook
))
1072 (run-hooks 'vc-before-checkin-hook
)))
1074 (set-buffer (get-buffer-create "*VC-log*"))
1075 (pop-to-buffer (get-buffer-create "*VC-log*")))
1076 (set (make-local-variable 'vc-parent-buffer
) parent
)
1077 (set (make-local-variable 'vc-parent-buffer-name
)
1078 (concat " from " (buffer-name vc-parent-buffer
)))
1079 (if file
(vc-mode-line file
))
1081 (make-local-variable 'vc-log-after-operation-hook
)
1083 (setq vc-log-after-operation-hook after-hook
))
1084 (setq vc-log-operation action
)
1085 (setq vc-log-version rev
)
1090 (vc-finish-logentry t
)
1092 (vc-finish-logentry nil
)))
1093 (message "%s Type C-c C-c when done." msg
))))
1095 (defun vc-admin (file rev
&optional comment
)
1096 "Check a file into your version-control system.
1097 FILE is the unmodified name of the file. REV should be the base version
1098 level to check it in under. COMMENT, if specified, is the checkin comment."
1099 (vc-start-entry file rev
1100 (or comment
(not vc-initial-comment
))
1101 "Enter initial comment." 'vc-backend-admin
1104 (defun vc-checkout (file &optional writable rev
)
1105 "Retrieve a copy of the latest version of the given file."
1106 ;; If ftp is on this system and the name matches the ange-ftp format
1107 ;; for a remote file, the user is trying something that won't work.
1108 (if (and (string-match "^/[^/:]+:" file
) (vc-find-binary "ftp"))
1109 (error "Sorry, you can't check out files over FTP"))
1110 (vc-backend-checkout file writable rev
)
1111 (vc-resynch-buffer file t t
))
1113 (defun vc-steal-lock (file rev
&optional owner
)
1114 "Steal the lock on the current workfile."
1115 (let (file-description)
1117 (setq owner
(vc-locking-user file
)))
1119 (setq file-description
(format "%s:%s" file rev
))
1120 (setq file-description file
))
1121 (if (not (yes-or-no-p (format "Steal the lock on %s from %s? "
1122 file-description owner
)))
1123 (error "Steal cancelled"))
1124 (pop-to-buffer (get-buffer-create "*VC-mail*"))
1125 (setq default-directory
(expand-file-name "~/"))
1126 (auto-save-mode auto-save-default
)
1129 (mail-setup owner
(format "Stolen lock on %s" file-description
) nil nil nil
1130 (list (list 'vc-finish-steal file rev
)))
1131 (goto-char (point-max))
1133 (format "I stole the lock on %s, " file-description
)
1134 (current-time-string)
1136 (message "Please explain why you stole the lock. Type C-c C-c when done.")))
1138 ;; This is called when the notification has been sent.
1139 (defun vc-finish-steal (file version
)
1140 (vc-backend-steal file version
)
1141 (if (get-file-buffer file
)
1143 (set-buffer (get-file-buffer file
))
1144 (vc-resynch-window file t t
))))
1146 (defun vc-checkin (file &optional rev comment
)
1147 "Check in the file specified by FILE.
1148 The optional argument REV may be a string specifying the new version level
1149 \(if nil increment the current level). The file is either retained with write
1150 permissions zeroed, or deleted (according to the value of `vc-keep-workfiles').
1151 If the back-end is CVS, a writable workfile is always kept.
1152 COMMENT is a comment string; if omitted, a buffer is popped up to accept a
1155 Runs the normal hook `vc-checkin-hook'."
1156 (vc-start-entry file rev comment
1157 "Enter a change comment." 'vc-backend-checkin
1160 (defun vc-comment-to-change-log (&optional whoami file-name
)
1161 "Enter last VC comment into change log file for current buffer's file.
1162 Optional arg (interactive prefix) non-nil means prompt for user name and site.
1163 Second arg is file name of change log. \
1164 If nil, uses `change-log-default-name'.
1166 May be useful as a `vc-checkin-hook' to update change logs automatically."
1167 (interactive (if current-prefix-arg
1168 (list current-prefix-arg
1169 (prompt-for-change-log-name))))
1170 ;; Make sure the defvar for add-log-current-defun-function has been executed
1171 ;; before binding it.
1173 (let (;; Extract the comment first so we get any error before doing anything.
1174 (comment (ring-ref vc-comment-ring
0))
1175 ;; Don't let add-change-log-entry insert a defun name.
1176 (add-log-current-defun-function 'ignore
)
1178 ;; Call add-log to do half the work.
1179 (add-change-log-entry whoami file-name t t
)
1180 ;; Insert the VC comment, leaving point before it.
1181 (setq end
(save-excursion (insert comment
) (point-marker)))
1182 (if (looking-at "\\s *\\s(")
1183 ;; It starts with an open-paren, as in "(foo): Frobbed."
1184 ;; So remove the ": " add-log inserted.
1186 ;; Canonicalize the white space between the file name and comment.
1188 ;; Indent rest of the text the same way add-log indented the first line.
1189 (let ((indentation (current-indentation)))
1191 (while (< (point) end
)
1193 (indent-to indentation
))
1194 (setq end
(point))))
1195 ;; Fill the inserted text, preserving open-parens at bol.
1196 (let ((paragraph-separate (concat paragraph-separate
"\\|\\s *\\s("))
1197 (paragraph-start (concat paragraph-start
"\\|\\s *\\s(")))
1199 (fill-region (point) end
))
1200 ;; Canonicalize the white space at the end of the entry so it is
1201 ;; separated from the next entry by a single blank line.
1202 (skip-syntax-forward " " end
)
1203 (delete-char (- (skip-syntax-backward " ")))
1204 (or (eobp) (looking-at "\n\n")
1208 (defun vc-finish-logentry (&optional nocomment
)
1209 "Complete the operation implied by the current log entry."
1211 ;; Check and record the comment, if any.
1214 ;; Comment too long?
1215 (vc-backend-logentry-check vc-log-file
)
1216 ;; Record the comment in the comment ring
1217 (ring-insert vc-comment-ring
(buffer-string))
1219 ;; Sync parent buffer in case the user modified it while editing the comment.
1220 ;; But not if it is a vc-dired buffer.
1222 (set-buffer vc-parent-buffer
)
1225 (if (not vc-log-operation
) (error "No log operation is pending"))
1226 ;; save the parameters held in buffer-local variables
1227 (let ((log-operation vc-log-operation
)
1228 (log-file vc-log-file
)
1229 (log-version vc-log-version
)
1230 (log-entry (buffer-string))
1231 (after-hook vc-log-after-operation-hook
))
1232 (pop-to-buffer vc-parent-buffer
)
1235 (funcall log-operation
1239 ;; Remove checkin window (after the checkin so that if that fails
1240 ;; we don't zap the *VC-log* buffer and the typing therein).
1241 (let ((logbuf (get-buffer "*VC-log*")))
1243 (delete-windows-on logbuf
(selected-frame))
1244 ;; Kill buffer and delete any other dedicated windows/frames.
1245 (kill-buffer logbuf
))))
1246 ;; Now make sure we see the expanded headers
1247 (if buffer-file-name
1248 (vc-resynch-window buffer-file-name vc-keep-workfiles t
))
1250 (dired-move-to-filename))
1251 (run-hooks after-hook
'vc-finish-logentry-hook
)))
1253 ;; Code for access to the comment ring
1255 (defun vc-previous-comment (arg)
1256 "Cycle backwards through comment history."
1258 (let ((len (ring-length vc-comment-ring
)))
1260 (message "Empty comment ring")
1264 ;; Initialize the index on the first use of this command
1265 ;; so that the first M-p gets index 0, and the first M-n gets
1267 (if (null vc-comment-ring-index
)
1268 (setq vc-comment-ring-index
1270 (if (< arg
0) 1 0))))
1271 (setq vc-comment-ring-index
1272 (mod (+ vc-comment-ring-index arg
) len
))
1273 (message "%d" (1+ vc-comment-ring-index
))
1274 (insert (ring-ref vc-comment-ring vc-comment-ring-index
))))))
1276 (defun vc-next-comment (arg)
1277 "Cycle forwards through comment history."
1279 (vc-previous-comment (- arg
)))
1281 (defun vc-comment-search-reverse (str)
1282 "Searches backwards through comment history for substring match."
1283 (interactive "sComment substring: ")
1284 (if (string= str
"")
1285 (setq str vc-last-comment-match
)
1286 (setq vc-last-comment-match str
))
1287 (if (null vc-comment-ring-index
)
1288 (setq vc-comment-ring-index -
1))
1289 (let ((str (regexp-quote str
))
1290 (len (ring-length vc-comment-ring
))
1291 (n (1+ vc-comment-ring-index
)))
1292 (while (and (< n len
) (not (string-match str
(ring-ref vc-comment-ring n
))))
1295 (vc-previous-comment (- n vc-comment-ring-index
)))
1296 (t (error "Not found")))))
1298 (defun vc-comment-search-forward (str)
1299 "Searches forwards through comment history for substring match."
1300 (interactive "sComment substring: ")
1301 (if (string= str
"")
1302 (setq str vc-last-comment-match
)
1303 (setq vc-last-comment-match str
))
1304 (if (null vc-comment-ring-index
)
1305 (setq vc-comment-ring-index
0))
1306 (let ((str (regexp-quote str
))
1307 (len (ring-length vc-comment-ring
))
1308 (n vc-comment-ring-index
))
1309 (while (and (>= n
0) (not (string-match str
(ring-ref vc-comment-ring n
))))
1312 (vc-next-comment (- n vc-comment-ring-index
)))
1313 (t (error "Not found")))))
1315 ;; Additional entry points for examining version histories
1318 (defun vc-diff (historic &optional not-urgent
)
1319 "Display diffs between file versions.
1320 Normally this compares the current file and buffer with the most recent
1321 checked in version of that file. This uses no arguments.
1322 With a prefix argument, it reads the file name to use
1323 and two version designators specifying which versions to compare."
1324 (interactive (list current-prefix-arg t
))
1325 (vc-ensure-vc-buffer)
1327 (call-interactively 'vc-version-diff
)
1328 (let ((file buffer-file-name
)
1330 (vc-buffer-sync not-urgent
)
1331 (setq unchanged
(vc-workfile-unchanged-p buffer-file-name
))
1333 (message "No changes to %s since latest version" file
)
1334 (vc-backend-diff file
)
1335 ;; Ideally, we'd like at this point to parse the diff so that
1336 ;; the buffer effectively goes into compilation mode and we
1337 ;; can visit the old and new change locations via next-error.
1338 ;; Unfortunately, this is just too painful to do. The basic
1339 ;; problem is that the `old' file doesn't exist to be
1340 ;; visited. This plays hell with numerous assumptions in
1341 ;; the diff.el and compile.el machinery.
1342 (set-buffer "*vc-diff*")
1343 (setq default-directory
(file-name-directory file
))
1344 (if (= 0 (buffer-size))
1347 (message "No changes to %s since latest version" file
))
1348 (pop-to-buffer "*vc-diff*")
1349 (goto-char (point-min))
1350 (shrink-window-if-larger-than-buffer)))
1353 (defun vc-version-diff (file rel1 rel2
)
1354 "For FILE, report diffs between two stored versions REL1 and REL2 of it.
1355 If FILE is a directory, generate diffs between versions for all registered
1356 files in or below it."
1358 (let ((file (read-file-name (if buffer-file-name
1359 "File or dir to diff: (default visited file) "
1360 "File or dir to diff: ")
1361 default-directory buffer-file-name t
))
1362 (rel1-default nil
) (rel2-default nil
))
1363 ;; compute default versions based on the file state
1365 ;; if it's a directory, don't supply any version defauolt
1366 ((file-directory-p file
)
1368 ;; if the file is locked, use current version as older version
1369 ((vc-locking-user file
)
1370 (setq rel1-default
(vc-workfile-version file
)))
1371 ;; if the file is not locked, use last and previous version as default
1373 (setq rel1-default
(vc-previous-version (vc-workfile-version file
)))
1374 (setq rel2-default
(vc-workfile-version file
))))
1375 ;; construct argument list
1377 (read-string (if rel1-default
1378 (concat "Older version: (default "
1381 nil nil rel1-default
)
1382 (read-string (if rel2-default
1383 (concat "Newer version: (default "
1385 "Newer version (default: current source): ")
1386 nil nil rel2-default
))))
1387 (if (string-equal rel1
"") (setq rel1 nil
))
1388 (if (string-equal rel2
"") (setq rel2 nil
))
1389 (if (file-directory-p file
)
1390 (let ((camefrom (current-buffer)))
1391 (set-buffer (get-buffer-create "*vc-status*"))
1392 (set (make-local-variable 'vc-parent-buffer
) camefrom
)
1393 (set (make-local-variable 'vc-parent-buffer-name
)
1394 (concat " from " (buffer-name camefrom
)))
1396 (insert "Diffs between "
1397 (or rel1
"last version checked in")
1399 (or rel2
"current workfile(s)")
1401 (set-buffer (get-buffer-create "*vc-diff*"))
1405 (function (lambda (f)
1406 (message "Looking at %s" f
)
1408 (not (file-directory-p f
))
1410 (vc-backend-diff f rel1 rel2
)
1411 (append-to-buffer "*vc-status*" (point-min) (point-max)))
1413 (pop-to-buffer "*vc-status*")
1414 (insert "\nEnd of diffs.\n")
1415 (goto-char (point-min))
1416 (set-buffer-modified-p nil
)
1418 (if (zerop (vc-backend-diff file rel1 rel2
))
1419 (message "No changes to %s between %s and %s." file rel1 rel2
)
1420 (pop-to-buffer "*vc-diff*"))))
1423 (defun vc-version-other-window (rev)
1424 "Visit version REV of the current buffer in another window.
1425 If the current buffer is named `F', the version is named `F.~REV~'.
1426 If `F.~REV~' already exists, it is used instead of being re-created."
1427 (interactive "sVersion to visit (default is latest version): ")
1428 (vc-ensure-vc-buffer)
1429 (let* ((version (if (string-equal rev
"")
1430 (vc-latest-version buffer-file-name
)
1432 (filename (concat buffer-file-name
".~" version
"~")))
1433 (or (file-exists-p filename
)
1434 (vc-backend-checkout buffer-file-name nil version filename
))
1435 (find-file-other-window filename
)))
1437 ;; Header-insertion code
1440 (defun vc-insert-headers ()
1441 "Insert headers in a file for use with your version-control system.
1442 Headers desired are inserted at point, and are pulled from
1443 the variable `vc-header-alist'."
1445 (vc-ensure-vc-buffer)
1449 (if (or (not (vc-check-headers))
1450 (y-or-n-p "Version headers already exist. Insert another set? "))
1452 (let* ((delims (cdr (assq major-mode vc-comment-alist
)))
1453 (comment-start-vc (or (car delims
) comment-start
"#"))
1454 (comment-end-vc (or (car (cdr delims
)) comment-end
""))
1455 (hdstrings (cdr (assoc (vc-backend (buffer-file-name)) vc-header-alist
))))
1456 (mapcar (function (lambda (s)
1457 (insert comment-start-vc
"\t" s
"\t"
1458 comment-end-vc
"\n")))
1460 (if vc-static-header-alist
1461 (mapcar (function (lambda (f)
1462 (if (string-match (car f
) buffer-file-name
)
1463 (insert (format (cdr f
) (car hdstrings
))))))
1464 vc-static-header-alist
))
1468 (defun vc-clear-headers ()
1469 ;; Clear all version headers in the current buffer, i.e. reset them
1470 ;; to the nonexpanded form. Only implemented for RCS, yet.
1471 ;; Don't lose point and mark during this.
1472 (let ((context (vc-buffer-context))
1473 (case-fold-search nil
))
1474 ;; save-excursion may be able to relocate point and mark properly.
1475 ;; If it fails, vc-restore-buffer-context will give it a second try.
1477 (goto-char (point-min))
1478 (while (re-search-forward
1479 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
1480 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
1482 (replace-match "$\\1$")))
1483 (vc-restore-buffer-context context
)))
1488 (vc-ensure-vc-buffer)
1490 (let* ((file buffer-file-name
)
1491 (backend (vc-backend file
))
1492 first-version second-version locking-user
)
1493 (if (eq backend
'SCCS
)
1494 (error "Sorry, merging is not implemented for SCCS")
1495 (setq locking-user
(vc-locking-user file
))
1496 (if (eq (vc-checkout-model file
) 'manual
)
1497 (if (not locking-user
)
1499 (format "File must be %s for merging. %s now? "
1500 (if (eq backend
'RCS
) "locked" "writable")
1501 (if (eq backend
'RCS
) "Lock" "Check out"))))
1502 (error "Merge aborted")
1503 (vc-checkout file t
))
1504 (if (not (string= locking-user
(vc-user-login-name)))
1505 (error "File is locked by %s" locking-user
))))
1506 (setq first-version
(read-string "Branch or version to merge from: "))
1507 (if (and (>= (elt first-version
0) ?
0)
1508 (<= (elt first-version
0) ?
9))
1509 (if (not (vc-branch-p first-version
))
1510 (setq second-version
1511 (read-string "Second version: "
1512 (concat (vc-branch-part first-version
) ".")))
1513 ;; We want to merge an entire branch. Set versions
1514 ;; accordingly, so that vc-backend-merge understands us.
1515 (setq second-version first-version
)
1516 ;; first-version must be the starting point of the branch
1517 (setq first-version
(vc-branch-part first-version
))))
1518 (let ((status (vc-backend-merge file first-version second-version
)))
1519 (if (and (eq (vc-checkout-model file
) 'implicit
)
1520 (not (vc-locking-user file
)))
1521 (vc-file-setprop file
'vc-locking-user nil
))
1522 (vc-resynch-buffer file t t
)
1523 (if (not (zerop status
))
1524 (if (y-or-n-p "Conflicts detected. Resolve them now? ")
1525 (vc-resolve-conflicts "WORKFILE" "MERGE SOURCE")
1526 (message "File contains conflict markers"))
1527 (message "Merge successful"))))))
1530 (defun vc-resolve-conflicts (&optional name-A name-B
)
1531 "Invoke ediff to resolve conflicts in the current buffer.
1532 The conflicts must be marked with rcsmerge conflict markers."
1534 (vc-ensure-vc-buffer)
1536 (file-name (file-name-nondirectory buffer-file-name
))
1537 (your-buffer (generate-new-buffer
1538 (concat "*" file-name
1539 " " (or name-A
"WORKFILE") "*")))
1540 (other-buffer (generate-new-buffer
1541 (concat "*" file-name
1542 " " (or name-B
"CHECKED-IN") "*")))
1543 (result-buffer (current-buffer)))
1545 (set-buffer your-buffer
)
1547 (insert-buffer result-buffer
)
1548 (goto-char (point-min))
1549 (while (re-search-forward (concat "^<<<<<<< "
1550 (regexp-quote file-name
) "\n") nil t
)
1553 (if (not (re-search-forward "^=======\n" nil t
))
1554 (error "Malformed conflict marker"))
1556 (let ((start (point)))
1557 (if (not (re-search-forward "^>>>>>>> [0-9.]+\n" nil t
))
1558 (error "Malformed conflict marker"))
1559 (delete-region start
(point))))
1562 (kill-buffer your-buffer
)
1563 (kill-buffer other-buffer
)
1564 (error "No conflict markers found")))
1565 (set-buffer other-buffer
)
1567 (insert-buffer result-buffer
)
1568 (goto-char (point-min))
1569 (while (re-search-forward (concat "^<<<<<<< "
1570 (regexp-quote file-name
) "\n") nil t
)
1571 (let ((start (match-beginning 0)))
1572 (if (not (re-search-forward "^=======\n" nil t
))
1573 (error "Malformed conflict marker"))
1574 (delete-region start
(point))
1575 (if (not (re-search-forward "^>>>>>>> [0-9.]+\n" nil t
))
1576 (error "Malformed conflict marker"))
1577 (replace-match "")))
1578 (let ((config (current-window-configuration))
1579 (ediff-default-variant 'default-B
))
1583 (set-buffer (ediff-merge-buffers your-buffer other-buffer
))
1585 ;; Ediff is now set up, and we are in the control buffer.
1586 ;; Do a few further adjustments and take precautions for exit.
1588 (make-local-variable 'vc-ediff-windows
)
1589 (setq vc-ediff-windows config
)
1590 (make-local-variable 'vc-ediff-result
)
1591 (setq vc-ediff-result result-buffer
)
1592 (make-local-variable 'ediff-quit-hook
)
1593 (setq ediff-quit-hook
1596 (let ((buffer-A ediff-buffer-A
)
1597 (buffer-B ediff-buffer-B
)
1598 (buffer-C ediff-buffer-C
)
1599 (result vc-ediff-result
)
1600 (windows vc-ediff-windows
))
1601 (ediff-cleanup-mess)
1604 (insert-buffer buffer-C
)
1605 (kill-buffer buffer-A
)
1606 (kill-buffer buffer-B
)
1607 (kill-buffer buffer-C
)
1608 (set-window-configuration windows
)
1609 (message "Conflict resolution finished; you may save the buffer")))))
1610 (message "Please resolve conflicts now; exit ediff when done")
1613 ;; The VC directory major mode. Coopt Dired for this.
1614 ;; All VC commands get mapped into logical equivalents.
1616 (define-derived-mode vc-dired-mode dired-mode
"Dired under VC"
1617 "The major mode used in VC directory buffers. It works like Dired,
1618 but lists only files under version control, with the current VC state of
1619 each file being indicated in the place of the file's link count, owner,
1620 group and size. Subdirectories are also listed, and you may insert them
1621 into the buffer as desired, like in Dired.
1622 All Dired commands operate normally, with the exception of `v', which
1623 is redefined as the version control prefix, so that you can type
1624 `vl', `v=' etc. to invoke `vc-print-log', `vc-diff', and the like on
1625 the file named in the current Dired buffer line. `vv' invokes
1626 `vc-next-action' on this file, or on all files currently marked.
1627 There is a special command, `*l', to mark all files currently locked."
1628 (make-local-hook 'dired-after-readin-hook
)
1629 (add-hook 'dired-after-readin-hook
'vc-dired-hook nil t
)
1630 ;; The following is slightly modified from dired.el,
1631 ;; because file lines look a bit different in vc-dired-mode.
1632 (set (make-local-variable 'dired-move-to-filename-regexp
)
1634 ((l "\\([A-Za-z]\\|[^\0-\177]\\)")
1635 ;; In some locales, month abbreviations are as short as 2 letters,
1636 ;; and they can be padded on the right with spaces.
1637 (month (concat l l
"+ *"))
1638 ;; Recognize any non-ASCII character.
1639 ;; The purpose is to match a Kanji character.
1641 ;; (k "[^\x00-\x7f\x80-\xff]")
1643 (yyyy "[0-9][0-9][0-9][0-9]")
1646 (HH:MM
"[ 0-2][0-9]:[0-5][0-9]")
1647 (western (concat "\\(" month s dd
"\\|" dd s month
"\\)"
1648 s
"\\(" HH
:MM
"\\|" s yyyy
"\\)"))
1649 (japanese (concat mm k s dd k s
"\\(" s HH
:MM
"\\|" yyyy k
"\\)")))
1650 (concat s
"\\(" western
"\\|" japanese
"\\)" s
)))
1651 (and (boundp 'vc-dired-switches
)
1653 (set (make-local-variable 'dired-actual-switches
)
1655 (set (make-local-variable 'vc-dired-terse-mode
) vc-dired-terse-display
)
1656 (setq vc-dired-mode t
))
1658 (define-key vc-dired-mode-map
"\C-xv" vc-prefix-map
)
1659 (define-key vc-dired-mode-map
"v" vc-prefix-map
)
1661 (defun vc-dired-toggle-terse-mode ()
1662 "Toggle terse display in VC Dired."
1664 (if (not vc-dired-mode
)
1666 (setq vc-dired-terse-mode
(not vc-dired-terse-mode
))
1667 (if vc-dired-terse-mode
1671 (define-key vc-dired-mode-map
"vt" 'vc-dired-toggle-terse-mode
)
1673 (defun vc-dired-mark-locked ()
1674 "Mark all files currently locked."
1676 (dired-mark-if (let ((f (dired-get-filename nil t
)))
1678 (not (file-directory-p f
))
1679 (vc-locking-user f
)))
1682 (define-key vc-dired-mode-map
"*l" 'vc-dired-mark-locked
)
1684 (defun vc-fetch-cvs-status (dir)
1685 (let ((default-directory dir
))
1686 ;; Don't specify DIR in this command, the default-directory is
1687 ;; enough. Otherwise it might fail with remote repositories.
1688 (vc-do-command "*vc-info*" 0 "cvs" nil nil
"status")
1690 (set-buffer (get-buffer "*vc-info*"))
1691 (goto-char (point-min))
1692 (while (re-search-forward "^=+\n\\([^=\n].*\n\\|\n\\)+" nil t
)
1693 (narrow-to-region (match-beginning 0) (match-end 0))
1694 (vc-parse-cvs-status)
1695 (goto-char (point-max))
1698 (defun vc-dired-state-info (file)
1699 ;; Return the string that indicates the version control status
1700 ;; on a VC dired line.
1701 (let* ((cvs-state (and (eq (vc-backend file
) 'CVS
)
1702 (vc-cvs-status file
)))
1705 (cond ((eq cvs-state
'up-to-date
) nil
)
1706 ((eq cvs-state
'needs-checkout
) "patch")
1707 ((eq cvs-state
'locally-modified
) "modified")
1708 ((eq cvs-state
'needs-merge
) "merge")
1709 ((eq cvs-state
'unresolved-conflict
) "conflict")
1710 ((eq cvs-state
'locally-added
) "added"))
1711 (vc-locking-user file
))))
1712 (if state
(concat "(" state
")"))))
1714 (defun vc-dired-reformat-line (x)
1715 ;; Reformat a directory-listing line, replacing various columns with
1716 ;; version control information.
1717 ;; This code, like dired, assumes UNIX -l format.
1719 (let ((pos (point)) limit perm date-and-file
)
1721 (setq limit
(point))
1725 (re-search-forward ;; owner and group
1726 "^\\(..[drwxlts-]+ \\) *[0-9]+ [^ ]+ +[^ ]+ +[0-9]+\\( .*\\)"
1728 (re-search-forward ;; only owner displayed
1729 "^\\(..[drwxlts-]+ \\) *[0-9]+ [^ ]+ +[0-9]+\\( .*\\)"
1731 (re-search-forward ;; OS/2 -l format, no links, owner, group
1732 "^\\(..[drwxlts-]+ \\) *[0-9]+\\( .*\\)"
1734 (setq perm
(match-string 1)
1735 date-and-file
(match-string 2))
1736 (setq x
(substring (concat x
" ") 0 10))
1737 (replace-match (concat perm x date-and-file
)))))
1739 (defun vc-dired-hook ()
1740 ;; Called by dired after any portion of a vc-dired buffer has been read in.
1741 ;; Reformat the listing according to version control.
1742 (message "Getting version information... ")
1743 (let (subdir filename
(buffer-read-only nil
) cvs-dir
)
1744 (goto-char (point-min))
1745 (while (not (eq (point) (point-max)))
1747 ;; subdir header line
1748 ((setq subdir
(dired-get-subdir))
1749 (if (file-directory-p (concat subdir
"/CVS"))
1751 (vc-fetch-cvs-status (file-name-as-directory subdir
))
1755 ;; erase (but don't remove) the "total" line
1756 (let ((start (point)))
1758 (delete-region start
(point))
1762 ((setq filename
(dired-get-filename nil t
))
1765 ((file-directory-p filename
)
1767 ((member (file-name-nondirectory filename
)
1768 vc-directory-exclusion-list
)
1769 (let ((pos (point)))
1770 (dired-kill-tree filename
)
1773 (vc-dired-terse-mode
1774 ;; Don't show directories in terse mode. Don't use
1775 ;; dired-kill-line to remove it, because in recursive listings,
1776 ;; that would remove the directory contents as well.
1777 (delete-region (progn (beginning-of-line) (point))
1778 (progn (forward-line 1) (point))))
1779 ((string-match "\\`\\.\\.?\\'" (file-name-nondirectory filename
))
1782 (vc-dired-reformat-line nil
)
1786 (and (eq (vc-file-getprop filename
'vc-backend
) 'CVS
)
1787 (or (not vc-dired-terse-mode
)
1788 (not (eq (vc-cvs-status filename
) 'up-to-date
))))
1789 (and (vc-backend filename
)
1790 (or (not vc-dired-terse-mode
)
1791 (vc-locking-user filename
))))
1792 (vc-dired-reformat-line (vc-dired-state-info filename
))
1795 (dired-kill-line))))
1797 (t (forward-line 1))))
1799 (message "Getting version information... done")
1802 (cond ((eq (count-lines (point-min) (point-max)) 1)
1803 (goto-char (point-min))
1804 (message "No files locked under %s" default-directory
)))))
1806 (defun vc-dired-purge ()
1807 ;; Remove empty subdirs
1809 (goto-char (point-min))
1810 (while (setq subdir
(dired-get-subdir))
1812 (if (dired-get-filename nil t
)
1813 (if (not (dired-next-subdir 1 t
))
1814 (goto-char (point-max)))
1816 (if (not (string= (dired-current-directory) default-directory
))
1817 (dired-do-kill-lines t
"")
1818 ;; We cannot remove the top level directory.
1819 ;; Just make it look a little nicer.
1822 (if (not (dired-next-subdir 1 t
))
1823 (goto-char (point-max))))))
1824 (goto-char (point-min))))
1827 (defun vc-directory (dirname read-switches
)
1828 (interactive "DDired under VC (directory): \nP")
1829 (let ((vc-dired-switches (concat dired-listing-switches
1830 (if vc-dired-recurse
"R" ""))))
1832 (setq vc-dired-switches
1833 (read-string "Dired listing switches: "
1834 vc-dired-switches
)))
1836 (require 'dired-aux
)
1837 ;; force a trailing slash
1838 (if (not (eq (elt dirname
(1- (length dirname
))) ?
/))
1839 (setq dirname
(concat dirname
"/")))
1841 (dired-internal-noselect (expand-file-name dirname
)
1842 (or vc-dired-switches dired-listing-switches
)
1845 ;; Named-configuration support for SCCS
1847 (defun vc-add-triple (name file rev
)
1849 (find-file (expand-file-name
1851 (file-name-directory (vc-name file
))))
1852 (goto-char (point-max))
1853 (insert name
"\t:\t" file
"\t" rev
"\n")
1855 (kill-buffer (current-buffer))
1858 (defun vc-record-rename (file newname
)
1863 (file-name-directory (vc-name file
))))
1864 (goto-char (point-min))
1865 ;; (replace-regexp (concat ":" (regexp-quote file) "$") (concat ":" newname))
1866 (while (re-search-forward (concat ":" (regexp-quote file
) "$") nil t
)
1867 (replace-match (concat ":" newname
) nil nil
))
1869 (kill-buffer (current-buffer))
1872 (defun vc-lookup-triple (file name
)
1873 ;; Return the numeric version corresponding to a named snapshot of file
1874 ;; If name is nil or a version number string it's just passed through
1875 (cond ((null name
) name
)
1876 ((let ((firstchar (aref name
0)))
1877 (and (>= firstchar ?
0) (<= firstchar ?
9)))
1881 (set-buffer (get-buffer-create "*vc-info*"))
1885 (file-name-directory (vc-name file
))))
1887 (car (vc-parse-buffer
1888 (list (list (concat name
"\t:\t" file
"\t\\(.+\\)") 1))))
1889 (kill-buffer "*vc-info*"))))
1892 ;; Named-configuration entry points
1894 (defun vc-snapshot-precondition ()
1895 ;; Scan the tree below the current directory.
1896 ;; If any files are locked, return the name of the first such file.
1897 ;; (This means, neither snapshot creation nor retrieval is allowed.)
1898 ;; If one or more of the files are currently visited, return `visited'.
1899 ;; Otherwise, return nil.
1901 (catch 'vc-locked-example
1904 (function (lambda (f)
1905 (and (vc-registered f
)
1906 (if (vc-locking-user f
) (throw 'vc-locked-example f
)
1907 (if (get-file-buffer f
) (setq status
'visited
)))))))
1911 (defun vc-create-snapshot (name)
1912 "Make a snapshot called NAME.
1913 The snapshot is made from all registered files at or below the current
1914 directory. For each file, the version level of its latest
1915 version becomes part of the named configuration."
1916 (interactive "sNew snapshot name: ")
1917 (let ((result (vc-snapshot-precondition)))
1918 (if (stringp result
)
1919 (error "File %s is locked" result
)
1922 (function (lambda (f) (and
1924 (vc-backend-assign-name f name
)))))
1928 (defun vc-retrieve-snapshot (name)
1929 "Retrieve the snapshot called NAME, or latest versions if NAME is empty.
1930 When retrieving a snapshot, there must not be any locked files at or below
1931 the current directory. If none are locked, all registered files are
1932 checked out (unlocked) at their version levels in the snapshot NAME.
1933 If NAME is the empty string, all registered files that are not currently
1934 locked are updated to the latest versions."
1935 (interactive "sSnapshot name to retrieve (default latest versions): ")
1936 (let ((update (yes-or-no-p "Update any affected buffers? ")))
1937 (if (string= name
"")
1941 (function (lambda (f) (and
1943 (not (vc-locking-user f
))
1945 (vc-backend-checkout f nil
"")
1946 (if update
(vc-resynch-buffer f t t
))))))))
1947 (let ((result (vc-snapshot-precondition)))
1948 (if (stringp result
)
1949 (error "File %s is locked" result
)
1950 (setq update
(and (eq result
'visited
) update
))
1953 (function (lambda (f) (and
1956 (vc-backend-checkout f nil name
)
1957 (if update
(vc-resynch-buffer f t t
)))))))
1960 ;; Miscellaneous other entry points
1963 (defun vc-print-log ()
1964 "List the change log of the current buffer in a window."
1966 (vc-ensure-vc-buffer)
1967 (let ((file buffer-file-name
))
1968 (vc-backend-print-log file
)
1969 (pop-to-buffer (get-buffer-create "*vc*"))
1970 (setq default-directory
(file-name-directory file
))
1971 (goto-char (point-max)) (forward-line -
1)
1972 (while (looking-at "=*\n")
1973 (delete-char (- (match-end 0) (match-beginning 0)))
1975 (goto-char (point-min))
1976 (if (looking-at "[\b\t\n\v\f\r ]+")
1977 (delete-char (- (match-end 0) (match-beginning 0))))
1978 (shrink-window-if-larger-than-buffer)
1979 ;; move point to the log entry for the current version
1980 (and (not (eq (vc-backend file
) 'SCCS
))
1982 ;; also match some context, for safety
1983 (concat "----\nrevision " (vc-workfile-version file
)
1984 "\\(\tlocked by:.*\n\\|\n\\)date: ") nil t
)
1985 ;; set the display window so that
1986 ;; the whole log entry is displayed
1987 (let (start end lines
)
1988 (beginning-of-line) (forward-line -
1) (setq start
(point))
1989 (if (not (re-search-forward "^----*\nrevision" nil t
))
1990 (setq end
(point-max))
1991 (beginning-of-line) (forward-line -
1) (setq end
(point)))
1992 (setq lines
(count-lines start end
))
1994 ;; if the global information and this log entry fit
1995 ;; into the window, display from the beginning
1996 ((< (count-lines (point-min) end
) (window-height))
1997 (goto-char (point-min))
2000 ;; if the whole entry fits into the window,
2001 ;; display it centered
2002 ((< (1+ lines
) (window-height))
2004 (recenter (1- (- (/ (window-height) 2) (/ lines
2)))))
2005 ;; otherwise (the entry is too large for the window),
2006 ;; display from the start
2012 (defun vc-revert-buffer ()
2013 "Revert the current buffer's file back to the version it was based on.
2014 This asks for confirmation if the buffer contents are not identical
2015 to that version. Note that for RCS and CVS, this function does not
2016 automatically pick up newer changes found in the master file;
2017 use C-u \\[vc-next-action] RET to do so."
2019 (vc-ensure-vc-buffer)
2020 (let ((file buffer-file-name
)
2021 ;; This operation should always ask for confirmation.
2022 (vc-suppress-confirm nil
)
2023 (obuf (current-buffer)) (changed (vc-diff nil t
)))
2026 (if (not (yes-or-no-p "Discard changes? "))
2027 (error "Revert cancelled"))
2028 (if (and (window-dedicated-p (selected-window))
2029 (one-window-p t
'selected-frame
))
2030 (make-frame-invisible (selected-frame))
2033 (vc-backend-revert file
)
2034 (vc-resynch-window file t t
)))
2037 (defun vc-cancel-version (norevert)
2038 "Get rid of most recently checked in version of this file.
2039 A prefix argument means do not revert the buffer afterwards."
2041 (vc-ensure-vc-buffer)
2043 ((eq (vc-backend (buffer-file-name)) 'CVS
)
2044 (error "Unchecking files under CVS is dangerous and not supported in VC"))
2045 ((vc-locking-user (buffer-file-name))
2046 (error "This version is locked; use vc-revert-buffer to discard changes"))
2047 ((not (vc-latest-on-branch-p (buffer-file-name)))
2048 (error "This is not the latest version--VC cannot cancel it")))
2049 (let* ((target (vc-workfile-version (buffer-file-name)))
2050 (recent (if (vc-trunk-p target
) "" (vc-branch-part target
)))
2051 (config (current-window-configuration)) done
)
2052 (if (null (yes-or-no-p (format "Remove version %s from master? " target
)))
2054 (setq norevert
(or norevert
(not
2055 (yes-or-no-p "Revert buffer to most recent remaining version? "))))
2056 (vc-backend-uncheck (buffer-file-name) target
)
2057 ;; Check out the most recent remaining version. If it fails, because
2058 ;; the whole branch got deleted, do a double-take and check out the
2059 ;; version where the branch started.
2064 ;; Check out locked, but only to disc, and keep
2065 ;; modifications in the buffer.
2066 (vc-backend-checkout (buffer-file-name) t recent
)
2067 ;; Check out unlocked, and revert buffer.
2068 (vc-checkout (buffer-file-name) nil recent
))
2070 ;; If the checkout fails, vc-do-command signals an error.
2071 ;; We catch this error, check the reason, correct the
2072 ;; version number, and try a second time.
2073 (error (set-buffer "*vc*")
2074 (goto-char (point-min))
2075 (if (search-forward "no side branches present for" nil t
)
2076 (progn (setq recent
(vc-branch-part recent
))
2077 ;; vc-do-command popped up a window with
2078 ;; the error message. Get rid of it, by
2079 ;; restoring the old window configuration.
2080 (set-window-configuration config
))
2081 ;; No, it was some other error: re-signal it.
2082 (signal (car err
) (cdr err
))))))
2083 ;; If norevert, clear version headers and mark the buffer modified.
2086 (set-visited-file-name (buffer-file-name))
2087 (if (not vc-make-backup-files
)
2088 ;; inhibit backup for this buffer
2089 (progn (make-local-variable 'backup-inhibited
)
2090 (setq backup-inhibited t
)))
2091 (if (eq (vc-backend (buffer-file-name)) 'RCS
)
2092 (progn (setq buffer-read-only nil
)
2093 (vc-clear-headers)))
2094 (vc-mode-line (buffer-file-name))))
2095 (message "Version %s has been removed from the master" target
)
2099 (defun vc-rename-file (old new
)
2100 "Rename file OLD to NEW, and rename its master file likewise."
2101 (interactive "fVC rename file: \nFRename to: ")
2102 ;; There are several ways of renaming files under CVS 1.3, but they all
2103 ;; have serious disadvantages. See the FAQ (available from think.com in
2104 ;; pub/cvs/). I'd rather send the user an error, than do something he might
2105 ;; consider to be wrong. When the famous, long-awaited rename database is
2106 ;; implemented things might change for the better. This is unlikely to occur
2107 ;; until CVS 2.0 is released. --ceder 1994-01-23 21:27:51
2108 (if (eq (vc-backend old
) 'CVS
)
2109 (error "Renaming files under CVS is dangerous and not supported in VC"))
2110 (let ((oldbuf (get-file-buffer old
)))
2111 (if (and oldbuf
(buffer-modified-p oldbuf
))
2112 (error "Please save files before moving them"))
2113 (if (get-file-buffer new
)
2114 (error "Already editing new file name"))
2115 (if (file-exists-p new
)
2116 (error "New file already exists"))
2117 (let ((oldmaster (vc-name old
)) newmaster
)
2120 (if (vc-locking-user old
)
2121 (error "Please check in files before moving them"))
2122 (if (or (file-symlink-p oldmaster
)
2123 ;; This had FILE, I changed it to OLD. -- rms.
2124 (file-symlink-p (vc-backend-subdirectory-name old
)))
2125 (error "This is not a safe thing to do in the presence of symbolic links"))
2127 (let ((backend (vc-backend old
))
2128 (newdir (or (file-name-directory new
) ""))
2129 (newbase (file-name-nondirectory new
)))
2134 (if (eq backend
(cdr s
))
2135 (let* ((newmaster (format (car s
) newdir newbase
))
2136 (newmasterdir (file-name-directory newmaster
)))
2137 (if (or (not newmasterdir
)
2138 (file-directory-p newmasterdir
))
2139 (throw 'found newmaster
))))))
2140 vc-master-templates
)
2141 (error "New file lacks a version control directory"))))
2142 ;; Handle the SCCS PROJECTDIR feature. It is odd that this
2143 ;; is a special case, but a more elegant solution would require
2144 ;; significant changes in other parts of VC.
2145 (if (eq (vc-backend old
) 'SCCS
)
2146 (let ((project-dir (vc-sccs-project-dir)))
2150 (file-name-nondirectory newmaster
))))))
2151 (rename-file oldmaster newmaster
)))
2152 (if (or (not oldmaster
) (file-exists-p old
))
2153 (rename-file old new
)))
2154 ; ?? Renaming a file might change its contents due to keyword expansion.
2155 ; We should really check out a new copy if the old copy was precisely equal
2156 ; to some checked in version. However, testing for this is tricky....
2160 (let ((buffer-read-only buffer-read-only
))
2161 (set-visited-file-name new
))
2164 (set-buffer-modified-p nil
))))
2165 ;; This had FILE, I changed it to OLD. -- rms.
2166 (vc-backend-dispatch old
2167 (vc-record-rename old new
) ;SCCS
2174 (defun vc-update-change-log (&rest args
)
2175 "Find change log file and add entries from recent RCS/CVS logs.
2176 Normally, find log entries for all registered files in the default
2177 directory using `rcs2log', which finds CVS logs preferentially.
2178 The mark is left at the end of the text prepended to the change log.
2180 With prefix arg of C-u, only find log entries for the current buffer's file.
2182 With any numeric prefix arg, find log entries for all currently visited
2183 files that are under version control. This puts all the entries in the
2184 log for the default directory, which may not be appropriate.
2186 From a program, any arguments are assumed to be filenames and are
2187 passed to the `rcs2log' script after massaging to be relative to the
2190 (cond ((consp current-prefix-arg
) ;C-u
2191 (list buffer-file-name
))
2192 (current-prefix-arg ;Numeric argument.
2194 (buffers (buffer-list))
2197 (setq file
(buffer-file-name (car buffers
)))
2198 (and file
(vc-backend file
)
2199 (setq files
(cons file files
)))
2200 (setq buffers
(cdr buffers
)))
2203 ;; `rcs2log' will find the relevant RCS or CVS files
2204 ;; relative to the curent directory if none supplied.
2206 (let ((odefault default-directory
)
2207 (changelog (find-change-log))
2208 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
2209 (tempfile (make-temp-name
2210 (expand-file-name "vc" temporary-file-directory
)))
2211 (full-name (or add-log-full-name
2214 (format "uid%d" (number-to-string (user-uid)))))
2215 (mailing-address (or add-log-mailing-address
2216 user-mail-address
)))
2217 (find-file-other-window changelog
)
2218 (barf-if-buffer-read-only)
2221 (goto-char (point-min))
2223 (message "Computing change log entries...")
2224 (message "Computing change log entries... %s"
2228 (if (eq 0 (apply 'call-process
"rcs2log" nil
2229 (list t tempfile
) nil
2231 "-u" (concat (vc-user-login-name)
2233 "\t" mailing-address
)
2238 (if (file-name-absolute-p f
)
2240 (concat odefault f
)))))
2244 (set-buffer (get-buffer-create "*vc*")))
2246 (insert-file tempfile
)
2248 (cd (file-name-directory changelog
))
2249 (delete-file tempfile
)))))
2251 ;; vc-annotate functionality (CVS only).
2252 (defvar vc-annotate-mode nil
2253 "Variable indicating if VC-Annotate mode is active.")
2255 (defvar vc-annotate-mode-map nil
2256 "Local keymap used for VC-Annotate mode.")
2258 (defvar vc-annotate-mode-menu nil
2259 "Local keymap used for VC-Annotate mode's menu bar menu.")
2262 (defvar vc-annotate-mode-syntax-table nil
2263 "Syntax table used in VC-Annotate mode buffers.")
2265 ;; Declare globally instead of additional parameter to
2266 ;; temp-buffer-show-function (not possible to pass more than one
2268 (defvar vc-annotate-ratio nil
)
2270 (defun vc-annotate-mode-variables ()
2271 (if (not vc-annotate-mode-syntax-table
)
2272 (progn (setq vc-annotate-mode-syntax-table
(make-syntax-table))
2273 (set-syntax-table vc-annotate-mode-syntax-table
)))
2274 (if (not vc-annotate-mode-map
)
2275 (setq vc-annotate-mode-map
(make-sparse-keymap)))
2276 (setq vc-annotate-mode-menu
(make-sparse-keymap "Annotate"))
2277 (define-key vc-annotate-mode-map
[menu-bar
]
2278 (make-sparse-keymap "VC-Annotate"))
2279 (define-key vc-annotate-mode-map
[menu-bar vc-annotate-mode
]
2280 (cons "VC-Annotate" vc-annotate-mode-menu
)))
2282 (defun vc-annotate-mode ()
2283 "Major mode for buffers displaying output from the CVS `annotate' command.
2285 You can use the mode-specific menu to alter the time-span of the used
2286 colors. See variable `vc-annotate-menu-elements' for customizing the
2289 (kill-all-local-variables) ; Recommended by RMS.
2290 (vc-annotate-mode-variables) ; This defines various variables.
2291 (use-local-map vc-annotate-mode-map
) ; This provides the local keymap.
2292 (set-syntax-table vc-annotate-mode-syntax-table
)
2293 (setq major-mode
'vc-annotate-mode
) ; This is how `describe-mode'
2294 ; finds out what to describe.
2295 (setq mode-name
"Annotate") ; This goes into the mode line.
2296 (run-hooks 'vc-annotate-mode-hook
)
2297 (vc-annotate-add-menu))
2299 (defun vc-annotate-display-default (&optional event
)
2300 "Use the default color spectrum for VC Annotate mode."
2302 (message "Redisplaying annotation...")
2303 (vc-annotate-display (get-buffer (buffer-name)))
2304 (message "Redisplaying annotation...done"))
2306 (defun vc-annotate-add-menu ()
2307 "Adds the menu 'Annotate' to the menu bar in VC-Annotate mode."
2308 (define-key vc-annotate-mode-menu
[default]
2309 '("Default" . vc-annotate-display-default))
2310 (let ((menu-elements vc-annotate-menu-elements))
2311 (while menu-elements
2312 (let* ((element (car menu-elements))
2313 (days (round (* element
2314 (vc-annotate-car-last-cons vc-annotate-color-map)
2316 (setq menu-elements (cdr menu-elements))
2317 (define-key vc-annotate-mode-menu
2319 (cons (format "Span %d days"
2322 ,(format "Use colors spanning %d days" days)
2324 (message "Redisplaying annotation...")
2325 (vc-annotate-display
2326 (get-buffer (buffer-name))
2327 (vc-annotate-time-span vc-annotate-color-map ,element))
2328 (message "Redisplaying annotation...done"))))))))
2331 (defun vc-annotate (ratio)
2332 "Display the result of the CVS `annotate' command using colors.
2333 New lines are displayed in red, old in blue.
2334 A prefix argument specifies a factor for stretching the time scale.
2336 `vc-annotate-menu-elements' customizes the menu elements of the
2337 mode-specific menu. `vc-annotate-color-map' and
2338 `vc-annotate-very-old-color' defines the mapping of time to
2339 colors. `vc-annotate-background' specifies the background color."
2341 (vc-ensure-vc-buffer)
2342 (if (not (eq (vc-backend (buffer-file-name)) 'CVS))
2343 (error "Sorry, vc-annotate is only implemented for CVS"))
2344 (message "Annotating...")
2345 (let ((temp-buffer-name (concat "*cvs annotate " (buffer-name) "*"))
2346 (temp-buffer-show-function 'vc-annotate-display)
2347 (vc-annotate-ratio ratio))
2348 (with-output-to-temp-buffer temp-buffer-name
2349 (call-process "cvs" nil (get-buffer temp-buffer-name) nil
2350 "annotate" (file-name-nondirectory (buffer-file-name)))))
2351 (message "Annotating... done"))
2353 (defun vc-annotate-car-last-cons (a-list)
2354 "Return car of last cons in association list A-LIST."
2355 (if (not (eq nil (cdr a-list)))
2356 (vc-annotate-car-last-cons (cdr a-list))
2357 (car (car a-list))))
2359 (defun vc-annotate-time-span (a-list span &optional quantize)
2360 "Return an association list with factor SPAN applied to the time-span
2361 of association list A-LIST. Optionaly quantize to the factor of
2363 ;; Apply span to each car of every cons
2364 (if (not (eq nil a-list))
2365 (append (list (cons (* (car (car a-list)) span)
2366 (cdr (car a-list))))
2367 (vc-annotate-time-span (nthcdr (cond (quantize) ; optional
2368 (1)) ; Default to cdr
2369 a-list) span quantize))))
2371 (defun vc-annotate-compcar (threshold a-list)
2372 "Test successive cons cells of association list A-LIST against
2373 THRESHOLD. Return the first cons cell which car is not less than
2374 THRESHOLD, nil otherwise"
2376 (tmp-cons (car a-list)))
2377 (while (and tmp-cons (< (car tmp-cons) threshold))
2378 (setq tmp-cons (car (nthcdr i a-list)))
2380 tmp-cons)) ; Return the appropriate value
2383 (defun vc-annotate-display (buffer &optional color-map)
2384 "Do the VC-Annotate display in BUFFER using COLOR-MAP."
2386 ;; Handle the case of the global variable vc-annotate-ratio being
2387 ;; set. This variable is used to pass information from function
2388 ;; vc-annotate since it is not possible to use another parameter
2389 ;; (see temp-buffer-show-function).
2390 (if (and (not color-map) vc-annotate-ratio)
2391 ;; This will only be true if called from vc-annotate with ratio
2393 (setq color-map (vc-annotate-time-span vc-annotate-color-map
2394 vc-annotate-ratio)))
2396 ;; We need a list of months and their corresponding numbers.
2397 (let* ((local-month-numbers
2398 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4)
2399 ("May" . 5) ("Jun" . 6) ("Jul" . 7) ("Aug" . 8)
2400 ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12))))
2402 (display-buffer buffer)
2403 (if (not vc-annotate-mode) ; Turn on vc-annotate-mode if not done
2405 (goto-char (point-min)) ; Position at the top of the buffer.
2406 (while (re-search-forward
2407 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): "
2408 ;; "^[0-9]+\\(\.[0-9]+\\)*\\s-+(\\sw+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): "
2411 (let* (;; Unfortunately, order is important. match-string will
2412 ;; be corrupted by extent functions in XEmacs. Access
2413 ;; string-matches first.
2414 (day (string-to-number (match-string 1)))
2415 (month (cdr (assoc (match-string 2) local-month-numbers)))
2416 (year-tmp (string-to-number (match-string 3)))
2417 (year (+ (if (> 100 year-tmp) 1900 0) year-tmp)) ; Possible millenium problem
2418 (high (- (car (current-time))
2419 (car (encode-time 0 0 0 day month year))))
2420 (color (cond ((vc-annotate-compcar high (cond (color-map)
2421 (vc-annotate-color-map))))
2422 ((cons nil vc-annotate-very-old-color))))
2423 ;; substring from index 1 to remove any leading `#' in the name
2424 (face-name (concat "vc-annotate-face-" (substring (cdr color) 1)))
2425 ;; Make the face if not done.
2426 (face (cond ((intern-soft face-name))
2427 ((let ((tmp-face (make-face (intern face-name))))
2428 (set-face-foreground tmp-face (cdr color))
2429 (if vc-annotate-background
2430 (set-face-background tmp-face vc-annotate-background))
2431 tmp-face)))) ; Return the face
2435 (overlay-put (make-overlay point (point) nil) 'face face)))))
2438 ;; Collect back-end-dependent stuff here
2440 (defun vc-backend-admin (file &optional rev comment)
2441 ;; Register a file into the version-control system
2442 ;; Automatically retrieves a read-only version of the file with
2443 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
2444 ;; it deletes the workfile.
2445 (vc-file-clearprops file)
2446 (or vc-default-back-end
2447 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))
2448 (message "Registering %s..." file)
2450 (if (stringp vc-register-switches)
2451 (list vc-register-switches)
2452 vc-register-switches))
2456 ((file-exists-p (vc-backend-subdirectory-name)) vc-default-back-end)
2457 ((file-exists-p "RCS") 'RCS)
2458 ((file-exists-p "CVS") 'CVS)
2459 ((file-exists-p "SCCS") 'SCCS)
2460 ((setq project-dir (vc-sccs-project-dir)) 'SCCS)
2461 (t vc-default-back-end))))
2462 (cond ((eq backend 'SCCS)
2464 (if project-dir (concat project-dir
2465 "s." (file-name-nondirectory file))
2467 (car (rassq 'SCCS vc-master-templates))
2468 (or (file-name-directory file) "")
2469 (file-name-nondirectory file)))))
2470 (apply 'vc-do-command nil 0 "admin" nil nil ;; SCCS
2471 (and rev (concat "-r" rev))
2474 (and comment (concat "-y" comment))
2478 (if vc-keep-workfiles
2479 (vc-do-command nil 0 "get" file 'MASTER)))
2481 (apply 'vc-do-command nil 0 "ci" file 'WORKFILE ;; RCS
2482 ;; if available, use the secure registering option
2483 (and (vc-backend-release-p 'RCS "5.6.4") "-i")
2484 (concat (if vc-keep-workfiles "-u" "-r") rev)
2485 (and comment (concat "-t-" comment))
2488 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE ;; CVS
2490 (and comment (string-match "[^\t\n ]" comment)
2491 (concat "-m" comment))
2494 (message "Registering %s...done" file)
2497 (defun vc-backend-checkout (file &optional writable rev workfile)
2498 ;; Retrieve a copy of a saved version into a workfile
2499 (let ((filename (or workfile file))
2500 (file-buffer (get-file-buffer file))
2502 (message "Checking out %s..." filename)
2504 ;; Change buffers to get local value of vc-checkout-switches.
2505 (if file-buffer (set-buffer file-buffer))
2506 (setq switches (if (stringp vc-checkout-switches)
2507 (list vc-checkout-switches)
2508 vc-checkout-switches))
2509 ;; Save this buffer's default-directory
2510 ;; and use save-excursion to make sure it is restored
2511 ;; in the same buffer it was saved in.
2512 (let ((default-directory default-directory))
2514 ;; Adjust the default-directory so that the check-out creates
2515 ;; the file in the right place.
2516 (setq default-directory (file-name-directory filename))
2517 (vc-backend-dispatch file
2519 (and rev (string= rev "") (setq rev nil))
2521 ;; Some SCCS implementations allow checking out directly to a
2522 ;; file using the -G option, but then some don't so use the
2523 ;; least common denominator approach and use the -p option
2525 (let ((vc-modes (logior (file-modes (vc-name file))
2526 (if writable 128 0)))
2530 (apply 'vc-do-command
2531 nil 0 "/bin/sh" file 'MASTER "-c"
2532 ;; Some shells make the "" dummy argument into $0
2533 ;; while others use the shell's name as $0 and
2534 ;; use the "" as $1. The if-statement
2535 ;; converts the latter case to the former.
2536 (format "if [ x\"$1\" = x ]; then shift; fi; \
2537 umask %o; exec >\"$1\" || exit; \
2538 shift; umask %o; exec get \"$@\""
2539 (logand 511 (lognot vc-modes))
2540 (logand 511 (lognot (default-file-modes))))
2541 "" ; dummy argument for shell's $0
2546 (concat "-r" (vc-lookup-triple file rev)))
2549 (and failed (file-exists-p filename)
2550 (delete-file filename))))
2551 (apply 'vc-do-command nil 0 "get" file 'MASTER ;; SCCS
2553 (and rev (concat "-r" (vc-lookup-triple file rev)))
2555 (vc-file-setprop file 'vc-workfile-version nil)))
2557 ;; RCS doesn't let us check out into arbitrary file names directly.
2558 ;; Use `co -p' and make stdout point to the correct file.
2559 (let ((vc-modes (logior (file-modes (vc-name file))
2560 (if writable 128 0)))
2564 (apply 'vc-do-command
2565 nil 0 "/bin/sh" file 'MASTER "-c"
2566 ;; See the SCCS case, above, regarding the
2568 (format "if [ x\"$1\" = x ]; then shift; fi; \
2569 umask %o; exec >\"$1\" || exit; \
2570 shift; umask %o; exec co \"$@\""
2571 (logand 511 (lognot vc-modes))
2572 (logand 511 (lognot (default-file-modes))))
2573 "" ; dummy argument for shell's $0
2579 (and failed (file-exists-p filename) (delete-file filename))))
2581 ;; if we should go to the head of the trunk,
2582 ;; clear the default branch first
2583 (and rev (string= rev "")
2584 (vc-do-command nil 0 "rcs" file 'MASTER "-b"))
2585 ;; now do the checkout
2586 (apply 'vc-do-command
2587 nil 0 "co" file 'MASTER
2588 ;; If locking is not strict, force to overwrite
2589 ;; the writable workfile.
2590 (if (eq (vc-checkout-model file) 'implicit) "-f")
2592 (if rev (concat "-r" rev)
2593 ;; if no explicit revision was specified,
2594 ;; check out that of the working file
2595 (let ((workrev (vc-workfile-version file)))
2596 (if workrev (concat "-r" workrev)
2599 ;; determine the new workfile version
2602 (goto-char (point-min))
2604 (if (re-search-forward "^revision \\([0-9.]+\\).*\n" nil t)
2605 (buffer-substring (match-beginning 1) (match-end 1)))))
2606 (vc-file-setprop file 'vc-workfile-version new-version)
2607 ;; if necessary, adjust the default branch
2608 (and rev (not (string= rev ""))
2609 (vc-do-command nil 0 "rcs" file 'MASTER
2610 (concat "-b" (if (vc-latest-on-branch-p file)
2611 (if (vc-trunk-p new-version) nil
2612 (vc-branch-part new-version))
2615 ;; CVS is much like RCS
2619 (apply 'vc-do-command
2620 nil 0 "/bin/sh" file 'WORKFILE "-c"
2621 "exec >\"$1\" || exit; shift; exec cvs update \"$@\""
2622 "" ; dummy argument for shell's $0
2628 (and failed (file-exists-p filename) (delete-file filename))))
2629 ;; default for verbose checkout: clear the sticky tag
2630 ;; so that the actual update will get the head of the trunk
2631 (and rev (string= rev "")
2632 (vc-do-command nil 0 "cvs" file 'WORKFILE "update" "-A"))
2633 ;; If a revision was specified, check that out.
2635 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE
2636 (and writable (eq (vc-checkout-model file) 'manual) "-w")
2638 (and rev (not (string= rev ""))
2641 ;; If no revision was specified, call "cvs edit" to make
2642 ;; the file writeable.
2643 (and writable (eq (vc-checkout-model file) 'manual)
2644 (vc-do-command nil 0 "cvs" file 'WORKFILE "edit")))
2645 (if rev (vc-file-setprop file 'vc-workfile-version nil))))
2648 (vc-file-clear-masterprops file)
2650 (vc-file-setprop file 'vc-locking-user (vc-user-login-name)))
2651 (vc-file-setprop file
2652 'vc-checkout-time (nth 5 (file-attributes file)))))
2653 (message "Checking out %s...done" filename))))))
2655 (defun vc-backend-logentry-check (file)
2656 (vc-backend-dispatch file
2657 (if (>= (buffer-size) 512) ;; SCCS
2661 "Log must be less than 512 characters; point is now at pos 512")))
2666 (defun vc-backend-checkin (file rev comment)
2667 ;; Register changes to FILE as level REV with explanatory COMMENT.
2668 ;; Automatically retrieves a read-only version of the file with
2669 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
2670 ;; it deletes the workfile.
2671 ;; Adaptation for RCS branch support: if this is an explicit checkin,
2672 ;; or if the checkin creates a new branch, set the master file branch
2674 (message "Checking in %s..." file)
2675 ;; "This log message intentionally left almost blank".
2676 ;; RCS 5.7 gripes about white-space-only comments too.
2677 (or (and comment (string-match "[^\t\n ]" comment))
2678 (setq comment "*** empty log message ***"))
2680 ;; Change buffers to get local value of vc-checkin-switches.
2681 (set-buffer (or (get-file-buffer file) (current-buffer)))
2683 (if (stringp vc-checkin-switches)
2684 (list vc-checkin-switches)
2685 vc-checkin-switches)))
2686 ;; Clear the master-properties. Do that here, not at the
2687 ;; end, because if the check-in fails we want them to get
2688 ;; re-computed before the next try.
2689 (vc-file-clear-masterprops file)
2690 (vc-backend-dispatch file
2693 (apply 'vc-do-command nil 0 "delta" file 'MASTER
2694 (if rev (concat "-r" rev))
2695 (concat "-y" comment)
2697 (vc-file-setprop file 'vc-locking-user 'none)
2698 (vc-file-setprop file 'vc-workfile-version nil)
2699 (if vc-keep-workfiles
2700 (vc-do-command nil 0 "get" file 'MASTER))
2703 (let ((old-version (vc-workfile-version file)) new-version)
2704 (apply 'vc-do-command nil 0 "ci" file 'MASTER
2705 ;; if available, use the secure check-in option
2706 (and (vc-backend-release-p 'RCS "5.6.4") "-j")
2707 (concat (if vc-keep-workfiles "-u" "-r") rev)
2708 (concat "-m" comment)
2710 (vc-file-setprop file 'vc-locking-user 'none)
2711 (vc-file-setprop file 'vc-workfile-version nil)
2713 ;; determine the new workfile version
2715 (goto-char (point-min))
2716 (if (or (re-search-forward
2717 "new revision: \\([0-9.]+\\);" nil t)
2719 "reverting to previous revision \\([0-9.]+\\)" nil t))
2720 (progn (setq new-version (buffer-substring (match-beginning 1)
2722 (vc-file-setprop file 'vc-workfile-version new-version)))
2724 ;; if we got to a different branch, adjust the default
2725 ;; branch accordingly
2727 ((and old-version new-version
2728 (not (string= (vc-branch-part old-version)
2729 (vc-branch-part new-version))))
2730 (vc-do-command nil 0 "rcs" file 'MASTER
2731 (if (vc-trunk-p new-version) "-b"
2732 (concat "-b" (vc-branch-part new-version))))
2733 ;; If this is an old RCS release, we might have
2734 ;; to remove a remaining lock.
2735 (if (not (vc-backend-release-p 'RCS "5.6.2"))
2736 ;; exit status of 1 is also accepted.
2737 ;; It means that the lock was removed before.
2738 (vc-do-command nil 1 "rcs" file 'MASTER
2739 (concat "-u" old-version))))))
2742 ;; explicit check-in to the trunk requires a
2743 ;; double check-in (first unexplicit) (CVS-1.3)
2746 (if (and rev (vc-trunk-p rev))
2747 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE
2748 "ci" "-m" "intermediate"
2750 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE
2751 "ci" (if rev (concat "-r" rev))
2752 (concat "-m" comment)
2754 (error (if (eq (vc-cvs-status file) 'needs-merge)
2755 ;; The CVS output will be on top of this message.
2756 (error "Type C-x 0 C-x C-q to merge in changes")
2757 (error "Check-in failed"))))
2758 ;; determine and store the new workfile version
2760 (goto-char (point-min))
2761 (if (re-search-forward
2762 "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" nil t)
2763 (vc-file-setprop file 'vc-workfile-version
2764 (buffer-substring (match-beginning 2)
2766 (vc-file-setprop file 'vc-workfile-version nil))
2767 ;; if this was an explicit check-in, remove the sticky tag
2769 (vc-do-command nil 0 "cvs" file 'WORKFILE "update" "-A"))
2770 ;; Forget the checkout model, because we might have assumed
2771 ;; a wrong one when we found the file. After commit, we can
2772 ;; tell it from the permissions of the file
2773 ;; (see vc-checkout-model).
2774 (vc-file-setprop file 'vc-checkout-model nil)
2775 (vc-file-setprop file 'vc-locking-user 'none)
2776 (vc-file-setprop file 'vc-checkout-time
2777 (nth 5 (file-attributes file)))))))
2778 (message "Checking in %s...done" file))
2780 (defun vc-backend-revert (file)
2781 ;; Revert file to the version it was based on.
2782 (message "Reverting %s..." file)
2783 (vc-file-clear-masterprops file)
2784 (vc-backend-dispatch
2788 (vc-do-command nil 0 "unget" file 'MASTER nil)
2789 (vc-do-command nil 0 "get" file 'MASTER nil)
2790 ;; Checking out explicit versions is not supported under SCCS, yet.
2791 ;; We always "revert" to the latest version; therefore
2792 ;; vc-workfile-version is cleared here so that it gets recomputed.
2793 (vc-file-setprop file 'vc-workfile-version nil))
2795 (vc-do-command nil 0 "co" file 'MASTER
2796 "-f" (concat "-u" (vc-workfile-version file)))
2798 ;; Check out via standard output (caused by the final argument
2799 ;; FILE below), so that no sticky tag is set.
2800 (vc-backend-checkout file nil (vc-workfile-version file) file))
2801 (vc-file-setprop file 'vc-locking-user 'none)
2802 (vc-file-setprop file 'vc-checkout-time (nth 5 (file-attributes file)))
2803 (message "Reverting %s...done" file)
2806 (defun vc-backend-steal (file &optional rev)
2807 ;; Steal the lock on the current workfile. Needs RCS 5.6.2 or later for -M.
2808 (message "Stealing lock on %s..." file)
2809 (vc-backend-dispatch file
2811 (vc-do-command nil 0 "unget" file 'MASTER "-n" (if rev (concat "-r" rev)))
2812 (vc-do-command nil 0 "get" file 'MASTER "-g" (if rev (concat "-r" rev)))
2814 (vc-do-command nil 0 "rcs" file 'MASTER ;RCS
2815 "-M" (concat "-u" rev) (concat "-l" rev))
2816 (error "You cannot steal a CVS lock; there are no CVS locks to steal") ;CVS
2818 (vc-file-setprop file 'vc-locking-user (vc-user-login-name))
2819 (message "Stealing lock on %s...done" file)
2822 (defun vc-backend-uncheck (file target)
2823 ;; Undo the latest checkin.
2824 (message "Removing last change from %s..." file)
2825 (vc-backend-dispatch file
2826 (vc-do-command nil 0 "rmdel" file 'MASTER (concat "-r" target))
2827 (vc-do-command nil 0 "rcs" file 'MASTER (concat "-o" target))
2828 nil ;; this is never reached under CVS
2830 (message "Removing last change from %s...done" file)
2833 (defun vc-backend-print-log (file)
2834 ;; Get change log associated with FILE.
2835 (vc-backend-dispatch
2837 (vc-do-command nil 0 "prs" file 'MASTER)
2838 (vc-do-command nil 0 "rlog" file 'MASTER)
2839 (vc-do-command nil 0 "cvs" file 'WORKFILE "log")))
2841 (defun vc-backend-assign-name (file name)
2842 ;; Assign to a FILE's latest version a given NAME.
2843 (vc-backend-dispatch file
2844 (vc-add-triple name file (vc-latest-version file)) ;; SCCS
2845 (vc-do-command nil 0 "rcs" file 'MASTER (concat "-n" name ":")) ;; RCS
2846 (vc-do-command nil 0 "cvs" file 'WORKFILE "tag" name) ;; CVS
2850 (defun vc-backend-diff (file &optional oldvers newvers cmp)
2851 ;; Get a difference report between two versions of FILE.
2852 ;; Get only a brief comparison report if CMP, a difference report otherwise.
2853 (let ((backend (vc-backend file)) options status
2854 (diff-switches-list (if (listp diff-switches)
2856 (list diff-switches))))
2859 (setq oldvers (vc-lookup-triple file oldvers))
2860 (setq newvers (vc-lookup-triple file newvers))
2861 (setq options (append (list (and cmp "--brief") "-q"
2862 (and oldvers (concat "-r" oldvers))
2863 (and newvers (concat "-r" newvers)))
2864 (and (not cmp) diff-switches-list)))
2865 (apply 'vc-do-command "*vc-diff*" 1 "vcdiff" file 'MASTER options))
2867 (if (not oldvers) (setq oldvers (vc-workfile-version file)))
2868 ;; If we know that --brief is not supported, don't try it.
2869 (setq cmp (and cmp (not (eq vc-rcsdiff-knows-brief 'no))))
2870 (setq options (append (list (and cmp "--brief") "-q"
2871 (concat "-r" oldvers)
2872 (and newvers (concat "-r" newvers)))
2873 (and (not cmp) diff-switches-list)))
2874 (setq status (apply 'vc-do-command "*vc-diff*" 2
2875 "rcsdiff" file 'WORKFILE options))
2876 ;; If --brief didn't work, do a double-take and remember it
2880 (apply 'vc-do-command "*vc-diff*" 1 "rcsdiff" file 'WORKFILE
2881 (if cmp (cdr options) options))
2882 (if cmp (setq vc-rcsdiff-knows-brief 'no)))
2883 ;; If --brief DID work, remember that, too.
2884 (and cmp (not vc-rcsdiff-knows-brief)
2885 (setq vc-rcsdiff-knows-brief 'yes))
2887 ;; CVS is different.
2889 (if (string= (vc-workfile-version file) "0")
2890 ;; This file is added but not yet committed; there is no master file.
2891 (if (or oldvers newvers)
2892 (error "No revisions of %s exist" file)
2893 (if cmp 1 ;; file is added but not committed,
2894 ;; we regard this as "changed".
2895 ;; diff it against /dev/null.
2896 (apply 'vc-do-command
2897 "*vc-diff*" 1 "diff" file 'WORKFILE
2898 (append (if (listp diff-switches)
2900 (list diff-switches)) '("/dev/null")))))
2901 ;; cmp is not yet implemented -- we always do a full diff.
2902 (apply 'vc-do-command
2903 "*vc-diff*" 1 "cvs" file 'WORKFILE "diff"
2904 (and oldvers (concat "-r" oldvers))
2905 (and newvers (concat "-r" newvers))
2906 (if (listp diff-switches)
2908 (list diff-switches))))))))
2910 (defun vc-backend-merge-news (file)
2911 ;; Merge in any new changes made to FILE.
2912 (message "Merging changes into %s..." file)
2914 (vc-backend-dispatch
2916 (error "vc-backend-merge-news not meaningful for SCCS files") ;SCCS
2917 (error "vc-backend-merge-news not meaningful for RCS files") ;RCS
2918 (save-excursion ; CVS
2919 (vc-file-clear-masterprops file)
2920 (vc-file-setprop file 'vc-workfile-version nil)
2921 (vc-file-setprop file 'vc-locking-user nil)
2922 (vc-file-setprop file 'vc-checkout-time nil)
2923 (vc-do-command nil 0 "cvs" file 'WORKFILE "update")
2924 ;; Analyze the merge result reported by CVS, and set
2925 ;; file properties accordingly.
2926 (set-buffer (get-buffer "*vc*"))
2927 (goto-char (point-min))
2928 ;; get new workfile version
2929 (if (re-search-forward (concat "^Merging differences between "
2930 "[01234567890.]* and "
2931 "\\([01234567890.]*\\) into")
2933 (vc-file-setprop file 'vc-workfile-version (match-string 1)))
2935 (if (re-search-forward
2936 (concat "^\\(\\([CMU]\\) \\)?"
2937 (regexp-quote (file-name-nondirectory file))
2938 "\\( already contains the differences between \\)?")
2941 ;; Merge successful, we are in sync with repository now
2942 ((or (string= (match-string 2) "U")
2943 ;; Special case: file contents in sync with
2944 ;; repository anyhow:
2946 (vc-file-setprop file 'vc-locking-user 'none)
2947 (vc-file-setprop file 'vc-checkout-time
2948 (nth 5 (file-attributes file)))
2949 0) ;; indicate success to the caller
2950 ;; Merge successful, but our own changes are still in the file
2951 ((string= (match-string 2) "M")
2952 (vc-file-setprop file 'vc-locking-user (vc-file-owner file))
2953 (vc-file-setprop file 'vc-checkout-time 0)
2954 0) ;; indicate success to the caller
2955 ;; Conflicts detected!
2956 ((string= (match-string 2) "C")
2957 (vc-file-setprop file 'vc-locking-user (vc-file-owner file))
2958 (vc-file-setprop file 'vc-checkout-time 0)
2959 1) ;; signal the error to the caller
2961 (pop-to-buffer "*vc*")
2962 (error "Couldn't analyze cvs update result"))))
2963 (message "Merging changes into %s...done" file)))
2965 (defun vc-backend-merge (file first-version &optional second-version)
2966 ;; Merge the changes between FIRST-VERSION and SECOND-VERSION into
2967 ;; the current working copy of FILE. It is assumed that FILE is
2968 ;; locked and writable (vc-merge ensures this).
2969 (vc-backend-dispatch file
2971 (error "Sorry, merging is not implemented for SCCS")
2973 (vc-do-command nil 1 "rcsmerge" file 'MASTER
2974 "-kk" ;; ignore keyword conflicts
2975 (concat "-r" first-version)
2976 (if second-version (concat "-r" second-version)))
2979 (vc-do-command nil 0 "cvs" file 'WORKFILE
2981 (concat "-j" first-version)
2982 (concat "-j" second-version))
2984 (set-buffer (get-buffer "*vc*"))
2985 (goto-char (point-min))
2986 (if (re-search-forward "conflicts during merge" nil t)
2991 (defun vc-check-headers ()
2992 "Check if the current file has any headers in it."
2995 (goto-char (point-min))
2996 (vc-backend-dispatch buffer-file-name
2997 (re-search-forward "%[MIRLBSDHTEGUYFPQCZWA]%" nil t) ;; SCCS
2998 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t) ;; RCS
2999 'RCS ;; CVS works like RCS in this regard.
3003 ;; Back-end-dependent stuff ends here.
3005 ;; Set up key bindings for use while editing log messages
3007 (defun vc-log-mode (&optional file)
3008 "Minor mode for driving version-control tools.
3009 These bindings are added to the global keymap when you enter this mode:
3010 \\[vc-next-action] perform next logical version-control operation on current file
3011 \\[vc-register] register current file
3012 \\[vc-toggle-read-only] like next-action, but won't register files
3013 \\[vc-insert-headers] insert version-control headers in current file
3014 \\[vc-print-log] display change history of current file
3015 \\[vc-revert-buffer] revert buffer to latest version
3016 \\[vc-cancel-version] undo latest checkin
3017 \\[vc-diff] show diffs between file versions
3018 \\[vc-version-other-window] visit old version in another window
3019 \\[vc-directory] show all files locked by any user in or below .
3020 \\[vc-annotate] colorful display of the cvs annotate command
3021 \\[vc-update-change-log] add change log entry from recent checkins
3023 While you are entering a change log message for a version, the following
3024 additional bindings will be in effect.
3026 \\[vc-finish-logentry] proceed with check in, ending log message entry
3028 Whenever you do a checkin, your log comment is added to a ring of
3029 saved comments. These can be recalled as follows:
3031 \\[vc-next-comment] replace region with next message in comment ring
3032 \\[vc-previous-comment] replace region with previous message in comment ring
3033 \\[vc-comment-search-reverse] search backward for regexp in the comment ring
3034 \\[vc-comment-search-forward] search backward for regexp in the comment ring
3036 Entry to the change-log submode calls the value of text-mode-hook, then
3037 the value of vc-log-mode-hook.
3039 Global user options:
3040 vc-initial-comment If non-nil, require user to enter a change
3041 comment upon first checkin of the file.
3043 vc-keep-workfiles Non-nil value prevents workfiles from being
3044 deleted when changes are checked in
3046 vc-suppress-confirm Suppresses some confirmation prompts,
3047 notably for reversions.
3049 vc-header-alist Which keywords to insert when adding headers
3050 with \\[vc-insert-headers]. Defaults to
3051 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under
3054 vc-static-header-alist By default, version headers inserted in C files
3055 get stuffed in a static string area so that
3056 ident(RCS/CVS) or what(SCCS) can see them in
3057 the compiled object code. You can override
3058 this by setting this variable to nil, or change
3059 the header template by changing it.
3061 vc-command-messages if non-nil, display run messages from the
3062 actual version-control utilities (this is
3063 intended primarily for people hacking vc
3067 (set-syntax-table text-mode-syntax-table)
3068 (use-local-map vc-log-entry-mode)
3069 (setq local-abbrev-table text-mode-abbrev-table)
3070 (setq major-mode 'vc-log-mode)
3071 (setq mode-name "VC-Log")
3072 (make-local-variable 'vc-log-file)
3073 (setq vc-log-file file)
3074 (make-local-variable 'vc-log-version)
3075 (make-local-variable 'vc-comment-ring-index)
3076 (set-buffer-modified-p nil)
3077 (setq buffer-file-name nil)
3078 (run-hooks 'text-mode-hook 'vc-log-mode-hook)
3081 ;; Initialization code, to be done just once at load-time
3082 (if vc-log-entry-mode
3084 (setq vc-log-entry-mode (make-sparse-keymap))
3085 (define-key vc-log-entry-mode "\M-n" 'vc-next-comment)
3086 (define-key vc-log-entry-mode "\M-p" 'vc-previous-comment)
3087 (define-key vc-log-entry-mode "\M-r" 'vc-comment-search-reverse)
3088 (define-key vc-log-entry-mode "\M-s" 'vc-comment-search-forward)
3089 (define-key vc-log-entry-mode "\C-c\C-c" 'vc-finish-logentry)
3092 ;;; These things should probably be generally available
3094 (defun vc-file-tree-walk (dirname func &rest args)
3095 "Walk recursively through DIRNAME.
3096 Invoke FUNC f ARGS on each non-directory file f underneath it."
3097 (vc-file-tree-walk-internal (expand-file-name dirname) func args)
3098 (message "Traversing directory %s...done" dirname))
3100 (defun vc-file-tree-walk-internal (file func args)
3101 (if (not (file-directory-p file))
3102 (apply func file args)
3103 (message "Traversing directory %s..." (abbreviate-file-name file))
3104 (let ((dir (file-name-as-directory file)))
3108 (string-equal f ".")
3109 (string-equal f "..")
3110 (member f vc-directory-exclusion-list)
3111 (let ((dirf (concat dir f)))
3113 (file-symlink-p dirf) ;; Avoid possible loops
3114 (vc-file-tree-walk-internal dirf func args))))))
3115 (directory-files dir)))))
3119 ;;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
3121 ;;; These may be useful to anyone who has to debug or extend the package.
3122 ;;; (Note that this information corresponds to versions 5.x. Some of it
3123 ;;; might have been invalidated by the additions to support branching
3124 ;;; and RCS keyword lookup. AS, 1995/03/24)
3126 ;;; A fundamental problem in VC is that there are time windows between
3127 ;;; vc-next-action's computations of the file's version-control state and
3128 ;;; the actions that change it. This is a window open to lossage in a
3129 ;;; multi-user environment; someone else could nip in and change the state
3130 ;;; of the master during it.
3132 ;;; The performance problem is that rlog/prs calls are very expensive; we want
3133 ;;; to avoid them as much as possible.
3137 ;;; The performance problem, it turns out, simplifies in practice to the
3138 ;;; problem of making vc-locking-user fast. The two other functions that call
3139 ;;; prs/rlog will not be so commonly used that the slowdown is a problem; one
3140 ;;; makes snapshots, the other deletes the calling user's last change in the
3143 ;;; The race condition implies that we have to either (a) lock the master
3144 ;;; during the entire execution of vc-next-action, or (b) detect and
3145 ;;; recover from errors resulting from dispatch on an out-of-date state.
3147 ;;; Alternative (a) appears to be infeasible. The problem is that we can't
3148 ;;; guarantee that the lock will ever be removed. Suppose a user starts a
3149 ;;; checkin, the change message buffer pops up, and the user, having wandered
3150 ;;; off to do something else, simply forgets about it?
3152 ;;; Alternative (b), on the other hand, works well with a cheap way to speed up
3153 ;;; vc-locking-user. Usually, if a file is registered, we can read its locked/
3154 ;;; unlocked state and its current owner from its permissions.
3156 ;;; This shortcut will fail if someone has manually changed the workfile's
3157 ;;; permissions; also if developers are munging the workfile in several
3158 ;;; directories, with symlinks to a master (in this latter case, the
3159 ;;; permissions shortcut will fail to detect a lock asserted from another
3162 ;;; Note that these cases correspond exactly to the errors which could happen
3163 ;;; because of a competing checkin/checkout race in between two instances of
3166 ;;; For VC's purposes, a workfile/master pair may have the following states:
3168 ;;; A. Unregistered. There is a workfile, there is no master.
3170 ;;; B. Registered and not locked by anyone.
3172 ;;; C. Locked by calling user and unchanged.
3174 ;;; D. Locked by the calling user and changed.
3176 ;;; E. Locked by someone other than the calling user.
3178 ;;; This makes for 25 states and 20 error conditions. Here's the matrix:
3180 ;;; VC's idea of state
3182 ;;; V Actual state RCS action SCCS action Effect
3184 ;;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
3185 ;;; B 5 . 6 7 8 co -l get -e checkout
3186 ;;; C 9 10 . 11 12 co -u unget; get revert
3187 ;;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
3188 ;;; E 17 18 19 20 . rcs -u -M -l unget -n ; get -g steal lock
3190 ;;; All commands take the master file name as a last argument (not shown).
3192 ;;; In the discussion below, a "self-race" is a pathological situation in
3193 ;;; which VC operations are being attempted simultaneously by two or more
3194 ;;; Emacsen running under the same username.
3196 ;;; The vc-next-action code has the following windows:
3199 ;;; Between the check for existence of a master file and the call to
3200 ;;; admin/checkin in vc-buffer-admin (apparent state A). This window may
3201 ;;; never close if the initial-comment feature is on.
3204 ;;; Between the call to vc-workfile-unchanged-p in and the immediately
3205 ;;; following revert (apparent state C).
3208 ;;; Between the call to vc-workfile-unchanged-p in and the following
3209 ;;; checkin (apparent state D). This window may never close.
3212 ;;; Between the unlock and the immediately following checkout during a
3213 ;;; revert operation (apparent state C). Included in window Q.
3216 ;;; Between vc-locking-user and the following checkout (apparent state B).
3219 ;;; Between vc-locking-user and the following revert (apparent state C).
3220 ;;; Includes windows Q and S.
3223 ;;; Between vc-locking-user and the following checkin (apparent state
3224 ;;; D). This window may never be closed if the user fails to complete the
3225 ;;; checkin message. Includes window R.
3228 ;;; Between vc-locking-user and the following steal-lock (apparent
3229 ;;; state E). This window may never close if the user fails to complete
3230 ;;; the steal-lock message. Includes window X.
3233 ;;; Between the unlock and the immediately following re-lock during a
3234 ;;; steal-lock operation (apparent state E). This window may never cloce
3235 ;;; if the user fails to complete the steal-lock message.
3239 ;;; Apparent state A ---
3241 ;;; 1. File looked unregistered but is actually registered and not locked.
3243 ;;; Potential cause: someone else's admin during window P, with
3244 ;;; caller's admin happening before their checkout.
3246 ;;; RCS: Prior to version 5.6.4, ci fails with message
3247 ;;; "no lock set by <user>". From 5.6.4 onwards, VC uses the new
3248 ;;; ci -i option and the message is "<file>,v: already exists".
3249 ;;; SCCS: admin will fail with error (ad19).
3251 ;;; We can let these errors be passed up to the user.
3253 ;;; 2. File looked unregistered but is actually locked by caller, unchanged.
3255 ;;; Potential cause: self-race during window P.
3257 ;;; RCS: Prior to version 5.6.4, reverts the file to the last saved
3258 ;;; version and unlocks it. From 5.6.4 onwards, VC uses the new
3259 ;;; ci -i option, failing with message "<file>,v: already exists".
3260 ;;; SCCS: will fail with error (ad19).
3262 ;;; Either of these consequences is acceptable.
3264 ;;; 3. File looked unregistered but is actually locked by caller, changed.
3266 ;;; Potential cause: self-race during window P.
3268 ;;; RCS: Prior to version 5.6.4, VC registers the caller's workfile as
3269 ;;; a delta with a null change comment (the -t- switch will be
3270 ;;; ignored). From 5.6.4 onwards, VC uses the new ci -i option,
3271 ;;; failing with message "<file>,v: already exists".
3272 ;;; SCCS: will fail with error (ad19).
3274 ;;; 4. File looked unregistered but is locked by someone else.
3276 ;;; Potential cause: someone else's admin during window P, with
3277 ;;; caller's admin happening *after* their checkout.
3279 ;;; RCS: Prior to version 5.6.4, ci fails with a
3280 ;;; "no lock set by <user>" message. From 5.6.4 onwards,
3281 ;;; VC uses the new ci -i option, failing with message
3282 ;;; "<file>,v: already exists".
3283 ;;; SCCS: will fail with error (ad19).
3285 ;;; We can let these errors be passed up to the user.
3287 ;;; Apparent state B ---
3289 ;;; 5. File looked registered and not locked, but is actually unregistered.
3291 ;;; Potential cause: master file got nuked during window P.
3293 ;;; RCS: will fail with "RCS/<file>: No such file or directory"
3294 ;;; SCCS: will fail with error ut4.
3296 ;;; We can let these errors be passed up to the user.
3298 ;;; 6. File looked registered and not locked, but is actually locked by the
3299 ;;; calling user and unchanged.
3301 ;;; Potential cause: self-race during window T.
3303 ;;; RCS: in the same directory as the previous workfile, co -l will fail
3304 ;;; with "co error: writable foo exists; checkout aborted". In any other
3305 ;;; directory, checkout will succeed.
3306 ;;; SCCS: will fail with ge17.
3308 ;;; Either of these consequences is acceptable.
3310 ;;; 7. File looked registered and not locked, but is actually locked by the
3311 ;;; calling user and changed.
3315 ;;; 8. File looked registered and not locked, but is actually locked by another
3318 ;;; Potential cause: someone else checks it out during window T.
3320 ;;; RCS: co error: revision 1.3 already locked by <user>
3321 ;;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
3323 ;;; We can let these errors be passed up to the user.
3325 ;;; Apparent state C ---
3327 ;;; 9. File looks locked by calling user and unchanged, but is unregistered.
3331 ;;; 10. File looks locked by calling user and unchanged, but is actually not
3334 ;;; Potential cause: a self-race in window U, or by the revert's
3335 ;;; landing during window X of some other user's steal-lock or window S
3336 ;;; of another user's revert.
3338 ;;; RCS: succeeds, refreshing the file from the identical version in
3340 ;;; SCCS: fails with error ut4 (p file nonexistent).
3342 ;;; Either of these consequences is acceptable.
3344 ;;; 11. File is locked by calling user. It looks unchanged, but is actually
3347 ;;; Potential cause: the file would have to be touched by a self-race
3348 ;;; during window Q.
3350 ;;; The revert will succeed, removing whatever changes came with
3351 ;;; the touch. It is theoretically possible that work could be lost.
3353 ;;; 12. File looks like it's locked by the calling user and unchanged, but
3354 ;;; it's actually locked by someone else.
3356 ;;; Potential cause: a steal-lock in window V.
3358 ;;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
3359 ;;; SCCS: fails with error un2
3361 ;;; We can pass these errors up to the user.
3363 ;;; Apparent state D ---
3365 ;;; 13. File looks like it's locked by the calling user and changed, but it's
3366 ;;; actually unregistered.
3368 ;;; Potential cause: master file got nuked during window P.
3370 ;;; RCS: Prior to version 5.6.4, checks in the user's version as an
3371 ;;; initial delta. From 5.6.4 onwards, VC uses the new ci -j
3372 ;;; option, failing with message "no such file or directory".
3373 ;;; SCCS: will fail with error ut4.
3375 ;;; This case is kind of nasty. Under RCS prior to version 5.6.4,
3376 ;;; VC may fail to detect the loss of previous version information.
3378 ;;; 14. File looks like it's locked by the calling user and changed, but it's
3379 ;;; actually unlocked.
3381 ;;; Potential cause: self-race in window V, or the checkin happening
3382 ;;; during the window X of someone else's steal-lock or window S of
3383 ;;; someone else's revert.
3385 ;;; RCS: ci will fail with "no lock set by <user>".
3386 ;;; SCCS: delta will fail with error ut4.
3388 ;;; 15. File looks like it's locked by the calling user and changed, but it's
3389 ;;; actually locked by the calling user and unchanged.
3391 ;;; Potential cause: another self-race --- a whole checkin/checkout
3392 ;;; sequence by the calling user would have to land in window R.
3394 ;;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
3395 ;;; RCS: reverts to the file state as of the second user's checkin, leaving
3396 ;;; the file unlocked.
3398 ;;; It is theoretically possible that work could be lost under RCS.
3400 ;;; 16. File looks like it's locked by the calling user and changed, but it's
3401 ;;; actually locked by a different user.
3403 ;;; RCS: ci error: no lock set by <user>
3404 ;;; SCCS: unget will fail with error un2
3406 ;;; We can pass these errors up to the user.
3408 ;;; Apparent state E ---
3410 ;;; 17. File looks like it's locked by some other user, but it's actually
3415 ;;; 18. File looks like it's locked by some other user, but it's actually
3418 ;;; Potential cause: someone released a lock during window W.
3420 ;;; RCS: The calling user will get the lock on the file.
3421 ;;; SCCS: unget -n will fail with cm4.
3423 ;;; Either of these consequences will be OK.
3425 ;;; 19. File looks like it's locked by some other user, but it's actually
3426 ;;; locked by the calling user and unchanged.
3428 ;;; Potential cause: the other user relinquishing a lock followed by
3429 ;;; a self-race, both in window W.
3431 ;;; Under both RCS and SCCS, both unlock and lock will succeed, making
3432 ;;; the sequence a no-op.
3434 ;;; 20. File looks like it's locked by some other user, but it's actually
3435 ;;; locked by the calling user and changed.
3441 ;;; In order of decreasing severity:
3443 ;;; Cases 11 and 15 are the only ones that potentially lose work.
3444 ;;; They would require a self-race for this to happen.
3446 ;;; Case 13 in RCS loses information about previous deltas, retaining
3447 ;;; only the information in the current workfile. This can only happen
3448 ;;; if the master file gets nuked in window P.
3450 ;;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
3451 ;;; no change comment in the master. This would require a self-race in
3452 ;;; window P or R respectively.
3454 ;;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
3456 ;;; Unfortunately, it appears to me that no recovery is possible in these
3457 ;;; cases. They don't yield error messages, so there's no way to tell that
3458 ;;; a race condition has occurred.
3460 ;;; All other cases don't change either the workfile or the master, and
3461 ;;; trigger command errors which the user will see.
3463 ;;; Thus, there is no explicit recovery code.