(set-language-environment): Do the real work here.
[emacs.git] / lisp / vc.el
blobf88a36871a2d335b46ed1efa00dc9fb02c0b076d
1 ;;; vc.el --- drive a version-control system from within Emacs
3 ;; Copyright (C) 1992, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
6 ;; Maintainer: Andre Spiegel <spiegel@inf.fu-berlin.de>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;; Commentary:
27 ;; This mode is fully documented in the Emacs user's manual.
29 ;; This was designed and implemented by Eric Raymond <esr@snark.thyrsus.com>.
30 ;; Paul Eggert <eggert@twinsun.com>, Sebastian Kremer <sk@thp.uni-koeln.de>,
31 ;; and Richard Stallman contributed valuable criticism, support, and testing.
32 ;; CVS support was added by Per Cederqvist <ceder@lysator.liu.se>
33 ;; in Jan-Feb 1994. Further enhancements came from ttn.netcom.com and
34 ;; Andre Spiegel <spiegel@inf.fu-berlin.de>.
36 ;; Supported version-control systems presently include SCCS, RCS, and CVS.
38 ;; Some features will not work with old RCS versions. Where
39 ;; appropriate, VC finds out which version you have, and allows or
40 ;; disallows those features (stealing locks, for example, works only
41 ;; from 5.6.2 onwards).
42 ;; Even initial checkins will fail if your RCS version is so old that ci
43 ;; doesn't understand -t-; this has been known to happen to people running
44 ;; NExTSTEP 3.0.
46 ;; You can support the RCS -x option by adding pairs to the
47 ;; vc-master-templates list.
49 ;; Proper function of the SCCS diff commands requires the shellscript vcdiff
50 ;; to be installed somewhere on Emacs's path for executables.
52 ;; If your site uses the ChangeLog convention supported by Emacs, the
53 ;; function vc-comment-to-change-log should prove a useful checkin hook.
55 ;; This code depends on call-process passing back the subprocess exit
56 ;; status. Thus, you need Emacs 18.58 or later to run it. For the
57 ;; vc-directory command to work properly as documented, you need 19.
58 ;; You also need Emacs 19's ring.el.
60 ;; The vc code maintains some internal state in order to reduce expensive
61 ;; version-control operations to a minimum. Some names are only computed
62 ;; once. If you perform version control operations with RCS/SCCS/CVS while
63 ;; vc's back is turned, or move/rename master files while vc is running,
64 ;; vc may get seriously confused. Don't do these things!
66 ;; Developer's notes on some concurrency issues are included at the end of
67 ;; the file.
69 ;;; Code:
71 (require 'vc-hooks)
72 (require 'ring)
73 (eval-when-compile (require 'dired)) ; for dired-map-over-marks macro
75 (if (not (assoc 'vc-parent-buffer minor-mode-alist))
76 (setq minor-mode-alist
77 (cons '(vc-parent-buffer vc-parent-buffer-name)
78 minor-mode-alist)))
80 ;; To implement support for a new version-control system, add another
81 ;; branch to the vc-backend-dispatch macro and fill it in in each
82 ;; call. The variable vc-master-templates in vc-hooks.el will also
83 ;; have to change.
85 (defmacro vc-backend-dispatch (f s r c)
86 "Execute FORM1, FORM2 or FORM3 for SCCS, RCS or CVS respectively.
87 If FORM3 is `RCS', use FORM2 for CVS as well as RCS.
88 \(CVS shares some code with RCS)."
89 (list 'let (list (list 'type (list 'vc-backend f)))
90 (list 'cond
91 (list (list 'eq 'type (quote 'SCCS)) s) ;; SCCS
92 (list (list 'eq 'type (quote 'RCS)) r) ;; RCS
93 (list (list 'eq 'type (quote 'CVS)) ;; CVS
94 (if (eq c 'RCS) r c))
95 )))
97 ;; General customization
99 (defgroup vc nil
100 "Version-control system in Emacs."
101 :group 'tools)
103 (defcustom vc-suppress-confirm nil
104 "*If non-nil, treat user as expert; suppress yes-no prompts on some things."
105 :type 'boolean
106 :group 'vc)
108 (defcustom vc-initial-comment nil
109 "*If non-nil, prompt for initial comment when a file is registered."
110 :type 'boolean
111 :group 'vc)
113 (defcustom vc-command-messages nil
114 "*If non-nil, display run messages from back-end commands."
115 :type 'boolean
116 :group 'vc)
118 (defcustom vc-checkin-switches nil
119 "*A string or list of strings specifying extra switches for checkin.
120 These are passed to the checkin program by \\[vc-checkin]."
121 :type '(choice (const :tag "None" nil)
122 (string :tag "Argument String")
123 (repeat :tag "Argument List"
124 :value ("")
125 string))
126 :group 'vc)
128 (defcustom vc-checkout-switches nil
129 "*A string or list of strings specifying extra switches for checkout.
130 These are passed to the checkout program by \\[vc-checkout]."
131 :type '(choice (const :tag "None" nil)
132 (string :tag "Argument String")
133 (repeat :tag "Argument List"
134 :value ("")
135 string))
136 :group 'vc)
138 (defcustom vc-register-switches nil
139 "*A string or list of strings; extra switches for registering a file.
140 These are passed to the checkin program by \\[vc-register]."
141 :type '(choice (const :tag "None" nil)
142 (string :tag "Argument String")
143 (repeat :tag "Argument List"
144 :value ("")
145 string))
146 :group 'vc)
148 (defcustom vc-directory-exclusion-list '("SCCS" "RCS" "CVS")
149 "*List of directory names to be ignored while recursively walking file trees."
150 :type '(repeat string)
151 :group 'vc)
153 (defconst vc-maximum-comment-ring-size 32
154 "Maximum number of saved comments in the comment ring.")
156 ;;; This is duplicated in diff.el.
157 (defvar diff-switches "-c"
158 "*A string or list of strings specifying switches to be be passed to diff.")
160 (defcustom vc-annotate-color-map
161 '(( 26.3672 . "#FF0000")
162 ( 52.7344 . "#FF3800")
163 ( 79.1016 . "#FF7000")
164 (105.4688 . "#FFA800")
165 (131.8359 . "#FFE000")
166 (158.2031 . "#E7FF00")
167 (184.5703 . "#AFFF00")
168 (210.9375 . "#77FF00")
169 (237.3047 . "#3FFF00")
170 (263.6719 . "#07FF00")
171 (290.0391 . "#00FF31")
172 (316.4063 . "#00FF69")
173 (342.7734 . "#00FFA1")
174 (369.1406 . "#00FFD9")
175 (395.5078 . "#00EEFF")
176 (421.8750 . "#00B6FF")
177 (448.2422 . "#007EFF"))
178 "*Association list of age versus color, for \\[vc-annotate].
179 Ages are given in units of 2**-16 seconds.
180 Default is eighteen steps using a twenty day increment."
181 :type 'sexp
182 :group 'vc)
184 (defcustom vc-annotate-very-old-color "#0046FF"
185 "*Color for lines older than CAR of last cons in `vc-annotate-color-map'."
186 :type 'string
187 :group 'vc)
189 (defcustom vc-annotate-background "black"
190 "*Background color for \\[vc-annotate].
191 Default color is used if nil."
192 :type 'string
193 :group 'vc)
195 (defcustom vc-annotate-menu-elements '(2 0.5 0.1 0.01)
196 "*Menu elements for the mode-specific menu of VC-Annotate mode.
197 List of factors, used to expand/compress the time scale. See `vc-annotate'."
198 :type 'sexp
199 :group 'vc)
201 ;;;###autoload
202 (defcustom vc-checkin-hook nil
203 "*Normal hook (List of functions) run after a checkin is done.
204 See `run-hooks'."
205 :type 'hook
206 :group 'vc)
208 ;;;###autoload
209 (defcustom vc-before-checkin-hook nil
210 "*Normal hook (list of functions) run before a file gets checked in.
211 See `run-hooks'."
212 :type 'hook
213 :group 'vc)
215 ;;;###autoload
216 (defcustom vc-annotate-mode-hook nil
217 "*Hooks to run when VC-Annotate mode is turned on."
218 :type 'hook
219 :group 'vc)
221 ;; Header-insertion hair
223 (defcustom vc-header-alist
224 '((SCCS "\%W\%") (RCS "\$Id\$") (CVS "\$Id\$"))
225 "*Header keywords to be inserted by `vc-insert-headers'.
226 Must be a list of two-element lists, the first element of each must
227 be `RCS', `CVS', or `SCCS'. The second element is the string to
228 be inserted for this particular backend."
229 :type '(repeat (list :format "%v"
230 (choice :tag "System"
231 (const SCCS)
232 (const RCS)
233 (const CVS))
234 (string :tag "Header")))
235 :group 'vc)
237 (defcustom vc-static-header-alist
238 '(("\\.c$" .
239 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
240 "*Associate static header string templates with file types. A \%s in the
241 template is replaced with the first string associated with the file's
242 version-control type in `vc-header-alist'."
243 :type '(repeat (cons :format "%v"
244 (regexp :tag "File Type")
245 (string :tag "Header String")))
246 :group 'vc)
248 (defcustom vc-comment-alist
249 '((nroff-mode ".\\\"" ""))
250 "*Special comment delimiters to be used in generating vc headers only.
251 Add an entry in this list if you need to override the normal comment-start
252 and comment-end variables. This will only be necessary if the mode language
253 is sensitive to blank lines."
254 :type '(repeat (list :format "%v"
255 (symbol :tag "Mode")
256 (string :tag "Comment Start")
257 (string :tag "Comment End")))
258 :group 'vc)
260 ;; Default is to be extra careful for super-user.
261 (defcustom vc-checkout-carefully (= (user-uid) 0)
262 "*Non-nil means be extra-careful in checkout.
263 Verify that the file really is not locked
264 and that its contents match what the master file says."
265 :type 'boolean
266 :group 'vc)
268 (defcustom vc-rcs-release nil
269 "*The release number of your RCS installation, as a string.
270 If nil, VC itself computes this value when it is first needed."
271 :type '(choice (const :tag "Auto" nil)
272 string)
273 :group 'vc)
275 (defcustom vc-sccs-release nil
276 "*The release number of your SCCS installation, as a string.
277 If nil, VC itself computes this value when it is first needed."
278 :type '(choice (const :tag "Auto" nil)
279 string)
280 :group 'vc)
282 (defcustom vc-cvs-release nil
283 "*The release number of your CVS installation, as a string.
284 If nil, VC itself computes this value when it is first needed."
285 :type '(choice (const :tag "Auto" nil)
286 string)
287 :group 'vc)
289 ;; Variables the user doesn't need to know about.
290 (defvar vc-log-entry-mode nil)
291 (defvar vc-log-operation nil)
292 (defvar vc-log-after-operation-hook nil)
293 (defvar vc-checkout-writable-buffer-hook 'vc-checkout-writable-buffer)
294 ;; In a log entry buffer, this is a local variable
295 ;; that points to the buffer for which it was made
296 ;; (either a file, or a VC dired buffer).
297 (defvar vc-parent-buffer nil)
298 (defvar vc-parent-buffer-name nil)
300 (defvar vc-log-file)
301 (defvar vc-log-version)
303 (defconst vc-name-assoc-file "VC-names")
305 (defvar vc-dired-mode nil)
306 (make-variable-buffer-local 'vc-dired-mode)
308 (defvar vc-comment-ring (make-ring vc-maximum-comment-ring-size))
309 (defvar vc-comment-ring-index nil)
310 (defvar vc-last-comment-match nil)
312 ;; Back-portability to Emacs 18
314 (defun file-executable-p-18 (f)
315 (let ((modes (file-modes f)))
316 (and modes (not (zerop (logand 292))))))
318 (defun file-regular-p-18 (f)
319 (let ((attributes (file-attributes f)))
320 (and attributes (not (car attributes)))))
322 ; Conditionally rebind some things for Emacs 18 compatibility
323 (if (not (boundp 'minor-mode-map-alist))
324 (progn
325 (setq compilation-old-error-list nil)
326 (fset 'file-executable-p 'file-executable-p-18)
327 (fset 'shrink-window-if-larger-than-buffer 'beginning-of-buffer)
330 (if (not (fboundp 'file-regular-p))
331 (fset 'file-regular-p 'file-regular-p-18))
333 ;;; Find and compare backend releases
335 (defun vc-backend-release (backend)
336 ;; Returns which backend release is installed on this system.
337 (cond
338 ((eq backend 'RCS)
339 (or vc-rcs-release
340 (and (zerop (vc-do-command nil nil "rcs" nil nil "-V"))
341 (save-excursion
342 (set-buffer (get-buffer "*vc*"))
343 (setq vc-rcs-release
344 (car (vc-parse-buffer
345 '(("^RCS version \\([0-9.]+ *.*\\)" 1)))))))
346 (setq vc-rcs-release 'unknown)))
347 ((eq backend 'CVS)
348 (or vc-cvs-release
349 (and (zerop (vc-do-command nil 1 "cvs" nil nil "-v"))
350 (save-excursion
351 (set-buffer (get-buffer "*vc*"))
352 (setq vc-cvs-release
353 (car (vc-parse-buffer
354 '(("^Concurrent Versions System (CVS) \\([0-9.]+\\)"
355 1)))))))
356 (setq vc-cvs-release 'unknown)))
357 ((eq backend 'SCCS)
358 vc-sccs-release)))
360 (defun vc-release-greater-or-equal (r1 r2)
361 ;; Compare release numbers, represented as strings.
362 ;; Release components are assumed cardinal numbers, not decimal
363 ;; fractions (5.10 is a higher release than 5.9). Omitted fields
364 ;; are considered lower (5.6.7 is earlier than 5.6.7.1).
365 ;; Comparison runs till the end of the string is found, or a
366 ;; non-numeric component shows up (5.6.7 is earlier than "5.6.7 beta",
367 ;; which is probably not what you want in some cases).
368 ;; This code is suitable for existing RCS release numbers.
369 ;; CVS releases are handled reasonably, too (1.3 < 1.4* < 1.5).
370 (let (v1 v2 i1 i2)
371 (catch 'done
372 (or (and (string-match "^\\.?\\([0-9]+\\)" r1)
373 (setq i1 (match-end 0))
374 (setq v1 (string-to-number (match-string 1 r1)))
375 (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
376 (setq i2 (match-end 0))
377 (setq v2 (string-to-number (match-string 1 r2)))
378 (if (> v1 v2) (throw 'done t)
379 (if (< v1 v2) (throw 'done nil)
380 (throw 'done
381 (vc-release-greater-or-equal
382 (substring r1 i1)
383 (substring r2 i2)))))))
384 (throw 'done t)))
385 (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
386 (throw 'done nil))
387 (throw 'done t)))))
389 (defun vc-backend-release-p (backend release)
390 ;; Return t if we have RELEASE of BACKEND or better
391 (let (i r (ri 0) (ii 0) is rs (installation (vc-backend-release backend)))
392 (if (not (eq installation 'unknown))
393 (cond
394 ((or (eq backend 'RCS) (eq backend 'CVS))
395 (vc-release-greater-or-equal installation release))))))
397 ;;; functions that operate on RCS revision numbers
399 (defun vc-trunk-p (rev)
400 ;; return t if REV is a revision on the trunk
401 (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev))))
403 (defun vc-branch-part (rev)
404 ;; return the branch part of a revision number REV
405 (substring rev 0 (string-match "\\.[0-9]+\\'" rev)))
407 ;; File property caching
409 (defun vc-clear-context ()
410 "Clear all cached file properties and the comment ring."
411 (interactive)
412 (fillarray vc-file-prop-obarray nil)
413 ;; Note: there is potential for minor lossage here if there is an open
414 ;; log buffer with a nonzero local value of vc-comment-ring-index.
415 (setq vc-comment-ring (make-ring vc-maximum-comment-ring-size)))
417 (defun vc-file-clear-masterprops (file)
418 ;; clear all properties of FILE that were retrieved
419 ;; from the master file
420 (vc-file-setprop file 'vc-latest-version nil)
421 (vc-file-setprop file 'vc-your-latest-version nil)
422 (vc-backend-dispatch file
423 (progn ;; SCCS
424 (vc-file-setprop file 'vc-master-locks nil))
425 (progn ;; RCS
426 (vc-file-setprop file 'vc-default-branch nil)
427 (vc-file-setprop file 'vc-head-version nil)
428 (vc-file-setprop file 'vc-master-workfile-version nil)
429 (vc-file-setprop file 'vc-master-locks nil))
430 (progn
431 (vc-file-setprop file 'vc-cvs-status nil))))
433 (defun vc-head-version (file)
434 ;; Return the RCS head version of FILE
435 (cond ((vc-file-getprop file 'vc-head-version))
436 (t (vc-fetch-master-properties file)
437 (vc-file-getprop file 'vc-head-version))))
439 ;; Random helper functions
441 (defun vc-latest-on-branch-p (file)
442 ;; return t iff the current workfile version of FILE is
443 ;; the latest on its branch.
444 (vc-backend-dispatch file
445 ;; SCCS
446 (string= (vc-workfile-version file) (vc-latest-version file))
447 ;; RCS
448 (let ((workfile-version (vc-workfile-version file)) tip-version)
449 (if (vc-trunk-p workfile-version)
450 (progn
451 ;; Re-fetch the head version number. This is to make
452 ;; sure that no-one has checked in a new version behind
453 ;; our back.
454 (vc-fetch-master-properties file)
455 (string= (vc-file-getprop file 'vc-head-version)
456 workfile-version))
457 ;; If we are not on the trunk, we need to examine the
458 ;; whole current branch. (vc-master-workfile-version
459 ;; is not what we need.)
460 (save-excursion
461 (set-buffer (get-buffer-create "*vc-info*"))
462 (vc-insert-file (vc-name file) "^desc")
463 (setq tip-version (car (vc-parse-buffer (list (list
464 (concat "^\\(" (regexp-quote (vc-branch-part workfile-version))
465 "\\.[0-9]+\\)\ndate[ \t]+\\([0-9.]+\\);") 1 2)))))
466 (if (get-buffer "*vc-info*")
467 (kill-buffer (get-buffer "*vc-info*")))
468 (string= tip-version workfile-version))))
469 ;; CVS
472 (defun vc-registration-error (file)
473 (if file
474 (error "File %s is not under version control" file)
475 (error "Buffer %s is not associated with a file" (buffer-name))))
477 (defvar vc-binary-assoc nil)
479 (defun vc-find-binary (name)
480 "Look for a command anywhere on the subprocess-command search path."
481 (or (cdr (assoc name vc-binary-assoc))
482 (catch 'found
483 (mapcar
484 (function
485 (lambda (s)
486 (if s
487 (let ((full (concat s "/" name)))
488 (if (file-executable-p full)
489 (progn
490 (setq vc-binary-assoc
491 (cons (cons name full) vc-binary-assoc))
492 (throw 'found full)))))))
493 exec-path)
494 nil)))
496 (defun vc-do-command (buffer okstatus command file last &rest flags)
497 "Execute a version-control command, notifying user and checking for errors.
498 Output from COMMAND goes to BUFFER, or *vc* if BUFFER is nil.
499 The command is successful if its exit status does not exceed OKSTATUS.
500 (If OKSTATUS is nil, that means to ignore errors.)
501 The last argument of the command is the master name of FILE if LAST is
502 `MASTER', or the workfile of FILE if LAST is `WORKFILE'; this is appended
503 to an optional list of FLAGS."
504 (and file (setq file (expand-file-name file)))
505 (if (not buffer) (setq buffer "*vc*"))
506 (if vc-command-messages
507 (message "Running %s on %s..." command file))
508 (let ((obuf (current-buffer)) (camefrom (current-buffer))
509 (squeezed nil)
510 (vc-file (and file (vc-name file)))
511 (olddir default-directory)
512 status)
513 (set-buffer (get-buffer-create buffer))
514 (set (make-local-variable 'vc-parent-buffer) camefrom)
515 (set (make-local-variable 'vc-parent-buffer-name)
516 (concat " from " (buffer-name camefrom)))
517 (setq default-directory olddir)
519 (erase-buffer)
521 (mapcar
522 (function (lambda (s) (and s (setq squeezed (append squeezed (list s))))))
523 flags)
524 (if (and vc-file (eq last 'MASTER))
525 (setq squeezed (append squeezed (list vc-file))))
526 (if (eq last 'WORKFILE)
527 (progn
528 (let* ((pwd (expand-file-name default-directory))
529 (preflen (length pwd)))
530 (if (string= (substring file 0 preflen) pwd)
531 (setq file (substring file preflen))))
532 (setq squeezed (append squeezed (list file)))))
533 (let ((exec-path (append vc-path exec-path))
534 ;; Add vc-path to PATH for the execution of this command.
535 (process-environment
536 (cons (concat "PATH=" (getenv "PATH")
537 path-separator
538 (mapconcat 'identity vc-path path-separator))
539 process-environment))
540 (w32-quote-process-args t))
541 (setq status (apply 'call-process command nil t nil squeezed)))
542 (goto-char (point-max))
543 (set-buffer-modified-p nil)
544 (forward-line -1)
545 (if (or (not (integerp status)) (and okstatus (< okstatus status)))
546 (progn
547 (pop-to-buffer buffer)
548 (goto-char (point-min))
549 (shrink-window-if-larger-than-buffer)
550 (error "Running %s...FAILED (%s)" command
551 (if (integerp status)
552 (format "status %d" status)
553 status))
555 (if vc-command-messages
556 (message "Running %s...OK" command))
558 (set-buffer obuf)
559 status)
562 ;;; Save a bit of the text around POSN in the current buffer, to help
563 ;;; us find the corresponding position again later. This works even
564 ;;; if all markers are destroyed or corrupted.
565 ;;; A lot of this was shamelessly lifted from Sebastian Kremer's rcs.el mode.
566 (defun vc-position-context (posn)
567 (list posn
568 (buffer-size)
569 (buffer-substring posn
570 (min (point-max) (+ posn 100)))))
572 ;;; Return the position of CONTEXT in the current buffer, or nil if we
573 ;;; couldn't find it.
574 (defun vc-find-position-by-context (context)
575 (let ((context-string (nth 2 context)))
576 (if (equal "" context-string)
577 (point-max)
578 (save-excursion
579 (let ((diff (- (nth 1 context) (buffer-size))))
580 (if (< diff 0) (setq diff (- diff)))
581 (goto-char (nth 0 context))
582 (if (or (search-forward context-string nil t)
583 ;; Can't use search-backward since the match may continue
584 ;; after point.
585 (progn (goto-char (- (point) diff (length context-string)))
586 ;; goto-char doesn't signal an error at
587 ;; beginning of buffer like backward-char would
588 (search-forward context-string nil t)))
589 ;; to beginning of OSTRING
590 (- (point) (length context-string))))))))
592 (defun vc-buffer-context ()
593 ;; Return a list '(point-context mark-context reparse); from which
594 ;; vc-restore-buffer-context can later restore the context.
595 (let ((point-context (vc-position-context (point)))
596 ;; Use mark-marker to avoid confusion in transient-mark-mode.
597 (mark-context (if (eq (marker-buffer (mark-marker)) (current-buffer))
598 (vc-position-context (mark-marker))))
599 ;; Make the right thing happen in transient-mark-mode.
600 (mark-active nil)
601 ;; We may want to reparse the compilation buffer after revert
602 (reparse (and (boundp 'compilation-error-list) ;compile loaded
603 (let ((curbuf (current-buffer)))
604 ;; Construct a list; each elt is nil or a buffer
605 ;; iff that buffer is a compilation output buffer
606 ;; that contains markers into the current buffer.
607 (save-excursion
608 (mapcar (function
609 (lambda (buffer)
610 (set-buffer buffer)
611 (let ((errors (or
612 compilation-old-error-list
613 compilation-error-list))
614 (buffer-error-marked-p nil))
615 (while (and (consp errors)
616 (not buffer-error-marked-p))
617 (and (markerp (cdr (car errors)))
618 (eq buffer
619 (marker-buffer
620 (cdr (car errors))))
621 (setq buffer-error-marked-p t))
622 (setq errors (cdr errors)))
623 (if buffer-error-marked-p buffer))))
624 (buffer-list)))))))
625 (list point-context mark-context reparse)))
627 (defun vc-restore-buffer-context (context)
628 ;; Restore point/mark, and reparse any affected compilation buffers.
629 ;; CONTEXT is that which vc-buffer-context returns.
630 (let ((point-context (nth 0 context))
631 (mark-context (nth 1 context))
632 (reparse (nth 2 context)))
633 ;; Reparse affected compilation buffers.
634 (while reparse
635 (if (car reparse)
636 (save-excursion
637 (set-buffer (car reparse))
638 (let ((compilation-last-buffer (current-buffer)) ;select buffer
639 ;; Record the position in the compilation buffer of
640 ;; the last error next-error went to.
641 (error-pos (marker-position
642 (car (car-safe compilation-error-list)))))
643 ;; Reparse the error messages as far as they were parsed before.
644 (compile-reinitialize-errors '(4) compilation-parsing-end)
645 ;; Move the pointer up to find the error we were at before
646 ;; reparsing. Now next-error should properly go to the next one.
647 (while (and compilation-error-list
648 (/= error-pos (car (car compilation-error-list))))
649 (setq compilation-error-list (cdr compilation-error-list))))))
650 (setq reparse (cdr reparse)))
652 ;; Restore point and mark
653 (let ((new-point (vc-find-position-by-context point-context)))
654 (if new-point (goto-char new-point)))
655 (if mark-context
656 (let ((new-mark (vc-find-position-by-context mark-context)))
657 (if new-mark (set-mark new-mark))))))
659 (defun vc-revert-buffer1 (&optional arg no-confirm)
660 ;; Revert buffer, try to keep point and mark where user expects them in spite
661 ;; of changes because of expanded version-control key words.
662 ;; This is quite important since otherwise typeahead won't work as expected.
663 (interactive "P")
664 (widen)
665 (let ((context (vc-buffer-context)))
666 ;; t means don't call normal-mode; that's to preserve various minor modes.
667 (revert-buffer arg no-confirm t)
668 (vc-restore-buffer-context context)))
671 (defun vc-buffer-sync (&optional not-urgent)
672 ;; Make sure the current buffer and its working file are in sync
673 ;; NOT-URGENT means it is ok to continue if the user says not to save.
674 (if (buffer-modified-p)
675 (if (or vc-suppress-confirm
676 (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name))))
677 (save-buffer)
678 (if not-urgent
680 (error "Aborted")))))
683 (defun vc-workfile-unchanged-p (file &optional want-differences-if-changed)
684 ;; Has the given workfile changed since last checkout?
685 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time))
686 (lastmod (nth 5 (file-attributes file))))
687 (or (equal checkout-time lastmod)
688 (and (or (not checkout-time) want-differences-if-changed)
689 (let ((unchanged (zerop (vc-backend-diff file nil nil
690 (not want-differences-if-changed)))))
691 ;; 0 stands for an unknown time; it can't match any mod time.
692 (vc-file-setprop file 'vc-checkout-time (if unchanged lastmod 0))
693 unchanged)))))
695 (defun vc-next-action-on-file (file verbose &optional comment)
696 ;;; If comment is specified, it will be used as an admin or checkin comment.
697 (let ((vc-file (vc-name file))
698 (vc-type (vc-backend file))
699 owner version buffer)
700 (cond
702 ;; if there is no master file corresponding, create one
703 ((not vc-file)
704 (vc-register verbose comment)
705 (if vc-initial-comment
706 (setq vc-log-after-operation-hook
707 'vc-checkout-writable-buffer-hook)
708 (vc-checkout-writable-buffer file)))
710 ;; CVS: changes to the master file need to be
711 ;; merged back into the working file
712 ((and (eq vc-type 'CVS)
713 (or (eq (vc-cvs-status file) 'needs-checkout)
714 (eq (vc-cvs-status file) 'needs-merge)))
715 (if (or vc-dired-mode
716 (yes-or-no-p
717 (format "%s is not up-to-date. Merge in changes now? "
718 (buffer-name))))
719 (progn
720 (if vc-dired-mode
721 (and (setq buffer (get-file-buffer file))
722 (buffer-modified-p buffer)
723 (switch-to-buffer-other-window buffer)
724 (vc-buffer-sync t))
725 (setq buffer (current-buffer))
726 (vc-buffer-sync t))
727 (if (and buffer (buffer-modified-p buffer)
728 (not (yes-or-no-p
729 (format
730 "Buffer %s modified; merge file on disc anyhow? "
731 (buffer-name buffer)))))
732 (error "Merge aborted"))
733 (if (not (zerop (vc-backend-merge-news file)))
734 ;; Overlaps detected - what now? Should use some
735 ;; fancy RCS conflict resolving package, or maybe
736 ;; emerge, but for now, simply warn the user with a
737 ;; message.
738 (message "Conflicts detected!"))
739 (and buffer
740 (vc-resynch-buffer file t (not (buffer-modified-p buffer)))))
741 (error "%s needs update" (buffer-name))))
743 ;; If there is no lock on the file, assert one and get it.
744 ;; (With implicit checkout, make sure not to lose unsaved changes.)
745 ((progn (and (eq (vc-checkout-model file) 'implicit)
746 (buffer-modified-p buffer)
747 (vc-buffer-sync))
748 (not (setq owner (vc-locking-user file))))
749 (if (and vc-checkout-carefully
750 (not (vc-workfile-unchanged-p file t)))
751 (if (save-window-excursion
752 (pop-to-buffer "*vc-diff*")
753 (goto-char (point-min))
754 (insert-string (format "Changes to %s since last lock:\n\n"
755 file))
756 (not (beep))
757 (yes-or-no-p
758 (concat "File has unlocked changes, "
759 "claim lock retaining changes? ")))
760 (progn (vc-backend-steal file)
761 (vc-mode-line file))
762 (if (not (yes-or-no-p "Revert to checked-in version, instead? "))
763 (error "Checkout aborted")
764 (vc-revert-buffer1 t t)
765 (vc-checkout-writable-buffer file))
767 (if verbose
768 (if (not (eq vc-type 'SCCS))
769 (vc-checkout file nil
770 (read-string "Branch or version to move to: "))
771 (error "Sorry, this is not implemented for SCCS"))
772 (if (vc-latest-on-branch-p file)
773 (vc-checkout-writable-buffer file)
774 (if (yes-or-no-p
775 "This is not the latest version. Really lock it? ")
776 (vc-checkout-writable-buffer file)
777 (if (yes-or-no-p "Lock the latest version instead? ")
778 (vc-checkout-writable-buffer file
779 (if (vc-trunk-p (vc-workfile-version file))
780 "" ;; this means check out latest on trunk
781 (vc-branch-part (vc-workfile-version file)))))))
784 ;; a checked-out version exists, but the user may not own the lock
785 ((and (not (eq vc-type 'CVS))
786 (not (string-equal owner (vc-user-login-name))))
787 (if comment
788 (error "Sorry, you can't steal the lock on %s this way" file))
789 (and (eq vc-type 'RCS)
790 (not (vc-backend-release-p 'RCS "5.6.2"))
791 (error "File is locked by %s" owner))
792 (vc-steal-lock
793 file
794 (if verbose (read-string "Version to steal: ")
795 (vc-workfile-version file))
796 owner))
798 ;; OK, user owns the lock on the file
800 (if vc-dired-mode
801 (find-file-other-window file)
802 (find-file file))
804 ;; give luser a chance to save before checking in.
805 (vc-buffer-sync)
807 ;; Revert if file is unchanged and buffer is too.
808 ;; If buffer is modified, that means the user just said no
809 ;; to saving it; in that case, don't revert,
810 ;; because the user might intend to save
811 ;; after finishing the log entry.
812 (if (and (vc-workfile-unchanged-p file)
813 (not (buffer-modified-p)))
814 ;; DO NOT revert the file without asking the user!
815 (cond
816 ((yes-or-no-p "Revert to master version? ")
817 (vc-backend-revert file)
818 (vc-resynch-window file t t)))
820 ;; user may want to set nonstandard parameters
821 (if verbose
822 (setq version (read-string "New version level: ")))
824 ;; OK, let's do the checkin
825 (vc-checkin file version comment)
826 )))))
828 (defun vc-next-action-dired (file rev comment)
829 ;; Do a vc-next-action-on-file on all the marked files, possibly
830 ;; passing on the log comment we've just entered.
831 (let ((configuration (current-window-configuration))
832 (dired-buffer (current-buffer))
833 (dired-dir default-directory))
834 (dired-map-over-marks
835 (let ((file (dired-get-filename)) p
836 (default-directory default-directory))
837 (message "Processing %s..." file)
838 ;; Adjust the default directory so that checkouts
839 ;; go to the right place.
840 (setq default-directory (file-name-directory file))
841 (vc-next-action-on-file file nil comment)
842 (set-buffer dired-buffer)
843 (setq default-directory dired-dir)
844 (vc-dired-update-line file)
845 (set-window-configuration configuration)
846 (message "Processing %s...done" file))
847 nil t)))
849 ;; Here's the major entry point.
851 ;;;###autoload
852 (defun vc-next-action (verbose)
853 "Do the next logical checkin or checkout operation on the current file.
854 If you call this from within a VC dired buffer with no files marked,
855 it will operate on the file in the current line.
856 If you call this from within a VC dired buffer, and one or more
857 files are marked, it will accept a log message and then operate on
858 each one. The log message will be used as a comment for any register
859 or checkin operations, but ignored when doing checkouts. Attempted
860 lock steals will raise an error.
861 A prefix argument lets you specify the version number to use.
863 For RCS and SCCS files:
864 If the file is not already registered, this registers it for version
865 control and then retrieves a writable, locked copy for editing.
866 If the file is registered and not locked by anyone, this checks out
867 a writable and locked file ready for editing.
868 If the file is checked out and locked by the calling user, this
869 first checks to see if the file has changed since checkout. If not,
870 it performs a revert.
871 If the file has been changed, this pops up a buffer for entry
872 of a log message; when the message has been entered, it checks in the
873 resulting changes along with the log message as change commentary. If
874 the variable `vc-keep-workfiles' is non-nil (which is its default), a
875 read-only copy of the changed file is left in place afterwards.
876 If the file is registered and locked by someone else, you are given
877 the option to steal the lock.
879 For CVS files:
880 If the file is not already registered, this registers it for version
881 control. This does a \"cvs add\", but no \"cvs commit\".
882 If the file is added but not committed, it is committed.
883 If your working file is changed, but the repository file is
884 unchanged, this pops up a buffer for entry of a log message; when the
885 message has been entered, it checks in the resulting changes along
886 with the logmessage as change commentary. A writable file is retained.
887 If the repository file is changed, you are asked if you want to
888 merge in the changes into your working copy."
890 (interactive "P")
891 (catch 'nogo
892 (if vc-dired-mode
893 (let ((files (dired-get-marked-files)))
894 (if (string= ""
895 (mapconcat
896 (function (lambda (f)
897 (if (eq (vc-backend f) 'CVS)
898 (if (or (eq (vc-cvs-status f) 'locally-modified)
899 (eq (vc-cvs-status f) 'locally-added))
900 "@" "")
901 (if (vc-locking-user f) "@" ""))))
902 files ""))
903 (vc-next-action-dired nil nil "dummy")
904 (vc-start-entry nil nil nil
905 "Enter a change comment for the marked files."
906 'vc-next-action-dired))
907 (throw 'nogo nil)))
908 (while vc-parent-buffer
909 (pop-to-buffer vc-parent-buffer))
910 (if buffer-file-name
911 (vc-next-action-on-file buffer-file-name verbose)
912 (vc-registration-error nil))))
914 ;;; These functions help the vc-next-action entry point
916 (defun vc-checkout-writable-buffer (&optional file rev)
917 "Retrieve a writable copy of the latest version of the current buffer's file."
918 (vc-checkout (or file (buffer-file-name)) t rev)
921 ;;;###autoload
922 (defun vc-register (&optional override comment)
923 "Register the current file into your version-control system."
924 (interactive "P")
925 (or buffer-file-name
926 (error "No visited file"))
927 (let ((master (vc-name buffer-file-name)))
928 (and master (file-exists-p master)
929 (error "This file is already registered"))
930 (and master
931 (not (y-or-n-p "Previous master file has vanished. Make a new one? "))
932 (error "This file is already registered")))
933 ;; Watch out for new buffers of size 0: the corresponding file
934 ;; does not exist yet, even though buffer-modified-p is nil.
935 (if (and (not (buffer-modified-p))
936 (zerop (buffer-size))
937 (not (file-exists-p buffer-file-name)))
938 (set-buffer-modified-p t))
939 (vc-buffer-sync)
940 (cond ((not vc-make-backup-files)
941 ;; inhibit backup for this buffer
942 (make-local-variable 'backup-inhibited)
943 (setq backup-inhibited t)))
944 (vc-admin
945 buffer-file-name
946 (and override
947 (read-string
948 (format "Initial version level for %s: " buffer-file-name))))
951 (defun vc-resynch-window (file &optional keep noquery)
952 ;; If the given file is in the current buffer,
953 ;; either revert on it so we see expanded keywords,
954 ;; or unvisit it (depending on vc-keep-workfiles)
955 ;; NOQUERY if non-nil inhibits confirmation for reverting.
956 ;; NOQUERY should be t *only* if it is known the only difference
957 ;; between the buffer and the file is due to RCS rather than user editing!
958 (and (string= buffer-file-name file)
959 (if keep
960 (progn
961 ;; temporarily remove vc-find-file-hook, so that
962 ;; we don't lose the properties
963 (remove-hook 'find-file-hooks 'vc-find-file-hook)
964 (vc-revert-buffer1 t noquery)
965 (add-hook 'find-file-hooks 'vc-find-file-hook)
966 (vc-mode-line buffer-file-name))
967 (kill-buffer (current-buffer)))))
969 (defun vc-resynch-buffer (file &optional keep noquery)
970 ;; if FILE is currently visited, resynch its buffer
971 (let ((buffer (get-file-buffer file)))
972 (if buffer
973 (save-excursion
974 (set-buffer buffer)
975 (vc-resynch-window file keep noquery)))))
977 (defun vc-start-entry (file rev comment msg action &optional after-hook)
978 ;; Accept a comment for an operation on FILE revision REV. If COMMENT
979 ;; is nil, pop up a VC-log buffer, emit MSG, and set the
980 ;; action on close to ACTION; otherwise, do action immediately.
981 ;; Remember the file's buffer in vc-parent-buffer (current one if no file).
982 ;; AFTER-HOOK specifies the local value for vc-log-operation-hook.
983 (let ((parent (if file (find-file-noselect file) (current-buffer))))
984 (if vc-before-checkin-hook
985 (if file
986 (save-excursion
987 (set-buffer parent)
988 (run-hooks 'vc-before-checkin-hook))
989 (run-hooks 'vc-before-checkin-hook)))
990 (if comment
991 (set-buffer (get-buffer-create "*VC-log*"))
992 (pop-to-buffer (get-buffer-create "*VC-log*")))
993 (set (make-local-variable 'vc-parent-buffer) parent)
994 (set (make-local-variable 'vc-parent-buffer-name)
995 (concat " from " (buffer-name vc-parent-buffer)))
996 (if file (vc-mode-line file))
997 (vc-log-mode file)
998 (make-local-variable 'vc-log-after-operation-hook)
999 (if after-hook
1000 (setq vc-log-after-operation-hook after-hook))
1001 (setq vc-log-operation action)
1002 (setq vc-log-version rev)
1003 (if comment
1004 (progn
1005 (erase-buffer)
1006 (if (eq comment t)
1007 (vc-finish-logentry t)
1008 (insert comment)
1009 (vc-finish-logentry nil)))
1010 (message "%s Type C-c C-c when done." msg))))
1012 (defun vc-admin (file rev &optional comment)
1013 "Check a file into your version-control system.
1014 FILE is the unmodified name of the file. REV should be the base version
1015 level to check it in under. COMMENT, if specified, is the checkin comment."
1016 (vc-start-entry file rev
1017 (or comment (not vc-initial-comment))
1018 "Enter initial comment." 'vc-backend-admin
1019 nil))
1021 (defun vc-checkout (file &optional writable rev)
1022 "Retrieve a copy of the latest version of the given file."
1023 ;; If ftp is on this system and the name matches the ange-ftp format
1024 ;; for a remote file, the user is trying something that won't work.
1025 (if (and (string-match "^/[^/:]+:" file) (vc-find-binary "ftp"))
1026 (error "Sorry, you can't check out files over FTP"))
1027 (vc-backend-checkout file writable rev)
1028 (vc-resynch-buffer file t t))
1030 (defun vc-steal-lock (file rev &optional owner)
1031 "Steal the lock on the current workfile."
1032 (let (file-description)
1033 (if (not owner)
1034 (setq owner (vc-locking-user file)))
1035 (if rev
1036 (setq file-description (format "%s:%s" file rev))
1037 (setq file-description file))
1038 (if (not (yes-or-no-p (format "Steal the lock on %s from %s? "
1039 file-description owner)))
1040 (error "Steal cancelled"))
1041 (pop-to-buffer (get-buffer-create "*VC-mail*"))
1042 (setq default-directory (expand-file-name "~/"))
1043 (auto-save-mode auto-save-default)
1044 (mail-mode)
1045 (erase-buffer)
1046 (mail-setup owner (format "Stolen lock on %s" file-description) nil nil nil
1047 (list (list 'vc-finish-steal file rev)))
1048 (goto-char (point-max))
1049 (insert
1050 (format "I stole the lock on %s, " file-description)
1051 (current-time-string)
1052 ".\n")
1053 (message "Please explain why you stole the lock. Type C-c C-c when done.")))
1055 ;; This is called when the notification has been sent.
1056 (defun vc-finish-steal (file version)
1057 (vc-backend-steal file version)
1058 (if (get-file-buffer file)
1059 (save-excursion
1060 (set-buffer (get-file-buffer file))
1061 (vc-resynch-window file t t))))
1063 (defun vc-checkin (file &optional rev comment)
1064 "Check in the file specified by FILE.
1065 The optional argument REV may be a string specifying the new version level
1066 \(if nil increment the current level). The file is either retained with write
1067 permissions zeroed, or deleted (according to the value of `vc-keep-workfiles').
1068 If the back-end is CVS, a writable workfile is always kept.
1069 COMMENT is a comment string; if omitted, a buffer is
1070 popped up to accept a comment."
1071 (vc-start-entry file rev comment
1072 "Enter a change comment." 'vc-backend-checkin
1073 'vc-checkin-hook))
1075 ;;; Here is a checkin hook that may prove useful to sites using the
1076 ;;; ChangeLog facility supported by Emacs.
1077 (defun vc-comment-to-change-log (&optional whoami file-name)
1078 "Enter last VC comment into change log file for current buffer's file.
1079 Optional arg (interactive prefix) non-nil means prompt for user name and site.
1080 Second arg is file name of change log. \
1081 If nil, uses `change-log-default-name'."
1082 (interactive (if current-prefix-arg
1083 (list current-prefix-arg
1084 (prompt-for-change-log-name))))
1085 ;; Make sure the defvar for add-log-current-defun-function has been executed
1086 ;; before binding it.
1087 (require 'add-log)
1088 (let (;; Extract the comment first so we get any error before doing anything.
1089 (comment (ring-ref vc-comment-ring 0))
1090 ;; Don't let add-change-log-entry insert a defun name.
1091 (add-log-current-defun-function 'ignore)
1092 end)
1093 ;; Call add-log to do half the work.
1094 (add-change-log-entry whoami file-name t t)
1095 ;; Insert the VC comment, leaving point before it.
1096 (setq end (save-excursion (insert comment) (point-marker)))
1097 (if (looking-at "\\s *\\s(")
1098 ;; It starts with an open-paren, as in "(foo): Frobbed."
1099 ;; So remove the ": " add-log inserted.
1100 (delete-char -2))
1101 ;; Canonicalize the white space between the file name and comment.
1102 (just-one-space)
1103 ;; Indent rest of the text the same way add-log indented the first line.
1104 (let ((indentation (current-indentation)))
1105 (save-excursion
1106 (while (< (point) end)
1107 (forward-line 1)
1108 (indent-to indentation))
1109 (setq end (point))))
1110 ;; Fill the inserted text, preserving open-parens at bol.
1111 (let ((paragraph-separate (concat paragraph-separate "\\|\\s *\\s("))
1112 (paragraph-start (concat paragraph-start "\\|\\s *\\s(")))
1113 (beginning-of-line)
1114 (fill-region (point) end))
1115 ;; Canonicalize the white space at the end of the entry so it is
1116 ;; separated from the next entry by a single blank line.
1117 (skip-syntax-forward " " end)
1118 (delete-char (- (skip-syntax-backward " ")))
1119 (or (eobp) (looking-at "\n\n")
1120 (insert "\n"))))
1123 (defun vc-finish-logentry (&optional nocomment)
1124 "Complete the operation implied by the current log entry."
1125 (interactive)
1126 ;; Check and record the comment, if any.
1127 (if (not nocomment)
1128 (progn
1129 (goto-char (point-max))
1130 (if (not (bolp))
1131 (newline))
1132 ;; Comment too long?
1133 (vc-backend-logentry-check vc-log-file)
1134 ;; Record the comment in the comment ring
1135 (ring-insert vc-comment-ring (buffer-string))
1137 ;; Sync parent buffer in case the user modified it while editing the comment.
1138 ;; But not if it is a vc-dired buffer.
1139 (save-excursion
1140 (set-buffer vc-parent-buffer)
1141 (or vc-dired-mode
1142 (vc-buffer-sync)))
1143 (if (not vc-log-operation) (error "No log operation is pending"))
1144 ;; save the parameters held in buffer-local variables
1145 (let ((log-operation vc-log-operation)
1146 (log-file vc-log-file)
1147 (log-version vc-log-version)
1148 (log-entry (buffer-string))
1149 (after-hook vc-log-after-operation-hook))
1150 ;; Return to "parent" buffer of this checkin and remove checkin window
1151 (pop-to-buffer vc-parent-buffer)
1152 (let ((logbuf (get-buffer "*VC-log*")))
1153 (delete-windows-on logbuf)
1154 (kill-buffer logbuf))
1155 ;; OK, do it to it
1156 (save-excursion
1157 (funcall log-operation
1158 log-file
1159 log-version
1160 log-entry))
1161 ;; Now make sure we see the expanded headers
1162 (if buffer-file-name
1163 (vc-resynch-window buffer-file-name vc-keep-workfiles t))
1164 (run-hooks after-hook 'vc-finish-logentry-hook)))
1166 ;; Code for access to the comment ring
1168 (defun vc-previous-comment (arg)
1169 "Cycle backwards through comment history."
1170 (interactive "*p")
1171 (let ((len (ring-length vc-comment-ring)))
1172 (cond ((<= len 0)
1173 (message "Empty comment ring")
1174 (ding))
1176 (erase-buffer)
1177 ;; Initialize the index on the first use of this command
1178 ;; so that the first M-p gets index 0, and the first M-n gets
1179 ;; index -1.
1180 (if (null vc-comment-ring-index)
1181 (setq vc-comment-ring-index
1182 (if (> arg 0) -1
1183 (if (< arg 0) 1 0))))
1184 (setq vc-comment-ring-index
1185 (mod (+ vc-comment-ring-index arg) len))
1186 (message "%d" (1+ vc-comment-ring-index))
1187 (insert (ring-ref vc-comment-ring vc-comment-ring-index))))))
1189 (defun vc-next-comment (arg)
1190 "Cycle forwards through comment history."
1191 (interactive "*p")
1192 (vc-previous-comment (- arg)))
1194 (defun vc-comment-search-reverse (str)
1195 "Searches backwards through comment history for substring match."
1196 (interactive "sComment substring: ")
1197 (if (string= str "")
1198 (setq str vc-last-comment-match)
1199 (setq vc-last-comment-match str))
1200 (if (null vc-comment-ring-index)
1201 (setq vc-comment-ring-index -1))
1202 (let ((str (regexp-quote str))
1203 (len (ring-length vc-comment-ring))
1204 (n (1+ vc-comment-ring-index)))
1205 (while (and (< n len) (not (string-match str (ring-ref vc-comment-ring n))))
1206 (setq n (+ n 1)))
1207 (cond ((< n len)
1208 (vc-previous-comment (- n vc-comment-ring-index)))
1209 (t (error "Not found")))))
1211 (defun vc-comment-search-forward (str)
1212 "Searches forwards through comment history for substring match."
1213 (interactive "sComment substring: ")
1214 (if (string= str "")
1215 (setq str vc-last-comment-match)
1216 (setq vc-last-comment-match str))
1217 (if (null vc-comment-ring-index)
1218 (setq vc-comment-ring-index 0))
1219 (let ((str (regexp-quote str))
1220 (len (ring-length vc-comment-ring))
1221 (n vc-comment-ring-index))
1222 (while (and (>= n 0) (not (string-match str (ring-ref vc-comment-ring n))))
1223 (setq n (- n 1)))
1224 (cond ((>= n 0)
1225 (vc-next-comment (- n vc-comment-ring-index)))
1226 (t (error "Not found")))))
1228 ;; Additional entry points for examining version histories
1230 ;;;###autoload
1231 (defun vc-diff (historic &optional not-urgent)
1232 "Display diffs between file versions.
1233 Normally this compares the current file and buffer with the most recent
1234 checked in version of that file. This uses no arguments.
1235 With a prefix argument, it reads the file name to use
1236 and two version designators specifying which versions to compare."
1237 (interactive (list current-prefix-arg t))
1238 (if vc-dired-mode
1239 (set-buffer (find-file-noselect (dired-get-filename))))
1240 (while vc-parent-buffer
1241 (pop-to-buffer vc-parent-buffer))
1242 (if historic
1243 (call-interactively 'vc-version-diff)
1244 (if (or (null buffer-file-name) (null (vc-name buffer-file-name)))
1245 (error
1246 "There is no version-control master associated with this buffer"))
1247 (let ((file buffer-file-name)
1248 unchanged)
1249 (or (and file (vc-name file))
1250 (vc-registration-error file))
1251 (vc-buffer-sync not-urgent)
1252 (setq unchanged (vc-workfile-unchanged-p buffer-file-name))
1253 (if unchanged
1254 (message "No changes to %s since latest version" file)
1255 (vc-backend-diff file)
1256 ;; Ideally, we'd like at this point to parse the diff so that
1257 ;; the buffer effectively goes into compilation mode and we
1258 ;; can visit the old and new change locations via next-error.
1259 ;; Unfortunately, this is just too painful to do. The basic
1260 ;; problem is that the `old' file doesn't exist to be
1261 ;; visited. This plays hell with numerous assumptions in
1262 ;; the diff.el and compile.el machinery.
1263 (set-buffer "*vc-diff*")
1264 (setq default-directory (file-name-directory file))
1265 (if (= 0 (buffer-size))
1266 (progn
1267 (setq unchanged t)
1268 (message "No changes to %s since latest version" file))
1269 (pop-to-buffer "*vc-diff*")
1270 (goto-char (point-min))
1271 (shrink-window-if-larger-than-buffer)))
1272 (not unchanged))))
1274 (defun vc-version-diff (file rel1 rel2)
1275 "For FILE, report diffs between two stored versions REL1 and REL2 of it.
1276 If FILE is a directory, generate diffs between versions for all registered
1277 files in or below it."
1278 (interactive "FFile or directory to diff: \nsOlder version: \nsNewer version: ")
1279 (if (string-equal rel1 "") (setq rel1 nil))
1280 (if (string-equal rel2 "") (setq rel2 nil))
1281 (if (file-directory-p file)
1282 (let ((camefrom (current-buffer)))
1283 (set-buffer (get-buffer-create "*vc-status*"))
1284 (set (make-local-variable 'vc-parent-buffer) camefrom)
1285 (set (make-local-variable 'vc-parent-buffer-name)
1286 (concat " from " (buffer-name camefrom)))
1287 (erase-buffer)
1288 (insert "Diffs between "
1289 (or rel1 "last version checked in")
1290 " and "
1291 (or rel2 "current workfile(s)")
1292 ":\n\n")
1293 (set-buffer (get-buffer-create "*vc-diff*"))
1294 (cd file)
1295 (vc-file-tree-walk
1296 default-directory
1297 (function (lambda (f)
1298 (message "Looking at %s" f)
1299 (and
1300 (not (file-directory-p f))
1301 (vc-registered f)
1302 (vc-backend-diff f rel1 rel2)
1303 (append-to-buffer "*vc-status*" (point-min) (point-max)))
1305 (pop-to-buffer "*vc-status*")
1306 (insert "\nEnd of diffs.\n")
1307 (goto-char (point-min))
1308 (set-buffer-modified-p nil)
1310 (if (zerop (vc-backend-diff file rel1 rel2))
1311 (message "No changes to %s between %s and %s." file rel1 rel2)
1312 (pop-to-buffer "*vc-diff*"))))
1314 ;;;###autoload
1315 (defun vc-version-other-window (rev)
1316 "Visit version REV of the current buffer in another window.
1317 If the current buffer is named `F', the version is named `F.~REV~'.
1318 If `F.~REV~' already exists, it is used instead of being re-created."
1319 (interactive "sVersion to visit (default is latest version): ")
1320 (if vc-dired-mode
1321 (set-buffer (find-file-noselect (dired-get-filename))))
1322 (while vc-parent-buffer
1323 (pop-to-buffer vc-parent-buffer))
1324 (if (and buffer-file-name (vc-name buffer-file-name))
1325 (let* ((version (if (string-equal rev "")
1326 (vc-latest-version buffer-file-name)
1327 rev))
1328 (filename (concat buffer-file-name ".~" version "~")))
1329 (or (file-exists-p filename)
1330 (vc-backend-checkout buffer-file-name nil version filename))
1331 (find-file-other-window filename))
1332 (vc-registration-error buffer-file-name)))
1334 ;; Header-insertion code
1336 ;;;###autoload
1337 (defun vc-insert-headers ()
1338 "Insert headers in a file for use with your version-control system.
1339 Headers desired are inserted at the start of the buffer, and are pulled from
1340 the variable `vc-header-alist'."
1341 (interactive)
1342 (if vc-dired-mode
1343 (find-file-other-window (dired-get-filename)))
1344 (while vc-parent-buffer
1345 (pop-to-buffer vc-parent-buffer))
1346 (save-excursion
1347 (save-restriction
1348 (widen)
1349 (if (or (not (vc-check-headers))
1350 (y-or-n-p "Version headers already exist. Insert another set? "))
1351 (progn
1352 (let* ((delims (cdr (assq major-mode vc-comment-alist)))
1353 (comment-start-vc (or (car delims) comment-start "#"))
1354 (comment-end-vc (or (car (cdr delims)) comment-end ""))
1355 (hdstrings (cdr (assoc (vc-backend (buffer-file-name)) vc-header-alist))))
1356 (mapcar (function (lambda (s)
1357 (insert comment-start-vc "\t" s "\t"
1358 comment-end-vc "\n")))
1359 hdstrings)
1360 (if vc-static-header-alist
1361 (mapcar (function (lambda (f)
1362 (if (string-match (car f) buffer-file-name)
1363 (insert (format (cdr f) (car hdstrings))))))
1364 vc-static-header-alist))
1366 )))))
1368 (defun vc-clear-headers ()
1369 ;; Clear all version headers in the current buffer, i.e. reset them
1370 ;; to the nonexpanded form. Only implemented for RCS, yet.
1371 ;; Don't lose point and mark during this.
1372 (let ((context (vc-buffer-context)))
1373 (goto-char (point-min))
1374 (while (re-search-forward "\\$\\([A-Za-z]+\\): [^\\$]+\\$" nil t)
1375 (replace-match "$\\1$"))
1376 (vc-restore-buffer-context context)))
1378 ;; The VC directory major mode. Coopt Dired for this.
1379 ;; All VC commands get mapped into logical equivalents.
1381 (define-derived-mode vc-dired-mode dired-mode "Dired under VC"
1382 "The major mode used in VC directory buffers. It is derived from Dired.
1383 All Dired commands operate normally. Users currently locking listed files
1384 are listed in place of the file's owner and group.
1385 Keystrokes bound to VC commands will execute as though they had been called
1386 on a buffer attached to the file named in the current Dired buffer line."
1387 (setq vc-dired-mode t))
1389 (define-key vc-dired-mode-map "\C-xv" vc-prefix-map)
1390 (define-key vc-dired-mode-map "g" 'vc-dired-update)
1391 (define-key vc-dired-mode-map "=" 'vc-diff)
1393 (defun vc-dired-state-info (file)
1394 ;; Return the string that indicates the version control status
1395 ;; on a VC dired line.
1396 (let ((cvs-state (and (eq (vc-backend file) 'CVS)
1397 (vc-cvs-status file))))
1398 (if cvs-state
1399 (cond ((eq cvs-state 'up-to-date) nil)
1400 ((eq cvs-state 'needs-checkout) "patch")
1401 ((eq cvs-state 'locally-modified) "modified")
1402 ((eq cvs-state 'needs-merge) "merge")
1403 ((eq cvs-state 'unresolved-conflict) "conflict")
1404 ((eq cvs-state 'locally-added) "added"))
1405 (vc-locking-user file))))
1407 (defun vc-dired-reformat-line (x)
1408 ;; Hack a directory-listing line, plugging in locking-user info in
1409 ;; place of the user and group info. Should have the beneficial
1410 ;; side-effect of shortening the listing line. Each call starts with
1411 ;; point immediately following the dired mark area on the line to be
1412 ;; hacked.
1414 ;; Simplest possible one:
1415 ;; (insert (concat x "\t")))
1417 ;; This code, like dired, assumes UNIX -l format.
1418 (let ((pos (point)) limit perm owner date-and-file)
1419 (end-of-line)
1420 (setq limit (point))
1421 (goto-char pos)
1422 (cond
1423 ((or
1424 (re-search-forward ;; owner and group
1425 "\\([drwxlts-]+ \\) *[0-9]+ \\([^ ]+\\) +[^ ]+ +[0-9]+\\( [^ 0-9]+ [0-9 ][0-9] .*\\)"
1426 limit t)
1427 (re-search-forward ;; only owner displayed
1428 "\\([drwxlts-]+ \\) *[0-9]+ \\([^ ]+\\) +[0-9]+\\( [^ 0-9]+ [0-9 ][0-9] .*\\)"
1429 limit t))
1430 (setq perm (match-string 1)
1431 owner (match-string 2)
1432 date-and-file (match-string 3)))
1433 ((re-search-forward ;; OS/2 -l format, no links, owner, group
1434 "\\([drwxlts-]+ \\) *[0-9]+\\( [^ 0-9]+ [0-9 ][0-9] .*\\)"
1435 limit t)
1436 (setq perm (match-string 1)
1437 date-and-file (match-string 2))))
1438 (if x (setq x (concat "(" x ")")))
1439 (let ((rep (substring (concat x " ") 0 10)))
1440 (replace-match (concat perm rep date-and-file)))))
1442 (defun vc-dired-update-line (file)
1443 ;; Update the vc-dired listing line of file -- it is assumed
1444 ;; that point is already on this line. Don't use dired-do-redisplay
1445 ;; for this, because it cannot handle the way vc-dired deals with
1446 ;; subdirectories.
1447 (beginning-of-line)
1448 (forward-char 2)
1449 (let ((start (point)))
1450 (forward-line 1)
1451 (beginning-of-line)
1452 (delete-region start (point))
1453 (insert-directory file dired-listing-switches)
1454 (forward-line -1)
1455 (end-of-line)
1456 (delete-char (- (length file)))
1457 (insert (substring file (length (expand-file-name default-directory))))
1458 (goto-char start))
1459 (vc-dired-reformat-line (vc-dired-state-info file)))
1461 (defun vc-dired-update (verbose)
1462 (interactive "P")
1463 (vc-directory default-directory verbose))
1465 ;;; Note in Emacs 18 the following defun gets overridden
1466 ;;; with the symbol 'vc-directory-18. See below.
1467 ;;;###autoload
1468 (defun vc-directory (dirname verbose)
1469 "Show version-control status of the current directory and subdirectories.
1470 Normally it creates a Dired buffer that lists only the locked files
1471 in all these directories. With a prefix argument, it lists all files."
1472 (interactive "DDired under VC (directory): \nP")
1473 (require 'dired)
1474 (setq dirname (expand-file-name dirname))
1475 ;; force a trailing slash
1476 (if (not (eq (elt dirname (1- (length dirname))) ?/))
1477 (setq dirname (concat dirname "/")))
1478 (let (nonempty
1479 (dl (length dirname))
1480 (filelist nil) (statelist nil)
1481 (old-dir default-directory)
1482 dired-buf
1483 dired-buf-mod-count)
1484 (vc-file-tree-walk
1485 dirname
1486 (function
1487 (lambda (f)
1488 (if (vc-registered f)
1489 (let ((state (vc-dired-state-info f)))
1490 (and (or verbose state)
1491 (setq filelist (cons (substring f dl) filelist))
1492 (setq statelist (cons state statelist))))))))
1493 (save-window-excursion
1494 (save-excursion
1495 ;; This uses a semi-documented feature of dired; giving a switch
1496 ;; argument forces the buffer to refresh each time.
1497 (setq dired-buf
1498 (dired-internal-noselect
1499 (cons dirname (nreverse filelist))
1500 dired-listing-switches 'vc-dired-mode))
1501 (setq nonempty (not (eq 0 (length filelist))))))
1502 (switch-to-buffer dired-buf)
1503 ;; Make a few modifications to the header
1504 (setq buffer-read-only nil)
1505 (goto-char (point-min))
1506 (forward-line 1) ;; Skip header line
1507 (let ((start (point))) ;; Erase (but don't remove) the
1508 (end-of-line) ;; "wildcard" line.
1509 (delete-region start (point)))
1510 (beginning-of-line)
1511 (if nonempty
1512 (progn
1513 ;; Plug the version information into the individual lines
1514 (mapcar
1515 (function
1516 (lambda (x)
1517 (forward-char 2) ;; skip dired's mark area
1518 (vc-dired-reformat-line x)
1519 (forward-line 1))) ;; go to next line
1520 (nreverse statelist))
1521 (setq buffer-read-only t)
1522 (goto-char (point-min))
1523 (dired-next-line 2)
1525 (dired-next-line 1)
1526 (insert " ")
1527 (setq buffer-read-only t)
1528 (message "No files are currently %s under %s"
1529 (if verbose "registered" "locked") dirname))
1532 ;; Emacs 18 version
1533 (defun vc-directory-18 (verbose)
1534 "Show version-control status of all files under the current directory."
1535 (interactive "P")
1536 (let (nonempty (dir default-directory))
1537 (save-excursion
1538 (set-buffer (get-buffer-create "*vc-status*"))
1539 (erase-buffer)
1540 (cd dir)
1541 (vc-file-tree-walk
1542 default-directory
1543 (function (lambda (f)
1544 (if (vc-registered f)
1545 (let ((user (vc-locking-user f)))
1546 (if (or user verbose)
1547 (insert (format
1548 "%s %s\n"
1549 (concat user) f))))))))
1550 (setq nonempty (not (zerop (buffer-size)))))
1552 (if nonempty
1553 (progn
1554 (pop-to-buffer "*vc-status*" t)
1555 (goto-char (point-min))
1556 (shrink-window-if-larger-than-buffer)))
1557 (message "No files are currently %s under %s"
1558 (if verbose "registered" "locked") default-directory))
1561 (or (boundp 'minor-mode-map-alist)
1562 (fset 'vc-directory 'vc-directory-18))
1564 ;; Named-configuration support for SCCS
1566 (defun vc-add-triple (name file rev)
1567 (save-excursion
1568 (find-file (expand-file-name
1569 vc-name-assoc-file
1570 (file-name-as-directory
1571 (expand-file-name (vc-backend-subdirectory-name file)
1572 (file-name-directory file)))))
1573 (goto-char (point-max))
1574 (insert name "\t:\t" file "\t" rev "\n")
1575 (basic-save-buffer)
1576 (kill-buffer (current-buffer))
1579 (defun vc-record-rename (file newname)
1580 (save-excursion
1581 (find-file
1582 (expand-file-name
1583 vc-name-assoc-file
1584 (file-name-as-directory
1585 (expand-file-name (vc-backend-subdirectory-name file)
1586 (file-name-directory file)))))
1587 (goto-char (point-min))
1588 ;; (replace-regexp (concat ":" (regexp-quote file) "$") (concat ":" newname))
1589 (while (re-search-forward (concat ":" (regexp-quote file) "$") nil t)
1590 (replace-match (concat ":" newname) nil nil))
1591 (basic-save-buffer)
1592 (kill-buffer (current-buffer))
1595 (defun vc-lookup-triple (file name)
1596 ;; Return the numeric version corresponding to a named snapshot of file
1597 ;; If name is nil or a version number string it's just passed through
1598 (cond ((null name) name)
1599 ((let ((firstchar (aref name 0)))
1600 (and (>= firstchar ?0) (<= firstchar ?9)))
1601 name)
1603 (save-excursion
1604 (set-buffer (get-buffer-create "*vc-info*"))
1605 (vc-insert-file
1606 (expand-file-name
1607 vc-name-assoc-file
1608 (file-name-as-directory
1609 (expand-file-name (vc-backend-subdirectory-name file)
1610 (file-name-directory file)))))
1611 (prog1
1612 (car (vc-parse-buffer
1613 (list (list (concat name "\t:\t" file "\t\\(.+\\)") 1))))
1614 (kill-buffer "*vc-info*"))))
1617 ;; Named-configuration entry points
1619 (defun vc-snapshot-precondition ()
1620 ;; Scan the tree below the current directory.
1621 ;; If any files are locked, return the name of the first such file.
1622 ;; (This means, neither snapshot creation nor retrieval is allowed.)
1623 ;; If one or more of the files are currently visited, return `visited'.
1624 ;; Otherwise, return nil.
1625 (let ((status nil))
1626 (catch 'vc-locked-example
1627 (vc-file-tree-walk
1628 default-directory
1629 (function (lambda (f)
1630 (and (vc-registered f)
1631 (if (vc-locking-user f) (throw 'vc-locked-example f)
1632 (if (get-file-buffer f) (setq status 'visited)))))))
1633 status)))
1635 ;;;###autoload
1636 (defun vc-create-snapshot (name)
1637 "Make a snapshot called NAME.
1638 The snapshot is made from all registered files at or below the current
1639 directory. For each file, the version level of its latest
1640 version becomes part of the named configuration."
1641 (interactive "sNew snapshot name: ")
1642 (let ((result (vc-snapshot-precondition)))
1643 (if (stringp result)
1644 (error "File %s is locked" result)
1645 (vc-file-tree-walk
1646 default-directory
1647 (function (lambda (f) (and
1648 (vc-name f)
1649 (vc-backend-assign-name f name)))))
1652 ;;;###autoload
1653 (defun vc-retrieve-snapshot (name)
1654 "Retrieve the snapshot called NAME.
1655 This function fails if any files are locked at or below the current directory
1656 Otherwise, all registered files are checked out (unlocked) at their version
1657 levels in the snapshot."
1658 (interactive "sSnapshot name to retrieve: ")
1659 (let ((result (vc-snapshot-precondition))
1660 (update nil))
1661 (if (stringp result)
1662 (error "File %s is locked" result)
1663 (if (eq result 'visited)
1664 (setq update (yes-or-no-p "Update the affected buffers? ")))
1665 (vc-file-tree-walk
1666 default-directory
1667 (function (lambda (f) (and
1668 (vc-name f)
1669 (vc-error-occurred
1670 (vc-backend-checkout f nil name)
1671 (if update (vc-resynch-buffer f t t)))))))
1674 ;; Miscellaneous other entry points
1676 ;;;###autoload
1677 (defun vc-print-log ()
1678 "List the change log of the current buffer in a window."
1679 (interactive)
1680 (if vc-dired-mode
1681 (set-buffer (find-file-noselect (dired-get-filename))))
1682 (while vc-parent-buffer
1683 (pop-to-buffer vc-parent-buffer))
1684 (if (and buffer-file-name (vc-name buffer-file-name))
1685 (let ((file buffer-file-name))
1686 (vc-backend-print-log file)
1687 (pop-to-buffer (get-buffer-create "*vc*"))
1688 (setq default-directory (file-name-directory file))
1689 (goto-char (point-max)) (forward-line -1)
1690 (while (looking-at "=*\n")
1691 (delete-char (- (match-end 0) (match-beginning 0)))
1692 (forward-line -1))
1693 (goto-char (point-min))
1694 (if (looking-at "[\b\t\n\v\f\r ]+")
1695 (delete-char (- (match-end 0) (match-beginning 0))))
1696 (shrink-window-if-larger-than-buffer)
1697 ;; move point to the log entry for the current version
1698 (and (not (eq (vc-backend file) 'SCCS))
1699 (re-search-forward
1700 ;; also match some context, for safety
1701 (concat "----\nrevision " (vc-workfile-version file)
1702 "\\(\tlocked by:.*\n\\|\n\\)date: ") nil t)
1703 ;; set the display window so that
1704 ;; the whole log entry is displayed
1705 (let (start end lines)
1706 (beginning-of-line) (forward-line -1) (setq start (point))
1707 (if (not (re-search-forward "^----*\nrevision" nil t))
1708 (setq end (point-max))
1709 (beginning-of-line) (forward-line -1) (setq end (point)))
1710 (setq lines (count-lines start end))
1711 (cond
1712 ;; if the global information and this log entry fit
1713 ;; into the window, display from the beginning
1714 ((< (count-lines (point-min) end) (window-height))
1715 (goto-char (point-min))
1716 (recenter 0)
1717 (goto-char start))
1718 ;; if the whole entry fits into the window,
1719 ;; display it centered
1720 ((< (1+ lines) (window-height))
1721 (goto-char start)
1722 (recenter (1- (- (/ (window-height) 2) (/ lines 2)))))
1723 ;; otherwise (the entry is too large for the window),
1724 ;; display from the start
1726 (goto-char start)
1727 (recenter 0)))))
1729 (vc-registration-error buffer-file-name)
1733 ;;;###autoload
1734 (defun vc-revert-buffer ()
1735 "Revert the current buffer's file back to the latest checked-in version.
1736 This asks for confirmation if the buffer contents are not identical
1737 to that version.
1738 If the back-end is CVS, this will give you the most recent revision of
1739 the file on the branch you are editing."
1740 (interactive)
1741 (if vc-dired-mode
1742 (find-file-other-window (dired-get-filename)))
1743 (while vc-parent-buffer
1744 (pop-to-buffer vc-parent-buffer))
1745 (let ((file buffer-file-name)
1746 ;; This operation should always ask for confirmation.
1747 (vc-suppress-confirm nil)
1748 (obuf (current-buffer)) (changed (vc-diff nil t)))
1749 (if (and changed (not (yes-or-no-p "Discard changes? ")))
1750 (progn
1751 (if (and (window-dedicated-p (selected-window))
1752 (one-window-p t 'selected-frame))
1753 (make-frame-invisible (selected-frame))
1754 (delete-window))
1755 (error "Revert cancelled"))
1756 (set-buffer obuf))
1757 (if changed
1758 (if (and (window-dedicated-p (selected-window))
1759 (one-window-p t 'selected-frame))
1760 (make-frame-invisible (selected-frame))
1761 (delete-window)))
1762 (vc-backend-revert file)
1763 (vc-resynch-window file t t)
1767 ;;;###autoload
1768 (defun vc-cancel-version (norevert)
1769 "Get rid of most recently checked in version of this file.
1770 A prefix argument means do not revert the buffer afterwards."
1771 (interactive "P")
1772 (if vc-dired-mode
1773 (find-file-other-window (dired-get-filename)))
1774 (while vc-parent-buffer
1775 (pop-to-buffer vc-parent-buffer))
1776 (cond
1777 ((not (vc-registered (buffer-file-name)))
1778 (vc-registration-error (buffer-file-name)))
1779 ((eq (vc-backend (buffer-file-name)) 'CVS)
1780 (error "Unchecking files under CVS is dangerous and not supported in VC"))
1781 ((vc-locking-user (buffer-file-name))
1782 (error "This version is locked; use vc-revert-buffer to discard changes"))
1783 ((not (vc-latest-on-branch-p (buffer-file-name)))
1784 (error "This is not the latest version--VC cannot cancel it")))
1785 (let* ((target (vc-workfile-version (buffer-file-name)))
1786 (recent (if (vc-trunk-p target) "" (vc-branch-part target)))
1787 (config (current-window-configuration)) done)
1788 (if (null (yes-or-no-p (format "Remove version %s from master? " target)))
1790 (setq norevert (or norevert (not
1791 (yes-or-no-p "Revert buffer to most recent remaining version? "))))
1792 (vc-backend-uncheck (buffer-file-name) target)
1793 ;; Check out the most recent remaining version. If it fails, because
1794 ;; the whole branch got deleted, do a double-take and check out the
1795 ;; version where the branch started.
1796 (while (not done)
1797 (condition-case err
1798 (progn
1799 (if norevert
1800 ;; Check out locked, but only to disc, and keep
1801 ;; modifications in the buffer.
1802 (vc-backend-checkout (buffer-file-name) t recent)
1803 ;; Check out unlocked, and revert buffer.
1804 (vc-checkout (buffer-file-name) nil recent))
1805 (setq done t))
1806 ;; If the checkout fails, vc-do-command signals an error.
1807 ;; We catch this error, check the reason, correct the
1808 ;; version number, and try a second time.
1809 (error (set-buffer "*vc*")
1810 (goto-char (point-min))
1811 (if (search-forward "no side branches present for" nil t)
1812 (progn (setq recent (vc-branch-part recent))
1813 ;; vc-do-command popped up a window with
1814 ;; the error message. Get rid of it, by
1815 ;; restoring the old window configuration.
1816 (set-window-configuration config))
1817 ;; No, it was some other error: re-signal it.
1818 (signal (car err) (cdr err))))))
1819 ;; If norevert, clear version headers and mark the buffer modified.
1820 (if norevert
1821 (progn
1822 (set-visited-file-name (buffer-file-name))
1823 (if (not vc-make-backup-files)
1824 ;; inhibit backup for this buffer
1825 (progn (make-local-variable 'backup-inhibited)
1826 (setq backup-inhibited t)))
1827 (if (eq (vc-backend (buffer-file-name)) 'RCS)
1828 (progn (setq buffer-read-only nil)
1829 (vc-clear-headers)))
1830 (vc-mode-line (buffer-file-name))))
1831 (message "Version %s has been removed from the master" target)
1834 ;;;###autoload
1835 (defun vc-rename-file (old new)
1836 "Rename file OLD to NEW, and rename its master file likewise."
1837 (interactive "fVC rename file: \nFRename to: ")
1838 ;; There are several ways of renaming files under CVS 1.3, but they all
1839 ;; have serious disadvantages. See the FAQ (available from think.com in
1840 ;; pub/cvs/). I'd rather send the user an error, than do something he might
1841 ;; consider to be wrong. When the famous, long-awaited rename database is
1842 ;; implemented things might change for the better. This is unlikely to occur
1843 ;; until CVS 2.0 is released. --ceder 1994-01-23 21:27:51
1844 (if (eq (vc-backend old) 'CVS)
1845 (error "Renaming files under CVS is dangerous and not supported in VC"))
1846 (let ((oldbuf (get-file-buffer old)))
1847 (if (and oldbuf (buffer-modified-p oldbuf))
1848 (error "Please save files before moving them"))
1849 (if (get-file-buffer new)
1850 (error "Already editing new file name"))
1851 (if (file-exists-p new)
1852 (error "New file already exists"))
1853 (let ((oldmaster (vc-name old)))
1854 (if oldmaster
1855 (progn
1856 (if (vc-locking-user old)
1857 (error "Please check in files before moving them"))
1858 (if (or (file-symlink-p oldmaster)
1859 ;; This had FILE, I changed it to OLD. -- rms.
1860 (file-symlink-p (vc-backend-subdirectory-name old)))
1861 (error "This is not a safe thing to do in the presence of symbolic links"))
1862 (rename-file
1863 oldmaster
1864 (let ((backend (vc-backend old))
1865 (newdir (or (file-name-directory new) ""))
1866 (newbase (file-name-nondirectory new)))
1867 (catch 'found
1868 (mapcar
1869 (function
1870 (lambda (s)
1871 (if (eq backend (cdr s))
1872 (let* ((newmaster (format (car s) newdir newbase))
1873 (newmasterdir (file-name-directory newmaster)))
1874 (if (or (not newmasterdir)
1875 (file-directory-p newmasterdir))
1876 (throw 'found newmaster))))))
1877 vc-master-templates)
1878 (error "New file lacks a version control directory"))))))
1879 (if (or (not oldmaster) (file-exists-p old))
1880 (rename-file old new)))
1881 ; ?? Renaming a file might change its contents due to keyword expansion.
1882 ; We should really check out a new copy if the old copy was precisely equal
1883 ; to some checked in version. However, testing for this is tricky....
1884 (if oldbuf
1885 (save-excursion
1886 (set-buffer oldbuf)
1887 (let ((buffer-read-only buffer-read-only))
1888 (set-visited-file-name new))
1889 (vc-backend new)
1890 (vc-mode-line new)
1891 (set-buffer-modified-p nil))))
1892 ;; This had FILE, I changed it to OLD. -- rms.
1893 (vc-backend-dispatch old
1894 (vc-record-rename old new) ;SCCS
1895 nil ;RCS
1896 nil ;CVS
1900 ;;;###autoload
1901 (defun vc-update-change-log (&rest args)
1902 "Find change log file and add entries from recent RCS/CVS logs.
1903 Normally, find log entries for all registered files in the default
1904 directory using `rcs2log', which finds CVS logs preferentially.
1905 The mark is left at the end of the text prepended to the change log.
1907 With prefix arg of C-u, only find log entries for the current buffer's file.
1909 With any numeric prefix arg, find log entries for all currently visited
1910 files that are under version control. This puts all the entries in the
1911 log for the default directory, which may not be appropriate.
1913 From a program, any arguments are assumed to be filenames and are
1914 passed to the `rcs2log' script after massaging to be relative to the
1915 default directory."
1916 (interactive
1917 (cond ((consp current-prefix-arg) ;C-u
1918 (list buffer-file-name))
1919 (current-prefix-arg ;Numeric argument.
1920 (let ((files nil)
1921 (buffers (buffer-list))
1922 file)
1923 (while buffers
1924 (setq file (buffer-file-name (car buffers)))
1925 (and file (vc-backend file)
1926 (setq files (cons file files)))
1927 (setq buffers (cdr buffers)))
1928 files))
1930 ;; `rcs2log' will find the relevant RCS or CVS files
1931 ;; relative to the curent directory if none supplied.
1932 nil)))
1933 (let ((odefault default-directory)
1934 (changelog (find-change-log))
1935 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
1936 (tempfile (make-temp-name
1937 (concat (file-name-as-directory
1938 (directory-file-name (or (getenv "TMPDIR")
1939 (getenv "TMP")
1940 (getenv "TEMP")
1941 "/tmp")))
1942 "vc")))
1943 (full-name (or add-log-full-name
1944 (user-full-name)
1945 (user-login-name)
1946 (format "uid%d" (number-to-string (user-uid)))))
1947 (mailing-address (or add-log-mailing-address
1948 user-mail-address)))
1949 (find-file-other-window changelog)
1950 (barf-if-buffer-read-only)
1951 (vc-buffer-sync)
1952 (undo-boundary)
1953 (goto-char (point-min))
1954 (push-mark)
1955 (message "Computing change log entries...")
1956 (message "Computing change log entries... %s"
1957 (unwind-protect
1958 (progn
1959 (cd odefault)
1960 (if (eq 0 (apply 'call-process "rcs2log" nil
1961 (list t tempfile) nil
1962 "-c" changelog
1963 "-u" (concat (vc-user-login-name)
1964 "\t" full-name
1965 "\t" mailing-address)
1966 (mapcar
1967 (function
1968 (lambda (f)
1969 (file-relative-name
1970 (if (file-name-absolute-p f)
1972 (concat odefault f)))))
1973 args)))
1974 "done"
1975 (pop-to-buffer
1976 (set-buffer (get-buffer-create "*vc*")))
1977 (erase-buffer)
1978 (insert-file tempfile)
1979 "failed"))
1980 (cd (file-name-directory changelog))
1981 (delete-file tempfile)))))
1983 ;; vc-annotate functionality (CVS only).
1984 (defvar vc-annotate-mode nil
1985 "Variable indicating if VC-Annotate mode is active.")
1987 (defvar vc-annotate-mode-map nil
1988 "Local keymap used for VC-Annotate mode.")
1990 (defvar vc-annotate-mode-menu nil
1991 "Local keymap used for VC-Annotate mode's menu bar menu.")
1993 ;; Syntax Table
1994 (defvar vc-annotate-mode-syntax-table nil
1995 "Syntax table used in VC-Annotate mode buffers.")
1997 ;; Declare globally instead of additional parameter to
1998 ;; temp-buffer-show-function (not possible to pass more than one
1999 ;; parameter).
2000 (defvar vc-annotate-ratio nil)
2002 (defun vc-annotate-mode-variables ()
2003 (if (not vc-annotate-mode-syntax-table)
2004 (progn (setq vc-annotate-mode-syntax-table (make-syntax-table))
2005 (set-syntax-table vc-annotate-mode-syntax-table)))
2006 (if (not vc-annotate-mode-map)
2007 (setq vc-annotate-mode-map (make-sparse-keymap)))
2008 (setq vc-annotate-mode-menu (make-sparse-keymap "Annotate"))
2009 (define-key vc-annotate-mode-map [menu-bar]
2010 (make-sparse-keymap "VC-Annotate"))
2011 (define-key vc-annotate-mode-map [menu-bar vc-annotate-mode]
2012 (cons "VC-Annotate" vc-annotate-mode-menu)))
2014 (defun vc-annotate-mode ()
2015 "Major mode for buffers displaying output from the CVS `annotate' command.
2017 You can use the mode-specific menu to alter the time-span of the used
2018 colors. See variable `vc-annotate-menu-elements' for customizing the
2019 menu items."
2020 (interactive)
2021 (kill-all-local-variables) ; Recommended by RMS.
2022 (vc-annotate-mode-variables) ; This defines various variables.
2023 (use-local-map vc-annotate-mode-map) ; This provides the local keymap.
2024 (set-syntax-table vc-annotate-mode-syntax-table)
2025 (setq major-mode 'vc-annotate-mode) ; This is how `describe-mode'
2026 ; finds out what to describe.
2027 (setq mode-name "Annotate") ; This goes into the mode line.
2028 (run-hooks 'vc-annotate-mode-hook)
2029 (vc-annotate-add-menu))
2031 (defun vc-annotate-display-default (&optional event)
2032 "Use the default color spectrum for VC Annotate mode."
2033 (interactive)
2034 (message "Redisplaying annotation...")
2035 (vc-annotate-display (get-buffer (buffer-name)))
2036 (message "Redisplaying annotation...done"))
2038 (defun vc-annotate-add-menu ()
2039 "Adds the menu 'Annotate' to the menu bar in VC-Annotate mode."
2040 (define-key vc-annotate-mode-menu [default]
2041 '("Default" . vc-annotate-display-default))
2042 (let ((menu-elements vc-annotate-menu-elements))
2043 (while menu-elements
2044 (let* ((element (car menu-elements))
2045 (days (round (* element
2046 (vc-annotate-car-last-cons vc-annotate-color-map)
2047 0.7585))))
2048 (setq menu-elements (cdr menu-elements))
2049 (define-key vc-annotate-mode-menu
2050 (vector days)
2051 (cons (format "Span %d days"
2052 days)
2053 `(lambda ()
2054 ,(format "Use colors spanning %d days" days)
2055 (interactive)
2056 (message "Redisplaying annotation...")
2057 (vc-annotate-display
2058 (get-buffer (buffer-name))
2059 (vc-annotate-time-span vc-annotate-color-map ,element))
2060 (message "Redisplaying annotation...done"))))))))
2062 ;;;###autoload
2063 (defun vc-annotate (ratio)
2064 "Display the result of the CVS `annotate' command using colors.
2065 New lines are displayed in red, old in blue.
2066 A prefix argument specifies a factor for stretching the time scale.
2068 `vc-annotate-menu-elements' customizes the menu elements of the
2069 mode-specific menu. `vc-annotate-color-map' and
2070 `vc-annotate-very-old-color' defines the mapping of time to
2071 colors. `vc-annotate-background' specifies the background color."
2072 (interactive "p")
2073 (if (not (eq (vc-buffer-backend) 'CVS)) ; This only works with CVS
2074 (vc-registration-error (buffer-file-name)))
2075 (message "Annotating...")
2076 (let ((temp-buffer-name (concat "*cvs annotate " (buffer-name) "*"))
2077 (temp-buffer-show-function 'vc-annotate-display)
2078 (vc-annotate-ratio ratio))
2079 (with-output-to-temp-buffer temp-buffer-name
2080 (call-process "cvs" nil (get-buffer temp-buffer-name) nil
2081 "annotate" (file-name-nondirectory (buffer-file-name)))))
2082 (message "Annotating... done"))
2084 (defun vc-annotate-car-last-cons (assoc-list)
2085 "Return car of last cons in ASSOC-LIST."
2086 (if (not (eq nil (cdr assoc-list)))
2087 (vc-annotate-car-last-cons (cdr assoc-list))
2088 (car (car assoc-list))))
2090 ;; Return an association list with span factor applied to the
2091 ;; time-span of assoc-list. Optionaly quantize to the factor of
2092 ;; quantize.
2093 (defun vc-annotate-time-span (assoc-list span &optional quantize)
2094 ;; Apply span to each car of every cons
2095 (if (not (eq nil assoc-list))
2096 (append (list (cons (* (car (car assoc-list)) span)
2097 (cdr (car assoc-list))))
2098 (vc-annotate-time-span (nthcdr (cond (quantize) ; optional
2099 (1)) ; Default to cdr
2100 assoc-list) span quantize))))
2102 (defun vc-annotate-compcar (threshold &rest args)
2103 "Test successive cars of ARGS against THRESHOLD.
2104 Return the first cons which CAR is not less than THRESHOLD, nil otherwise"
2105 ;; If no list is exhausted,
2106 (if (and (not (memq 'nil args)) (< (car (car (car args))) threshold))
2107 ;; apply to CARs.
2108 (apply 'vc-annotate-compcar threshold
2109 ;; Recurse for rest of elements.
2110 (mapcar 'cdr args))
2111 ;; Return the proper result
2112 (car (car args))))
2114 (defun vc-annotate-display (buffer &optional color-map)
2115 "Do the VC-Annotate display in BUFFER using COLOR-MAP."
2117 ;; Handle the case of the global variable vc-annotate-ratio being
2118 ;; set. This variable is used to pass information from function
2119 ;; vc-annotate since it is not possible to use another parameter
2120 ;; (see temp-buffer-show-function).
2121 (if (and (not color-map) vc-annotate-ratio)
2122 ;; This will only be true if called from vc-annotate with ratio
2123 ;; being non-nil.
2124 (setq color-map (vc-annotate-time-span vc-annotate-color-map
2125 vc-annotate-ratio)))
2127 ;; We need a list of months and their corresponding numbers.
2128 (let* ((local-month-numbers
2129 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4)
2130 ("May" . 5) ("Jun" . 6) ("Jul" . 7) ("Aug" . 8)
2131 ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12)))
2132 ;; XEmacs use extents, GNU Emacs overlays.
2133 (overlay-or-extent (if (string-match "XEmacs" emacs-version)
2134 (cons 'make-extent 'set-extent-property)
2135 (cons 'make-overlay 'overlay-put)))
2136 (make-overlay-or-extent (car overlay-or-extent))
2137 (set-property-overlay-or-extent (cdr overlay-or-extent)))
2139 (set-buffer buffer)
2140 (display-buffer buffer)
2141 (if (not vc-annotate-mode) ; Turn on vc-annotate-mode if not done
2142 (vc-annotate-mode))
2143 (goto-char (point-min)) ; Position at the top of the buffer.
2144 (while (re-search-forward
2145 "^[0-9]+\\(\.[0-9]+\\)*\\s-+(\\sw+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): "
2146 nil t)
2148 (let* (;; Unfortunately, order is important. match-string will
2149 ;; be corrupted by extent functions in XEmacs. Access
2150 ;; string-matches first.
2151 (day (string-to-number (match-string 2)))
2152 (month (cdr (assoc (match-string 3) local-month-numbers)))
2153 (year-tmp (string-to-number (match-string 4)))
2154 (year (+ (if (> 100 year-tmp) 1900 0) year-tmp)) ; Possible millenium problem
2155 (high (- (car (current-time))
2156 (car (encode-time 0 0 0 day month year))))
2157 (color (cond ((vc-annotate-compcar high (cond (color-map)
2158 (vc-annotate-color-map))))
2159 ((cons nil vc-annotate-very-old-color))))
2160 ;; substring from index 1 to remove any leading `#' in the name
2161 (face-name (concat "vc-annotate-face-" (substring (cdr color) 1)))
2162 ;; Make the face if not done.
2163 (face (cond ((intern-soft face-name))
2164 ((make-face (intern face-name)))))
2165 (point (point))
2166 (foo (forward-line 1))
2167 (overlay (cond ((if (string-match "XEmacs" emacs-version)
2168 (extent-at point)
2169 (car (overlays-at point ))))
2170 ((apply make-overlay-or-extent point (point) nil)))))
2172 (if vc-annotate-background
2173 (set-face-background face vc-annotate-background))
2174 (set-face-foreground face (cdr color))
2175 (apply set-property-overlay-or-extent overlay
2176 'face face nil)))))
2178 ;; Collect back-end-dependent stuff here
2180 (defun vc-backend-admin (file &optional rev comment)
2181 ;; Register a file into the version-control system
2182 ;; Automatically retrieves a read-only version of the file with
2183 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
2184 ;; it deletes the workfile.
2185 (vc-file-clearprops file)
2186 (or vc-default-back-end
2187 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))
2188 (message "Registering %s..." file)
2189 (let ((switches
2190 (if (stringp vc-register-switches)
2191 (list vc-register-switches)
2192 vc-register-switches))
2193 (backend
2194 (cond
2195 ((file-exists-p (vc-backend-subdirectory-name)) vc-default-back-end)
2196 ((file-exists-p "RCS") 'RCS)
2197 ((file-exists-p "SCCS") 'SCCS)
2198 ((file-exists-p "CVS") 'CVS)
2199 (t vc-default-back-end))))
2200 (cond ((eq backend 'SCCS)
2201 ;; If there is no SCCS subdirectory yet, create it.
2202 ;; (SCCS could do without it, but VC requires it to be there.)
2203 (if (not (file-exists-p "SCCS")) (make-directory "SCCS"))
2204 (apply 'vc-do-command nil 0 "admin" file 'MASTER ;; SCCS
2205 (and rev (concat "-r" rev))
2206 "-fb"
2207 (concat "-i" file)
2208 (and comment (concat "-y" comment))
2209 (format
2210 (car (rassq 'SCCS vc-master-templates))
2211 (or (file-name-directory file) "")
2212 (file-name-nondirectory file))
2213 switches)
2214 (delete-file file)
2215 (if vc-keep-workfiles
2216 (vc-do-command nil 0 "get" file 'MASTER)))
2217 ((eq backend 'RCS)
2218 (apply 'vc-do-command nil 0 "ci" file 'WORKFILE ;; RCS
2219 ;; if available, use the secure registering option
2220 (and (vc-backend-release-p 'RCS "5.6.4") "-i")
2221 (concat (if vc-keep-workfiles "-u" "-r") rev)
2222 (and comment (concat "-t-" comment))
2223 switches))
2224 ((eq backend 'CVS)
2225 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE ;; CVS
2226 "add"
2227 (and comment (string-match "[^\t\n ]" comment)
2228 (concat "-m" comment))
2229 switches)
2231 (message "Registering %s...done" file)
2234 (defun vc-backend-checkout (file &optional writable rev workfile)
2235 ;; Retrieve a copy of a saved version into a workfile
2236 (let ((filename (or workfile file))
2237 (file-buffer (get-file-buffer file))
2238 switches)
2239 (message "Checking out %s..." filename)
2240 (save-excursion
2241 ;; Change buffers to get local value of vc-checkout-switches.
2242 (if file-buffer (set-buffer file-buffer))
2243 (setq switches (if (stringp vc-checkout-switches)
2244 (list vc-checkout-switches)
2245 vc-checkout-switches))
2246 ;; Save this buffer's default-directory
2247 ;; and use save-excursion to make sure it is restored
2248 ;; in the same buffer it was saved in.
2249 (let ((default-directory default-directory))
2250 (save-excursion
2251 ;; Adjust the default-directory so that the check-out creates
2252 ;; the file in the right place.
2253 (setq default-directory (file-name-directory filename))
2254 (vc-backend-dispatch file
2255 (progn ;; SCCS
2256 (and rev (string= rev "") (setq rev nil))
2257 (if workfile
2258 ;; Some SCCS implementations allow checking out directly to a
2259 ;; file using the -G option, but then some don't so use the
2260 ;; least common denominator approach and use the -p option
2261 ;; ala RCS.
2262 (let ((vc-modes (logior (file-modes (vc-name file))
2263 (if writable 128 0)))
2264 (failed t))
2265 (unwind-protect
2266 (progn
2267 (apply 'vc-do-command
2268 nil 0 "/bin/sh" file 'MASTER "-c"
2269 ;; Some shells make the "" dummy argument into $0
2270 ;; while others use the shell's name as $0 and
2271 ;; use the "" as $1. The if-statement
2272 ;; converts the latter case to the former.
2273 (format "if [ x\"$1\" = x ]; then shift; fi; \
2274 umask %o; exec >\"$1\" || exit; \
2275 shift; umask %o; exec get \"$@\""
2276 (logand 511 (lognot vc-modes))
2277 (logand 511 (lognot (default-file-modes))))
2278 "" ; dummy argument for shell's $0
2279 filename
2280 (if writable "-e")
2281 "-p"
2282 (and rev
2283 (concat "-r" (vc-lookup-triple file rev)))
2284 switches)
2285 (setq failed nil))
2286 (and failed (file-exists-p filename)
2287 (delete-file filename))))
2288 (apply 'vc-do-command nil 0 "get" file 'MASTER ;; SCCS
2289 (if writable "-e")
2290 (and rev (concat "-r" (vc-lookup-triple file rev)))
2291 switches)
2292 (vc-file-setprop file 'vc-workfile-version nil)))
2293 (if workfile ;; RCS
2294 ;; RCS doesn't let us check out into arbitrary file names directly.
2295 ;; Use `co -p' and make stdout point to the correct file.
2296 (let ((vc-modes (logior (file-modes (vc-name file))
2297 (if writable 128 0)))
2298 (failed t))
2299 (unwind-protect
2300 (progn
2301 (apply 'vc-do-command
2302 nil 0 "/bin/sh" file 'MASTER "-c"
2303 ;; See the SCCS case, above, regarding the
2304 ;; if-statement.
2305 (format "if [ x\"$1\" = x ]; then shift; fi; \
2306 umask %o; exec >\"$1\" || exit; \
2307 shift; umask %o; exec co \"$@\""
2308 (logand 511 (lognot vc-modes))
2309 (logand 511 (lognot (default-file-modes))))
2310 "" ; dummy argument for shell's $0
2311 filename
2312 (if writable "-l")
2313 (concat "-p" rev)
2314 switches)
2315 (setq failed nil))
2316 (and failed (file-exists-p filename) (delete-file filename))))
2317 (let (new-version)
2318 ;; if we should go to the head of the trunk,
2319 ;; clear the default branch first
2320 (and rev (string= rev "")
2321 (vc-do-command nil 0 "rcs" file 'MASTER "-b"))
2322 ;; now do the checkout
2323 (apply 'vc-do-command
2324 nil 0 "co" file 'MASTER
2325 ;; If locking is not strict, force to overwrite
2326 ;; the writable workfile.
2327 (if (eq (vc-checkout-model file) 'implicit) "-f")
2328 (if writable "-l")
2329 (if rev (concat "-r" rev)
2330 ;; if no explicit revision was specified,
2331 ;; check out that of the working file
2332 (let ((workrev (vc-workfile-version file)))
2333 (if workrev (concat "-r" workrev)
2334 nil)))
2335 switches)
2336 ;; determine the new workfile version
2337 (save-excursion
2338 (set-buffer "*vc*")
2339 (goto-char (point-min))
2340 (setq new-version
2341 (if (re-search-forward "^revision \\([0-9.]+\\).*\n" nil t)
2342 (buffer-substring (match-beginning 1) (match-end 1)))))
2343 (vc-file-setprop file 'vc-workfile-version new-version)
2344 ;; if necessary, adjust the default branch
2345 (and rev (not (string= rev ""))
2346 (vc-do-command nil 0 "rcs" file 'MASTER
2347 (concat "-b" (if (vc-latest-on-branch-p file)
2348 (if (vc-trunk-p new-version) nil
2349 (vc-branch-part new-version))
2350 new-version))))))
2351 (if workfile ;; CVS
2352 ;; CVS is much like RCS
2353 (let ((failed t))
2354 (unwind-protect
2355 (progn
2356 (apply 'vc-do-command
2357 nil 0 "/bin/sh" file 'WORKFILE "-c"
2358 "exec >\"$1\" || exit; shift; exec cvs update \"$@\""
2359 "" ; dummy argument for shell's $0
2360 workfile
2361 (concat "-r" rev)
2362 "-p"
2363 switches)
2364 (setq failed nil))
2365 (and failed (file-exists-p filename) (delete-file filename))))
2366 ;; default for verbose checkout: clear the sticky tag
2367 ;; so that the actual update will get the head of the trunk
2368 (and rev (string= rev "")
2369 (vc-do-command nil 0 "cvs" file 'WORKFILE "update" "-A"))
2370 ;; If a revision was specified, check that out.
2371 (if rev
2372 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE
2373 (and writable (eq (vc-checkout-model file) 'manual) "-w")
2374 "update"
2375 (and rev (not (string= rev ""))
2376 (concat "-r" rev))
2377 switches)
2378 ;; If no revision was specified, simply make the file writable.
2379 (and writable
2380 (or (eq (vc-checkout-model file) 'manual)
2381 (zerop (logand 128 (file-modes file))))
2382 (set-file-modes file (logior 128 (file-modes file)))))
2383 (if rev (vc-file-setprop file 'vc-workfile-version nil))))
2384 (cond
2385 ((not workfile)
2386 (vc-file-clear-masterprops file)
2387 (if writable
2388 (vc-file-setprop file 'vc-locking-user (vc-user-login-name)))
2389 (vc-file-setprop file
2390 'vc-checkout-time (nth 5 (file-attributes file)))))
2391 (message "Checking out %s...done" filename))))))
2393 (defun vc-backend-logentry-check (file)
2394 (vc-backend-dispatch file
2395 (if (>= (buffer-size) 512) ;; SCCS
2396 (progn
2397 (goto-char 512)
2398 (error
2399 "Log must be less than 512 characters; point is now at pos 512")))
2400 nil ;; RCS
2401 nil) ;; CVS
2404 (defun vc-backend-checkin (file rev comment)
2405 ;; Register changes to FILE as level REV with explanatory COMMENT.
2406 ;; Automatically retrieves a read-only version of the file with
2407 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
2408 ;; it deletes the workfile.
2409 ;; Adaptation for RCS branch support: if this is an explicit checkin,
2410 ;; or if the checkin creates a new branch, set the master file branch
2411 ;; accordingly.
2412 (message "Checking in %s..." file)
2413 ;; "This log message intentionally left almost blank".
2414 ;; RCS 5.7 gripes about white-space-only comments too.
2415 (or (and comment (string-match "[^\t\n ]" comment))
2416 (setq comment "*** empty log message ***"))
2417 (save-excursion
2418 ;; Change buffers to get local value of vc-checkin-switches.
2419 (set-buffer (or (get-file-buffer file) (current-buffer)))
2420 (let ((switches
2421 (if (stringp vc-checkin-switches)
2422 (list vc-checkin-switches)
2423 vc-checkin-switches)))
2424 ;; Clear the master-properties. Do that here, not at the
2425 ;; end, because if the check-in fails we want them to get
2426 ;; re-computed before the next try.
2427 (vc-file-clear-masterprops file)
2428 (vc-backend-dispatch file
2429 ;; SCCS
2430 (progn
2431 (apply 'vc-do-command nil 0 "delta" file 'MASTER
2432 (if rev (concat "-r" rev))
2433 (concat "-y" comment)
2434 switches)
2435 (vc-file-setprop file 'vc-locking-user 'none)
2436 (vc-file-setprop file 'vc-workfile-version nil)
2437 (if vc-keep-workfiles
2438 (vc-do-command nil 0 "get" file 'MASTER))
2440 ;; RCS
2441 (let ((old-version (vc-workfile-version file)) new-version)
2442 (apply 'vc-do-command nil 0 "ci" file 'MASTER
2443 ;; if available, use the secure check-in option
2444 (and (vc-backend-release-p 'RCS "5.6.4") "-j")
2445 (concat (if vc-keep-workfiles "-u" "-r") rev)
2446 (concat "-m" comment)
2447 switches)
2448 (vc-file-setprop file 'vc-locking-user 'none)
2449 (vc-file-setprop file 'vc-workfile-version nil)
2451 ;; determine the new workfile version
2452 (set-buffer "*vc*")
2453 (goto-char (point-min))
2454 (if (or (re-search-forward
2455 "new revision: \\([0-9.]+\\);" nil t)
2456 (re-search-forward
2457 "reverting to previous revision \\([0-9.]+\\)" nil t))
2458 (progn (setq new-version (buffer-substring (match-beginning 1)
2459 (match-end 1)))
2460 (vc-file-setprop file 'vc-workfile-version new-version)))
2462 ;; if we got to a different branch, adjust the default
2463 ;; branch accordingly
2464 (cond
2465 ((and old-version new-version
2466 (not (string= (vc-branch-part old-version)
2467 (vc-branch-part new-version))))
2468 (vc-do-command nil 0 "rcs" file 'MASTER
2469 (if (vc-trunk-p new-version) "-b"
2470 (concat "-b" (vc-branch-part new-version))))
2471 ;; If this is an old RCS release, we might have
2472 ;; to remove a remaining lock.
2473 (if (not (vc-backend-release-p 'RCS "5.6.2"))
2474 ;; exit status of 1 is also accepted.
2475 ;; It means that the lock was removed before.
2476 (vc-do-command nil 1 "rcs" file 'MASTER
2477 (concat "-u" old-version))))))
2478 ;; CVS
2479 (progn
2480 ;; explicit check-in to the trunk requires a
2481 ;; double check-in (first unexplicit) (CVS-1.3)
2482 (condition-case nil
2483 (progn
2484 (if (and rev (vc-trunk-p rev))
2485 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE
2486 "ci" "-m" "intermediate"
2487 switches))
2488 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE
2489 "ci" (if rev (concat "-r" rev))
2490 (concat "-m" comment)
2491 switches))
2492 (error (if (eq (vc-cvs-status file) 'needs-merge)
2493 ;; The CVS output will be on top of this message.
2494 (error "Type C-x 0 C-x C-q to merge in changes")
2495 (error "Check-in failed"))))
2496 ;; determine and store the new workfile version
2497 (set-buffer "*vc*")
2498 (goto-char (point-min))
2499 (if (re-search-forward
2500 "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" nil t)
2501 (vc-file-setprop file 'vc-workfile-version
2502 (buffer-substring (match-beginning 2)
2503 (match-end 2)))
2504 (vc-file-setprop file 'vc-workfile-version nil))
2505 ;; if this was an explicit check-in, remove the sticky tag
2506 (if rev
2507 (vc-do-command nil 0 "cvs" file 'WORKFILE "update" "-A"))
2508 (vc-file-setprop file 'vc-locking-user 'none)
2509 (vc-file-setprop file 'vc-checkout-time
2510 (nth 5 (file-attributes file)))))))
2511 (message "Checking in %s...done" file))
2513 (defun vc-backend-revert (file)
2514 ;; Revert file to latest checked-in version.
2515 ;; (for RCS, to workfile version)
2516 (message "Reverting %s..." file)
2517 (vc-file-clear-masterprops file)
2518 (vc-backend-dispatch
2519 file
2520 ;; SCCS
2521 (progn
2522 (vc-do-command nil 0 "unget" file 'MASTER nil)
2523 (vc-do-command nil 0 "get" file 'MASTER nil))
2524 ;; RCS
2525 (vc-do-command nil 0 "co" file 'MASTER
2526 "-f" (concat "-u" (vc-workfile-version file)))
2527 ;; CVS
2528 (progn
2529 (delete-file file)
2530 (vc-do-command nil 0 "cvs" file 'WORKFILE "update")))
2531 (vc-file-setprop file 'vc-locking-user 'none)
2532 (vc-file-setprop file 'vc-checkout-time (nth 5 (file-attributes file)))
2533 (message "Reverting %s...done" file)
2536 (defun vc-backend-steal (file &optional rev)
2537 ;; Steal the lock on the current workfile. Needs RCS 5.6.2 or later for -M.
2538 (message "Stealing lock on %s..." file)
2539 (vc-backend-dispatch file
2540 (progn ;SCCS
2541 (vc-do-command nil 0 "unget" file 'MASTER "-n" (if rev (concat "-r" rev)))
2542 (vc-do-command nil 0 "get" file 'MASTER "-g" (if rev (concat "-r" rev)))
2544 (vc-do-command nil 0 "rcs" file 'MASTER ;RCS
2545 "-M" (concat "-u" rev) (concat "-l" rev))
2546 (error "You cannot steal a CVS lock; there are no CVS locks to steal") ;CVS
2548 (vc-file-setprop file 'vc-locking-user (vc-user-login-name))
2549 (message "Stealing lock on %s...done" file)
2552 (defun vc-backend-uncheck (file target)
2553 ;; Undo the latest checkin.
2554 (message "Removing last change from %s..." file)
2555 (vc-backend-dispatch file
2556 (vc-do-command nil 0 "rmdel" file 'MASTER (concat "-r" target))
2557 (vc-do-command nil 0 "rcs" file 'MASTER (concat "-o" target))
2558 nil ;; this is never reached under CVS
2560 (message "Removing last change from %s...done" file)
2563 (defun vc-backend-print-log (file)
2564 ;; Get change log associated with FILE.
2565 (vc-backend-dispatch
2566 file
2567 (vc-do-command nil 0 "prs" file 'MASTER)
2568 (vc-do-command nil 0 "rlog" file 'MASTER)
2569 (vc-do-command nil 0 "cvs" file 'WORKFILE "log")))
2571 (defun vc-backend-assign-name (file name)
2572 ;; Assign to a FILE's latest version a given NAME.
2573 (vc-backend-dispatch file
2574 (vc-add-triple name file (vc-latest-version file)) ;; SCCS
2575 (vc-do-command nil 0 "rcs" file 'MASTER (concat "-n" name ":")) ;; RCS
2576 (vc-do-command nil 0 "cvs" file 'WORKFILE "tag" name) ;; CVS
2580 (defun vc-backend-diff (file &optional oldvers newvers cmp)
2581 ;; Get a difference report between two versions of FILE.
2582 ;; Get only a brief comparison report if CMP, a difference report otherwise.
2583 (let ((backend (vc-backend file)) options status
2584 (diff-switches-list (if (listp diff-switches)
2585 diff-switches
2586 (list diff-switches))))
2587 (cond
2588 ((eq backend 'SCCS)
2589 (setq oldvers (vc-lookup-triple file oldvers))
2590 (setq newvers (vc-lookup-triple file newvers))
2591 (setq options (append (list (and cmp "--brief") "-q"
2592 (and oldvers (concat "-r" oldvers))
2593 (and newvers (concat "-r" newvers)))
2594 (and (not cmp) diff-switches-list)))
2595 (apply 'vc-do-command "*vc-diff*" 1 "vcdiff" file 'MASTER options))
2596 ((eq backend 'RCS)
2597 (if (not oldvers) (setq oldvers (vc-workfile-version file)))
2598 ;; If we know that --brief is not supported, don't try it.
2599 (setq cmp (and cmp (not (eq vc-rcsdiff-knows-brief 'no))))
2600 (setq options (append (list (and cmp "--brief") "-q"
2601 (concat "-r" oldvers)
2602 (and newvers (concat "-r" newvers)))
2603 (and (not cmp) diff-switches-list)))
2604 (setq status (apply 'vc-do-command "*vc-diff*" 2
2605 "rcsdiff" file 'WORKFILE options))
2606 ;; If --brief didn't work, do a double-take and remember it
2607 ;; for the future.
2608 (if (eq status 2)
2609 (prog1
2610 (apply 'vc-do-command "*vc-diff*" 1 "rcsdiff" file 'WORKFILE
2611 (if cmp (cdr options) options))
2612 (if cmp (setq vc-rcsdiff-knows-brief 'no)))
2613 ;; If --brief DID work, remember that, too.
2614 (and cmp (not vc-rcsdiff-knows-brief)
2615 (setq vc-rcsdiff-knows-brief 'yes))
2616 status))
2617 ;; CVS is different.
2618 ((eq backend 'CVS)
2619 (if (string= (vc-workfile-version file) "0")
2620 ;; This file is added but not yet committed; there is no master file.
2621 (if (or oldvers newvers)
2622 (error "No revisions of %s exist" file)
2623 (if cmp 1 ;; file is added but not committed,
2624 ;; we regard this as "changed".
2625 ;; diff it against /dev/null.
2626 (apply 'vc-do-command
2627 "*vc-diff*" 1 "diff" file 'WORKFILE
2628 (append (if (listp diff-switches)
2629 diff-switches
2630 (list diff-switches)) '("/dev/null")))))
2631 ;; cmp is not yet implemented -- we always do a full diff.
2632 (apply 'vc-do-command
2633 "*vc-diff*" 1 "cvs" file 'WORKFILE "diff"
2634 (and oldvers (concat "-r" oldvers))
2635 (and newvers (concat "-r" newvers))
2636 (if (listp diff-switches)
2637 diff-switches
2638 (list diff-switches)))))
2640 (vc-registration-error file)))))
2642 (defun vc-backend-merge-news (file)
2643 ;; Merge in any new changes made to FILE.
2644 (message "Merging changes into %s..." file)
2645 (prog1
2646 (vc-backend-dispatch
2647 file
2648 (error "vc-backend-merge-news not meaningful for SCCS files") ;SCCS
2649 (error "vc-backend-merge-news not meaningful for RCS files") ;RCS
2650 (save-excursion ; CVS
2651 (vc-file-clear-masterprops file)
2652 (vc-file-setprop file 'vc-workfile-version nil)
2653 (vc-file-setprop file 'vc-locking-user nil)
2654 (vc-do-command nil 0 "cvs" file 'WORKFILE "update")
2655 ;; CVS doesn't return an error code if conflicts are detected.
2656 ;; Since we want to warn the user about it (and possibly start
2657 ;; emerge later), scan the output and see if this occurred.
2658 (set-buffer (get-buffer "*vc*"))
2659 (goto-char (point-min))
2660 (if (re-search-forward "^cvs update: conflicts found in .*" nil t)
2661 1 ;; error code for caller
2662 0 ;; no conflict detected
2664 (message "Merging changes into %s...done" file)))
2666 (defun vc-check-headers ()
2667 "Check if the current file has any headers in it."
2668 (interactive)
2669 (save-excursion
2670 (goto-char (point-min))
2671 (vc-backend-dispatch buffer-file-name
2672 (re-search-forward "%[MIRLBSDHTEGUYFPQCZWA]%" nil t) ;; SCCS
2673 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t) ;; RCS
2674 'RCS ;; CVS works like RCS in this regard.
2678 ;; Back-end-dependent stuff ends here.
2680 ;; Set up key bindings for use while editing log messages
2682 (defun vc-log-mode (&optional file)
2683 "Minor mode for driving version-control tools.
2684 These bindings are added to the global keymap when you enter this mode:
2685 \\[vc-next-action] perform next logical version-control operation on current file
2686 \\[vc-register] register current file
2687 \\[vc-toggle-read-only] like next-action, but won't register files
2688 \\[vc-insert-headers] insert version-control headers in current file
2689 \\[vc-print-log] display change history of current file
2690 \\[vc-revert-buffer] revert buffer to latest version
2691 \\[vc-cancel-version] undo latest checkin
2692 \\[vc-diff] show diffs between file versions
2693 \\[vc-version-other-window] visit old version in another window
2694 \\[vc-directory] show all files locked by any user in or below .
2695 \\[vc-annotate] colorful display of the cvs annotate command
2696 \\[vc-update-change-log] add change log entry from recent checkins
2698 While you are entering a change log message for a version, the following
2699 additional bindings will be in effect.
2701 \\[vc-finish-logentry] proceed with check in, ending log message entry
2703 Whenever you do a checkin, your log comment is added to a ring of
2704 saved comments. These can be recalled as follows:
2706 \\[vc-next-comment] replace region with next message in comment ring
2707 \\[vc-previous-comment] replace region with previous message in comment ring
2708 \\[vc-comment-search-reverse] search backward for regexp in the comment ring
2709 \\[vc-comment-search-forward] search backward for regexp in the comment ring
2711 Entry to the change-log submode calls the value of text-mode-hook, then
2712 the value of vc-log-mode-hook.
2714 Global user options:
2715 vc-initial-comment If non-nil, require user to enter a change
2716 comment upon first checkin of the file.
2718 vc-keep-workfiles Non-nil value prevents workfiles from being
2719 deleted when changes are checked in
2721 vc-suppress-confirm Suppresses some confirmation prompts,
2722 notably for reversions.
2724 vc-header-alist Which keywords to insert when adding headers
2725 with \\[vc-insert-headers]. Defaults to
2726 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under
2727 RCS and CVS.
2729 vc-static-header-alist By default, version headers inserted in C files
2730 get stuffed in a static string area so that
2731 ident(RCS/CVS) or what(SCCS) can see them in
2732 the compiled object code. You can override
2733 this by setting this variable to nil, or change
2734 the header template by changing it.
2736 vc-command-messages if non-nil, display run messages from the
2737 actual version-control utilities (this is
2738 intended primarily for people hacking vc
2739 itself).
2741 (interactive)
2742 (set-syntax-table text-mode-syntax-table)
2743 (use-local-map vc-log-entry-mode)
2744 (setq local-abbrev-table text-mode-abbrev-table)
2745 (setq major-mode 'vc-log-mode)
2746 (setq mode-name "VC-Log")
2747 (make-local-variable 'vc-log-file)
2748 (setq vc-log-file file)
2749 (make-local-variable 'vc-log-version)
2750 (make-local-variable 'vc-comment-ring-index)
2751 (set-buffer-modified-p nil)
2752 (setq buffer-file-name nil)
2753 (run-hooks 'text-mode-hook 'vc-log-mode-hook)
2756 ;; Initialization code, to be done just once at load-time
2757 (if vc-log-entry-mode
2759 (setq vc-log-entry-mode (make-sparse-keymap))
2760 (define-key vc-log-entry-mode "\M-n" 'vc-next-comment)
2761 (define-key vc-log-entry-mode "\M-p" 'vc-previous-comment)
2762 (define-key vc-log-entry-mode "\M-r" 'vc-comment-search-reverse)
2763 (define-key vc-log-entry-mode "\M-s" 'vc-comment-search-forward)
2764 (define-key vc-log-entry-mode "\C-c\C-c" 'vc-finish-logentry)
2767 ;;; These things should probably be generally available
2769 (defun vc-file-tree-walk (dirname func &rest args)
2770 "Walk recursively through DIRNAME.
2771 Invoke FUNC f ARGS on each non-directory file f underneath it."
2772 (vc-file-tree-walk-internal (expand-file-name dirname) func args)
2773 (message "Traversing directory %s...done" dirname))
2775 (defun vc-file-tree-walk-internal (file func args)
2776 (if (not (file-directory-p file))
2777 (apply func file args)
2778 (message "Traversing directory %s..." (abbreviate-file-name file))
2779 (let ((dir (file-name-as-directory file)))
2780 (mapcar
2781 (function
2782 (lambda (f) (or
2783 (string-equal f ".")
2784 (string-equal f "..")
2785 (member f vc-directory-exclusion-list)
2786 (let ((dirf (concat dir f)))
2788 (file-symlink-p dirf) ;; Avoid possible loops
2789 (vc-file-tree-walk-internal dirf func args))))))
2790 (directory-files dir)))))
2792 (provide 'vc)
2794 ;;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
2796 ;;; These may be useful to anyone who has to debug or extend the package.
2797 ;;; (Note that this information corresponds to versions 5.x. Some of it
2798 ;;; might have been invalidated by the additions to support branching
2799 ;;; and RCS keyword lookup. AS, 1995/03/24)
2800 ;;;
2801 ;;; A fundamental problem in VC is that there are time windows between
2802 ;;; vc-next-action's computations of the file's version-control state and
2803 ;;; the actions that change it. This is a window open to lossage in a
2804 ;;; multi-user environment; someone else could nip in and change the state
2805 ;;; of the master during it.
2806 ;;;
2807 ;;; The performance problem is that rlog/prs calls are very expensive; we want
2808 ;;; to avoid them as much as possible.
2809 ;;;
2810 ;;; ANALYSIS:
2811 ;;;
2812 ;;; The performance problem, it turns out, simplifies in practice to the
2813 ;;; problem of making vc-locking-user fast. The two other functions that call
2814 ;;; prs/rlog will not be so commonly used that the slowdown is a problem; one
2815 ;;; makes snapshots, the other deletes the calling user's last change in the
2816 ;;; master.
2817 ;;;
2818 ;;; The race condition implies that we have to either (a) lock the master
2819 ;;; during the entire execution of vc-next-action, or (b) detect and
2820 ;;; recover from errors resulting from dispatch on an out-of-date state.
2821 ;;;
2822 ;;; Alternative (a) appears to be infeasible. The problem is that we can't
2823 ;;; guarantee that the lock will ever be removed. Suppose a user starts a
2824 ;;; checkin, the change message buffer pops up, and the user, having wandered
2825 ;;; off to do something else, simply forgets about it?
2826 ;;;
2827 ;;; Alternative (b), on the other hand, works well with a cheap way to speed up
2828 ;;; vc-locking-user. Usually, if a file is registered, we can read its locked/
2829 ;;; unlocked state and its current owner from its permissions.
2830 ;;;
2831 ;;; This shortcut will fail if someone has manually changed the workfile's
2832 ;;; permissions; also if developers are munging the workfile in several
2833 ;;; directories, with symlinks to a master (in this latter case, the
2834 ;;; permissions shortcut will fail to detect a lock asserted from another
2835 ;;; directory).
2836 ;;;
2837 ;;; Note that these cases correspond exactly to the errors which could happen
2838 ;;; because of a competing checkin/checkout race in between two instances of
2839 ;;; vc-next-action.
2840 ;;;
2841 ;;; For VC's purposes, a workfile/master pair may have the following states:
2842 ;;;
2843 ;;; A. Unregistered. There is a workfile, there is no master.
2844 ;;;
2845 ;;; B. Registered and not locked by anyone.
2846 ;;;
2847 ;;; C. Locked by calling user and unchanged.
2848 ;;;
2849 ;;; D. Locked by the calling user and changed.
2850 ;;;
2851 ;;; E. Locked by someone other than the calling user.
2852 ;;;
2853 ;;; This makes for 25 states and 20 error conditions. Here's the matrix:
2854 ;;;
2855 ;;; VC's idea of state
2856 ;;; |
2857 ;;; V Actual state RCS action SCCS action Effect
2858 ;;; A B C D E
2859 ;;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
2860 ;;; B 5 . 6 7 8 co -l get -e checkout
2861 ;;; C 9 10 . 11 12 co -u unget; get revert
2862 ;;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
2863 ;;; E 17 18 19 20 . rcs -u -M -l unget -n ; get -g steal lock
2864 ;;;
2865 ;;; All commands take the master file name as a last argument (not shown).
2866 ;;;
2867 ;;; In the discussion below, a "self-race" is a pathological situation in
2868 ;;; which VC operations are being attempted simultaneously by two or more
2869 ;;; Emacsen running under the same username.
2870 ;;;
2871 ;;; The vc-next-action code has the following windows:
2872 ;;;
2873 ;;; Window P:
2874 ;;; Between the check for existence of a master file and the call to
2875 ;;; admin/checkin in vc-buffer-admin (apparent state A). This window may
2876 ;;; never close if the initial-comment feature is on.
2877 ;;;
2878 ;;; Window Q:
2879 ;;; Between the call to vc-workfile-unchanged-p in and the immediately
2880 ;;; following revert (apparent state C).
2881 ;;;
2882 ;;; Window R:
2883 ;;; Between the call to vc-workfile-unchanged-p in and the following
2884 ;;; checkin (apparent state D). This window may never close.
2885 ;;;
2886 ;;; Window S:
2887 ;;; Between the unlock and the immediately following checkout during a
2888 ;;; revert operation (apparent state C). Included in window Q.
2889 ;;;
2890 ;;; Window T:
2891 ;;; Between vc-locking-user and the following checkout (apparent state B).
2892 ;;;
2893 ;;; Window U:
2894 ;;; Between vc-locking-user and the following revert (apparent state C).
2895 ;;; Includes windows Q and S.
2896 ;;;
2897 ;;; Window V:
2898 ;;; Between vc-locking-user and the following checkin (apparent state
2899 ;;; D). This window may never be closed if the user fails to complete the
2900 ;;; checkin message. Includes window R.
2901 ;;;
2902 ;;; Window W:
2903 ;;; Between vc-locking-user and the following steal-lock (apparent
2904 ;;; state E). This window may never close if the user fails to complete
2905 ;;; the steal-lock message. Includes window X.
2906 ;;;
2907 ;;; Window X:
2908 ;;; Between the unlock and the immediately following re-lock during a
2909 ;;; steal-lock operation (apparent state E). This window may never cloce
2910 ;;; if the user fails to complete the steal-lock message.
2911 ;;;
2912 ;;; Errors:
2913 ;;;
2914 ;;; Apparent state A ---
2916 ;;; 1. File looked unregistered but is actually registered and not locked.
2917 ;;;
2918 ;;; Potential cause: someone else's admin during window P, with
2919 ;;; caller's admin happening before their checkout.
2920 ;;;
2921 ;;; RCS: Prior to version 5.6.4, ci fails with message
2922 ;;; "no lock set by <user>". From 5.6.4 onwards, VC uses the new
2923 ;;; ci -i option and the message is "<file>,v: already exists".
2924 ;;; SCCS: admin will fail with error (ad19).
2925 ;;;
2926 ;;; We can let these errors be passed up to the user.
2927 ;;;
2928 ;;; 2. File looked unregistered but is actually locked by caller, unchanged.
2929 ;;;
2930 ;;; Potential cause: self-race during window P.
2931 ;;;
2932 ;;; RCS: Prior to version 5.6.4, reverts the file to the last saved
2933 ;;; version and unlocks it. From 5.6.4 onwards, VC uses the new
2934 ;;; ci -i option, failing with message "<file>,v: already exists".
2935 ;;; SCCS: will fail with error (ad19).
2936 ;;;
2937 ;;; Either of these consequences is acceptable.
2938 ;;;
2939 ;;; 3. File looked unregistered but is actually locked by caller, changed.
2940 ;;;
2941 ;;; Potential cause: self-race during window P.
2942 ;;;
2943 ;;; RCS: Prior to version 5.6.4, VC registers the caller's workfile as
2944 ;;; a delta with a null change comment (the -t- switch will be
2945 ;;; ignored). From 5.6.4 onwards, VC uses the new ci -i option,
2946 ;;; failing with message "<file>,v: already exists".
2947 ;;; SCCS: will fail with error (ad19).
2948 ;;;
2949 ;;; 4. File looked unregistered but is locked by someone else.
2950 ;;;
2951 ;;; Potential cause: someone else's admin during window P, with
2952 ;;; caller's admin happening *after* their checkout.
2953 ;;;
2954 ;;; RCS: Prior to version 5.6.4, ci fails with a
2955 ;;; "no lock set by <user>" message. From 5.6.4 onwards,
2956 ;;; VC uses the new ci -i option, failing with message
2957 ;;; "<file>,v: already exists".
2958 ;;; SCCS: will fail with error (ad19).
2959 ;;;
2960 ;;; We can let these errors be passed up to the user.
2961 ;;;
2962 ;;; Apparent state B ---
2964 ;;; 5. File looked registered and not locked, but is actually unregistered.
2965 ;;;
2966 ;;; Potential cause: master file got nuked during window P.
2967 ;;;
2968 ;;; RCS: will fail with "RCS/<file>: No such file or directory"
2969 ;;; SCCS: will fail with error ut4.
2970 ;;;
2971 ;;; We can let these errors be passed up to the user.
2972 ;;;
2973 ;;; 6. File looked registered and not locked, but is actually locked by the
2974 ;;; calling user and unchanged.
2975 ;;;
2976 ;;; Potential cause: self-race during window T.
2977 ;;;
2978 ;;; RCS: in the same directory as the previous workfile, co -l will fail
2979 ;;; with "co error: writable foo exists; checkout aborted". In any other
2980 ;;; directory, checkout will succeed.
2981 ;;; SCCS: will fail with ge17.
2982 ;;;
2983 ;;; Either of these consequences is acceptable.
2984 ;;;
2985 ;;; 7. File looked registered and not locked, but is actually locked by the
2986 ;;; calling user and changed.
2987 ;;;
2988 ;;; As case 6.
2989 ;;;
2990 ;;; 8. File looked registered and not locked, but is actually locked by another
2991 ;;; user.
2992 ;;;
2993 ;;; Potential cause: someone else checks it out during window T.
2994 ;;;
2995 ;;; RCS: co error: revision 1.3 already locked by <user>
2996 ;;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
2997 ;;;
2998 ;;; We can let these errors be passed up to the user.
2999 ;;;
3000 ;;; Apparent state C ---
3002 ;;; 9. File looks locked by calling user and unchanged, but is unregistered.
3003 ;;;
3004 ;;; As case 5.
3005 ;;;
3006 ;;; 10. File looks locked by calling user and unchanged, but is actually not
3007 ;;; locked.
3008 ;;;
3009 ;;; Potential cause: a self-race in window U, or by the revert's
3010 ;;; landing during window X of some other user's steal-lock or window S
3011 ;;; of another user's revert.
3012 ;;;
3013 ;;; RCS: succeeds, refreshing the file from the identical version in
3014 ;;; the master.
3015 ;;; SCCS: fails with error ut4 (p file nonexistent).
3017 ;;; Either of these consequences is acceptable.
3018 ;;;
3019 ;;; 11. File is locked by calling user. It looks unchanged, but is actually
3020 ;;; changed.
3021 ;;;
3022 ;;; Potential cause: the file would have to be touched by a self-race
3023 ;;; during window Q.
3024 ;;;
3025 ;;; The revert will succeed, removing whatever changes came with
3026 ;;; the touch. It is theoretically possible that work could be lost.
3027 ;;;
3028 ;;; 12. File looks like it's locked by the calling user and unchanged, but
3029 ;;; it's actually locked by someone else.
3030 ;;;
3031 ;;; Potential cause: a steal-lock in window V.
3032 ;;;
3033 ;;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
3034 ;;; SCCS: fails with error un2
3035 ;;;
3036 ;;; We can pass these errors up to the user.
3037 ;;;
3038 ;;; Apparent state D ---
3040 ;;; 13. File looks like it's locked by the calling user and changed, but it's
3041 ;;; actually unregistered.
3042 ;;;
3043 ;;; Potential cause: master file got nuked during window P.
3044 ;;;
3045 ;;; RCS: Prior to version 5.6.4, checks in the user's version as an
3046 ;;; initial delta. From 5.6.4 onwards, VC uses the new ci -j
3047 ;;; option, failing with message "no such file or directory".
3048 ;;; SCCS: will fail with error ut4.
3050 ;;; This case is kind of nasty. Under RCS prior to version 5.6.4,
3051 ;;; VC may fail to detect the loss of previous version information.
3052 ;;;
3053 ;;; 14. File looks like it's locked by the calling user and changed, but it's
3054 ;;; actually unlocked.
3055 ;;;
3056 ;;; Potential cause: self-race in window V, or the checkin happening
3057 ;;; during the window X of someone else's steal-lock or window S of
3058 ;;; someone else's revert.
3059 ;;;
3060 ;;; RCS: ci will fail with "no lock set by <user>".
3061 ;;; SCCS: delta will fail with error ut4.
3062 ;;;
3063 ;;; 15. File looks like it's locked by the calling user and changed, but it's
3064 ;;; actually locked by the calling user and unchanged.
3065 ;;;
3066 ;;; Potential cause: another self-race --- a whole checkin/checkout
3067 ;;; sequence by the calling user would have to land in window R.
3068 ;;;
3069 ;;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
3070 ;;; RCS: reverts to the file state as of the second user's checkin, leaving
3071 ;;; the file unlocked.
3073 ;;; It is theoretically possible that work could be lost under RCS.
3074 ;;;
3075 ;;; 16. File looks like it's locked by the calling user and changed, but it's
3076 ;;; actually locked by a different user.
3077 ;;;
3078 ;;; RCS: ci error: no lock set by <user>
3079 ;;; SCCS: unget will fail with error un2
3080 ;;;
3081 ;;; We can pass these errors up to the user.
3082 ;;;
3083 ;;; Apparent state E ---
3085 ;;; 17. File looks like it's locked by some other user, but it's actually
3086 ;;; unregistered.
3087 ;;;
3088 ;;; As case 13.
3089 ;;;
3090 ;;; 18. File looks like it's locked by some other user, but it's actually
3091 ;;; unlocked.
3092 ;;;
3093 ;;; Potential cause: someone released a lock during window W.
3094 ;;;
3095 ;;; RCS: The calling user will get the lock on the file.
3096 ;;; SCCS: unget -n will fail with cm4.
3097 ;;;
3098 ;;; Either of these consequences will be OK.
3099 ;;;
3100 ;;; 19. File looks like it's locked by some other user, but it's actually
3101 ;;; locked by the calling user and unchanged.
3102 ;;;
3103 ;;; Potential cause: the other user relinquishing a lock followed by
3104 ;;; a self-race, both in window W.
3105 ;;;
3106 ;;; Under both RCS and SCCS, both unlock and lock will succeed, making
3107 ;;; the sequence a no-op.
3108 ;;;
3109 ;;; 20. File looks like it's locked by some other user, but it's actually
3110 ;;; locked by the calling user and changed.
3111 ;;;
3112 ;;; As case 19.
3113 ;;;
3114 ;;; PROBLEM CASES:
3115 ;;;
3116 ;;; In order of decreasing severity:
3117 ;;;
3118 ;;; Cases 11 and 15 are the only ones that potentially lose work.
3119 ;;; They would require a self-race for this to happen.
3120 ;;;
3121 ;;; Case 13 in RCS loses information about previous deltas, retaining
3122 ;;; only the information in the current workfile. This can only happen
3123 ;;; if the master file gets nuked in window P.
3124 ;;;
3125 ;;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
3126 ;;; no change comment in the master. This would require a self-race in
3127 ;;; window P or R respectively.
3128 ;;;
3129 ;;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
3130 ;;;
3131 ;;; Unfortunately, it appears to me that no recovery is possible in these
3132 ;;; cases. They don't yield error messages, so there's no way to tell that
3133 ;;; a race condition has occurred.
3134 ;;;
3135 ;;; All other cases don't change either the workfile or the master, and
3136 ;;; trigger command errors which the user will see.
3137 ;;;
3138 ;;; Thus, there is no explicit recovery code.
3140 ;;; vc.el ends here