1 ;;; vc.el --- drive a version-control system from within Emacs
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: FSF (see below for full credits)
7 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
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 3, or (at your option)
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., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
31 ;; VC was initially designed and implemented by Eric S. Raymond
32 ;; <esr@thyrsus.com> in 1992. Over the years, many other people have
33 ;; contributed substantial amounts of work to VC. These include:
35 ;; Per Cederqvist <ceder@lysator.liu.se>
36 ;; Paul Eggert <eggert@twinsun.com>
37 ;; Sebastian Kremer <sk@thp.uni-koeln.de>
38 ;; Martin Lorentzson <martinl@gnu.org>
39 ;; Dave Love <fx@gnu.org>
40 ;; Stefan Monnier <monnier@cs.yale.edu>
41 ;; J.D. Smith <jdsmith@alum.mit.edu>
42 ;; Andre Spiegel <spiegel@gnu.org>
43 ;; Richard Stallman <rms@gnu.org>
44 ;; Thien-Thi Nguyen <ttn@gnu.org>
46 ;; In July 2007 ESR returned and redesigned the mode to cope better
47 ;; with modern version-control systems that do commits by fileset
48 ;; rather than per individual file.
50 ;; Features in the new version:
51 ;; * Key commands (vc-next-action = C-x v v, vc-print-log = C-x v l, vc-revert
52 ;; = C-x v u, vc-rollback = C-x v c, vc-diff = C-x v =, vc-update = C-x v +)
53 ;; now operate on filesets rather than individual files.
54 ;; * The fileset for a command is either (a) all marked files in VC-dired
55 ;; mode, (b) the currently visited file if it's under version control,
56 ;; or (c) the current directory if the visited buffer is not under
57 ;; version control and a wildcarding-enable flag has been set.
59 ;; If you maintain a client of the mode or customize it in your .emacs,
60 ;; note that some backend functions which formerly took single file arguments
61 ;; now take a list of files. These include: register, checkin, print-log,
62 ;; rollback, and diff.
66 ;; This mode is fully documented in the Emacs user's manual.
68 ;; Supported version-control systems presently include CVS, RCS, GNU
69 ;; Arch, Subversion, Bzr, Git, Mercurial, Meta-CVS, Monotone and SCCS
70 ;; (or its free replacement, CSSC).
72 ;; Some features will not work with old RCS versions. Where
73 ;; appropriate, VC finds out which version you have, and allows or
74 ;; disallows those features (stealing locks, for example, works only
75 ;; from 5.6.2 onwards).
76 ;; Even initial checkins will fail if your RCS version is so old that ci
77 ;; doesn't understand -t-; this has been known to happen to people running
80 ;; You can support the RCS -x option by customizing vc-rcs-master-templates.
82 ;; Proper function of the SCCS diff commands requires the shellscript vcdiff
83 ;; to be installed somewhere on Emacs's path for executables.
85 ;; If your site uses the ChangeLog convention supported by Emacs, the
86 ;; function `log-edit-comment-to-change-log' could prove a useful checkin hook,
87 ;; although you might prefer to use C-c C-a (i.e. `log-edit-insert-changelog')
88 ;; from the commit buffer instead or to set `log-edit-setup-invert'.
90 ;; The vc code maintains some internal state in order to reduce expensive
91 ;; version-control operations to a minimum. Some names are only computed
92 ;; once. If you perform version control operations with the backend while
93 ;; vc's back is turned, or move/rename master files while vc is running,
94 ;; vc may get seriously confused. Don't do these things!
96 ;; Developer's notes on some concurrency issues are included at the end of
99 ;; ADDING SUPPORT FOR OTHER BACKENDS
101 ;; VC can use arbitrary version control systems as a backend. To add
102 ;; support for a new backend named SYS, write a library vc-sys.el that
103 ;; contains functions of the form `vc-sys-...' (note that SYS is in lower
104 ;; case for the function and library names). VC will use that library if
105 ;; you put the symbol SYS somewhere into the list of
106 ;; `vc-handled-backends'. Then, for example, if `vc-sys-registered'
107 ;; returns non-nil for a file, all SYS-specific versions of VC commands
108 ;; will be available for that file.
110 ;; VC keeps some per-file information in the form of properties (see
111 ;; vc-file-set/getprop in vc-hooks.el). The backend-specific functions
112 ;; do not generally need to be aware of these properties. For example,
113 ;; `vc-sys-working-revision' should compute the working revision and
114 ;; return it; it should not look it up in the property, and it needn't
115 ;; store it there either. However, if a backend-specific function does
116 ;; store a value in a property, that value takes precedence over any
117 ;; value that the generic code might want to set (check for uses of
118 ;; the macro `with-vc-properties' in vc.el).
120 ;; In the list of functions below, each identifier needs to be prepended
121 ;; with `vc-sys-'. Some of the functions are mandatory (marked with a
122 ;; `*'), others are optional (`-').
124 ;; BACKEND PROPERTIES
126 ;; * revision-granularity
128 ;; Takes no arguments. Returns either 'file or 'repository. Backends
129 ;; that return 'file have per-file revision numbering; backends
130 ;; that return 'repository have per-repository revision numbering,
131 ;; so a revision level implicitly identifies a changeset
133 ;; STATE-QUERYING FUNCTIONS
135 ;; * registered (file)
137 ;; Return non-nil if FILE is registered in this backend. Both this
138 ;; function as well as `state' should be careful to fail gracefully
139 ;; in the event that the backend executable is absent. It is
140 ;; preferable that this function's body is autoloaded, that way only
141 ;; calling vc-registered does not cause the backend to be loaded
142 ;; (all the vc-FOO-registered functions are called to try to find
143 ;; the controlling backend for FILE.
147 ;; Return the current version control state of FILE. For a list of
148 ;; possible values, see `vc-state'. This function should do a full and
149 ;; reliable state computation; it is usually called immediately after
150 ;; C-x v v. If you want to use a faster heuristic when visiting a
151 ;; file, put that into `state-heuristic' below.
153 ;; - state-heuristic (file)
155 ;; If provided, this function is used to estimate the version control
156 ;; state of FILE at visiting time. It should be considerably faster
157 ;; than the implementation of `state'. For a list of possible values,
158 ;; see the doc string of `vc-state'.
162 ;; If provided, this function is used to find the version control
163 ;; state of as many files as possible in DIR, and all subdirecties
164 ;; of DIR, in a fast way; it is used to avoid expensive indivitual
165 ;; vc-state calls. The function should not return anything, but
166 ;; rather store the files' states into the corresponding properties.
167 ;; Two properties are required: `vc-backend' and `vc-state'. (Note:
168 ;; in older versions this method was not required to recurse into
171 ;; * working-revision (file)
173 ;; Return the working revision of FILE. This is the revision fetched
174 ;; by the last checkout or upate, not necessarily the same thing as the
175 ;; head or tip revision. Should return "0" for a file added but not yet
178 ;; - latest-on-branch-p (file)
180 ;; Return non-nil if the working revision of FILE is the latest revision
181 ;; on its branch (many VCSes call this the 'tip' or 'head' revision).
182 ;; The default implementation always returns t, which means that
183 ;; working with non-current revisions is not supported by default.
185 ;; * checkout-model (file)
187 ;; Indicate whether FILE needs to be "checked out" before it can be
188 ;; edited. See `vc-checkout-model' for a list of possible values.
190 ;; - workfile-unchanged-p (file)
192 ;; Return non-nil if FILE is unchanged from the working revision.
193 ;; This function should do a brief comparison of FILE's contents
194 ;; with those of the repository master of the working revision. If
195 ;; the backend does not have such a brief-comparison feature, the
196 ;; default implementation of this function can be used, which
197 ;; delegates to a full vc-BACKEND-diff. (Note that vc-BACKEND-diff
198 ;; must not run asynchronously in this case, see variable
199 ;; `vc-disable-async-diff'.)
201 ;; - mode-line-string (file)
203 ;; If provided, this function should return the VC-specific mode
204 ;; line string for FILE. The returned string should have a
205 ;; `help-echo' property which is the text to be displayed as a
206 ;; tooltip when the mouse hovers over the VC entry on the mode-line.
207 ;; The default implementation deals well with all states that
208 ;; `vc-state' can return.
210 ;; - dired-state-info (file)
212 ;; Translate the `vc-state' property of FILE into a string that can be
213 ;; used in a vc-dired buffer. The default implementation deals well
214 ;; with all states that `vc-state' can return.
216 ;; STATE-CHANGING FUNCTIONS
218 ;; * create-repo (backend)
220 ;; Create an empty repository in the current directory and initialize
221 ;; it so VC mode can add files to it. For file-oriented systems, this
222 ;; need do no more than create a subdirectory with the right name.
224 ;; * register (files &optional rev comment)
226 ;; Register FILES in this backend. Optionally, an initial revision REV
227 ;; and an initial description of the file, COMMENT, may be specified,
228 ;; but it is not guaranteed that the backend will do anything with this.
229 ;; The implementation should pass the value of vc-register-switches
230 ;; to the backend command. (Note: in older versions of VC, this
231 ;; command took a single file argument and not a list.)
233 ;; - init-revision (file)
235 ;; The initial revision to use when registering FILE if one is not
236 ;; specified by the user. If not provided, the variable
237 ;; vc-default-init-revision is used instead.
239 ;; - responsible-p (file)
241 ;; Return non-nil if this backend considers itself "responsible" for
242 ;; FILE, which can also be a directory. This function is used to find
243 ;; out what backend to use for registration of new files and for things
244 ;; like change log generation. The default implementation always
247 ;; - could-register (file)
249 ;; Return non-nil if FILE could be registered under this backend. The
250 ;; default implementation always returns t.
252 ;; - receive-file (file rev)
254 ;; Let this backend "receive" a file that is already registered under
255 ;; another backend. The default implementation simply calls `register'
256 ;; for FILE, but it can be overridden to do something more specific,
257 ;; e.g. keep revision numbers consistent or choose editing modes for
258 ;; FILE that resemble those of the other backend.
260 ;; - unregister (file)
262 ;; Unregister FILE from this backend. This is only needed if this
263 ;; backend may be used as a "more local" backend for temporary editing.
265 ;; * checkin (files rev comment)
267 ;; Commit changes in FILES to this backend. If REV is non-nil, that
268 ;; should become the new revision number (not all backends do
269 ;; anything with it). COMMENT is used as a check-in comment. The
270 ;; implementation should pass the value of vc-checkin-switches to
271 ;; the backend command. (Note: in older versions of VC, this
272 ;; command took a single file argument and not a list.)
274 ;; * find-revision (file rev buffer)
276 ;; Fetch revision REV of file FILE and put it into BUFFER.
277 ;; If REV is the empty string, fetch the head of the trunk.
278 ;; The implementation should pass the value of vc-checkout-switches
279 ;; to the backend command.
281 ;; * checkout (file &optional editable rev)
283 ;; Check out revision REV of FILE into the working area. If EDITABLE
284 ;; is non-nil, FILE should be writable by the user and if locking is
285 ;; used for FILE, a lock should also be set. If REV is non-nil, that
286 ;; is the revision to check out (default is the working revision).
287 ;; If REV is t, that means to check out the head of the current branch;
288 ;; if it is the empty string, check out the head of the trunk.
289 ;; The implementation should pass the value of vc-checkout-switches
290 ;; to the backend command.
292 ;; * revert (file &optional contents-done)
294 ;; Revert FILE back to the working revision. If optional
295 ;; arg CONTENTS-DONE is non-nil, then the contents of FILE have
296 ;; already been reverted from a version backup, and this function
297 ;; only needs to update the status of FILE within the backend.
299 ;; - rollback (files)
301 ;; Remove the tip revision of each of FILES from the repository. If
302 ;; this function is not provided, trying to cancel a revision is
303 ;; caught as an error. (Most backends don't provide it.) (Also
304 ;; note that older versions of this backend command were called
305 ;; 'cancel-version' and took a single file arg, not a list of
308 ;; - merge (file rev1 rev2)
310 ;; Merge the changes between REV1 and REV2 into the current working file.
312 ;; - merge-news (file)
314 ;; Merge recent changes from the current branch into FILE.
316 ;; - steal-lock (file &optional revision)
318 ;; Steal any lock on the working revision of FILE, or on REVISION if
319 ;; that is provided. This function is only needed if locking is
320 ;; used for files under this backend, and if files can indeed be
321 ;; locked by other users.
323 ;; - modify-change-comment (files rev comment)
325 ;; Modify the change comments associated with the files at the
326 ;; given revision. This is optional, many backends do not support it.
330 ;; * print-log (files &optional buffer)
332 ;; Insert the revision log for FILES into BUFFER, or the *vc* buffer
333 ;; if BUFFER is nil. (Note: older versions of this function expected
334 ;; only a single file argument.)
336 ;; - log-view-mode ()
338 ;; Mode to use for the output of print-log. This defaults to
339 ;; `log-view-mode' and is expected to be changed (if at all) to a derived
340 ;; mode of `log-view-mode'.
342 ;; - show-log-entry (revision)
344 ;; If provided, search the log entry for REVISION in the current buffer,
345 ;; and make sure it is displayed in the buffer's window. The default
346 ;; implementation of this function works for RCS-style logs.
350 ;; Remove all non-comment information from the output of print-log.
352 ;; - logentry-check ()
354 ;; If defined, this function is run to find out whether the user
355 ;; entered a valid log entry for check-in. The log entry is in the
356 ;; current buffer, and if it is not a valid one, the function should
359 ;; - comment-history (file)
361 ;; Return a string containing all log entries that were made for FILE.
362 ;; This is used for transferring a file from one backend to another,
363 ;; retaining comment information. The default implementation of this
364 ;; function does this by calling print-log and then wash-log, and
365 ;; returning the resulting buffer contents as a string.
367 ;; - update-changelog (files)
369 ;; Using recent log entries, create ChangeLog entries for FILES, or for
370 ;; all files at or below the default-directory if FILES is nil. The
371 ;; default implementation runs rcs2log, which handles RCS- and
374 ;; * diff (files &optional rev1 rev2 buffer)
376 ;; Insert the diff for FILE into BUFFER, or the *vc-diff* buffer if
377 ;; BUFFER is nil. If REV1 and REV2 are non-nil, report differences
378 ;; from REV1 to REV2. If REV1 is nil, use the working revision (as
379 ;; found in the repository) as the older revision; if REV2 is nil,
380 ;; use the current working-copy contents as the newer revision. This
381 ;; function should pass the value of (vc-switches BACKEND 'diff) to
382 ;; the backend command. It should return a status of either 0 (no
383 ;; differences found), or 1 (either non-empty diff or the diff is
384 ;; run asynchronously).
386 ;; - revision-completion-table (files)
388 ;; Return a completion table for existing revisions of FILES.
389 ;; The default is to not use any completion table.
391 ;; - annotate-command (file buf &optional rev)
393 ;; If this function is provided, it should produce an annotated display
394 ;; of FILE in BUF, relative to revision REV. Annotation means each line
395 ;; of FILE displayed is prefixed with version information associated with
396 ;; its addition (deleted lines leave no history) and that the text of the
397 ;; file is fontified according to age.
399 ;; - annotate-time ()
401 ;; Only required if `annotate-command' is defined for the backend.
402 ;; Return the time of the next line of annotation at or after point,
403 ;; as a floating point fractional number of days. The helper
404 ;; function `vc-annotate-convert-time' may be useful for converting
405 ;; multi-part times as returned by `current-time' and `encode-time'
406 ;; to this format. Return nil if no more lines of annotation appear
407 ;; in the buffer. You can safely assume that point is placed at the
408 ;; beginning of each line, starting at `point-min'. The buffer that
409 ;; point is placed in is the Annotate output, as defined by the
410 ;; relevant backend. This function also affects how much of the line
411 ;; is fontified; where it leaves point is where fontification begins.
413 ;; - annotate-current-time ()
415 ;; Only required if `annotate-command' is defined for the backend,
416 ;; AND you'd like the current time considered to be anything besides
417 ;; (vc-annotate-convert-time (current-time)) -- i.e. the current
418 ;; time with hours, minutes, and seconds included. Probably safe to
419 ;; ignore. Return the current-time, in units of fractional days.
421 ;; - annotate-extract-revision-at-line ()
423 ;; Only required if `annotate-command' is defined for the backend.
424 ;; Invoked from a buffer in vc-annotate-mode, return the revision
425 ;; corresponding to the current line, or nil if there is no revision
426 ;; corresponding to the current line.
430 ;; - create-snapshot (dir name branchp)
432 ;; Take a snapshot of the current state of files under DIR and name it
433 ;; NAME. This should make sure that files are up-to-date before
434 ;; proceeding with the action. DIR can also be a file and if BRANCHP
435 ;; is specified, NAME should be created as a branch and DIR should be
436 ;; checked out under this new branch. The default implementation does
437 ;; not support branches but does a sanity check, a tree traversal and
438 ;; for each file calls `assign-name'.
440 ;; - assign-name (file name)
442 ;; Give name NAME to the working revision of FILE, assuming it is
443 ;; up-to-date. Only used by the default version of `create-snapshot'.
445 ;; - retrieve-snapshot (dir name update)
447 ;; Retrieve a named snapshot of all registered files at or below DIR.
448 ;; If UPDATE is non-nil, then update buffers of any files in the
449 ;; snapshot that are currently visited. The default implementation
450 ;; does a sanity check whether there aren't any uncommitted changes at
451 ;; or below DIR, and then performs a tree walk, using the `checkout'
452 ;; function to retrieve the corresponding revisions.
456 ;; - make-version-backups-p (file)
458 ;; Return non-nil if unmodified repository revisions of FILE should be
459 ;; backed up locally. If this is done, VC can perform `diff' and
460 ;; `revert' operations itself, without calling the backend system. The
461 ;; default implementation always returns nil.
463 ;; - repository-hostname (dirname)
465 ;; Return the hostname that the backend will have to contact
466 ;; in order to operate on a file in DIRNAME. If the return value
467 ;; is nil, it means that the repository is local.
468 ;; This function is used in `vc-stay-local-p' which backends can use
469 ;; for their convenience.
471 ;; - previous-revision (file rev)
473 ;; Return the revision number that precedes REV for FILE, or nil if no such
476 ;; - next-revision (file rev)
478 ;; Return the revision number that follows REV for FILE, or nil if no such
481 ;; - check-headers ()
483 ;; Return non-nil if the current buffer contains any version headers.
485 ;; - clear-headers ()
487 ;; In the current buffer, reset all version headers to their unexpanded
488 ;; form. This function should be provided if the state-querying code
489 ;; for this backend uses the version headers to determine the state of
490 ;; a file. This function will then be called whenever VC changes the
491 ;; version control state in such a way that the headers would give
492 ;; wrong information.
494 ;; - delete-file (file)
496 ;; Delete FILE and mark it as deleted in the repository. If this
497 ;; function is not provided, the command `vc-delete-file' will
500 ;; - rename-file (old new)
502 ;; Rename file OLD to NEW, both in the working area and in the
503 ;; repository. If this function is not provided, the renaming
504 ;; will be done by (vc-delete-file old) and (vc-register new).
506 ;; - find-file-hook ()
508 ;; Operation called in current buffer when opening a file. This can
509 ;; be used by the backend to setup some local variables it might need.
511 ;; - find-file-not-found-hook ()
513 ;; Operation called in current buffer when opening a non-existing file.
514 ;; By default, this asks the user if she wants to check out the file.
518 ;; Return a menu keymap, the items in the keymap will appear at the
519 ;; end of the Version Control menu. The goal is to allow backends
520 ;; to specify extra menu items that appear in the VC menu. This way
521 ;; you can provide menu entries for functionality that is specific
522 ;; to your backend and which does not map to any of the VC generic
532 (require 'dired
) ; for dired-map-over-marks macro
533 (require 'dired-aux
)) ; for dired-kill-{line,tree}
535 (if (not (assoc 'vc-parent-buffer minor-mode-alist
))
536 (setq minor-mode-alist
537 (cons '(vc-parent-buffer vc-parent-buffer-name
)
540 ;; General customization
543 "Version-control system in Emacs."
546 (defcustom vc-suppress-confirm nil
547 "If non-nil, treat user as expert; suppress yes-no prompts on some things."
551 (defcustom vc-delete-logbuf-window t
552 "If non-nil, delete the *VC-log* buffer and window after each logical action.
553 If nil, bury that buffer instead.
554 This is most useful if you have multiple windows on a frame and would like to
555 preserve the setting."
559 (defcustom vc-initial-comment nil
560 "If non-nil, prompt for initial comment when a file is registered."
564 (defcustom vc-default-init-revision
"1.1"
565 "A string used as the default revision number when a new file is registered.
566 This can be overridden by giving a prefix argument to \\[vc-register]. This
567 can also be overridden by a particular VC backend."
572 (defcustom vc-command-messages nil
573 "If non-nil, display run messages from back-end commands."
577 (defcustom vc-checkin-switches nil
578 "A string or list of strings specifying extra switches for checkin.
579 These are passed to the checkin program by \\[vc-checkin]."
580 :type
'(choice (const :tag
"None" nil
)
581 (string :tag
"Argument String")
582 (repeat :tag
"Argument List"
587 (defcustom vc-checkout-switches nil
588 "A string or list of strings specifying extra switches for checkout.
589 These are passed to the checkout program by \\[vc-checkout]."
590 :type
'(choice (const :tag
"None" nil
)
591 (string :tag
"Argument String")
592 (repeat :tag
"Argument List"
597 (defcustom vc-register-switches nil
598 "A string or list of strings; extra switches for registering a file.
599 These are passed to the checkin program by \\[vc-register]."
600 :type
'(choice (const :tag
"None" nil
)
601 (string :tag
"Argument String")
602 (repeat :tag
"Argument List"
607 (defcustom vc-dired-listing-switches
"-al"
608 "Switches passed to `ls' for vc-dired. MUST contain the `l' option."
613 (defcustom vc-dired-recurse t
614 "If non-nil, show directory trees recursively in VC Dired."
619 (defcustom vc-dired-terse-display t
620 "If non-nil, show only locked or locally modified files in VC Dired."
625 (defcustom vc-diff-switches nil
626 "A string or list of strings specifying switches for diff under VC.
627 When running diff under a given BACKEND, VC concatenates the values of
628 `diff-switches', `vc-diff-switches', and `vc-BACKEND-diff-switches' to
629 get the switches for that command. Thus, `vc-diff-switches' should
630 contain switches that are specific to version control, but not
631 specific to any particular backend."
632 :type
'(choice (const :tag
"None" nil
)
633 (string :tag
"Argument String")
634 (repeat :tag
"Argument List"
640 (defcustom vc-diff-knows-L nil
641 "*Indicates whether diff understands the -L option.
642 The value is either `yes', `no', or nil. If it is nil, VC tries
643 to use -L and sets this variable to remember whether it worked."
644 :type
'(choice (const :tag
"Work out" nil
) (const yes
) (const no
))
647 (defcustom vc-allow-async-revert nil
648 "Specifies whether the diff during \\[vc-revert] may be asynchronous.
649 Enabling this option means that you can confirm a revert operation even
650 if the local changes in the file have not been found and displayed yet."
651 :type
'(choice (const :tag
"No" nil
)
652 (const :tag
"Yes" t
))
657 (defcustom vc-checkout-hook nil
658 "Normal hook (list of functions) run after checking out a file.
664 (defcustom vc-annotate-display-mode
'fullscale
665 "Which mode to color the output of \\[vc-annotate] with by default."
666 :type
'(choice (const :tag
"By Color Map Range" nil
)
667 (const :tag
"Scale to Oldest" scale
)
668 (const :tag
"Scale Oldest->Newest" fullscale
)
669 (number :tag
"Specify Fractional Number of Days"
674 (defcustom vc-checkin-hook nil
675 "Normal hook (list of functions) run after commit or file checkin.
676 See also `log-edit-done-hook'."
678 :options
'(log-edit-comment-to-change-log)
682 (defcustom vc-before-checkin-hook nil
683 "Normal hook (list of functions) run before a commit or a file checkin.
688 (defcustom vc-logentry-check-hook nil
689 "Normal hook run by `vc-backend-logentry-check'.
690 Use this to impose your own rules on the entry in addition to any the
691 version control backend imposes itself."
695 ;; Annotate customization
696 (defcustom vc-annotate-color-map
697 (if (and (tty-display-color-p) (<= (display-color-cells) 8))
698 ;; A custom sorted TTY colormap
704 (string-equal (car x
) "white")
705 (string-equal (car x
) "black") ))
710 ((or (string-equal a
"red") (string-equal b
"blue")) t
)
711 ((or (string-equal b
"red") (string-equal a
"blue")) nil
)
712 ((string-equal a
"yellow") t
)
713 ((string-equal b
"yellow") nil
)
714 ((string-equal a
"cyan") t
)
715 ((string-equal b
"cyan") nil
)
716 ((string-equal a
"green") t
)
717 ((string-equal b
"green") nil
)
718 ((string-equal a
"magenta") t
)
719 ((string-equal b
"magenta") nil
)
720 (t (string< a b
))))))
722 (delta (/ (- 360. date
) (1- (length colors
)))))
726 (setq date
(+ date delta
)))) colors
))
727 ;; Normal colormap: hue stepped from 0-240deg, value=1., saturation=0.75
746 "Association list of age versus color, for \\[vc-annotate].
747 Ages are given in units of fractional days. Default is eighteen
748 steps using a twenty day increment, from red to blue. For TTY
749 displays with 8 or fewer colors, the default is red to blue with
750 all other colors between (excluding black and white)."
754 (defcustom vc-annotate-very-old-color
"#3F3FFF"
755 "Color for lines older than the current color range in \\[vc-annotate]]."
759 (defcustom vc-annotate-background
"black"
760 "Background color for \\[vc-annotate].
761 Default color is used if nil."
765 (defcustom vc-annotate-menu-elements
'(2 0.5 0.1 0.01)
766 "Menu elements for the mode-specific menu of VC-Annotate mode.
767 List of factors, used to expand/compress the time scale. See `vc-annotate'."
768 :type
'(repeat number
)
771 (defvar vc-annotate-mode-map
772 (let ((m (make-sparse-keymap)))
773 (define-key m
"A" 'vc-annotate-revision-previous-to-line
)
774 (define-key m
"D" 'vc-annotate-show-diff-revision-at-line
)
775 (define-key m
"J" 'vc-annotate-revision-at-line
)
776 (define-key m
"L" 'vc-annotate-show-log-revision-at-line
)
777 (define-key m
"N" 'vc-annotate-next-revision
)
778 (define-key m
"P" 'vc-annotate-prev-revision
)
779 (define-key m
"W" 'vc-annotate-working-revision
)
780 (define-key m
"V" 'vc-annotate-toggle-annotation-visibility
)
782 "Local keymap used for VC-Annotate mode.")
784 ;; Header-insertion hair
786 (defcustom vc-static-header-alist
788 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
789 "*Associate static header string templates with file types.
790 A \%s in the template is replaced with the first string associated with
791 the file's version control type in `vc-header-alist'."
792 :type
'(repeat (cons :format
"%v"
793 (regexp :tag
"File Type")
794 (string :tag
"Header String")))
797 (defcustom vc-comment-alist
798 '((nroff-mode ".\\\"" ""))
799 "*Special comment delimiters for generating VC headers.
800 Add an entry in this list if you need to override the normal `comment-start'
801 and `comment-end' variables. This will only be necessary if the mode language
802 is sensitive to blank lines."
803 :type
'(repeat (list :format
"%v"
805 (string :tag
"Comment Start")
806 (string :tag
"Comment End")))
809 (defcustom vc-checkout-carefully
(= (user-uid) 0)
810 "*Non-nil means be extra-careful in checkout.
811 Verify that the file really is not locked
812 and that its contents match what the master file says."
815 (make-obsolete-variable 'vc-checkout-carefully
816 "the corresponding checks are always done now."
820 ;; Variables the user doesn't need to know about.
821 (defvar vc-log-operation nil
)
822 (defvar vc-log-after-operation-hook nil
)
824 ;; In a log entry buffer, this is a local variable
825 ;; that points to the buffer for which it was made
826 ;; (either a file, or a VC dired buffer).
827 (defvar vc-parent-buffer nil
)
828 (put 'vc-parent-buffer
'permanent-local t
)
829 (defvar vc-parent-buffer-name nil
)
830 (put 'vc-parent-buffer-name
'permanent-local t
)
832 (defvar vc-disable-async-diff nil
833 "VC sets this to t locally to disable some async diff operations.
834 Backends that offer asynchronous diffs should respect this variable
835 in their implementation of vc-BACKEND-diff.")
837 (defvar vc-log-fileset
)
838 (defvar vc-log-revision
)
840 (defvar vc-dired-mode nil
)
841 (make-variable-buffer-local 'vc-dired-mode
)
843 ;; File property caching
845 (defun vc-clear-context ()
846 "Clear all cached file properties."
848 (fillarray vc-file-prop-obarray
0))
850 (defmacro with-vc-properties
(files form settings
)
851 "Execute FORM, then maybe set per-file properties for FILES.
852 SETTINGS is an association list of property/value pairs. After
853 executing FORM, set those properties from SETTINGS that have not yet
854 been updated to their corresponding values."
856 `(let ((vc-touched-properties (list t
)))
858 (dolist (file ,files
)
859 (dolist (setting ,settings
)
860 (let ((property (car setting
)))
861 (unless (memq property vc-touched-properties
)
862 (put (intern file vc-file-prop-obarray
)
863 property
(cdr setting
))))))))
865 ;; Two macros for elisp programming
868 (defmacro with-vc-file
(file comment
&rest body
)
869 "Check out a writable copy of FILE if necessary, then execute BODY.
870 Check in FILE with COMMENT (a string) after BODY has been executed.
871 FILE is passed through `expand-file-name'; BODY executed within
872 `save-excursion'. If FILE is not under version control, or you are
873 using a locking version-control system and the file is locked by
874 somebody else, signal error."
875 (declare (debug t
) (indent 2))
876 (let ((filevar (make-symbol "file")))
877 `(let ((,filevar
(expand-file-name ,file
)))
878 (or (vc-backend ,filevar
)
879 (error "File not under version control: `%s'" file
))
880 (unless (vc-editable-p ,filevar
)
881 (let ((state (vc-state ,filevar
)))
883 (error "`%s' is locking `%s'" state
,filevar
)
884 (vc-checkout ,filevar t
))))
887 (vc-checkin (list ,filevar
) nil
,comment
))))
890 (defmacro edit-vc-file
(file comment
&rest body
)
891 "Edit FILE under version control, executing body.
892 Checkin with COMMENT after executing BODY.
893 This macro uses `with-vc-file', passing args to it.
894 However, before executing BODY, find FILE, and after BODY, save buffer."
895 (declare (debug t
) (indent 2))
896 (let ((filevar (make-symbol "file")))
897 `(let ((,filevar
(expand-file-name ,file
)))
900 (set-buffer (find-file-noselect ,filevar
))
904 ;; Common command execution logic to be used by backends
906 (defun vc-process-filter (p s
)
907 "An alternative output filter for async process P.
908 One difference with the default filter is that this inserts S after markers.
909 Another is that undo information is not kept."
910 (with-current-buffer (process-buffer p
)
912 (let ((buffer-undo-list t
)
913 (inhibit-read-only t
))
914 (goto-char (process-mark p
))
916 (set-marker (process-mark p
) (point))))))
918 (defun vc-setup-buffer (&optional buf
)
919 "Prepare BUF for executing a VC command and make it current.
920 BUF defaults to \"*vc*\", can be a string and will be created if necessary."
921 (unless buf
(setq buf
"*vc*"))
922 (let ((camefrom (current-buffer))
923 (olddir default-directory
))
924 (set-buffer (get-buffer-create buf
))
925 (kill-all-local-variables)
926 (set (make-local-variable 'vc-parent-buffer
) camefrom
)
927 (set (make-local-variable 'vc-parent-buffer-name
)
928 (concat " from " (buffer-name camefrom
)))
929 (setq default-directory olddir
)
930 (let ((buffer-undo-list t
)
931 (inhibit-read-only t
))
934 (defvar vc-sentinel-movepoint
) ;Dynamically scoped.
936 (defun vc-process-sentinel (p s
)
937 (let ((previous (process-get p
'vc-previous-sentinel
)))
938 (if previous
(funcall previous p s
))
939 (with-current-buffer (process-buffer p
)
940 (let (vc-sentinel-movepoint)
941 ;; Normally, we want async code such as sentinels to not move point.
943 (goto-char (process-mark p
))
944 (let ((cmds (process-get p
'vc-sentinel-commands
)))
945 (process-put p
'vc-postprocess nil
)
947 ;; Each sentinel may move point and the next one should be run
948 ;; at that new point. We could get the same result by having
949 ;; each sentinel read&set process-mark, but since `cmd' needs
950 ;; to work both for async and sync processes, this would be
951 ;; difficult to achieve.
952 (vc-exec-after cmd
))))
953 ;; But sometimes the sentinels really want to move point.
954 (if vc-sentinel-movepoint
955 (let ((win (get-buffer-window (current-buffer) 0)))
957 (goto-char vc-sentinel-movepoint
)
958 (with-selected-window win
959 (goto-char vc-sentinel-movepoint
)))))))))
961 (defun vc-exec-after (code)
962 "Eval CODE when the current buffer's process is done.
963 If the current buffer has no process, just evaluate CODE.
964 Else, add CODE to the process' sentinel."
965 (let ((proc (get-buffer-process (current-buffer))))
967 ;; If there's no background process, just execute the code.
968 ;; We used to explicitly call delete-process on exited processes,
969 ;; but this led to timing problems causing process output to be
970 ;; lost. Terminated processes get deleted automatically
972 ((or (null proc
) (eq (process-status proc
) 'exit
))
973 ;; Make sure we've read the process's output before going further.
974 (if proc
(accept-process-output proc
))
976 ;; If a process is running, add CODE to the sentinel
977 ((eq (process-status proc
) 'run
)
978 (let ((previous (process-sentinel proc
)))
979 (unless (eq previous
'vc-process-sentinel
)
980 (process-put proc
'vc-previous-sentinel previous
))
981 (set-process-sentinel proc
'vc-process-sentinel
))
982 (process-put proc
'vc-sentinel-commands
983 (cons code
(process-get proc
'vc-sentinel-commands
))))
984 (t (error "Unexpected process state"))))
987 (defvar vc-post-command-functions nil
988 "Hook run at the end of `vc-do-command'.
989 Each function is called inside the buffer in which the command was run
990 and is passed 3 arguments: the COMMAND, the FILES and the FLAGS.")
992 (defvar w32-quote-process-args
)
994 (defun vc-delistify (filelist)
995 "Smash a FILELIST into a file list string suitable for info messages."
996 ;; FIXME what about file names with spaces?
997 (if (not filelist
) "." (mapconcat 'identity filelist
" ")))
1000 (defun vc-do-command (buffer okstatus command file-or-list
&rest flags
)
1001 "Execute a VC command, notifying user and checking for errors.
1002 Output from COMMAND goes to BUFFER, or *vc* if BUFFER is nil or the
1003 current buffer if BUFFER is t. If the destination buffer is not
1004 already current, set it up properly and erase it. The command is
1005 considered successful if its exit status does not exceed OKSTATUS (if
1006 OKSTATUS is nil, that means to ignore error status, if it is `async', that
1007 means not to wait for termination of the subprocess; if it is t it means to
1008 ignore all execution errors). FILE-OR-LIST is the name of a working file;
1009 it may be a list of files or be nil (to execute commands that don't expect
1010 a file name or set of files). If an optional list of FLAGS is present,
1011 that is inserted into the command line before the filename."
1012 ;; FIXME: file-relative-name can return a bogus result because
1013 ;; it doesn't look at the actual file-system to see if symlinks
1016 (mapcar (lambda (f) (file-relative-name (expand-file-name f
)))
1017 (if (listp file-or-list
) file-or-list
(list file-or-list
))))
1019 ;; What we're doing here is preparing a version of the command
1020 ;; for display in a debug-progess message. If it's fewer than
1021 ;; 20 characters display the entire command (without trailing
1022 ;; newline). Otherwise display the first 20 followed by an ellipsis.
1023 (concat (if (string= (substring command -
1) "\n")
1024 (substring command
0 -
1)
1027 (vc-delistify (mapcar (lambda (s) (if (> (length s
) 20) (concat (substring s
0 2) "...") s
)) flags
))
1028 " " (vc-delistify files
))))
1029 (save-current-buffer
1030 (unless (or (eq buffer t
)
1031 (and (stringp buffer
)
1032 (string= (buffer-name) buffer
))
1033 (eq buffer
(current-buffer)))
1034 (vc-setup-buffer buffer
))
1035 (let ((squeezed (remq nil flags
))
1036 (inhibit-read-only t
)
1039 (setq squeezed
(nconc squeezed files
)))
1040 (let ((exec-path (append vc-path exec-path
))
1041 ;; Add vc-path to PATH for the execution of this command.
1042 (process-environment
1043 (cons (concat "PATH=" (getenv "PATH")
1045 (mapconcat 'identity vc-path path-separator
))
1046 process-environment
))
1047 (w32-quote-process-args t
))
1048 (if (and (eq okstatus
'async
) (file-remote-p default-directory
))
1049 ;; start-process does not support remote execution
1050 (setq okstatus nil
))
1051 (if (eq okstatus
'async
)
1052 ;; Run asynchronously
1054 (let ((process-connection-type nil
))
1055 (apply 'start-process command
(current-buffer) command
1057 (if vc-command-messages
1058 (message "Running %s in background..." full-command
))
1059 ;;(set-process-sentinel proc (lambda (p msg) (delete-process p)))
1060 (set-process-filter proc
'vc-process-filter
)
1062 `(if vc-command-messages
1063 (message "Running %s in background... done" ',full-command
))))
1065 (if vc-command-messages
1066 (message "Running %s in foreground..." full-command
))
1067 (let ((buffer-undo-list t
))
1068 (setq status
(apply 'process-file command nil t nil squeezed
)))
1069 (when (and (not (eq t okstatus
))
1070 (or (not (integerp status
))
1071 (and okstatus
(< okstatus status
))))
1072 (pop-to-buffer (current-buffer))
1073 (goto-char (point-min))
1074 (shrink-window-if-larger-than-buffer)
1075 (error "Running %s...FAILED (%s)" full-command
1076 (if (integerp status
) (format "status %d" status
) status
))))
1077 ;; We're done. But don't emit a status message if running
1078 ;; asychronously, it would just mislead.
1079 (if (and vc-command-messages
(not (eq okstatus
'async
)))
1080 (message "Running %s...OK = %d" full-command status
)))
1082 `(run-hook-with-args 'vc-post-command-functions
1083 ',command
',file-or-list
',flags
))
1086 (defun vc-position-context (posn)
1087 "Save a bit of the text around POSN in the current buffer.
1088 Used to help us find the corresponding position again later
1089 if markers are destroyed or corrupted."
1090 ;; A lot of this was shamelessly lifted from Sebastian Kremer's
1094 (buffer-substring posn
1095 (min (point-max) (+ posn
100)))))
1097 (defun vc-find-position-by-context (context)
1098 "Return the position of CONTEXT in the current buffer.
1099 If CONTEXT cannot be found, return nil."
1100 (let ((context-string (nth 2 context
)))
1101 (if (equal "" context-string
)
1104 (let ((diff (- (nth 1 context
) (buffer-size))))
1105 (if (< diff
0) (setq diff
(- diff
)))
1106 (goto-char (nth 0 context
))
1107 (if (or (search-forward context-string nil t
)
1108 ;; Can't use search-backward since the match may continue
1110 (progn (goto-char (- (point) diff
(length context-string
)))
1111 ;; goto-char doesn't signal an error at
1112 ;; beginning of buffer like backward-char would
1113 (search-forward context-string nil t
)))
1114 ;; to beginning of OSTRING
1115 (- (point) (length context-string
))))))))
1117 (defun vc-context-matches-p (posn context
)
1118 "Return t if POSN matches CONTEXT, nil otherwise."
1119 (let* ((context-string (nth 2 context
))
1120 (len (length context-string
))
1122 (if (> end
(1+ (buffer-size)))
1124 (string= context-string
(buffer-substring posn end
)))))
1126 (defun vc-buffer-context ()
1127 "Return a list (POINT-CONTEXT MARK-CONTEXT REPARSE).
1128 Used by `vc-restore-buffer-context' to later restore the context."
1129 (let ((point-context (vc-position-context (point)))
1130 ;; Use mark-marker to avoid confusion in transient-mark-mode.
1131 (mark-context (if (eq (marker-buffer (mark-marker)) (current-buffer))
1132 (vc-position-context (mark-marker))))
1133 ;; Make the right thing happen in transient-mark-mode.
1135 ;; The new compilation code does not use compilation-error-list any
1136 ;; more, so the code below is now ineffective and might as well
1137 ;; be disabled. -- Stef
1138 ;; ;; We may want to reparse the compilation buffer after revert
1139 ;; (reparse (and (boundp 'compilation-error-list) ;compile loaded
1140 ;; ;; Construct a list; each elt is nil or a buffer
1141 ;; ;; if that buffer is a compilation output buffer
1142 ;; ;; that contains markers into the current buffer.
1143 ;; (save-current-buffer
1144 ;; (mapcar (lambda (buffer)
1145 ;; (set-buffer buffer)
1146 ;; (let ((errors (or
1147 ;; compilation-old-error-list
1148 ;; compilation-error-list))
1149 ;; (buffer-error-marked-p nil))
1150 ;; (while (and (consp errors)
1151 ;; (not buffer-error-marked-p))
1152 ;; (and (markerp (cdr (car errors)))
1155 ;; (cdr (car errors))))
1156 ;; (setq buffer-error-marked-p t))
1157 ;; (setq errors (cdr errors)))
1158 ;; (if buffer-error-marked-p buffer)))
1159 ;; (buffer-list)))))
1161 (list point-context mark-context reparse
)))
1163 (defun vc-restore-buffer-context (context)
1164 "Restore point/mark, and reparse any affected compilation buffers.
1165 CONTEXT is that which `vc-buffer-context' returns."
1166 (let ((point-context (nth 0 context
))
1167 (mark-context (nth 1 context
))
1168 ;; (reparse (nth 2 context))
1170 ;; The new compilation code does not use compilation-error-list any
1171 ;; more, so the code below is now ineffective and might as well
1172 ;; be disabled. -- Stef
1173 ;; ;; Reparse affected compilation buffers.
1175 ;; (if (car reparse)
1176 ;; (with-current-buffer (car reparse)
1177 ;; (let ((compilation-last-buffer (current-buffer)) ;select buffer
1178 ;; ;; Record the position in the compilation buffer of
1179 ;; ;; the last error next-error went to.
1180 ;; (error-pos (marker-position
1181 ;; (car (car-safe compilation-error-list)))))
1182 ;; ;; Reparse the error messages as far as they were parsed before.
1183 ;; (compile-reinitialize-errors '(4) compilation-parsing-end)
1184 ;; ;; Move the pointer up to find the error we were at before
1185 ;; ;; reparsing. Now next-error should properly go to the next one.
1186 ;; (while (and compilation-error-list
1187 ;; (/= error-pos (car (car compilation-error-list))))
1188 ;; (setq compilation-error-list (cdr compilation-error-list))))))
1189 ;; (setq reparse (cdr reparse)))
1191 ;; if necessary, restore point and mark
1192 (if (not (vc-context-matches-p (point) point-context
))
1193 (let ((new-point (vc-find-position-by-context point-context
)))
1194 (if new-point
(goto-char new-point
))))
1197 (not (vc-context-matches-p (mark) mark-context
))
1198 (let ((new-mark (vc-find-position-by-context mark-context
)))
1199 (if new-mark
(set-mark new-mark
))))))
1201 ;;; Code for deducing what fileset and backend to assume
1203 (defun vc-responsible-backend (file &optional register
)
1204 "Return the name of a backend system that is responsible for FILE.
1205 The optional argument REGISTER means that a backend suitable for
1206 registration should be found.
1208 If REGISTER is nil, then if FILE is already registered, return the
1209 backend of FILE. If FILE is not registered, or a directory, then the
1210 first backend in `vc-handled-backends' that declares itself
1211 responsible for FILE is returned. If no backend declares itself
1212 responsible, return the first backend.
1214 If REGISTER is non-nil, return the first responsible backend under
1215 which FILE is not yet registered. If there is no such backend, return
1216 the first backend under which FILE is not yet registered, but could
1218 (if (not vc-handled-backends
)
1219 (error "No handled backends"))
1220 (or (and (not (file-directory-p file
)) (not register
) (vc-backend file
))
1222 ;; First try: find a responsible backend. If this is for registration,
1223 ;; it must be a backend under which FILE is not yet registered.
1224 (dolist (backend vc-handled-backends
)
1225 (and (or (not register
)
1226 (not (vc-call-backend backend
'registered file
)))
1227 (vc-call-backend backend
'responsible-p file
)
1228 (throw 'found backend
)))
1229 ;; no responsible backend
1231 ;; if this is not for registration, the first backend must do
1232 (car vc-handled-backends
)
1233 ;; for registration, we need to find a new backend that
1234 ;; could register FILE
1235 (dolist (backend vc-handled-backends
)
1236 (and (not (vc-call-backend backend
'registered file
))
1237 (vc-call-backend backend
'could-register file
)
1238 (throw 'found backend
)))
1239 (error "No backend that could register")))))
1241 (defun vc-expand-dirs (file-or-dir-list)
1242 "Expands directories in a file list specification.
1243 Only files already under version control are noticed."
1244 ;; FIXME: Kill this function.
1245 (let ((flattened '()))
1246 (dolist (node file-or-dir-list
)
1248 node
(lambda (f) (if (vc-backend f
) (push f flattened
)))))
1249 (nreverse flattened
)))
1251 (defun vc-deduce-fileset (&optional allow-directory-wildcard allow-unregistered
)
1252 "Deduce a set of files and a backend to which to apply an operation.
1254 If we're in VC-dired mode, the fileset is the list of marked files.
1255 Otherwise, if we're looking at a buffer visiting a version-controlled file,
1256 the fileset is a singleton containing this file.
1257 If neither of these things is true, but ALLOW-DIRECTORY-WILDCARD is on
1258 and we're in a dired buffer, select the current directory.
1259 If none of these conditions is met, but ALLOW_UNREGISTERED is in and the
1260 visited file is not registered, return a singletin fileset containing it.
1261 Otherwise, throw an error."
1262 (cond (vc-dired-mode
1263 (let ((marked (dired-map-over-marks (dired-get-filename) nil
)))
1265 (error "No files have been selected."))
1266 ;; All members of the fileset must have the same backend
1267 (let ((firstbackend (vc-backend (car marked
))))
1268 (dolist (f (cdr marked
))
1269 (unless (eq (vc-backend f
) firstbackend
)
1270 (error "All members of a fileset must be under the same version-control system."))))
1272 ((vc-backend buffer-file-name
)
1273 (list buffer-file-name
))
1274 ((and vc-parent-buffer
(or (buffer-file-name vc-parent-buffer
)
1275 (with-current-buffer vc-parent-buffer
1278 (set-buffer vc-parent-buffer
)
1279 (vc-deduce-fileset)))
1280 ;; This is guarded by an enabling arg so users won't potentially
1281 ;; shoot themselves in the foot by modifying a fileset they can't
1282 ;; verify by eyeball. Allow it for nondestructive commands like
1283 ;; making diffs, or possibly for destructive ones that have
1284 ;; confirmation prompts.
1285 ((and allow-directory-wildcard
1286 ;; I think this is a misfeature. For now, I'll leave it in, but
1287 ;; I'll disable it anywhere else than in dired buffers. --Stef
1288 (and (derived-mode-p 'dired-mode
)
1289 (equal buffer-file-name nil
)
1290 (equal list-buffers-directory default-directory
)))
1292 (message "All version-controlled files below %s selected."
1294 (list default-directory
)))
1295 ((and allow-unregistered
(not (vc-registered buffer-file-name
)))
1296 (list buffer-file-name
))
1297 (t (error "No fileset is available here."))))
1299 (defun vc-ensure-vc-buffer ()
1300 "Make sure that the current buffer visits a version-controlled file."
1302 (set-buffer (find-file-noselect (dired-get-filename)))
1303 (while (and vc-parent-buffer
1304 ;; Avoid infinite looping when vc-parent-buffer and
1305 ;; current buffer are the same buffer.
1306 (not (eq vc-parent-buffer
(current-buffer))))
1307 (set-buffer vc-parent-buffer
))
1308 (if (not buffer-file-name
)
1309 (error "Buffer %s is not associated with a file" (buffer-name))
1310 (if (not (vc-backend buffer-file-name
))
1311 (error "File %s is not under version control" buffer-file-name
)))))
1313 ;;; Support for the C-x v v command. This is where all the single-file-oriented
1314 ;;; code from before the fileset rewrite lives.
1316 (defsubst vc-editable-p
(file)
1317 "Return non-nil if FILE can be edited."
1318 (or (eq (vc-checkout-model file
) 'implicit
)
1319 (memq (vc-state file
) '(edited needs-merge
))))
1321 (defun vc-revert-buffer-internal (&optional arg no-confirm
)
1322 "Revert buffer, keeping point and mark where user expects them.
1323 Try to be clever in the face of changes due to expanded version-control
1324 key words. This is important for typeahead to work as expected.
1325 ARG and NO-CONFIRM are passed on to `revert-buffer'."
1328 (let ((context (vc-buffer-context)))
1329 ;; Use save-excursion here, because it may be able to restore point
1330 ;; and mark properly even in cases where vc-restore-buffer-context
1331 ;; would fail. However, save-excursion might also get it wrong --
1332 ;; in this case, vc-restore-buffer-context gives it a second try.
1334 ;; t means don't call normal-mode;
1335 ;; that's to preserve various minor modes.
1336 (revert-buffer arg no-confirm t
))
1337 (vc-restore-buffer-context context
)))
1339 (defun vc-buffer-sync (&optional not-urgent
)
1340 "Make sure the current buffer and its working file are in sync.
1341 NOT-URGENT means it is ok to continue if the user says not to save."
1342 (if (buffer-modified-p)
1343 (if (or vc-suppress-confirm
1344 (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name))))
1347 (error "Aborted")))))
1349 (defvar vc-dired-window-configuration
)
1351 (defun vc-compatible-state (p q
)
1352 "Controls which states can be in the same commit."
1355 (and (member p
'(edited added removed
)) (member q
'(edited added removed
)))))
1357 ;; Here's the major entry point.
1360 (defun vc-next-action (verbose)
1361 "Do the next logical version control operation on the current fileset.
1362 This requires that all files in the fileset be in the same state.
1364 For locking systems:
1365 If every file is not already registered, this registers each for version
1367 If every file is registered and not locked by anyone, this checks out
1368 a writable and locked file of each ready for editing.
1369 If every file is checked out and locked by the calling user, this
1370 first checks to see if each file has changed since checkout. If not,
1371 it performs a revert on that file.
1372 If every file has been changed, this pops up a buffer for entry
1373 of a log message; when the message has been entered, it checks in the
1374 resulting changes along with the log message as change commentary. If
1375 the variable `vc-keep-workfiles' is non-nil (which is its default), a
1376 read-only copy of each changed file is left in place afterwards.
1377 If the affected file is registered and locked by someone else, you are
1378 given the option to steal the lock(s).
1380 For merging systems:
1381 If every file is not already registered, this registers each one for version
1382 control. This does an add, but not a commit.
1383 If every file is added but not committed, each one is committed.
1384 If every working file is changed, but the corresponding repository file is
1385 unchanged, this pops up a buffer for entry of a log message; when the
1386 message has been entered, it checks in the resulting changes along
1387 with the logmessage as change commentary. A writable file is retained.
1388 If the repository file is changed, you are asked if you want to
1389 merge in the changes into your working copy."
1391 (let* ((files (vc-deduce-fileset nil t
))
1392 (state (vc-state (car files
)))
1393 (model (vc-checkout-model (car files
)))
1395 ;; Verify that the fileset is homogenous
1396 (dolist (file (cdr files
))
1397 (if (not (vc-compatible-state (vc-state file
) state
))
1398 (error "Fileset is in a mixed-up state"))
1399 (if (not (eq (vc-checkout-model file
) model
))
1400 (error "Fileset has mixed checkout models")))
1401 ;; Check for buffers in the fileset not matching the on-disk contents.
1402 (dolist (file files
)
1403 (let ((visited (get-file-buffer file
)))
1406 (switch-to-buffer-other-window visited
)
1407 (set-buffer visited
))
1408 ;; Check relation of buffer and file, and make sure
1409 ;; user knows what he's doing. First, finding the file
1410 ;; will check whether the file on disk is newer.
1411 ;; Ignore buffer-read-only during this test, and
1412 ;; preserve find-file-literally.
1413 (let ((buffer-read-only (not (file-writable-p file
))))
1414 (find-file-noselect file nil find-file-literally
))
1415 (if (not (verify-visited-file-modtime (current-buffer)))
1416 (if (yes-or-no-p (format "Replace %s on disk with buffer contents? " file
))
1417 (write-file buffer-file-name
)
1419 ;; Now, check if we have unsaved changes.
1421 (if (buffer-modified-p)
1422 (or (y-or-n-p (message "Use %s on disk, keeping modified buffer? " file
))
1423 (error "Aborted")))))))
1424 ;; Do the right thing
1426 ;; Files aren't registered
1428 (mapc 'vc-register files
))
1429 ;; Files are up-to-date, or need a merge and user specified a revision
1430 ((or (eq state
'up-to-date
) (and verbose
(eq state
'needs-patch
)))
1433 ;; go to a different revision
1434 (setq revision
(read-string "Branch, revision, or backend to move to: "))
1435 (let ((vsym (intern-soft (upcase revision
))))
1436 (if (member vsym vc-handled-backends
)
1437 (dolist (file files
) (vc-transfer-file file vsym
))
1438 (dolist (file files
)
1439 (vc-checkout file
(eq model
'implicit
) revision
)))))
1440 ((not (eq model
'implicit
))
1441 ;; check the files out
1442 (dolist (file files
) (vc-checkout file t
)))
1445 (message "Fileset is up-to-date"))))
1446 ;; Files have local changes
1447 ((vc-compatible-state state
'edited
)
1448 (let ((ready-for-commit files
))
1449 ;; If files are edited but read-only, give user a chance to correct
1450 (dolist (file files
)
1451 (if (not (file-writable-p file
))
1453 ;; Make the file+buffer read-write.
1454 (unless (y-or-n-p (format "%s is edited but read-only; make it writable and continue?" file
))
1456 (set-file-modes file
(logior (file-modes file
) 128))
1457 (let ((visited (get-file-buffer file
)))
1459 (with-current-buffer visited
1460 (toggle-read-only -
1)))))))
1461 ;; Allow user to revert files with no changes
1463 (dolist (file files
)
1464 (let ((visited (get-file-buffer file
)))
1465 ;; For files with locking, if the file does not contain
1466 ;; any changes, just let go of the lock, i.e. revert.
1467 (if (and (not (eq model
'implicit
))
1468 (vc-workfile-unchanged-p file
)
1469 ;; If buffer is modified, that means the user just
1470 ;; said no to saving it; in that case, don't revert,
1471 ;; because the user might intend to save after
1472 ;; finishing the log entry and committing.
1473 (not (and visited
(buffer-modified-p))))
1475 (vc-revert-file file
)
1476 (delete file ready-for-commit
))))))
1477 ;; Remaining files need to be committed
1478 (if (not ready-for-commit
)
1479 (message "No files remain to be committed")
1481 (vc-checkin ready-for-commit
)
1483 (setq revision
(read-string "New revision or backend: "))
1484 (let ((vsym (intern (upcase revision
))))
1485 (if (member vsym vc-handled-backends
)
1486 (vc-transfer-file file vsym
)
1487 (vc-checkin ready-for-commit revision
))))))))
1488 ;; locked by somebody else (locking VCSes only)
1492 (read-string "Revision to steal: ")
1493 (vc-working-revision file
))))
1494 (dolist (file files
) (vc-steal-lock file revision state
))))
1496 ((eq state
'needs-patch
)
1497 (dolist (file files
)
1498 (if (yes-or-no-p (format
1499 "%s is not up-to-date. Get latest revision? "
1500 (file-name-nondirectory file
)))
1501 (vc-checkout file
(eq model
'implicit
) t
)
1502 (if (and (not (eq model
'implicit
))
1503 (yes-or-no-p "Lock this revision? "))
1504 (vc-checkout file t
)))))
1506 ((eq state
'needs-merge
)
1507 (dolist (file files
)
1508 (if (yes-or-no-p (format
1509 "%s is not up-to-date. Merge in changes now? "
1510 (file-name-nondirectory file
)))
1511 (vc-maybe-resolve-conflicts file
(vc-call merge-news file
)))))
1514 ((eq state
'unlocked-changes
)
1515 (dolist (file files
)
1516 (if (not (equal buffer-file-name file
))
1517 (find-file-other-window file
))
1518 (if (save-window-excursion
1519 (vc-diff-internal nil
(list file
) (vc-working-revision file
) nil
)
1520 (goto-char (point-min))
1521 (let ((inhibit-read-only t
))
1523 (format "Changes to %s since last lock:\n\n" file
)))
1525 (yes-or-no-p (concat "File has unlocked changes. "
1526 "Claim lock retaining changes? ")))
1527 (progn (vc-call steal-lock file
)
1528 (clear-visited-file-modtime)
1529 ;; Must clear any headers here because they wouldn't
1530 ;; show that the file is locked now.
1531 (vc-clear-headers file
)
1532 (write-file buffer-file-name
)
1533 (vc-mode-line file
))
1534 (if (not (yes-or-no-p
1535 "Revert to checked-in revision, instead? "))
1536 (error "Checkout aborted")
1537 (vc-revert-buffer-internal t t
)
1538 (vc-checkout file t
))))))))
1540 (defun vc-create-repo (backend)
1541 "Create an empty repository in the current directory."
1547 "Create repository for: "
1548 (mapcar (lambda (b) (list (downcase (symbol-name b
)))) vc-handled-backends
)
1550 (vc-call-backend backend
'create-repo
))
1553 (defun vc-register (&optional fname set-revision comment
)
1554 "Register into a version control system.
1555 If FNAME is given register that file, otherwise register the current file.
1556 With prefix argument SET-REVISION, allow user to specify initial revision
1557 level. If COMMENT is present, use that as an initial comment.
1559 The version control system to use is found by cycling through the list
1560 `vc-handled-backends'. The first backend in that list which declares
1561 itself responsible for the file (usually because other files in that
1562 directory are already registered under that backend) will be used to
1563 register the file. If no backend declares itself responsible, the
1564 first backend that could register the file is used."
1566 (when (and (null fname
) (null buffer-file-name
)) (error "No visited file"))
1568 (let ((bname (if fname
(get-file-buffer fname
) (current-buffer))))
1569 (unless fname
(setq fname buffer-file-name
))
1570 (when (vc-backend fname
)
1571 (if (vc-registered fname
)
1572 (error "This file is already registered")
1573 (unless (y-or-n-p "Previous master file has vanished. Make a new one? ")
1574 (error "Aborted"))))
1575 ;; Watch out for new buffers of size 0: the corresponding file
1576 ;; does not exist yet, even though buffer-modified-p is nil.
1578 (with-current-buffer bname
1579 (if (and (not (buffer-modified-p))
1580 (zerop (buffer-size))
1581 (not (file-exists-p buffer-file-name
)))
1582 (set-buffer-modified-p t
))
1584 (vc-start-entry (list fname
)
1586 (read-string (format "Initial revision level for %s: "
1588 (vc-call-backend (vc-responsible-backend fname
)
1590 (or comment
(not vc-initial-comment
))
1592 "Enter initial comment."
1593 (lambda (files rev comment
)
1594 (dolist (file files
)
1595 (message "Registering %s... " file
)
1596 (let ((backend (vc-responsible-backend file t
)))
1597 (vc-file-clearprops file
)
1598 (vc-call-backend backend
'register
(list file
) rev comment
)
1599 (vc-file-setprop file
'vc-backend backend
)
1600 (unless vc-make-backup-files
1601 (make-local-variable 'backup-inhibited
)
1602 (setq backup-inhibited t
)))
1603 (message "Registering %s... done" file
))))))
1605 (defun vc-register-with (backend)
1606 "Register the current file with a specified back end."
1607 (interactive "SBackend: ")
1608 (if (not (member backend vc-handled-backends
))
1609 (error "Unknown back end."))
1610 (let ((vc-handled-backends (list backend
)))
1611 (call-interactively 'vc-register
)))
1613 (declare-function view-mode-exit
"view" (&optional return-to-alist exit-action all-win
))
1615 (defun vc-resynch-window (file &optional keep noquery
)
1616 "If FILE is in the current buffer, either revert or unvisit it.
1617 The choice between revert (to see expanded keywords) and unvisit depends on
1618 `vc-keep-workfiles'. NOQUERY if non-nil inhibits confirmation for
1619 reverting. NOQUERY should be t *only* if it is known the only
1620 difference between the buffer and the file is due to version control
1621 rather than user editing!"
1622 (and (string= buffer-file-name file
)
1625 (vc-revert-buffer-internal t noquery
)
1626 ;; TODO: Adjusting view mode might no longer be necessary
1627 ;; after RMS change to files.el of 1999-08-08. Investigate
1628 ;; this when we install the new VC.
1630 (if (file-writable-p file
)
1632 (let ((view-old-buffer-read-only nil
))
1634 (and (not view-mode
)
1635 (not (eq (get major-mode
'mode-class
) 'special
))
1636 (view-mode-enter))))
1637 (vc-mode-line buffer-file-name
))
1638 (kill-buffer (current-buffer)))))
1640 (defun vc-resynch-buffer (file &optional keep noquery
)
1641 "If FILE is currently visited, resynch its buffer."
1642 (if (string= buffer-file-name file
)
1643 (vc-resynch-window file keep noquery
)
1644 (let ((buffer (get-file-buffer file
)))
1646 (with-current-buffer buffer
1647 (vc-resynch-window file keep noquery
)))))
1648 (vc-dired-resynch-file file
))
1650 (defun vc-start-entry (files rev comment initial-contents msg action
&optional after-hook
)
1651 "Accept a comment for an operation on FILES revision REV.
1652 If COMMENT is nil, pop up a VC-log buffer, emit MSG, and set the
1653 action on close to ACTION. If COMMENT is a string and
1654 INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial
1655 contents of the log entry buffer. If COMMENT is a string and
1656 INITIAL-CONTENTS is nil, do action immediately as if the user had
1657 entered COMMENT. If COMMENT is t, also do action immediately with an
1658 empty comment. Remember the file's buffer in `vc-parent-buffer'
1659 \(current one if no file). AFTER-HOOK specifies the local value
1660 for vc-log-operation-hook."
1662 (if (eq major-mode
'vc-dired-mode
)
1663 ;; If we are called from VC dired, the parent buffer is
1664 ;; the current buffer.
1666 (if (and files
(equal (length files
) 1))
1667 (get-file-buffer (car files
))
1668 (current-buffer)))))
1669 (when vc-before-checkin-hook
1671 (with-current-buffer parent
1672 (run-hooks 'vc-before-checkin-hook
))
1673 (run-hooks 'vc-before-checkin-hook
)))
1674 (if (and comment
(not initial-contents
))
1675 (set-buffer (get-buffer-create "*VC-log*"))
1676 (pop-to-buffer (get-buffer-create "*VC-log*")))
1677 (set (make-local-variable 'vc-parent-buffer
) parent
)
1678 (set (make-local-variable 'vc-parent-buffer-name
)
1679 (concat " from " (buffer-name vc-parent-buffer
)))
1680 ;;(if file (vc-mode-line file))
1682 (make-local-variable 'vc-log-after-operation-hook
)
1684 (setq vc-log-after-operation-hook after-hook
))
1685 (setq vc-log-operation action
)
1686 (setq vc-log-revision rev
)
1689 (when (stringp comment
) (insert comment
)))
1690 (if (or (not comment
) initial-contents
)
1691 (message "%s Type C-c C-c when done" msg
)
1692 (vc-finish-logentry (eq comment t
)))))
1694 (defun vc-checkout (file &optional writable rev
)
1695 "Retrieve a copy of the revision REV of FILE.
1696 If WRITABLE is non-nil, make sure the retrieved file is writable.
1697 REV defaults to the latest revision.
1699 After check-out, runs the normal hook `vc-checkout-hook'."
1702 (vc-call make-version-backups-p file
)
1703 (vc-up-to-date-p file
)
1704 (vc-make-version-backup file
))
1708 (vc-call checkout file writable rev
)
1710 ;; Maybe the backend is not installed ;-(
1712 (let ((buf (get-file-buffer file
)))
1713 (when buf
(with-current-buffer buf
(toggle-read-only -
1)))))
1714 (signal (car err
) (cdr err
))))
1715 `((vc-state .
,(if (or (eq (vc-checkout-model file
) 'implicit
)
1717 (if (vc-call latest-on-branch-p file
)
1721 (vc-checkout-time .
,(nth 5 (file-attributes file
)))))
1722 (vc-resynch-buffer file t t
)
1723 (run-hooks 'vc-checkout-hook
))
1725 (defun vc-steal-lock (file rev owner
)
1726 "Steal the lock on FILE."
1727 (let (file-description)
1729 (setq file-description
(format "%s:%s" file rev
))
1730 (setq file-description file
))
1731 (if (not (yes-or-no-p (format "Steal the lock on %s from %s? "
1732 file-description owner
)))
1733 (error "Steal canceled"))
1734 (message "Stealing lock on %s..." file
)
1737 (vc-call steal-lock file rev
)
1738 `((vc-state . edited
)))
1739 (vc-resynch-buffer file t t
)
1740 (message "Stealing lock on %s...done" file
)
1741 ;; Write mail after actually stealing, because if the stealing
1742 ;; goes wrong, we don't want to send any mail.
1743 (compose-mail owner
(format "Stolen lock on %s" file-description
))
1744 (setq default-directory
(expand-file-name "~/"))
1745 (goto-char (point-max))
1747 (format "I stole the lock on %s, " file-description
)
1748 (current-time-string)
1750 (message "Please explain why you stole the lock. Type C-c C-c when done.")))
1752 (defun vc-checkin (files &optional rev comment initial-contents
)
1754 The optional argument REV may be a string specifying the new revision
1755 level (if nil increment the current level). COMMENT is a comment
1756 string; if omitted, a buffer is popped up to accept a comment. If
1757 INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial contents
1758 of the log entry buffer.
1760 If `vc-keep-workfiles' is nil, FILE is deleted afterwards, provided
1761 that the version control system supports this mode of operation.
1763 Runs the normal hook `vc-checkin-hook'."
1765 files rev comment initial-contents
1766 "Enter a change comment."
1767 (lambda (files rev comment
)
1768 (message "Checking in %s..." (vc-delistify files
))
1769 ;; "This log message intentionally left almost blank".
1770 ;; RCS 5.7 gripes about white-space-only comments too.
1771 (or (and comment
(string-match "[^\t\n ]" comment
))
1772 (setq comment
"*** empty log message ***"))
1775 ;; We used to change buffers to get local value of vc-checkin-switches,
1776 ;; but 'the' local buffer is not a well-defined concept for filesets.
1778 (vc-call checkin files rev comment
)
1779 (mapc 'vc-delete-automatic-version-backups files
))
1780 `((vc-state . up-to-date
)
1781 (vc-checkout-time .
,(nth 5 (file-attributes file
)))
1782 (vc-working-revision . nil
)))
1783 (message "Checking in %s...done" (vc-delistify files
)))
1786 (defun vc-finish-logentry (&optional nocomment
)
1787 "Complete the operation implied by the current log entry.
1788 Use the contents of the current buffer as a check-in or registration
1789 comment. If the optional arg NOCOMMENT is non-nil, then don't check
1790 the buffer contents as a comment."
1792 ;; Check and record the comment, if any.
1794 ;; Comment too long?
1795 (vc-call-backend (or (if vc-log-fileset
(vc-backend vc-log-fileset
))
1796 (vc-responsible-backend default-directory
))
1798 (run-hooks 'vc-logentry-check-hook
))
1799 ;; Sync parent buffer in case the user modified it while editing the comment.
1800 ;; But not if it is a vc-dired buffer.
1801 (with-current-buffer vc-parent-buffer
1802 (or vc-dired-mode
(vc-buffer-sync)))
1803 (if (not vc-log-operation
)
1804 (error "No log operation is pending"))
1805 ;; save the parameters held in buffer-local variables
1806 (let ((log-operation vc-log-operation
)
1807 (log-fileset vc-log-fileset
)
1808 (log-revision vc-log-revision
)
1809 (log-entry (buffer-string))
1810 (after-hook vc-log-after-operation-hook
)
1811 (tmp-vc-parent-buffer vc-parent-buffer
))
1812 (pop-to-buffer vc-parent-buffer
)
1815 (funcall log-operation
1819 ;; Remove checkin window (after the checkin so that if that fails
1820 ;; we don't zap the *VC-log* buffer and the typing therein).
1821 (let ((logbuf (get-buffer "*VC-log*")))
1822 (cond ((and logbuf vc-delete-logbuf-window
)
1823 (delete-windows-on logbuf
(selected-frame))
1824 ;; Kill buffer and delete any other dedicated windows/frames.
1825 (kill-buffer logbuf
))
1826 (logbuf (pop-to-buffer "*VC-log*")
1828 (pop-to-buffer tmp-vc-parent-buffer
))))
1829 ;; Now make sure we see the expanded headers
1832 (lambda (file) (vc-resynch-buffer file vc-keep-workfiles t
))
1835 (dired-move-to-filename))
1836 (run-hooks after-hook
'vc-finish-logentry-hook
)))
1838 ;;; Additional entry points for examining version histories
1840 ;; (defun vc-default-diff-tree (backend dir rev1 rev2)
1841 ;; "List differences for all registered files at and below DIR.
1842 ;; The meaning of REV1 and REV2 is the same as for `vc-revision-diff'."
1843 ;; ;; This implementation does an explicit tree walk, and calls
1844 ;; ;; vc-BACKEND-diff directly for each file. An optimization
1845 ;; ;; would be to use `vc-diff-internal', so that diffs can be local,
1846 ;; ;; and to call it only for files that are actually changed.
1847 ;; ;; However, this is expensive for some backends, and so it is left
1848 ;; ;; to backend-specific implementations.
1849 ;; (setq default-directory dir)
1850 ;; (vc-file-tree-walk
1851 ;; default-directory
1854 ;; `(let ((coding-system-for-read (vc-coding-system-for-diff ',f)))
1855 ;; (message "Looking at %s" ',f)
1856 ;; (vc-call-backend ',(vc-backend f)
1857 ;; 'diff (list ',f) ',rev1 ',rev2))))))
1859 (defun vc-coding-system-for-diff (file)
1860 "Return the coding system for reading diff output for FILE."
1861 (or coding-system-for-read
1862 ;; if we already have this file open,
1863 ;; use the buffer's coding system
1864 (let ((buf (find-buffer-visiting file
)))
1865 (if buf
(with-current-buffer buf
1866 buffer-file-coding-system
)))
1867 ;; otherwise, try to find one based on the file name
1868 (car (find-operation-coding-system 'insert-file-contents file
))
1869 ;; and a final fallback
1872 (defun vc-switches (backend op
)
1875 (let ((sym (vc-make-backend-sym
1876 backend
(intern (concat (symbol-name op
)
1878 (if (boundp sym
) (symbol-value sym
))))
1879 (let ((sym (intern (format "vc-%s-switches" (symbol-name op
)))))
1880 (if (boundp sym
) (symbol-value sym
)))
1882 ((eq op
'diff
) diff-switches
)))))
1883 (if (stringp switches
) (list switches
)
1884 ;; If not a list, return nil.
1885 ;; This is so we can set vc-diff-switches to t to override
1886 ;; any switches in diff-switches.
1887 (if (listp switches
) switches
))))
1889 ;; Old def for compatibility with Emacs-21.[123].
1890 (defmacro vc-diff-switches-list
(backend) `(vc-switches ',backend
'diff
))
1891 (make-obsolete 'vc-diff-switches-list
'vc-switches
"22.1")
1893 (defun vc-diff-sentinel (verbose rev1-name rev2-name
)
1894 ;; The empty sync output case has already been handled, so the only
1895 ;; possibility of an empty output is for an async process, in which case
1896 ;; it's important to insert the "diffs end here" message in the buffer
1897 ;; since the user may miss a message in the echo area.
1899 (let ((inhibit-read-only t
))
1900 (if (eq (buffer-size) 0)
1901 (insert "No differences found.\n")
1902 (insert (format "\n\nDiffs between %s and %s end here." rev1-name rev2-name
)))))
1903 (goto-char (point-min))
1904 (shrink-window-if-larger-than-buffer))
1906 (defvar vc-diff-added-files nil
1907 "If non-nil, diff added files by comparing them to /dev/null.")
1909 (defun vc-diff-internal (async files rev1 rev2
&optional verbose
)
1910 "Report diffs between two revisions of a fileset.
1911 Diff output goes to the *vc-diff* buffer. The function
1912 returns t if the buffer had changes, nil otherwise."
1913 (let* ((filenames (vc-delistify files
))
1914 (rev1-name (or rev1
"working revision"))
1915 (rev2-name (or rev2
"workfile"))
1916 ;; Set coding system based on the first file. It's a kluge,
1917 ;; but the only way to set it for each file included would
1918 ;; be to call the back end separately for each file.
1919 (coding-system-for-read
1920 (if files
(vc-coding-system-for-diff (car files
)) 'undecided
)))
1921 (vc-setup-buffer "*vc-diff*")
1922 (message "Finding changes in %s..." filenames
)
1923 ;; Many backends don't handle well the case of a file that has been
1924 ;; added but not yet committed to the repo (notably CVS and Subversion).
1925 ;; Do that work here so the backends don't have to futz with it. --ESR
1927 ;; Actually most backends (including CVS) have options to control the
1928 ;; behavior since which one is better depends on the user and on the
1929 ;; situation). Worse yet: this code does not handle the case where
1930 ;; `file' is a directory which contains added files.
1931 ;; I made it conditional on vc-diff-added-files but it should probably
1932 ;; just be removed (or copied/moved to specific backends). --Stef.
1933 (when vc-diff-added-files
1934 (let ((filtered '()))
1935 (dolist (file files
)
1936 (if (or (file-directory-p file
)
1937 (not (string= (vc-working-revision file
) "0")))
1938 (push file filtered
)
1939 ;; This file is added but not yet committed;
1940 ;; there is no master file to diff against.
1942 (error "No revisions of %s exist" file
)
1943 ;; We regard this as "changed".
1944 ;; Diff it against /dev/null.
1945 (apply 'vc-do-command
"*vc-diff*"
1947 (append (vc-switches nil
'diff
) '("/dev/null"))))))
1948 (setq files
(nreverse filtered
))))
1949 (let ((vc-disable-async-diff (not async
)))
1950 (vc-call diff files rev1 rev2
"*vc-diff*"))
1951 (set-buffer "*vc-diff*")
1952 (if (and (zerop (buffer-size))
1953 (not (get-buffer-process (current-buffer))))
1954 ;; Treat this case specially so as not to pop the buffer.
1956 (message "No changes between %s and %s" rev1-name rev2-name
)
1959 ;; Make the *vc-diff* buffer read only, the diff-mode key
1960 ;; bindings are nicer for read only buffers. pcl-cvs does the
1962 (setq buffer-read-only t
)
1963 (vc-exec-after `(vc-diff-sentinel ,verbose
,rev1-name
,rev2-name
))
1964 ;; Display the buffer, but at the end because it can change point.
1965 (pop-to-buffer (current-buffer))
1966 ;; In the async case, we return t even if there are no differences
1967 ;; because we don't know that yet.
1971 (defun vc-version-diff (files rev1 rev2
)
1972 "Report diffs between revisions of the fileset in the repository history."
1974 (let* ((files (vc-deduce-fileset t
))
1977 (vc-call revision-completion-table files
))
1981 ;; someday we may be able to do revision completion on non-singleton
1982 ;; filesets, but not yet.
1983 ((/= (length files
) 1)
1985 ;; if it's a directory, don't supply any revision default
1986 ((file-directory-p first
)
1988 ;; if the file is not up-to-date, use working revision as older revision
1989 ((not (vc-up-to-date-p first
))
1990 (setq rev1-default
(vc-working-revision first
)))
1991 ;; if the file is not locked, use last and previous revisions as defaults
1993 (setq rev1-default
(vc-call previous-revision first
1994 (vc-working-revision first
)))
1995 (if (string= rev1-default
"") (setq rev1-default nil
))
1996 (setq rev2-default
(vc-working-revision first
))))
1997 ;; construct argument list
1998 (let* ((rev1-prompt (if rev1-default
1999 (concat "Older revision (default "
2001 "Older revision: "))
2002 (rev2-prompt (concat "Newer revision (default "
2003 (or rev2-default
"current source") "): "))
2004 (rev1 (if completion-table
2005 (completing-read rev1-prompt completion-table
2006 nil nil nil nil rev1-default
)
2007 (read-string rev1-prompt nil nil rev1-default
)))
2008 (rev2 (if completion-table
2009 (completing-read rev2-prompt completion-table
2010 nil nil nil nil rev2-default
)
2011 (read-string rev2-prompt nil nil rev2-default
))))
2012 (if (string= rev1
"") (setq rev1 nil
))
2013 (if (string= rev2
"") (setq rev2 nil
))
2014 (list files rev1 rev2
))))
2015 (if (and (not rev1
) rev2
)
2016 (error "Not a valid revision range."))
2017 (vc-diff-internal t files rev1 rev2
(interactive-p)))
2019 ;; (defun vc-contains-version-controlled-file (dir)
2020 ;; "Return t if DIR contains a version-controlled file, nil otherwise."
2022 ;; (mapc (lambda (f) (and (not (file-directory-p f)) (vc-backend f) (throw 'found 't))) (directory-files dir))
2026 (defun vc-diff (historic &optional not-urgent
)
2027 "Display diffs between file revisions.
2028 Normally this compares the currently selected fileset with their
2029 working revisions. With a prefix argument HISTORIC, it reads two revision
2030 designators specifying which revisions to compare.
2032 If no current fileset is available (that is, we are not in
2033 VC-Dired mode and the visited file of the current buffer is not
2034 under version control) and we're in a Dired buffer, use
2035 the current directory.
2036 The optional argument NOT-URGENT non-nil means it is ok to say no to
2038 (interactive (list current-prefix-arg t
))
2040 (call-interactively 'vc-version-diff
)
2041 (let* ((files (vc-deduce-fileset t
)))
2042 (if buffer-file-name
(vc-buffer-sync not-urgent
))
2043 (vc-diff-internal t files nil nil
(interactive-p)))))
2047 (defun vc-revision-other-window (rev)
2048 "Visit revision REV of the current file in another window.
2049 If the current file is named `F', the revision is named `F.~REV~'.
2050 If `F.~REV~' already exists, use it instead of checking it out again."
2052 (save-current-buffer
2053 (vc-ensure-vc-buffer)
2054 (let ((completion-table
2055 (vc-call revision-completion-table buffer-file-name
))
2056 (prompt "Revision to visit (default is working revision): "))
2058 (if completion-table
2059 (completing-read prompt completion-table
)
2060 (read-string prompt
))))))
2061 (vc-ensure-vc-buffer)
2062 (let* ((file buffer-file-name
)
2063 (revision (if (string-equal rev
"")
2064 (vc-working-revision file
)
2066 (switch-to-buffer-other-window (vc-find-revision file revision
))))
2068 (defun vc-find-revision (file revision
)
2069 "Read REVISION of FILE into a buffer and return the buffer."
2070 (let ((automatic-backup (vc-version-backup-file-name file revision
))
2071 (filebuf (or (get-file-buffer file
) (current-buffer)))
2072 (filename (vc-version-backup-file-name file revision
'manual
)))
2073 (unless (file-exists-p filename
)
2074 (if (file-exists-p automatic-backup
)
2075 (rename-file automatic-backup filename nil
)
2076 (message "Checking out %s..." filename
)
2077 (with-current-buffer filebuf
2080 (let ((coding-system-for-read 'no-conversion
)
2081 (coding-system-for-write 'no-conversion
))
2082 (with-temp-file filename
2083 (let ((outbuf (current-buffer)))
2084 ;; Change buffer to get local value of
2085 ;; vc-checkout-switches.
2086 (with-current-buffer filebuf
2087 (vc-call find-revision file revision outbuf
))))
2089 (when (and failed
(file-exists-p filename
))
2090 (delete-file filename
))))
2091 (vc-mode-line file
))
2092 (message "Checking out %s...done" filename
)))
2093 (let ((result-buf (find-file-noselect filename
)))
2094 (with-current-buffer result-buf
2095 ;; Set the parent buffer so that things like
2096 ;; C-x v g, C-x v l, ... etc work.
2097 (setq vc-parent-buffer filebuf
))
2100 ;; Header-insertion code
2103 (defun vc-insert-headers ()
2104 "Insert headers into a file for use with a version control system.
2105 Headers desired are inserted at point, and are pulled from
2106 the variable `vc-BACKEND-header'."
2108 (vc-ensure-vc-buffer)
2112 (if (or (not (vc-check-headers))
2113 (y-or-n-p "Version headers already exist. Insert another set? "))
2114 (let* ((delims (cdr (assq major-mode vc-comment-alist
)))
2115 (comment-start-vc (or (car delims
) comment-start
"#"))
2116 (comment-end-vc (or (car (cdr delims
)) comment-end
""))
2117 (hdsym (vc-make-backend-sym (vc-backend buffer-file-name
)
2119 (hdstrings (and (boundp hdsym
) (symbol-value hdsym
))))
2120 (dolist (s hdstrings
)
2121 (insert comment-start-vc
"\t" s
"\t"
2122 comment-end-vc
"\n"))
2123 (if vc-static-header-alist
2124 (dolist (f vc-static-header-alist
)
2125 (if (string-match (car f
) buffer-file-name
)
2126 (insert (format (cdr f
) (car hdstrings
)))))))))))
2128 (defun vc-clear-headers (&optional file
)
2129 "Clear all version headers in the current buffer (or FILE).
2130 The headers are reset to their non-expanded form."
2131 (let* ((filename (or file buffer-file-name
))
2132 (visited (find-buffer-visiting filename
))
2133 (backend (vc-backend filename
)))
2134 (when (vc-find-backend-function backend
'clear-headers
)
2136 (let ((context (vc-buffer-context)))
2137 ;; save-excursion may be able to relocate point and mark
2138 ;; properly. If it fails, vc-restore-buffer-context
2139 ;; will give it a second try.
2141 (vc-call-backend backend
'clear-headers
))
2142 (vc-restore-buffer-context context
))
2143 (set-buffer (find-file-noselect filename
))
2144 (vc-call-backend backend
'clear-headers
)
2145 (kill-buffer filename
)))))
2147 (defun vc-modify-change-comment (files rev oldcomment
)
2148 "Edit the comment associated with the given files and revision."
2150 files rev oldcomment t
2151 "Enter a replacement change comment."
2152 (lambda (files rev comment
)
2154 ;; Less of a kluge than it looks like; log-view mode only passes
2155 ;; this function a singleton list. Arguments left in this form in
2156 ;; case the more general operation ever becomes meaningful.
2157 (vc-responsible-backend (car files
))
2158 'modify-change-comment files rev comment
))))
2162 "Merge changes between two revisions into the current buffer's file.
2163 This asks for two revisions to merge from in the minibuffer. If the
2164 first revision is a branch number, then merge all changes from that
2165 branch. If the first revision is empty, merge news, i.e. recent changes
2166 from the current branch.
2168 See Info node `Merging'."
2170 (vc-ensure-vc-buffer)
2172 (let* ((file buffer-file-name
)
2173 (backend (vc-backend file
))
2174 (state (vc-state file
))
2175 first-revision second-revision status
)
2177 ((stringp state
) ;; Locking VCses only
2178 (error "File is locked by %s" state
))
2179 ((not (vc-editable-p file
))
2181 "File must be checked out for merging. Check out now? ")
2182 (vc-checkout file t
)
2183 (error "Merge aborted"))))
2184 (setq first-revision
2185 (read-string (concat "Branch or revision to merge from "
2186 "(default news on current branch): ")))
2187 (if (string= first-revision
"")
2188 (if (not (vc-find-backend-function backend
'merge-news
))
2189 (error "Sorry, merging news is not implemented for %s" backend
)
2190 (setq status
(vc-call merge-news file
)))
2191 (if (not (vc-find-backend-function backend
'merge
))
2192 (error "Sorry, merging is not implemented for %s" backend
)
2193 (if (not (vc-branch-p first-revision
))
2194 (setq second-revision
2195 (read-string "Second revision: "
2196 (concat (vc-branch-part first-revision
) ".")))
2197 ;; We want to merge an entire branch. Set revisions
2198 ;; accordingly, so that vc-BACKEND-merge understands us.
2199 (setq second-revision first-revision
)
2200 ;; first-revision must be the starting point of the branch
2201 (setq first-revision
(vc-branch-part first-revision
)))
2202 (setq status
(vc-call merge file first-revision second-revision
))))
2203 (vc-maybe-resolve-conflicts file status
"WORKFILE" "MERGE SOURCE")))
2205 (defun vc-maybe-resolve-conflicts (file status
&optional name-A name-B
)
2206 (vc-resynch-buffer file t
(not (buffer-modified-p)))
2207 (if (zerop status
) (message "Merge successful")
2209 (message "File contains conflicts.")))
2212 (defalias 'vc-resolve-conflicts
'smerge-ediff
)
2214 ;; The VC directory major mode. Coopt Dired for this.
2215 ;; All VC commands get mapped into logical equivalents.
2217 (defvar vc-dired-switches
)
2218 (defvar vc-dired-terse-mode
)
2220 (defvar vc-dired-mode-map
2221 (let ((map (make-sparse-keymap))
2222 (vmap (make-sparse-keymap)))
2223 (define-key map
"\C-xv" vmap
)
2224 (define-key map
"v" vmap
)
2225 (set-keymap-parent vmap vc-prefix-map
)
2226 (define-key vmap
"t" 'vc-dired-toggle-terse-mode
)
2229 (define-derived-mode vc-dired-mode dired-mode
"Dired under "
2230 "The major mode used in VC directory buffers.
2232 It works like Dired, but lists only files under version control, with
2233 the current VC state of each file being indicated in the place of the
2234 file's link count, owner, group and size. Subdirectories are also
2235 listed, and you may insert them into the buffer as desired, like in
2238 All Dired commands operate normally, with the exception of `v', which
2239 is redefined as the version control prefix, so that you can type
2240 `vl', `v=' etc. to invoke `vc-print-log', `vc-diff', and the like on
2241 the file named in the current Dired buffer line. `vv' invokes
2242 `vc-next-action' on this file, or on all files currently marked.
2243 There is a special command, `*l', to mark all files currently locked."
2244 ;; define-derived-mode does it for us in Emacs-21, but not in Emacs-20.
2245 ;; We do it here because dired might not be loaded yet
2246 ;; when vc-dired-mode-map is initialized.
2247 (set-keymap-parent vc-dired-mode-map dired-mode-map
)
2248 (add-hook 'dired-after-readin-hook
'vc-dired-hook nil t
)
2249 ;; The following is slightly modified from files.el,
2250 ;; because file lines look a bit different in vc-dired-mode
2251 ;; (the column before the date does not end in a digit).
2252 ;; albinus: It should be done in the original declaration. Problem
2253 ;; is the optional empty state-info; otherwise ")" would be good
2254 ;; enough as delimeter.
2255 (set (make-local-variable 'directory-listing-before-filename-regexp
)
2256 (let* ((l "\\([A-Za-z]\\|[^\0-\177]\\)")
2257 ;; In some locales, month abbreviations are as short as 2 letters,
2258 ;; and they can be followed by ".".
2259 (month (concat l l
"+\\.?"))
2261 (yyyy "[0-9][0-9][0-9][0-9]")
2263 (HH:MM
"[ 0-2][0-9]:[0-5][0-9]")
2264 (seconds "[0-6][0-9]\\([.,][0-9]+\\)?")
2265 (zone "[-+][0-2][0-9][0-5][0-9]")
2266 (iso-mm-dd "[01][0-9]-[0-3][0-9]")
2267 (iso-time (concat HH
:MM
"\\(:" seconds
"\\( ?" zone
"\\)?\\)?"))
2268 (iso (concat "\\(\\(" yyyy
"-\\)?" iso-mm-dd
"[ T]" iso-time
2269 "\\|" yyyy
"-" iso-mm-dd
"\\)"))
2270 (western (concat "\\(" month s
"+" dd
"\\|" dd
"\\.?" s month
"\\)"
2272 "\\(" HH
:MM
"\\|" yyyy
"\\)"))
2273 (western-comma (concat month s
"+" dd
"," s
"+" yyyy
))
2274 ;; Japanese MS-Windows ls-lisp has one-digit months, and
2275 ;; omits the Kanji characters after month and day-of-month.
2278 (concat mm l
"?" s dd l
"?" s
"+"
2279 "\\(" HH
:MM
"\\|" yyyy l
"?" "\\)")))
2280 ;; the .* below ensures that we find the last match on a line
2282 "\\(" western
"\\|" western-comma
"\\|" japanese
"\\|" iso
"\\)"
2284 (and (boundp 'vc-dired-switches
)
2286 (set (make-local-variable 'dired-actual-switches
)
2288 (set (make-local-variable 'vc-dired-terse-mode
) vc-dired-terse-display
)
2289 (let ((backend-name (symbol-name (vc-responsible-backend
2290 default-directory
))))
2291 (setq mode-name
(concat mode-name backend-name
))
2292 ;; Add menu after `vc-dired-mode-map' has `dired-mode-map' as the parent.
2293 (let ((vc-dire-menu-map (copy-keymap vc-menu-map
)))
2294 (define-key-after (lookup-key vc-dired-mode-map
[menu-bar
]) [vc]
2295 (cons backend-name vc-dire-menu-map) 'subdir)))
2296 (setq vc-dired-mode t))
2298 (defun vc-dired-toggle-terse-mode ()
2299 "Toggle terse display in VC Dired."
2301 (if (not vc-dired-mode)
2303 (setq vc-dired-terse-mode (not vc-dired-terse-mode))
2304 (if vc-dired-terse-mode
2308 (defun vc-dired-mark-locked ()
2309 "Mark all files currently locked."
2311 (dired-mark-if (let ((f (dired-get-filename nil t)))
2313 (not (file-directory-p f))
2314 (not (vc-up-to-date-p f))))
2317 (define-key vc-dired-mode-map "*l" 'vc-dired-mark-locked)
2319 (defun vc-dired-reformat-line (vc-info)
2320 "Reformat a directory-listing line.
2321 Replace various columns with version control information, VC-INFO.
2322 This code, like dired, assumes UNIX -l format."
2324 (when (re-search-forward
2325 ;; Match link count, owner, group, size. Group may be missing,
2326 ;; and only the size is present in OS/2 -l format.
2327 "^..[drwxlts-]+ \\( *[0-9]+\\( [^ ]+ +\\([^ ]+ +\\)?[0-9]+\\)?\\) "
2328 (line-end-position) t)
2329 (replace-match (substring (concat vc-info " ") 0 10)
2332 (defun vc-dired-ignorable-p (filename)
2333 "Should FILENAME be ignored in VC-Dired listings?"
2335 ;; Ignore anything that wouldn't be found by completion (.o, .la, etc.)
2336 (dolist (ignorable completion-ignored-extensions)
2337 (let ((ext (substring filename
2338 (- (length filename)
2339 (length ignorable)))))
2340 (if (string= ignorable ext) (throw t t))))
2341 ;; Ignore Makefiles derived from something else
2342 (when (string= (file-name-nondirectory filename) "Makefile")
2343 (let* ((dir (file-name-directory filename))
2344 (peers (directory-files (or dir default-directory))))
2345 (if (or (member "Makefile.in" peers) (member "Makefile.am" peers))
2349 (defun vc-dired-hook ()
2350 "Reformat the listing according to version control.
2351 Called by dired after any portion of a vc-dired buffer has been read in."
2352 (message "Getting version information... ")
2353 ;; if the backend supports it, get the state
2354 ;; of all files in this directory at once
2355 (let ((backend (vc-responsible-backend default-directory)))
2356 ;; check `backend' can really handle `default-directory'.
2357 (if (and (vc-call-backend backend 'responsible-p default-directory)
2358 (vc-find-backend-function backend 'dir-state))
2359 (vc-call-backend backend 'dir-state default-directory)))
2361 (inhibit-read-only t)
2362 (buffer-undo-list t))
2363 (goto-char (point-min))
2366 ;; subdir header line
2369 ;; erase (but don't remove) the "total" line
2370 (delete-region (point) (line-end-position))
2374 ((setq filename (dired-get-filename nil t))
2377 ((file-directory-p filename)
2379 ((member (file-name-nondirectory filename)
2380 vc-directory-exclusion-list)
2381 (let ((pos (point)))
2382 (dired-kill-tree filename)
2385 (vc-dired-terse-mode
2386 ;; Don't show directories in terse mode. Don't use
2387 ;; dired-kill-line to remove it, because in recursive listings,
2388 ;; that would remove the directory contents as well.
2389 (delete-region (line-beginning-position)
2390 (progn (forward-line 1) (point))))
2391 ((string-match "\\`\\.\\.?\\'" (file-name-nondirectory filename))
2394 (vc-dired-reformat-line nil)
2396 ;; Try to head off calling the expensive state query -
2397 ;; ignore object files, TeX intermediate files, and so forth.
2398 ((vc-dired-ignorable-p filename)
2400 ;; Ordinary file -- call the (possibly expensive) state query
2402 ;; First case: unregistered or unknown. (Unknown shouldn't happen here)
2403 ((member (vc-state filename) '(nil unregistered))
2404 (if vc-dired-terse-mode
2406 (vc-dired-reformat-line "?")
2408 ;; Either we're in non-terse mode or it's out of date
2409 ((not (and vc-dired-terse-mode (vc-up-to-date-p filename)))
2410 (vc-dired-reformat-line (vc-call dired-state-info filename))
2412 ;; Remaining cases are under version control but uninteresting
2414 (dired-kill-line))))
2416 (t (forward-line 1))))
2418 (message "Getting version information... done")
2421 (cond ((eq (count-lines (point-min) (point-max)) 1)
2422 (goto-char (point-min))
2423 (message "No changes pending under %s" default-directory)))))
2425 (defun vc-dired-purge ()
2426 "Remove empty subdirs."
2427 (goto-char (point-min))
2428 (while (dired-get-subdir)
2430 (if (dired-get-filename nil t)
2431 (if (not (dired-next-subdir 1 t))
2432 (goto-char (point-max)))
2434 (if (not (string= (dired-current-directory) default-directory))
2435 (dired-do-kill-lines t "")
2436 ;; We cannot remove the top level directory.
2437 ;; Just make it look a little nicer.
2439 (or (eobp) (kill-line))
2440 (if (not (dired-next-subdir 1 t))
2441 (goto-char (point-max))))))
2442 (goto-char (point-min)))
2444 (defun vc-dired-buffers-for-dir (dir)
2445 "Return a list of all vc-dired buffers that currently display DIR."
2447 ;; Check whether dired is loaded.
2448 (when (fboundp 'dired-buffers-for-dir)
2449 (dolist (buffer (dired-buffers-for-dir dir))
2450 (with-current-buffer buffer
2452 (push buffer result)))))
2455 (defun vc-dired-resynch-file (file)
2456 "Update the entries for FILE in any VC Dired buffers that list it."
2457 (let ((buffers (vc-dired-buffers-for-dir (file-name-directory file))))
2459 (mapcar (lambda (buffer)
2460 (with-current-buffer buffer
2461 (if (dired-goto-file file)
2462 ;; bind vc-dired-terse-mode to nil so that
2463 ;; files won't vanish when they are checked in
2464 (let ((vc-dired-terse-mode nil))
2465 (dired-do-redisplay 1)))))
2469 (defun vc-directory (dir read-switches)
2470 "Create a buffer in VC Dired Mode for directory DIR.
2472 See Info node `VC Dired Mode'.
2474 With prefix arg READ-SWITCHES, specify a value to override
2475 `dired-listing-switches' when generating the listing."
2476 (interactive "DDired under VC (directory): \nP")
2477 (let ((vc-dired-switches (concat vc-dired-listing-switches
2478 (if vc-dired-recurse "R" ""))))
2479 (if (eq (string-match tramp-file-name-regexp dir) 0)
2480 (error "Sorry, vc-directory does not work over Tramp"))
2482 (setq vc-dired-switches
2483 (read-string "Dired listing switches: "
2484 vc-dired-switches)))
2486 (require 'dired-aux)
2488 (dired-internal-noselect (expand-file-name (file-name-as-directory dir))
2493 ;; Named-configuration entry points
2495 (defun vc-snapshot-precondition (dir)
2496 "Scan the tree below DIR, looking for files not up-to-date.
2497 If any file is not up-to-date, return the name of the first such file.
2498 \(This means, neither snapshot creation nor retrieval is allowed.\)
2499 If one or more of the files are currently visited, return `visited'.
2500 Otherwise, return nil."
2502 (catch 'vc-locked-example
2506 (if (not (vc-up-to-date-p f)) (throw 'vc-locked-example f)
2507 (if (get-file-buffer f) (setq status 'visited)))))
2511 (defun vc-create-snapshot (dir name branchp)
2512 "Descending recursively from DIR, make a snapshot called NAME.
2513 For each registered file, the working revision becomes part of
2514 the named configuration. If the prefix argument BRANCHP is
2515 given, the snapshot is made as a new branch and the files are
2516 checked out in that new branch."
2518 (list (read-file-name "Directory: " default-directory default-directory t)
2519 (read-string "New snapshot name: ")
2520 current-prefix-arg))
2521 (message "Making %s... " (if branchp "branch" "snapshot"))
2522 (if (file-directory-p dir) (setq dir (file-name-as-directory dir)))
2523 (vc-call-backend (vc-responsible-backend dir)
2524 'create-snapshot dir name branchp)
2525 (message "Making %s... done" (if branchp "branch" "snapshot")))
2528 (defun vc-retrieve-snapshot (dir name)
2529 "Descending recursively from DIR, retrieve the snapshot called NAME.
2530 If NAME is empty, it refers to the latest revisions.
2531 If locking is used for the files in DIR, then there must not be any
2532 locked files at or below DIR (but if NAME is empty, locked files are
2533 allowed and simply skipped)."
2535 (list (read-file-name "Directory: " default-directory default-directory t)
2536 (read-string "Snapshot name to retrieve (default latest revisions): ")))
2537 (let ((update (yes-or-no-p "Update any affected buffers? "))
2538 (msg (if (or (not name) (string= name ""))
2539 (format "Updating %s... " (abbreviate-file-name dir))
2540 (format "Retrieving snapshot into %s... "
2541 (abbreviate-file-name dir)))))
2543 (vc-call-backend (vc-responsible-backend dir)
2544 'retrieve-snapshot dir name update)
2545 (message "%s" (concat msg "done"))))
2547 ;; Miscellaneous other entry points
2550 (defun vc-print-log (&optional working-revision)
2551 "List the change log of the current fileset in a window.
2552 If WORKING-REVISION is non-nil, leave the point at that revision."
2554 (let* ((files (vc-deduce-fileset))
2555 (backend (vc-backend files))
2556 (working-revision (or working-revision (vc-working-revision (car files)))))
2557 ;; Don't switch to the output buffer before running the command,
2558 ;; so that any buffer-local settings in the vc-controlled
2559 ;; buffer can be accessed by the command.
2560 (vc-call-backend backend 'print-log files "*vc-change-log*")
2561 (pop-to-buffer "*vc-change-log*")
2563 `(let ((inhibit-read-only t))
2564 (vc-call-backend ',backend 'log-view-mode)
2565 (goto-char (point-max)) (forward-line -1)
2566 (while (looking-at "=*\n")
2567 (delete-char (- (match-end 0) (match-beginning 0)))
2569 (goto-char (point-min))
2570 (if (looking-at "[\b\t\n\v\f\r ]+")
2571 (delete-char (- (match-end 0) (match-beginning 0))))
2572 (shrink-window-if-larger-than-buffer)
2573 ;; move point to the log entry for the working revision
2574 (vc-call-backend ',backend 'show-log-entry ',working-revision)
2575 (setq vc-sentinel-movepoint (point))
2576 (set-buffer-modified-p nil)))))
2580 "Revert working copies of the selected fileset to their repository contents.
2581 This asks for confirmation if the buffer contents are not identical
2582 to the working revision (except for keyword expansion)."
2584 (let* ((files (vc-deduce-fileset)))
2585 ;; If any of the files is visited by the current buffer, make
2586 ;; sure buffer is saved. If the user says `no', abort since
2587 ;; we cannot show the changes and ask for confirmation to
2589 (if (or (not files) (memq (buffer-file-name) files))
2590 (vc-buffer-sync nil))
2591 (dolist (file files)
2592 (let ((buf (get-file-buffer file)))
2593 (if (and buf (buffer-modified-p buf))
2594 (error "Please kill or save all modified buffers before reverting.")))
2595 (if (vc-up-to-date-p file)
2596 (unless (yes-or-no-p (format "%s seems up-to-date. Revert anyway? " file))
2597 (error "Revert canceled"))))
2598 (if (vc-diff-internal vc-allow-async-revert files nil nil)
2600 (unless (yes-or-no-p (format "Discard changes in %s? " (vc-delistify files)))
2601 (error "Revert canceled"))
2602 (delete-windows-on "*vc-diff*")
2603 (kill-buffer "*vc-diff*")))
2604 (dolist (file files)
2606 (message "Reverting %s..." (vc-delistify files))
2607 (vc-revert-file file)
2608 (message "Reverting %s...done" (vc-delistify files))))))
2611 (defun vc-rollback ()
2612 "Roll back (remove) the most recent changeset committed to the repository.
2613 This may be either a file-level or a repository-level operation,
2614 depending on the underlying version-control system."
2616 (let* ((files (vc-deduce-fileset))
2617 (backend (vc-backend files))
2618 (granularity (vc-call-backend backend 'revision-granularity)))
2619 (unless (vc-find-backend-function backend 'rollback)
2620 (error "Rollback is not supported in %s" backend))
2621 (if (and (not (eq granularity 'repository)) (/= (length files) 1))
2622 (error "Rollback requires a singleton fileset or repository versioning"))
2623 (if (not (vc-call latest-on-branch-p (car files)))
2624 (error "Rollback is only possible at the tip revision."))
2625 ;; If any of the files is visited by the current buffer, make
2626 ;; sure buffer is saved. If the user says `no', abort since
2627 ;; we cannot show the changes and ask for confirmation to
2629 (if (or (not files) (memq (buffer-file-name) files))
2630 (vc-buffer-sync nil))
2631 (dolist (file files)
2632 (if (buffer-modified-p (get-file-buffer file))
2633 (error "Please kill or save all modified buffers before rollback."))
2634 (if (not (vc-up-to-date-p file))
2635 (error "Please revert all modified workfiles before rollback.")))
2636 ;; Accumulate changes associated with the fileset
2637 (vc-setup-buffer "*vc-diff*")
2639 (message "Finding changes...")
2640 (let* ((tip (vc-working-revision (car files)))
2641 (previous (vc-call previous-revision (car files) tip)))
2642 (vc-diff-internal nil files previous tip))
2644 (unless (yes-or-no-p "Discard these revisions? ")
2645 (error "Rollback canceled"))
2646 (delete-windows-on "*vc-diff*")
2647 (kill-buffer"*vc-diff*")
2648 ;; Do the actual reversions
2649 (message "Rolling back %s..." (vc-delistify files))
2652 (vc-call-backend backend 'rollback files)
2653 `((vc-state . ,'up-to-date)
2654 (vc-checkout-time . , (nth 5 (file-attributes file)))
2655 (vc-working-revision . nil)))
2656 (dolist (f files) (vc-resynch-buffer f t t))
2657 (message "Rolling back %s...done" (vc-delistify files))))
2660 (define-obsolete-function-alias 'vc-revert-buffer 'vc-revert "23.1")
2664 "Update the current fileset's files to their tip revisions.
2665 For each one that contains no changes, and is not locked, then this simply
2666 replaces the work file with the latest revision on its branch. If the file
2667 contains changes, and the backend supports merging news, then any recent
2668 changes from the current branch are merged into the working file."
2670 (dolist (file (vc-deduce-fileset))
2671 (if (buffer-modified-p (get-file-buffer file))
2672 (error "Please kill or save all modified buffers before updating."))
2673 (if (vc-up-to-date-p file)
2674 (vc-checkout file nil "")
2675 (if (eq (vc-checkout-model file) 'locking)
2676 (if (eq (vc-state file) 'edited)
2678 (substitute-command-keys
2679 "File is locked--type \\[vc-revert] to discard changes"))
2680 (error "Unexpected file state (%s) -- type %s"
2682 (substitute-command-keys
2683 "\\[vc-next-action] to correct")))
2684 (if (not (vc-find-backend-function (vc-backend file) 'merge-news))
2685 (error "Sorry, merging news is not implemented for %s"
2687 (vc-call merge-news file)
2688 (vc-resynch-buffer file t t))))))
2690 (defun vc-version-backup-file (file &optional rev)
2691 "Return name of backup file for revision REV of FILE.
2692 If version backups should be used for FILE, and there exists
2693 such a backup for REV or the working revision of file, return
2694 its name; otherwise return nil."
2695 (when (vc-call make-version-backups-p file)
2696 (let ((backup-file (vc-version-backup-file-name file rev)))
2697 (if (file-exists-p backup-file)
2699 ;; there is no automatic backup, but maybe the user made one manually
2700 (setq backup-file (vc-version-backup-file-name file rev 'manual))
2701 (if (file-exists-p backup-file)
2704 (defun vc-revert-file (file)
2705 "Revert FILE back to the repository working revision it was based on."
2708 (let ((backup-file (vc-version-backup-file file)))
2710 (copy-file backup-file file 'ok-if-already-exists 'keep-date)
2711 (vc-delete-automatic-version-backups file))
2712 (vc-call revert file backup-file))
2713 `((vc-state . up-to-date)
2714 (vc-checkout-time . ,(nth 5 (file-attributes file)))))
2715 (vc-resynch-buffer file t t))
2718 (defun vc-switch-backend (file backend)
2719 "Make BACKEND the current version control system for FILE.
2720 FILE must already be registered in BACKEND. The change is not
2721 permanent, only for the current session. This function only changes
2722 VC's perspective on FILE, it does not register or unregister it.
2723 By default, this command cycles through the registered backends.
2724 To get a prompt, use a prefix argument."
2727 (or buffer-file-name
2728 (error "There is no version-controlled file in this buffer"))
2729 (let ((backend (vc-backend buffer-file-name))
2732 (error "File %s is not under version control" buffer-file-name))
2733 ;; Find the registered backends.
2734 (dolist (backend vc-handled-backends)
2735 (when (vc-call-backend backend 'registered buffer-file-name)
2736 (push backend backends)))
2737 ;; Find the next backend.
2738 (let ((def (car (delq backend (append (memq backend backends) backends))))
2739 (others (delete backend backends)))
2741 ((null others) (error "No other backend to switch to"))
2746 (format "Switch to backend [%s]: " def)
2747 (mapcar (lambda (b) (list (downcase (symbol-name b)))) backends)
2748 nil t nil nil (downcase (symbol-name def))))))
2750 (unless (eq backend (vc-backend file))
2751 (vc-file-clearprops file)
2752 (vc-file-setprop file 'vc-backend backend)
2753 ;; Force recomputation of the state
2754 (unless (vc-call-backend backend 'registered file)
2755 (vc-file-clearprops file)
2756 (error "%s is not registered in %s" file backend))
2757 (vc-mode-line file)))
2760 (defun vc-transfer-file (file new-backend)
2761 "Transfer FILE to another version control system NEW-BACKEND.
2762 If NEW-BACKEND has a higher precedence than FILE's current backend
2763 \(i.e. it comes earlier in `vc-handled-backends'), then register FILE in
2764 NEW-BACKEND, using the revision number from the current backend as the
2765 base level. If NEW-BACKEND has a lower precedence than the current
2766 backend, then commit all changes that were made under the current
2767 backend to NEW-BACKEND, and unregister FILE from the current backend.
2768 \(If FILE is not yet registered under NEW-BACKEND, register it.)"
2769 (let* ((old-backend (vc-backend file))
2770 (edited (memq (vc-state file) '(edited needs-merge)))
2771 (registered (vc-call-backend new-backend 'registered file))
2773 (and registered ; Never move if not registered in new-backend yet.
2774 ;; move if new-backend comes later in vc-handled-backends
2775 (or (memq new-backend (memq old-backend vc-handled-backends))
2776 (y-or-n-p "Final transfer? "))))
2778 (if (eq old-backend new-backend)
2779 (error "%s is the current backend of %s" new-backend file))
2781 (set-file-modes file (logior (file-modes file) 128))
2782 ;; `registered' might have switched under us.
2783 (vc-switch-backend file old-backend)
2784 (let* ((rev (vc-working-revision file))
2785 (modified-file (and edited (make-temp-file file)))
2786 (unmodified-file (and modified-file (vc-version-backup-file file))))
2787 ;; Go back to the base unmodified file.
2791 (copy-file file modified-file 'ok-if-already-exists)
2792 ;; If we have a local copy of the unmodified file, handle that
2793 ;; here and not in vc-revert-file because we don't want to
2794 ;; delete that copy -- it is still useful for OLD-BACKEND.
2796 (copy-file unmodified-file file
2797 'ok-if-already-exists 'keep-date)
2798 (if (y-or-n-p "Get base revision from master? ")
2799 (vc-revert-file file))))
2800 (vc-call-backend new-backend 'receive-file file rev))
2802 (vc-switch-backend file new-backend)
2803 (unless (eq (vc-checkout-model file) 'implicit)
2804 (vc-checkout file t nil))
2805 (rename-file modified-file file 'ok-if-already-exists)
2806 (vc-file-setprop file 'vc-checkout-time nil)))))
2808 (vc-switch-backend file old-backend)
2809 (setq comment (vc-call comment-history file))
2810 (vc-call unregister file))
2811 (vc-switch-backend file new-backend)
2812 (when (or move edited)
2813 (vc-file-setprop file 'vc-state 'edited)
2815 (vc-checkin file nil comment (stringp comment)))))
2817 (defun vc-rename-master (oldmaster newfile templates)
2818 "Rename OLDMASTER to be the master file for NEWFILE based on TEMPLATES."
2819 (let* ((dir (file-name-directory (expand-file-name oldmaster)))
2820 (newdir (or (file-name-directory newfile) ""))
2821 (newbase (file-name-nondirectory newfile))
2823 ;; List of potential master files for `newfile'
2825 (lambda (s) (vc-possible-master s newdir newbase))
2827 (if (or (file-symlink-p oldmaster)
2828 (file-symlink-p (file-name-directory oldmaster)))
2829 (error "This is unsafe in the presence of symbolic links"))
2833 ;; If possible, keep the master file in the same directory.
2835 (if (and f (string= (file-name-directory (expand-file-name f)) dir))
2837 ;; If not, just use the first possible place.
2839 (and f (or (not (setq dir (file-name-directory f)))
2840 (file-directory-p dir))
2842 (error "New file lacks a version control directory")))))
2844 (defun vc-delete-file (file)
2845 "Delete file and mark it as such in the version control system."
2846 (interactive "fVC delete file: ")
2847 (let ((buf (get-file-buffer file))
2848 (backend (vc-backend file)))
2850 (error "File %s is not under version control"
2851 (file-name-nondirectory file)))
2852 (unless (vc-find-backend-function backend 'delete-file)
2853 (error "Deleting files under %s is not supported in VC" backend))
2854 (if (and buf (buffer-modified-p buf))
2855 (error "Please save files before deleting them"))
2856 (unless (y-or-n-p (format "Really want to delete %s? "
2857 (file-name-nondirectory file)))
2859 (unless (or (file-directory-p file) (null make-backup-files))
2860 (with-current-buffer (or buf (find-file-noselect file))
2861 (let ((backup-inhibited nil))
2863 (vc-call delete-file file)
2864 ;; If the backend hasn't deleted the file itself, let's do it for him.
2865 (if (file-exists-p file) (delete-file file))))
2868 (defun vc-rename-file (old new)
2869 "Rename file OLD to NEW, and rename its master file likewise."
2870 (interactive "fVC rename file: \nFRename to: ")
2871 (let ((oldbuf (get-file-buffer old)))
2872 (if (and oldbuf (buffer-modified-p oldbuf))
2873 (error "Please save files before moving them"))
2874 (if (get-file-buffer new)
2875 (error "Already editing new file name"))
2876 (if (file-exists-p new)
2877 (error "New file already exists"))
2878 (let ((state (vc-state old)))
2879 (unless (memq state '(up-to-date edited))
2880 (error "Please %s files before moving them"
2881 (if (stringp state) "check in" "update"))))
2882 (vc-call rename-file old new)
2883 (vc-file-clearprops old)
2884 ;; Move the actual file (unless the backend did it already)
2885 (if (file-exists-p old) (rename-file old new))
2886 ;; ?? Renaming a file might change its contents due to keyword expansion.
2887 ;; We should really check out a new copy if the old copy was precisely equal
2888 ;; to some checked-in revision. However, testing for this is tricky....
2890 (with-current-buffer oldbuf
2891 (let ((buffer-read-only buffer-read-only))
2892 (set-visited-file-name new))
2895 (set-buffer-modified-p nil)))))
2898 (defun vc-update-change-log (&rest args)
2899 "Find change log file and add entries from recent version control logs.
2900 Normally, find log entries for all registered files in the default
2903 With prefix arg of \\[universal-argument], only find log entries for the current buffer's file.
2905 With any numeric prefix arg, find log entries for all currently visited
2906 files that are under version control. This puts all the entries in the
2907 log for the default directory, which may not be appropriate.
2909 From a program, any ARGS are assumed to be filenames for which
2910 log entries should be gathered."
2912 (cond ((consp current-prefix-arg) ;C-u
2913 (list buffer-file-name))
2914 (current-prefix-arg ;Numeric argument.
2916 (buffers (buffer-list))
2919 (setq file (buffer-file-name (car buffers)))
2920 (and file (vc-backend file)
2921 (setq files (cons file files)))
2922 (setq buffers (cdr buffers)))
2925 ;; Don't supply any filenames to backend; this means
2926 ;; it should find all relevant files relative to
2927 ;; the default-directory.
2929 (dolist (file (or args (list default-directory)))
2930 (if (eq (string-match tramp-file-name-regexp file) 0)
2931 (error "Sorry, vc-update-change-log does not work over Tramp")))
2932 (vc-call-backend (vc-responsible-backend default-directory)
2933 'update-changelog args))
2935 ;;; The default back end. Assumes RCS-like revision numbering.
2937 (defun vc-default-revision-granularity ()
2938 (error "Your backend will not work with this version of VC mode."))
2940 ;; functions that operate on RCS revision numbers. This code should
2941 ;; also be moved into the backends. It stays for now, however, since
2942 ;; it is used in code below.
2944 (defun vc-trunk-p (rev)
2945 "Return t if REV is a revision on the trunk."
2946 (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev))))
2948 (defun vc-branch-p (rev)
2949 "Return t if REV is a branch revision."
2950 (not (eq nil (string-match "\\`[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*\\'" rev))))
2953 (defun vc-branch-part (rev)
2954 "Return the branch part of a revision number REV."
2955 (let ((index (string-match "\\.[0-9]+\\'" rev)))
2957 (substring rev 0 index))))
2959 (defun vc-minor-part (rev)
2960 "Return the minor revision number of a revision number REV."
2961 (string-match "[0-9]+\\'" rev)
2962 (substring rev (match-beginning 0) (match-end 0)))
2964 (defun vc-default-previous-revision (backend file rev)
2965 "Return the revision number immediately preceding REV for FILE,
2966 or nil if there is no previous revision. This default
2967 implementation works for MAJOR.MINOR-style revision numbers as
2968 used by RCS and CVS."
2969 (let ((branch (vc-branch-part rev))
2970 (minor-num (string-to-number (vc-minor-part rev))))
2973 ;; revision does probably not start a branch or release
2974 (concat branch "." (number-to-string (1- minor-num)))
2975 (if (vc-trunk-p rev)
2976 ;; we are at the beginning of the trunk --
2977 ;; don't know anything to return here
2979 ;; we are at the beginning of a branch --
2980 ;; return revision of starting point
2981 (vc-branch-part branch))))))
2983 (defun vc-default-next-revision (backend file rev)
2984 "Return the revision number immediately following REV for FILE,
2985 or nil if there is no next revision. This default implementation
2986 works for MAJOR.MINOR-style revision numbers as used by RCS
2988 (when (not (string= rev (vc-working-revision file)))
2989 (let ((branch (vc-branch-part rev))
2990 (minor-num (string-to-number (vc-minor-part rev))))
2991 (concat branch "." (number-to-string (1+ minor-num))))))
2993 (defun vc-default-responsible-p (backend file)
2994 "Indicate whether BACKEND is reponsible for FILE.
2995 The default is to return nil always."
2998 (defun vc-default-could-register (backend file)
2999 "Return non-nil if BACKEND could be used to register FILE.
3000 The default implementation returns t for all files."
3003 (defun vc-default-latest-on-branch-p (backend file)
3004 "Return non-nil if FILE is the latest on its branch.
3005 This default implementation always returns non-nil, which means that
3006 editing non-current revisions is not supported by default."
3009 (defun vc-default-init-revision (backend) vc-default-init-revision)
3011 (defalias 'vc-cvs-update-changelog 'vc-update-changelog-rcs2log)
3012 (defalias 'vc-rcs-update-changelog 'vc-update-changelog-rcs2log)
3013 ;; FIXME: This should probably be moved to vc-rcs.el and replaced in
3014 ;; vc-cvs.el by code using cvs2cl.
3015 (defun vc-update-changelog-rcs2log (files)
3016 "Default implementation of update-changelog.
3017 Uses `rcs2log' which only works for RCS and CVS."
3018 ;; FIXME: We (c|sh)ould add support for cvs2cl
3019 (let ((odefault default-directory)
3020 (changelog (find-change-log))
3021 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
3022 (tempfile (make-temp-file
3023 (expand-file-name "vc"
3024 (or small-temporary-file-directory
3025 temporary-file-directory))))
3026 (login-name (or user-login-name
3027 (format "uid%d" (number-to-string (user-uid)))))
3028 (full-name (or add-log-full-name
3031 (format "uid%d" (number-to-string (user-uid)))))
3032 (mailing-address (or add-log-mailing-address
3033 user-mail-address)))
3034 (find-file-other-window changelog)
3035 (barf-if-buffer-read-only)
3038 (goto-char (point-min))
3040 (message "Computing change log entries...")
3041 (message "Computing change log entries... %s"
3044 (setq default-directory odefault)
3045 (if (eq 0 (apply 'call-process
3046 (expand-file-name "rcs2log"
3048 nil (list t tempfile) nil
3050 "-u" (concat login-name
3052 "\t" mailing-address)
3056 (expand-file-name f odefault)))
3059 (pop-to-buffer (get-buffer-create "*vc*"))
3061 (insert-file-contents tempfile)
3063 (setq default-directory (file-name-directory changelog))
3064 (delete-file tempfile)))))
3066 (defun vc-default-find-revision (backend file rev buffer)
3067 "Provide the new `find-revision' op based on the old `checkout' op.
3068 This is only for compatibility with old backends. They should be updated
3069 to provide the `find-revision' operation instead."
3070 (let ((tmpfile (make-temp-file (expand-file-name file))))
3073 (vc-call-backend backend 'checkout file nil rev tmpfile)
3074 (with-current-buffer buffer
3075 (insert-file-contents-literally tmpfile)))
3076 (delete-file tmpfile))))
3078 (defun vc-default-dired-state-info (backend file)
3079 (let* ((state (vc-state file))
3082 ((stringp state) (concat "(" state ")"))
3083 ((eq state 'edited) (concat "(" (vc-user-login-name file) ")"))
3084 ((eq state 'needs-merge) "(merge)")
3085 ((eq state 'needs-patch) "(patch)")
3086 ((eq state 'added) "(added)")
3087 ((eq state 'removed) "(removed)")
3088 ((eq state 'ignored) "(ignored)") ;; dired-hook filters this out
3089 ((eq state 'unregistered) "?")
3090 ((eq state 'unlocked-changes) "(stale)")
3091 ((not state) "(unknown)")))
3093 (get-file-buffer file))
3095 (if (and buffer (buffer-modified-p buffer)) "+" "")))
3096 (concat statestring modflag)))
3098 (defun vc-default-rename-file (backend old new)
3100 (add-name-to-file old new)
3101 (error (rename-file old new)))
3102 (vc-delete-file old)
3103 (with-current-buffer (find-file-noselect new)
3106 (defalias 'vc-default-logentry-check 'ignore)
3107 (defalias 'vc-default-check-headers 'ignore)
3109 (defun vc-default-log-view-mode (backend) (log-view-mode))
3111 (defun vc-default-show-log-entry (backend rev)
3113 (log-view-goto-rev rev)))
3115 (defun vc-default-comment-history (backend file)
3116 "Return a string with all log entries stored in BACKEND for FILE."
3117 (if (vc-find-backend-function backend 'print-log)
3118 (with-current-buffer "*vc*"
3119 (vc-call print-log (list file))
3120 (vc-call-backend backend 'wash-log)
3123 (defun vc-default-receive-file (backend file rev)
3124 "Let BACKEND receive FILE from another version control system."
3125 (vc-call-backend backend 'register file rev ""))
3127 (defun vc-default-create-snapshot (backend dir name branchp)
3129 (error "VC backend %s does not support module branches" backend))
3130 (let ((result (vc-snapshot-precondition dir)))
3131 (if (stringp result)
3132 (error "File %s is not up-to-date" result)
3136 (vc-call assign-name f name))))))
3138 (defun vc-default-retrieve-snapshot (backend dir name update)
3139 (if (string= name "")
3146 (vc-call checkout f nil "")
3147 (if update (vc-resynch-buffer f t t)))))))
3148 (let ((result (vc-snapshot-precondition dir)))
3149 (if (stringp result)
3150 (error "File %s is locked" result)
3151 (setq update (and (eq result 'visited) update))
3154 (lambda (f) (vc-error-occurred
3155 (vc-call checkout f nil name)
3156 (if update (vc-resynch-buffer f t t)))))))))
3158 (defun vc-default-revert (backend file contents-done)
3159 (unless contents-done
3160 (let ((rev (vc-working-revision file))
3161 (file-buffer (or (get-file-buffer file) (current-buffer))))
3162 (message "Checking out %s..." file)
3164 (backup-name (car (find-backup-file-name file))))
3166 (copy-file file backup-name 'ok-if-already-exists 'keep-date)
3167 (unless (file-writable-p file)
3168 (set-file-modes file (logior (file-modes file) 128))))
3170 (let ((coding-system-for-read 'no-conversion)
3171 (coding-system-for-write 'no-conversion))
3172 (with-temp-file file
3173 (let ((outbuf (current-buffer)))
3174 ;; Change buffer to get local value of vc-checkout-switches.
3175 (with-current-buffer file-buffer
3176 (let ((default-directory (file-name-directory file)))
3177 (vc-call find-revision file rev outbuf)))))
3181 (rename-file backup-name file 'ok-if-already-exists)
3182 (and (not vc-make-backup-files) (delete-file backup-name))))))
3183 (message "Checking out %s...done" file))))
3185 (defalias 'vc-default-revision-completion-table 'ignore)
3187 (defun vc-check-headers ()
3188 "Check if the current file has any headers in it."
3190 (vc-call-backend (vc-backend buffer-file-name) 'check-headers))
3192 ;;; Annotate functionality
3194 ;; Declare globally instead of additional parameter to
3195 ;; temp-buffer-show-function (not possible to pass more than one
3196 ;; parameter). The use of annotate-ratio is deprecated in favor of
3197 ;; annotate-mode, which replaces it with the more sensible "span-to
3198 ;; days", along with autoscaling support.
3199 (defvar vc-annotate-ratio nil "Global variable.")
3201 ;; internal buffer-local variables
3202 (defvar vc-annotate-backend nil)
3203 (defvar vc-annotate-parent-file nil)
3204 (defvar vc-annotate-parent-rev nil)
3205 (defvar vc-annotate-parent-display-mode nil)
3207 (defconst vc-annotate-font-lock-keywords
3208 ;; The fontification is done by vc-annotate-lines instead of font-lock.
3209 '((vc-annotate-lines)))
3211 (define-derived-mode vc-annotate-mode fundamental-mode "Annotate"
3212 "Major mode for output buffers of the `vc-annotate' command.
3214 You can use the mode-specific menu to alter the time-span of the used
3215 colors. See variable `vc-annotate-menu-elements' for customizing the
3217 ;; Frob buffer-invisibility-spec so that if it is originally a naked t,
3218 ;; it will become a list, to avoid initial annotations being invisible.
3219 (add-to-invisibility-spec 'foo)
3220 (remove-from-invisibility-spec 'foo)
3221 (set (make-local-variable 'truncate-lines) t)
3222 (set (make-local-variable 'font-lock-defaults)
3223 '(vc-annotate-font-lock-keywords t))
3226 (defun vc-annotate-toggle-annotation-visibility ()
3227 "Toggle whether or not the annotation is visible."
3229 (funcall (if (memq 'vc-annotate-annotation buffer-invisibility-spec)
3230 'remove-from-invisibility-spec
3231 'add-to-invisibility-spec)
3232 'vc-annotate-annotation)
3233 (force-window-update (current-buffer)))
3235 (defun vc-annotate-display-default (ratio)
3236 "Display the output of \\[vc-annotate] using the default color range.
3237 The color range is given by `vc-annotate-color-map', scaled by RATIO.
3238 The current time is used as the offset."
3239 (interactive (progn (kill-local-variable 'vc-annotate-color-map) '(1.0)))
3240 (message "Redisplaying annotation...")
3241 (vc-annotate-display ratio)
3242 (message "Redisplaying annotation...done"))
3244 (defun vc-annotate-oldest-in-map (color-map)
3245 "Return the oldest time in the COLOR-MAP."
3246 ;; Since entries should be sorted, we can just use the last one.
3247 (caar (last color-map)))
3249 (defun vc-annotate-get-time-set-line-props ()
3251 (date (vc-call-backend vc-annotate-backend 'annotate-time))
3252 (inhibit-read-only t))
3253 (put-text-property bol (point) 'invisible 'vc-annotate-annotation)
3256 (defun vc-annotate-display-autoscale (&optional full)
3257 "Highlight the output of \\[vc-annotate] using an autoscaled color map.
3258 Autoscaling means that the map is scaled from the current time to the
3259 oldest annotation in the buffer, or, with prefix argument FULL, to
3260 cover the range from the oldest annotation to the newest."
3263 (oldest 999999.) ;Any CVS users at the founding of Rome?
3264 (current (vc-annotate-convert-time (current-time)))
3266 (message "Redisplaying annotation...")
3267 ;; Run through this file and find the oldest and newest dates annotated.
3269 (goto-char (point-min))
3271 (when (setq date (vc-annotate-get-time-set-line-props))
3275 (setq oldest date)))
3277 (vc-annotate-display
3278 (/ (- (if full newest current) oldest)
3279 (vc-annotate-oldest-in-map vc-annotate-color-map))
3281 (message "Redisplaying annotation...done \(%s\)"
3283 (format "Spanned from %.1f to %.1f days old"
3286 (format "Spanned to %.1f days old" (- current oldest))))))
3288 ;; Menu -- Using easymenu.el
3289 (easy-menu-define vc-annotate-mode-menu vc-annotate-mode-map
3290 "VC Annotate Display Menu"
3292 ["By Color Map Range" (unless (null vc-annotate-display-mode)
3293 (setq vc-annotate-display-mode nil)
3294 (vc-annotate-display-select))
3295 :style toggle :selected (null vc-annotate-display-mode)]
3296 ,@(let ((oldest-in-map (vc-annotate-oldest-in-map vc-annotate-color-map)))
3297 (mapcar (lambda (element)
3298 (let ((days (* element oldest-in-map)))
3299 `[,(format "Span %.1f days" days)
3300 (vc-annotate-display-select nil ,days)
3301 :style toggle :selected
3302 (eql vc-annotate-display-mode ,days) ]))
3303 vc-annotate-menu-elements))
3305 (vc-annotate-display-select
3306 nil (float (string-to-number (read-string "Span how many days? "))))]
3309 (unless (eq vc-annotate-display-mode 'scale)
3310 (vc-annotate-display-select nil 'scale))
3311 :style toggle :selected
3312 (eq vc-annotate-display-mode 'scale)]
3313 ["Span Oldest->Newest"
3314 (unless (eq vc-annotate-display-mode 'fullscale)
3315 (vc-annotate-display-select nil 'fullscale))
3316 :style toggle :selected
3317 (eq vc-annotate-display-mode 'fullscale)]
3319 ["Toggle annotation visibility" vc-annotate-toggle-annotation-visibility]
3320 ["Annotate previous revision" vc-annotate-prev-revision]
3321 ["Annotate next revision" vc-annotate-next-revision]
3322 ["Annotate revision at line" vc-annotate-revision-at-line]
3323 ["Annotate revision previous to line" vc-annotate-revision-previous-to-line]
3324 ["Annotate latest revision" vc-annotate-working-revision]
3325 ["Show log of revision at line" vc-annotate-show-log-revision-at-line]
3326 ["Show diff of revision at line" vc-annotate-show-diff-revision-at-line]))
3328 (defun vc-annotate-display-select (&optional buffer mode)
3329 "Highlight the output of \\[vc-annotate].
3330 By default, the current buffer is highlighted, unless overridden by
3331 BUFFER. `vc-annotate-display-mode' specifies the highlighting mode to
3332 use; you may override this using the second optional arg MODE."
3334 (if mode (setq vc-annotate-display-mode mode))
3335 (pop-to-buffer (or buffer (current-buffer)))
3336 (cond ((null vc-annotate-display-mode)
3337 ;; The ratio is global, thus relative to the global color-map.
3338 (kill-local-variable 'vc-annotate-color-map)
3339 (vc-annotate-display-default (or vc-annotate-ratio 1.0)))
3340 ;; One of the auto-scaling modes
3341 ((eq vc-annotate-display-mode 'scale)
3342 (vc-exec-after `(vc-annotate-display-autoscale)))
3343 ((eq vc-annotate-display-mode 'fullscale)
3344 (vc-exec-after `(vc-annotate-display-autoscale t)))
3345 ((numberp vc-annotate-display-mode) ; A fixed number of days lookback
3346 (vc-annotate-display-default
3347 (/ vc-annotate-display-mode
3348 (vc-annotate-oldest-in-map vc-annotate-color-map))))
3349 (t (error "No such display mode: %s"
3350 vc-annotate-display-mode))))
3353 (defun vc-annotate (file rev &optional display-mode buf)
3354 "Display the edit history of the current file using colors.
3356 This command creates a buffer that shows, for each line of the current
3357 file, when it was last edited and by whom. Additionally, colors are
3358 used to show the age of each line--blue means oldest, red means
3359 youngest, and intermediate colors indicate intermediate ages. By
3360 default, the time scale stretches back one year into the past;
3361 everything that is older than that is shown in blue.
3363 With a prefix argument, this command asks two questions in the
3364 minibuffer. First, you may enter a revision number; then the buffer
3365 displays and annotates that revision instead of the working revision
3366 \(type RET in the minibuffer to leave that default unchanged). Then,
3367 you are prompted for the time span in days which the color range
3368 should cover. For example, a time span of 20 days means that changes
3369 over the past 20 days are shown in red to blue, according to their
3370 age, and everything that is older than that is shown in blue.
3372 Customization variables:
3374 `vc-annotate-menu-elements' customizes the menu elements of the
3375 mode-specific menu. `vc-annotate-color-map' and
3376 `vc-annotate-very-old-color' define the mapping of time to colors.
3377 `vc-annotate-background' specifies the background color."
3379 (save-current-buffer
3380 (vc-ensure-vc-buffer)
3381 (list buffer-file-name
3382 (let ((def (vc-working-revision buffer-file-name)))
3383 (if (null current-prefix-arg) def
3385 (format "Annotate from revision (default %s): " def)
3387 (if (null current-prefix-arg)
3388 vc-annotate-display-mode
3389 (float (string-to-number
3390 (read-string "Annotate span days (default 20): "
3392 (vc-ensure-vc-buffer)
3393 (setq vc-annotate-display-mode display-mode) ;Not sure why. --Stef
3394 (let* ((temp-buffer-name (format "*Annotate %s (rev %s)*" (buffer-name) rev))
3395 (temp-buffer-show-function 'vc-annotate-display-select)
3396 ;; If BUF is specified, we presume the caller maintains current line,
3397 ;; so we don't need to do it here. This implementation may give
3398 ;; strange results occasionally in the case of REV != WORKFILE-REV.
3399 (current-line (unless buf (line-number-at-pos))))
3400 (message "Annotating...")
3401 ;; If BUF is specified it tells in which buffer we should put the
3402 ;; annotations. This is used when switching annotations to another
3403 ;; revision, so we should update the buffer's name.
3404 (if buf (with-current-buffer buf
3405 (rename-buffer temp-buffer-name t)
3406 ;; In case it had to be uniquified.
3407 (setq temp-buffer-name (buffer-name))))
3408 (with-output-to-temp-buffer temp-buffer-name
3409 (vc-call annotate-command file (get-buffer temp-buffer-name) rev)
3410 ;; we must setup the mode first, and then set our local
3411 ;; variables before the show-function is called at the exit of
3412 ;; with-output-to-temp-buffer
3413 (with-current-buffer temp-buffer-name
3414 (if (not (equal major-mode 'vc-annotate-mode))
3416 (set (make-local-variable 'vc-annotate-backend) (vc-backend file))
3417 (set (make-local-variable 'vc-annotate-parent-file) file)
3418 (set (make-local-variable 'vc-annotate-parent-rev) rev)
3419 (set (make-local-variable 'vc-annotate-parent-display-mode)
3422 (with-current-buffer temp-buffer-name
3425 ;; Ideally, we'd rather not move point if the user has already
3426 ;; moved it elsewhere, but really point here is not the position
3427 ;; of the user's cursor :-(
3428 (when ,current-line ;(and (bobp))
3429 (goto-line ,current-line)
3430 (setq vc-sentinel-movepoint (point)))
3431 (unless (active-minibuffer-window)
3432 (message "Annotating... done")))))))
3434 (defun vc-annotate-prev-revision (prefix)
3435 "Visit the annotation of the revision previous to this one.
3437 With a numeric prefix argument, annotate the revision that many
3438 revisions previous."
3440 (vc-annotate-warp-revision (- 0 prefix)))
3442 (defun vc-annotate-next-revision (prefix)
3443 "Visit the annotation of the revision after this one.
3445 With a numeric prefix argument, annotate the revision that many
3448 (vc-annotate-warp-revision prefix))
3450 (defun vc-annotate-working-revision ()
3451 "Visit the annotation of the working revision of this file."
3453 (if (not (equal major-mode 'vc-annotate-mode))
3454 (message "Cannot be invoked outside of a vc annotate buffer")
3455 (let ((warp-rev (vc-working-revision vc-annotate-parent-file)))
3456 (if (equal warp-rev vc-annotate-parent-rev)
3457 (message "Already at revision %s" warp-rev)
3458 (vc-annotate-warp-revision warp-rev)))))
3460 (defun vc-annotate-extract-revision-at-line ()
3461 "Extract the revision number of the current line."
3462 ;; This function must be invoked from a buffer in vc-annotate-mode
3463 (vc-call-backend vc-annotate-backend 'annotate-extract-revision-at-line))
3465 (defun vc-annotate-revision-at-line ()
3466 "Visit the annotation of the revision identified in the current line."
3468 (if (not (equal major-mode 'vc-annotate-mode))
3469 (message "Cannot be invoked outside of a vc annotate buffer")
3470 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
3471 (if (not rev-at-line)
3472 (message "Cannot extract revision number from the current line")
3473 (if (equal rev-at-line vc-annotate-parent-rev)
3474 (message "Already at revision %s" rev-at-line)
3475 (vc-annotate-warp-revision rev-at-line))))))
3477 (defun vc-annotate-revision-previous-to-line ()
3478 "Visit the annotation of the revision before the revision at line."
3480 (if (not (equal major-mode 'vc-annotate-mode))
3481 (message "Cannot be invoked outside of a vc annotate buffer")
3482 (let ((rev-at-line (vc-annotate-extract-revision-at-line))
3484 (if (not rev-at-line)
3485 (message "Cannot extract revision number from the current line")
3487 (vc-call previous-revision vc-annotate-parent-file rev-at-line))
3488 (vc-annotate-warp-revision prev-rev)))))
3490 (defun vc-annotate-show-log-revision-at-line ()
3491 "Visit the log of the revision at line."
3493 (if (not (equal major-mode 'vc-annotate-mode))
3494 (message "Cannot be invoked outside of a vc annotate buffer")
3495 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
3496 (if (not rev-at-line)
3497 (message "Cannot extract revision number from the current line")
3498 (vc-print-log rev-at-line)))))
3500 (defun vc-annotate-show-diff-revision-at-line ()
3501 "Visit the diff of the revision at line from its previous revision."
3503 (if (not (equal major-mode 'vc-annotate-mode))
3504 (message "Cannot be invoked outside of a vc annotate buffer")
3505 (let ((rev-at-line (vc-annotate-extract-revision-at-line))
3507 (if (not rev-at-line)
3508 (message "Cannot extract revision number from the current line")
3510 (vc-call previous-revision vc-annotate-parent-file rev-at-line))
3512 (message "Cannot diff from any revision prior to %s" rev-at-line)
3513 (save-window-excursion
3514 (vc-diff-internal nil (list vc-annotate-parent-file)
3515 prev-rev rev-at-line))
3516 (switch-to-buffer "*vc-diff*"))))))
3518 (defun vc-annotate-warp-revision (revspec)
3519 "Annotate the revision described by REVSPEC.
3521 If REVSPEC is a positive integer, warp that many revisions
3522 forward, if possible, otherwise echo a warning message. If
3523 REVSPEC is a negative integer, warp that many revisions backward,
3524 if possible, otherwise echo a warning message. If REVSPEC is a
3525 string, then it describes a revision number, so warp to that
3527 (if (not (equal major-mode 'vc-annotate-mode))
3528 (message "Cannot be invoked outside of a vc annotate buffer")
3529 (let* ((buf (current-buffer))
3530 (oldline (line-number-at-pos))
3531 (revspeccopy revspec)
3534 ((and (integerp revspec) (> revspec 0))
3535 (setq newrev vc-annotate-parent-rev)
3536 (while (and (> revspec 0) newrev)
3537 (setq newrev (vc-call next-revision
3538 vc-annotate-parent-file newrev))
3539 (setq revspec (1- revspec)))
3541 (message "Cannot increment %d revisions from revision %s"
3542 revspeccopy vc-annotate-parent-rev)))
3543 ((and (integerp revspec) (< revspec 0))
3544 (setq newrev vc-annotate-parent-rev)
3545 (while (and (< revspec 0) newrev)
3546 (setq newrev (vc-call previous-revision
3547 vc-annotate-parent-file newrev))
3548 (setq revspec (1+ revspec)))
3550 (message "Cannot decrement %d revisions from revision %s"
3551 (- 0 revspeccopy) vc-annotate-parent-rev)))
3552 ((stringp revspec) (setq newrev revspec))
3553 (t (error "Invalid argument to vc-annotate-warp-revision")))
3555 (vc-annotate vc-annotate-parent-file newrev
3556 vc-annotate-parent-display-mode
3558 (goto-line (min oldline (progn (goto-char (point-max))
3560 (line-number-at-pos))) buf)))))
3562 (defun vc-annotate-compcar (threshold a-list)
3563 "Test successive cons cells of A-LIST against THRESHOLD.
3564 Return the first cons cell with a car that is not less than THRESHOLD,
3565 nil if no such cell exists."
3567 (tmp-cons (car a-list)))
3568 (while (and tmp-cons (< (car tmp-cons) threshold))
3569 (setq tmp-cons (car (nthcdr i a-list)))
3571 tmp-cons)) ; Return the appropriate value
3573 (defun vc-annotate-convert-time (time)
3574 "Convert a time value to a floating-point number of days.
3575 The argument TIME is a list as returned by `current-time' or
3576 `encode-time', only the first two elements of that list are considered."
3577 (/ (+ (* (float (car time)) (lsh 1 16)) (cadr time)) 24 3600))
3579 (defun vc-annotate-difference (&optional offset)
3580 "Return the time span in days to the next annotation.
3581 This calls the backend function annotate-time, and returns the
3582 difference in days between the time returned and the current time,
3583 or OFFSET if present."
3584 (let ((next-time (vc-annotate-get-time-set-line-props)))
3587 (vc-call-backend vc-annotate-backend 'annotate-current-time))
3590 (defun vc-default-annotate-current-time (backend)
3591 "Return the current time, encoded as fractional days."
3592 (vc-annotate-convert-time (current-time)))
3594 (defvar vc-annotate-offset nil)
3596 (defun vc-annotate-display (ratio &optional offset)
3597 "Highlight `vc-annotate' output in the current buffer.
3598 RATIO, is the expansion that should be applied to `vc-annotate-color-map'.
3599 The annotations are relative to the current time, unless overridden by OFFSET."
3601 (set (make-local-variable 'vc-annotate-color-map)
3602 (mapcar (lambda (elem) (cons (* (car elem) ratio) (cdr elem)))
3603 vc-annotate-color-map)))
3604 (set (make-local-variable 'vc-annotate-offset) offset)
3607 (defun vc-annotate-lines (limit)
3608 (while (< (point) limit)
3609 (let ((difference (vc-annotate-difference vc-annotate-offset))
3611 (end (progn (forward-line 1) (point))))
3613 (let* ((color (or (vc-annotate-compcar difference vc-annotate-color-map)
3614 (cons nil vc-annotate-very-old-color)))
3615 ;; substring from index 1 to remove any leading `#' in the name
3616 (face-name (concat "vc-annotate-face-"
3618 (substring (cdr color) 0 1) "#")
3619 (substring (cdr color) 1)
3621 ;; Make the face if not done.
3622 (face (or (intern-soft face-name)
3623 (let ((tmp-face (make-face (intern face-name))))
3624 (set-face-foreground tmp-face (cdr color))
3625 (if vc-annotate-background
3626 (set-face-background tmp-face
3627 vc-annotate-background))
3628 tmp-face)))) ; Return the face
3629 (put-text-property start end 'face face)))))
3630 ;; Pretend to font-lock there were no matches.
3634 ;; Set up key bindings for use while editing log messages
3636 (defun vc-log-edit (fileset)
3637 "Set up `log-edit' for use with VC on FILE."
3638 (setq default-directory
3639 (with-current-buffer vc-parent-buffer default-directory))
3640 (log-edit 'vc-finish-logentry
3642 `((log-edit-listfun . (lambda () ',fileset))
3643 (log-edit-diff-function . (lambda () (vc-diff nil)))))
3644 (set (make-local-variable 'vc-log-fileset) fileset)
3645 (make-local-variable 'vc-log-revision)
3646 (set-buffer-modified-p nil)
3647 (setq buffer-file-name nil))
3649 ;; These things should probably be generally available
3651 (defun vc-file-tree-walk (dirname func &rest args)
3652 "Walk recursively through DIRNAME.
3653 Invoke FUNC f ARGS on each VC-managed file f underneath it."
3654 (vc-file-tree-walk-internal (expand-file-name dirname) func args)
3655 (message "Traversing directory %s...done" dirname))
3657 (defun vc-file-tree-walk-internal (file func args)
3658 (if (not (file-directory-p file))
3659 (if (vc-backend file) (apply func file args))
3660 (message "Traversing directory %s..." (abbreviate-file-name file))
3661 (let ((dir (file-name-as-directory file)))
3664 (string-equal f ".")
3665 (string-equal f "..")
3666 (member f vc-directory-exclusion-list)
3667 (let ((dirf (expand-file-name f dir)))
3669 (file-symlink-p dirf) ;; Avoid possible loops.
3670 (vc-file-tree-walk-internal dirf func args)))))
3671 (directory-files dir)))))
3675 ;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
3677 ;; These may be useful to anyone who has to debug or extend the package.
3678 ;; (Note that this information corresponds to versions 5.x. Some of it
3679 ;; might have been invalidated by the additions to support branching
3680 ;; and RCS keyword lookup. AS, 1995/03/24)
3682 ;; A fundamental problem in VC is that there are time windows between
3683 ;; vc-next-action's computations of the file's version-control state and
3684 ;; the actions that change it. This is a window open to lossage in a
3685 ;; multi-user environment; someone else could nip in and change the state
3686 ;; of the master during it.
3688 ;; The performance problem is that rlog/prs calls are very expensive; we want
3689 ;; to avoid them as much as possible.
3693 ;; The performance problem, it turns out, simplifies in practice to the
3694 ;; problem of making vc-state fast. The two other functions that call
3695 ;; prs/rlog will not be so commonly used that the slowdown is a problem; one
3696 ;; makes snapshots, the other deletes the calling user's last change in the
3699 ;; The race condition implies that we have to either (a) lock the master
3700 ;; during the entire execution of vc-next-action, or (b) detect and
3701 ;; recover from errors resulting from dispatch on an out-of-date state.
3703 ;; Alternative (a) appears to be infeasible. The problem is that we can't
3704 ;; guarantee that the lock will ever be removed. Suppose a user starts a
3705 ;; checkin, the change message buffer pops up, and the user, having wandered
3706 ;; off to do something else, simply forgets about it?
3708 ;; Alternative (b), on the other hand, works well with a cheap way to speed up
3709 ;; vc-state. Usually, if a file is registered, we can read its locked/
3710 ;; unlocked state and its current owner from its permissions.
3712 ;; This shortcut will fail if someone has manually changed the workfile's
3713 ;; permissions; also if developers are munging the workfile in several
3714 ;; directories, with symlinks to a master (in this latter case, the
3715 ;; permissions shortcut will fail to detect a lock asserted from another
3718 ;; Note that these cases correspond exactly to the errors which could happen
3719 ;; because of a competing checkin/checkout race in between two instances of
3722 ;; For VC's purposes, a workfile/master pair may have the following states:
3724 ;; A. Unregistered. There is a workfile, there is no master.
3726 ;; B. Registered and not locked by anyone.
3728 ;; C. Locked by calling user and unchanged.
3730 ;; D. Locked by the calling user and changed.
3732 ;; E. Locked by someone other than the calling user.
3734 ;; This makes for 25 states and 20 error conditions. Here's the matrix:
3736 ;; VC's idea of state
3738 ;; V Actual state RCS action SCCS action Effect
3740 ;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
3741 ;; B 5 . 6 7 8 co -l get -e checkout
3742 ;; C 9 10 . 11 12 co -u unget; get revert
3743 ;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
3744 ;; E 17 18 19 20 . rcs -u -M -l unget -n ; get -g steal lock
3746 ;; All commands take the master file name as a last argument (not shown).
3748 ;; In the discussion below, a "self-race" is a pathological situation in
3749 ;; which VC operations are being attempted simultaneously by two or more
3750 ;; Emacsen running under the same username.
3752 ;; The vc-next-action code has the following windows:
3755 ;; Between the check for existence of a master file and the call to
3756 ;; admin/checkin in vc-buffer-admin (apparent state A). This window may
3757 ;; never close if the initial-comment feature is on.
3760 ;; Between the call to vc-workfile-unchanged-p in and the immediately
3761 ;; following revert (apparent state C).
3764 ;; Between the call to vc-workfile-unchanged-p in and the following
3765 ;; checkin (apparent state D). This window may never close.
3768 ;; Between the unlock and the immediately following checkout during a
3769 ;; revert operation (apparent state C). Included in window Q.
3772 ;; Between vc-state and the following checkout (apparent state B).
3775 ;; Between vc-state and the following revert (apparent state C).
3776 ;; Includes windows Q and S.
3779 ;; Between vc-state and the following checkin (apparent state
3780 ;; D). This window may never be closed if the user fails to complete the
3781 ;; checkin message. Includes window R.
3784 ;; Between vc-state and the following steal-lock (apparent
3785 ;; state E). This window may never close if the user fails to complete
3786 ;; the steal-lock message. Includes window X.
3789 ;; Between the unlock and the immediately following re-lock during a
3790 ;; steal-lock operation (apparent state E). This window may never close
3791 ;; if the user fails to complete the steal-lock message.
3795 ;; Apparent state A ---
3797 ;; 1. File looked unregistered but is actually registered and not locked.
3799 ;; Potential cause: someone else's admin during window P, with
3800 ;; caller's admin happening before their checkout.
3802 ;; RCS: Prior to version 5.6.4, ci fails with message
3803 ;; "no lock set by <user>". From 5.6.4 onwards, VC uses the new
3804 ;; ci -i option and the message is "<file>,v: already exists".
3805 ;; SCCS: admin will fail with error (ad19).
3807 ;; We can let these errors be passed up to the user.
3809 ;; 2. File looked unregistered but is actually locked by caller, unchanged.
3811 ;; Potential cause: self-race during window P.
3813 ;; RCS: Prior to version 5.6.4, reverts the file to the last saved
3814 ;; version and unlocks it. From 5.6.4 onwards, VC uses the new
3815 ;; ci -i option, failing with message "<file>,v: already exists".
3816 ;; SCCS: will fail with error (ad19).
3818 ;; Either of these consequences is acceptable.
3820 ;; 3. File looked unregistered but is actually locked by caller, changed.
3822 ;; Potential cause: self-race during window P.
3824 ;; RCS: Prior to version 5.6.4, VC registers the caller's workfile as
3825 ;; a delta with a null change comment (the -t- switch will be
3826 ;; ignored). From 5.6.4 onwards, VC uses the new ci -i option,
3827 ;; failing with message "<file>,v: already exists".
3828 ;; SCCS: will fail with error (ad19).
3830 ;; 4. File looked unregistered but is locked by someone else.
3832 ;; Potential cause: someone else's admin during window P, with
3833 ;; caller's admin happening *after* their checkout.
3835 ;; RCS: Prior to version 5.6.4, ci fails with a
3836 ;; "no lock set by <user>" message. From 5.6.4 onwards,
3837 ;; VC uses the new ci -i option, failing with message
3838 ;; "<file>,v: already exists".
3839 ;; SCCS: will fail with error (ad19).
3841 ;; We can let these errors be passed up to the user.
3843 ;; Apparent state B ---
3845 ;; 5. File looked registered and not locked, but is actually unregistered.
3847 ;; Potential cause: master file got nuked during window P.
3849 ;; RCS: will fail with "RCS/<file>: No such file or directory"
3850 ;; SCCS: will fail with error ut4.
3852 ;; We can let these errors be passed up to the user.
3854 ;; 6. File looked registered and not locked, but is actually locked by the
3855 ;; calling user and unchanged.
3857 ;; Potential cause: self-race during window T.
3859 ;; RCS: in the same directory as the previous workfile, co -l will fail
3860 ;; with "co error: writable foo exists; checkout aborted". In any other
3861 ;; directory, checkout will succeed.
3862 ;; SCCS: will fail with ge17.
3864 ;; Either of these consequences is acceptable.
3866 ;; 7. File looked registered and not locked, but is actually locked by the
3867 ;; calling user and changed.
3871 ;; 8. File looked registered and not locked, but is actually locked by another
3874 ;; Potential cause: someone else checks it out during window T.
3876 ;; RCS: co error: revision 1.3 already locked by <user>
3877 ;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
3879 ;; We can let these errors be passed up to the user.
3881 ;; Apparent state C ---
3883 ;; 9. File looks locked by calling user and unchanged, but is unregistered.
3887 ;; 10. File looks locked by calling user and unchanged, but is actually not
3890 ;; Potential cause: a self-race in window U, or by the revert's
3891 ;; landing during window X of some other user's steal-lock or window S
3892 ;; of another user's revert.
3894 ;; RCS: succeeds, refreshing the file from the identical version in
3896 ;; SCCS: fails with error ut4 (p file nonexistent).
3898 ;; Either of these consequences is acceptable.
3900 ;; 11. File is locked by calling user. It looks unchanged, but is actually
3903 ;; Potential cause: the file would have to be touched by a self-race
3906 ;; The revert will succeed, removing whatever changes came with
3907 ;; the touch. It is theoretically possible that work could be lost.
3909 ;; 12. File looks like it's locked by the calling user and unchanged, but
3910 ;; it's actually locked by someone else.
3912 ;; Potential cause: a steal-lock in window V.
3914 ;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
3915 ;; SCCS: fails with error un2
3917 ;; We can pass these errors up to the user.
3919 ;; Apparent state D ---
3921 ;; 13. File looks like it's locked by the calling user and changed, but it's
3922 ;; actually unregistered.
3924 ;; Potential cause: master file got nuked during window P.
3926 ;; RCS: Prior to version 5.6.4, checks in the user's version as an
3927 ;; initial delta. From 5.6.4 onwards, VC uses the new ci -j
3928 ;; option, failing with message "no such file or directory".
3929 ;; SCCS: will fail with error ut4.
3931 ;; This case is kind of nasty. Under RCS prior to version 5.6.4,
3932 ;; VC may fail to detect the loss of previous version information.
3934 ;; 14. File looks like it's locked by the calling user and changed, but it's
3935 ;; actually unlocked.
3937 ;; Potential cause: self-race in window V, or the checkin happening
3938 ;; during the window X of someone else's steal-lock or window S of
3939 ;; someone else's revert.
3941 ;; RCS: ci will fail with "no lock set by <user>".
3942 ;; SCCS: delta will fail with error ut4.
3944 ;; 15. File looks like it's locked by the calling user and changed, but it's
3945 ;; actually locked by the calling user and unchanged.
3947 ;; Potential cause: another self-race --- a whole checkin/checkout
3948 ;; sequence by the calling user would have to land in window R.
3950 ;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
3951 ;; RCS: reverts to the file state as of the second user's checkin, leaving
3952 ;; the file unlocked.
3954 ;; It is theoretically possible that work could be lost under RCS.
3956 ;; 16. File looks like it's locked by the calling user and changed, but it's
3957 ;; actually locked by a different user.
3959 ;; RCS: ci error: no lock set by <user>
3960 ;; SCCS: unget will fail with error un2
3962 ;; We can pass these errors up to the user.
3964 ;; Apparent state E ---
3966 ;; 17. File looks like it's locked by some other user, but it's actually
3971 ;; 18. File looks like it's locked by some other user, but it's actually
3974 ;; Potential cause: someone released a lock during window W.
3976 ;; RCS: The calling user will get the lock on the file.
3977 ;; SCCS: unget -n will fail with cm4.
3979 ;; Either of these consequences will be OK.
3981 ;; 19. File looks like it's locked by some other user, but it's actually
3982 ;; locked by the calling user and unchanged.
3984 ;; Potential cause: the other user relinquishing a lock followed by
3985 ;; a self-race, both in window W.
3987 ;; Under both RCS and SCCS, both unlock and lock will succeed, making
3988 ;; the sequence a no-op.
3990 ;; 20. File looks like it's locked by some other user, but it's actually
3991 ;; locked by the calling user and changed.
3997 ;; In order of decreasing severity:
3999 ;; Cases 11 and 15 are the only ones that potentially lose work.
4000 ;; They would require a self-race for this to happen.
4002 ;; Case 13 in RCS loses information about previous deltas, retaining
4003 ;; only the information in the current workfile. This can only happen
4004 ;; if the master file gets nuked in window P.
4006 ;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
4007 ;; no change comment in the master. This would require a self-race in
4008 ;; window P or R respectively.
4010 ;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
4012 ;; Unfortunately, it appears to me that no recovery is possible in these
4013 ;; cases. They don't yield error messages, so there's no way to tell that
4014 ;; a race condition has occurred.
4016 ;; All other cases don't change either the workfile or the master, and
4017 ;; trigger command errors which the user will see.
4019 ;; Thus, there is no explicit recovery code.
4021 ;; arch-tag: ca82c1de-3091-4e26-af92-460abc6213a6