(Syntax Table Functions): Add syntax-after.
[emacs.git] / lisp / vc.el
blob5aac27e31a4921bf74f42cfb4f7968e2658642db
1 ;;; vc.el --- drive a version-control system from within Emacs
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 ;; 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
6 ;; Author: FSF (see below for full credits)
7 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
8 ;; Keywords: tools
10 ;; $Id$
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
29 ;;; Credits:
31 ;; VC was initially designed and implemented by Eric S. Raymond
32 ;; <esr@snark.thyrsus.com>. Over the years, many people have
33 ;; contributed substantial amounts of work to VC. These include:
34 ;; Per Cederqvist <ceder@lysator.liu.se>
35 ;; Paul Eggert <eggert@twinsun.com>
36 ;; Sebastian Kremer <sk@thp.uni-koeln.de>
37 ;; Martin Lorentzson <martinl@gnu.org>
38 ;; Dave Love <fx@gnu.org>
39 ;; Stefan Monnier <monnier@cs.yale.edu>
40 ;; J.D. Smith <jdsmith@alum.mit.edu>
41 ;; Andre Spiegel <spiegel@gnu.org>
42 ;; Richard Stallman <rms@gnu.org>
43 ;; Thien-Thi Nguyen <ttn@gnu.org>
45 ;;; Commentary:
47 ;; This mode is fully documented in the Emacs user's manual.
49 ;; Supported version-control systems presently include SCCS, RCS, and CVS.
51 ;; Some features will not work with old RCS versions. Where
52 ;; appropriate, VC finds out which version you have, and allows or
53 ;; disallows those features (stealing locks, for example, works only
54 ;; from 5.6.2 onwards).
55 ;; Even initial checkins will fail if your RCS version is so old that ci
56 ;; doesn't understand -t-; this has been known to happen to people running
57 ;; NExTSTEP 3.0.
59 ;; You can support the RCS -x option by customizing vc-rcs-master-templates.
61 ;; Proper function of the SCCS diff commands requires the shellscript vcdiff
62 ;; to be installed somewhere on Emacs's path for executables.
64 ;; If your site uses the ChangeLog convention supported by Emacs, the
65 ;; function log-edit-comment-to-change-log could prove a useful checkin hook,
66 ;; although you might prefer to use C-c C-a (i.e. log-edit-insert-changelog)
67 ;; from the commit buffer instead or to set `log-edit-setup-invert'.
69 ;; The vc code maintains some internal state in order to reduce expensive
70 ;; version-control operations to a minimum. Some names are only computed
71 ;; once. If you perform version control operations with RCS/SCCS/CVS while
72 ;; vc's back is turned, or move/rename master files while vc is running,
73 ;; vc may get seriously confused. Don't do these things!
75 ;; Developer's notes on some concurrency issues are included at the end of
76 ;; the file.
78 ;; ADDING SUPPORT FOR OTHER BACKENDS
80 ;; VC can use arbitrary version control systems as a backend. To add
81 ;; support for a new backend named SYS, write a library vc-sys.el that
82 ;; contains functions of the form `vc-sys-...' (note that SYS is in lower
83 ;; case for the function and library names). VC will use that library if
84 ;; you put the symbol SYS somewhere into the list of
85 ;; `vc-handled-backends'. Then, for example, if `vc-sys-registered'
86 ;; returns non-nil for a file, all SYS-specific versions of VC commands
87 ;; will be available for that file.
89 ;; VC keeps some per-file information in the form of properties (see
90 ;; vc-file-set/getprop in vc-hooks.el). The backend-specific functions
91 ;; do not generally need to be aware of these properties. For example,
92 ;; `vc-sys-workfile-version' should compute the workfile version and
93 ;; return it; it should not look it up in the property, and it needn't
94 ;; store it there either. However, if a backend-specific function does
95 ;; store a value in a property, that value takes precedence over any
96 ;; value that the generic code might want to set (check for uses of
97 ;; the macro `with-vc-properties' in vc.el).
99 ;; In the list of functions below, each identifier needs to be prepended
100 ;; with `vc-sys-'. Some of the functions are mandatory (marked with a
101 ;; `*'), others are optional (`-').
103 ;; STATE-QUERYING FUNCTIONS
105 ;; * registered (file)
107 ;; Return non-nil if FILE is registered in this backend.
109 ;; * state (file)
111 ;; Return the current version control state of FILE. For a list of
112 ;; possible values, see `vc-state'. This function should do a full and
113 ;; reliable state computation; it is usually called immediately after
114 ;; C-x v v. If you want to use a faster heuristic when visiting a
115 ;; file, put that into `state-heuristic' below.
117 ;; - state-heuristic (file)
119 ;; If provided, this function is used to estimate the version control
120 ;; state of FILE at visiting time. It should be considerably faster
121 ;; than the implementation of `state'. For a list of possible values,
122 ;; see the doc string of `vc-state'.
124 ;; - dir-state (dir)
126 ;; If provided, this function is used to find the version control state
127 ;; of all files in DIR in a fast way. The function should not return
128 ;; anything, but rather store the files' states into the corresponding
129 ;; `vc-state' properties.
131 ;; * workfile-version (file)
133 ;; Return the current workfile version of FILE.
135 ;; - latest-on-branch-p (file)
137 ;; Return non-nil if the current workfile version of FILE is the latest
138 ;; on its branch. The default implementation always returns t, which
139 ;; means that working with non-current versions is not supported by
140 ;; default.
142 ;; * checkout-model (file)
144 ;; Indicate whether FILE needs to be "checked out" before it can be
145 ;; edited. See `vc-checkout-model' for a list of possible values.
147 ;; - workfile-unchanged-p (file)
149 ;; Return non-nil if FILE is unchanged from its current workfile
150 ;; version. This function should do a brief comparison of FILE's
151 ;; contents with those of the master version. If the backend does not
152 ;; have such a brief-comparison feature, the default implementation of
153 ;; this function can be used, which delegates to a full
154 ;; vc-BACKEND-diff. (Note that vc-BACKEND-diff must not run
155 ;; asynchronously in this case.)
157 ;; - mode-line-string (file)
159 ;; If provided, this function should return the VC-specific mode line
160 ;; string for FILE. The default implementation deals well with all
161 ;; states that `vc-state' can return.
163 ;; - dired-state-info (file)
165 ;; Translate the `vc-state' property of FILE into a string that can be
166 ;; used in a vc-dired buffer. The default implementation deals well
167 ;; with all states that `vc-state' can return.
169 ;; STATE-CHANGING FUNCTIONS
171 ;; * register (file &optional rev comment)
173 ;; Register FILE in this backend. Optionally, an initial revision REV
174 ;; and an initial description of the file, COMMENT, may be specified.
175 ;; The implementation should pass the value of vc-register-switches
176 ;; to the backend command.
178 ;; - init-version (file)
180 ;; The initial version to use when registering FILE if one is not
181 ;; specified by the user. If not provided, the variable
182 ;; vc-default-init-version is used instead.
184 ;; - responsible-p (file)
186 ;; Return non-nil if this backend considers itself "responsible" for
187 ;; FILE, which can also be a directory. This function is used to find
188 ;; out what backend to use for registration of new files and for things
189 ;; like change log generation. The default implementation always
190 ;; returns nil.
192 ;; - could-register (file)
194 ;; Return non-nil if FILE could be registered under this backend. The
195 ;; default implementation always returns t.
197 ;; - receive-file (file rev)
199 ;; Let this backend "receive" a file that is already registered under
200 ;; another backend. The default implementation simply calls `register'
201 ;; for FILE, but it can be overridden to do something more specific,
202 ;; e.g. keep revision numbers consistent or choose editing modes for
203 ;; FILE that resemble those of the other backend.
205 ;; - unregister (file)
207 ;; Unregister FILE from this backend. This is only needed if this
208 ;; backend may be used as a "more local" backend for temporary editing.
210 ;; * checkin (file rev comment)
212 ;; Commit changes in FILE to this backend. If REV is non-nil, that
213 ;; should become the new revision number. COMMENT is used as a
214 ;; check-in comment. The implementation should pass the value of
215 ;; vc-checkin-switches to the backend command.
217 ;; * find-version (file rev buffer)
219 ;; Fetch revision REV of file FILE and put it into BUFFER.
220 ;; If REV is the empty string, fetch the head of the trunk.
221 ;; The implementation should pass the value of vc-checkout-switches
222 ;; to the backend command.
224 ;; * checkout (file &optional editable rev)
226 ;; Check out revision REV of FILE into the working area. If EDITABLE
227 ;; is non-nil, FILE should be writable by the user and if locking is
228 ;; used for FILE, a lock should also be set. If REV is non-nil, that
229 ;; is the revision to check out (default is current workfile version).
230 ;; If REV is t, that means to check out the head of the current branch;
231 ;; if it is the empty string, check out the head of the trunk.
232 ;; The implementation should pass the value of vc-checkout-switches
233 ;; to the backend command.
235 ;; * revert (file &optional contents-done)
237 ;; Revert FILE back to the current workfile version. If optional
238 ;; arg CONTENTS-DONE is non-nil, then the contents of FILE have
239 ;; already been reverted from a version backup, and this function
240 ;; only needs to update the status of FILE within the backend.
242 ;; - cancel-version (file editable)
244 ;; Cancel the current workfile version of FILE, i.e. remove it from the
245 ;; master. EDITABLE non-nil means that FILE should be writable
246 ;; afterwards, and if locking is used for FILE, then a lock should also
247 ;; be set. If this function is not provided, trying to cancel a
248 ;; version is caught as an error.
250 ;; - merge (file rev1 rev2)
252 ;; Merge the changes between REV1 and REV2 into the current working file.
254 ;; - merge-news (file)
256 ;; Merge recent changes from the current branch into FILE.
258 ;; - steal-lock (file &optional version)
260 ;; Steal any lock on the current workfile version of FILE, or on
261 ;; VERSION if that is provided. This function is only needed if
262 ;; locking is used for files under this backend, and if files can
263 ;; indeed be locked by other users.
265 ;; HISTORY FUNCTIONS
267 ;; * print-log (file &optional buffer)
269 ;; Insert the revision log of FILE into BUFFER, or the *vc* buffer
270 ;; if BUFFER is nil.
272 ;; - show-log-entry (version)
274 ;; If provided, search the log entry for VERSION in the current buffer,
275 ;; and make sure it is displayed in the buffer's window. The default
276 ;; implementation of this function works for RCS-style logs.
278 ;; - wash-log (file)
280 ;; Remove all non-comment information from the output of print-log. The
281 ;; default implementation of this function works for RCS-style logs.
283 ;; - logentry-check ()
285 ;; If defined, this function is run to find out whether the user
286 ;; entered a valid log entry for check-in. The log entry is in the
287 ;; current buffer, and if it is not a valid one, the function should
288 ;; throw an error.
290 ;; - comment-history (file)
292 ;; Return a string containing all log entries that were made for FILE.
293 ;; This is used for transferring a file from one backend to another,
294 ;; retaining comment information. The default implementation of this
295 ;; function does this by calling print-log and then wash-log, and
296 ;; returning the resulting buffer contents as a string.
298 ;; - update-changelog (files)
300 ;; Using recent log entries, create ChangeLog entries for FILES, or for
301 ;; all files at or below the default-directory if FILES is nil. The
302 ;; default implementation runs rcs2log, which handles RCS- and
303 ;; CVS-style logs.
305 ;; * diff (file &optional rev1 rev2 buffer)
307 ;; Insert the diff for FILE into BUFFER, or the *vc-diff* buffer if
308 ;; BUFFER is nil. If REV1 and REV2 are non-nil, report differences
309 ;; from REV1 to REV2. If REV1 is nil, use the current workfile
310 ;; version (as found in the repository) as the older version; if
311 ;; REV2 is nil, use the current workfile contents as the newer
312 ;; version. This function should pass the value of (vc-switches
313 ;; BACKEND 'diff) to the backend command. It should return a status
314 ;; of either 0 (no differences found), or 1 (either non-empty diff
315 ;; or the diff is run asynchronously).
317 ;; - diff-tree (dir &optional rev1 rev2)
319 ;; Insert the diff for all files at and below DIR into the *vc-diff*
320 ;; buffer. The meaning of REV1 and REV2 is the same as for
321 ;; vc-BACKEND-diff. The default implementation does an explicit tree
322 ;; walk, calling vc-BACKEND-diff for each individual file.
324 ;; - annotate-command (file buf rev)
326 ;; If this function is provided, it should produce an annotated version
327 ;; of FILE in BUF, relative to version REV. This is currently only
328 ;; implemented for CVS, using the `cvs annotate' command.
330 ;; - annotate-time ()
332 ;; Only required if `annotate-command' is defined for the backend.
333 ;; Return the time of the next line of annotation at or after point,
334 ;; as a floating point fractional number of days. The helper
335 ;; function `vc-annotate-convert-time' may be useful for converting
336 ;; multi-part times as returned by `current-time' and `encode-time'
337 ;; to this format. Return nil if no more lines of annotation appear
338 ;; in the buffer. You can safely assume that point is placed at the
339 ;; beginning of each line, starting at `point-min'. The buffer that
340 ;; point is placed in is the Annotate output, as defined by the
341 ;; relevant backend. This function also affects how much of the line
342 ;; is fontified; where it leaves point is where fontification begins.
344 ;; - annotate-current-time ()
346 ;; Only required if `annotate-command' is defined for the backend,
347 ;; AND you'd like the current time considered to be anything besides
348 ;; (vs-annotate-convert-time (current-time)) -- i.e. the current
349 ;; time with hours, minutes, and seconds included. Probably safe to
350 ;; ignore. Return the current-time, in units of fractional days.
352 ;; - annotate-extract-revision-at-line ()
354 ;; Only required if `annotate-command' is defined for the backend.
355 ;; Invoked from a buffer in vc-annotate-mode, return the revision
356 ;; corresponding to the current line, or nil if there is no revision
357 ;; corresponding to the current line.
359 ;; SNAPSHOT SYSTEM
361 ;; - create-snapshot (dir name branchp)
363 ;; Take a snapshot of the current state of files under DIR and name it
364 ;; NAME. This should make sure that files are up-to-date before
365 ;; proceeding with the action. DIR can also be a file and if BRANCHP
366 ;; is specified, NAME should be created as a branch and DIR should be
367 ;; checked out under this new branch. The default implementation does
368 ;; not support branches but does a sanity check, a tree traversal and
369 ;; for each file calls `assign-name'.
371 ;; - assign-name (file name)
373 ;; Give name NAME to the current version of FILE, assuming it is
374 ;; up-to-date. Only used by the default version of `create-snapshot'.
376 ;; - retrieve-snapshot (dir name update)
378 ;; Retrieve a named snapshot of all registered files at or below DIR.
379 ;; If UPDATE is non-nil, then update buffers of any files in the
380 ;; snapshot that are currently visited. The default implementation
381 ;; does a sanity check whether there aren't any uncommitted changes at
382 ;; or below DIR, and then performs a tree walk, using the `checkout'
383 ;; function to retrieve the corresponding versions.
385 ;; MISCELLANEOUS
387 ;; - make-version-backups-p (file)
389 ;; Return non-nil if unmodified repository versions of FILE should be
390 ;; backed up locally. If this is done, VC can perform `diff' and
391 ;; `revert' operations itself, without calling the backend system. The
392 ;; default implementation always returns nil.
394 ;; - repository-hostname (dirname)
396 ;; Return the hostname that the backend will have to contact
397 ;; in order to operate on a file in DIRNAME. If the return value
398 ;; is nil, it means that the repository is local.
399 ;; This function is used in `vc-stay-local-p' which backends can use
400 ;; for their convenience.
402 ;; - previous-version (file rev)
404 ;; Return the version number that precedes REV for FILE, or nil if no such
405 ;; version exists.
407 ;; - next-version (file rev)
409 ;; Return the version number that follows REV for FILE, or nil if no such
410 ;; version exists.
412 ;; - check-headers ()
414 ;; Return non-nil if the current buffer contains any version headers.
416 ;; - clear-headers ()
418 ;; In the current buffer, reset all version headers to their unexpanded
419 ;; form. This function should be provided if the state-querying code
420 ;; for this backend uses the version headers to determine the state of
421 ;; a file. This function will then be called whenever VC changes the
422 ;; version control state in such a way that the headers would give
423 ;; wrong information.
425 ;; - delete-file (file)
427 ;; Delete FILE and mark it as deleted in the repository. If this
428 ;; function is not provided, the command `vc-delete-file' will
429 ;; signal an error.
431 ;; - rename-file (old new)
433 ;; Rename file OLD to NEW, both in the working area and in the
434 ;; repository. If this function is not provided, the renaming
435 ;; will be done by (vc-delete-file old) and (vc-register new).
437 ;; - find-file-hook ()
439 ;; Operation called in current buffer when opening a file. This can
440 ;; be used by the backend to setup some local variables it might need.
442 ;; - find-file-not-found-hook ()
444 ;; Operation called in current buffer when opening a non-existing file.
445 ;; By default, this asks the user if she wants to check out the file.
447 ;;; Code:
449 (require 'vc-hooks)
450 (require 'ring)
451 (eval-when-compile
452 (require 'cl)
453 (require 'compile)
454 (require 'dired) ; for dired-map-over-marks macro
455 (require 'dired-aux)) ; for dired-kill-{line,tree}
457 (if (not (assoc 'vc-parent-buffer minor-mode-alist))
458 (setq minor-mode-alist
459 (cons '(vc-parent-buffer vc-parent-buffer-name)
460 minor-mode-alist)))
462 ;; General customization
464 (defgroup vc nil
465 "Version-control system in Emacs."
466 :group 'tools)
468 (defcustom vc-suppress-confirm nil
469 "*If non-nil, treat user as expert; suppress yes-no prompts on some things."
470 :type 'boolean
471 :group 'vc)
473 (defcustom vc-delete-logbuf-window t
474 "*If non-nil, delete the *VC-log* buffer and window after each logical action.
475 If nil, bury that buffer instead.
476 This is most useful if you have multiple windows on a frame and would like to
477 preserve the setting."
478 :type 'boolean
479 :group 'vc)
481 (defcustom vc-initial-comment nil
482 "*If non-nil, prompt for initial comment when a file is registered."
483 :type 'boolean
484 :group 'vc)
486 (defcustom vc-default-init-version "1.1"
487 "*A string used as the default version number when a new file is registered.
488 This can be overridden by giving a prefix argument to \\[vc-register]. This
489 can also be overridden by a particular VC backend."
490 :type 'string
491 :group 'vc
492 :version "20.3")
494 (defcustom vc-command-messages nil
495 "*If non-nil, display run messages from back-end commands."
496 :type 'boolean
497 :group 'vc)
499 (defcustom vc-checkin-switches nil
500 "*A string or list of strings specifying extra switches for checkin.
501 These are passed to the checkin program by \\[vc-checkin]."
502 :type '(choice (const :tag "None" nil)
503 (string :tag "Argument String")
504 (repeat :tag "Argument List"
505 :value ("")
506 string))
507 :group 'vc)
509 (defcustom vc-checkout-switches nil
510 "*A string or list of strings specifying extra switches for checkout.
511 These are passed to the checkout program by \\[vc-checkout]."
512 :type '(choice (const :tag "None" nil)
513 (string :tag "Argument String")
514 (repeat :tag "Argument List"
515 :value ("")
516 string))
517 :group 'vc)
519 (defcustom vc-register-switches nil
520 "*A string or list of strings; extra switches for registering a file.
521 These are passed to the checkin program by \\[vc-register]."
522 :type '(choice (const :tag "None" nil)
523 (string :tag "Argument String")
524 (repeat :tag "Argument List"
525 :value ("")
526 string))
527 :group 'vc)
529 (defcustom vc-dired-listing-switches "-al"
530 "*Switches passed to `ls' for vc-dired. MUST contain the `l' option."
531 :type 'string
532 :group 'vc
533 :version "21.1")
535 (defcustom vc-dired-recurse t
536 "*If non-nil, show directory trees recursively in VC Dired."
537 :type 'boolean
538 :group 'vc
539 :version "20.3")
541 (defcustom vc-dired-terse-display t
542 "*If non-nil, show only locked files in VC Dired."
543 :type 'boolean
544 :group 'vc
545 :version "20.3")
547 (defcustom vc-directory-exclusion-list '("SCCS" "RCS" "CVS" "MCVS" ".svn")
548 "*List of directory names to be ignored when walking directory trees."
549 :type '(repeat string)
550 :group 'vc)
552 (defcustom vc-diff-switches nil
553 "*A string or list of strings specifying switches for diff under VC.
554 When running diff under a given BACKEND, VC concatenates the values of
555 `diff-switches', `vc-diff-switches', and `vc-BACKEND-diff-switches' to
556 get the switches for that command. Thus, `vc-diff-switches' should
557 contain switches that are specific to version control, but not
558 specific to any particular backend."
559 :type '(choice (const :tag "None" nil)
560 (string :tag "Argument String")
561 (repeat :tag "Argument List"
562 :value ("")
563 string))
564 :group 'vc
565 :version "21.1")
567 ;;;###autoload
568 (defcustom vc-checkout-hook nil
569 "*Normal hook (list of functions) run after checking out a file.
570 See `run-hooks'."
571 :type 'hook
572 :group 'vc
573 :version "21.1")
575 (defcustom vc-annotate-display-mode nil
576 "Which mode to color the output of \\[vc-annotate] with by default."
577 :type '(choice (const :tag "Default" nil)
578 (const :tag "Scale to Oldest" scale)
579 (const :tag "Scale Oldest->Newest" fullscale)
580 (number :tag "Specify Fractional Number of Days"
581 :value "20.5"))
582 :group 'vc)
584 ;;;###autoload
585 (defcustom vc-checkin-hook nil
586 "*Normal hook (list of functions) run after a checkin is done.
587 See also `log-edit-done-hook'."
588 :type 'hook
589 :options '(log-edit-comment-to-change-log)
590 :group 'vc)
592 ;;;###autoload
593 (defcustom vc-before-checkin-hook nil
594 "*Normal hook (list of functions) run before a file is checked in.
595 See `run-hooks'."
596 :type 'hook
597 :group 'vc)
599 (defcustom vc-logentry-check-hook nil
600 "*Normal hook run by `vc-backend-logentry-check'.
601 Use this to impose your own rules on the entry in addition to any the
602 version control backend imposes itself."
603 :type 'hook
604 :group 'vc)
606 ;; Annotate customization
607 (defcustom vc-annotate-color-map
608 '(( 20. . "#FF0000")
609 ( 40. . "#FF3800")
610 ( 60. . "#FF7000")
611 ( 80. . "#FFA800")
612 (100. . "#FFE000")
613 (120. . "#E7FF00")
614 (140. . "#AFFF00")
615 (160. . "#77FF00")
616 (180. . "#3FFF00")
617 (200. . "#07FF00")
618 (220. . "#00FF31")
619 (240. . "#00FF69")
620 (260. . "#00FFA1")
621 (280. . "#00FFD9")
622 (300. . "#00EEFF")
623 (320. . "#00B6FF")
624 (340. . "#007EFF"))
625 "*Association list of age versus color, for \\[vc-annotate].
626 Ages are given in units of fractional days. Default is eighteen steps
627 using a twenty day increment."
628 :type 'alist
629 :group 'vc)
631 (defcustom vc-annotate-very-old-color "#0046FF"
632 "*Color for lines older than the current color range in \\[vc-annotate]]."
633 :type 'string
634 :group 'vc)
636 (defcustom vc-annotate-background "black"
637 "*Background color for \\[vc-annotate].
638 Default color is used if nil."
639 :type 'string
640 :group 'vc)
642 (defcustom vc-annotate-menu-elements '(2 0.5 0.1 0.01)
643 "*Menu elements for the mode-specific menu of VC-Annotate mode.
644 List of factors, used to expand/compress the time scale. See `vc-annotate'."
645 :type '(repeat number)
646 :group 'vc)
648 ;; vc-annotate functionality (CVS only).
649 (defvar vc-annotate-mode-map
650 (let ((m (make-sparse-keymap)))
651 (define-key m [menu-bar] (make-sparse-keymap "VC-Annotate"))
653 "Local keymap used for VC-Annotate mode.")
655 (define-key vc-annotate-mode-map "A" 'vc-annotate-revision-previous-to-line)
656 (define-key vc-annotate-mode-map "D" 'vc-annotate-show-diff-revision-at-line)
657 (define-key vc-annotate-mode-map "J" 'vc-annotate-revision-at-line)
658 (define-key vc-annotate-mode-map "L" 'vc-annotate-show-log-revision-at-line)
659 (define-key vc-annotate-mode-map "N" 'vc-annotate-next-version)
660 (define-key vc-annotate-mode-map "P" 'vc-annotate-prev-version)
661 (define-key vc-annotate-mode-map "W" 'vc-annotate-workfile-version)
663 (defvar vc-annotate-mode-menu nil
664 "Local keymap used for VC-Annotate mode's menu bar menu.")
666 ;; Header-insertion hair
668 (defcustom vc-static-header-alist
669 '(("\\.c$" .
670 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
671 "*Associate static header string templates with file types.
672 A \%s in the template is replaced with the first string associated with
673 the file's version control type in `vc-header-alist'."
674 :type '(repeat (cons :format "%v"
675 (regexp :tag "File Type")
676 (string :tag "Header String")))
677 :group 'vc)
679 (defcustom vc-comment-alist
680 '((nroff-mode ".\\\"" ""))
681 "*Special comment delimiters for generating VC headers.
682 Add an entry in this list if you need to override the normal `comment-start'
683 and `comment-end' variables. This will only be necessary if the mode language
684 is sensitive to blank lines."
685 :type '(repeat (list :format "%v"
686 (symbol :tag "Mode")
687 (string :tag "Comment Start")
688 (string :tag "Comment End")))
689 :group 'vc)
691 (defcustom vc-checkout-carefully (= (user-uid) 0)
692 "*Non-nil means be extra-careful in checkout.
693 Verify that the file really is not locked
694 and that its contents match what the master file says."
695 :type 'boolean
696 :group 'vc)
697 (make-obsolete-variable 'vc-checkout-carefully
698 "the corresponding checks are always done now."
699 "21.1")
702 ;; Variables the user doesn't need to know about.
703 (defvar vc-log-operation nil)
704 (defvar vc-log-after-operation-hook nil)
705 (defvar vc-annotate-buffers nil
706 "Alist of current \"Annotate\" buffers and their corresponding backends.
707 The keys are \(BUFFER . BACKEND\). See also `vc-annotate-get-backend'.")
708 ;; In a log entry buffer, this is a local variable
709 ;; that points to the buffer for which it was made
710 ;; (either a file, or a VC dired buffer).
711 (defvar vc-parent-buffer nil)
712 (put 'vc-parent-buffer 'permanent-local t)
713 (defvar vc-parent-buffer-name nil)
714 (put 'vc-parent-buffer-name 'permanent-local t)
716 (defvar vc-log-file)
717 (defvar vc-log-version)
719 (defvar vc-dired-mode nil)
720 (make-variable-buffer-local 'vc-dired-mode)
722 ;; functions that operate on RCS revision numbers. This code should
723 ;; also be moved into the backends. It stays for now, however, since
724 ;; it is used in code below.
725 (defun vc-trunk-p (rev)
726 "Return t if REV is a revision on the trunk."
727 (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev))))
729 (defun vc-branch-p (rev)
730 "Return t if REV is a branch revision."
731 (not (eq nil (string-match "\\`[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*\\'" rev))))
733 ;;;###autoload
734 (defun vc-branch-part (rev)
735 "Return the branch part of a revision number REV."
736 (let ((index (string-match "\\.[0-9]+\\'" rev)))
737 (if index
738 (substring rev 0 index))))
740 (defun vc-minor-part (rev)
741 "Return the minor version number of a revision number REV."
742 (string-match "[0-9]+\\'" rev)
743 (substring rev (match-beginning 0) (match-end 0)))
745 (defun vc-default-previous-version (backend file rev)
746 "Return the version number immediately preceding REV for FILE,
747 or nil if there is no previous version. This default
748 implementation works for <major>.<minor>-style version numbers as
749 used by RCS and CVS."
750 (let ((branch (vc-branch-part rev))
751 (minor-num (string-to-number (vc-minor-part rev))))
752 (when branch
753 (if (> minor-num 1)
754 ;; version does probably not start a branch or release
755 (concat branch "." (number-to-string (1- minor-num)))
756 (if (vc-trunk-p rev)
757 ;; we are at the beginning of the trunk --
758 ;; don't know anything to return here
760 ;; we are at the beginning of a branch --
761 ;; return version of starting point
762 (vc-branch-part branch))))))
764 (defun vc-default-next-version (backend file rev)
765 "Return the version number immediately following REV for FILE,
766 or nil if there is no next version. This default implementation
767 works for <major>.<minor>-style version numbers as used by RCS
768 and CVS."
769 (when (not (string= rev (vc-workfile-version file)))
770 (let ((branch (vc-branch-part rev))
771 (minor-num (string-to-number (vc-minor-part rev))))
772 (concat branch "." (number-to-string (1+ minor-num))))))
774 ;; File property caching
776 (defun vc-clear-context ()
777 "Clear all cached file properties."
778 (interactive)
779 (fillarray vc-file-prop-obarray 0))
781 (defmacro with-vc-properties (file form settings)
782 "Execute FORM, then maybe set per-file properties for FILE.
783 SETTINGS is an association list of property/value pairs. After
784 executing FORM, set those properties from SETTINGS that have not yet
785 been updated to their corresponding values."
786 (declare (debug t))
787 `(let ((vc-touched-properties (list t)))
788 ,form
789 (mapcar (lambda (setting)
790 (let ((property (car setting)))
791 (unless (memq property vc-touched-properties)
792 (put (intern ,file vc-file-prop-obarray)
793 property (cdr setting)))))
794 ,settings)))
796 ;; Random helper functions
798 (defsubst vc-editable-p (file)
799 "Return non-nil if FILE can be edited."
800 (or (eq (vc-checkout-model file) 'implicit)
801 (memq (vc-state file) '(edited needs-merge))))
803 ;; Two macros for elisp programming
804 ;;;###autoload
805 (defmacro with-vc-file (file comment &rest body)
806 "Check out a writable copy of FILE if necessary, then execute BODY.
807 Check in FILE with COMMENT (a string) after BODY has been executed.
808 FILE is passed through `expand-file-name'; BODY executed within
809 `save-excursion'. If FILE is not under version control, or locked by
810 somebody else, signal error."
811 (declare (debug t) (indent 2))
812 (let ((filevar (make-symbol "file")))
813 `(let ((,filevar (expand-file-name ,file)))
814 (or (vc-backend ,filevar)
815 (error "File not under version control: `%s'" file))
816 (unless (vc-editable-p ,filevar)
817 (let ((state (vc-state ,filevar)))
818 (if (stringp state)
819 (error "`%s' is locking `%s'" state ,filevar)
820 (vc-checkout ,filevar t))))
821 (save-excursion
822 ,@body)
823 (vc-checkin ,filevar nil ,comment))))
825 ;;;###autoload
826 (defmacro edit-vc-file (file comment &rest body)
827 "Edit FILE under version control, executing body.
828 Checkin with COMMENT after executing BODY.
829 This macro uses `with-vc-file', passing args to it.
830 However, before executing BODY, find FILE, and after BODY, save buffer."
831 (declare (debug t) (indent 2))
832 (let ((filevar (make-symbol "file")))
833 `(let ((,filevar (expand-file-name ,file)))
834 (with-vc-file
835 ,filevar ,comment
836 (set-buffer (find-file-noselect ,filevar))
837 ,@body
838 (save-buffer)))))
840 (defun vc-ensure-vc-buffer ()
841 "Make sure that the current buffer visits a version-controlled file."
842 (if vc-dired-mode
843 (set-buffer (find-file-noselect (dired-get-filename)))
844 (while vc-parent-buffer
845 (pop-to-buffer vc-parent-buffer))
846 (if (not buffer-file-name)
847 (error "Buffer %s is not associated with a file" (buffer-name))
848 (if (not (vc-backend buffer-file-name))
849 (error "File %s is not under version control" buffer-file-name)))))
851 (defun vc-process-filter (p s)
852 "An alternative output filter for async process P.
853 The only difference with the default filter is to insert S after markers."
854 (with-current-buffer (process-buffer p)
855 (save-excursion
856 (let ((inhibit-read-only t))
857 (goto-char (process-mark p))
858 (insert s)
859 (set-marker (process-mark p) (point))))))
861 (defun vc-setup-buffer (&optional buf)
862 "Prepare BUF for executing a VC command and make it current.
863 BUF defaults to \"*vc*\", can be a string and will be created if necessary."
864 (unless buf (setq buf "*vc*"))
865 (let ((camefrom (current-buffer))
866 (olddir default-directory))
867 (set-buffer (get-buffer-create buf))
868 (kill-all-local-variables)
869 (set (make-local-variable 'vc-parent-buffer) camefrom)
870 (set (make-local-variable 'vc-parent-buffer-name)
871 (concat " from " (buffer-name camefrom)))
872 (setq default-directory olddir)
873 (let ((inhibit-read-only t))
874 (erase-buffer))))
876 (defun vc-exec-after (code)
877 "Eval CODE when the current buffer's process is done.
878 If the current buffer has no process, just evaluate CODE.
879 Else, add CODE to the process' sentinel."
880 (let ((proc (get-buffer-process (current-buffer))))
881 (cond
882 ;; If there's no background process, just execute the code.
883 ((null proc) (eval code))
884 ;; If the background process has exited, reap it and try again
885 ((eq (process-status proc) 'exit)
886 (delete-process proc)
887 (vc-exec-after code))
888 ;; If a process is running, add CODE to the sentinel
889 ((eq (process-status proc) 'run)
890 (let ((sentinel (process-sentinel proc)))
891 (set-process-sentinel proc
892 `(lambda (p s)
893 (with-current-buffer ',(current-buffer)
894 (goto-char (process-mark p))
895 ,@(append (cdr (cdr (cdr ;strip off `with-current-buffer buf
896 ; (goto-char...)'
897 (car (cdr (cdr ;strip off `lambda (p s)'
898 sentinel))))))
899 (list `(vc-exec-after ',code))))))))
900 (t (error "Unexpected process state"))))
901 nil)
903 (defvar vc-post-command-functions nil
904 "Hook run at the end of `vc-do-command'.
905 Each function is called inside the buffer in which the command was run
906 and is passed 3 arguments: the COMMAND, the FILE and the FLAGS.")
908 (defvar w32-quote-process-args)
909 ;;;###autoload
910 (defun vc-do-command (buffer okstatus command file &rest flags)
911 "Execute a VC command, notifying user and checking for errors.
912 Output from COMMAND goes to BUFFER, or *vc* if BUFFER is nil or the
913 current buffer if BUFFER is t. If the destination buffer is not
914 already current, set it up properly and erase it. The command is
915 considered successful if its exit status does not exceed OKSTATUS (if
916 OKSTATUS is nil, that means to ignore errors, if it is 'async, that
917 means not to wait for termination of the subprocess). FILE is the
918 name of the working file (may also be nil, to execute commands that
919 don't expect a file name). If an optional list of FLAGS is present,
920 that is inserted into the command line before the filename."
921 (and file (setq file (expand-file-name file)))
922 (if vc-command-messages
923 (message "Running %s on %s..." command file))
924 (save-current-buffer
925 (unless (or (eq buffer t)
926 (and (stringp buffer)
927 (string= (buffer-name) buffer))
928 (eq buffer (current-buffer)))
929 (vc-setup-buffer buffer))
930 (let ((squeezed (remq nil flags))
931 (inhibit-read-only t)
932 (status 0))
933 (when file
934 ;; FIXME: file-relative-name can return a bogus result because
935 ;; it doesn't look at the actual file-system to see if symlinks
936 ;; come into play.
937 (setq squeezed (append squeezed (list (file-relative-name file)))))
938 (let ((exec-path (append vc-path exec-path))
939 ;; Add vc-path to PATH for the execution of this command.
940 (process-environment
941 (cons (concat "PATH=" (getenv "PATH")
942 path-separator
943 (mapconcat 'identity vc-path path-separator))
944 process-environment))
945 (w32-quote-process-args t))
946 (if (eq okstatus 'async)
947 (let ((proc (apply 'start-process command (current-buffer) command
948 squeezed)))
949 (unless (active-minibuffer-window)
950 (message "Running %s in the background..." command))
951 ;;(set-process-sentinel proc (lambda (p msg) (delete-process p)))
952 (set-process-filter proc 'vc-process-filter)
953 (vc-exec-after
954 `(unless (active-minibuffer-window)
955 (message "Running %s in the background... done" ',command))))
956 (setq status (apply 'process-file command nil t nil squeezed))
957 (when (or (not (integerp status)) (and okstatus (< okstatus status)))
958 (pop-to-buffer (current-buffer))
959 (goto-char (point-min))
960 (shrink-window-if-larger-than-buffer)
961 (error "Running %s...FAILED (%s)" command
962 (if (integerp status) (format "status %d" status) status))))
963 (if vc-command-messages
964 (message "Running %s...OK" command)))
965 (vc-exec-after
966 `(run-hook-with-args 'vc-post-command-functions ',command ',file ',flags))
967 status)))
969 (defun vc-position-context (posn)
970 "Save a bit of the text around POSN in the current buffer.
971 Used to help us find the corresponding position again later
972 if markers are destroyed or corrupted."
973 ;; A lot of this was shamelessly lifted from Sebastian Kremer's
974 ;; rcs.el mode.
975 (list posn
976 (buffer-size)
977 (buffer-substring posn
978 (min (point-max) (+ posn 100)))))
980 (defun vc-find-position-by-context (context)
981 "Return the position of CONTEXT in the current buffer.
982 If CONTEXT cannot be found, return nil."
983 (let ((context-string (nth 2 context)))
984 (if (equal "" context-string)
985 (point-max)
986 (save-excursion
987 (let ((diff (- (nth 1 context) (buffer-size))))
988 (if (< diff 0) (setq diff (- diff)))
989 (goto-char (nth 0 context))
990 (if (or (search-forward context-string nil t)
991 ;; Can't use search-backward since the match may continue
992 ;; after point.
993 (progn (goto-char (- (point) diff (length context-string)))
994 ;; goto-char doesn't signal an error at
995 ;; beginning of buffer like backward-char would
996 (search-forward context-string nil t)))
997 ;; to beginning of OSTRING
998 (- (point) (length context-string))))))))
1000 (defun vc-context-matches-p (posn context)
1001 "Return t if POSN matches CONTEXT, nil otherwise."
1002 (let* ((context-string (nth 2 context))
1003 (len (length context-string))
1004 (end (+ posn len)))
1005 (if (> end (1+ (buffer-size)))
1007 (string= context-string (buffer-substring posn end)))))
1009 (defun vc-buffer-context ()
1010 "Return a list (POINT-CONTEXT MARK-CONTEXT REPARSE).
1011 Used by `vc-restore-buffer-context' to later restore the context."
1012 (let ((point-context (vc-position-context (point)))
1013 ;; Use mark-marker to avoid confusion in transient-mark-mode.
1014 (mark-context (if (eq (marker-buffer (mark-marker)) (current-buffer))
1015 (vc-position-context (mark-marker))))
1016 ;; Make the right thing happen in transient-mark-mode.
1017 (mark-active nil)
1018 ;; The new compilation code does not use compilation-error-list any
1019 ;; more, so the code below is now ineffective and might as well
1020 ;; be disabled. -- Stef
1021 ;; ;; We may want to reparse the compilation buffer after revert
1022 ;; (reparse (and (boundp 'compilation-error-list) ;compile loaded
1023 ;; ;; Construct a list; each elt is nil or a buffer
1024 ;; ;; iff that buffer is a compilation output buffer
1025 ;; ;; that contains markers into the current buffer.
1026 ;; (save-current-buffer
1027 ;; (mapcar (lambda (buffer)
1028 ;; (set-buffer buffer)
1029 ;; (let ((errors (or
1030 ;; compilation-old-error-list
1031 ;; compilation-error-list))
1032 ;; (buffer-error-marked-p nil))
1033 ;; (while (and (consp errors)
1034 ;; (not buffer-error-marked-p))
1035 ;; (and (markerp (cdr (car errors)))
1036 ;; (eq buffer
1037 ;; (marker-buffer
1038 ;; (cdr (car errors))))
1039 ;; (setq buffer-error-marked-p t))
1040 ;; (setq errors (cdr errors)))
1041 ;; (if buffer-error-marked-p buffer)))
1042 ;; (buffer-list)))))
1043 (reparse nil))
1044 (list point-context mark-context reparse)))
1046 (defun vc-restore-buffer-context (context)
1047 "Restore point/mark, and reparse any affected compilation buffers.
1048 CONTEXT is that which `vc-buffer-context' returns."
1049 (let ((point-context (nth 0 context))
1050 (mark-context (nth 1 context))
1051 (reparse (nth 2 context)))
1052 ;; The new compilation code does not use compilation-error-list any
1053 ;; more, so the code below is now ineffective and might as well
1054 ;; be disabled. -- Stef
1055 ;; ;; Reparse affected compilation buffers.
1056 ;; (while reparse
1057 ;; (if (car reparse)
1058 ;; (with-current-buffer (car reparse)
1059 ;; (let ((compilation-last-buffer (current-buffer)) ;select buffer
1060 ;; ;; Record the position in the compilation buffer of
1061 ;; ;; the last error next-error went to.
1062 ;; (error-pos (marker-position
1063 ;; (car (car-safe compilation-error-list)))))
1064 ;; ;; Reparse the error messages as far as they were parsed before.
1065 ;; (compile-reinitialize-errors '(4) compilation-parsing-end)
1066 ;; ;; Move the pointer up to find the error we were at before
1067 ;; ;; reparsing. Now next-error should properly go to the next one.
1068 ;; (while (and compilation-error-list
1069 ;; (/= error-pos (car (car compilation-error-list))))
1070 ;; (setq compilation-error-list (cdr compilation-error-list))))))
1071 ;; (setq reparse (cdr reparse)))
1073 ;; if necessary, restore point and mark
1074 (if (not (vc-context-matches-p (point) point-context))
1075 (let ((new-point (vc-find-position-by-context point-context)))
1076 (if new-point (goto-char new-point))))
1077 (and mark-active
1078 mark-context
1079 (not (vc-context-matches-p (mark) mark-context))
1080 (let ((new-mark (vc-find-position-by-context mark-context)))
1081 (if new-mark (set-mark new-mark))))))
1083 (defun vc-revert-buffer1 (&optional arg no-confirm)
1084 "Revert buffer, keeping point and mark where user expects them.
1085 Try to be clever in the face of changes due to expanded version control
1086 key words. This is important for typeahead to work as expected.
1087 ARG and NO-CONFIRM are passed on to `revert-buffer'."
1088 (interactive "P")
1089 (widen)
1090 (let ((context (vc-buffer-context)))
1091 ;; Use save-excursion here, because it may be able to restore point
1092 ;; and mark properly even in cases where vc-restore-buffer-context
1093 ;; would fail. However, save-excursion might also get it wrong --
1094 ;; in this case, vc-restore-buffer-context gives it a second try.
1095 (save-excursion
1096 ;; t means don't call normal-mode;
1097 ;; that's to preserve various minor modes.
1098 (revert-buffer arg no-confirm t))
1099 (vc-restore-buffer-context context)))
1102 (defun vc-buffer-sync (&optional not-urgent)
1103 "Make sure the current buffer and its working file are in sync.
1104 NOT-URGENT means it is ok to continue if the user says not to save."
1105 (if (buffer-modified-p)
1106 (if (or vc-suppress-confirm
1107 (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name))))
1108 (save-buffer)
1109 (unless not-urgent
1110 (error "Aborted")))))
1112 (defun vc-default-latest-on-branch-p (backend file)
1113 "Return non-nil if FILE is the latest on its branch.
1114 This default implementation always returns non-nil, which means that
1115 editing non-current versions is not supported by default."
1118 (defun vc-recompute-state (file)
1119 "Force a recomputation of the version control state of FILE.
1120 The state is computed using the exact, and possibly expensive
1121 function `vc-BACKEND-state', not the heuristic."
1122 (vc-file-setprop file 'vc-state (vc-call state file)))
1124 (defun vc-next-action-on-file (file verbose &optional comment)
1125 "Do The Right Thing for a given FILE under version control.
1126 If COMMENT is specified, it will be used as an admin or checkin comment.
1127 If VERBOSE is non-nil, query the user rather than using default parameters."
1128 (let ((visited (get-file-buffer file))
1129 state version)
1130 (when visited
1131 (if vc-dired-mode
1132 (switch-to-buffer-other-window visited)
1133 (set-buffer visited))
1134 ;; Check relation of buffer and file, and make sure
1135 ;; user knows what he's doing. First, finding the file
1136 ;; will check whether the file on disk is newer.
1137 ;; Ignore buffer-read-only during this test, and
1138 ;; preserve find-file-literally.
1139 (let ((buffer-read-only (not (file-writable-p file))))
1140 (find-file-noselect file nil find-file-literally))
1141 (if (not (verify-visited-file-modtime (current-buffer)))
1142 (if (yes-or-no-p "Replace file on disk with buffer contents? ")
1143 (write-file buffer-file-name)
1144 (error "Aborted"))
1145 ;; Now, check if we have unsaved changes.
1146 (vc-buffer-sync t)
1147 (if (buffer-modified-p)
1148 (or (y-or-n-p "Operate on disk file, keeping modified buffer? ")
1149 (error "Aborted")))))
1151 ;; Do the right thing
1152 (if (not (vc-registered file))
1153 (vc-register verbose comment)
1154 (vc-recompute-state file)
1155 (if visited (vc-mode-line file))
1156 (setq state (vc-state file))
1157 (cond
1158 ;; up-to-date
1159 ((or (eq state 'up-to-date)
1160 (and verbose (eq state 'needs-patch)))
1161 (cond
1162 (verbose
1163 ;; go to a different version
1164 (setq version
1165 (read-string "Branch, version, or backend to move to: "))
1166 (let ((vsym (intern-soft (upcase version))))
1167 (if (member vsym vc-handled-backends)
1168 (vc-transfer-file file vsym)
1169 (vc-checkout file (eq (vc-checkout-model file) 'implicit)
1170 version))))
1171 ((not (eq (vc-checkout-model file) 'implicit))
1172 ;; check the file out
1173 (vc-checkout file t))
1175 ;; do nothing
1176 (message "%s is up-to-date" file))))
1178 ;; Abnormal: edited but read-only
1179 ((and visited (eq state 'edited)
1180 buffer-read-only (not (file-writable-p file)))
1181 ;; Make the file+buffer read-write. If the user really wanted to
1182 ;; commit, he'll get a chance to do that next time around, anyway.
1183 (message "File is edited but read-only; making it writable")
1184 (set-file-modes buffer-file-name
1185 (logior (file-modes buffer-file-name) 128))
1186 (toggle-read-only -1))
1188 ;; edited
1189 ((eq state 'edited)
1190 (cond
1191 ;; For files with locking, if the file does not contain
1192 ;; any changes, just let go of the lock, i.e. revert.
1193 ((and (not (eq (vc-checkout-model file) 'implicit))
1194 (vc-workfile-unchanged-p file)
1195 ;; If buffer is modified, that means the user just
1196 ;; said no to saving it; in that case, don't revert,
1197 ;; because the user might intend to save after
1198 ;; finishing the log entry.
1199 (not (and visited (buffer-modified-p))))
1200 ;; DO NOT revert the file without asking the user!
1201 (if (not visited) (find-file-other-window file))
1202 (if (yes-or-no-p "Revert to master version? ")
1203 (vc-revert-buffer)))
1204 (t ;; normal action
1205 (if (not verbose)
1206 (vc-checkin file nil comment)
1207 (setq version (read-string "New version or backend: "))
1208 (let ((vsym (intern (upcase version))))
1209 (if (member vsym vc-handled-backends)
1210 (vc-transfer-file file vsym)
1211 (vc-checkin file version comment)))))))
1213 ;; locked by somebody else
1214 ((stringp state)
1215 (if comment
1216 (error "Sorry, you can't steal the lock on %s this way"
1217 (file-name-nondirectory file)))
1218 (vc-steal-lock file
1219 (if verbose (read-string "Version to steal: ")
1220 (vc-workfile-version file))
1221 state))
1223 ;; needs-patch
1224 ((eq state 'needs-patch)
1225 (if (yes-or-no-p (format
1226 "%s is not up-to-date. Get latest version? "
1227 (file-name-nondirectory file)))
1228 (vc-checkout file (eq (vc-checkout-model file) 'implicit) t)
1229 (if (and (not (eq (vc-checkout-model file) 'implicit))
1230 (yes-or-no-p "Lock this version? "))
1231 (vc-checkout file t)
1232 (error "Aborted"))))
1234 ;; needs-merge
1235 ((eq state 'needs-merge)
1236 (if (yes-or-no-p (format
1237 "%s is not up-to-date. Merge in changes now? "
1238 (file-name-nondirectory file)))
1239 (vc-maybe-resolve-conflicts file (vc-call merge-news file))
1240 (error "Aborted")))
1242 ;; unlocked-changes
1243 ((eq state 'unlocked-changes)
1244 (if (not visited) (find-file-other-window file))
1245 (if (save-window-excursion
1246 (vc-version-diff file (vc-workfile-version file) nil)
1247 (goto-char (point-min))
1248 (let ((inhibit-read-only t))
1249 (insert
1250 (format "Changes to %s since last lock:\n\n" file)))
1251 (not (beep))
1252 (yes-or-no-p (concat "File has unlocked changes. "
1253 "Claim lock retaining changes? ")))
1254 (progn (vc-call steal-lock file)
1255 (clear-visited-file-modtime)
1256 ;; Must clear any headers here because they wouldn't
1257 ;; show that the file is locked now.
1258 (vc-clear-headers file)
1259 (write-file buffer-file-name)
1260 (vc-mode-line file))
1261 (if (not (yes-or-no-p
1262 "Revert to checked-in version, instead? "))
1263 (error "Checkout aborted")
1264 (vc-revert-buffer1 t t)
1265 (vc-checkout file t))))))))
1267 (defvar vc-dired-window-configuration)
1269 (defun vc-next-action-dired (file rev comment)
1270 "Call `vc-next-action-on-file' on all the marked files.
1271 Ignores FILE and REV, but passes on COMMENT."
1272 (let ((dired-buffer (current-buffer)))
1273 (dired-map-over-marks
1274 (let ((file (dired-get-filename)))
1275 (message "Processing %s..." file)
1276 (vc-next-action-on-file file nil comment)
1277 (set-buffer dired-buffer)
1278 (set-window-configuration vc-dired-window-configuration)
1279 (message "Processing %s...done" file))
1280 nil t))
1281 (dired-move-to-filename))
1283 ;; Here's the major entry point.
1285 ;;;###autoload
1286 (defun vc-next-action (verbose)
1287 "Do the next logical version control operation on the current file.
1289 If you call this from within a VC dired buffer with no files marked,
1290 it will operate on the file in the current line.
1292 If you call this from within a VC dired buffer, and one or more
1293 files are marked, it will accept a log message and then operate on
1294 each one. The log message will be used as a comment for any register
1295 or checkin operations, but ignored when doing checkouts. Attempted
1296 lock steals will raise an error.
1298 A prefix argument lets you specify the version number to use.
1300 For RCS and SCCS files:
1301 If the file is not already registered, this registers it for version
1302 control.
1303 If the file is registered and not locked by anyone, this checks out
1304 a writable and locked file ready for editing.
1305 If the file is checked out and locked by the calling user, this
1306 first checks to see if the file has changed since checkout. If not,
1307 it performs a revert.
1308 If the file has been changed, this pops up a buffer for entry
1309 of a log message; when the message has been entered, it checks in the
1310 resulting changes along with the log message as change commentary. If
1311 the variable `vc-keep-workfiles' is non-nil (which is its default), a
1312 read-only copy of the changed file is left in place afterwards.
1313 If the file is registered and locked by someone else, you are given
1314 the option to steal the lock.
1316 For CVS files:
1317 If the file is not already registered, this registers it for version
1318 control. This does a \"cvs add\", but no \"cvs commit\".
1319 If the file is added but not committed, it is committed.
1320 If your working file is changed, but the repository file is
1321 unchanged, this pops up a buffer for entry of a log message; when the
1322 message has been entered, it checks in the resulting changes along
1323 with the logmessage as change commentary. A writable file is retained.
1324 If the repository file is changed, you are asked if you want to
1325 merge in the changes into your working copy."
1327 (interactive "P")
1328 (catch 'nogo
1329 (if vc-dired-mode
1330 (let ((files (dired-get-marked-files)))
1331 (set (make-local-variable 'vc-dired-window-configuration)
1332 (current-window-configuration))
1333 (if (string= ""
1334 (mapconcat
1335 (lambda (f)
1336 (if (not (vc-up-to-date-p f)) "@" ""))
1337 files ""))
1338 (vc-next-action-dired nil nil "dummy")
1339 (vc-start-entry nil nil nil nil
1340 "Enter a change comment for the marked files."
1341 'vc-next-action-dired))
1342 (throw 'nogo nil)))
1343 (while vc-parent-buffer
1344 (pop-to-buffer vc-parent-buffer))
1345 (if buffer-file-name
1346 (vc-next-action-on-file buffer-file-name verbose)
1347 (error "Buffer %s is not associated with a file" (buffer-name)))))
1349 ;; These functions help the vc-next-action entry point
1351 ;;;###autoload
1352 (defun vc-register (&optional set-version comment)
1353 "Register the current file into a version control system.
1354 With prefix argument SET-VERSION, allow user to specify initial version
1355 level. If COMMENT is present, use that as an initial comment.
1357 The version control system to use is found by cycling through the list
1358 `vc-handled-backends'. The first backend in that list which declares
1359 itself responsible for the file (usually because other files in that
1360 directory are already registered under that backend) will be used to
1361 register the file. If no backend declares itself responsible, the
1362 first backend that could register the file is used."
1363 (interactive "P")
1364 (unless buffer-file-name (error "No visited file"))
1365 (when (vc-backend buffer-file-name)
1366 (if (vc-registered buffer-file-name)
1367 (error "This file is already registered")
1368 (unless (y-or-n-p "Previous master file has vanished. Make a new one? ")
1369 (error "Aborted"))))
1370 ;; Watch out for new buffers of size 0: the corresponding file
1371 ;; does not exist yet, even though buffer-modified-p is nil.
1372 (if (and (not (buffer-modified-p))
1373 (zerop (buffer-size))
1374 (not (file-exists-p buffer-file-name)))
1375 (set-buffer-modified-p t))
1376 (vc-buffer-sync)
1378 (vc-start-entry buffer-file-name
1379 (if set-version
1380 (read-string (format "Initial version level for %s: "
1381 (buffer-name)))
1382 (let ((backend (vc-responsible-backend buffer-file-name)))
1383 (if (vc-find-backend-function backend 'init-version)
1384 (vc-call-backend backend 'init-version)
1385 vc-default-init-version)))
1386 (or comment (not vc-initial-comment))
1388 "Enter initial comment."
1389 (lambda (file rev comment)
1390 (message "Registering %s... " file)
1391 (let ((backend (vc-responsible-backend file t)))
1392 (vc-file-clearprops file)
1393 (vc-call-backend backend 'register file rev comment)
1394 (vc-file-setprop file 'vc-backend backend)
1395 (unless vc-make-backup-files
1396 (make-local-variable 'backup-inhibited)
1397 (setq backup-inhibited t)))
1398 (message "Registering %s... done" file))))
1401 (defun vc-responsible-backend (file &optional register)
1402 "Return the name of a backend system that is responsible for FILE.
1403 The optional argument REGISTER means that a backend suitable for
1404 registration should be found.
1406 If REGISTER is nil, then if FILE is already registered, return the
1407 backend of FILE. If FILE is not registered, or a directory, then the
1408 first backend in `vc-handled-backends' that declares itself
1409 responsible for FILE is returned. If no backend declares itself
1410 responsible, return the first backend.
1412 If REGISTER is non-nil, return the first responsible backend under
1413 which FILE is not yet registered. If there is no such backend, return
1414 the first backend under which FILE is not yet registered, but could
1415 be registered."
1416 (if (not vc-handled-backends)
1417 (error "No handled backends"))
1418 (or (and (not (file-directory-p file)) (not register) (vc-backend file))
1419 (catch 'found
1420 ;; First try: find a responsible backend. If this is for registration,
1421 ;; it must be a backend under which FILE is not yet registered.
1422 (dolist (backend vc-handled-backends)
1423 (and (or (not register)
1424 (not (vc-call-backend backend 'registered file)))
1425 (vc-call-backend backend 'responsible-p file)
1426 (throw 'found backend)))
1427 ;; no responsible backend
1428 (if (not register)
1429 ;; if this is not for registration, the first backend must do
1430 (car vc-handled-backends)
1431 ;; for registration, we need to find a new backend that
1432 ;; could register FILE
1433 (dolist (backend vc-handled-backends)
1434 (and (not (vc-call-backend backend 'registered file))
1435 (vc-call-backend backend 'could-register file)
1436 (throw 'found backend)))
1437 (error "No backend that could register")))))
1439 (defun vc-default-responsible-p (backend file)
1440 "Indicate whether BACKEND is reponsible for FILE.
1441 The default is to return nil always."
1442 nil)
1444 (defun vc-default-could-register (backend file)
1445 "Return non-nil if BACKEND could be used to register FILE.
1446 The default implementation returns t for all files."
1449 (defun vc-resynch-window (file &optional keep noquery)
1450 "If FILE is in the current buffer, either revert or unvisit it.
1451 The choice between revert (to see expanded keywords) and unvisit depends on
1452 `vc-keep-workfiles'. NOQUERY if non-nil inhibits confirmation for
1453 reverting. NOQUERY should be t *only* if it is known the only
1454 difference between the buffer and the file is due to version control
1455 rather than user editing!"
1456 (and (string= buffer-file-name file)
1457 (if keep
1458 (progn
1459 (vc-revert-buffer1 t noquery)
1460 ;; TODO: Adjusting view mode might no longer be necessary
1461 ;; after RMS change to files.el of 1999-08-08. Investigate
1462 ;; this when we install the new VC.
1463 (and view-read-only
1464 (if (file-writable-p file)
1465 (and view-mode
1466 (let ((view-old-buffer-read-only nil))
1467 (view-mode-exit)))
1468 (and (not view-mode)
1469 (not (eq (get major-mode 'mode-class) 'special))
1470 (view-mode-enter))))
1471 (vc-mode-line buffer-file-name))
1472 (kill-buffer (current-buffer)))))
1474 (defun vc-resynch-buffer (file &optional keep noquery)
1475 "If FILE is currently visited, resynch its buffer."
1476 (if (string= buffer-file-name file)
1477 (vc-resynch-window file keep noquery)
1478 (let ((buffer (get-file-buffer file)))
1479 (if buffer
1480 (with-current-buffer buffer
1481 (vc-resynch-window file keep noquery)))))
1482 (vc-dired-resynch-file file))
1484 (defun vc-start-entry (file rev comment initial-contents msg action &optional after-hook)
1485 "Accept a comment for an operation on FILE revision REV.
1486 If COMMENT is nil, pop up a VC-log buffer, emit MSG, and set the
1487 action on close to ACTION. If COMMENT is a string and
1488 INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial
1489 contents of the log entry buffer. If COMMENT is a string and
1490 INITIAL-CONTENTS is nil, do action immediately as if the user had
1491 entered COMMENT. If COMMENT is t, also do action immediately with an
1492 empty comment. Remember the file's buffer in `vc-parent-buffer'
1493 \(current one if no file). AFTER-HOOK specifies the local value
1494 for vc-log-operation-hook."
1495 (let ((parent (or (and file (get-file-buffer file)) (current-buffer))))
1496 (if vc-before-checkin-hook
1497 (if file
1498 (with-current-buffer parent
1499 (run-hooks 'vc-before-checkin-hook))
1500 (run-hooks 'vc-before-checkin-hook)))
1501 (if (and comment (not initial-contents))
1502 (set-buffer (get-buffer-create "*VC-log*"))
1503 (pop-to-buffer (get-buffer-create "*VC-log*")))
1504 (set (make-local-variable 'vc-parent-buffer) parent)
1505 (set (make-local-variable 'vc-parent-buffer-name)
1506 (concat " from " (buffer-name vc-parent-buffer)))
1507 (if file (vc-mode-line file))
1508 (vc-log-edit file)
1509 (make-local-variable 'vc-log-after-operation-hook)
1510 (if after-hook
1511 (setq vc-log-after-operation-hook after-hook))
1512 (setq vc-log-operation action)
1513 (setq vc-log-version rev)
1514 (when comment
1515 (erase-buffer)
1516 (when (stringp comment) (insert comment)))
1517 (if (or (not comment) initial-contents)
1518 (message "%s Type C-c C-c when done" msg)
1519 (vc-finish-logentry (eq comment t)))))
1521 (defun vc-checkout (file &optional writable rev)
1522 "Retrieve a copy of the revision REV of FILE.
1523 If WRITABLE is non-nil, make sure the retrieved file is writable.
1524 REV defaults to the latest revision.
1526 After check-out, runs the normal hook `vc-checkout-hook'."
1527 (and writable
1528 (not rev)
1529 (vc-call make-version-backups-p file)
1530 (vc-up-to-date-p file)
1531 (vc-make-version-backup file))
1532 (with-vc-properties
1533 file
1534 (condition-case err
1535 (vc-call checkout file writable rev)
1536 (file-error
1537 ;; Maybe the backend is not installed ;-(
1538 (when writable
1539 (let ((buf (get-file-buffer file)))
1540 (when buf (with-current-buffer buf (toggle-read-only -1)))))
1541 (signal (car err) (cdr err))))
1542 `((vc-state . ,(if (or (eq (vc-checkout-model file) 'implicit)
1543 (not writable))
1544 (if (vc-call latest-on-branch-p file)
1545 'up-to-date
1546 'needs-patch)
1547 'edited))
1548 (vc-checkout-time . ,(nth 5 (file-attributes file)))))
1549 (vc-resynch-buffer file t t)
1550 (run-hooks 'vc-checkout-hook))
1552 (defun vc-steal-lock (file rev owner)
1553 "Steal the lock on FILE."
1554 (let (file-description)
1555 (if rev
1556 (setq file-description (format "%s:%s" file rev))
1557 (setq file-description file))
1558 (if (not (yes-or-no-p (format "Steal the lock on %s from %s? "
1559 file-description owner)))
1560 (error "Steal canceled"))
1561 (message "Stealing lock on %s..." file)
1562 (with-vc-properties
1563 file
1564 (vc-call steal-lock file rev)
1565 `((vc-state . edited)))
1566 (vc-resynch-buffer file t t)
1567 (message "Stealing lock on %s...done" file)
1568 ;; Write mail after actually stealing, because if the stealing
1569 ;; goes wrong, we don't want to send any mail.
1570 (compose-mail owner (format "Stolen lock on %s" file-description))
1571 (setq default-directory (expand-file-name "~/"))
1572 (goto-char (point-max))
1573 (insert
1574 (format "I stole the lock on %s, " file-description)
1575 (current-time-string)
1576 ".\n")
1577 (message "Please explain why you stole the lock. Type C-c C-c when done.")))
1579 (defun vc-checkin (file &optional rev comment initial-contents)
1580 "Check in FILE.
1581 The optional argument REV may be a string specifying the new version
1582 level (if nil increment the current level). COMMENT is a comment
1583 string; if omitted, a buffer is popped up to accept a comment. If
1584 INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial contents
1585 of the log entry buffer.
1587 If `vc-keep-workfiles' is nil, FILE is deleted afterwards, provided
1588 that the version control system supports this mode of operation.
1590 Runs the normal hook `vc-checkin-hook'."
1591 (vc-start-entry
1592 file rev comment initial-contents
1593 "Enter a change comment."
1594 (lambda (file rev comment)
1595 (message "Checking in %s..." file)
1596 ;; "This log message intentionally left almost blank".
1597 ;; RCS 5.7 gripes about white-space-only comments too.
1598 (or (and comment (string-match "[^\t\n ]" comment))
1599 (setq comment "*** empty log message ***"))
1600 (with-vc-properties
1601 file
1602 ;; Change buffers to get local value of vc-checkin-switches.
1603 (with-current-buffer (or (get-file-buffer file) (current-buffer))
1604 (progn
1605 (vc-call checkin file rev comment)
1606 (vc-delete-automatic-version-backups file)))
1607 `((vc-state . up-to-date)
1608 (vc-checkout-time . ,(nth 5 (file-attributes file)))
1609 (vc-workfile-version . nil)))
1610 (message "Checking in %s...done" file))
1611 'vc-checkin-hook))
1613 (defun vc-finish-logentry (&optional nocomment)
1614 "Complete the operation implied by the current log entry.
1615 Use the contents of the current buffer as a check-in or registration
1616 comment. If the optional arg NOCOMMENT is non-nil, then don't check
1617 the buffer contents as a comment."
1618 (interactive)
1619 ;; Check and record the comment, if any.
1620 (unless nocomment
1621 ;; Comment too long?
1622 (vc-call-backend (or (and vc-log-file (vc-backend vc-log-file))
1623 (vc-responsible-backend default-directory))
1624 'logentry-check)
1625 (run-hooks 'vc-logentry-check-hook))
1626 ;; Sync parent buffer in case the user modified it while editing the comment.
1627 ;; But not if it is a vc-dired buffer.
1628 (with-current-buffer vc-parent-buffer
1629 (or vc-dired-mode (vc-buffer-sync)))
1630 (if (not vc-log-operation) (error "No log operation is pending"))
1631 ;; save the parameters held in buffer-local variables
1632 (let ((log-operation vc-log-operation)
1633 (log-file vc-log-file)
1634 (log-version vc-log-version)
1635 (log-entry (buffer-string))
1636 (after-hook vc-log-after-operation-hook)
1637 (tmp-vc-parent-buffer vc-parent-buffer))
1638 (pop-to-buffer vc-parent-buffer)
1639 ;; OK, do it to it
1640 (save-excursion
1641 (funcall log-operation
1642 log-file
1643 log-version
1644 log-entry))
1645 ;; Remove checkin window (after the checkin so that if that fails
1646 ;; we don't zap the *VC-log* buffer and the typing therein).
1647 (let ((logbuf (get-buffer "*VC-log*")))
1648 (cond ((and logbuf vc-delete-logbuf-window)
1649 (delete-windows-on logbuf (selected-frame))
1650 ;; Kill buffer and delete any other dedicated windows/frames.
1651 (kill-buffer logbuf))
1652 (logbuf (pop-to-buffer "*VC-log*")
1653 (bury-buffer)
1654 (pop-to-buffer tmp-vc-parent-buffer))))
1655 ;; Now make sure we see the expanded headers
1656 (if log-file
1657 (vc-resynch-buffer log-file vc-keep-workfiles t))
1658 (if vc-dired-mode
1659 (dired-move-to-filename))
1660 (run-hooks after-hook 'vc-finish-logentry-hook)))
1662 ;; Code for access to the comment ring
1664 ;; Additional entry points for examining version histories
1666 ;;;###autoload
1667 (defun vc-diff (historic &optional not-urgent)
1668 "Display diffs between file versions.
1669 Normally this compares the current file and buffer with the most
1670 recent checked in version of that file. This uses no arguments. With
1671 a prefix argument HISTORIC, it reads the file name to use and two
1672 version designators specifying which versions to compare. The
1673 optional argument NOT-URGENT non-nil means it is ok to say no to
1674 saving the buffer."
1675 (interactive (list current-prefix-arg t))
1676 (if historic
1677 (call-interactively 'vc-version-diff)
1678 (vc-ensure-vc-buffer)
1679 (let ((file buffer-file-name))
1680 (vc-buffer-sync not-urgent)
1681 (if (vc-workfile-unchanged-p buffer-file-name)
1682 (message "No changes to %s since latest version" file)
1683 (vc-version-diff file nil nil)))))
1685 (defun vc-version-diff (file rev1 rev2)
1686 "List the differences between FILE's versions REV1 and REV2.
1687 If REV1 is empty or nil it means to use the current workfile version;
1688 REV2 empty or nil means the current file contents. FILE may also be
1689 a directory, in that case, generate diffs between the correponding
1690 versions of all registered files in or below it."
1691 (interactive
1692 (let ((file (expand-file-name
1693 (read-file-name (if buffer-file-name
1694 "File or dir to diff: (default visited file) "
1695 "File or dir to diff: ")
1696 default-directory buffer-file-name t)))
1697 (rev1-default nil) (rev2-default nil))
1698 ;; compute default versions based on the file state
1699 (cond
1700 ;; if it's a directory, don't supply any version default
1701 ((file-directory-p file)
1702 nil)
1703 ;; if the file is not up-to-date, use current version as older version
1704 ((not (vc-up-to-date-p file))
1705 (setq rev1-default (vc-workfile-version file)))
1706 ;; if the file is not locked, use last and previous version as default
1708 (setq rev1-default (vc-call previous-version file
1709 (vc-workfile-version file)))
1710 (if (string= rev1-default "") (setq rev1-default nil))
1711 (setq rev2-default (vc-workfile-version file))))
1712 ;; construct argument list
1713 (list file
1714 (read-string (if rev1-default
1715 (concat "Older version: (default "
1716 rev1-default ") ")
1717 "Older version: ")
1718 nil nil rev1-default)
1719 (read-string (if rev2-default
1720 (concat "Newer version: (default "
1721 rev2-default ") ")
1722 "Newer version (default: current source): ")
1723 nil nil rev2-default))))
1724 (if (file-directory-p file)
1725 ;; recursive directory diff
1726 (progn
1727 (vc-setup-buffer "*vc-diff*")
1728 (if (string-equal rev1 "") (setq rev1 nil))
1729 (if (string-equal rev2 "") (setq rev2 nil))
1730 (let ((inhibit-read-only t))
1731 (insert "Diffs between "
1732 (or rev1 "last version checked in")
1733 " and "
1734 (or rev2 "current workfile(s)")
1735 ":\n\n"))
1736 (let ((dir (file-name-as-directory file)))
1737 (vc-call-backend (vc-responsible-backend dir)
1738 'diff-tree dir rev1 rev2))
1739 (vc-exec-after `(let ((inhibit-read-only t))
1740 (insert "\nEnd of diffs.\n"))))
1741 ;; Single file diff. It is important that the vc-controlled buffer
1742 ;; is still current at this time, because any local settings in that
1743 ;; buffer should affect the diff command.
1744 (vc-diff-internal file rev1 rev2))
1745 (set-buffer "*vc-diff*")
1746 (if (and (zerop (buffer-size))
1747 (not (get-buffer-process (current-buffer))))
1748 (progn
1749 (if rev1
1750 (if rev2
1751 (message "No changes to %s between %s and %s" file rev1 rev2)
1752 (message "No changes to %s since %s" file rev1))
1753 (message "No changes to %s since latest version" file))
1754 nil)
1755 (pop-to-buffer (current-buffer))
1756 ;; Gnus-5.8.5 sets up an autoload for diff-mode, even if it's
1757 ;; not available. Work around that.
1758 (if (require 'diff-mode nil t) (diff-mode))
1759 (vc-exec-after '(let ((inhibit-read-only t))
1760 (if (eq (buffer-size) 0)
1761 (insert "No differences found.\n"))
1762 (goto-char (point-min))
1763 (shrink-window-if-larger-than-buffer)))
1766 (defun vc-diff-label (file file-rev rev)
1767 (concat (file-relative-name file)
1768 (format-time-string "\t%d %b %Y %T %z\t"
1769 (nth 5 (file-attributes file-rev)))
1770 rev))
1772 (defun vc-diff-internal (file rev1 rev2)
1773 "Run diff to compare FILE's revisions REV1 and REV2.
1774 Diff output goes to the *vc-diff* buffer. The exit status of the diff
1775 command is returned.
1777 This function takes care to set up a proper coding system for diff output.
1778 If both revisions are available as local files, then it also does not
1779 actually call the backend, but performs a local diff."
1780 (if (or (not rev1) (string-equal rev1 ""))
1781 (setq rev1 (vc-workfile-version file)))
1782 (if (string-equal rev2 "")
1783 (setq rev2 nil))
1784 (let ((file-rev1 (vc-version-backup-file file rev1))
1785 (file-rev2 (if (not rev2)
1786 file
1787 (vc-version-backup-file file rev2)))
1788 (coding-system-for-read (vc-coding-system-for-diff file)))
1789 (if (and file-rev1 file-rev2)
1790 (apply 'vc-do-command "*vc-diff*" 1 "diff" nil
1791 (append (vc-switches nil 'diff)
1792 ;; Provide explicit labels like RCS or CVS would do
1793 ;; so diff-mode refers to `file' rather than to
1794 ;; `file-rev1' when trying to find/apply/undo hunks.
1795 (list "-L" (vc-diff-label file file-rev1 rev1)
1796 "-L" (vc-diff-label file file-rev2 rev2)
1797 (file-relative-name file-rev1)
1798 (file-relative-name file-rev2))))
1799 (vc-call diff file rev1 rev2))))
1802 (defun vc-switches (backend op)
1803 (let ((switches
1804 (or (if backend
1805 (let ((sym (vc-make-backend-sym
1806 backend (intern (concat (symbol-name op)
1807 "-switches")))))
1808 (if (boundp sym) (symbol-value sym))))
1809 (let ((sym (intern (format "vc-%s-switches" (symbol-name op)))))
1810 (if (boundp sym) (symbol-value sym)))
1811 (cond
1812 ((eq op 'diff) diff-switches)))))
1813 (if (stringp switches) (list switches)
1814 ;; If not a list, return nil.
1815 ;; This is so we can set vc-diff-switches to t to override
1816 ;; any switches in diff-switches.
1817 (if (listp switches) switches))))
1819 ;; Old def for compatibility with Emacs-21.[123].
1820 (defmacro vc-diff-switches-list (backend) `(vc-switches ',backend 'diff))
1821 (make-obsolete 'vc-diff-switches-list 'vc-switches "21.4")
1823 (defun vc-default-diff-tree (backend dir rev1 rev2)
1824 "List differences for all registered files at and below DIR.
1825 The meaning of REV1 and REV2 is the same as for `vc-version-diff'."
1826 ;; This implementation does an explicit tree walk, and calls
1827 ;; vc-BACKEND-diff directly for each file. An optimization
1828 ;; would be to use `vc-diff-internal', so that diffs can be local,
1829 ;; and to call it only for files that are actually changed.
1830 ;; However, this is expensive for some backends, and so it is left
1831 ;; to backend-specific implementations.
1832 (setq default-directory dir)
1833 (vc-file-tree-walk
1834 default-directory
1835 (lambda (f)
1836 (vc-exec-after
1837 `(let ((coding-system-for-read (vc-coding-system-for-diff ',f)))
1838 (message "Looking at %s" ',f)
1839 (vc-call-backend ',(vc-backend f)
1840 'diff ',f ',rev1 ',rev2))))))
1842 (defun vc-coding-system-for-diff (file)
1843 "Return the coding system for reading diff output for FILE."
1844 (or coding-system-for-read
1845 ;; if we already have this file open,
1846 ;; use the buffer's coding system
1847 (let ((buf (find-buffer-visiting file)))
1848 (if buf (with-current-buffer buf
1849 buffer-file-coding-system)))
1850 ;; otherwise, try to find one based on the file name
1851 (car (find-operation-coding-system 'insert-file-contents file))
1852 ;; and a final fallback
1853 'undecided))
1855 ;;;###autoload
1856 (defun vc-version-other-window (rev)
1857 "Visit version REV of the current file in another window.
1858 If the current file is named `F', the version is named `F.~REV~'.
1859 If `F.~REV~' already exists, use it instead of checking it out again."
1860 (interactive "sVersion to visit (default is workfile version): ")
1861 (vc-ensure-vc-buffer)
1862 (let* ((file buffer-file-name)
1863 (version (if (string-equal rev "")
1864 (vc-workfile-version file)
1865 rev)))
1866 (switch-to-buffer-other-window (vc-find-version file version))))
1868 (defun vc-find-version (file version)
1869 "Read VERSION of FILE into a buffer and return the buffer."
1870 (let ((automatic-backup (vc-version-backup-file-name file version))
1871 (filebuf (or (get-file-buffer file) (current-buffer)))
1872 (filename (vc-version-backup-file-name file version 'manual)))
1873 (unless (file-exists-p filename)
1874 (if (file-exists-p automatic-backup)
1875 (rename-file automatic-backup filename nil)
1876 (message "Checking out %s..." filename)
1877 (with-current-buffer filebuf
1878 (let ((failed t))
1879 (unwind-protect
1880 (let ((coding-system-for-read 'no-conversion)
1881 (coding-system-for-write 'no-conversion))
1882 (with-temp-file filename
1883 (let ((outbuf (current-buffer)))
1884 ;; Change buffer to get local value of
1885 ;; vc-checkout-switches.
1886 (with-current-buffer filebuf
1887 (vc-call find-version file version outbuf))))
1888 (setq failed nil))
1889 (if (and failed (file-exists-p filename))
1890 (delete-file filename))))
1891 (vc-mode-line file))
1892 (message "Checking out %s...done" filename)))
1893 (find-file-noselect filename)))
1895 (defun vc-default-find-version (backend file rev buffer)
1896 "Provide the new `find-version' op based on the old `checkout' op.
1897 This is only for compatibility with old backends. They should be updated
1898 to provide the `find-version' operation instead."
1899 (let ((tmpfile (make-temp-file (expand-file-name file))))
1900 (unwind-protect
1901 (progn
1902 (vc-call-backend backend 'checkout file nil rev tmpfile)
1903 (with-current-buffer buffer
1904 (insert-file-contents-literally tmpfile)))
1905 (delete-file tmpfile))))
1907 ;; Header-insertion code
1909 ;;;###autoload
1910 (defun vc-insert-headers ()
1911 "Insert headers into a file for use with a version control system.
1912 Headers desired are inserted at point, and are pulled from
1913 the variable `vc-BACKEND-header'."
1914 (interactive)
1915 (vc-ensure-vc-buffer)
1916 (save-excursion
1917 (save-restriction
1918 (widen)
1919 (if (or (not (vc-check-headers))
1920 (y-or-n-p "Version headers already exist. Insert another set? "))
1921 (progn
1922 (let* ((delims (cdr (assq major-mode vc-comment-alist)))
1923 (comment-start-vc (or (car delims) comment-start "#"))
1924 (comment-end-vc (or (car (cdr delims)) comment-end ""))
1925 (hdsym (vc-make-backend-sym (vc-backend buffer-file-name)
1926 'header))
1927 (hdstrings (and (boundp hdsym) (symbol-value hdsym))))
1928 (mapcar (lambda (s)
1929 (insert comment-start-vc "\t" s "\t"
1930 comment-end-vc "\n"))
1931 hdstrings)
1932 (if vc-static-header-alist
1933 (mapcar (lambda (f)
1934 (if (string-match (car f) buffer-file-name)
1935 (insert (format (cdr f) (car hdstrings)))))
1936 vc-static-header-alist))
1938 )))))
1940 (defun vc-clear-headers (&optional file)
1941 "Clear all version headers in the current buffer (or FILE).
1942 The headers are reset to their non-expanded form."
1943 (let* ((filename (or file buffer-file-name))
1944 (visited (find-buffer-visiting filename))
1945 (backend (vc-backend filename)))
1946 (when (vc-find-backend-function backend 'clear-headers)
1947 (if visited
1948 (let ((context (vc-buffer-context)))
1949 ;; save-excursion may be able to relocate point and mark
1950 ;; properly. If it fails, vc-restore-buffer-context
1951 ;; will give it a second try.
1952 (save-excursion
1953 (vc-call-backend backend 'clear-headers))
1954 (vc-restore-buffer-context context))
1955 (set-buffer (find-file-noselect filename))
1956 (vc-call-backend backend 'clear-headers)
1957 (kill-buffer filename)))))
1959 ;;;###autoload
1960 (defun vc-merge ()
1961 "Merge changes between two versions into the current buffer's file.
1962 This asks for two versions to merge from in the minibuffer. If the
1963 first version is a branch number, then merge all changes from that
1964 branch. If the first version is empty, merge news, i.e. recent changes
1965 from the current branch.
1967 See Info node `Merging'."
1968 (interactive)
1969 (vc-ensure-vc-buffer)
1970 (vc-buffer-sync)
1971 (let* ((file buffer-file-name)
1972 (backend (vc-backend file))
1973 (state (vc-state file))
1974 first-version second-version status)
1975 (cond
1976 ((stringp state)
1977 (error "File is locked by %s" state))
1978 ((not (vc-editable-p file))
1979 (if (y-or-n-p
1980 "File must be checked out for merging. Check out now? ")
1981 (vc-checkout file t)
1982 (error "Merge aborted"))))
1983 (setq first-version
1984 (read-string (concat "Branch or version to merge from "
1985 "(default: news on current branch): ")))
1986 (if (string= first-version "")
1987 (if (not (vc-find-backend-function backend 'merge-news))
1988 (error "Sorry, merging news is not implemented for %s" backend)
1989 (setq status (vc-call merge-news file)))
1990 (if (not (vc-find-backend-function backend 'merge))
1991 (error "Sorry, merging is not implemented for %s" backend)
1992 (if (not (vc-branch-p first-version))
1993 (setq second-version
1994 (read-string "Second version: "
1995 (concat (vc-branch-part first-version) ".")))
1996 ;; We want to merge an entire branch. Set versions
1997 ;; accordingly, so that vc-BACKEND-merge understands us.
1998 (setq second-version first-version)
1999 ;; first-version must be the starting point of the branch
2000 (setq first-version (vc-branch-part first-version)))
2001 (setq status (vc-call merge file first-version second-version))))
2002 (vc-maybe-resolve-conflicts file status "WORKFILE" "MERGE SOURCE")))
2004 (defun vc-maybe-resolve-conflicts (file status &optional name-A name-B)
2005 (vc-resynch-buffer file t (not (buffer-modified-p)))
2006 (if (zerop status) (message "Merge successful")
2007 (smerge-mode 1)
2008 (message "File contains conflicts.")))
2010 ;;;###autoload
2011 (defalias 'vc-resolve-conflicts 'smerge-ediff)
2013 ;; The VC directory major mode. Coopt Dired for this.
2014 ;; All VC commands get mapped into logical equivalents.
2016 (defvar vc-dired-switches)
2017 (defvar vc-dired-terse-mode)
2019 (defvar vc-dired-mode-map
2020 (let ((map (make-sparse-keymap))
2021 (vmap (make-sparse-keymap)))
2022 (define-key map "\C-xv" vmap)
2023 (define-key map "v" vmap)
2024 (set-keymap-parent vmap vc-prefix-map)
2025 (define-key vmap "t" 'vc-dired-toggle-terse-mode)
2026 map))
2028 (define-derived-mode vc-dired-mode dired-mode "Dired under VC"
2029 "The major mode used in VC directory buffers.
2031 It works like Dired, but lists only files under version control, with
2032 the current VC state of each file being indicated in the place of the
2033 file's link count, owner, group and size. Subdirectories are also
2034 listed, and you may insert them into the buffer as desired, like in
2035 Dired.
2037 All Dired commands operate normally, with the exception of `v', which
2038 is redefined as the version control prefix, so that you can type
2039 `vl', `v=' etc. to invoke `vc-print-log', `vc-diff', and the like on
2040 the file named in the current Dired buffer line. `vv' invokes
2041 `vc-next-action' on this file, or on all files currently marked.
2042 There is a special command, `*l', to mark all files currently locked."
2043 ;; define-derived-mode does it for us in Emacs-21, but not in Emacs-20.
2044 ;; We do it here because dired might not be loaded yet
2045 ;; when vc-dired-mode-map is initialized.
2046 (set-keymap-parent vc-dired-mode-map dired-mode-map)
2047 (add-hook 'dired-after-readin-hook 'vc-dired-hook nil t)
2048 ;; The following is slightly modified from dired.el,
2049 ;; because file lines look a bit different in vc-dired-mode
2050 ;; (the column before the date does not end in a digit).
2051 (set (make-local-variable 'dired-move-to-filename-regexp)
2052 (let* ((l "\\([A-Za-z]\\|[^\0-\177]\\)")
2053 ;; In some locales, month abbreviations are as short as 2 letters,
2054 ;; and they can be followed by ".".
2055 (month (concat l l "+\\.?"))
2056 (s " ")
2057 (yyyy "[0-9][0-9][0-9][0-9]")
2058 (dd "[ 0-3][0-9]")
2059 (HH:MM "[ 0-2][0-9]:[0-5][0-9]")
2060 (seconds "[0-6][0-9]\\([.,][0-9]+\\)?")
2061 (zone "[-+][0-2][0-9][0-5][0-9]")
2062 (iso-mm-dd "[01][0-9]-[0-3][0-9]")
2063 (iso-time (concat HH:MM "\\(:" seconds "\\( ?" zone "\\)?\\)?"))
2064 (iso (concat "\\(\\(" yyyy "-\\)?" iso-mm-dd "[ T]" iso-time
2065 "\\|" yyyy "-" iso-mm-dd "\\)"))
2066 (western (concat "\\(" month s "+" dd "\\|" dd "\\.?" s month "\\)"
2067 s "+"
2068 "\\(" HH:MM "\\|" yyyy "\\)"))
2069 (western-comma (concat month s "+" dd "," s "+" yyyy))
2070 ;; Japanese MS-Windows ls-lisp has one-digit months, and
2071 ;; omits the Kanji characters after month and day-of-month.
2072 (mm "[ 0-1]?[0-9]")
2073 (japanese
2074 (concat mm l "?" s dd l "?" s "+"
2075 "\\(" HH:MM "\\|" yyyy l "?" "\\)")))
2076 ;; the .* below ensures that we find the last match on a line
2077 (concat ".*" s
2078 "\\(" western "\\|" western-comma "\\|" japanese "\\|" iso "\\)"
2079 s "+")))
2080 (and (boundp 'vc-dired-switches)
2081 vc-dired-switches
2082 (set (make-local-variable 'dired-actual-switches)
2083 vc-dired-switches))
2084 (set (make-local-variable 'vc-dired-terse-mode) vc-dired-terse-display)
2085 (setq vc-dired-mode t))
2087 (defun vc-dired-toggle-terse-mode ()
2088 "Toggle terse display in VC Dired."
2089 (interactive)
2090 (if (not vc-dired-mode)
2092 (setq vc-dired-terse-mode (not vc-dired-terse-mode))
2093 (if vc-dired-terse-mode
2094 (vc-dired-hook)
2095 (revert-buffer))))
2097 (defun vc-dired-mark-locked ()
2098 "Mark all files currently locked."
2099 (interactive)
2100 (dired-mark-if (let ((f (dired-get-filename nil t)))
2101 (and f
2102 (not (file-directory-p f))
2103 (not (vc-up-to-date-p f))))
2104 "locked file"))
2106 (define-key vc-dired-mode-map "*l" 'vc-dired-mark-locked)
2108 (defun vc-default-dired-state-info (backend file)
2109 (let ((state (vc-state file)))
2110 (cond
2111 ((stringp state) (concat "(" state ")"))
2112 ((eq state 'edited) (concat "(" (vc-user-login-name) ")"))
2113 ((eq state 'needs-merge) "(merge)")
2114 ((eq state 'needs-patch) "(patch)")
2115 ((eq state 'unlocked-changes) "(stale)"))))
2117 (defun vc-dired-reformat-line (vc-info)
2118 "Reformat a directory-listing line.
2119 Replace various columns with version control information, VC-INFO.
2120 This code, like dired, assumes UNIX -l format."
2121 (beginning-of-line)
2122 (when (re-search-forward
2123 ;; Match link count, owner, group, size. Group may be missing,
2124 ;; and only the size is present in OS/2 -l format.
2125 "^..[drwxlts-]+ \\( *[0-9]+\\( [^ ]+ +\\([^ ]+ +\\)?[0-9]+\\)?\\) "
2126 (line-end-position) t)
2127 (replace-match (substring (concat vc-info " ") 0 10)
2128 t t nil 1)))
2130 (defun vc-dired-hook ()
2131 "Reformat the listing according to version control.
2132 Called by dired after any portion of a vc-dired buffer has been read in."
2133 (message "Getting version information... ")
2134 (let (subdir filename (buffer-read-only nil))
2135 (goto-char (point-min))
2136 (while (not (eobp))
2137 (cond
2138 ;; subdir header line
2139 ((setq subdir (dired-get-subdir))
2140 ;; if the backend supports it, get the state
2141 ;; of all files in this directory at once
2142 (let ((backend (vc-responsible-backend subdir)))
2143 (if (vc-find-backend-function backend 'dir-state)
2144 (vc-call-backend backend 'dir-state subdir)))
2145 (forward-line 1)
2146 ;; erase (but don't remove) the "total" line
2147 (delete-region (point) (line-end-position))
2148 (beginning-of-line)
2149 (forward-line 1))
2150 ;; file line
2151 ((setq filename (dired-get-filename nil t))
2152 (cond
2153 ;; subdir
2154 ((file-directory-p filename)
2155 (cond
2156 ((member (file-name-nondirectory filename)
2157 vc-directory-exclusion-list)
2158 (let ((pos (point)))
2159 (dired-kill-tree filename)
2160 (goto-char pos)
2161 (dired-kill-line)))
2162 (vc-dired-terse-mode
2163 ;; Don't show directories in terse mode. Don't use
2164 ;; dired-kill-line to remove it, because in recursive listings,
2165 ;; that would remove the directory contents as well.
2166 (delete-region (line-beginning-position)
2167 (progn (forward-line 1) (point))))
2168 ((string-match "\\`\\.\\.?\\'" (file-name-nondirectory filename))
2169 (dired-kill-line))
2171 (vc-dired-reformat-line nil)
2172 (forward-line 1))))
2173 ;; ordinary file
2174 ((and (vc-backend filename)
2175 (not (and vc-dired-terse-mode
2176 (vc-up-to-date-p filename))))
2177 (vc-dired-reformat-line (vc-call dired-state-info filename))
2178 (forward-line 1))
2180 (dired-kill-line))))
2181 ;; any other line
2182 (t (forward-line 1))))
2183 (vc-dired-purge))
2184 (message "Getting version information... done")
2185 (save-restriction
2186 (widen)
2187 (cond ((eq (count-lines (point-min) (point-max)) 1)
2188 (goto-char (point-min))
2189 (message "No files locked under %s" default-directory)))))
2191 (defun vc-dired-purge ()
2192 "Remove empty subdirs."
2193 (goto-char (point-min))
2194 (while (dired-get-subdir)
2195 (forward-line 2)
2196 (if (dired-get-filename nil t)
2197 (if (not (dired-next-subdir 1 t))
2198 (goto-char (point-max)))
2199 (forward-line -2)
2200 (if (not (string= (dired-current-directory) default-directory))
2201 (dired-do-kill-lines t "")
2202 ;; We cannot remove the top level directory.
2203 ;; Just make it look a little nicer.
2204 (forward-line 1)
2205 (or (eobp) (kill-line))
2206 (if (not (dired-next-subdir 1 t))
2207 (goto-char (point-max))))))
2208 (goto-char (point-min)))
2210 (defun vc-dired-buffers-for-dir (dir)
2211 "Return a list of all vc-dired buffers that currently display DIR."
2212 (let (result)
2213 ;; Check whether dired is loaded.
2214 (when (fboundp 'dired-buffers-for-dir)
2215 (mapcar (lambda (buffer)
2216 (with-current-buffer buffer
2217 (if vc-dired-mode
2218 (setq result (append result (list buffer))))))
2219 (dired-buffers-for-dir dir)))
2220 result))
2222 (defun vc-dired-resynch-file (file)
2223 "Update the entries for FILE in any VC Dired buffers that list it."
2224 (let ((buffers (vc-dired-buffers-for-dir (file-name-directory file))))
2225 (when buffers
2226 (mapcar (lambda (buffer)
2227 (with-current-buffer buffer
2228 (if (dired-goto-file file)
2229 ;; bind vc-dired-terse-mode to nil so that
2230 ;; files won't vanish when they are checked in
2231 (let ((vc-dired-terse-mode nil))
2232 (dired-do-redisplay 1)))))
2233 buffers))))
2235 ;;;###autoload
2236 (defun vc-directory (dir read-switches)
2237 "Create a buffer in VC Dired Mode for directory DIR.
2239 See Info node `VC Dired Mode'.
2241 With prefix arg READ-SWITCHES, specify a value to override
2242 `dired-listing-switches' when generating the listing."
2243 (interactive "DDired under VC (directory): \nP")
2244 (let ((vc-dired-switches (concat vc-dired-listing-switches
2245 (if vc-dired-recurse "R" ""))))
2246 (if read-switches
2247 (setq vc-dired-switches
2248 (read-string "Dired listing switches: "
2249 vc-dired-switches)))
2250 (require 'dired)
2251 (require 'dired-aux)
2252 (switch-to-buffer
2253 (dired-internal-noselect (expand-file-name (file-name-as-directory dir))
2254 vc-dired-switches
2255 'vc-dired-mode))))
2258 ;; Named-configuration entry points
2260 (defun vc-snapshot-precondition (dir)
2261 "Scan the tree below DIR, looking for files not up-to-date.
2262 If any file is not up-to-date, return the name of the first such file.
2263 \(This means, neither snapshot creation nor retrieval is allowed.\)
2264 If one or more of the files are currently visited, return `visited'.
2265 Otherwise, return nil."
2266 (let ((status nil))
2267 (catch 'vc-locked-example
2268 (vc-file-tree-walk
2270 (lambda (f)
2271 (if (not (vc-up-to-date-p f)) (throw 'vc-locked-example f)
2272 (if (get-file-buffer f) (setq status 'visited)))))
2273 status)))
2275 ;;;###autoload
2276 (defun vc-create-snapshot (dir name branchp)
2277 "Descending recursively from DIR, make a snapshot called NAME.
2278 For each registered file, the version level of its latest version
2279 becomes part of the named configuration. If the prefix argument
2280 BRANCHP is given, the snapshot is made as a new branch and the files
2281 are checked out in that new branch."
2282 (interactive
2283 (list (read-file-name "Directory: " default-directory default-directory t)
2284 (read-string "New snapshot name: ")
2285 current-prefix-arg))
2286 (message "Making %s... " (if branchp "branch" "snapshot"))
2287 (if (file-directory-p dir) (setq dir (file-name-as-directory dir)))
2288 (vc-call-backend (vc-responsible-backend dir)
2289 'create-snapshot dir name branchp)
2290 (message "Making %s... done" (if branchp "branch" "snapshot")))
2292 (defun vc-default-create-snapshot (backend dir name branchp)
2293 (when branchp
2294 (error "VC backend %s does not support module branches" backend))
2295 (let ((result (vc-snapshot-precondition dir)))
2296 (if (stringp result)
2297 (error "File %s is not up-to-date" result)
2298 (vc-file-tree-walk
2300 (lambda (f)
2301 (vc-call assign-name f name))))))
2303 ;;;###autoload
2304 (defun vc-retrieve-snapshot (dir name)
2305 "Descending recursively from DIR, retrieve the snapshot called NAME.
2306 If NAME is empty, it refers to the latest versions.
2307 If locking is used for the files in DIR, then there must not be any
2308 locked files at or below DIR (but if NAME is empty, locked files are
2309 allowed and simply skipped)."
2310 (interactive
2311 (list (read-file-name "Directory: " default-directory default-directory t)
2312 (read-string "Snapshot name to retrieve (default latest versions): ")))
2313 (let ((update (yes-or-no-p "Update any affected buffers? "))
2314 (msg (if (or (not name) (string= name ""))
2315 (format "Updating %s... " (abbreviate-file-name dir))
2316 (format "Retrieving snapshot into %s... "
2317 (abbreviate-file-name dir)))))
2318 (message msg)
2319 (vc-call-backend (vc-responsible-backend dir)
2320 'retrieve-snapshot dir name update)
2321 (message (concat msg "done"))))
2323 (defun vc-default-retrieve-snapshot (backend dir name update)
2324 (if (string= name "")
2325 (progn
2326 (vc-file-tree-walk
2328 (lambda (f) (and
2329 (vc-up-to-date-p f)
2330 (vc-error-occurred
2331 (vc-call checkout f nil "")
2332 (if update (vc-resynch-buffer f t t)))))))
2333 (let ((result (vc-snapshot-precondition dir)))
2334 (if (stringp result)
2335 (error "File %s is locked" result)
2336 (setq update (and (eq result 'visited) update))
2337 (vc-file-tree-walk
2339 (lambda (f) (vc-error-occurred
2340 (vc-call checkout f nil name)
2341 (if update (vc-resynch-buffer f t t)))))))))
2343 ;; Miscellaneous other entry points
2345 ;;;###autoload
2346 (defun vc-print-log (&optional focus-rev)
2347 "List the change log of the current buffer in a window.
2348 If FOCUS-REV is non-nil, leave the point at that revision."
2349 (interactive)
2350 (vc-ensure-vc-buffer)
2351 (let ((file buffer-file-name))
2352 (or focus-rev (setq focus-rev (vc-workfile-version file)))
2353 ;; Don't switch to the output buffer before running the command,
2354 ;; so that any buffer-local settings in the vc-controlled
2355 ;; buffer can be accessed by the command.
2356 (condition-case err
2357 (progn
2358 (vc-call print-log file "*vc-change-log*")
2359 (set-buffer "*vc-change-log*"))
2360 (wrong-number-of-arguments
2361 ;; If this error came from the above call to print-log, try again
2362 ;; without the optional buffer argument (for backward compatibility).
2363 ;; Otherwise, resignal.
2364 (if (or (not (eq (cadr err)
2365 (indirect-function
2366 (vc-find-backend-function (vc-backend file)
2367 'print-log))))
2368 (not (eq (caddr err) 2)))
2369 (signal (car err) (cdr err))
2370 ;; for backward compatibility
2371 (vc-call print-log file)
2372 (set-buffer "*vc*"))))
2373 (pop-to-buffer (current-buffer))
2374 (log-view-mode)
2375 (vc-exec-after
2376 `(let ((inhibit-read-only t))
2377 (goto-char (point-max)) (forward-line -1)
2378 (while (looking-at "=*\n")
2379 (delete-char (- (match-end 0) (match-beginning 0)))
2380 (forward-line -1))
2381 (goto-char (point-min))
2382 (if (looking-at "[\b\t\n\v\f\r ]+")
2383 (delete-char (- (match-end 0) (match-beginning 0))))
2384 (shrink-window-if-larger-than-buffer)
2385 ;; move point to the log entry for the current version
2386 (vc-call-backend ',(vc-backend file)
2387 'show-log-entry
2388 ',focus-rev)
2389 (set-buffer-modified-p nil)))))
2391 (defun vc-default-show-log-entry (backend rev)
2392 (with-no-warnings
2393 (log-view-goto-rev rev)))
2395 (defun vc-default-comment-history (backend file)
2396 "Return a string with all log entries stored in BACKEND for FILE."
2397 (if (vc-find-backend-function backend 'print-log)
2398 (with-current-buffer "*vc*"
2399 (vc-call print-log file)
2400 (vc-call wash-log file)
2401 (buffer-string))))
2403 (defun vc-default-wash-log (backend file)
2404 "Remove all non-comment information from log output.
2405 This default implementation works for RCS logs; backends should override
2406 it if their logs are not in RCS format."
2407 (let ((separator (concat "^-+\nrevision [0-9.]+\ndate: .*\n"
2408 "\\(branches: .*;\n\\)?"
2409 "\\(\\*\\*\\* empty log message \\*\\*\\*\n\\)?")))
2410 (goto-char (point-max)) (forward-line -1)
2411 (while (looking-at "=*\n")
2412 (delete-char (- (match-end 0) (match-beginning 0)))
2413 (forward-line -1))
2414 (goto-char (point-min))
2415 (if (looking-at "[\b\t\n\v\f\r ]+")
2416 (delete-char (- (match-end 0) (match-beginning 0))))
2417 (goto-char (point-min))
2418 (re-search-forward separator nil t)
2419 (delete-region (point-min) (point))
2420 (while (re-search-forward separator nil t)
2421 (delete-region (match-beginning 0) (match-end 0)))))
2423 ;;;###autoload
2424 (defun vc-revert-buffer ()
2425 "Revert the current buffer's file to the version it was based on.
2426 This asks for confirmation if the buffer contents are not identical
2427 to that version. This function does not automatically pick up newer
2428 changes found in the master file; use \\[universal-argument] \\[vc-next-action] to do so."
2429 (interactive)
2430 (vc-ensure-vc-buffer)
2431 ;; Make sure buffer is saved. If the user says `no', abort since
2432 ;; we cannot show the changes and ask for confirmation to discard them.
2433 (vc-buffer-sync nil)
2434 (let ((file buffer-file-name)
2435 ;; This operation should always ask for confirmation.
2436 (vc-suppress-confirm nil)
2437 (obuf (current-buffer))
2438 status)
2439 (if (vc-up-to-date-p file)
2440 (unless (yes-or-no-p "File seems up-to-date. Revert anyway? ")
2441 (error "Revert canceled")))
2442 (unless (vc-workfile-unchanged-p file)
2443 ;; vc-diff selects the new window, which is not what we want:
2444 ;; if the new window is on another frame, that'd require the user
2445 ;; moving her mouse to answer the yes-or-no-p question.
2446 (let ((win (save-selected-window
2447 (setq status (vc-diff nil t)) (selected-window))))
2448 (vc-exec-after `(message nil))
2449 (when status
2450 (unwind-protect
2451 (unless (yes-or-no-p "Discard changes? ")
2452 (error "Revert canceled"))
2453 (select-window win)
2454 (if (one-window-p t)
2455 (if (window-dedicated-p (selected-window))
2456 (make-frame-invisible))
2457 (delete-window))))))
2458 (set-buffer obuf)
2459 ;; Do the reverting
2460 (message "Reverting %s..." file)
2461 (vc-revert-file file)
2462 (message "Reverting %s...done" file)))
2464 ;;;###autoload
2465 (defun vc-update ()
2466 "Update the current buffer's file to the latest version on its branch.
2467 If the file contains no changes, and is not locked, then this simply replaces
2468 the working file with the latest version on its branch. If the file contains
2469 changes, and the backend supports merging news, then any recent changes from
2470 the current branch are merged into the working file."
2471 (interactive)
2472 (vc-ensure-vc-buffer)
2473 (vc-buffer-sync nil)
2474 (let ((file buffer-file-name))
2475 (if (vc-up-to-date-p file)
2476 (vc-checkout file nil "")
2477 (if (eq (vc-checkout-model file) 'locking)
2478 (if (eq (vc-state file) 'edited)
2479 (error
2480 (substitute-command-keys
2481 "File is locked--type \\[vc-revert-buffer] to discard changes"))
2482 (error
2483 (substitute-command-keys
2484 "Unexpected file state (%s)--type \\[vc-next-action] to correct")
2485 (vc-state file)))
2486 (if (not (vc-find-backend-function (vc-backend file) 'merge-news))
2487 (error "Sorry, merging news is not implemented for %s"
2488 (vc-backend file))
2489 (vc-call merge-news file)
2490 (vc-resynch-window file t t))))))
2492 (defun vc-version-backup-file (file &optional rev)
2493 "Return name of backup file for revision REV of FILE.
2494 If version backups should be used for FILE, and there exists
2495 such a backup for REV or the current workfile version of file,
2496 return its name; otherwise return nil."
2497 (when (vc-call make-version-backups-p file)
2498 (let ((backup-file (vc-version-backup-file-name file rev)))
2499 (if (file-exists-p backup-file)
2500 backup-file
2501 ;; there is no automatic backup, but maybe the user made one manually
2502 (setq backup-file (vc-version-backup-file-name file rev 'manual))
2503 (if (file-exists-p backup-file)
2504 backup-file)))))
2506 (defun vc-revert-file (file)
2507 "Revert FILE back to the version it was based on."
2508 (with-vc-properties
2509 file
2510 (let ((backup-file (vc-version-backup-file file)))
2511 (when backup-file
2512 (copy-file backup-file file 'ok-if-already-exists 'keep-date)
2513 (vc-delete-automatic-version-backups file))
2514 (vc-call revert file backup-file))
2515 `((vc-state . up-to-date)
2516 (vc-checkout-time . ,(nth 5 (file-attributes file)))))
2517 (vc-resynch-buffer file t t))
2519 ;;;###autoload
2520 (defun vc-cancel-version (norevert)
2521 "Get rid of most recently checked in version of this file.
2522 A prefix argument NOREVERT means do not revert the buffer afterwards."
2523 (interactive "P")
2524 (vc-ensure-vc-buffer)
2525 (let* ((file buffer-file-name)
2526 (backend (vc-backend file))
2527 (target (vc-workfile-version file)))
2528 (cond
2529 ((not (vc-find-backend-function backend 'cancel-version))
2530 (error "Sorry, canceling versions is not supported under %s" backend))
2531 ((not (vc-call latest-on-branch-p file))
2532 (error "This is not the latest version; VC cannot cancel it"))
2533 ((not (vc-up-to-date-p file))
2534 (error "%s" (substitute-command-keys "File is not up to date; use \\[vc-revert-buffer] to discard changes"))))
2535 (if (null (yes-or-no-p (format "Remove version %s from master? " target)))
2536 (error "Aborted")
2537 (setq norevert (or norevert (not
2538 (yes-or-no-p "Revert buffer to most recent remaining version? "))))
2540 (message "Removing last change from %s..." file)
2541 (with-vc-properties
2542 file
2543 (vc-call cancel-version file norevert)
2544 `((vc-state . ,(if norevert 'edited 'up-to-date))
2545 (vc-checkout-time . ,(if norevert
2547 (nth 5 (file-attributes file))))
2548 (vc-workfile-version . nil)))
2549 (message "Removing last change from %s...done" file)
2551 (cond
2552 (norevert ;; clear version headers and mark the buffer modified
2553 (set-visited-file-name file)
2554 (when (not vc-make-backup-files)
2555 ;; inhibit backup for this buffer
2556 (make-local-variable 'backup-inhibited)
2557 (setq backup-inhibited t))
2558 (setq buffer-read-only nil)
2559 (vc-clear-headers)
2560 (vc-mode-line file)
2561 (vc-dired-resynch-file file))
2562 (t ;; revert buffer to file on disk
2563 (vc-resynch-buffer file t t)))
2564 (message "Version %s has been removed from the master" target))))
2566 ;;;###autoload
2567 (defun vc-switch-backend (file backend)
2568 "Make BACKEND the current version control system for FILE.
2569 FILE must already be registered in BACKEND. The change is not
2570 permanent, only for the current session. This function only changes
2571 VC's perspective on FILE, it does not register or unregister it.
2572 By default, this command cycles through the registered backends.
2573 To get a prompt, use a prefix argument."
2574 (interactive
2575 (list
2576 buffer-file-name
2577 (let ((backend (vc-backend buffer-file-name))
2578 (backends nil))
2579 ;; Find the registered backends.
2580 (dolist (backend vc-handled-backends)
2581 (when (vc-call-backend backend 'registered buffer-file-name)
2582 (push backend backends)))
2583 ;; Find the next backend.
2584 (let ((def (car (delq backend (append (memq backend backends) backends))))
2585 (others (delete backend backends)))
2586 (cond
2587 ((null others) (error "No other backend to switch to"))
2588 (current-prefix-arg
2589 (intern
2590 (upcase
2591 (completing-read
2592 (format "Switch to backend [%s]: " def)
2593 (mapcar (lambda (b) (list (downcase (symbol-name b)))) backends)
2594 nil t nil nil (downcase (symbol-name def))))))
2595 (t def))))))
2596 (unless (eq backend (vc-backend file))
2597 (vc-file-clearprops file)
2598 (vc-file-setprop file 'vc-backend backend)
2599 ;; Force recomputation of the state
2600 (unless (vc-call-backend backend 'registered file)
2601 (vc-file-clearprops file)
2602 (error "%s is not registered in %s" file backend))
2603 (vc-mode-line file)))
2605 ;;;###autoload
2606 (defun vc-transfer-file (file new-backend)
2607 "Transfer FILE to another version control system NEW-BACKEND.
2608 If NEW-BACKEND has a higher precedence than FILE's current backend
2609 \(i.e. it comes earlier in `vc-handled-backends'), then register FILE in
2610 NEW-BACKEND, using the version number from the current backend as the
2611 base level. If NEW-BACKEND has a lower precedence than the current
2612 backend, then commit all changes that were made under the current
2613 backend to NEW-BACKEND, and unregister FILE from the current backend.
2614 \(If FILE is not yet registered under NEW-BACKEND, register it.)"
2615 (let* ((old-backend (vc-backend file))
2616 (edited (memq (vc-state file) '(edited needs-merge)))
2617 (registered (vc-call-backend new-backend 'registered file))
2618 (move
2619 (and registered ; Never move if not registered in new-backend yet.
2620 ;; move if new-backend comes later in vc-handled-backends
2621 (or (memq new-backend (memq old-backend vc-handled-backends))
2622 (y-or-n-p "Final transfer? "))))
2623 (comment nil))
2624 (if (eq old-backend new-backend)
2625 (error "%s is the current backend of %s" new-backend file))
2626 (if registered
2627 (set-file-modes file (logior (file-modes file) 128))
2628 ;; `registered' might have switched under us.
2629 (vc-switch-backend file old-backend)
2630 (let* ((rev (vc-workfile-version file))
2631 (modified-file (and edited (make-temp-file file)))
2632 (unmodified-file (and modified-file (vc-version-backup-file file))))
2633 ;; Go back to the base unmodified file.
2634 (unwind-protect
2635 (progn
2636 (when modified-file
2637 (copy-file file modified-file 'ok-if-already-exists)
2638 ;; If we have a local copy of the unmodified file, handle that
2639 ;; here and not in vc-revert-file because we don't want to
2640 ;; delete that copy -- it is still useful for OLD-BACKEND.
2641 (if unmodified-file
2642 (copy-file unmodified-file file
2643 'ok-if-already-exists 'keep-date)
2644 (if (y-or-n-p "Get base version from master? ")
2645 (vc-revert-file file))))
2646 (vc-call-backend new-backend 'receive-file file rev))
2647 (when modified-file
2648 (vc-switch-backend file new-backend)
2649 (unless (eq (vc-checkout-model file) 'implicit)
2650 (vc-checkout file t nil))
2651 (rename-file modified-file file 'ok-if-already-exists)
2652 (vc-file-setprop file 'vc-checkout-time nil)))))
2653 (when move
2654 (vc-switch-backend file old-backend)
2655 (setq comment (vc-call comment-history file))
2656 (vc-call unregister file))
2657 (vc-switch-backend file new-backend)
2658 (when (or move edited)
2659 (vc-file-setprop file 'vc-state 'edited)
2660 (vc-mode-line file)
2661 (vc-checkin file nil comment (stringp comment)))))
2663 (defun vc-default-unregister (backend file)
2664 "Default implementation of `vc-unregister', signals an error."
2665 (error "Unregistering files is not supported for %s" backend))
2667 (defun vc-default-receive-file (backend file rev)
2668 "Let BACKEND receive FILE from another version control system."
2669 (vc-call-backend backend 'register file rev ""))
2671 (defun vc-rename-master (oldmaster newfile templates)
2672 "Rename OLDMASTER to be the master file for NEWFILE based on TEMPLATES."
2673 (let* ((dir (file-name-directory (expand-file-name oldmaster)))
2674 (newdir (or (file-name-directory newfile) ""))
2675 (newbase (file-name-nondirectory newfile))
2676 (masters
2677 ;; List of potential master files for `newfile'
2678 (mapcar
2679 (lambda (s) (vc-possible-master s newdir newbase))
2680 templates)))
2681 (if (or (file-symlink-p oldmaster)
2682 (file-symlink-p (file-name-directory oldmaster)))
2683 (error "This is unsafe in the presence of symbolic links"))
2684 (rename-file
2685 oldmaster
2686 (catch 'found
2687 ;; If possible, keep the master file in the same directory.
2688 (dolist (f masters)
2689 (if (and f (string= (file-name-directory (expand-file-name f)) dir))
2690 (throw 'found f)))
2691 ;; If not, just use the first possible place.
2692 (dolist (f masters)
2693 (and f (or (not (setq dir (file-name-directory f)))
2694 (file-directory-p dir))
2695 (throw 'found f)))
2696 (error "New file lacks a version control directory")))))
2698 (defun vc-delete-file (file)
2699 "Delete file and mark it as such in the version control system."
2700 (interactive "fVC delete file: ")
2701 (let ((buf (get-file-buffer file))
2702 (backend (vc-backend file)))
2703 (unless backend
2704 (error "File %s is not under version control"
2705 (file-name-nondirectory file)))
2706 (unless (vc-find-backend-function backend 'delete-file)
2707 (error "Deleting files under %s is not supported in VC" backend))
2708 (if (and buf (buffer-modified-p buf))
2709 (error "Please save files before deleting them"))
2710 (unless (y-or-n-p (format "Really want to delete %s ? "
2711 (file-name-nondirectory file)))
2712 (error "Abort!"))
2713 (unless (or (file-directory-p file) (null make-backup-files))
2714 (with-current-buffer (or buf (find-file-noselect file))
2715 (let ((backup-inhibited nil))
2716 (backup-buffer))))
2717 (vc-call delete-file file)
2718 ;; If the backend hasn't deleted the file itself, let's do it for him.
2719 (if (file-exists-p file) (delete-file file))))
2721 (defun vc-default-rename-file (backend old new)
2722 (condition-case nil
2723 (add-name-to-file old new)
2724 (error (rename-file old new)))
2725 (vc-delete-file old)
2726 (with-current-buffer (find-file-noselect new)
2727 (vc-register)))
2729 ;;;###autoload
2730 (defun vc-rename-file (old new)
2731 "Rename file OLD to NEW, and rename its master file likewise."
2732 (interactive "fVC rename file: \nFRename to: ")
2733 (let ((oldbuf (get-file-buffer old)))
2734 (if (and oldbuf (buffer-modified-p oldbuf))
2735 (error "Please save files before moving them"))
2736 (if (get-file-buffer new)
2737 (error "Already editing new file name"))
2738 (if (file-exists-p new)
2739 (error "New file already exists"))
2740 (let ((state (vc-state old)))
2741 (unless (memq state '(up-to-date edited))
2742 (error "Please %s files before moving them"
2743 (if (stringp state) "check in" "update"))))
2744 (vc-call rename-file old new)
2745 (vc-file-clearprops old)
2746 ;; Move the actual file (unless the backend did it already)
2747 (if (file-exists-p old) (rename-file old new))
2748 ;; ?? Renaming a file might change its contents due to keyword expansion.
2749 ;; We should really check out a new copy if the old copy was precisely equal
2750 ;; to some checked in version. However, testing for this is tricky....
2751 (if oldbuf
2752 (with-current-buffer oldbuf
2753 (let ((buffer-read-only buffer-read-only))
2754 (set-visited-file-name new))
2755 (vc-backend new)
2756 (vc-mode-line new)
2757 (set-buffer-modified-p nil)))))
2759 ;; Only defined in very recent Emacsen
2760 (defvar small-temporary-file-directory nil)
2762 ;;;###autoload
2763 (defun vc-update-change-log (&rest args)
2764 "Find change log file and add entries from recent version control logs.
2765 Normally, find log entries for all registered files in the default
2766 directory.
2768 With prefix arg of \\[universal-argument], only find log entries for the current buffer's file.
2770 With any numeric prefix arg, find log entries for all currently visited
2771 files that are under version control. This puts all the entries in the
2772 log for the default directory, which may not be appropriate.
2774 From a program, any ARGS are assumed to be filenames for which
2775 log entries should be gathered."
2776 (interactive
2777 (cond ((consp current-prefix-arg) ;C-u
2778 (list buffer-file-name))
2779 (current-prefix-arg ;Numeric argument.
2780 (let ((files nil)
2781 (buffers (buffer-list))
2782 file)
2783 (while buffers
2784 (setq file (buffer-file-name (car buffers)))
2785 (and file (vc-backend file)
2786 (setq files (cons file files)))
2787 (setq buffers (cdr buffers)))
2788 files))
2790 ;; Don't supply any filenames to backend; this means
2791 ;; it should find all relevant files relative to
2792 ;; the default-directory.
2793 nil)))
2794 (vc-call-backend (vc-responsible-backend default-directory)
2795 'update-changelog args))
2797 (defun vc-default-update-changelog (backend files)
2798 "Default implementation of update-changelog.
2799 Uses `rcs2log' which only works for RCS and CVS."
2800 ;; FIXME: We (c|sh)ould add support for cvs2cl
2801 (let ((odefault default-directory)
2802 (changelog (find-change-log))
2803 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
2804 (tempfile (make-temp-file
2805 (expand-file-name "vc"
2806 (or small-temporary-file-directory
2807 temporary-file-directory))))
2808 (full-name (or add-log-full-name
2809 (user-full-name)
2810 (user-login-name)
2811 (format "uid%d" (number-to-string (user-uid)))))
2812 (mailing-address (or add-log-mailing-address
2813 user-mail-address)))
2814 (find-file-other-window changelog)
2815 (barf-if-buffer-read-only)
2816 (vc-buffer-sync)
2817 (undo-boundary)
2818 (goto-char (point-min))
2819 (push-mark)
2820 (message "Computing change log entries...")
2821 (message "Computing change log entries... %s"
2822 (unwind-protect
2823 (progn
2824 (setq default-directory odefault)
2825 (if (eq 0 (apply 'call-process
2826 (expand-file-name "rcs2log"
2827 exec-directory)
2828 nil (list t tempfile) nil
2829 "-c" changelog
2830 "-u" (concat (vc-user-login-name)
2831 "\t" full-name
2832 "\t" mailing-address)
2833 (mapcar
2834 (lambda (f)
2835 (file-relative-name
2836 (if (file-name-absolute-p f)
2838 (concat odefault f))))
2839 files)))
2840 "done"
2841 (pop-to-buffer
2842 (set-buffer (get-buffer-create "*vc*")))
2843 (erase-buffer)
2844 (insert-file tempfile)
2845 "failed"))
2846 (setq default-directory (file-name-directory changelog))
2847 (delete-file tempfile)))))
2849 ;; Annotate functionality
2851 ;; Declare globally instead of additional parameter to
2852 ;; temp-buffer-show-function (not possible to pass more than one
2853 ;; parameter). The use of annotate-ratio is deprecated in favor of
2854 ;; annotate-mode, which replaces it with the more sensible "span-to
2855 ;; days", along with autoscaling support.
2856 (defvar vc-annotate-ratio nil "Global variable.")
2857 (defvar vc-annotate-backend nil "Global variable.")
2859 ;; internal buffer-local variables
2860 (defvar vc-annotate-parent-file nil)
2861 (defvar vc-annotate-parent-rev nil)
2862 (defvar vc-annotate-parent-display-mode nil)
2864 (defconst vc-annotate-font-lock-keywords
2865 ;; The fontification is done by vc-annotate-lines instead of font-lock.
2866 '((vc-annotate-lines)))
2868 (defun vc-annotate-get-backend (buffer)
2869 "Return the backend matching \"Annotate\" buffer BUFFER.
2870 Return nil if no match made. Associations are made based on
2871 `vc-annotate-buffers'."
2872 (cdr (assoc buffer vc-annotate-buffers)))
2874 (define-derived-mode vc-annotate-mode fundamental-mode "Annotate"
2875 "Major mode for output buffers of the `vc-annotate' command.
2877 You can use the mode-specific menu to alter the time-span of the used
2878 colors. See variable `vc-annotate-menu-elements' for customizing the
2879 menu items."
2880 (set (make-local-variable 'truncate-lines) t)
2881 (set (make-local-variable 'font-lock-defaults)
2882 '(vc-annotate-font-lock-keywords t))
2883 (view-mode 1)
2884 (vc-annotate-add-menu))
2886 (defun vc-annotate-display-default (&optional ratio)
2887 "Display the output of \\[vc-annotate] using the default color range.
2888 The color range is given by `vc-annotate-color-map', scaled by RATIO
2889 if present. The current time is used as the offset."
2890 (interactive "e")
2891 (message "Redisplaying annotation...")
2892 (vc-annotate-display
2893 (if ratio (vc-annotate-time-span vc-annotate-color-map ratio)))
2894 (message "Redisplaying annotation...done"))
2896 (defun vc-annotate-display-autoscale (&optional full)
2897 "Highlight the output of \\[vc-annotate] using an autoscaled color map.
2898 Autoscaling means that the map is scaled from the current time to the
2899 oldest annotation in the buffer, or, with prefix argument FULL, to
2900 cover the range from the oldest annotation to the newest."
2901 (interactive "P")
2902 (let ((newest 0.0)
2903 (oldest 999999.) ;Any CVS users at the founding of Rome?
2904 (current (vc-annotate-convert-time (current-time)))
2905 date)
2906 (message "Redisplaying annotation...")
2907 ;; Run through this file and find the oldest and newest dates annotated.
2908 (save-excursion
2909 (goto-char (point-min))
2910 (while (setq date (prog1 (vc-call-backend vc-annotate-backend
2911 'annotate-time)
2912 (forward-line 1)))
2913 (if (> date newest)
2914 (setq newest date))
2915 (if (< date oldest)
2916 (setq oldest date))))
2917 (vc-annotate-display
2918 (vc-annotate-time-span ;return the scaled colormap.
2919 vc-annotate-color-map
2920 (/ (- (if full newest current) oldest)
2921 (vc-annotate-car-last-cons vc-annotate-color-map)))
2922 (if full newest))
2923 (message "Redisplaying annotation...done \(%s\)"
2924 (if full
2925 (format "Spanned from %.1f to %.1f days old"
2926 (- current oldest)
2927 (- current newest))
2928 (format "Spanned to %.1f days old" (- current oldest))))))
2930 ;; Menu -- Using easymenu.el
2931 (defun vc-annotate-add-menu ()
2932 "Add the menu 'Annotate' to the menu bar in VC-Annotate mode."
2933 (let ((menu-elements vc-annotate-menu-elements)
2934 (menu-def
2935 '("VC-Annotate"
2936 ["Default" (unless (null vc-annotate-display-mode)
2937 (setq vc-annotate-display-mode nil)
2938 (vc-annotate-display-select))
2939 :style toggle :selected (null vc-annotate-display-mode)]))
2940 (oldest-in-map (vc-annotate-car-last-cons vc-annotate-color-map)))
2941 (while menu-elements
2942 (let* ((element (car menu-elements))
2943 (days (* element oldest-in-map)))
2944 (setq menu-elements (cdr menu-elements))
2945 (setq menu-def
2946 (append menu-def
2947 `([,(format "Span %.1f days" days)
2948 (unless (and (numberp vc-annotate-display-mode)
2949 (= vc-annotate-display-mode ,days))
2950 (vc-annotate-display-select nil ,days))
2951 :style toggle :selected
2952 (and (numberp vc-annotate-display-mode)
2953 (= vc-annotate-display-mode ,days)) ])))))
2954 (setq menu-def
2955 (append menu-def
2956 (list
2957 ["Span ..."
2958 (let ((days
2959 (float (string-to-number
2960 (read-string "Span how many days? ")))))
2961 (vc-annotate-display-select nil days)) t])
2962 (list "--")
2963 (list
2964 ["Span to Oldest"
2965 (unless (eq vc-annotate-display-mode 'scale)
2966 (vc-annotate-display-select nil 'scale))
2967 :style toggle :selected
2968 (eq vc-annotate-display-mode 'scale)])
2969 (list
2970 ["Span Oldest->Newest"
2971 (unless (eq vc-annotate-display-mode 'fullscale)
2972 (vc-annotate-display-select nil 'fullscale))
2973 :style toggle :selected
2974 (eq vc-annotate-display-mode 'fullscale)])
2975 (list "--")
2976 (list ["Annotate previous revision"
2977 (call-interactively 'vc-annotate-prev-version)])
2978 (list ["Annotate next revision"
2979 (call-interactively 'vc-annotate-next-version)])
2980 (list ["Annotate revision at line"
2981 (vc-annotate-revision-at-line)])
2982 (list ["Annotate revision previous to line"
2983 (vc-annotate-revision-previous-to-line)])
2984 (list ["Annotate latest revision"
2985 (vc-annotate-workfile-version)])
2986 (list ["Show log of revision at line"
2987 (vc-annotate-show-log-revision-at-line)])
2988 (list ["Show diff of revision at line"
2989 (vc-annotate-show-diff-revision-at-line)])))
2991 ;; Define the menu
2992 (if (or (featurep 'easymenu) (load "easymenu" t))
2993 (easy-menu-define vc-annotate-mode-menu vc-annotate-mode-map
2994 "VC Annotate Display Menu" menu-def))))
2996 (defun vc-annotate-display-select (&optional buffer mode)
2997 "Highlight the output of \\[vc-annotate].
2998 By default, the current buffer is highlighted, unless overridden by
2999 BUFFER. `vc-annotate-display-mode' specifies the highlighting mode to
3000 use; you may override this using the second optional arg MODE."
3001 (interactive)
3002 (if mode (setq vc-annotate-display-mode mode))
3003 (when buffer
3004 (set-buffer buffer)
3005 (display-buffer buffer))
3006 (if (not vc-annotate-parent-rev)
3007 (vc-annotate-mode))
3008 (cond ((null vc-annotate-display-mode)
3009 (vc-annotate-display-default vc-annotate-ratio))
3010 ;; One of the auto-scaling modes
3011 ((eq vc-annotate-display-mode 'scale)
3012 (vc-annotate-display-autoscale))
3013 ((eq vc-annotate-display-mode 'fullscale)
3014 (vc-annotate-display-autoscale t))
3015 ((numberp vc-annotate-display-mode) ; A fixed number of days lookback
3016 (vc-annotate-display-default
3017 (/ vc-annotate-display-mode (vc-annotate-car-last-cons
3018 vc-annotate-color-map))))
3019 (t (error "No such display mode: %s"
3020 vc-annotate-display-mode))))
3022 ;;;; (defun vc-BACKEND-annotate-command (file buffer) ...)
3023 ;;;; Execute "annotate" on FILE by using `call-process' and insert
3024 ;;;; the contents in BUFFER.
3026 ;;;###autoload
3027 (defun vc-annotate (prefix &optional revision display-mode)
3028 "Display the edit history of the current file using colours.
3030 This command creates a buffer that shows, for each line of the current
3031 file, when it was last edited and by whom. Additionally, colours are
3032 used to show the age of each line--blue means oldest, red means
3033 youngest, and intermediate colours indicate intermediate ages. By
3034 default, the time scale stretches back one year into the past;
3035 everything that is older than that is shown in blue.
3037 With a prefix argument, this command asks two questions in the
3038 minibuffer. First, you may enter a version number; then the buffer
3039 displays and annotates that version instead of the current version
3040 \(type RET in the minibuffer to leave that default unchanged). Then,
3041 you are prompted for the time span in days which the color range
3042 should cover. For example, a time span of 20 days means that changes
3043 over the past 20 days are shown in red to blue, according to their
3044 age, and everything that is older than that is shown in blue.
3046 Customization variables:
3048 `vc-annotate-menu-elements' customizes the menu elements of the
3049 mode-specific menu. `vc-annotate-color-map' and
3050 `vc-annotate-very-old-color' defines the mapping of time to
3051 colors. `vc-annotate-background' specifies the background color."
3052 (interactive "P")
3053 (vc-ensure-vc-buffer)
3054 (let* ((temp-buffer-name nil)
3055 (temp-buffer-show-function 'vc-annotate-display-select)
3056 (rev (or revision (vc-workfile-version buffer-file-name)))
3057 (bfn buffer-file-name)
3058 (vc-annotate-version
3059 (if prefix (read-string
3060 (format "Annotate from version: (default %s) " rev)
3061 nil nil rev)
3062 rev)))
3063 (if display-mode
3064 (setq vc-annotate-display-mode display-mode)
3065 (if prefix
3066 (setq vc-annotate-display-mode
3067 (float (string-to-number
3068 (read-string "Annotate span days: (default 20) "
3069 nil nil "20"))))))
3070 (setq temp-buffer-name (format "*Annotate %s (rev %s)*"
3071 (buffer-name) vc-annotate-version))
3072 (setq vc-annotate-backend (vc-backend buffer-file-name))
3073 (message "Annotating...")
3074 (if (not (vc-find-backend-function vc-annotate-backend 'annotate-command))
3075 (error "Sorry, annotating is not implemented for %s"
3076 vc-annotate-backend))
3077 (with-output-to-temp-buffer temp-buffer-name
3078 (vc-call-backend vc-annotate-backend 'annotate-command
3079 buffer-file-name
3080 (get-buffer temp-buffer-name)
3081 vc-annotate-version))
3082 (save-excursion
3083 (set-buffer temp-buffer-name)
3084 (set (make-local-variable 'vc-annotate-parent-file) bfn)
3085 (set (make-local-variable 'vc-annotate-parent-rev) vc-annotate-version)
3086 (set (make-local-variable 'vc-annotate-parent-display-mode)
3087 vc-annotate-display-mode))
3089 ;; Don't use the temp-buffer-name until the buffer is created
3090 ;; (only after `with-output-to-temp-buffer'.)
3091 (setq vc-annotate-buffers
3092 (append vc-annotate-buffers
3093 (list (cons (get-buffer temp-buffer-name) vc-annotate-backend))))
3094 (message "Annotating... done")))
3096 (defun vc-annotate-prev-version (prefix)
3097 "Visit the annotation of the version previous to this one.
3099 With a numeric prefix argument, annotate the version that many
3100 versions previous."
3101 (interactive "p")
3102 (vc-annotate-warp-version (- 0 prefix)))
3104 (defun vc-annotate-next-version (prefix)
3105 "Visit the annotation of the version after this one.
3107 With a numeric prefix argument, annotate the version that many
3108 versions after."
3109 (interactive "p")
3110 (vc-annotate-warp-version prefix))
3112 (defun vc-annotate-workfile-version ()
3113 "Visit the annotation of the workfile version of this file."
3114 (interactive)
3115 (if (not (equal major-mode 'vc-annotate-mode))
3116 (message "Cannot be invoked outside of a vc annotate buffer")
3117 (let ((warp-rev (vc-workfile-version vc-annotate-parent-file)))
3118 (if (equal warp-rev vc-annotate-parent-rev)
3119 (message "Already at version %s" warp-rev)
3120 (vc-annotate-warp-version warp-rev)))))
3122 (defun vc-annotate-extract-revision-at-line ()
3123 "Extract the revision number of the current line."
3124 ;; This function must be invoked from a buffer in vc-annotate-mode
3125 (save-window-excursion
3126 (vc-ensure-vc-buffer)
3127 (setq vc-annotate-backend (vc-backend buffer-file-name)))
3128 (vc-call-backend vc-annotate-backend 'annotate-extract-revision-at-line))
3130 (defun vc-annotate-revision-at-line ()
3131 "Visit the annotation of the version identified in the current line."
3132 (interactive)
3133 (if (not (equal major-mode 'vc-annotate-mode))
3134 (message "Cannot be invoked outside of a vc annotate buffer")
3135 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
3136 (if (not rev-at-line)
3137 (message "Cannot extract revision number from the current line")
3138 (if (equal rev-at-line vc-annotate-parent-rev)
3139 (message "Already at version %s" rev-at-line)
3140 (vc-annotate-warp-version rev-at-line))))))
3142 (defun vc-annotate-revision-previous-to-line ()
3143 "Visit the annotation of the version before the version at line."
3144 (interactive)
3145 (if (not (equal major-mode 'vc-annotate-mode))
3146 (message "Cannot be invoked outside of a vc annotate buffer")
3147 (let ((rev-at-line (vc-annotate-extract-revision-at-line))
3148 (prev-rev nil))
3149 (if (not rev-at-line)
3150 (message "Cannot extract revision number from the current line")
3151 (setq prev-rev
3152 (vc-call previous-version vc-annotate-parent-file rev-at-line))
3153 (vc-annotate-warp-version prev-rev)))))
3155 (defun vc-annotate-show-log-revision-at-line ()
3156 "Visit the log of the version at line."
3157 (interactive)
3158 (if (not (equal major-mode 'vc-annotate-mode))
3159 (message "Cannot be invoked outside of a vc annotate buffer")
3160 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
3161 (if (not rev-at-line)
3162 (message "Cannot extract revision number from the current line")
3163 (vc-print-log rev-at-line)))))
3165 (defun vc-annotate-show-diff-revision-at-line ()
3166 "Visit the diff of the version at line from its previous version."
3167 (interactive)
3168 (if (not (equal major-mode 'vc-annotate-mode))
3169 (message "Cannot be invoked outside of a vc annotate buffer")
3170 (let ((rev-at-line (vc-annotate-extract-revision-at-line))
3171 (prev-rev nil))
3172 (if (not rev-at-line)
3173 (message "Cannot extract revision number from the current line")
3174 (setq prev-rev
3175 (vc-call previous-version vc-annotate-parent-file rev-at-line))
3176 (if (not prev-rev)
3177 (message "Cannot diff from any version prior to %s" rev-at-line)
3178 (save-window-excursion
3179 (vc-version-diff vc-annotate-parent-file prev-rev rev-at-line))
3180 (switch-to-buffer "*vc-diff*"))))))
3182 (defun vc-annotate-warp-version (revspec)
3183 "Annotate the version described by REVSPEC.
3185 If REVSPEC is a positive integer, warp that many versions
3186 forward, if possible, otherwise echo a warning message. If
3187 REVSPEC is a negative integer, warp that many versions backward,
3188 if possible, otherwise echo a warning message. If REVSPEC is a
3189 string, then it describes a revision number, so warp to that
3190 revision."
3191 (if (not (equal major-mode 'vc-annotate-mode))
3192 (message "Cannot be invoked outside of a vc annotate buffer")
3193 (let* ((oldline (line-number-at-pos))
3194 (revspeccopy revspec)
3195 (newrev nil))
3196 (cond
3197 ((and (integerp revspec) (> revspec 0))
3198 (setq newrev vc-annotate-parent-rev)
3199 (while (and (> revspec 0) newrev)
3200 (setq newrev (vc-call next-version
3201 vc-annotate-parent-file newrev))
3202 (setq revspec (1- revspec)))
3203 (if (not newrev)
3204 (message "Cannot increment %d versions from version %s"
3205 revspeccopy vc-annotate-parent-rev)))
3206 ((and (integerp revspec) (< revspec 0))
3207 (setq newrev vc-annotate-parent-rev)
3208 (while (and (< revspec 0) newrev)
3209 (setq newrev (vc-call previous-version
3210 vc-annotate-parent-file newrev))
3211 (setq revspec (1+ revspec)))
3212 (if (not newrev)
3213 (message "Cannot decrement %d versions from version %s"
3214 (- 0 revspeccopy) vc-annotate-parent-rev)))
3215 ((stringp revspec) (setq newrev revspec))
3216 (t (error "Invalid argument to vc-annotate-warp-version")))
3217 (when newrev
3218 (save-window-excursion
3219 (find-file vc-annotate-parent-file)
3220 (vc-annotate nil newrev vc-annotate-parent-display-mode))
3221 (kill-buffer (current-buffer)) ;; kill the buffer we started from
3222 (switch-to-buffer (car (car (last vc-annotate-buffers))))
3223 (goto-line (min oldline (progn (goto-char (point-max))
3224 (previous-line)
3225 (line-number-at-pos))))))))
3227 (defun vc-annotate-car-last-cons (a-list)
3228 "Return car of last cons in association list A-LIST."
3229 (if (not (eq nil (cdr a-list)))
3230 (vc-annotate-car-last-cons (cdr a-list))
3231 (car (car a-list))))
3233 (defun vc-annotate-time-span (a-list span &optional quantize)
3234 "Apply factor SPAN to the time-span of association list A-LIST.
3235 Return the new alist.
3236 Optionally quantize to the factor of QUANTIZE."
3237 ;; Apply span to each car of every cons
3238 (if (not (eq nil a-list))
3239 (append (list (cons (* (car (car a-list)) span)
3240 (cdr (car a-list))))
3241 (vc-annotate-time-span (nthcdr (or quantize ; optional
3242 1) ; Default to cdr
3243 a-list) span quantize))))
3245 (defun vc-annotate-compcar (threshold a-list)
3246 "Test successive cons cells of A-LIST against THRESHOLD.
3247 Return the first cons cell with a car that is not less than THRESHOLD,
3248 nil if no such cell exists."
3249 (let ((i 1)
3250 (tmp-cons (car a-list)))
3251 (while (and tmp-cons (< (car tmp-cons) threshold))
3252 (setq tmp-cons (car (nthcdr i a-list)))
3253 (setq i (+ i 1)))
3254 tmp-cons)) ; Return the appropriate value
3256 (defun vc-annotate-convert-time (time)
3257 "Convert a time value to a floating-point number of days.
3258 The argument TIME is a list as returned by `current-time' or
3259 `encode-time', only the first two elements of that list are considered."
3260 (/ (+ (* (float (car time)) (lsh 1 16)) (cadr time)) 24 3600))
3262 (defun vc-annotate-difference (&optional offset)
3263 "Return the time span in days to the next annotation.
3264 This calls the backend function annotate-time, and returns the
3265 difference in days between the time returned and the current time,
3266 or OFFSET if present."
3267 (let ((next-time (vc-call-backend vc-annotate-backend 'annotate-time)))
3268 (if next-time
3269 (- (or offset
3270 (vc-call-backend vc-annotate-backend 'annotate-current-time))
3271 next-time))))
3273 (defun vc-default-annotate-current-time (backend)
3274 "Return the current time, encoded as fractional days."
3275 (vc-annotate-convert-time (current-time)))
3277 (defvar vc-annotate-offset nil)
3279 (defun vc-annotate-display (&optional color-map offset)
3280 "Highlight `vc-annotate' output in the current buffer.
3281 COLOR-MAP, if present, overrides `vc-annotate-color-map'.
3282 The annotations are relative to the current time, unless overridden by OFFSET."
3283 (if (and color-map (not (eq color-map vc-annotate-color-map)))
3284 (set (make-local-variable 'vc-annotate-color-map) color-map))
3285 (set (make-local-variable 'vc-annotate-offset) offset)
3286 (font-lock-mode 1))
3288 (defun vc-annotate-lines (limit)
3289 (let (difference)
3290 (while (and (< (point) limit)
3291 (setq difference (vc-annotate-difference vc-annotate-offset)))
3292 (let* ((color (or (vc-annotate-compcar difference vc-annotate-color-map)
3293 (cons nil vc-annotate-very-old-color)))
3294 ;; substring from index 1 to remove any leading `#' in the name
3295 (face-name (concat "vc-annotate-face-" (substring (cdr color) 1)))
3296 ;; Make the face if not done.
3297 (face (or (intern-soft face-name)
3298 (let ((tmp-face (make-face (intern face-name))))
3299 (set-face-foreground tmp-face (cdr color))
3300 (if vc-annotate-background
3301 (set-face-background tmp-face
3302 vc-annotate-background))
3303 tmp-face))) ; Return the face
3304 (point (point)))
3305 (forward-line 1)
3306 (put-text-property point (point) 'face face)))
3307 ;; Pretend to font-lock there were no matches.
3308 nil))
3310 ;; Collect back-end-dependent stuff here
3312 (defalias 'vc-default-logentry-check 'ignore)
3314 (defun vc-check-headers ()
3315 "Check if the current file has any headers in it."
3316 (interactive)
3317 (vc-call-backend (vc-backend buffer-file-name) 'check-headers))
3319 (defun vc-default-check-headers (backend)
3320 "Default implementation of check-headers; always returns nil."
3321 nil)
3323 ;; Back-end-dependent stuff ends here.
3325 ;; Set up key bindings for use while editing log messages
3327 (defun vc-log-edit (file)
3328 "Set up `log-edit' for use with VC on FILE."
3329 (setq default-directory
3330 (if file (file-name-directory file)
3331 (with-current-buffer vc-parent-buffer default-directory)))
3332 (log-edit 'vc-finish-logentry nil
3333 (if file `(lambda () ',(list (file-name-nondirectory file)))
3334 ;; If FILE is nil, we were called from vc-dired.
3335 (lambda ()
3336 (with-current-buffer vc-parent-buffer
3337 (dired-get-marked-files t)))))
3338 (set (make-local-variable 'vc-log-file) file)
3339 (make-local-variable 'vc-log-version)
3340 (set-buffer-modified-p nil)
3341 (setq buffer-file-name nil))
3343 ;; These things should probably be generally available
3345 (defun vc-file-tree-walk (dirname func &rest args)
3346 "Walk recursively through DIRNAME.
3347 Invoke FUNC f ARGS on each VC-managed file f underneath it."
3348 (vc-file-tree-walk-internal (expand-file-name dirname) func args)
3349 (message "Traversing directory %s...done" dirname))
3351 (defun vc-file-tree-walk-internal (file func args)
3352 (if (not (file-directory-p file))
3353 (if (vc-backend file) (apply func file args))
3354 (message "Traversing directory %s..." (abbreviate-file-name file))
3355 (let ((dir (file-name-as-directory file)))
3356 (mapcar
3357 (lambda (f) (or
3358 (string-equal f ".")
3359 (string-equal f "..")
3360 (member f vc-directory-exclusion-list)
3361 (let ((dirf (expand-file-name f dir)))
3363 (file-symlink-p dirf);; Avoid possible loops
3364 (vc-file-tree-walk-internal dirf func args)))))
3365 (directory-files dir)))))
3367 (provide 'vc)
3369 ;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
3371 ;; These may be useful to anyone who has to debug or extend the package.
3372 ;; (Note that this information corresponds to versions 5.x. Some of it
3373 ;; might have been invalidated by the additions to support branching
3374 ;; and RCS keyword lookup. AS, 1995/03/24)
3376 ;; A fundamental problem in VC is that there are time windows between
3377 ;; vc-next-action's computations of the file's version-control state and
3378 ;; the actions that change it. This is a window open to lossage in a
3379 ;; multi-user environment; someone else could nip in and change the state
3380 ;; of the master during it.
3382 ;; The performance problem is that rlog/prs calls are very expensive; we want
3383 ;; to avoid them as much as possible.
3385 ;; ANALYSIS:
3387 ;; The performance problem, it turns out, simplifies in practice to the
3388 ;; problem of making vc-state fast. The two other functions that call
3389 ;; prs/rlog will not be so commonly used that the slowdown is a problem; one
3390 ;; makes snapshots, the other deletes the calling user's last change in the
3391 ;; master.
3393 ;; The race condition implies that we have to either (a) lock the master
3394 ;; during the entire execution of vc-next-action, or (b) detect and
3395 ;; recover from errors resulting from dispatch on an out-of-date state.
3397 ;; Alternative (a) appears to be infeasible. The problem is that we can't
3398 ;; guarantee that the lock will ever be removed. Suppose a user starts a
3399 ;; checkin, the change message buffer pops up, and the user, having wandered
3400 ;; off to do something else, simply forgets about it?
3402 ;; Alternative (b), on the other hand, works well with a cheap way to speed up
3403 ;; vc-state. Usually, if a file is registered, we can read its locked/
3404 ;; unlocked state and its current owner from its permissions.
3406 ;; This shortcut will fail if someone has manually changed the workfile's
3407 ;; permissions; also if developers are munging the workfile in several
3408 ;; directories, with symlinks to a master (in this latter case, the
3409 ;; permissions shortcut will fail to detect a lock asserted from another
3410 ;; directory).
3412 ;; Note that these cases correspond exactly to the errors which could happen
3413 ;; because of a competing checkin/checkout race in between two instances of
3414 ;; vc-next-action.
3416 ;; For VC's purposes, a workfile/master pair may have the following states:
3418 ;; A. Unregistered. There is a workfile, there is no master.
3420 ;; B. Registered and not locked by anyone.
3422 ;; C. Locked by calling user and unchanged.
3424 ;; D. Locked by the calling user and changed.
3426 ;; E. Locked by someone other than the calling user.
3428 ;; This makes for 25 states and 20 error conditions. Here's the matrix:
3430 ;; VC's idea of state
3431 ;; |
3432 ;; V Actual state RCS action SCCS action Effect
3433 ;; A B C D E
3434 ;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
3435 ;; B 5 . 6 7 8 co -l get -e checkout
3436 ;; C 9 10 . 11 12 co -u unget; get revert
3437 ;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
3438 ;; E 17 18 19 20 . rcs -u -M -l unget -n ; get -g steal lock
3440 ;; All commands take the master file name as a last argument (not shown).
3442 ;; In the discussion below, a "self-race" is a pathological situation in
3443 ;; which VC operations are being attempted simultaneously by two or more
3444 ;; Emacsen running under the same username.
3446 ;; The vc-next-action code has the following windows:
3448 ;; Window P:
3449 ;; Between the check for existence of a master file and the call to
3450 ;; admin/checkin in vc-buffer-admin (apparent state A). This window may
3451 ;; never close if the initial-comment feature is on.
3453 ;; Window Q:
3454 ;; Between the call to vc-workfile-unchanged-p in and the immediately
3455 ;; following revert (apparent state C).
3457 ;; Window R:
3458 ;; Between the call to vc-workfile-unchanged-p in and the following
3459 ;; checkin (apparent state D). This window may never close.
3461 ;; Window S:
3462 ;; Between the unlock and the immediately following checkout during a
3463 ;; revert operation (apparent state C). Included in window Q.
3465 ;; Window T:
3466 ;; Between vc-state and the following checkout (apparent state B).
3468 ;; Window U:
3469 ;; Between vc-state and the following revert (apparent state C).
3470 ;; Includes windows Q and S.
3472 ;; Window V:
3473 ;; Between vc-state and the following checkin (apparent state
3474 ;; D). This window may never be closed if the user fails to complete the
3475 ;; checkin message. Includes window R.
3477 ;; Window W:
3478 ;; Between vc-state and the following steal-lock (apparent
3479 ;; state E). This window may never close if the user fails to complete
3480 ;; the steal-lock message. Includes window X.
3482 ;; Window X:
3483 ;; Between the unlock and the immediately following re-lock during a
3484 ;; steal-lock operation (apparent state E). This window may never close
3485 ;; if the user fails to complete the steal-lock message.
3487 ;; Errors:
3489 ;; Apparent state A ---
3491 ;; 1. File looked unregistered but is actually registered and not locked.
3493 ;; Potential cause: someone else's admin during window P, with
3494 ;; caller's admin happening before their checkout.
3496 ;; RCS: Prior to version 5.6.4, ci fails with message
3497 ;; "no lock set by <user>". From 5.6.4 onwards, VC uses the new
3498 ;; ci -i option and the message is "<file>,v: already exists".
3499 ;; SCCS: admin will fail with error (ad19).
3501 ;; We can let these errors be passed up to the user.
3503 ;; 2. File looked unregistered but is actually locked by caller, unchanged.
3505 ;; Potential cause: self-race during window P.
3507 ;; RCS: Prior to version 5.6.4, reverts the file to the last saved
3508 ;; version and unlocks it. From 5.6.4 onwards, VC uses the new
3509 ;; ci -i option, failing with message "<file>,v: already exists".
3510 ;; SCCS: will fail with error (ad19).
3512 ;; Either of these consequences is acceptable.
3514 ;; 3. File looked unregistered but is actually locked by caller, changed.
3516 ;; Potential cause: self-race during window P.
3518 ;; RCS: Prior to version 5.6.4, VC registers the caller's workfile as
3519 ;; a delta with a null change comment (the -t- switch will be
3520 ;; ignored). From 5.6.4 onwards, VC uses the new ci -i option,
3521 ;; failing with message "<file>,v: already exists".
3522 ;; SCCS: will fail with error (ad19).
3524 ;; 4. File looked unregistered but is locked by someone else.
3526 ;; Potential cause: someone else's admin during window P, with
3527 ;; caller's admin happening *after* their checkout.
3529 ;; RCS: Prior to version 5.6.4, ci fails with a
3530 ;; "no lock set by <user>" message. From 5.6.4 onwards,
3531 ;; VC uses the new ci -i option, failing with message
3532 ;; "<file>,v: already exists".
3533 ;; SCCS: will fail with error (ad19).
3535 ;; We can let these errors be passed up to the user.
3537 ;; Apparent state B ---
3539 ;; 5. File looked registered and not locked, but is actually unregistered.
3541 ;; Potential cause: master file got nuked during window P.
3543 ;; RCS: will fail with "RCS/<file>: No such file or directory"
3544 ;; SCCS: will fail with error ut4.
3546 ;; We can let these errors be passed up to the user.
3548 ;; 6. File looked registered and not locked, but is actually locked by the
3549 ;; calling user and unchanged.
3551 ;; Potential cause: self-race during window T.
3553 ;; RCS: in the same directory as the previous workfile, co -l will fail
3554 ;; with "co error: writable foo exists; checkout aborted". In any other
3555 ;; directory, checkout will succeed.
3556 ;; SCCS: will fail with ge17.
3558 ;; Either of these consequences is acceptable.
3560 ;; 7. File looked registered and not locked, but is actually locked by the
3561 ;; calling user and changed.
3563 ;; As case 6.
3565 ;; 8. File looked registered and not locked, but is actually locked by another
3566 ;; user.
3568 ;; Potential cause: someone else checks it out during window T.
3570 ;; RCS: co error: revision 1.3 already locked by <user>
3571 ;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
3573 ;; We can let these errors be passed up to the user.
3575 ;; Apparent state C ---
3577 ;; 9. File looks locked by calling user and unchanged, but is unregistered.
3579 ;; As case 5.
3581 ;; 10. File looks locked by calling user and unchanged, but is actually not
3582 ;; locked.
3584 ;; Potential cause: a self-race in window U, or by the revert's
3585 ;; landing during window X of some other user's steal-lock or window S
3586 ;; of another user's revert.
3588 ;; RCS: succeeds, refreshing the file from the identical version in
3589 ;; the master.
3590 ;; SCCS: fails with error ut4 (p file nonexistent).
3592 ;; Either of these consequences is acceptable.
3594 ;; 11. File is locked by calling user. It looks unchanged, but is actually
3595 ;; changed.
3597 ;; Potential cause: the file would have to be touched by a self-race
3598 ;; during window Q.
3600 ;; The revert will succeed, removing whatever changes came with
3601 ;; the touch. It is theoretically possible that work could be lost.
3603 ;; 12. File looks like it's locked by the calling user and unchanged, but
3604 ;; it's actually locked by someone else.
3606 ;; Potential cause: a steal-lock in window V.
3608 ;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
3609 ;; SCCS: fails with error un2
3611 ;; We can pass these errors up to the user.
3613 ;; Apparent state D ---
3615 ;; 13. File looks like it's locked by the calling user and changed, but it's
3616 ;; actually unregistered.
3618 ;; Potential cause: master file got nuked during window P.
3620 ;; RCS: Prior to version 5.6.4, checks in the user's version as an
3621 ;; initial delta. From 5.6.4 onwards, VC uses the new ci -j
3622 ;; option, failing with message "no such file or directory".
3623 ;; SCCS: will fail with error ut4.
3625 ;; This case is kind of nasty. Under RCS prior to version 5.6.4,
3626 ;; VC may fail to detect the loss of previous version information.
3628 ;; 14. File looks like it's locked by the calling user and changed, but it's
3629 ;; actually unlocked.
3631 ;; Potential cause: self-race in window V, or the checkin happening
3632 ;; during the window X of someone else's steal-lock or window S of
3633 ;; someone else's revert.
3635 ;; RCS: ci will fail with "no lock set by <user>".
3636 ;; SCCS: delta will fail with error ut4.
3638 ;; 15. File looks like it's locked by the calling user and changed, but it's
3639 ;; actually locked by the calling user and unchanged.
3641 ;; Potential cause: another self-race --- a whole checkin/checkout
3642 ;; sequence by the calling user would have to land in window R.
3644 ;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
3645 ;; RCS: reverts to the file state as of the second user's checkin, leaving
3646 ;; the file unlocked.
3648 ;; It is theoretically possible that work could be lost under RCS.
3650 ;; 16. File looks like it's locked by the calling user and changed, but it's
3651 ;; actually locked by a different user.
3653 ;; RCS: ci error: no lock set by <user>
3654 ;; SCCS: unget will fail with error un2
3656 ;; We can pass these errors up to the user.
3658 ;; Apparent state E ---
3660 ;; 17. File looks like it's locked by some other user, but it's actually
3661 ;; unregistered.
3663 ;; As case 13.
3665 ;; 18. File looks like it's locked by some other user, but it's actually
3666 ;; unlocked.
3668 ;; Potential cause: someone released a lock during window W.
3670 ;; RCS: The calling user will get the lock on the file.
3671 ;; SCCS: unget -n will fail with cm4.
3673 ;; Either of these consequences will be OK.
3675 ;; 19. File looks like it's locked by some other user, but it's actually
3676 ;; locked by the calling user and unchanged.
3678 ;; Potential cause: the other user relinquishing a lock followed by
3679 ;; a self-race, both in window W.
3681 ;; Under both RCS and SCCS, both unlock and lock will succeed, making
3682 ;; the sequence a no-op.
3684 ;; 20. File looks like it's locked by some other user, but it's actually
3685 ;; locked by the calling user and changed.
3687 ;; As case 19.
3689 ;; PROBLEM CASES:
3691 ;; In order of decreasing severity:
3693 ;; Cases 11 and 15 are the only ones that potentially lose work.
3694 ;; They would require a self-race for this to happen.
3696 ;; Case 13 in RCS loses information about previous deltas, retaining
3697 ;; only the information in the current workfile. This can only happen
3698 ;; if the master file gets nuked in window P.
3700 ;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
3701 ;; no change comment in the master. This would require a self-race in
3702 ;; window P or R respectively.
3704 ;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
3706 ;; Unfortunately, it appears to me that no recovery is possible in these
3707 ;; cases. They don't yield error messages, so there's no way to tell that
3708 ;; a race condition has occurred.
3710 ;; All other cases don't change either the workfile or the master, and
3711 ;; trigger command errors which the user will see.
3713 ;; Thus, there is no explicit recovery code.
3715 ;; arch-tag: ca82c1de-3091-4e26-af92-460abc6213a6
3716 ;;; vc.el ends here