(lm-get-header-re): Allow spaces between the header and the colon.
[emacs.git] / lisp / vc.el
blob081c232243a60ebe0d91f916c0221271158b53b1
1 ;;; vc.el --- drive a version-control system from within Emacs
3 ;; Copyright (C) 1992,93,94,95,96,97,98,2000 Free Software Foundation, Inc.
5 ;; Author: FSF (see below for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
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 ;;; Credits:
27 ;; VC was initially designed and implemented by Eric S. Raymond
28 ;; <esr@snark.thyrsus.com>. Over the years, many people have
29 ;; contributed substantial amounts of work to VC. These include:
30 ;; Per Cederqvist <ceder@lysator.liu.se>
31 ;; Paul Eggert <eggert@twinsun.com>
32 ;; Sebastian Kremer <sk@thp.uni-koeln.de>
33 ;; Martin Lorentzson <martinl@gnu.org>
34 ;; Dave Love <d.love@gnu.org>
35 ;; Stefan Monnier <monnier@cs.yale.edu>
36 ;; Andre Spiegel <spiegel@gnu.org>
37 ;; Richard Stallman <rms@gnu.org>
38 ;; ttn@netcom.com
40 ;;; Commentary:
42 ;; This mode is fully documented in the Emacs user's manual.
44 ;; Supported version-control systems presently include SCCS, RCS, and CVS.
46 ;; Some features will not work with old RCS versions. Where
47 ;; appropriate, VC finds out which version you have, and allows or
48 ;; disallows those features (stealing locks, for example, works only
49 ;; from 5.6.2 onwards).
50 ;; Even initial checkins will fail if your RCS version is so old that ci
51 ;; doesn't understand -t-; this has been known to happen to people running
52 ;; NExTSTEP 3.0.
54 ;; You can support the RCS -x option by customizing vc-rcs-master-templates.
56 ;; Proper function of the SCCS diff commands requires the shellscript vcdiff
57 ;; to be installed somewhere on Emacs's path for executables.
59 ;; If your site uses the ChangeLog convention supported by Emacs, the
60 ;; function vc-comment-to-change-log should prove a useful checkin hook.
62 ;; The vc code maintains some internal state in order to reduce expensive
63 ;; version-control operations to a minimum. Some names are only computed
64 ;; once. If you perform version control operations with RCS/SCCS/CVS while
65 ;; vc's back is turned, or move/rename master files while vc is running,
66 ;; vc may get seriously confused. Don't do these things!
68 ;; Developer's notes on some concurrency issues are included at the end of
69 ;; the file.
71 ;;; Code:
73 ;;;;;;;;;;;;;;;;; Backend-specific functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75 ;; for each operation FUN, the backend should provide a function vc-BACKEND-FUN.
76 ;; Operations marked with a `-' instead of a `*' have a sensible default
77 ;; behavior.
79 ;; * registered (file)
80 ;; * state (file)
81 ;; - state-heuristic (file)
82 ;; The default behavior delegates to `state'.
83 ;; - dir-state (dir)
84 ;; * checkout-model (file)
85 ;; - mode-line-string (file)
86 ;; * workfile-version (file)
87 ;; * revert (file)
88 ;; - merge-news (file)
89 ;; Only needed if state `needs-merge' is possible.
90 ;; - merge (file rev1 rev2)
91 ;; - steal-lock (file &optional version)
92 ;; Only required if files can be locked by somebody else.
93 ;; * register (file rev comment)
94 ;; - responsible-p (file)
95 ;; Should also work if FILE is a directory (ends with a slash).
96 ;; - could-register (file)
97 ;; * checkout (file writable &optional rev destfile)
98 ;; Checkout revision REV of FILE into DESTFILE.
99 ;; DESTFILE defaults to FILE.
100 ;; The file should be made writable if WRITABLE is non-nil.
101 ;; REV can be nil (BASE) or "" (HEAD) or any other revision.
102 ;; * checkin (file rev comment)
103 ;; - logentry-check ()
104 ;; * diff (file &optional rev1 rev2)
105 ;; Insert the diff for FILE into the current buffer.
106 ;; REV1 should default to workfile-version.
107 ;; REV2 should default to the current workfile
108 ;; Return a status of either 0 (i.e. no diff) or 1 (i.e. either non-empty
109 ;; diff or the diff is run asynchronously).
110 ;; - workfile-unchanged-p (file)
111 ;; Return non-nil if FILE is unchanged from its current workfile version.
112 ;; This function should do a brief comparison of FILE's contents
113 ;; with those of the master version. If the backend does not have
114 ;; such a brief-comparison feature, the default implementation of this
115 ;; function can be used, which delegates to a full vc-BACKEND-diff.
116 ;; - clear-headers ()
117 ;; * check-headers ()
118 ;; - dired-state-info (file)
119 ;; - create-snapshot (dir name branchp)
120 ;; Take a snapshot of the current state of files under DIR and name it NAME.
121 ;; This should make sure that files are up-to-date before proceeding
122 ;; with the action.
123 ;; DIR can also be a file and if BRANCHP is specified, NAME
124 ;; should be created as a branch and DIR should be checked out under
125 ;; this new branch. The default behavior does not support branches
126 ;; but does a sanity check, a tree traversal and for each file calls
127 ;; `assign-name'.
128 ;; * assign-name (file name)
129 ;; Give name NAME to the current version of FILE, assuming it is
130 ;; up-to-date. Only used by the default version of `create-snapshot'.
131 ;; - retrieve-snapshot (dir name update)
132 ;; Retrieve a named snapshot of all registered files at or below DIR.
133 ;; If UPDATE is non-nil, then update buffers of any files in the snapshot
134 ;; that are currently visited.
135 ;; * print-log (file)
136 ;; Insert the revision log of FILE into the current buffer.
137 ;; - show-log-entry (version)
138 ;; - update-changelog (files)
139 ;; Find changelog entries for FILES, or for all files at or below
140 ;; the default-directory if FILES is nil.
141 ;; * latest-on-branch-p (file)
142 ;; - cancel-version (file writable)
143 ;; - rename-file (old new)
144 ;; - annotate-command (file buf)
145 ;; - annotate-difference (pos)
146 ;; Only required if `annotate-command' is defined for the backend.
148 (require 'vc-hooks)
149 (require 'ring)
150 (eval-when-compile
151 (require 'compile)
152 (require 'dired) ; for dired-map-over-marks macro
153 (require 'dired-aux)) ; for dired-kill-{line,tree}
155 (if (not (assoc 'vc-parent-buffer minor-mode-alist))
156 (setq minor-mode-alist
157 (cons '(vc-parent-buffer vc-parent-buffer-name)
158 minor-mode-alist)))
160 ;; General customization
162 (defgroup vc nil
163 "Version-control system in Emacs."
164 :group 'tools)
166 (defcustom vc-suppress-confirm nil
167 "*If non-nil, treat user as expert; suppress yes-no prompts on some things."
168 :type 'boolean
169 :group 'vc)
171 (defcustom vc-delete-logbuf-window t
172 "*If non-nil, delete the *VC-log* buffer and window after each logical action.
173 If nil, bury that buffer instead.
174 This is most useful if you have multiple windows on a frame and would like to
175 preserve the setting."
176 :type 'boolean
177 :group 'vc)
179 (defcustom vc-initial-comment nil
180 "*If non-nil, prompt for initial comment when a file is registered."
181 :type 'boolean
182 :group 'vc)
184 (defcustom vc-default-init-version "1.1"
185 "*A string used as the default version number when a new file is registered.
186 This can be overridden by giving a prefix argument to \\[vc-register]."
187 :type 'string
188 :group 'vc
189 :version "20.3")
191 (defcustom vc-command-messages nil
192 "*If non-nil, display run messages from back-end commands."
193 :type 'boolean
194 :group 'vc)
196 (defcustom vc-checkin-switches nil
197 "*A string or list of strings specifying extra switches for checkin.
198 These are passed to the checkin program by \\[vc-checkin]."
199 :type '(choice (const :tag "None" nil)
200 (string :tag "Argument String")
201 (repeat :tag "Argument List"
202 :value ("")
203 string))
204 :group 'vc)
206 (defcustom vc-checkout-switches nil
207 "*A string or list of strings specifying extra switches for checkout.
208 These are passed to the checkout program by \\[vc-checkout]."
209 :type '(choice (const :tag "None" nil)
210 (string :tag "Argument String")
211 (repeat :tag "Argument List"
212 :value ("")
213 string))
214 :group 'vc)
216 (defcustom vc-register-switches nil
217 "*A string or list of strings; extra switches for registering a file.
218 These are passed to the checkin program by \\[vc-register]."
219 :type '(choice (const :tag "None" nil)
220 (string :tag "Argument String")
221 (repeat :tag "Argument List"
222 :value ("")
223 string))
224 :group 'vc)
226 (defcustom vc-dired-listing-switches "-al"
227 "*Switches passed to `ls' for vc-dired. MUST contain the `l' option."
228 :type 'string
229 :group 'vc
230 :version "21.1")
232 (defcustom vc-dired-recurse t
233 "*If non-nil, show directory trees recursively in VC Dired."
234 :type 'boolean
235 :group 'vc
236 :version "20.3")
238 (defcustom vc-dired-terse-display t
239 "*If non-nil, show only locked files in VC Dired."
240 :type 'boolean
241 :group 'vc
242 :version "20.3")
244 (defcustom vc-directory-exclusion-list '("SCCS" "RCS" "CVS")
245 "*List of directory names to be ignored while recursively walking file trees."
246 :type '(repeat string)
247 :group 'vc)
249 (defconst vc-maximum-comment-ring-size 32
250 "Maximum number of saved comments in the comment ring.")
252 ;;; This is duplicated in diff.el.
253 (defvar diff-switches "-c"
254 "*A string or list of strings specifying switches to be passed to diff.")
256 ;;;###autoload
257 (defcustom vc-checkin-hook nil
258 "*Normal hook (list of functions) run after a checkin is done.
259 See `run-hooks'."
260 :type 'hook
261 :options '(vc-comment-to-change-log)
262 :group 'vc)
264 ;;;###autoload
265 (defcustom vc-before-checkin-hook nil
266 "*Normal hook (list of functions) run before a file gets checked in.
267 See `run-hooks'."
268 :type 'hook
269 :group 'vc)
271 (defcustom vc-logentry-check-hook nil
272 "*Normal hook run by `vc-backend-logentry-check'.
273 Use this to impose your own rules on the entry in addition to any the
274 version control backend imposes itself."
275 :type 'hook
276 :group 'vc)
278 ;; Annotate customization
279 (defcustom vc-annotate-color-map
280 '(( 26.3672 . "#FF0000")
281 ( 52.7344 . "#FF3800")
282 ( 79.1016 . "#FF7000")
283 (105.4688 . "#FFA800")
284 (131.8359 . "#FFE000")
285 (158.2031 . "#E7FF00")
286 (184.5703 . "#AFFF00")
287 (210.9375 . "#77FF00")
288 (237.3047 . "#3FFF00")
289 (263.6719 . "#07FF00")
290 (290.0391 . "#00FF31")
291 (316.4063 . "#00FF69")
292 (342.7734 . "#00FFA1")
293 (369.1406 . "#00FFD9")
294 (395.5078 . "#00EEFF")
295 (421.8750 . "#00B6FF")
296 (448.2422 . "#007EFF"))
297 "*Association list of age versus color, for \\[vc-annotate].
298 Ages are given in units of 2**-16 seconds.
299 Default is eighteen steps using a twenty day increment."
300 :type 'alist
301 :group 'vc)
303 (defcustom vc-annotate-very-old-color "#0046FF"
304 "*Color for lines older than CAR of last cons in `vc-annotate-color-map'."
305 :type 'string
306 :group 'vc)
308 (defcustom vc-annotate-background "black"
309 "*Background color for \\[vc-annotate].
310 Default color is used if nil."
311 :type 'string
312 :group 'vc)
314 (defcustom vc-annotate-menu-elements '(2 0.5 0.1 0.01)
315 "*Menu elements for the mode-specific menu of VC-Annotate mode.
316 List of factors, used to expand/compress the time scale. See `vc-annotate'."
317 :type '(repeat number)
318 :group 'vc)
320 ;; vc-annotate functionality (CVS only).
321 (defvar vc-annotate-mode nil
322 "Variable indicating if VC-Annotate mode is active.")
324 (defvar vc-annotate-mode-map
325 (let ((m (make-sparse-keymap)))
326 (define-key m [menu-bar] (make-sparse-keymap "VC-Annotate"))
328 "Local keymap used for VC-Annotate mode.")
330 (defvar vc-annotate-mode-menu nil
331 "Local keymap used for VC-Annotate mode's menu bar menu.")
333 ;; Header-insertion hair
335 (defcustom vc-static-header-alist
336 '(("\\.c$" .
337 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
338 "*Associate static header string templates with file types.
339 A \%s in the template is replaced with the first string associated with
340 the file's version control type in `vc-header-alist'."
341 :type '(repeat (cons :format "%v"
342 (regexp :tag "File Type")
343 (string :tag "Header String")))
344 :group 'vc)
346 (defcustom vc-comment-alist
347 '((nroff-mode ".\\\"" ""))
348 "*Special comment delimiters to be used in generating vc headers only.
349 Add an entry in this list if you need to override the normal `comment-start'
350 and `comment-end' variables. This will only be necessary if the mode language
351 is sensitive to blank lines."
352 :type '(repeat (list :format "%v"
353 (symbol :tag "Mode")
354 (string :tag "Comment Start")
355 (string :tag "Comment End")))
356 :group 'vc)
358 ;; Default is to be extra careful for super-user.
359 ;; TODO: This variable is no longer used; the corresponding checks
360 ;; are always done now. If that turns out to be fast enough,
361 ;; the variable can be obsoleted.
362 (defcustom vc-checkout-carefully (= (user-uid) 0)
363 "*Non-nil means be extra-careful in checkout.
364 Verify that the file really is not locked
365 and that its contents match what the master file says."
366 :type 'boolean
367 :group 'vc)
370 ;;; The main keymap
372 (defvar vc-prefix-map
373 (let ((map (make-sparse-keymap)))
374 (define-key map "a" 'vc-update-change-log)
375 (define-key map "c" 'vc-cancel-version)
376 (define-key map "d" 'vc-directory)
377 (define-key map "g" 'vc-annotate)
378 (define-key map "h" 'vc-insert-headers)
379 (define-key map "i" 'vc-register)
380 (define-key map "l" 'vc-print-log)
381 (define-key map "m" 'vc-merge)
382 (define-key map "r" 'vc-retrieve-snapshot)
383 (define-key map "s" 'vc-create-snapshot)
384 (define-key map "u" 'vc-revert-buffer)
385 (define-key map "v" 'vc-next-action)
386 (define-key map "=" 'vc-diff)
387 (define-key map "~" 'vc-version-other-window)
388 map))
389 (fset 'vc-prefix-map vc-prefix-map)
391 ;; Initialization code, to be done just once at load-time
392 (defvar vc-log-mode-map
393 (let ((map (make-sparse-keymap)))
394 (define-key map "\M-n" 'vc-next-comment)
395 (define-key map "\M-p" 'vc-previous-comment)
396 (define-key map "\M-r" 'vc-comment-search-reverse)
397 (define-key map "\M-s" 'vc-comment-search-forward)
398 (define-key map "\C-c\C-c" 'vc-finish-logentry)
399 map))
400 ;; Compatibility with old name. Should we bother ?
401 (defvar vc-log-entry-mode vc-log-mode-map)
404 ;; Variables the user doesn't need to know about.
405 (defvar vc-log-operation nil)
406 (defvar vc-log-after-operation-hook nil)
407 (defvar vc-annotate-buffers nil
408 "Alist of current \"Annotate\" buffers and their corresponding backends.
409 The keys are \(BUFFER . BACKEND\). See also `vc-annotate-get-backend'.")
410 ;; In a log entry buffer, this is a local variable
411 ;; that points to the buffer for which it was made
412 ;; (either a file, or a VC dired buffer).
413 (defvar vc-parent-buffer nil)
414 (put 'vc-parent-buffer 'permanent-local t)
415 (defvar vc-parent-buffer-name nil)
416 (put 'vc-parent-buffer-name 'permanent-local t)
418 (defvar vc-log-file)
419 (defvar vc-log-version)
421 (defvar vc-dired-mode nil)
422 (make-variable-buffer-local 'vc-dired-mode)
424 (defvar vc-comment-ring (make-ring vc-maximum-comment-ring-size))
425 (defvar vc-comment-ring-index nil)
426 (defvar vc-last-comment-match "")
428 ;;; functions that operate on RCS revision numbers. This code should
429 ;;; also be moved into the backends. It stays for now, however, since
430 ;;; it is used in code below.
431 (defun vc-trunk-p (rev)
432 "Return t if REV is a revision on the trunk."
433 (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev))))
435 (defun vc-branch-p (rev)
436 "Return t if REV is a branch revision."
437 (not (eq nil (string-match "\\`[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*\\'" rev))))
439 (defun vc-branch-part (rev)
440 "Return the branch part of a revision number REV."
441 (substring rev 0 (string-match "\\.[0-9]+\\'" rev)))
443 (defun vc-minor-part (rev)
444 "Return the minor version number of a revision number REV."
445 (string-match "[0-9]+\\'" rev)
446 (substring rev (match-beginning 0) (match-end 0)))
448 (defun vc-previous-version (rev)
449 "Guess the version number immediately preceding REV."
450 (let ((branch (vc-branch-part rev))
451 (minor-num (string-to-number (vc-minor-part rev))))
452 (if (> minor-num 1)
453 ;; version does probably not start a branch or release
454 (concat branch "." (number-to-string (1- minor-num)))
455 (if (vc-trunk-p rev)
456 ;; we are at the beginning of the trunk --
457 ;; don't know anything to return here
459 ;; we are at the beginning of a branch --
460 ;; return version of starting point
461 (vc-branch-part branch)))))
463 ;; File property caching
465 (defun vc-clear-context ()
466 "Clear all cached file properties and the comment ring."
467 (interactive)
468 (fillarray vc-file-prop-obarray nil)
469 ;; Note: there is potential for minor lossage here if there is an open
470 ;; log buffer with a nonzero local value of vc-comment-ring-index.
471 (setq vc-comment-ring (make-ring vc-maximum-comment-ring-size)))
473 (defmacro with-vc-properties (file form settings)
474 "Execute FORM, then set per-file properties for FILE, but only those
475 that have not been set during the execution of FORM. SETTINGS is a list
476 of two-element lists, each of which has the form (PROPERTY VALUE)."
477 `(let ((vc-touched-properties (list t))
478 (filename ,file))
479 ,form
480 (mapcar (lambda (setting)
481 (let ((property (nth 0 setting))
482 (value (nth 1 setting)))
483 (unless (memq property vc-touched-properties)
484 (put (intern filename vc-file-prop-obarray)
485 property value))))
486 ,settings)))
488 ;; Random helper functions
490 (defsubst vc-editable-p (file)
491 (or (eq (vc-checkout-model file) 'implicit)
492 (eq (vc-state file) 'edited)
493 (eq (vc-state file) 'needs-merge)))
495 ;;; Two macros for elisp programming
496 ;;;###autoload
497 (defmacro with-vc-file (file comment &rest body)
498 "Check out a writable copy of FILE if necessary and execute the body.
499 Check in FILE with COMMENT (a string) after BODY has been executed.
500 FILE is passed through `expand-file-name'; BODY executed within
501 `save-excursion'. If FILE is not under version control, or locked by
502 somebody else, signal error."
503 `(let ((file (expand-file-name ,file)))
504 (or (vc-registered file)
505 (error (format "File not under version control: `%s'" file)))
506 (unless (vc-editable-p file)
507 (let ((state (vc-state file)))
508 (if (stringp state) (error (format "`%s' is locking `%s'" state file))
509 (vc-checkout file t))))
510 (save-excursion
511 ,@body)
512 (vc-checkin file nil ,comment)))
514 ;;;###autoload
515 (defmacro edit-vc-file (file comment &rest body)
516 "Edit FILE under version control, executing body.
517 Checkin with COMMENT after executing BODY.
518 This macro uses `with-vc-file', passing args to it.
519 However, before executing BODY, find FILE, and after BODY, save buffer."
520 `(with-vc-file
521 ,file ,comment
522 (find-file ,file)
523 ,@body
524 (save-buffer)))
526 (defun vc-ensure-vc-buffer ()
527 "Make sure that the current buffer visits a version-controlled file."
528 (if vc-dired-mode
529 (set-buffer (find-file-noselect (dired-get-filename)))
530 (while vc-parent-buffer
531 (pop-to-buffer vc-parent-buffer))
532 (if (not (buffer-file-name))
533 (error "Buffer %s is not associated with a file" (buffer-name))
534 (if (not (vc-backend (buffer-file-name)))
535 (error "File %s is not under version control" (buffer-file-name))))))
537 (defvar vc-binary-assoc nil)
538 (defvar vc-binary-suffixes
539 (if (memq system-type '(ms-dos windows-nt))
540 '(".exe" ".com" ".bat" ".cmd" ".btm" "")
541 '("")))
543 (defun vc-process-filter (p s)
544 "An alternative output filter for async process P.
545 The only difference with the default filter is to insert S after markers."
546 (with-current-buffer (process-buffer p)
547 (save-excursion
548 (let ((inhibit-read-only t))
549 (goto-char (process-mark p))
550 (insert s)
551 (set-marker (process-mark p) (point))))))
553 (defun vc-setup-buffer (&optional buf)
554 "Prepare BUF for executing a VC command and make it the current buffer.
555 BUF defaults to \"*vc*\", can be a string and will be created if necessary."
556 (unless buf (setq buf "*vc*"))
557 (let ((camefrom (current-buffer))
558 (olddir default-directory))
559 (set-buffer (get-buffer-create buf))
560 (kill-all-local-variables)
561 (set (make-local-variable 'vc-parent-buffer) camefrom)
562 (set (make-local-variable 'vc-parent-buffer-name)
563 (concat " from " (buffer-name camefrom)))
564 (setq default-directory olddir)
565 (let ((inhibit-read-only t))
566 (erase-buffer))))
568 (defun vc-exec-after (code)
569 "Eval CODE when the current buffer's process is done.
570 If the current buffer has no process, just evaluate CODE.
571 Else, add CODE to the process' sentinel."
572 (let ((proc (get-buffer-process (current-buffer))))
573 (cond
574 ;; If there's no background process, just execute the code.
575 ((null proc) (eval code))
576 ;; If the background process has exited, reap it and try again
577 ((eq (process-status proc) 'exit)
578 (delete-process proc)
579 (vc-exec-after code))
580 ;; If a process is running, add CODE to the sentinel
581 ((eq (process-status proc) 'run)
582 (let ((sentinel (process-sentinel proc)))
583 (set-process-sentinel proc
584 `(lambda (p s)
585 (with-current-buffer ',(current-buffer)
586 (goto-char (process-mark p))
587 ,@(append (cdr (cdr (cdr ;strip off `with-current-buffer buf
588 ; (goto-char...)'
589 (car (cdr (cdr ;strip off `lambda (p s)'
590 sentinel))))))
591 (list `(vc-exec-after ',code))))))))
592 (t (error "Unexpected process state"))))
593 nil)
595 (defvar vc-post-command-functions nil
596 "Hook run at the end of `vc-do-command'.
597 Each function is called inside the buffer in which the command was run
598 and is passed 3 argument: the COMMAND, the FILE and the FLAGS.")
600 (defun vc-do-command (buffer okstatus command file &rest flags)
601 "Execute a version control command, notifying user and checking for errors.
602 Output from COMMAND goes to BUFFER, or *vc* if BUFFER is nil or the current
603 buffer (which is assumed to be properly setup) if BUFFER is t. The
604 command is considered successful if its exit status does not exceed
605 OKSTATUS (if OKSTATUS is nil, that means to ignore errors, if it is 'async,
606 that means not to wait for termination of the subprocess). FILE is
607 the name of the working file (may also be nil, to execute commands
608 that don't expect a file name). If an optional list of FLAGS is present,
609 that is inserted into the command line before the filename."
610 (and file (setq file (expand-file-name file)))
611 (if vc-command-messages
612 (message "Running %s on %s..." command file))
613 (save-current-buffer
614 (unless (eq buffer t) (vc-setup-buffer buffer))
615 (let ((squeezed nil)
616 (inhibit-read-only t)
617 (status 0))
618 (setq squeezed (delq nil (copy-sequence flags)))
619 (when file
620 ;; FIXME: file-relative-name can return a bogus result because
621 ;; it doesn't look at the actual file-system to see if symlinks
622 ;; come into play.
623 (setq squeezed (append squeezed (list (file-relative-name file)))))
624 (let ((exec-path (append vc-path exec-path))
625 ;; Add vc-path to PATH for the execution of this command.
626 (process-environment
627 (cons (concat "PATH=" (getenv "PATH")
628 path-separator
629 (mapconcat 'identity vc-path path-separator))
630 process-environment))
631 (w32-quote-process-args t))
632 (if (eq okstatus 'async)
633 (let ((proc (apply 'start-process command (current-buffer) command
634 squeezed)))
635 (message "Running %s in the background..." command)
636 ;;(set-process-sentinel proc (lambda (p msg) (delete-process p)))
637 (set-process-filter proc 'vc-process-filter)
638 (vc-exec-after
639 `(message "Running %s in the background... done" ',command)))
640 (setq status (apply 'call-process command nil t nil squeezed))
641 (when (or (not (integerp status)) (and okstatus (< okstatus status)))
642 (pop-to-buffer (current-buffer))
643 (goto-char (point-min))
644 (shrink-window-if-larger-than-buffer)
645 (error "Running %s...FAILED (%s)" command
646 (if (integerp status) (format "status %d" status) status))))
647 (if vc-command-messages
648 (message "Running %s...OK" command)))
649 (vc-exec-after
650 `(run-hook-with-args 'vc-post-command-functions ',command ',file ',flags))
651 status)))
653 (defun vc-position-context (posn)
654 "Save a bit of the text around POSN in the current buffer.
655 Used to help us find the corresponding position again later
656 if markers are destroyed or corrupted."
657 ;; A lot of this was shamelessly lifted from Sebastian Kremer's
658 ;; rcs.el mode.
659 (list posn
660 (buffer-size)
661 (buffer-substring posn
662 (min (point-max) (+ posn 100)))))
664 (defun vc-find-position-by-context (context)
665 "Return the position of CONTEXT in the current buffer, or nil if not found."
666 (let ((context-string (nth 2 context)))
667 (if (equal "" context-string)
668 (point-max)
669 (save-excursion
670 (let ((diff (- (nth 1 context) (buffer-size))))
671 (if (< diff 0) (setq diff (- diff)))
672 (goto-char (nth 0 context))
673 (if (or (search-forward context-string nil t)
674 ;; Can't use search-backward since the match may continue
675 ;; after point.
676 (progn (goto-char (- (point) diff (length context-string)))
677 ;; goto-char doesn't signal an error at
678 ;; beginning of buffer like backward-char would
679 (search-forward context-string nil t)))
680 ;; to beginning of OSTRING
681 (- (point) (length context-string))))))))
683 (defun vc-context-matches-p (posn context)
684 "Return t if POSN matches CONTEXT, nil otherwise."
685 (let* ((context-string (nth 2 context))
686 (len (length context-string))
687 (end (+ posn len)))
688 (if (> end (1+ (buffer-size)))
690 (string= context-string (buffer-substring posn end)))))
692 (defun vc-buffer-context ()
693 "Return a list (POINT-CONTEXT MARK-CONTEXT REPARSE).
694 Used by `vc-restore-buffer-context' to later restore the context."
695 (let ((point-context (vc-position-context (point)))
696 ;; Use mark-marker to avoid confusion in transient-mark-mode.
697 (mark-context (if (eq (marker-buffer (mark-marker)) (current-buffer))
698 (vc-position-context (mark-marker))))
699 ;; Make the right thing happen in transient-mark-mode.
700 (mark-active nil)
701 ;; We may want to reparse the compilation buffer after revert
702 (reparse (and (boundp 'compilation-error-list) ;compile loaded
703 (let ((curbuf (current-buffer)))
704 ;; Construct a list; each elt is nil or a buffer
705 ;; iff that buffer is a compilation output buffer
706 ;; that contains markers into the current buffer.
707 (save-excursion
708 (mapcar (lambda (buffer)
709 (set-buffer buffer)
710 (let ((errors (or
711 compilation-old-error-list
712 compilation-error-list))
713 (buffer-error-marked-p nil))
714 (while (and (consp errors)
715 (not buffer-error-marked-p))
716 (and (markerp (cdr (car errors)))
717 (eq buffer
718 (marker-buffer
719 (cdr (car errors))))
720 (setq buffer-error-marked-p t))
721 (setq errors (cdr errors)))
722 (if buffer-error-marked-p buffer)))
723 (buffer-list)))))))
724 (list point-context mark-context reparse)))
726 (defun vc-restore-buffer-context (context)
727 "Restore point/mark, and reparse any affected compilation buffers.
728 CONTEXT is that which `vc-buffer-context' returns."
729 (let ((point-context (nth 0 context))
730 (mark-context (nth 1 context))
731 (reparse (nth 2 context)))
732 ;; Reparse affected compilation buffers.
733 (while reparse
734 (if (car reparse)
735 (with-current-buffer (car reparse)
736 (let ((compilation-last-buffer (current-buffer)) ;select buffer
737 ;; Record the position in the compilation buffer of
738 ;; the last error next-error went to.
739 (error-pos (marker-position
740 (car (car-safe compilation-error-list)))))
741 ;; Reparse the error messages as far as they were parsed before.
742 (compile-reinitialize-errors '(4) compilation-parsing-end)
743 ;; Move the pointer up to find the error we were at before
744 ;; reparsing. Now next-error should properly go to the next one.
745 (while (and compilation-error-list
746 (/= error-pos (car (car compilation-error-list))))
747 (setq compilation-error-list (cdr compilation-error-list))))))
748 (setq reparse (cdr reparse)))
750 ;; if necessary, restore point and mark
751 (if (not (vc-context-matches-p (point) point-context))
752 (let ((new-point (vc-find-position-by-context point-context)))
753 (if new-point (goto-char new-point))))
754 (and mark-active
755 mark-context
756 (not (vc-context-matches-p (mark) mark-context))
757 (let ((new-mark (vc-find-position-by-context mark-context)))
758 (if new-mark (set-mark new-mark))))))
760 (defun vc-revert-buffer1 (&optional arg no-confirm)
761 "Revert buffer, trying to keep point and mark where user expects them.
762 Tries to be clever in the face of changes due to expanded version control
763 key words. This is important for typeahead to work as expected.
764 ARG and NO-CONFIRM are passed on to `revert-buffer'."
765 (interactive "P")
766 (widen)
767 (let ((context (vc-buffer-context)))
768 ;; Use save-excursion here, because it may be able to restore point
769 ;; and mark properly even in cases where vc-restore-buffer-context
770 ;; would fail. However, save-excursion might also get it wrong --
771 ;; in this case, vc-restore-buffer-context gives it a second try.
772 (save-excursion
773 ;; t means don't call normal-mode;
774 ;; that's to preserve various minor modes.
775 (revert-buffer arg no-confirm t))
776 (vc-restore-buffer-context context)))
779 (defun vc-buffer-sync (&optional not-urgent)
780 "Make sure the current buffer and its working file are in sync.
781 NOT-URGENT means it is ok to continue if the user says not to save."
782 (if (buffer-modified-p)
783 (if (or vc-suppress-confirm
784 (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name))))
785 (save-buffer)
786 (unless not-urgent
787 (error "Aborted")))))
789 (defun vc-workfile-unchanged-p (file)
790 "Has FILE changed since last checkout?"
791 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time))
792 (lastmod (nth 5 (file-attributes file))))
793 (if checkout-time
794 (equal checkout-time lastmod)
795 (let ((unchanged (vc-call workfile-unchanged-p file)))
796 (vc-file-setprop file 'vc-checkout-time (if unchanged lastmod 0))
797 unchanged))))
799 (defun vc-default-workfile-unchanged-p (file)
800 "Default check whether FILE is unchanged: diff against master version."
801 (zerop (vc-call diff file (vc-workfile-version file))))
803 (defun vc-recompute-state (file)
804 "Force a recomputation of the version control state of FILE.
805 The state is computed using the exact, and possibly expensive
806 function `vc-BACKEND-state', not the heuristic."
807 (vc-file-setprop file 'vc-state (vc-call state file)))
809 (defun vc-next-action-on-file (file verbose &optional comment)
810 "Do The Right Thing for a given version-controlled FILE.
811 If COMMENT is specified, it will be used as an admin or checkin comment.
812 If VERBOSE is non-nil, query the user rather than using default parameters."
813 (let ((visited (get-file-buffer file))
814 state version)
815 (when visited
816 ;; Check relation of buffer and file, and make sure
817 ;; user knows what he's doing. First, finding the file
818 ;; will check whether the file on disk is newer.
819 (if vc-dired-mode
820 (find-file-other-window file)
821 (find-file file))
822 (if (not (verify-visited-file-modtime (current-buffer)))
823 (if (yes-or-no-p "Replace file on disk with buffer contents? ")
824 (write-file (buffer-file-name))
825 (error "Aborted"))
826 ;; Now, check if we have unsaved changes.
827 (vc-buffer-sync t)
828 (if (buffer-modified-p)
829 (or (y-or-n-p "Operate on disk file, keeping modified buffer? ")
830 (error "Aborted")))))
832 ;; Do the right thing
833 (if (not (vc-registered file))
834 (vc-register verbose comment)
835 (vc-recompute-state file)
836 (setq state (vc-state file))
837 (cond
838 ;; up-to-date
839 ((or (eq state 'up-to-date)
840 (and verbose (eq state 'needs-patch)))
841 (cond
842 (verbose
843 ;; go to a different version
844 (setq version (read-string "Branch or version to move to: "))
845 (vc-checkout file (eq (vc-checkout-model file) 'implicit) version))
846 ((not (eq (vc-checkout-model file) 'implicit))
847 ;; check the file out
848 (vc-checkout file t))
850 ;; do nothing
851 (message "%s is up-to-date" file))))
853 ;; Abnormal: edited but read-only
854 ((and visited (eq state 'edited) buffer-read-only)
855 ;; Make the file+buffer read-write. If the user really wanted to
856 ;; commit, he'll get a chance to do that next time around, anyway.
857 (message "File is edited but read-only; making it writable")
858 (set-file-modes buffer-file-name
859 (logior (file-modes buffer-file-name) 128))
860 (toggle-read-only -1))
862 ;; edited
863 ((eq state 'edited)
864 (cond
865 ;; For files with locking, if the file does not contain
866 ;; any changes, just let go of the lock, i.e. revert.
867 ((and (not (eq (vc-checkout-model file) 'implicit))
868 (vc-workfile-unchanged-p file)
869 ;; If buffer is modified, that means the user just
870 ;; said no to saving it; in that case, don't revert,
871 ;; because the user might intend to save after
872 ;; finishing the log entry.
873 (not (and visited (buffer-modified-p))))
874 ;; DO NOT revert the file without asking the user!
875 (if (not visited) (find-file-other-window file))
876 (if (yes-or-no-p "Revert to master version? ")
877 (vc-revert-buffer)))
878 (t ;; normal action
879 (if verbose (setq version (read-string "New version: ")))
880 (vc-checkin file version comment))))
882 ;; locked by somebody else
883 ((stringp state)
884 (if comment
885 (error "Sorry, you can't steal the lock on %s this way"
886 (file-name-nondirectory file)))
887 (vc-steal-lock file
888 (if verbose (read-string "Version to steal: ")
889 (vc-workfile-version file))
890 state))
892 ;; needs-patch
893 ((eq state 'needs-patch)
894 (if (yes-or-no-p (format
895 "%s is not up-to-date. Get latest version? "
896 (file-name-nondirectory file)))
897 (vc-checkout file (eq (vc-checkout-model file) 'implicit) "")
898 (if (and (not (eq (vc-checkout-model file) 'implicit))
899 (yes-or-no-p "Lock this version? "))
900 (vc-checkout file t)
901 (error "Aborted"))))
903 ;; needs-merge
904 ((eq state 'needs-merge)
905 (if (yes-or-no-p (format
906 "%s is not up-to-date. Merge in changes now? "
907 (file-name-nondirectory file)))
908 (vc-maybe-resolve-conflicts file (vc-call merge-news file))
909 (error "Aborted")))
911 ;; unlocked-changes
912 ((eq state 'unlocked-changes)
913 (if (not visited) (find-file-other-window file))
914 (if (save-window-excursion
915 (vc-version-diff file (vc-workfile-version file) nil)
916 (goto-char (point-min))
917 (insert-string (format "Changes to %s since last lock:\n\n"
918 file))
919 (not (beep))
920 (yes-or-no-p (concat "File has unlocked changes. "
921 "Claim lock retaining changes? ")))
922 (progn (vc-call steal-lock file)
923 ;; Must clear any headers here because they wouldn't
924 ;; show that the file is locked now.
925 (vc-clear-headers file)
926 (vc-mode-line file))
927 (if (not (yes-or-no-p
928 "Revert to checked-in version, instead? "))
929 (error "Checkout aborted")
930 (vc-revert-buffer1 t t)
931 (vc-checkout file t))))))))
933 (defvar vc-dired-window-configuration)
935 (defun vc-next-action-dired (file rev comment)
936 "Call `vc-next-action-on-file' on all the marked files.
937 Ignores FILE and REV, but passes on COMMENT."
938 (let ((dired-buffer (current-buffer))
939 (dired-dir default-directory))
940 (dired-map-over-marks
941 (let ((file (dired-get-filename)))
942 (message "Processing %s..." file)
943 (vc-next-action-on-file file nil comment)
944 (set-buffer dired-buffer)
945 (set-window-configuration vc-dired-window-configuration)
946 (message "Processing %s...done" file))
947 nil t))
948 (dired-move-to-filename))
950 ;; Here's the major entry point.
952 ;;;###autoload
953 (defun vc-next-action (verbose)
954 "Do the next logical checkin or checkout operation on the current file.
956 If you call this from within a VC dired buffer with no files marked,
957 it will operate on the file in the current line.
959 If you call this from within a VC dired buffer, and one or more
960 files are marked, it will accept a log message and then operate on
961 each one. The log message will be used as a comment for any register
962 or checkin operations, but ignored when doing checkouts. Attempted
963 lock steals will raise an error.
965 A prefix argument lets you specify the version number to use.
967 For RCS and SCCS files:
968 If the file is not already registered, this registers it for version
969 control.
970 If the file is registered and not locked by anyone, this checks out
971 a writable and locked file ready for editing.
972 If the file is checked out and locked by the calling user, this
973 first checks to see if the file has changed since checkout. If not,
974 it performs a revert.
975 If the file has been changed, this pops up a buffer for entry
976 of a log message; when the message has been entered, it checks in the
977 resulting changes along with the log message as change commentary. If
978 the variable `vc-keep-workfiles' is non-nil (which is its default), a
979 read-only copy of the changed file is left in place afterwards.
980 If the file is registered and locked by someone else, you are given
981 the option to steal the lock.
983 For CVS files:
984 If the file is not already registered, this registers it for version
985 control. This does a \"cvs add\", but no \"cvs commit\".
986 If the file is added but not committed, it is committed.
987 If your working file is changed, but the repository file is
988 unchanged, this pops up a buffer for entry of a log message; when the
989 message has been entered, it checks in the resulting changes along
990 with the logmessage as change commentary. A writable file is retained.
991 If the repository file is changed, you are asked if you want to
992 merge in the changes into your working copy."
994 (interactive "P")
995 (catch 'nogo
996 (if vc-dired-mode
997 (let ((files (dired-get-marked-files)))
998 (set (make-local-variable 'vc-dired-window-configuration)
999 (current-window-configuration))
1000 (if (string= ""
1001 (mapconcat
1002 (lambda (f)
1003 (if (not (vc-up-to-date-p f)) "@" ""))
1004 files ""))
1005 (vc-next-action-dired nil nil "dummy")
1006 (vc-start-entry nil nil nil
1007 "Enter a change comment for the marked files."
1008 'vc-next-action-dired))
1009 (throw 'nogo nil)))
1010 (while vc-parent-buffer
1011 (pop-to-buffer vc-parent-buffer))
1012 (if buffer-file-name
1013 (vc-next-action-on-file buffer-file-name verbose)
1014 (error "Buffer %s is not associated with a file" (buffer-name)))))
1016 ;;; These functions help the vc-next-action entry point
1018 ;;;###autoload
1019 (defun vc-register (&optional set-version comment)
1020 "Register the current file into a version control system.
1021 With prefix argument SET-VERSION, allow user to specify initial version
1022 level. If COMMENT is present, use that as an initial comment.
1024 The version control system to use is found by cycling through the list
1025 `vc-handled-backends'. The first backend in that list which declares
1026 itself responsible for the file (usually because other files in that
1027 directory are already registered under that backend) will be used to
1028 register the file. If no backend declares itself responsible, the
1029 first backend that could register the file is used."
1030 (interactive "P")
1031 (unless buffer-file-name (error "No visited file"))
1032 (when (vc-backend buffer-file-name)
1033 (if (vc-registered buffer-file-name)
1034 (error "This file is already registered")
1035 (unless (y-or-n-p "Previous master file has vanished. Make a new one? ")
1036 (error "Aborted"))))
1037 ;; Watch out for new buffers of size 0: the corresponding file
1038 ;; does not exist yet, even though buffer-modified-p is nil.
1039 (if (and (not (buffer-modified-p))
1040 (zerop (buffer-size))
1041 (not (file-exists-p buffer-file-name)))
1042 (set-buffer-modified-p t))
1043 (vc-buffer-sync)
1045 (vc-start-entry buffer-file-name
1046 (if set-version
1047 (read-string "Initial version level for %s: "
1048 (buffer-name))
1049 ;; TODO: Use backend-specific init version.
1050 vc-default-init-version)
1051 (or comment (not vc-initial-comment))
1052 "Enter initial comment."
1053 (lambda (file rev comment)
1054 (message "Registering %s... " file)
1055 (let ((backend (vc-responsible-backend file)))
1056 (vc-file-clearprops file)
1057 (vc-call-backend backend 'register file rev comment)
1058 (vc-file-setprop file 'vc-backend backend)
1059 (unless vc-make-backup-files
1060 (make-local-variable 'backup-inhibited)
1061 (setq backup-inhibited t)))
1062 (message "Registering %s... done" file))))
1064 (defun vc-responsible-backend (file &optional register)
1065 "Return the name of the backend system that is responsible for FILE.
1066 If no backend in variable `vc-handled-backends' declares itself
1067 responsible, the first backend in that list will be returned (if optional
1068 arg REGISTER is non-nil, return the first backend that could register the
1069 file).
1070 FILE can also be a directory name (ending with a slash)."
1071 (if (null vc-handled-backends)
1072 (error "Cannot register, no backends in `vc-handled-backends'"))
1073 (or (and (not (file-directory-p file)) (vc-backend file))
1074 (catch 'found
1075 (mapcar (lambda (backend)
1076 (if (vc-call-backend backend 'responsible-p file)
1077 (throw 'found backend)))
1078 vc-handled-backends)
1079 (if register
1080 (mapcar (lambda (backend)
1081 (if (vc-call-backend backend 'could-register file)
1082 (throw 'found backend)))
1083 vc-handled-backends)
1084 (car vc-handled-backends)))))
1086 (defun vc-default-responsible-p (backend file)
1087 "Indicate whether BACKEND is reponsible for FILE.
1088 The default is to return nil always."
1089 nil)
1091 (defun vc-default-could-register (backend file)
1092 "Return non-nil if BACKEND could be used to register FILE.
1093 The default implementation returns t for all files."
1096 (defun vc-resynch-window (file &optional keep noquery)
1097 "If FILE is in the current buffer, either revert or unvisit it.
1098 The choice between revert (to see expanded keywords) and unvisit depends on
1099 `vc-keep-workfiles'. NOQUERY if non-nil inhibits confirmation for
1100 reverting. NOQUERY should be t *only* if it is known the only
1101 difference between the buffer and the file is due to version control
1102 rather than user editing!"
1103 (and (string= buffer-file-name file)
1104 (if keep
1105 (progn
1106 (vc-revert-buffer1 t noquery)
1107 ;; TODO: Adjusting view mode might no longer be necessary
1108 ;; after RMS change to files.el of 1999-08-08. Investigate
1109 ;; this when we install the new VC.
1110 (and view-read-only
1111 (if (file-writable-p file)
1112 (and view-mode
1113 (let ((view-old-buffer-read-only nil))
1114 (view-mode-exit)))
1115 (and (not view-mode)
1116 (not (eq (get major-mode 'mode-class) 'special))
1117 (view-mode-enter))))
1118 (vc-mode-line buffer-file-name))
1119 (kill-buffer (current-buffer)))))
1121 (defun vc-resynch-buffer (file &optional keep noquery)
1122 "If FILE is currently visited, resynch its buffer."
1123 (if (string= buffer-file-name file)
1124 (vc-resynch-window file keep noquery)
1125 (let ((buffer (get-file-buffer file)))
1126 (if buffer
1127 (with-current-buffer buffer
1128 (vc-resynch-window file keep noquery)))))
1129 (vc-dired-resynch-file file))
1131 (defun vc-start-entry (file rev comment msg action &optional after-hook)
1132 "Accept a comment for an operation on FILE revision REV.
1133 If COMMENT is nil, pop up a VC-log buffer, emit MSG, and set the
1134 action on close to ACTION; otherwise, do action immediately. Remember
1135 the file's buffer in `vc-parent-buffer' (current one if no file).
1136 AFTER-HOOK specifies the local value for vc-log-operation-hook."
1137 (let ((parent (if file (find-file-noselect file) (current-buffer))))
1138 (if vc-before-checkin-hook
1139 (if file
1140 (with-current-buffer parent
1141 (run-hooks 'vc-before-checkin-hook))
1142 (run-hooks 'vc-before-checkin-hook)))
1143 (if comment
1144 (set-buffer (get-buffer-create "*VC-log*"))
1145 (pop-to-buffer (get-buffer-create "*VC-log*")))
1146 (set (make-local-variable 'vc-parent-buffer) parent)
1147 (set (make-local-variable 'vc-parent-buffer-name)
1148 (concat " from " (buffer-name vc-parent-buffer)))
1149 (if file (vc-mode-line file))
1150 (vc-log-edit file)
1151 (make-local-variable 'vc-log-after-operation-hook)
1152 (if after-hook
1153 (setq vc-log-after-operation-hook after-hook))
1154 (setq vc-log-operation action)
1155 (setq vc-log-version rev)
1156 (if comment
1157 (progn
1158 (erase-buffer)
1159 (if (eq comment t)
1160 (vc-finish-logentry t)
1161 (insert comment)
1162 (vc-finish-logentry nil)))
1163 (message "%s Type C-c C-c when done" msg))))
1165 (defun vc-checkout (file &optional writable rev)
1166 "Retrieve a copy of the revision REV of FILE.
1167 If WRITABLE is non-nil, make sure the retrieved file is writable.
1168 REV defaults to the latest revision."
1169 (with-vc-properties
1170 file
1171 (condition-case err
1172 (vc-call checkout file writable rev)
1173 (file-error
1174 ;; Maybe the backend is not installed ;-(
1175 (when writable
1176 (let ((buf (get-file-buffer file)))
1177 (when buf (with-current-buffer buf (toggle-read-only -1)))))
1178 (signal (car err) (cdr err))))
1179 `((vc-state ,(if (or (eq (vc-checkout-model file) 'implicit)
1180 (not writable))
1181 (if (vc-call latest-on-branch-p file)
1182 'up-to-date
1183 'needs-patch)
1184 'edited))
1185 (vc-checkout-time ,(nth 5 (file-attributes file)))))
1186 (vc-resynch-buffer file t t))
1188 (defun vc-steal-lock (file rev owner)
1189 "Steal the lock on FILE."
1190 (let (file-description)
1191 (if rev
1192 (setq file-description (format "%s:%s" file rev))
1193 (setq file-description file))
1194 (if (not (yes-or-no-p (format "Steal the lock on %s from %s? "
1195 file-description owner)))
1196 (error "Steal canceled"))
1197 (compose-mail owner (format "Stolen lock on %s" file-description)
1198 nil nil nil nil
1199 (list (list 'vc-finish-steal file rev)))
1200 (setq default-directory (expand-file-name "~/"))
1201 (goto-char (point-max))
1202 (insert
1203 (format "I stole the lock on %s, " file-description)
1204 (current-time-string)
1205 ".\n")
1206 (message "Please explain why you stole the lock. Type C-c C-c when done.")))
1208 (defun vc-finish-steal (file version)
1209 ;; This is called when the notification has been sent.
1210 (message "Stealing lock on %s..." file)
1211 (with-vc-properties
1212 file
1213 (vc-call steal-lock file version)
1214 `((vc-state edited)))
1215 (vc-resynch-buffer file t t)
1216 (message "Stealing lock on %s...done" file))
1218 (defun vc-checkin (file &optional rev comment)
1219 "Check in FILE.
1220 The optional argument REV may be a string specifying the new version
1221 level (if nil increment the current level). COMMENT is a comment
1222 string; if omitted, a buffer is popped up to accept a comment.
1224 If `vc-keep-workfiles' is nil, FILE is deleted afterwards, provided
1225 that the version control system supports this mode of operation.
1227 Runs the normal hook `vc-checkin-hook'."
1228 (vc-start-entry
1229 file rev comment
1230 "Enter a change comment."
1231 (lambda (file rev comment)
1232 (message "Checking in %s..." file)
1233 ;; "This log message intentionally left almost blank".
1234 ;; RCS 5.7 gripes about white-space-only comments too.
1235 (or (and comment (string-match "[^\t\n ]" comment))
1236 (setq comment "*** empty log message ***"))
1237 (with-vc-properties
1238 file
1239 ;; Change buffers to get local value of vc-checkin-switches.
1240 (with-current-buffer (or (get-file-buffer file) (current-buffer))
1241 (vc-call checkin file rev comment))
1242 `((vc-state up-to-date)
1243 (vc-checkout-time ,(nth 5 (file-attributes file)))
1244 (vc-workfile-version nil)))
1245 (message "Checking in %s...done" file))
1246 'vc-checkin-hook))
1248 (defun vc-comment-to-change-log (&optional whoami file-name)
1249 "Enter last VC comment into change log file for current buffer's file.
1250 Optional arg (interactive prefix) non-nil means prompt for user name and site.
1251 Second arg is file name of change log. \
1252 If nil, uses `change-log-default-name'.
1254 May be useful as a `vc-checkin-hook' to update change logs automatically."
1255 (interactive (if current-prefix-arg
1256 (list current-prefix-arg
1257 (prompt-for-change-log-name))))
1258 ;; Make sure the defvar for add-log-current-defun-function has been executed
1259 ;; before binding it.
1260 (require 'add-log)
1261 (let (;; Extract the comment first so we get any error before doing anything.
1262 (comment (ring-ref vc-comment-ring 0))
1263 ;; Don't let add-change-log-entry insert a defun name.
1264 (add-log-current-defun-function 'ignore)
1265 end)
1266 ;; Call add-log to do half the work.
1267 (add-change-log-entry whoami file-name t t)
1268 ;; Insert the VC comment, leaving point before it.
1269 (setq end (save-excursion (insert comment) (point-marker)))
1270 (if (looking-at "\\s *\\s(")
1271 ;; It starts with an open-paren, as in "(foo): Frobbed."
1272 ;; So remove the ": " add-log inserted.
1273 (delete-char -2))
1274 ;; Canonicalize the white space between the file name and comment.
1275 (just-one-space)
1276 ;; Indent rest of the text the same way add-log indented the first line.
1277 (let ((indentation (current-indentation)))
1278 (save-excursion
1279 (while (< (point) end)
1280 (forward-line 1)
1281 (indent-to indentation))
1282 (setq end (point))))
1283 ;; Fill the inserted text, preserving open-parens at bol.
1284 (let ((paragraph-separate (concat paragraph-separate "\\|\\s *\\s("))
1285 (paragraph-start (concat paragraph-start "\\|\\s *\\s(")))
1286 (beginning-of-line)
1287 (fill-region (point) end))
1288 ;; Canonicalize the white space at the end of the entry so it is
1289 ;; separated from the next entry by a single blank line.
1290 (skip-syntax-forward " " end)
1291 (delete-char (- (skip-syntax-backward " ")))
1292 (or (eobp) (looking-at "\n\n")
1293 (insert "\n"))))
1295 (defun vc-finish-logentry (&optional nocomment)
1296 "Complete the operation implied by the current log entry."
1297 (interactive)
1298 ;; Check and record the comment, if any.
1299 (unless nocomment
1300 ;; Comment too long?
1301 (vc-call-backend (or (and vc-log-file (vc-backend vc-log-file))
1302 (vc-responsible-backend default-directory))
1303 'logentry-check)
1304 (run-hooks 'vc-logentry-check-hook)
1305 ;; Record the comment in the comment ring
1306 (let ((comment (buffer-string)))
1307 (unless (and (ring-p vc-comment-ring)
1308 (not (ring-empty-p vc-comment-ring))
1309 (equal comment (ring-ref vc-comment-ring 0)))
1310 (ring-insert vc-comment-ring comment))))
1311 ;; Sync parent buffer in case the user modified it while editing the comment.
1312 ;; But not if it is a vc-dired buffer.
1313 (with-current-buffer vc-parent-buffer
1314 (or vc-dired-mode (vc-buffer-sync)))
1315 (if (not vc-log-operation) (error "No log operation is pending"))
1316 ;; save the parameters held in buffer-local variables
1317 (let ((log-operation vc-log-operation)
1318 (log-file vc-log-file)
1319 (log-version vc-log-version)
1320 (log-entry (buffer-string))
1321 (after-hook vc-log-after-operation-hook)
1322 (tmp-vc-parent-buffer vc-parent-buffer))
1323 (pop-to-buffer vc-parent-buffer)
1324 ;; OK, do it to it
1325 (save-excursion
1326 (funcall log-operation
1327 log-file
1328 log-version
1329 log-entry))
1330 ;; Remove checkin window (after the checkin so that if that fails
1331 ;; we don't zap the *VC-log* buffer and the typing therein).
1332 (let ((logbuf (get-buffer "*VC-log*")))
1333 (cond ((and logbuf vc-delete-logbuf-window)
1334 (delete-windows-on logbuf (selected-frame))
1335 ;; Kill buffer and delete any other dedicated windows/frames.
1336 (kill-buffer logbuf))
1337 (t (pop-to-buffer "*VC-log*")
1338 (bury-buffer)
1339 (pop-to-buffer tmp-vc-parent-buffer))))
1340 ;; Now make sure we see the expanded headers
1341 (if buffer-file-name
1342 (vc-resynch-buffer buffer-file-name vc-keep-workfiles t))
1343 (if vc-dired-mode
1344 (dired-move-to-filename))
1345 (run-hooks after-hook 'vc-finish-logentry-hook)))
1347 ;; Code for access to the comment ring
1349 (defun vc-new-comment-index (stride len)
1350 (mod (cond
1351 (vc-comment-ring-index (+ vc-comment-ring-index stride))
1352 ;; Initialize the index on the first use of this command
1353 ;; so that the first M-p gets index 0, and the first M-n gets
1354 ;; index -1.
1355 ((> stride 0) (1- stride))
1356 (t stride))
1357 len))
1359 (defun vc-previous-comment (arg)
1360 "Cycle backwards through comment history."
1361 (interactive "*p")
1362 (let ((len (ring-length vc-comment-ring)))
1363 (if (<= len 0)
1364 (progn (message "Empty comment ring") (ding))
1365 (erase-buffer)
1366 (setq vc-comment-ring-index (vc-new-comment-index arg len))
1367 (message "Comment %d" (1+ vc-comment-ring-index))
1368 (insert (ring-ref vc-comment-ring vc-comment-ring-index)))))
1370 (defun vc-next-comment (arg)
1371 "Cycle forwards through comment history."
1372 (interactive "*p")
1373 (vc-previous-comment (- arg)))
1375 (defun vc-comment-search-reverse (str &optional stride)
1376 "Searches backwards through comment history for substring match."
1377 ;; Why substring rather than regexp ? -sm
1378 (interactive
1379 (list (read-string "Comment substring: " nil nil vc-last-comment-match)))
1380 (unless stride (setq stride 1))
1381 (if (string= str "")
1382 (setq str vc-last-comment-match)
1383 (setq vc-last-comment-match str))
1384 (let* ((str (regexp-quote str))
1385 (len (ring-length vc-comment-ring))
1386 (n (vc-new-comment-index stride len)))
1387 (while (progn (when (or (>= n len) (< n 0)) (error "Not found"))
1388 (not (string-match str (ring-ref vc-comment-ring n))))
1389 (setq n (+ n stride)))
1390 (setq vc-comment-ring-index n)
1391 (vc-previous-comment 0)))
1393 (defun vc-comment-search-forward (str)
1394 "Searches forwards through comment history for substring match."
1395 (interactive
1396 (list (read-string "Comment substring: " nil nil vc-last-comment-match)))
1397 (vc-comment-search-reverse str -1))
1399 ;; Additional entry points for examining version histories
1401 ;;;###autoload
1402 (defun vc-diff (historic &optional not-urgent)
1403 "Display diffs between file versions.
1404 Normally this compares the current file and buffer with the most recent
1405 checked in version of that file. This uses no arguments.
1406 With a prefix argument, it reads the file name to use
1407 and two version designators specifying which versions to compare."
1408 (interactive (list current-prefix-arg t))
1409 (vc-ensure-vc-buffer)
1410 (if historic
1411 (call-interactively 'vc-version-diff)
1412 (let ((file buffer-file-name))
1413 (vc-buffer-sync not-urgent)
1414 (if (vc-workfile-unchanged-p buffer-file-name)
1415 (message "No changes to %s since latest version" file)
1416 (vc-version-diff file nil nil)))))
1418 (defun vc-version-diff (file rel1 rel2)
1419 "For FILE, report diffs between two stored versions REL1 and REL2 of it.
1420 If FILE is a directory, generate diffs between versions for all registered
1421 files in or below it."
1422 (interactive
1423 (let ((file (expand-file-name
1424 (read-file-name (if buffer-file-name
1425 "File or dir to diff: (default visited file) "
1426 "File or dir to diff: ")
1427 default-directory buffer-file-name t)))
1428 (rel1-default nil) (rel2-default nil))
1429 ;; compute default versions based on the file state
1430 (cond
1431 ;; if it's a directory, don't supply any version default
1432 ((file-directory-p file)
1433 nil)
1434 ;; if the file is not up-to-date, use current version as older version
1435 ((not (vc-up-to-date-p file))
1436 (setq rel1-default (vc-workfile-version file)))
1437 ;; if the file is not locked, use last and previous version as default
1439 (setq rel1-default (vc-previous-version (vc-workfile-version file)))
1440 (if (string= rel1-default "") (setq rel1-default nil))
1441 (setq rel2-default (vc-workfile-version file))))
1442 ;; construct argument list
1443 (list file
1444 (read-string (if rel1-default
1445 (concat "Older version: (default "
1446 rel1-default ") ")
1447 "Older version: ")
1448 nil nil rel1-default)
1449 (read-string (if rel2-default
1450 (concat "Newer version: (default "
1451 rel2-default ") ")
1452 "Newer version (default: current source): ")
1453 nil nil rel2-default))))
1454 (if (string-equal rel1 "") (setq rel1 nil))
1455 (if (string-equal rel2 "") (setq rel2 nil))
1456 (vc-setup-buffer "*vc-diff*")
1457 (if (file-directory-p file)
1458 (let ((inhibit-read-only t))
1459 (insert "Diffs between "
1460 (or rel1 "last version checked in")
1461 " and "
1462 (or rel2 "current workfile(s)")
1463 ":\n\n")
1464 (setq default-directory (file-name-as-directory file))
1465 ;; FIXME: this should do a single exec in CVS.
1466 (vc-file-tree-walk
1467 default-directory
1468 (lambda (f)
1469 (vc-exec-after
1470 `(progn
1471 (message "Looking at %s" ',f)
1472 (vc-call-backend ',(vc-backend file) 'diff ',f ',rel1 ',rel2)))))
1473 (vc-exec-after `(let ((inhibit-read-only t))
1474 (insert "\nEnd of diffs.\n"))))
1476 (cd (file-name-directory file))
1477 (vc-call diff file rel1 rel2))
1478 (if (and (zerop (buffer-size))
1479 (not (get-buffer-process (current-buffer))))
1480 (progn
1481 (if rel1
1482 (if rel2
1483 (message "No changes to %s between %s and %s" file rel1 rel2)
1484 (message "No changes to %s since %s" file rel1))
1485 (message "No changes to %s since latest version" file))
1486 nil)
1487 (pop-to-buffer (current-buffer))
1488 ;; Gnus-5.8.5 sets up an autoload for diff-mode, even if it's
1489 ;; not available. Work around that.
1490 (if (require 'diff-mode nil t) (diff-mode))
1491 (vc-exec-after '(progn (goto-char (point-min))
1492 (shrink-window-if-larger-than-buffer)))
1495 ;;;###autoload
1496 (defun vc-version-other-window (rev)
1497 "Visit version REV of the current buffer in another window.
1498 If the current buffer is named `F', the version is named `F.~REV~'.
1499 If `F.~REV~' already exists, it is used instead of being re-created."
1500 (interactive "sVersion to visit (default is workfile version): ")
1501 (vc-ensure-vc-buffer)
1502 (let* ((version (if (string-equal rev "")
1503 (vc-workfile-version buffer-file-name)
1504 rev))
1505 (filename (concat buffer-file-name ".~" version "~")))
1506 (or (file-exists-p filename)
1507 (vc-call checkout buffer-file-name nil version filename))
1508 (find-file-other-window filename)))
1510 ;; Header-insertion code
1512 ;;;###autoload
1513 (defun vc-insert-headers ()
1514 "Insert headers in a file for use with your version control system.
1515 Headers desired are inserted at point, and are pulled from
1516 the variable `vc-BACKEND-header'."
1517 (interactive)
1518 (vc-ensure-vc-buffer)
1519 (save-excursion
1520 (save-restriction
1521 (widen)
1522 (if (or (not (vc-check-headers))
1523 (y-or-n-p "Version headers already exist. Insert another set? "))
1524 (progn
1525 (let* ((delims (cdr (assq major-mode vc-comment-alist)))
1526 (comment-start-vc (or (car delims) comment-start "#"))
1527 (comment-end-vc (or (car (cdr delims)) comment-end ""))
1528 (hdsym (vc-make-backend-sym (vc-backend (buffer-file-name))
1529 'header))
1530 (hdstrings (and (boundp hdsym) (symbol-value hdsym))))
1531 (mapcar (lambda (s)
1532 (insert comment-start-vc "\t" s "\t"
1533 comment-end-vc "\n"))
1534 hdstrings)
1535 (if vc-static-header-alist
1536 (mapcar (lambda (f)
1537 (if (string-match (car f) buffer-file-name)
1538 (insert (format (cdr f) (car hdstrings)))))
1539 vc-static-header-alist))
1541 )))))
1543 (defun vc-clear-headers (&optional file)
1544 "Clear all version headers in the current buffer (or FILE).
1545 I.e. reset them to the non-expanded form."
1546 (let* ((filename (or file buffer-file-name))
1547 (visited (find-buffer-visiting filename))
1548 (backend (vc-backend filename)))
1549 (when (vc-find-backend-function backend 'clear-headers)
1550 (if visited
1551 (let ((context (vc-buffer-context)))
1552 ;; save-excursion may be able to relocate point and mark
1553 ;; properly. If it fails, vc-restore-buffer-context
1554 ;; will give it a second try.
1555 (save-excursion
1556 (vc-call-backend backend 'clear-headers))
1557 (vc-restore-buffer-context context))
1558 (find-file filename)
1559 (vc-call-backend backend 'clear-headers)
1560 (kill-buffer filename)))))
1562 ;;;###autoload
1563 (defun vc-merge ()
1564 "Merge changes between two versions into the current buffer's file.
1565 This asks for two versions to merge from in the minibuffer. If the
1566 first version is a branch number, then merge all changes from that
1567 branch. If the first version is empty, merge news, i.e. recent changes
1568 from the current branch.
1570 See Info node `Merging'."
1571 (interactive)
1572 (vc-ensure-vc-buffer)
1573 (vc-buffer-sync)
1574 (let* ((file buffer-file-name)
1575 (backend (vc-backend file))
1576 (state (vc-state file))
1577 first-version second-version status)
1578 (cond
1579 ((stringp state)
1580 (error "File is locked by %s" state))
1581 ((not (vc-editable-p file))
1582 (if (y-or-n-p
1583 "File must be checked out for merging. Check out now? ")
1584 (vc-checkout file t)
1585 (error "Merge aborted"))))
1586 (setq first-version
1587 (read-string (concat "Branch or version to merge from "
1588 "(default: news on current branch): ")))
1589 (if (string= first-version "")
1590 (if (not (vc-find-backend-function backend 'merge-news))
1591 (error "Sorry, merging news is not implemented for %s" backend)
1592 (setq status (vc-call merge-news file)))
1593 (if (not (vc-find-backend-function backend 'merge))
1594 (error "Sorry, merging is not implemented for %s" backend)
1595 (if (not (vc-branch-p first-version))
1596 (setq second-version
1597 (read-string "Second version: "
1598 (concat (vc-branch-part first-version) ".")))
1599 ;; We want to merge an entire branch. Set versions
1600 ;; accordingly, so that vc-BACKEND-merge understands us.
1601 (setq second-version first-version)
1602 ;; first-version must be the starting point of the branch
1603 (setq first-version (vc-branch-part first-version)))
1604 (setq status (vc-call merge file first-version second-version))))
1605 (vc-maybe-resolve-conflicts file status "WORKFILE" "MERGE SOURCE")))
1607 (defun vc-maybe-resolve-conflicts (file status &optional name-A name-B)
1608 (vc-resynch-buffer file t (not (buffer-modified-p)))
1609 (if (zerop status) (message "Merge successful")
1610 (if (fboundp 'smerge-mode) (smerge-mode 1))
1611 (if (y-or-n-p "Conflicts detected. Resolve them now? ")
1612 (if (fboundp 'smerge-ediff)
1613 (smerge-ediff)
1614 (vc-resolve-conflicts name-A name-B))
1615 (message "File contains conflict markers"))))
1617 (defvar vc-ediff-windows)
1618 (defvar vc-ediff-result)
1619 (eval-when-compile
1620 (defvar ediff-buffer-A)
1621 (defvar ediff-buffer-B)
1622 (defvar ediff-buffer-C)
1623 (require 'ediff-util))
1624 ;;;###autoload
1625 (defun vc-resolve-conflicts (&optional name-A name-B)
1626 "Invoke ediff to resolve conflicts in the current buffer.
1627 The conflicts must be marked with rcsmerge conflict markers."
1628 (interactive)
1629 (vc-ensure-vc-buffer)
1630 (let* ((found nil)
1631 (file-name (file-name-nondirectory buffer-file-name))
1632 (your-buffer (generate-new-buffer
1633 (concat "*" file-name
1634 " " (or name-A "WORKFILE") "*")))
1635 (other-buffer (generate-new-buffer
1636 (concat "*" file-name
1637 " " (or name-B "CHECKED-IN") "*")))
1638 (result-buffer (current-buffer)))
1639 (save-excursion
1640 (set-buffer your-buffer)
1641 (erase-buffer)
1642 (insert-buffer result-buffer)
1643 (goto-char (point-min))
1644 (while (re-search-forward (concat "^<<<<<<< "
1645 (regexp-quote file-name) "\n") nil t)
1646 (setq found t)
1647 (replace-match "")
1648 (if (not (re-search-forward "^=======\n" nil t))
1649 (error "Malformed conflict marker"))
1650 (replace-match "")
1651 (let ((start (point)))
1652 (if (not (re-search-forward "^>>>>>>> [0-9.]+\n" nil t))
1653 (error "Malformed conflict marker"))
1654 (delete-region start (point))))
1655 (if (not found)
1656 (progn
1657 (kill-buffer your-buffer)
1658 (kill-buffer other-buffer)
1659 (error "No conflict markers found")))
1660 (set-buffer other-buffer)
1661 (erase-buffer)
1662 (insert-buffer result-buffer)
1663 (goto-char (point-min))
1664 (while (re-search-forward (concat "^<<<<<<< "
1665 (regexp-quote file-name) "\n") nil t)
1666 (let ((start (match-beginning 0)))
1667 (if (not (re-search-forward "^=======\n" nil t))
1668 (error "Malformed conflict marker"))
1669 (delete-region start (point))
1670 (if (not (re-search-forward "^>>>>>>> [0-9.]+\n" nil t))
1671 (error "Malformed conflict marker"))
1672 (replace-match "")))
1673 (let ((config (current-window-configuration))
1674 (ediff-default-variant 'default-B))
1676 ;; Fire up ediff.
1678 (set-buffer (ediff-merge-buffers your-buffer other-buffer))
1680 ;; Ediff is now set up, and we are in the control buffer.
1681 ;; Do a few further adjustments and take precautions for exit.
1683 (make-local-variable 'vc-ediff-windows)
1684 (setq vc-ediff-windows config)
1685 (make-local-variable 'vc-ediff-result)
1686 (setq vc-ediff-result result-buffer)
1687 (make-local-variable 'ediff-quit-hook)
1688 (setq ediff-quit-hook
1689 (lambda ()
1690 (let ((buffer-A ediff-buffer-A)
1691 (buffer-B ediff-buffer-B)
1692 (buffer-C ediff-buffer-C)
1693 (result vc-ediff-result)
1694 (windows vc-ediff-windows))
1695 (ediff-cleanup-mess)
1696 (set-buffer result)
1697 (erase-buffer)
1698 (insert-buffer buffer-C)
1699 (kill-buffer buffer-A)
1700 (kill-buffer buffer-B)
1701 (kill-buffer buffer-C)
1702 (set-window-configuration windows)
1703 (message "Conflict resolution finished; you may save the buffer"))))
1704 (message "Please resolve conflicts now; exit ediff when done")
1705 nil))))
1707 ;; The VC directory major mode. Coopt Dired for this.
1708 ;; All VC commands get mapped into logical equivalents.
1710 (defvar vc-dired-switches)
1711 (defvar vc-dired-terse-mode)
1713 (defvar vc-dired-mode-map
1714 (let ((map (make-sparse-keymap))
1715 (vmap (make-sparse-keymap)))
1716 (define-key map "\C-xv" vc-prefix-map)
1717 ;; Emacs-20 has a lousy keymap inheritance that won't work here.
1718 ;; Emacs-21's is still lousy but just better enough that it'd work. -sm
1719 ;; (set-keymap-parent vmap vc-prefix-map)
1720 (setq vmap vc-prefix-map)
1721 (define-key map "v" vmap)
1722 (define-key vmap "t" 'vc-dired-toggle-terse-mode)
1723 map))
1725 (define-derived-mode vc-dired-mode dired-mode "Dired under VC"
1726 "The major mode used in VC directory buffers.
1728 It works like Dired, but lists only files under version control, with
1729 the current VC state of each file being indicated in the place of the
1730 file's link count, owner, group and size. Subdirectories are also
1731 listed, and you may insert them into the buffer as desired, like in
1732 Dired.
1734 All Dired commands operate normally, with the exception of `v', which
1735 is redefined as the version control prefix, so that you can type
1736 `vl', `v=' etc. to invoke `vc-print-log', `vc-diff', and the like on
1737 the file named in the current Dired buffer line. `vv' invokes
1738 `vc-next-action' on this file, or on all files currently marked.
1739 There is a special command, `*l', to mark all files currently locked."
1740 ;; define-derived-mode does it for us in Emacs-21, but not in Emacs-20.
1741 ;; We do it here because dired might not be loaded yet
1742 ;; when vc-dired-mode-map is initialized.
1743 (set-keymap-parent vc-dired-mode-map dired-mode-map)
1744 (make-local-hook 'dired-after-readin-hook)
1745 (add-hook 'dired-after-readin-hook 'vc-dired-hook nil t)
1746 ;; The following is slightly modified from dired.el,
1747 ;; because file lines look a bit different in vc-dired-mode.
1748 (set (make-local-variable 'dired-move-to-filename-regexp)
1749 (let*
1750 ((l "\\([A-Za-z]\\|[^\0-\177]\\)")
1751 ;; In some locales, month abbreviations are as short as 2 letters,
1752 ;; and they can be padded on the right with spaces.
1753 (month (concat l l "+ *"))
1754 ;; Recognize any non-ASCII character.
1755 ;; The purpose is to match a Kanji character.
1756 (k "[^\0-\177]")
1757 ;; (k "[^\x00-\x7f\x80-\xff]")
1758 (s " ")
1759 (yyyy "[0-9][0-9][0-9][0-9]")
1760 (mm "[ 0-1][0-9]")
1761 (dd "[ 0-3][0-9]")
1762 (HH:MM "[ 0-2][0-9]:[0-5][0-9]")
1763 (western (concat "\\(" month s dd "\\|" dd s month "\\)"
1764 s "\\(" HH:MM "\\|" s yyyy"\\|" yyyy s "\\)"))
1765 (japanese (concat mm k s dd k s "\\(" s HH:MM "\\|" yyyy k "\\)")))
1766 ;; the .* below ensures that we find the last match on a line
1767 (concat ".*" s "\\(" western "\\|" japanese "\\)" s)))
1768 (and (boundp 'vc-dired-switches)
1769 vc-dired-switches
1770 (set (make-local-variable 'dired-actual-switches)
1771 vc-dired-switches))
1772 (set (make-local-variable 'vc-dired-terse-mode) vc-dired-terse-display)
1773 (setq vc-dired-mode t))
1775 (defun vc-dired-toggle-terse-mode ()
1776 "Toggle terse display in VC Dired."
1777 (interactive)
1778 (if (not vc-dired-mode)
1780 (setq vc-dired-terse-mode (not vc-dired-terse-mode))
1781 (if vc-dired-terse-mode
1782 (vc-dired-hook)
1783 (revert-buffer))))
1785 (defun vc-dired-mark-locked ()
1786 "Mark all files currently locked."
1787 (interactive)
1788 (dired-mark-if (let ((f (dired-get-filename nil t)))
1789 (and f
1790 (not (file-directory-p f))
1791 (not (vc-up-to-date-p f))))
1792 "locked file"))
1794 (define-key vc-dired-mode-map "*l" 'vc-dired-mark-locked)
1796 (defun vc-default-dired-state-info (backend file)
1797 (let ((state (vc-state file)))
1798 (cond
1799 ((stringp state) (concat "(" state ")"))
1800 ((eq state 'edited) (concat "(" (vc-user-login-name) ")"))
1801 ((eq state 'needs-merge) "(merge)")
1802 ((eq state 'needs-patch) "(patch)")
1803 ((eq state 'unlocked-changes) "(stale)"))))
1805 (defun vc-dired-reformat-line (x)
1806 "Reformat a directory-listing line.
1807 Replace various columns with version control information.
1808 This code, like dired, assumes UNIX -l format."
1809 (beginning-of-line)
1810 (let ((pos (point)) limit perm date-and-file)
1811 (end-of-line)
1812 (setq limit (point))
1813 (goto-char pos)
1814 (when
1816 (re-search-forward ;; owner and group
1817 "^\\(..[drwxlts-]+ \\) *[0-9]+ [^ ]+ +[^ ]+ +[0-9]+\\( .*\\)"
1818 limit t)
1819 (re-search-forward ;; only owner displayed
1820 "^\\(..[drwxlts-]+ \\) *[0-9]+ [^ ]+ +[0-9]+\\( .*\\)"
1821 limit t)
1822 (re-search-forward ;; OS/2 -l format, no links, owner, group
1823 "^\\(..[drwxlts-]+ \\) *[0-9]+\\( .*\\)"
1824 limit t))
1825 (setq perm (match-string 1)
1826 date-and-file (match-string 2))
1827 (setq x (substring (concat x " ") 0 10))
1828 (replace-match (concat perm x date-and-file)))))
1830 (defun vc-dired-hook ()
1831 "Reformat the listing according to version control.
1832 Called by dired after any portion of a vc-dired buffer has been read in."
1833 (message "Getting version information... ")
1834 (let (subdir filename (buffer-read-only nil) cvs-dir)
1835 (goto-char (point-min))
1836 (while (not (eobp))
1837 (cond
1838 ;; subdir header line
1839 ((setq subdir (dired-get-subdir))
1840 ;; if the backend supports it, get the state
1841 ;; of all files in this directory at once
1842 (let ((backend (vc-responsible-backend subdir)))
1843 (if (vc-find-backend-function backend 'dir-state)
1844 (vc-call-backend backend 'dir-state subdir)))
1845 (forward-line 1)
1846 ;; erase (but don't remove) the "total" line
1847 (delete-region (point) (line-end-position))
1848 (beginning-of-line)
1849 (forward-line 1))
1850 ;; file line
1851 ((setq filename (dired-get-filename nil t))
1852 (cond
1853 ;; subdir
1854 ((file-directory-p filename)
1855 (cond
1856 ((member (file-name-nondirectory filename)
1857 vc-directory-exclusion-list)
1858 (let ((pos (point)))
1859 (dired-kill-tree filename)
1860 (goto-char pos)
1861 (dired-kill-line)))
1862 (vc-dired-terse-mode
1863 ;; Don't show directories in terse mode. Don't use
1864 ;; dired-kill-line to remove it, because in recursive listings,
1865 ;; that would remove the directory contents as well.
1866 (delete-region (line-beginning-position)
1867 (progn (forward-line 1) (point))))
1868 ((string-match "\\`\\.\\.?\\'" (file-name-nondirectory filename))
1869 (dired-kill-line))
1871 (vc-dired-reformat-line nil)
1872 (forward-line 1))))
1873 ;; ordinary file
1874 ((and (vc-backend filename)
1875 (not (and vc-dired-terse-mode
1876 (vc-up-to-date-p filename))))
1877 (vc-dired-reformat-line (vc-call dired-state-info filename))
1878 (forward-line 1))
1880 (dired-kill-line))))
1881 ;; any other line
1882 (t (forward-line 1))))
1883 (vc-dired-purge))
1884 (message "Getting version information... done")
1885 (save-restriction
1886 (widen)
1887 (cond ((eq (count-lines (point-min) (point-max)) 1)
1888 (goto-char (point-min))
1889 (message "No files locked under %s" default-directory)))))
1891 (defun vc-dired-purge ()
1892 "Remove empty subdirs."
1893 (let (subdir)
1894 (goto-char (point-min))
1895 (while (setq subdir (dired-get-subdir))
1896 (forward-line 2)
1897 (if (dired-get-filename nil t)
1898 (if (not (dired-next-subdir 1 t))
1899 (goto-char (point-max)))
1900 (forward-line -2)
1901 (if (not (string= (dired-current-directory) default-directory))
1902 (dired-do-kill-lines t "")
1903 ;; We cannot remove the top level directory.
1904 ;; Just make it look a little nicer.
1905 (forward-line 1)
1906 (kill-line)
1907 (if (not (dired-next-subdir 1 t))
1908 (goto-char (point-max))))))
1909 (goto-char (point-min))))
1911 (defun vc-dired-buffers-for-dir (dir)
1912 "Return a list of all vc-dired buffers that currently display DIR."
1913 (let (result)
1914 ;; Check whether dired is loaded.
1915 (when (fboundp 'dired-buffers-for-dir)
1916 (mapcar (lambda (buffer)
1917 (with-current-buffer buffer
1918 (if vc-dired-mode
1919 (setq result (append result (list buffer))))))
1920 (dired-buffers-for-dir dir)))
1921 result))
1923 (defun vc-dired-resynch-file (file)
1924 "Update the entries for FILE in any VC Dired buffers that list it."
1925 (let ((buffers (vc-dired-buffers-for-dir (file-name-directory file))))
1926 (when buffers
1927 (mapcar (lambda (buffer)
1928 (with-current-buffer buffer
1929 (if (dired-goto-file file)
1930 ;; bind vc-dired-terse-mode to nil so that
1931 ;; files won't vanish when they are checked in
1932 (let ((vc-dired-terse-mode nil))
1933 (dired-do-redisplay 1)))))
1934 buffers))))
1936 ;;;###autoload
1937 (defun vc-directory (dir read-switches)
1938 "Create a buffer in VC Dired Mode for directory DIR.
1940 See Info node `VC Dired Mode'.
1942 With prefix arg READ-SWITCHES, specify a value to override
1943 `dired-listing-switches' when generating the listing."
1944 (interactive "DDired under VC (directory): \nP")
1945 (let ((vc-dired-switches (concat vc-dired-listing-switches
1946 (if vc-dired-recurse "R" ""))))
1947 (if read-switches
1948 (setq vc-dired-switches
1949 (read-string "Dired listing switches: "
1950 vc-dired-switches)))
1951 (require 'dired)
1952 (require 'dired-aux)
1953 (switch-to-buffer
1954 (dired-internal-noselect (expand-file-name (file-name-as-directory dir))
1955 vc-dired-switches
1956 'vc-dired-mode))))
1959 ;; Named-configuration entry points
1961 (defun vc-snapshot-precondition (dir)
1962 "Scan the tree below DIR, looking for non-uptodate files.
1963 If any file is not up-to-date, return the name of the first such file.
1964 \(This means, neither snapshot creation nor retrieval is allowed.\)
1965 If one or more of the files are currently visited, return `visited'.
1966 Otherwise, return nil."
1967 (let ((status nil))
1968 (catch 'vc-locked-example
1969 (vc-file-tree-walk
1971 (lambda (f)
1972 (if (not (vc-up-to-date-p f)) (throw 'vc-locked-example f)
1973 (if (get-file-buffer f) (setq status 'visited)))))
1974 status)))
1976 ;;;###autoload
1977 (defun vc-create-snapshot (dir name branchp)
1978 "Descending recursively from DIR, make a snapshot called NAME.
1979 For each registered file, the version level of its latest version
1980 becomes part of the named configuration. If the prefix argument
1981 BRANCHP is given, the snapshot is made as a new branch and the files
1982 are checked out in that new branch."
1983 (interactive
1984 (list (read-file-name "Directory: " default-directory default-directory t)
1985 (read-string "New snapshot name: ")
1986 current-prefix-arg))
1987 (message "Making %s... " (if branchp "branch" "snapshot"))
1988 (if (file-directory-p dir) (setq dir (file-name-as-directory dir)))
1989 (vc-call-backend (vc-responsible-backend dir)
1990 'create-snapshot dir name branchp)
1991 (message "Making %s... done" (if branchp "branch" "snapshot")))
1993 (defun vc-default-create-snapshot (backend dir name branchp)
1994 (when branchp
1995 (error "VC backend %s does not support module branches" backend))
1996 (let ((result (vc-snapshot-precondition dir)))
1997 (if (stringp result)
1998 (error "File %s is not up-to-date" result)
1999 (vc-file-tree-walk
2001 (lambda (f)
2002 (vc-call assign-name f name))))))
2004 ;;;###autoload
2005 (defun vc-retrieve-snapshot (dir name)
2006 "Descending recursively from DIR, retrieve the snapshot called NAME.
2007 If NAME is empty, it refers to the latest versions.
2008 If locking is used for the files in DIR, then there must not be any
2009 locked files at or below DIR (but if NAME is empty, locked files are
2010 allowed and simply skipped)."
2011 (interactive
2012 (list (read-file-name "Directory: " default-directory default-directory t)
2013 (read-string "Snapshot name to retrieve (default latest versions): ")))
2014 (let ((update (yes-or-no-p "Update any affected buffers? "))
2015 (msg (if (or (not name) (string= name ""))
2016 (format "Updating %s... " (abbreviate-file-name dir))
2017 (format "Retrieving snapshot into %s... "
2018 (abbreviate-file-name dir)))))
2019 (message msg)
2020 (vc-call-backend (vc-responsible-backend dir)
2021 'retrieve-snapshot dir name update)
2022 (message (concat msg "done"))))
2024 (defun vc-default-retrieve-snapshot (backend dir name update)
2025 (if (string= name "")
2026 (progn
2027 (vc-file-tree-walk
2029 (lambda (f) (and
2030 (vc-up-to-date-p f)
2031 (vc-error-occurred
2032 (vc-call checkout f nil "")
2033 (if update (vc-resynch-buffer f t t)))))))
2034 (let ((result (vc-snapshot-precondition dir)))
2035 (if (stringp result)
2036 (error "File %s is locked" result)
2037 (setq update (and (eq result 'visited) update))
2038 (vc-file-tree-walk
2040 (lambda (f) (and
2041 (vc-error-occurred
2042 (vc-call checkout f nil name)
2043 (if update (vc-resynch-buffer f t t))))))))))
2045 ;; Miscellaneous other entry points
2047 ;;;###autoload
2048 (defun vc-print-log ()
2049 "List the change log of the current buffer in a window."
2050 (interactive)
2051 (vc-ensure-vc-buffer)
2052 (let ((file buffer-file-name))
2053 (vc-setup-buffer nil)
2054 (setq default-directory (file-name-directory file))
2055 (vc-call print-log file)
2056 (pop-to-buffer (current-buffer))
2057 (if (fboundp 'log-view-mode) (log-view-mode))
2058 (vc-exec-after
2059 `(progn
2060 (goto-char (point-max)) (forward-line -1)
2061 (while (looking-at "=*\n")
2062 (delete-char (- (match-end 0) (match-beginning 0)))
2063 (forward-line -1))
2064 (goto-char (point-min))
2065 (if (looking-at "[\b\t\n\v\f\r ]+")
2066 (delete-char (- (match-end 0) (match-beginning 0))))
2067 (shrink-window-if-larger-than-buffer)
2068 ;; move point to the log entry for the current version
2069 (if (fboundp 'log-view-goto-rev)
2070 (log-view-goto-rev ',(vc-workfile-version file))
2071 (if (vc-find-backend-function ',(vc-backend file) 'show-log-entry)
2072 (vc-call-backend ',(vc-backend file)
2073 'show-log-entry
2074 ',(vc-workfile-version file))))))))
2076 ;;;###autoload
2077 (defun vc-revert-buffer ()
2078 "Revert the current buffer's file back to the version it was based on.
2079 This asks for confirmation if the buffer contents are not identical
2080 to that version. Note that for RCS and CVS, this function does not
2081 automatically pick up newer changes found in the master file;
2082 use \\[universal-argument] \\[vc-next-action] to do so."
2083 (interactive)
2084 (vc-ensure-vc-buffer)
2085 (let ((file buffer-file-name)
2086 ;; This operation should always ask for confirmation.
2087 (vc-suppress-confirm nil)
2088 (obuf (current-buffer)))
2089 (unless (vc-workfile-unchanged-p file)
2090 (vc-diff nil t)
2091 (vc-exec-after `(message nil))
2092 (unwind-protect
2093 (if (not (yes-or-no-p "Discard changes? "))
2094 (error "Revert canceled"))
2095 (if (or (window-dedicated-p (selected-window))
2096 (one-window-p t 'selected-frame))
2097 (make-frame-invisible (selected-frame))
2098 (delete-window))))
2099 (set-buffer obuf)
2100 ;; Do the reverting
2101 (message "Reverting %s..." file)
2102 (with-vc-properties
2103 file
2104 (vc-call revert file)
2105 `((vc-state up-to-date)
2106 (vc-checkout-time (nth 5 (file-attributes file)))))
2107 (vc-resynch-buffer file t t)
2108 (message "Reverting %s...done" file)))
2110 ;;;###autoload
2111 (defun vc-cancel-version (norevert)
2112 "Get rid of most recently checked in version of this file.
2113 A prefix argument NOREVERT means do not revert the buffer afterwards."
2114 (interactive "P")
2115 (vc-ensure-vc-buffer)
2116 (let* ((file (buffer-file-name))
2117 (backend (vc-backend file))
2118 (target (vc-workfile-version file))
2119 (config (current-window-configuration)) done)
2120 (cond
2121 ((not (vc-find-backend-function backend 'cancel-version))
2122 (error "Sorry, canceling versions is not supported under %s" backend))
2123 ((not (vc-call latest-on-branch-p file))
2124 (error "This is not the latest version; VC cannot cancel it"))
2125 ((not (vc-up-to-date-p file))
2126 (error (substitute-command-keys "File is not up to date; use \\[vc-revert-buffer] to discard changes"))))
2127 (if (null (yes-or-no-p (format "Remove version %s from master? " target)))
2128 (error "Aborted")
2129 (setq norevert (or norevert (not
2130 (yes-or-no-p "Revert buffer to most recent remaining version? "))))
2132 (message "Removing last change from %s..." file)
2133 (with-vc-properties
2134 file
2135 (vc-call cancel-version file norevert)
2136 `((vc-state ,(if norevert 'edited 'up-to-date))
2137 (vc-checkout-time ,(if norevert
2139 (nth 5 (file-attributes file))))
2140 (vc-workfile-version nil)))
2141 (message "Removing last change from %s...done" file)
2143 (cond
2144 (norevert ;; clear version headers and mark the buffer modified
2145 (set-visited-file-name file)
2146 (when (not vc-make-backup-files)
2147 ;; inhibit backup for this buffer
2148 (make-local-variable 'backup-inhibited)
2149 (setq backup-inhibited t))
2150 (setq buffer-read-only nil)
2151 (vc-clear-headers)
2152 (vc-mode-line file)
2153 (vc-dired-resynch-file file))
2154 (t ;; revert buffer to file on disk
2155 (vc-resynch-buffer file t t)))
2156 (message "Version %s has been removed from the master" target))))
2158 (defun vc-rename-master (oldmaster newfile templates)
2159 "Rename OLDMASTER to be the master file for NEWFILE based on TEMPLATES."
2160 (let* ((dir (file-name-directory (expand-file-name oldmaster)))
2161 (newdir (or (file-name-directory newfile) ""))
2162 (newbase (file-name-nondirectory newfile))
2163 (masters
2164 ;; List of potential master files for `newfile'
2165 (mapcar
2166 (lambda (s) (vc-possible-master s newdir newbase))
2167 templates)))
2168 (if (or (file-symlink-p oldmaster)
2169 (file-symlink-p (file-name-directory oldmaster)))
2170 (error "This unsafe in the presence of symbolic links"))
2171 (rename-file
2172 oldmaster
2173 (catch 'found
2174 ;; If possible, keep the master file in the same directory.
2175 (mapcar (lambda (f)
2176 (if (and f (string= (file-name-directory (expand-file-name f))
2177 dir))
2178 (throw 'found f)))
2179 masters)
2180 ;; If not, just use the first possible place.
2181 (mapcar (lambda (f)
2182 (and f
2183 (or (not (setq dir (file-name-directory f)))
2184 (file-directory-p dir))
2185 (throw 'found f)))
2186 masters)
2187 (error "New file lacks a version control directory")))))
2189 ;;;###autoload
2190 (defun vc-rename-file (old new)
2191 "Rename file OLD to NEW, and rename its master file likewise."
2192 (interactive "fVC rename file: \nFRename to: ")
2193 ;; There are several ways of renaming files under CVS 1.3, but they all
2194 ;; have serious disadvantages. See the FAQ (available from think.com in
2195 ;; pub/cvs/). I'd rather send the user an error, than do something he might
2196 ;; consider to be wrong. When the famous, long-awaited rename database is
2197 ;; implemented things might change for the better. This is unlikely to occur
2198 ;; until CVS 2.0 is released. --ceder 1994-01-23 21:27:51
2199 (let ((oldbuf (get-file-buffer old))
2200 (backend (vc-backend old)))
2201 (unless (or (null backend) (vc-find-backend-function backend 'rename-file))
2202 (error "Renaming files under %s is not supported in VC" backend))
2203 (if (and oldbuf (buffer-modified-p oldbuf))
2204 (error "Please save files before moving them"))
2205 (if (get-file-buffer new)
2206 (error "Already editing new file name"))
2207 (if (file-exists-p new)
2208 (error "New file already exists"))
2209 (when backend
2210 (if (and backend (not (vc-up-to-date-p old)))
2211 (error "Please check in files before moving them"))
2212 (vc-call-backend backend 'rename-file old new))
2213 ;; Move the actual file (unless the backend did it already)
2214 (if (or (not backend) (file-exists-p old))
2215 (rename-file old new))
2216 ;; ?? Renaming a file might change its contents due to keyword expansion.
2217 ;; We should really check out a new copy if the old copy was precisely equal
2218 ;; to some checked in version. However, testing for this is tricky....
2219 (if oldbuf
2220 (with-current-buffer oldbuf
2221 (let ((buffer-read-only buffer-read-only))
2222 (set-visited-file-name new))
2223 (vc-backend new)
2224 (vc-mode-line new)
2225 (set-buffer-modified-p nil)))))
2227 ;; Only defined in very recent Emacsen
2228 (defvar small-temporary-file-directory nil)
2230 ;;;###autoload
2231 (defun vc-update-change-log (&rest args)
2232 "Find change log file and add entries from recent version control logs.
2233 Normally, find log entries for all registered files in the default
2234 directory.
2236 With prefix arg of \\[universal-argument], only find log entries for the current buffer's file.
2238 With any numeric prefix arg, find log entries for all currently visited
2239 files that are under version control. This puts all the entries in the
2240 log for the default directory, which may not be appropriate.
2242 From a program, any ARGS are assumed to be filenames for which
2243 log entries should be gathered."
2244 (interactive
2245 (cond ((consp current-prefix-arg) ;C-u
2246 (list buffer-file-name))
2247 (current-prefix-arg ;Numeric argument.
2248 (let ((files nil)
2249 (buffers (buffer-list))
2250 file)
2251 (while buffers
2252 (setq file (buffer-file-name (car buffers)))
2253 (and file (vc-backend file)
2254 (setq files (cons file files)))
2255 (setq buffers (cdr buffers)))
2256 files))
2258 ;; Don't supply any filenames to backend; this means
2259 ;; it should find all relevant files relative to
2260 ;; the default-directory.
2261 nil)))
2262 (vc-call-backend (vc-responsible-backend default-directory)
2263 'update-changelog args))
2265 (defun vc-default-update-changelog (backend files)
2266 "Default implementation of update-changelog.
2267 Uses `rcs2log' which only works for RCS and CVS."
2268 ;; FIXME: We (c|sh)ould add support for cvs2cl
2269 (let ((odefault default-directory)
2270 (changelog (find-change-log))
2271 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
2272 (tempfile (funcall
2273 (if (fboundp 'make-temp-file) 'make-temp-file 'make-temp-name)
2274 (expand-file-name "vc"
2275 (or small-temporary-file-directory
2276 temporary-file-directory))))
2277 (full-name (or add-log-full-name
2278 (user-full-name)
2279 (user-login-name)
2280 (format "uid%d" (number-to-string (user-uid)))))
2281 (mailing-address (or add-log-mailing-address
2282 user-mail-address)))
2283 (find-file-other-window changelog)
2284 (barf-if-buffer-read-only)
2285 (vc-buffer-sync)
2286 (undo-boundary)
2287 (goto-char (point-min))
2288 (push-mark)
2289 (message "Computing change log entries...")
2290 (message "Computing change log entries... %s"
2291 (unwind-protect
2292 (progn
2293 (setq default-directory odefault)
2294 (if (eq 0 (apply 'call-process
2295 (expand-file-name "rcs2log"
2296 exec-directory)
2297 nil (list t tempfile) nil
2298 "-c" changelog
2299 "-u" (concat (vc-user-login-name)
2300 "\t" full-name
2301 "\t" mailing-address)
2302 (mapcar
2303 (lambda (f)
2304 (file-relative-name
2305 (if (file-name-absolute-p f)
2307 (concat odefault f))))
2308 files)))
2309 "done"
2310 (pop-to-buffer
2311 (set-buffer (get-buffer-create "*vc*")))
2312 (erase-buffer)
2313 (insert-file tempfile)
2314 "failed"))
2315 (setq default-directory (file-name-directory changelog))
2316 (delete-file tempfile)))))
2318 ;;; Annotate functionality
2320 ;; Declare globally instead of additional parameter to
2321 ;; temp-buffer-show-function (not possible to pass more than one
2322 ;; parameter).
2323 (defvar vc-annotate-ratio nil "Global variable.")
2324 (defvar vc-annotate-backend nil "Global variable.")
2326 (defun vc-annotate-get-backend (buffer)
2327 "Return the backend matching \"Annotate\" buffer BUFFER.
2328 Return NIL if no match made. Associations are made based on
2329 `vc-annotate-buffers'."
2330 (cdr (assoc buffer vc-annotate-buffers)))
2332 (define-derived-mode vc-annotate-mode fundamental-mode "Annotate"
2333 "Major mode for buffers displaying output from the `annotate' command.
2335 You can use the mode-specific menu to alter the time-span of the used
2336 colors. See variable `vc-annotate-menu-elements' for customizing the
2337 menu items."
2338 (vc-annotate-add-menu))
2340 (defun vc-annotate-display-default (&optional event)
2341 "Use the default color spectrum for VC Annotate mode."
2342 (interactive "e")
2343 (message "Redisplaying annotation...")
2344 (vc-annotate-display (current-buffer)
2346 (vc-annotate-get-backend (current-buffer)))
2347 (message "Redisplaying annotation...done"))
2349 (defun vc-annotate-add-menu ()
2350 "Add the menu 'Annotate' to the menu bar in VC-Annotate mode."
2351 (setq vc-annotate-mode-menu (make-sparse-keymap "Annotate"))
2352 (define-key vc-annotate-mode-map [menu-bar vc-annotate-mode]
2353 (cons "VC-Annotate" vc-annotate-mode-menu))
2354 (define-key vc-annotate-mode-menu [default]
2355 '("Default" . vc-annotate-display-default))
2356 (let ((menu-elements vc-annotate-menu-elements))
2357 (while menu-elements
2358 (let* ((element (car menu-elements))
2359 (days (round (* element
2360 (vc-annotate-car-last-cons vc-annotate-color-map)
2361 0.7585))))
2362 (setq menu-elements (cdr menu-elements))
2363 (define-key vc-annotate-mode-menu
2364 (vector days)
2365 (cons (format "Span %d days"
2366 days)
2367 `(lambda ()
2368 ,(format "Use colors spanning %d days" days)
2369 (interactive)
2370 (message "Redisplaying annotation...")
2371 (vc-annotate-display
2372 (get-buffer (buffer-name))
2373 (vc-annotate-time-span vc-annotate-color-map ,element)
2374 (vc-annotate-get-backend (current-buffer)))
2375 (message "Redisplaying annotation...done"))))))))
2378 ;;;; (defun vc-BACKEND-annotate-command (file buffer) ...)
2379 ;;;; Execute "annotate" on FILE by using `call-process' and insert
2380 ;;;; the contents in BUFFER.
2382 ;;;###autoload
2383 (defun vc-annotate (ratio)
2384 "Display the result of the \"Annotate\" command using colors.
2385 \"Annotate\" is defined by `vc-BACKEND-annotate-command'. New lines
2386 are displayed in red, old in blue. A prefix argument specifies a
2387 factor for stretching the time scale.
2389 `vc-annotate-menu-elements' customizes the menu elements of the
2390 mode-specific menu. `vc-annotate-color-map' and
2391 `vc-annotate-very-old-color' defines the mapping of time to
2392 colors. `vc-annotate-background' specifies the background color."
2393 (interactive "p")
2394 (vc-ensure-vc-buffer)
2395 (message "Annotating...")
2396 (let ((temp-buffer-name (concat "*Annotate " (buffer-name) "*"))
2397 (temp-buffer-show-function 'vc-annotate-display)
2398 (vc-annotate-ratio ratio)
2399 (vc-annotate-backend (vc-backend (buffer-file-name))))
2400 (if (not (vc-find-backend-function vc-annotate-backend 'annotate-command))
2401 (error "Sorry, annotating is not implemented for %s"
2402 vc-annotate-backend))
2403 (with-output-to-temp-buffer temp-buffer-name
2404 (vc-call-backend vc-annotate-backend 'annotate-command
2405 (file-name-nondirectory (buffer-file-name))
2406 (get-buffer temp-buffer-name)))
2407 ;; Don't use the temp-buffer-name until the buffer is created
2408 ;; (only after `with-output-to-temp-buffer'.)
2409 (setq vc-annotate-buffers
2410 (append vc-annotate-buffers
2411 (list (cons (get-buffer temp-buffer-name) vc-annotate-backend)))))
2412 (message "Annotating... done"))
2415 (defun vc-annotate-car-last-cons (a-list)
2416 "Return car of last cons in association list A-LIST."
2417 (if (not (eq nil (cdr a-list)))
2418 (vc-annotate-car-last-cons (cdr a-list))
2419 (car (car a-list))))
2421 (defun vc-annotate-time-span (a-list span &optional quantize)
2422 "Apply factor SPAN to the time-span of association list A-LIST.
2423 Return the new alist.
2424 Optionally quantize to the factor of QUANTIZE."
2425 ;; Apply span to each car of every cons
2426 (if (not (eq nil a-list))
2427 (append (list (cons (* (car (car a-list)) span)
2428 (cdr (car a-list))))
2429 (vc-annotate-time-span (nthcdr (or quantize ; optional
2430 1) ; Default to cdr
2431 a-list) span quantize))))
2433 (defun vc-annotate-compcar (threshold a-list)
2434 "Test successive cons cells of association list A-LIST against THRESHOLD.
2435 Return the first cons cell which car is not less than THRESHOLD,
2436 nil otherwise"
2437 (let ((i 1)
2438 (tmp-cons (car a-list)))
2439 (while (and tmp-cons (< (car tmp-cons) threshold))
2440 (setq tmp-cons (car (nthcdr i a-list)))
2441 (setq i (+ i 1)))
2442 tmp-cons)) ; Return the appropriate value
2445 ;;;; (defun vc-BACKEND-annotate-difference (point) ...)
2446 ;;;;
2447 ;;;; Return the difference between the age of the line at point and
2448 ;;;; the current time. Return NIL if there is no more comparison to
2449 ;;;; be made in the buffer. Return value as defined for
2450 ;;;; `current-time'. You can safely assume that point is placed at
2451 ;;;; the beginning of each line, starting at `point-min'. The buffer
2452 ;;;; that point is placed in is the Annotate output, as defined by
2453 ;;;; the relevant backend.
2455 (defun vc-annotate-display (buffer &optional color-map backend)
2456 "Do the VC-Annotate display in BUFFER using COLOR-MAP.
2457 The original annotating file is supposed to be handled by BACKEND.
2458 If BACKEND is NIL, variable VC-ANNOTATE-BACKEND is used instead.
2459 This function is destructive on VC-ANNOTATE-BACKEND when BACKEND is non-nil."
2461 ;; Handle the case of the global variable vc-annotate-ratio being
2462 ;; set. This variable is used to pass information from function
2463 ;; vc-annotate since it is not possible to use another parameter
2464 ;; (see temp-buffer-show-function).
2465 (if (and (not color-map) vc-annotate-ratio)
2466 ;; This will only be true if called from vc-annotate with ratio
2467 ;; being non-nil.
2468 (setq color-map (vc-annotate-time-span vc-annotate-color-map
2469 vc-annotate-ratio)))
2470 (set-buffer buffer)
2471 (display-buffer buffer)
2472 (if (not vc-annotate-mode) ; Turn on vc-annotate-mode if not done
2473 (vc-annotate-mode))
2474 (goto-char (point-min)) ; Position at the top of the buffer.
2475 ;; Delete old overlays
2476 (mapcar
2477 (lambda (overlay)
2478 (if (overlay-get overlay 'vc-annotation)
2479 (delete-overlay overlay)))
2480 (overlays-in (point-min) (point-max)))
2481 (goto-char (point-min)) ; Position at the top of the buffer.
2483 (if backend (setq vc-annotate-backend backend)) ; Destructive on `vc-annotate-backend'
2485 (let ((difference (vc-call-backend vc-annotate-backend 'annotate-difference (point))))
2486 (while difference
2487 (let*
2488 ((color (or (vc-annotate-compcar
2489 difference (or color-map vc-annotate-color-map))
2490 (cons nil vc-annotate-very-old-color)))
2491 ;; substring from index 1 to remove any leading `#' in the name
2492 (face-name (concat "vc-annotate-face-" (substring (cdr color) 1)))
2493 ;; Make the face if not done.
2494 (face (or (intern-soft face-name)
2495 (let ((tmp-face (make-face (intern face-name))))
2496 (set-face-foreground tmp-face (cdr color))
2497 (if vc-annotate-background
2498 (set-face-background tmp-face vc-annotate-background))
2499 tmp-face))) ; Return the face
2500 (point (point))
2501 overlay)
2502 (forward-line 1)
2503 (setq overlay (make-overlay point (point)))
2504 (overlay-put overlay 'face face)
2505 (overlay-put overlay 'vc-annotation t))
2506 (setq difference (vc-call-backend vc-annotate-backend 'annotate-difference (point))))))
2509 ;; Collect back-end-dependent stuff here
2511 (defalias 'vc-default-logentry-check 'ignore)
2513 (defun vc-check-headers ()
2514 "Check if the current file has any headers in it."
2515 (interactive)
2516 (vc-call-backend (vc-backend buffer-file-name) 'check-headers))
2518 ;; Back-end-dependent stuff ends here.
2520 ;; Set up key bindings for use while editing log messages
2522 (define-derived-mode vc-log-mode text-mode "VC-Log"
2523 "Major mode for editing VC log entries.
2524 These bindings are added to the global keymap when you enter this mode:
2525 \\[vc-next-action] perform next logical version-control operation on current file
2526 \\[vc-register] register current file
2527 \\[vc-toggle-read-only] like next-action, but won't register files
2528 \\[vc-insert-headers] insert version-control headers in current file
2529 \\[vc-print-log] display change history of current file
2530 \\[vc-revert-buffer] revert buffer to latest version
2531 \\[vc-cancel-version] undo latest checkin
2532 \\[vc-diff] show diffs between file versions
2533 \\[vc-version-other-window] visit old version in another window
2534 \\[vc-directory] show all files locked by any user in or below .
2535 \\[vc-annotate] colorful display of the cvs annotate command
2536 \\[vc-update-change-log] add change log entry from recent checkins
2538 While you are entering a change log message for a version, the following
2539 additional bindings will be in effect.
2541 \\[vc-finish-logentry] proceed with check in, ending log message entry
2543 Whenever you do a checkin, your log comment is added to a ring of
2544 saved comments. These can be recalled as follows:
2546 \\[vc-next-comment] replace region with next message in comment ring
2547 \\[vc-previous-comment] replace region with previous message in comment ring
2548 \\[vc-comment-search-reverse] search backward for regexp in the comment ring
2549 \\[vc-comment-search-forward] search backward for regexp in the comment ring
2551 Entry to the change-log submode calls the value of `text-mode-hook', then
2552 the value of `vc-log-mode-hook'.
2554 Global user options:
2555 `vc-initial-comment' If non-nil, require user to enter a change
2556 comment upon first checkin of the file.
2558 `vc-keep-workfiles' Non-nil value prevents workfiles from being
2559 deleted when changes are checked in
2561 `vc-suppress-confirm' Suppresses some confirmation prompts,
2562 notably for reversions.
2564 vc-BACKEND-header Which keywords to insert when adding headers
2565 with \\[vc-insert-headers]. Defaults to
2566 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under
2567 RCS and CVS.
2569 `vc-static-header-alist' By default, version headers inserted in C files
2570 get stuffed in a static string area so that
2571 ident(RCS/CVS) or what(SCCS) can see them in
2572 the compiled object code. You can override
2573 this by setting this variable to nil, or change
2574 the header template by changing it.
2576 `vc-command-messages' if non-nil, display run messages from the
2577 actual version-control utilities (this is
2578 intended primarily for people hacking vc
2579 itself)."
2580 (make-local-variable 'vc-comment-ring-index))
2582 (defun vc-log-edit (file)
2583 "Set up `log-edit' for use with VC on FILE.
2584 If `log-edit' is not available, resort to `vc-log-mode'."
2585 (setq default-directory
2586 (if file (file-name-directory file)
2587 (with-current-buffer vc-parent-buffer default-directory)))
2588 (if (fboundp 'log-edit)
2589 (log-edit 'vc-finish-logentry nil
2590 (if file `(lambda () ',(list (file-name-nondirectory file)))
2591 ;; If FILE is nil, we were called from vc-dired.
2592 (lambda ()
2593 (with-current-buffer vc-parent-buffer
2594 (dired-get-marked-files t)))))
2595 (vc-log-mode))
2596 (set (make-local-variable 'vc-log-file) file)
2597 (make-local-variable 'vc-log-version)
2598 (set-buffer-modified-p nil)
2599 (setq buffer-file-name nil))
2601 ;;; These things should probably be generally available
2603 (defun vc-file-tree-walk (dirname func &rest args)
2604 "Walk recursively through DIRNAME.
2605 Invoke FUNC f ARGS on each VC-managed file f underneath it."
2606 (vc-file-tree-walk-internal (expand-file-name dirname) func args)
2607 (message "Traversing directory %s...done" dirname))
2609 (defun vc-file-tree-walk-internal (file func args)
2610 (if (not (file-directory-p file))
2611 (if (vc-backend file) (apply func file args))
2612 (message "Traversing directory %s..." (abbreviate-file-name file))
2613 (let ((dir (file-name-as-directory file)))
2614 (mapcar
2615 (lambda (f) (or
2616 (string-equal f ".")
2617 (string-equal f "..")
2618 (member f vc-directory-exclusion-list)
2619 (let ((dirf (expand-file-name f dir)))
2621 (file-symlink-p dirf);; Avoid possible loops
2622 (vc-file-tree-walk-internal dirf func args)))))
2623 (directory-files dir)))))
2625 (provide 'vc)
2627 ;;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
2629 ;;; These may be useful to anyone who has to debug or extend the package.
2630 ;;; (Note that this information corresponds to versions 5.x. Some of it
2631 ;;; might have been invalidated by the additions to support branching
2632 ;;; and RCS keyword lookup. AS, 1995/03/24)
2634 ;;; A fundamental problem in VC is that there are time windows between
2635 ;;; vc-next-action's computations of the file's version-control state and
2636 ;;; the actions that change it. This is a window open to lossage in a
2637 ;;; multi-user environment; someone else could nip in and change the state
2638 ;;; of the master during it.
2640 ;;; The performance problem is that rlog/prs calls are very expensive; we want
2641 ;;; to avoid them as much as possible.
2643 ;;; ANALYSIS:
2645 ;;; The performance problem, it turns out, simplifies in practice to the
2646 ;;; problem of making vc-state fast. The two other functions that call
2647 ;;; prs/rlog will not be so commonly used that the slowdown is a problem; one
2648 ;;; makes snapshots, the other deletes the calling user's last change in the
2649 ;;; master.
2651 ;;; The race condition implies that we have to either (a) lock the master
2652 ;;; during the entire execution of vc-next-action, or (b) detect and
2653 ;;; recover from errors resulting from dispatch on an out-of-date state.
2655 ;;; Alternative (a) appears to be infeasible. The problem is that we can't
2656 ;;; guarantee that the lock will ever be removed. Suppose a user starts a
2657 ;;; checkin, the change message buffer pops up, and the user, having wandered
2658 ;;; off to do something else, simply forgets about it?
2660 ;;; Alternative (b), on the other hand, works well with a cheap way to speed up
2661 ;;; vc-state. Usually, if a file is registered, we can read its locked/
2662 ;;; unlocked state and its current owner from its permissions.
2664 ;;; This shortcut will fail if someone has manually changed the workfile's
2665 ;;; permissions; also if developers are munging the workfile in several
2666 ;;; directories, with symlinks to a master (in this latter case, the
2667 ;;; permissions shortcut will fail to detect a lock asserted from another
2668 ;;; directory).
2670 ;;; Note that these cases correspond exactly to the errors which could happen
2671 ;;; because of a competing checkin/checkout race in between two instances of
2672 ;;; vc-next-action.
2674 ;;; For VC's purposes, a workfile/master pair may have the following states:
2676 ;;; A. Unregistered. There is a workfile, there is no master.
2678 ;;; B. Registered and not locked by anyone.
2680 ;;; C. Locked by calling user and unchanged.
2682 ;;; D. Locked by the calling user and changed.
2684 ;;; E. Locked by someone other than the calling user.
2686 ;;; This makes for 25 states and 20 error conditions. Here's the matrix:
2688 ;;; VC's idea of state
2689 ;;; |
2690 ;;; V Actual state RCS action SCCS action Effect
2691 ;;; A B C D E
2692 ;;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
2693 ;;; B 5 . 6 7 8 co -l get -e checkout
2694 ;;; C 9 10 . 11 12 co -u unget; get revert
2695 ;;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
2696 ;;; E 17 18 19 20 . rcs -u -M -l unget -n ; get -g steal lock
2698 ;;; All commands take the master file name as a last argument (not shown).
2700 ;;; In the discussion below, a "self-race" is a pathological situation in
2701 ;;; which VC operations are being attempted simultaneously by two or more
2702 ;;; Emacsen running under the same username.
2704 ;;; The vc-next-action code has the following windows:
2706 ;;; Window P:
2707 ;;; Between the check for existence of a master file and the call to
2708 ;;; admin/checkin in vc-buffer-admin (apparent state A). This window may
2709 ;;; never close if the initial-comment feature is on.
2711 ;;; Window Q:
2712 ;;; Between the call to vc-workfile-unchanged-p in and the immediately
2713 ;;; following revert (apparent state C).
2715 ;;; Window R:
2716 ;;; Between the call to vc-workfile-unchanged-p in and the following
2717 ;;; checkin (apparent state D). This window may never close.
2719 ;;; Window S:
2720 ;;; Between the unlock and the immediately following checkout during a
2721 ;;; revert operation (apparent state C). Included in window Q.
2723 ;;; Window T:
2724 ;;; Between vc-state and the following checkout (apparent state B).
2726 ;;; Window U:
2727 ;;; Between vc-state and the following revert (apparent state C).
2728 ;;; Includes windows Q and S.
2730 ;;; Window V:
2731 ;;; Between vc-state and the following checkin (apparent state
2732 ;;; D). This window may never be closed if the user fails to complete the
2733 ;;; checkin message. Includes window R.
2735 ;;; Window W:
2736 ;;; Between vc-state and the following steal-lock (apparent
2737 ;;; state E). This window may never close if the user fails to complete
2738 ;;; the steal-lock message. Includes window X.
2740 ;;; Window X:
2741 ;;; Between the unlock and the immediately following re-lock during a
2742 ;;; steal-lock operation (apparent state E). This window may never close
2743 ;;; if the user fails to complete the steal-lock message.
2745 ;;; Errors:
2747 ;;; Apparent state A ---
2749 ;;; 1. File looked unregistered but is actually registered and not locked.
2751 ;;; Potential cause: someone else's admin during window P, with
2752 ;;; caller's admin happening before their checkout.
2754 ;;; RCS: Prior to version 5.6.4, ci fails with message
2755 ;;; "no lock set by <user>". From 5.6.4 onwards, VC uses the new
2756 ;;; ci -i option and the message is "<file>,v: already exists".
2757 ;;; SCCS: admin will fail with error (ad19).
2759 ;;; We can let these errors be passed up to the user.
2761 ;;; 2. File looked unregistered but is actually locked by caller, unchanged.
2763 ;;; Potential cause: self-race during window P.
2765 ;;; RCS: Prior to version 5.6.4, reverts the file to the last saved
2766 ;;; version and unlocks it. From 5.6.4 onwards, VC uses the new
2767 ;;; ci -i option, failing with message "<file>,v: already exists".
2768 ;;; SCCS: will fail with error (ad19).
2770 ;;; Either of these consequences is acceptable.
2772 ;;; 3. File looked unregistered but is actually locked by caller, changed.
2774 ;;; Potential cause: self-race during window P.
2776 ;;; RCS: Prior to version 5.6.4, VC registers the caller's workfile as
2777 ;;; a delta with a null change comment (the -t- switch will be
2778 ;;; ignored). From 5.6.4 onwards, VC uses the new ci -i option,
2779 ;;; failing with message "<file>,v: already exists".
2780 ;;; SCCS: will fail with error (ad19).
2782 ;;; 4. File looked unregistered but is locked by someone else.
2784 ;;; Potential cause: someone else's admin during window P, with
2785 ;;; caller's admin happening *after* their checkout.
2787 ;;; RCS: Prior to version 5.6.4, ci fails with a
2788 ;;; "no lock set by <user>" message. From 5.6.4 onwards,
2789 ;;; VC uses the new ci -i option, failing with message
2790 ;;; "<file>,v: already exists".
2791 ;;; SCCS: will fail with error (ad19).
2793 ;;; We can let these errors be passed up to the user.
2795 ;;; Apparent state B ---
2797 ;;; 5. File looked registered and not locked, but is actually unregistered.
2799 ;;; Potential cause: master file got nuked during window P.
2801 ;;; RCS: will fail with "RCS/<file>: No such file or directory"
2802 ;;; SCCS: will fail with error ut4.
2804 ;;; We can let these errors be passed up to the user.
2806 ;;; 6. File looked registered and not locked, but is actually locked by the
2807 ;;; calling user and unchanged.
2809 ;;; Potential cause: self-race during window T.
2811 ;;; RCS: in the same directory as the previous workfile, co -l will fail
2812 ;;; with "co error: writable foo exists; checkout aborted". In any other
2813 ;;; directory, checkout will succeed.
2814 ;;; SCCS: will fail with ge17.
2816 ;;; Either of these consequences is acceptable.
2818 ;;; 7. File looked registered and not locked, but is actually locked by the
2819 ;;; calling user and changed.
2821 ;;; As case 6.
2823 ;;; 8. File looked registered and not locked, but is actually locked by another
2824 ;;; user.
2826 ;;; Potential cause: someone else checks it out during window T.
2828 ;;; RCS: co error: revision 1.3 already locked by <user>
2829 ;;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
2831 ;;; We can let these errors be passed up to the user.
2833 ;;; Apparent state C ---
2835 ;;; 9. File looks locked by calling user and unchanged, but is unregistered.
2837 ;;; As case 5.
2839 ;;; 10. File looks locked by calling user and unchanged, but is actually not
2840 ;;; locked.
2842 ;;; Potential cause: a self-race in window U, or by the revert's
2843 ;;; landing during window X of some other user's steal-lock or window S
2844 ;;; of another user's revert.
2846 ;;; RCS: succeeds, refreshing the file from the identical version in
2847 ;;; the master.
2848 ;;; SCCS: fails with error ut4 (p file nonexistent).
2850 ;;; Either of these consequences is acceptable.
2852 ;;; 11. File is locked by calling user. It looks unchanged, but is actually
2853 ;;; changed.
2855 ;;; Potential cause: the file would have to be touched by a self-race
2856 ;;; during window Q.
2858 ;;; The revert will succeed, removing whatever changes came with
2859 ;;; the touch. It is theoretically possible that work could be lost.
2861 ;;; 12. File looks like it's locked by the calling user and unchanged, but
2862 ;;; it's actually locked by someone else.
2864 ;;; Potential cause: a steal-lock in window V.
2866 ;;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
2867 ;;; SCCS: fails with error un2
2869 ;;; We can pass these errors up to the user.
2871 ;;; Apparent state D ---
2873 ;;; 13. File looks like it's locked by the calling user and changed, but it's
2874 ;;; actually unregistered.
2876 ;;; Potential cause: master file got nuked during window P.
2878 ;;; RCS: Prior to version 5.6.4, checks in the user's version as an
2879 ;;; initial delta. From 5.6.4 onwards, VC uses the new ci -j
2880 ;;; option, failing with message "no such file or directory".
2881 ;;; SCCS: will fail with error ut4.
2883 ;;; This case is kind of nasty. Under RCS prior to version 5.6.4,
2884 ;;; VC may fail to detect the loss of previous version information.
2886 ;;; 14. File looks like it's locked by the calling user and changed, but it's
2887 ;;; actually unlocked.
2889 ;;; Potential cause: self-race in window V, or the checkin happening
2890 ;;; during the window X of someone else's steal-lock or window S of
2891 ;;; someone else's revert.
2893 ;;; RCS: ci will fail with "no lock set by <user>".
2894 ;;; SCCS: delta will fail with error ut4.
2896 ;;; 15. File looks like it's locked by the calling user and changed, but it's
2897 ;;; actually locked by the calling user and unchanged.
2899 ;;; Potential cause: another self-race --- a whole checkin/checkout
2900 ;;; sequence by the calling user would have to land in window R.
2902 ;;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
2903 ;;; RCS: reverts to the file state as of the second user's checkin, leaving
2904 ;;; the file unlocked.
2906 ;;; It is theoretically possible that work could be lost under RCS.
2908 ;;; 16. File looks like it's locked by the calling user and changed, but it's
2909 ;;; actually locked by a different user.
2911 ;;; RCS: ci error: no lock set by <user>
2912 ;;; SCCS: unget will fail with error un2
2914 ;;; We can pass these errors up to the user.
2916 ;;; Apparent state E ---
2918 ;;; 17. File looks like it's locked by some other user, but it's actually
2919 ;;; unregistered.
2921 ;;; As case 13.
2923 ;;; 18. File looks like it's locked by some other user, but it's actually
2924 ;;; unlocked.
2926 ;;; Potential cause: someone released a lock during window W.
2928 ;;; RCS: The calling user will get the lock on the file.
2929 ;;; SCCS: unget -n will fail with cm4.
2931 ;;; Either of these consequences will be OK.
2933 ;;; 19. File looks like it's locked by some other user, but it's actually
2934 ;;; locked by the calling user and unchanged.
2936 ;;; Potential cause: the other user relinquishing a lock followed by
2937 ;;; a self-race, both in window W.
2939 ;;; Under both RCS and SCCS, both unlock and lock will succeed, making
2940 ;;; the sequence a no-op.
2942 ;;; 20. File looks like it's locked by some other user, but it's actually
2943 ;;; locked by the calling user and changed.
2945 ;;; As case 19.
2947 ;;; PROBLEM CASES:
2949 ;;; In order of decreasing severity:
2951 ;;; Cases 11 and 15 are the only ones that potentially lose work.
2952 ;;; They would require a self-race for this to happen.
2954 ;;; Case 13 in RCS loses information about previous deltas, retaining
2955 ;;; only the information in the current workfile. This can only happen
2956 ;;; if the master file gets nuked in window P.
2958 ;;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
2959 ;;; no change comment in the master. This would require a self-race in
2960 ;;; window P or R respectively.
2962 ;;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
2964 ;;; Unfortunately, it appears to me that no recovery is possible in these
2965 ;;; cases. They don't yield error messages, so there's no way to tell that
2966 ;;; a race condition has occurred.
2968 ;;; All other cases don't change either the workfile or the master, and
2969 ;;; trigger command errors which the user will see.
2971 ;;; Thus, there is no explicit recovery code.
2973 ;;; vc.el ends here