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