(vc-process-sentinel): Fix bug introduced in last change:
[emacs.git] / lisp / vc.el
blob497ba1e0df4fff75ed24c16515a76a04d367b259
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, 2008 Free Software Foundation, Inc.
6 ;; Author: FSF (see below for full credits)
7 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
8 ;; Keywords: tools
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
27 ;;; Credits:
29 ;; VC was initially designed and implemented by Eric S. Raymond
30 ;; <esr@thyrsus.com> in 1992. Over the years, many other people have
31 ;; contributed substantial amounts of work to VC. These include:
33 ;; Per Cederqvist <ceder@lysator.liu.se>
34 ;; Paul Eggert <eggert@twinsun.com>
35 ;; Sebastian Kremer <sk@thp.uni-koeln.de>
36 ;; Martin Lorentzson <martinl@gnu.org>
37 ;; Dave Love <fx@gnu.org>
38 ;; Stefan Monnier <monnier@cs.yale.edu>
39 ;; J.D. Smith <jdsmith@alum.mit.edu>
40 ;; Andre Spiegel <spiegel@gnu.org>
41 ;; Richard Stallman <rms@gnu.org>
42 ;; Thien-Thi Nguyen <ttn@gnu.org>
44 ;; In July 2007 ESR returned and redesigned the mode to cope better
45 ;; with modern version-control systems that do commits by fileset
46 ;; rather than per individual file.
48 ;; Features in the new version:
49 ;; * Key commands (vc-next-action = C-x v v, vc-print-log = C-x v l, vc-revert
50 ;; = C-x v u, vc-rollback = C-x v c, vc-diff = C-x v =, vc-update = C-x v +)
51 ;; now operate on filesets rather than individual files.
52 ;; * The fileset for a command is either (a) all marked files in VC-dired
53 ;; mode, (b) the currently visited file if it's under version control,
54 ;; or (c) the current directory if the visited buffer is not under
55 ;; version control and a wildcarding-enable flag has been set.
57 ;; If you maintain a client of the mode or customize it in your .emacs,
58 ;; note that some backend functions which formerly took single file arguments
59 ;; now take a list of files. These include: register, checkin, print-log,
60 ;; rollback, and diff.
62 ;;; Commentary:
64 ;; This mode is fully documented in the Emacs user's manual.
66 ;; Supported version-control systems presently include CVS, RCS, GNU
67 ;; Arch, Subversion, Bzr, Git, Mercurial, Meta-CVS, Monotone and SCCS
68 ;; (or its free replacement, CSSC).
70 ;; Some features will not work with old RCS versions. Where
71 ;; appropriate, VC finds out which version you have, and allows or
72 ;; disallows those features (stealing locks, for example, works only
73 ;; from 5.6.2 onwards).
74 ;; Even initial checkins will fail if your RCS version is so old that ci
75 ;; doesn't understand -t-; this has been known to happen to people running
76 ;; NExTSTEP 3.0.
78 ;; You can support the RCS -x option by customizing vc-rcs-master-templates.
80 ;; Proper function of the SCCS diff commands requires the shellscript vcdiff
81 ;; to be installed somewhere on Emacs's path for executables.
83 ;; If your site uses the ChangeLog convention supported by Emacs, the
84 ;; function `log-edit-comment-to-change-log' could prove a useful checkin hook,
85 ;; although you might prefer to use C-c C-a (i.e. `log-edit-insert-changelog')
86 ;; from the commit buffer instead or to set `log-edit-setup-invert'.
88 ;; The vc code maintains some internal state in order to reduce expensive
89 ;; version-control operations to a minimum. Some names are only computed
90 ;; once. If you perform version control operations with the backend while
91 ;; vc's back is turned, or move/rename master files while vc is running,
92 ;; vc may get seriously confused. Don't do these things!
94 ;; Developer's notes on some concurrency issues are included at the end of
95 ;; the file.
97 ;; ADDING SUPPORT FOR OTHER BACKENDS
99 ;; VC can use arbitrary version control systems as a backend. To add
100 ;; support for a new backend named SYS, write a library vc-sys.el that
101 ;; contains functions of the form `vc-sys-...' (note that SYS is in lower
102 ;; case for the function and library names). VC will use that library if
103 ;; you put the symbol SYS somewhere into the list of
104 ;; `vc-handled-backends'. Then, for example, if `vc-sys-registered'
105 ;; returns non-nil for a file, all SYS-specific versions of VC commands
106 ;; will be available for that file.
108 ;; VC keeps some per-file information in the form of properties (see
109 ;; vc-file-set/getprop in vc-hooks.el). The backend-specific functions
110 ;; do not generally need to be aware of these properties. For example,
111 ;; `vc-sys-working-revision' should compute the working revision and
112 ;; return it; it should not look it up in the property, and it needn't
113 ;; store it there either. However, if a backend-specific function does
114 ;; store a value in a property, that value takes precedence over any
115 ;; value that the generic code might want to set (check for uses of
116 ;; the macro `with-vc-properties' in vc.el).
118 ;; In the list of functions below, each identifier needs to be prepended
119 ;; with `vc-sys-'. Some of the functions are mandatory (marked with a
120 ;; `*'), others are optional (`-').
122 ;; BACKEND PROPERTIES
124 ;; * revision-granularity
126 ;; Takes no arguments. Returns either 'file or 'repository. Backends
127 ;; that return 'file have per-file revision numbering; backends
128 ;; that return 'repository have per-repository revision numbering,
129 ;; so a revision level implicitly identifies a changeset
131 ;; STATE-QUERYING FUNCTIONS
133 ;; * registered (file)
135 ;; Return non-nil if FILE is registered in this backend. Both this
136 ;; function as well as `state' should be careful to fail gracefully
137 ;; in the event that the backend executable is absent. It is
138 ;; preferable that this function's body is autoloaded, that way only
139 ;; calling vc-registered does not cause the backend to be loaded
140 ;; (all the vc-FOO-registered functions are called to try to find
141 ;; the controlling backend for FILE.
143 ;; * state (file)
145 ;; Return the current version control state of FILE. For a list of
146 ;; possible values, see `vc-state'. This function should do a full and
147 ;; reliable state computation; it is usually called immediately after
148 ;; C-x v v. If you want to use a faster heuristic when visiting a
149 ;; file, put that into `state-heuristic' below.
151 ;; - state-heuristic (file)
153 ;; If provided, this function is used to estimate the version control
154 ;; state of FILE at visiting time. It should be considerably faster
155 ;; than the implementation of `state'. For a list of possible values,
156 ;; see the doc string of `vc-state'.
158 ;; - dir-state (dir)
160 ;; If provided, this function is used to find the version control
161 ;; state of as many files as possible in DIR, and all subdirectories
162 ;; of DIR, in a fast way; it is used to avoid expensive indivitual
163 ;; vc-state calls. The function should not return anything, but
164 ;; rather store the files' states into the corresponding properties.
165 ;; Two properties are required: `vc-backend' and `vc-state'. (Note:
166 ;; in older versions this method was not required to recurse into
167 ;; subdirectories.)
169 ;; * working-revision (file)
171 ;; Return the working revision of FILE. This is the revision fetched
172 ;; by the last checkout or upate, not necessarily the same thing as the
173 ;; head or tip revision. Should return "0" for a file added but not yet
174 ;; committed.
176 ;; - latest-on-branch-p (file)
178 ;; Return non-nil if the working revision of FILE is the latest revision
179 ;; on its branch (many VCSes call this the 'tip' or 'head' revision).
180 ;; The default implementation always returns t, which means that
181 ;; working with non-current revisions is not supported by default.
183 ;; * checkout-model (file)
185 ;; Indicate whether FILE needs to be "checked out" before it can be
186 ;; edited. See `vc-checkout-model' for a list of possible values.
188 ;; - workfile-unchanged-p (file)
190 ;; Return non-nil if FILE is unchanged from the working revision.
191 ;; This function should do a brief comparison of FILE's contents
192 ;; with those of the repository master of the working revision. If
193 ;; the backend does not have such a brief-comparison feature, the
194 ;; default implementation of this function can be used, which
195 ;; delegates to a full vc-BACKEND-diff. (Note that vc-BACKEND-diff
196 ;; must not run asynchronously in this case, see variable
197 ;; `vc-disable-async-diff'.)
199 ;; - mode-line-string (file)
201 ;; If provided, this function should return the VC-specific mode
202 ;; line string for FILE. The returned string should have a
203 ;; `help-echo' property which is the text to be displayed as a
204 ;; tooltip when the mouse hovers over the VC entry on the mode-line.
205 ;; The default implementation deals well with all states that
206 ;; `vc-state' can return.
208 ;; - dired-state-info (file)
210 ;; Translate the `vc-state' property of FILE into a string that can be
211 ;; used in a vc-dired buffer. The default implementation deals well
212 ;; with all states that `vc-state' can return.
214 ;; STATE-CHANGING FUNCTIONS
216 ;; * create-repo (backend)
218 ;; Create an empty repository in the current directory and initialize
219 ;; it so VC mode can add files to it. For file-oriented systems, this
220 ;; need do no more than create a subdirectory with the right name.
222 ;; * register (files &optional rev comment)
224 ;; Register FILES in this backend. Optionally, an initial revision REV
225 ;; and an initial description of the file, COMMENT, may be specified,
226 ;; but it is not guaranteed that the backend will do anything with this.
227 ;; The implementation should pass the value of vc-register-switches
228 ;; to the backend command. (Note: in older versions of VC, this
229 ;; command took a single file argument and not a list.)
231 ;; - init-revision (file)
233 ;; The initial revision to use when registering FILE if one is not
234 ;; specified by the user. If not provided, the variable
235 ;; vc-default-init-revision is used instead.
237 ;; - responsible-p (file)
239 ;; Return non-nil if this backend considers itself "responsible" for
240 ;; FILE, which can also be a directory. This function is used to find
241 ;; out what backend to use for registration of new files and for things
242 ;; like change log generation. The default implementation always
243 ;; returns nil.
245 ;; - could-register (file)
247 ;; Return non-nil if FILE could be registered under this backend. The
248 ;; default implementation always returns t.
250 ;; - receive-file (file rev)
252 ;; Let this backend "receive" a file that is already registered under
253 ;; another backend. The default implementation simply calls `register'
254 ;; for FILE, but it can be overridden to do something more specific,
255 ;; e.g. keep revision numbers consistent or choose editing modes for
256 ;; FILE that resemble those of the other backend.
258 ;; - unregister (file)
260 ;; Unregister FILE from this backend. This is only needed if this
261 ;; backend may be used as a "more local" backend for temporary editing.
263 ;; * checkin (files rev comment)
265 ;; Commit changes in FILES to this backend. If REV is non-nil, that
266 ;; should become the new revision number (not all backends do
267 ;; anything with it). COMMENT is used as a check-in comment. The
268 ;; implementation should pass the value of vc-checkin-switches to
269 ;; the backend command. (Note: in older versions of VC, this
270 ;; command took a single file argument and not a list.)
272 ;; * find-revision (file rev buffer)
274 ;; Fetch revision REV of file FILE and put it into BUFFER.
275 ;; If REV is the empty string, fetch the head of the trunk.
276 ;; The implementation should pass the value of vc-checkout-switches
277 ;; to the backend command.
279 ;; * checkout (file &optional editable rev)
281 ;; Check out revision REV of FILE into the working area. If EDITABLE
282 ;; is non-nil, FILE should be writable by the user and if locking is
283 ;; used for FILE, a lock should also be set. If REV is non-nil, that
284 ;; is the revision to check out (default is the working revision).
285 ;; If REV is t, that means to check out the head of the current branch;
286 ;; if it is the empty string, check out the head of the trunk.
287 ;; The implementation should pass the value of vc-checkout-switches
288 ;; to the backend command.
290 ;; * revert (file &optional contents-done)
292 ;; Revert FILE back to the working revision. If optional
293 ;; arg CONTENTS-DONE is non-nil, then the contents of FILE have
294 ;; already been reverted from a version backup, and this function
295 ;; only needs to update the status of FILE within the backend.
297 ;; - rollback (files)
299 ;; Remove the tip revision of each of FILES from the repository. If
300 ;; this function is not provided, trying to cancel a revision is
301 ;; caught as an error. (Most backends don't provide it.) (Also
302 ;; note that older versions of this backend command were called
303 ;; 'cancel-version' and took a single file arg, not a list of
304 ;; files.)
306 ;; - merge (file rev1 rev2)
308 ;; Merge the changes between REV1 and REV2 into the current working file.
310 ;; - merge-news (file)
312 ;; Merge recent changes from the current branch into FILE.
314 ;; - steal-lock (file &optional revision)
316 ;; Steal any lock on the working revision of FILE, or on REVISION if
317 ;; that is provided. This function is only needed if locking is
318 ;; used for files under this backend, and if files can indeed be
319 ;; locked by other users.
321 ;; - modify-change-comment (files rev comment)
323 ;; Modify the change comments associated with the files at the
324 ;; given revision. This is optional, many backends do not support it.
326 ;; HISTORY FUNCTIONS
328 ;; * print-log (files &optional buffer)
330 ;; Insert the revision log for FILES into BUFFER, or the *vc* buffer
331 ;; if BUFFER is nil. (Note: older versions of this function expected
332 ;; only a single file argument.)
334 ;; - log-view-mode ()
336 ;; Mode to use for the output of print-log. This defaults to
337 ;; `log-view-mode' and is expected to be changed (if at all) to a derived
338 ;; mode of `log-view-mode'.
340 ;; - show-log-entry (revision)
342 ;; If provided, search the log entry for REVISION in the current buffer,
343 ;; and make sure it is displayed in the buffer's window. The default
344 ;; implementation of this function works for RCS-style logs.
346 ;; - wash-log (file)
348 ;; Remove all non-comment information from the output of print-log.
350 ;; - logentry-check ()
352 ;; If defined, this function is run to find out whether the user
353 ;; entered a valid log entry for check-in. The log entry is in the
354 ;; current buffer, and if it is not a valid one, the function should
355 ;; throw an error.
357 ;; - comment-history (file)
359 ;; Return a string containing all log entries that were made for FILE.
360 ;; This is used for transferring a file from one backend to another,
361 ;; retaining comment information. The default implementation of this
362 ;; function does this by calling print-log and then wash-log, and
363 ;; returning the resulting buffer contents as a string.
365 ;; - update-changelog (files)
367 ;; Using recent log entries, create ChangeLog entries for FILES, or for
368 ;; all files at or below the default-directory if FILES is nil. The
369 ;; default implementation runs rcs2log, which handles RCS- and
370 ;; CVS-style logs.
372 ;; * diff (files &optional rev1 rev2 buffer)
374 ;; Insert the diff for FILE into BUFFER, or the *vc-diff* buffer if
375 ;; BUFFER is nil. If REV1 and REV2 are non-nil, report differences
376 ;; from REV1 to REV2. If REV1 is nil, use the working revision (as
377 ;; found in the repository) as the older revision; if REV2 is nil,
378 ;; use the current working-copy contents as the newer revision. This
379 ;; function should pass the value of (vc-switches BACKEND 'diff) to
380 ;; the backend command. It should return a status of either 0 (no
381 ;; differences found), or 1 (either non-empty diff or the diff is
382 ;; run asynchronously).
384 ;; - revision-completion-table (files)
386 ;; Return a completion table for existing revisions of FILES.
387 ;; The default is to not use any completion table.
389 ;; - annotate-command (file buf &optional rev)
391 ;; If this function is provided, it should produce an annotated display
392 ;; of FILE in BUF, relative to revision REV. Annotation means each line
393 ;; of FILE displayed is prefixed with version information associated with
394 ;; its addition (deleted lines leave no history) and that the text of the
395 ;; file is fontified according to age.
397 ;; - annotate-time ()
399 ;; Only required if `annotate-command' is defined for the backend.
400 ;; Return the time of the next line of annotation at or after point,
401 ;; as a floating point fractional number of days. The helper
402 ;; function `vc-annotate-convert-time' may be useful for converting
403 ;; multi-part times as returned by `current-time' and `encode-time'
404 ;; to this format. Return nil if no more lines of annotation appear
405 ;; in the buffer. You can safely assume that point is placed at the
406 ;; beginning of each line, starting at `point-min'. The buffer that
407 ;; point is placed in is the Annotate output, as defined by the
408 ;; relevant backend. This function also affects how much of the line
409 ;; is fontified; where it leaves point is where fontification begins.
411 ;; - annotate-current-time ()
413 ;; Only required if `annotate-command' is defined for the backend,
414 ;; AND you'd like the current time considered to be anything besides
415 ;; (vc-annotate-convert-time (current-time)) -- i.e. the current
416 ;; time with hours, minutes, and seconds included. Probably safe to
417 ;; ignore. Return the current-time, in units of fractional days.
419 ;; - annotate-extract-revision-at-line ()
421 ;; Only required if `annotate-command' is defined for the backend.
422 ;; Invoked from a buffer in vc-annotate-mode, return the revision
423 ;; corresponding to the current line, or nil if there is no revision
424 ;; corresponding to the current line.
426 ;; SNAPSHOT SYSTEM
428 ;; - create-snapshot (dir name branchp)
430 ;; Take a snapshot of the current state of files under DIR and name it
431 ;; NAME. This should make sure that files are up-to-date before
432 ;; proceeding with the action. DIR can also be a file and if BRANCHP
433 ;; is specified, NAME should be created as a branch and DIR should be
434 ;; checked out under this new branch. The default implementation does
435 ;; not support branches but does a sanity check, a tree traversal and
436 ;; for each file calls `assign-name'.
438 ;; - assign-name (file name)
440 ;; Give name NAME to the working revision of FILE, assuming it is
441 ;; up-to-date. Only used by the default version of `create-snapshot'.
443 ;; - retrieve-snapshot (dir name update)
445 ;; Retrieve a named snapshot of all registered files at or below DIR.
446 ;; If UPDATE is non-nil, then update buffers of any files in the
447 ;; snapshot that are currently visited. The default implementation
448 ;; does a sanity check whether there aren't any uncommitted changes at
449 ;; or below DIR, and then performs a tree walk, using the `checkout'
450 ;; function to retrieve the corresponding revisions.
452 ;; MISCELLANEOUS
454 ;; - make-version-backups-p (file)
456 ;; Return non-nil if unmodified repository revisions of FILE should be
457 ;; backed up locally. If this is done, VC can perform `diff' and
458 ;; `revert' operations itself, without calling the backend system. The
459 ;; default implementation always returns nil.
461 ;; - repository-hostname (dirname)
463 ;; Return the hostname that the backend will have to contact
464 ;; in order to operate on a file in DIRNAME. If the return value
465 ;; is nil, it means that the repository is local.
466 ;; This function is used in `vc-stay-local-p' which backends can use
467 ;; for their convenience.
469 ;; - previous-revision (file rev)
471 ;; Return the revision number that precedes REV for FILE, or nil if no such
472 ;; revision exists.
474 ;; - next-revision (file rev)
476 ;; Return the revision number that follows REV for FILE, or nil if no such
477 ;; revision exists.
479 ;; - check-headers ()
481 ;; Return non-nil if the current buffer contains any version headers.
483 ;; - clear-headers ()
485 ;; In the current buffer, reset all version headers to their unexpanded
486 ;; form. This function should be provided if the state-querying code
487 ;; for this backend uses the version headers to determine the state of
488 ;; a file. This function will then be called whenever VC changes the
489 ;; version control state in such a way that the headers would give
490 ;; wrong information.
492 ;; - delete-file (file)
494 ;; Delete FILE and mark it as deleted in the repository. If this
495 ;; function is not provided, the command `vc-delete-file' will
496 ;; signal an error.
498 ;; - rename-file (old new)
500 ;; Rename file OLD to NEW, both in the working area and in the
501 ;; repository. If this function is not provided, the renaming
502 ;; will be done by (vc-delete-file old) and (vc-register new).
504 ;; - find-file-hook ()
506 ;; Operation called in current buffer when opening a file. This can
507 ;; be used by the backend to setup some local variables it might need.
509 ;; - find-file-not-found-hook ()
511 ;; Operation called in current buffer when opening a non-existing file.
512 ;; By default, this asks the user if she wants to check out the file.
514 ;; - extra-menu ()
516 ;; Return a menu keymap, the items in the keymap will appear at the
517 ;; end of the Version Control menu. The goal is to allow backends
518 ;; to specify extra menu items that appear in the VC menu. This way
519 ;; you can provide menu entries for functionality that is specific
520 ;; to your backend and which does not map to any of the VC generic
521 ;; concepts.
523 ;;; Todo:
525 ;; - Make vc-checkin avoid reverting the buffer if has not changed
526 ;; after the checkin. Comparing (md5 BUFFER) to (md5 FILE) should
527 ;; be enough.
529 ;; - vc-update/vc-merge should deal with VC systems that don't
530 ;; update/merge on a file basis, but on a whole repository basis.
532 ;; - vc-register should register multiple files at a time. The
533 ;; `register' backend function already supports that.
535 ;; - the *VC-log* buffer needs font-locking.
537 ;; - make it easier to write logs, maybe C-x 4 a should add to the log
538 ;; buffer if there's one instead of the ChangeLog.
540 ;; - make vc-state for all backends return 'unregistered instead of
541 ;; nil for unregistered files, then update vc-next-action.
543 ;; - deal with push/pull operations.
545 ;; - decide if vc-status should replace vc-dired.
547 ;; - vc-status needs a menu, mouse bindings and some color bling.
549 ;;; Code:
551 (require 'vc-hooks)
552 (require 'ring)
553 (eval-when-compile
554 (require 'cl)
555 (require 'compile)
556 (require 'dired) ; for dired-map-over-marks macro
557 (require 'dired-aux)) ; for dired-kill-{line,tree}
559 (if (not (assoc 'vc-parent-buffer minor-mode-alist))
560 (setq minor-mode-alist
561 (cons '(vc-parent-buffer vc-parent-buffer-name)
562 minor-mode-alist)))
564 ;; General customization
566 (defgroup vc nil
567 "Version-control system in Emacs."
568 :group 'tools)
570 (defcustom vc-suppress-confirm nil
571 "If non-nil, treat user as expert; suppress yes-no prompts on some things."
572 :type 'boolean
573 :group 'vc)
575 (defcustom vc-delete-logbuf-window t
576 "If non-nil, delete the *VC-log* buffer and window after each logical action.
577 If nil, bury that buffer instead.
578 This is most useful if you have multiple windows on a frame and would like to
579 preserve the setting."
580 :type 'boolean
581 :group 'vc)
583 (defcustom vc-initial-comment nil
584 "If non-nil, prompt for initial comment when a file is registered."
585 :type 'boolean
586 :group 'vc)
588 (defcustom vc-default-init-revision "1.1"
589 "A string used as the default revision number when a new file is registered.
590 This can be overridden by giving a prefix argument to \\[vc-register]. This
591 can also be overridden by a particular VC backend."
592 :type 'string
593 :group 'vc
594 :version "20.3")
596 (defcustom vc-command-messages nil
597 "If non-nil, display run messages from back-end commands."
598 :type 'boolean
599 :group 'vc)
601 (defcustom vc-checkin-switches nil
602 "A string or list of strings specifying extra switches for checkin.
603 These are passed to the checkin program by \\[vc-checkin]."
604 :type '(choice (const :tag "None" nil)
605 (string :tag "Argument String")
606 (repeat :tag "Argument List"
607 :value ("")
608 string))
609 :group 'vc)
611 (defcustom vc-checkout-switches nil
612 "A string or list of strings specifying extra switches for checkout.
613 These are passed to the checkout program by \\[vc-checkout]."
614 :type '(choice (const :tag "None" nil)
615 (string :tag "Argument String")
616 (repeat :tag "Argument List"
617 :value ("")
618 string))
619 :group 'vc)
621 (defcustom vc-register-switches nil
622 "A string or list of strings; extra switches for registering a file.
623 These are passed to the checkin program by \\[vc-register]."
624 :type '(choice (const :tag "None" nil)
625 (string :tag "Argument String")
626 (repeat :tag "Argument List"
627 :value ("")
628 string))
629 :group 'vc)
631 (defcustom vc-dired-listing-switches "-al"
632 "Switches passed to `ls' for vc-dired. MUST contain the `l' option."
633 :type 'string
634 :group 'vc
635 :version "21.1")
637 (defcustom vc-dired-recurse t
638 "If non-nil, show directory trees recursively in VC Dired."
639 :type 'boolean
640 :group 'vc
641 :version "20.3")
643 (defcustom vc-dired-terse-display t
644 "If non-nil, show only locked or locally modified files in VC Dired."
645 :type 'boolean
646 :group 'vc
647 :version "20.3")
649 (defcustom vc-diff-switches nil
650 "A string or list of strings specifying switches for diff under VC.
651 When running diff under a given BACKEND, VC concatenates the values of
652 `diff-switches', `vc-diff-switches', and `vc-BACKEND-diff-switches' to
653 get the switches for that command. Thus, `vc-diff-switches' should
654 contain switches that are specific to version control, but not
655 specific to any particular backend."
656 :type '(choice (const :tag "None" nil)
657 (string :tag "Argument String")
658 (repeat :tag "Argument List"
659 :value ("")
660 string))
661 :group 'vc
662 :version "21.1")
664 (defcustom vc-diff-knows-L nil
665 "*Indicates whether diff understands the -L option.
666 The value is either `yes', `no', or nil. If it is nil, VC tries
667 to use -L and sets this variable to remember whether it worked."
668 :type '(choice (const :tag "Work out" nil) (const yes) (const no))
669 :group 'vc)
671 (defcustom vc-allow-async-revert nil
672 "Specifies whether the diff during \\[vc-revert] may be asynchronous.
673 Enabling this option means that you can confirm a revert operation even
674 if the local changes in the file have not been found and displayed yet."
675 :type '(choice (const :tag "No" nil)
676 (const :tag "Yes" t))
677 :group 'vc
678 :version "22.1")
680 ;;;###autoload
681 (defcustom vc-checkout-hook nil
682 "Normal hook (list of functions) run after checking out a file.
683 See `run-hooks'."
684 :type 'hook
685 :group 'vc
686 :version "21.1")
688 (defcustom vc-annotate-display-mode 'fullscale
689 "Which mode to color the output of \\[vc-annotate] with by default."
690 :type '(choice (const :tag "By Color Map Range" nil)
691 (const :tag "Scale to Oldest" scale)
692 (const :tag "Scale Oldest->Newest" fullscale)
693 (number :tag "Specify Fractional Number of Days"
694 :value "20.5"))
695 :group 'vc)
697 ;;;###autoload
698 (defcustom vc-checkin-hook nil
699 "Normal hook (list of functions) run after commit or file checkin.
700 See also `log-edit-done-hook'."
701 :type 'hook
702 :options '(log-edit-comment-to-change-log)
703 :group 'vc)
705 ;;;###autoload
706 (defcustom vc-before-checkin-hook nil
707 "Normal hook (list of functions) run before a commit or a file checkin.
708 See `run-hooks'."
709 :type 'hook
710 :group 'vc)
712 (defcustom vc-logentry-check-hook nil
713 "Normal hook run by `vc-backend-logentry-check'.
714 Use this to impose your own rules on the entry in addition to any the
715 version control backend imposes itself."
716 :type 'hook
717 :group 'vc)
719 ;; Annotate customization
720 (defcustom vc-annotate-color-map
721 (if (and (tty-display-color-p) (<= (display-color-cells) 8))
722 ;; A custom sorted TTY colormap
723 (let* ((colors
724 (sort
725 (delq nil
726 (mapcar (lambda (x)
727 (if (not (or
728 (string-equal (car x) "white")
729 (string-equal (car x) "black") ))
730 (car x)))
731 (tty-color-alist)))
732 (lambda (a b)
733 (cond
734 ((or (string-equal a "red") (string-equal b "blue")) t)
735 ((or (string-equal b "red") (string-equal a "blue")) nil)
736 ((string-equal a "yellow") t)
737 ((string-equal b "yellow") nil)
738 ((string-equal a "cyan") t)
739 ((string-equal b "cyan") nil)
740 ((string-equal a "green") t)
741 ((string-equal b "green") nil)
742 ((string-equal a "magenta") t)
743 ((string-equal b "magenta") nil)
744 (t (string< a b))))))
745 (date 20.)
746 (delta (/ (- 360. date) (1- (length colors)))))
747 (mapcar (lambda (x)
748 (prog1
749 (cons date x)
750 (setq date (+ date delta)))) colors))
751 ;; Normal colormap: hue stepped from 0-240deg, value=1., saturation=0.75
752 '(( 20. . "#FF3F3F")
753 ( 40. . "#FF6C3F")
754 ( 60. . "#FF993F")
755 ( 80. . "#FFC63F")
756 (100. . "#FFF33F")
757 (120. . "#DDFF3F")
758 (140. . "#B0FF3F")
759 (160. . "#83FF3F")
760 (180. . "#56FF3F")
761 (200. . "#3FFF56")
762 (220. . "#3FFF83")
763 (240. . "#3FFFB0")
764 (260. . "#3FFFDD")
765 (280. . "#3FF3FF")
766 (300. . "#3FC6FF")
767 (320. . "#3F99FF")
768 (340. . "#3F6CFF")
769 (360. . "#3F3FFF")))
770 "Association list of age versus color, for \\[vc-annotate].
771 Ages are given in units of fractional days. Default is eighteen
772 steps using a twenty day increment, from red to blue. For TTY
773 displays with 8 or fewer colors, the default is red to blue with
774 all other colors between (excluding black and white)."
775 :type 'alist
776 :group 'vc)
778 (defcustom vc-annotate-very-old-color "#3F3FFF"
779 "Color for lines older than the current color range in \\[vc-annotate]]."
780 :type 'string
781 :group 'vc)
783 (defcustom vc-annotate-background "black"
784 "Background color for \\[vc-annotate].
785 Default color is used if nil."
786 :type 'string
787 :group 'vc)
789 (defcustom vc-annotate-menu-elements '(2 0.5 0.1 0.01)
790 "Menu elements for the mode-specific menu of VC-Annotate mode.
791 List of factors, used to expand/compress the time scale. See `vc-annotate'."
792 :type '(repeat number)
793 :group 'vc)
795 (defvar vc-annotate-mode-map
796 (let ((m (make-sparse-keymap)))
797 (define-key m "A" 'vc-annotate-revision-previous-to-line)
798 (define-key m "D" 'vc-annotate-show-diff-revision-at-line)
799 (define-key m "J" 'vc-annotate-revision-at-line)
800 (define-key m "L" 'vc-annotate-show-log-revision-at-line)
801 (define-key m "N" 'vc-annotate-next-revision)
802 (define-key m "P" 'vc-annotate-prev-revision)
803 (define-key m "W" 'vc-annotate-working-revision)
804 (define-key m "V" 'vc-annotate-toggle-annotation-visibility)
806 "Local keymap used for VC-Annotate mode.")
808 ;; Header-insertion hair
810 (defcustom vc-static-header-alist
811 '(("\\.c\\'" .
812 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
813 "*Associate static header string templates with file types.
814 A \%s in the template is replaced with the first string associated with
815 the file's version control type in `vc-header-alist'."
816 :type '(repeat (cons :format "%v"
817 (regexp :tag "File Type")
818 (string :tag "Header String")))
819 :group 'vc)
821 (defcustom vc-comment-alist
822 '((nroff-mode ".\\\"" ""))
823 "*Special comment delimiters for generating VC headers.
824 Add an entry in this list if you need to override the normal `comment-start'
825 and `comment-end' variables. This will only be necessary if the mode language
826 is sensitive to blank lines."
827 :type '(repeat (list :format "%v"
828 (symbol :tag "Mode")
829 (string :tag "Comment Start")
830 (string :tag "Comment End")))
831 :group 'vc)
833 (defcustom vc-checkout-carefully (= (user-uid) 0)
834 "*Non-nil means be extra-careful in checkout.
835 Verify that the file really is not locked
836 and that its contents match what the master file says."
837 :type 'boolean
838 :group 'vc)
839 (make-obsolete-variable 'vc-checkout-carefully
840 "the corresponding checks are always done now."
841 "21.1")
844 ;; Variables the user doesn't need to know about.
845 (defvar vc-log-operation nil)
846 (defvar vc-log-after-operation-hook nil)
848 ;; In a log entry buffer, this is a local variable
849 ;; that points to the buffer for which it was made
850 ;; (either a file, or a VC dired buffer).
851 (defvar vc-parent-buffer nil)
852 (put 'vc-parent-buffer 'permanent-local t)
853 (defvar vc-parent-buffer-name nil)
854 (put 'vc-parent-buffer-name 'permanent-local t)
856 (defvar vc-disable-async-diff nil
857 "VC sets this to t locally to disable some async diff operations.
858 Backends that offer asynchronous diffs should respect this variable
859 in their implementation of vc-BACKEND-diff.")
861 (defvar vc-log-fileset)
862 (defvar vc-log-revision)
864 (defvar vc-dired-mode nil)
865 (make-variable-buffer-local 'vc-dired-mode)
867 ;; File property caching
869 (defun vc-clear-context ()
870 "Clear all cached file properties."
871 (interactive)
872 (fillarray vc-file-prop-obarray 0))
874 (defmacro with-vc-properties (files form settings)
875 "Execute FORM, then maybe set per-file properties for FILES.
876 SETTINGS is an association list of property/value pairs. After
877 executing FORM, set those properties from SETTINGS that have not yet
878 been updated to their corresponding values."
879 (declare (debug t))
880 `(let ((vc-touched-properties (list t)))
881 ,form
882 (dolist (file ,files)
883 (dolist (setting ,settings)
884 (let ((property (car setting)))
885 (unless (memq property vc-touched-properties)
886 (put (intern file vc-file-prop-obarray)
887 property (cdr setting))))))))
889 ;; Two macros for elisp programming
891 ;;;###autoload
892 (defmacro with-vc-file (file comment &rest body)
893 "Check out a writable copy of FILE if necessary, then execute BODY.
894 Check in FILE with COMMENT (a string) after BODY has been executed.
895 FILE is passed through `expand-file-name'; BODY executed within
896 `save-excursion'. If FILE is not under version control, or you are
897 using a locking version-control system and the file is locked by
898 somebody else, signal error."
899 (declare (debug t) (indent 2))
900 (let ((filevar (make-symbol "file")))
901 `(let ((,filevar (expand-file-name ,file)))
902 (or (vc-backend ,filevar)
903 (error "File not under version control: `%s'" file))
904 (unless (vc-editable-p ,filevar)
905 (let ((state (vc-state ,filevar)))
906 (if (stringp state)
907 (error "`%s' is locking `%s'" state ,filevar)
908 (vc-checkout ,filevar t))))
909 (save-excursion
910 ,@body)
911 (vc-checkin (list ,filevar) nil ,comment))))
913 ;;;###autoload
914 (defmacro edit-vc-file (file comment &rest body)
915 "Edit FILE under version control, executing body.
916 Checkin with COMMENT after executing BODY.
917 This macro uses `with-vc-file', passing args to it.
918 However, before executing BODY, find FILE, and after BODY, save buffer."
919 (declare (debug t) (indent 2))
920 (let ((filevar (make-symbol "file")))
921 `(let ((,filevar (expand-file-name ,file)))
922 (with-vc-file
923 ,filevar ,comment
924 (set-buffer (find-file-noselect ,filevar))
925 ,@body
926 (save-buffer)))))
928 ;; Common command execution logic to be used by backends
930 (defun vc-process-filter (p s)
931 "An alternative output filter for async process P.
932 One difference with the default filter is that this inserts S after markers.
933 Another is that undo information is not kept."
934 (with-current-buffer (process-buffer p)
935 (save-excursion
936 (let ((buffer-undo-list t)
937 (inhibit-read-only t))
938 (goto-char (process-mark p))
939 (insert s)
940 (set-marker (process-mark p) (point))))))
942 (defun vc-setup-buffer (&optional buf)
943 "Prepare BUF for executing a VC command and make it current.
944 BUF defaults to \"*vc*\", can be a string and will be created if necessary."
945 (unless buf (setq buf "*vc*"))
946 (let ((camefrom (current-buffer))
947 (olddir default-directory))
948 (set-buffer (get-buffer-create buf))
949 (kill-all-local-variables)
950 (set (make-local-variable 'vc-parent-buffer) camefrom)
951 (set (make-local-variable 'vc-parent-buffer-name)
952 (concat " from " (buffer-name camefrom)))
953 (setq default-directory olddir)
954 (let ((buffer-undo-list t)
955 (inhibit-read-only t))
956 (erase-buffer))))
958 (defvar vc-sentinel-movepoint) ;Dynamically scoped.
960 (defun vc-process-sentinel (p s)
961 (with-current-buffer (process-buffer p)
962 (setq mode-line-process
963 (let ((status (process-status p)))
964 ;; Leave mode-line uncluttered, normally.
965 ;; (Let known any weirdness in-form-ally. ;-) --ttn
966 (unless (eq 'exit status)
967 (format " (%s)" status)))))
968 (let ((previous (process-get p 'vc-previous-sentinel)))
969 (if previous (funcall previous p s))
970 (with-current-buffer (process-buffer p)
971 (let (vc-sentinel-movepoint)
972 ;; Normally, we want async code such as sentinels to not move point.
973 (save-excursion
974 (goto-char (process-mark p))
975 (let ((cmds (process-get p 'vc-sentinel-commands)))
976 (process-put p 'vc-sentinel-commands nil)
977 (dolist (cmd cmds)
978 ;; Each sentinel may move point and the next one should be run
979 ;; at that new point. We could get the same result by having
980 ;; each sentinel read&set process-mark, but since `cmd' needs
981 ;; to work both for async and sync processes, this would be
982 ;; difficult to achieve.
983 (vc-exec-after cmd))))
984 ;; But sometimes the sentinels really want to move point.
985 (if vc-sentinel-movepoint
986 (let ((win (get-buffer-window (current-buffer) 0)))
987 (if (not win)
988 (goto-char vc-sentinel-movepoint)
989 (with-selected-window win
990 (goto-char vc-sentinel-movepoint)))))))))
992 (defun vc-exec-after (code)
993 "Eval CODE when the current buffer's process is done.
994 If the current buffer has no process, just evaluate CODE.
995 Else, add CODE to the process' sentinel."
996 (let ((proc (get-buffer-process (current-buffer))))
997 (cond
998 ;; If there's no background process, just execute the code.
999 ;; We used to explicitly call delete-process on exited processes,
1000 ;; but this led to timing problems causing process output to be
1001 ;; lost. Terminated processes get deleted automatically
1002 ;; anyway. -- cyd
1003 ((or (null proc) (eq (process-status proc) 'exit))
1004 ;; Make sure we've read the process's output before going further.
1005 (if proc (accept-process-output proc))
1006 (eval code))
1007 ;; If a process is running, add CODE to the sentinel
1008 ((eq (process-status proc) 'run)
1009 (setq mode-line-process
1010 ;; Deliberate overstatement, but power law respected.
1011 ;; (The message is ephemeral, so we make it loud.) --ttn
1012 (propertize " (incomplete / in progress)"
1013 'face 'compilation-warning))
1014 (let ((previous (process-sentinel proc)))
1015 (unless (eq previous 'vc-process-sentinel)
1016 (process-put proc 'vc-previous-sentinel previous))
1017 (set-process-sentinel proc 'vc-process-sentinel))
1018 (process-put proc 'vc-sentinel-commands
1019 (cons code (process-get proc 'vc-sentinel-commands))))
1020 (t (error "Unexpected process state"))))
1021 nil)
1023 (defvar vc-post-command-functions nil
1024 "Hook run at the end of `vc-do-command'.
1025 Each function is called inside the buffer in which the command was run
1026 and is passed 3 arguments: the COMMAND, the FILES and the FLAGS.")
1028 (defvar w32-quote-process-args)
1030 (defun vc-delistify (filelist)
1031 "Smash a FILELIST into a file list string suitable for info messages."
1032 ;; FIXME what about file names with spaces?
1033 (if (not filelist) "." (mapconcat 'identity filelist " ")))
1035 ;;;###autoload
1036 (defun vc-do-command (buffer okstatus command file-or-list &rest flags)
1037 "Execute a VC command, notifying user and checking for errors.
1038 Output from COMMAND goes to BUFFER, or *vc* if BUFFER is nil or the
1039 current buffer if BUFFER is t. If the destination buffer is not
1040 already current, set it up properly and erase it. The command is
1041 considered successful if its exit status does not exceed OKSTATUS (if
1042 OKSTATUS is nil, that means to ignore error status, if it is `async', that
1043 means not to wait for termination of the subprocess; if it is t it means to
1044 ignore all execution errors). FILE-OR-LIST is the name of a working file;
1045 it may be a list of files or be nil (to execute commands that don't expect
1046 a file name or set of files). If an optional list of FLAGS is present,
1047 that is inserted into the command line before the filename."
1048 ;; FIXME: file-relative-name can return a bogus result because
1049 ;; it doesn't look at the actual file-system to see if symlinks
1050 ;; come into play.
1051 (let* ((files
1052 (mapcar (lambda (f) (file-relative-name (expand-file-name f)))
1053 (if (listp file-or-list) file-or-list (list file-or-list))))
1054 (full-command
1055 ;; What we're doing here is preparing a version of the command
1056 ;; for display in a debug-progess message. If it's fewer than
1057 ;; 20 characters display the entire command (without trailing
1058 ;; newline). Otherwise display the first 20 followed by an ellipsis.
1059 (concat (if (string= (substring command -1) "\n")
1060 (substring command 0 -1)
1061 command)
1063 (vc-delistify (mapcar (lambda (s) (if (> (length s) 20) (concat (substring s 0 2) "...") s)) flags))
1064 " " (vc-delistify files))))
1065 (save-current-buffer
1066 (unless (or (eq buffer t)
1067 (and (stringp buffer)
1068 (string= (buffer-name) buffer))
1069 (eq buffer (current-buffer)))
1070 (vc-setup-buffer buffer))
1071 ;; If there's some previous async process still running, just kill it.
1072 (let ((oldproc (get-buffer-process (current-buffer))))
1073 ;; If we wanted to wait for oldproc to finish before doing
1074 ;; something, we'd have used vc-eval-after.
1075 ;; Use `delete-process' rather than `kill-process' because we don't
1076 ;; want any of its output to appear from now on.
1077 (if oldproc (delete-process oldproc)))
1078 (let ((squeezed (remq nil flags))
1079 (inhibit-read-only t)
1080 (status 0))
1081 (when files
1082 (setq squeezed (nconc squeezed files)))
1083 (let ((exec-path (append vc-path exec-path))
1084 ;; Add vc-path to PATH for the execution of this command.
1085 (process-environment
1086 (cons (concat "PATH=" (getenv "PATH")
1087 path-separator
1088 (mapconcat 'identity vc-path path-separator))
1089 process-environment))
1090 (w32-quote-process-args t))
1091 (if (and (eq okstatus 'async) (file-remote-p default-directory))
1092 ;; start-process does not support remote execution
1093 (setq okstatus nil))
1094 (if (eq okstatus 'async)
1095 ;; Run asynchronously.
1096 (let ((proc
1097 (let ((process-connection-type nil))
1098 (apply 'start-file-process command (current-buffer)
1099 command squeezed))))
1100 (if vc-command-messages
1101 (message "Running %s in background..." full-command))
1102 ;;(set-process-sentinel proc (lambda (p msg) (delete-process p)))
1103 (set-process-filter proc 'vc-process-filter)
1104 (vc-exec-after
1105 `(if vc-command-messages
1106 (message "Running %s in background... done" ',full-command))))
1107 ;; Run synchrously
1108 (if vc-command-messages
1109 (message "Running %s in foreground..." full-command))
1110 (let ((buffer-undo-list t))
1111 (setq status (apply 'process-file command nil t nil squeezed)))
1112 (when (and (not (eq t okstatus))
1113 (or (not (integerp status))
1114 (and okstatus (< okstatus status))))
1115 (pop-to-buffer (current-buffer))
1116 (goto-char (point-min))
1117 (shrink-window-if-larger-than-buffer)
1118 (error "Running %s...FAILED (%s)" full-command
1119 (if (integerp status) (format "status %d" status) status))))
1120 ;; We're done. But don't emit a status message if running
1121 ;; asychronously, it would just mislead.
1122 (if (and vc-command-messages (not (eq okstatus 'async)))
1123 (message "Running %s...OK = %d" full-command status)))
1124 (vc-exec-after
1125 `(run-hook-with-args 'vc-post-command-functions
1126 ',command ',file-or-list ',flags))
1127 status))))
1129 (defun vc-position-context (posn)
1130 "Save a bit of the text around POSN in the current buffer.
1131 Used to help us find the corresponding position again later
1132 if markers are destroyed or corrupted."
1133 ;; A lot of this was shamelessly lifted from Sebastian Kremer's
1134 ;; rcs.el mode.
1135 (list posn
1136 (buffer-size)
1137 (buffer-substring posn
1138 (min (point-max) (+ posn 100)))))
1140 (defun vc-find-position-by-context (context)
1141 "Return the position of CONTEXT in the current buffer.
1142 If CONTEXT cannot be found, return nil."
1143 (let ((context-string (nth 2 context)))
1144 (if (equal "" context-string)
1145 (point-max)
1146 (save-excursion
1147 (let ((diff (- (nth 1 context) (buffer-size))))
1148 (if (< diff 0) (setq diff (- diff)))
1149 (goto-char (nth 0 context))
1150 (if (or (search-forward context-string nil t)
1151 ;; Can't use search-backward since the match may continue
1152 ;; after point.
1153 (progn (goto-char (- (point) diff (length context-string)))
1154 ;; goto-char doesn't signal an error at
1155 ;; beginning of buffer like backward-char would
1156 (search-forward context-string nil t)))
1157 ;; to beginning of OSTRING
1158 (- (point) (length context-string))))))))
1160 (defun vc-context-matches-p (posn context)
1161 "Return t if POSN matches CONTEXT, nil otherwise."
1162 (let* ((context-string (nth 2 context))
1163 (len (length context-string))
1164 (end (+ posn len)))
1165 (if (> end (1+ (buffer-size)))
1167 (string= context-string (buffer-substring posn end)))))
1169 (defun vc-buffer-context ()
1170 "Return a list (POINT-CONTEXT MARK-CONTEXT REPARSE).
1171 Used by `vc-restore-buffer-context' to later restore the context."
1172 (let ((point-context (vc-position-context (point)))
1173 ;; Use mark-marker to avoid confusion in transient-mark-mode.
1174 (mark-context (if (eq (marker-buffer (mark-marker)) (current-buffer))
1175 (vc-position-context (mark-marker))))
1176 ;; Make the right thing happen in transient-mark-mode.
1177 (mark-active nil)
1178 ;; The new compilation code does not use compilation-error-list any
1179 ;; more, so the code below is now ineffective and might as well
1180 ;; be disabled. -- Stef
1181 ;; ;; We may want to reparse the compilation buffer after revert
1182 ;; (reparse (and (boundp 'compilation-error-list) ;compile loaded
1183 ;; ;; Construct a list; each elt is nil or a buffer
1184 ;; ;; if that buffer is a compilation output buffer
1185 ;; ;; that contains markers into the current buffer.
1186 ;; (save-current-buffer
1187 ;; (mapcar (lambda (buffer)
1188 ;; (set-buffer buffer)
1189 ;; (let ((errors (or
1190 ;; compilation-old-error-list
1191 ;; compilation-error-list))
1192 ;; (buffer-error-marked-p nil))
1193 ;; (while (and (consp errors)
1194 ;; (not buffer-error-marked-p))
1195 ;; (and (markerp (cdr (car errors)))
1196 ;; (eq buffer
1197 ;; (marker-buffer
1198 ;; (cdr (car errors))))
1199 ;; (setq buffer-error-marked-p t))
1200 ;; (setq errors (cdr errors)))
1201 ;; (if buffer-error-marked-p buffer)))
1202 ;; (buffer-list)))))
1203 (reparse nil))
1204 (list point-context mark-context reparse)))
1206 (defun vc-restore-buffer-context (context)
1207 "Restore point/mark, and reparse any affected compilation buffers.
1208 CONTEXT is that which `vc-buffer-context' returns."
1209 (let ((point-context (nth 0 context))
1210 (mark-context (nth 1 context))
1211 ;; (reparse (nth 2 context))
1213 ;; The new compilation code does not use compilation-error-list any
1214 ;; more, so the code below is now ineffective and might as well
1215 ;; be disabled. -- Stef
1216 ;; ;; Reparse affected compilation buffers.
1217 ;; (while reparse
1218 ;; (if (car reparse)
1219 ;; (with-current-buffer (car reparse)
1220 ;; (let ((compilation-last-buffer (current-buffer)) ;select buffer
1221 ;; ;; Record the position in the compilation buffer of
1222 ;; ;; the last error next-error went to.
1223 ;; (error-pos (marker-position
1224 ;; (car (car-safe compilation-error-list)))))
1225 ;; ;; Reparse the error messages as far as they were parsed before.
1226 ;; (compile-reinitialize-errors '(4) compilation-parsing-end)
1227 ;; ;; Move the pointer up to find the error we were at before
1228 ;; ;; reparsing. Now next-error should properly go to the next one.
1229 ;; (while (and compilation-error-list
1230 ;; (/= error-pos (car (car compilation-error-list))))
1231 ;; (setq compilation-error-list (cdr compilation-error-list))))))
1232 ;; (setq reparse (cdr reparse)))
1234 ;; if necessary, restore point and mark
1235 (if (not (vc-context-matches-p (point) point-context))
1236 (let ((new-point (vc-find-position-by-context point-context)))
1237 (if new-point (goto-char new-point))))
1238 (and mark-active
1239 mark-context
1240 (not (vc-context-matches-p (mark) mark-context))
1241 (let ((new-mark (vc-find-position-by-context mark-context)))
1242 (if new-mark (set-mark new-mark))))))
1244 ;;; Code for deducing what fileset and backend to assume
1246 (defun vc-responsible-backend (file &optional register)
1247 "Return the name of a backend system that is responsible for FILE.
1248 The optional argument REGISTER means that a backend suitable for
1249 registration should be found.
1251 If REGISTER is nil, then if FILE is already registered, return the
1252 backend of FILE. If FILE is not registered, or a directory, then the
1253 first backend in `vc-handled-backends' that declares itself
1254 responsible for FILE is returned. If no backend declares itself
1255 responsible, return the first backend.
1257 If REGISTER is non-nil, return the first responsible backend under
1258 which FILE is not yet registered. If there is no such backend, return
1259 the first backend under which FILE is not yet registered, but could
1260 be registered."
1261 (if (not vc-handled-backends)
1262 (error "No handled backends"))
1263 (or (and (not (file-directory-p file)) (not register) (vc-backend file))
1264 (catch 'found
1265 ;; First try: find a responsible backend. If this is for registration,
1266 ;; it must be a backend under which FILE is not yet registered.
1267 (dolist (backend vc-handled-backends)
1268 (and (or (not register)
1269 (not (vc-call-backend backend 'registered file)))
1270 (vc-call-backend backend 'responsible-p file)
1271 (throw 'found backend)))
1272 ;; no responsible backend
1273 (if (not register)
1274 ;; if this is not for registration, the first backend must do
1275 (car vc-handled-backends)
1276 ;; for registration, we need to find a new backend that
1277 ;; could register FILE
1278 (dolist (backend vc-handled-backends)
1279 (and (not (vc-call-backend backend 'registered file))
1280 (vc-call-backend backend 'could-register file)
1281 (throw 'found backend)))
1282 (error "No backend that could register")))))
1284 (defun vc-expand-dirs (file-or-dir-list)
1285 "Expands directories in a file list specification.
1286 Only files already under version control are noticed."
1287 ;; FIXME: Kill this function.
1288 (let ((flattened '()))
1289 (dolist (node file-or-dir-list)
1290 (vc-file-tree-walk
1291 node (lambda (f) (if (vc-backend f) (push f flattened)))))
1292 (nreverse flattened)))
1294 (defun vc-deduce-fileset (&optional allow-directory-wildcard allow-unregistered)
1295 "Deduce a set of files and a backend to which to apply an operation.
1297 If we're in VC-dired mode, the fileset is the list of marked files.
1298 Otherwise, if we're looking at a buffer visiting a version-controlled file,
1299 the fileset is a singleton containing this file.
1300 If neither of these things is true, but ALLOW-DIRECTORY-WILDCARD is on
1301 and we're in a dired buffer, select the current directory.
1302 If none of these conditions is met, but ALLOW_UNREGISTERED is in and the
1303 visited file is not registered, return a singletin fileset containing it.
1304 Otherwise, throw an error."
1305 (cond (vc-dired-mode
1306 (let ((marked (dired-map-over-marks (dired-get-filename) nil)))
1307 (unless marked
1308 (error "No files have been selected."))
1309 ;; All members of the fileset must have the same backend
1310 (let ((firstbackend (vc-backend (car marked))))
1311 (dolist (f (cdr marked))
1312 (unless (eq (vc-backend f) firstbackend)
1313 (error "All members of a fileset must be under the same version-control system."))))
1314 marked))
1315 ((eq major-mode 'vc-status-mode)
1316 (let ((marked (vc-status-marked-files)))
1317 (if marked
1318 marked
1319 (list (vc-status-current-file)))))
1320 ((vc-backend buffer-file-name)
1321 (list buffer-file-name))
1322 ((and vc-parent-buffer (or (buffer-file-name vc-parent-buffer)
1323 (with-current-buffer vc-parent-buffer
1324 vc-dired-mode)))
1325 (progn
1326 (set-buffer vc-parent-buffer)
1327 (vc-deduce-fileset)))
1328 ;; This is guarded by an enabling arg so users won't potentially
1329 ;; shoot themselves in the foot by modifying a fileset they can't
1330 ;; verify by eyeball. Allow it for nondestructive commands like
1331 ;; making diffs, or possibly for destructive ones that have
1332 ;; confirmation prompts.
1333 ((and allow-directory-wildcard
1334 ;; I think this is a misfeature. For now, I'll leave it in, but
1335 ;; I'll disable it anywhere else than in dired buffers. --Stef
1336 (and (derived-mode-p 'dired-mode)
1337 (equal buffer-file-name nil)
1338 (equal list-buffers-directory default-directory)))
1339 (progn
1340 (message "All version-controlled files below %s selected."
1341 default-directory)
1342 (list default-directory)))
1343 ((and allow-unregistered (not (vc-registered buffer-file-name)))
1344 (list buffer-file-name))
1345 (t (error "No fileset is available here."))))
1347 (defun vc-ensure-vc-buffer ()
1348 "Make sure that the current buffer visits a version-controlled file."
1349 (cond
1350 (vc-dired-mode
1351 (set-buffer (find-file-noselect (dired-get-filename))))
1352 ((eq major-mode 'vc-status-mode)
1353 (set-buffer (find-file-noselect (vc-status-current-file))))
1355 (while (and vc-parent-buffer
1356 (buffer-live-p vc-parent-buffer)
1357 ;; Avoid infinite looping when vc-parent-buffer and
1358 ;; current buffer are the same buffer.
1359 (not (eq vc-parent-buffer (current-buffer))))
1360 (set-buffer vc-parent-buffer))
1361 (if (not buffer-file-name)
1362 (error "Buffer %s is not associated with a file" (buffer-name))
1363 (if (not (vc-backend buffer-file-name))
1364 (error "File %s is not under version control" buffer-file-name))))))
1366 ;;; Support for the C-x v v command. This is where all the single-file-oriented
1367 ;;; code from before the fileset rewrite lives.
1369 (defsubst vc-editable-p (file)
1370 "Return non-nil if FILE can be edited."
1371 (or (eq (vc-checkout-model file) 'implicit)
1372 (memq (vc-state file) '(edited needs-merge))))
1374 (defun vc-revert-buffer-internal (&optional arg no-confirm)
1375 "Revert buffer, keeping point and mark where user expects them.
1376 Try to be clever in the face of changes due to expanded version-control
1377 key words. This is important for typeahead to work as expected.
1378 ARG and NO-CONFIRM are passed on to `revert-buffer'."
1379 (interactive "P")
1380 (widen)
1381 (let ((context (vc-buffer-context)))
1382 ;; Use save-excursion here, because it may be able to restore point
1383 ;; and mark properly even in cases where vc-restore-buffer-context
1384 ;; would fail. However, save-excursion might also get it wrong --
1385 ;; in this case, vc-restore-buffer-context gives it a second try.
1386 (save-excursion
1387 ;; t means don't call normal-mode;
1388 ;; that's to preserve various minor modes.
1389 (revert-buffer arg no-confirm t))
1390 (vc-restore-buffer-context context)))
1392 (defun vc-buffer-sync (&optional not-urgent)
1393 "Make sure the current buffer and its working file are in sync.
1394 NOT-URGENT means it is ok to continue if the user says not to save."
1395 (if (buffer-modified-p)
1396 (if (or vc-suppress-confirm
1397 (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name))))
1398 (save-buffer)
1399 (unless not-urgent
1400 (error "Aborted")))))
1402 (defvar vc-dired-window-configuration)
1404 (defun vc-compatible-state (p q)
1405 "Controls which states can be in the same commit."
1407 (eq p q)
1408 (and (member p '(edited added removed)) (member q '(edited added removed)))))
1410 ;; Here's the major entry point.
1412 ;;;###autoload
1413 (defun vc-next-action (verbose)
1414 "Do the next logical version control operation on the current fileset.
1415 This requires that all files in the fileset be in the same state.
1417 For locking systems:
1418 If every file is not already registered, this registers each for version
1419 control.
1420 If every file is registered and not locked by anyone, this checks out
1421 a writable and locked file of each ready for editing.
1422 If every file is checked out and locked by the calling user, this
1423 first checks to see if each file has changed since checkout. If not,
1424 it performs a revert on that file.
1425 If every file has been changed, this pops up a buffer for entry
1426 of a log message; when the message has been entered, it checks in the
1427 resulting changes along with the log message as change commentary. If
1428 the variable `vc-keep-workfiles' is non-nil (which is its default), a
1429 read-only copy of each changed file is left in place afterwards.
1430 If the affected file is registered and locked by someone else, you are
1431 given the option to steal the lock(s).
1433 For merging systems:
1434 If every file is not already registered, this registers each one for version
1435 control. This does an add, but not a commit.
1436 If every file is added but not committed, each one is committed.
1437 If every working file is changed, but the corresponding repository file is
1438 unchanged, this pops up a buffer for entry of a log message; when the
1439 message has been entered, it checks in the resulting changes along
1440 with the logmessage as change commentary. A writable file is retained.
1441 If the repository file is changed, you are asked if you want to
1442 merge in the changes into your working copy."
1443 (interactive "P")
1444 (let* ((files (vc-deduce-fileset nil t))
1445 (state (vc-state (car files)))
1446 (model (vc-checkout-model (car files)))
1447 revision)
1448 ;; Verify that the fileset is homogenous
1449 (dolist (file (cdr files))
1450 (unless (vc-compatible-state (vc-state file) state)
1451 (error "Fileset is in a mixed-up state"))
1452 (unless (eq (vc-checkout-model file) model)
1453 (error "Fileset has mixed checkout models")))
1454 ;; Check for buffers in the fileset not matching the on-disk contents.
1455 (dolist (file files)
1456 (let ((visited (get-file-buffer file)))
1457 (when visited
1458 (if vc-dired-mode
1459 (switch-to-buffer-other-window visited)
1460 (set-buffer visited))
1461 ;; Check relation of buffer and file, and make sure
1462 ;; user knows what he's doing. First, finding the file
1463 ;; will check whether the file on disk is newer.
1464 ;; Ignore buffer-read-only during this test, and
1465 ;; preserve find-file-literally.
1466 (let ((buffer-read-only (not (file-writable-p file))))
1467 (find-file-noselect file nil find-file-literally))
1468 (if (not (verify-visited-file-modtime (current-buffer)))
1469 (if (yes-or-no-p (format "Replace %s on disk with buffer contents? " file))
1470 (write-file buffer-file-name)
1471 (error "Aborted"))
1472 ;; Now, check if we have unsaved changes.
1473 (vc-buffer-sync t)
1474 (when (buffer-modified-p)
1475 (or (y-or-n-p (message "Use %s on disk, keeping modified buffer? " file))
1476 (error "Aborted")))))))
1477 ;; Do the right thing
1478 (cond
1479 ;; Files aren't registered
1480 ((or (not state) ;; RCS uses nil for unregistered files.
1481 (eq state 'unregistered)
1482 (eq state 'ignored))
1483 (mapc 'vc-register files))
1484 ;; Files are up-to-date, or need a merge and user specified a revision
1485 ((or (eq state 'up-to-date) (and verbose (eq state 'needs-patch)))
1486 (cond
1487 (verbose
1488 ;; go to a different revision
1489 (setq revision (read-string "Branch, revision, or backend to move to: "))
1490 (let ((vsym (intern-soft (upcase revision))))
1491 (if (member vsym vc-handled-backends)
1492 (dolist (file files) (vc-transfer-file file vsym))
1493 (dolist (file files)
1494 (vc-checkout file (eq model 'implicit) revision)))))
1495 ((not (eq model 'implicit))
1496 ;; check the files out
1497 (dolist (file files) (vc-checkout file t)))
1499 ;; do nothing
1500 (message "Fileset is up-to-date"))))
1501 ;; Files have local changes
1502 ((vc-compatible-state state 'edited)
1503 (let ((ready-for-commit files))
1504 ;; If files are edited but read-only, give user a chance to correct
1505 (dolist (file files)
1506 (unless (file-writable-p file)
1507 ;; Make the file+buffer read-write.
1508 (unless (y-or-n-p (format "%s is edited but read-only; make it writable and continue?" file))
1509 (error "Aborted"))
1510 (set-file-modes file (logior (file-modes file) 128))
1511 (let ((visited (get-file-buffer file)))
1512 (when visited
1513 (with-current-buffer visited
1514 (toggle-read-only -1))))))
1515 ;; Allow user to revert files with no changes
1516 (save-excursion
1517 (dolist (file files)
1518 (let ((visited (get-file-buffer file)))
1519 ;; For files with locking, if the file does not contain
1520 ;; any changes, just let go of the lock, i.e. revert.
1521 (when (and (not (eq model 'implicit))
1522 (vc-workfile-unchanged-p file)
1523 ;; If buffer is modified, that means the user just
1524 ;; said no to saving it; in that case, don't revert,
1525 ;; because the user might intend to save after
1526 ;; finishing the log entry and committing.
1527 (not (and visited (buffer-modified-p))))
1528 (vc-revert-file file)
1529 (delete file ready-for-commit)))))
1530 ;; Remaining files need to be committed
1531 (if (not ready-for-commit)
1532 (message "No files remain to be committed")
1533 (if (not verbose)
1534 (vc-checkin ready-for-commit)
1535 (progn
1536 (setq revision (read-string "New revision or backend: "))
1537 (let ((vsym (intern (upcase revision))))
1538 (if (member vsym vc-handled-backends)
1539 (vc-transfer-file file vsym)
1540 (vc-checkin ready-for-commit revision))))))))
1541 ;; locked by somebody else (locking VCSes only)
1542 ((stringp state)
1543 (let ((revision
1544 (if verbose
1545 (read-string "Revision to steal: ")
1546 (vc-working-revision file))))
1547 (dolist (file files) (vc-steal-lock file revision state))))
1548 ;; needs-patch
1549 ((eq state 'needs-patch)
1550 (dolist (file files)
1551 (if (yes-or-no-p (format
1552 "%s is not up-to-date. Get latest revision? "
1553 (file-name-nondirectory file)))
1554 (vc-checkout file (eq model 'implicit) t)
1555 (when (and (not (eq model 'implicit))
1556 (yes-or-no-p "Lock this revision? "))
1557 (vc-checkout file t)))))
1558 ;; needs-merge
1559 ((eq state 'needs-merge)
1560 (dolist (file files)
1561 (when (yes-or-no-p (format
1562 "%s is not up-to-date. Merge in changes now? "
1563 (file-name-nondirectory file)))
1564 (vc-maybe-resolve-conflicts file (vc-call merge-news file)))))
1566 ;; unlocked-changes
1567 ((eq state 'unlocked-changes)
1568 (dolist (file files)
1569 (if (not (equal buffer-file-name file))
1570 (find-file-other-window file))
1571 (if (save-window-excursion
1572 (vc-diff-internal nil (list file) (vc-working-revision file) nil)
1573 (goto-char (point-min))
1574 (let ((inhibit-read-only t))
1575 (insert
1576 (format "Changes to %s since last lock:\n\n" file)))
1577 (not (beep))
1578 (yes-or-no-p (concat "File has unlocked changes. "
1579 "Claim lock retaining changes? ")))
1580 (progn (vc-call steal-lock file)
1581 (clear-visited-file-modtime)
1582 ;; Must clear any headers here because they wouldn't
1583 ;; show that the file is locked now.
1584 (vc-clear-headers file)
1585 (write-file buffer-file-name)
1586 (vc-mode-line file))
1587 (if (not (yes-or-no-p
1588 "Revert to checked-in revision, instead? "))
1589 (error "Checkout aborted")
1590 (vc-revert-buffer-internal t t)
1591 (vc-checkout file t))))))))
1593 (defun vc-create-repo (backend)
1594 "Create an empty repository in the current directory."
1595 (interactive
1596 (list
1597 (intern
1598 (upcase
1599 (completing-read
1600 "Create repository for: "
1601 (mapcar (lambda (b) (list (downcase (symbol-name b)))) vc-handled-backends)
1602 nil t)))))
1603 (vc-call-backend backend 'create-repo))
1605 ;;;###autoload
1606 (defun vc-register (&optional fname set-revision comment)
1607 "Register into a version control system.
1608 If FNAME is given register that file, otherwise register the current file.
1609 With prefix argument SET-REVISION, allow user to specify initial revision
1610 level. If COMMENT is present, use that as an initial comment.
1612 The version control system to use is found by cycling through the list
1613 `vc-handled-backends'. The first backend in that list which declares
1614 itself responsible for the file (usually because other files in that
1615 directory are already registered under that backend) will be used to
1616 register the file. If no backend declares itself responsible, the
1617 first backend that could register the file is used."
1618 (interactive "P")
1619 (when (and (null fname) (null buffer-file-name)) (error "No visited file"))
1621 (let ((bname (if fname (get-file-buffer fname) (current-buffer))))
1622 (unless fname (setq fname buffer-file-name))
1623 (when (vc-backend fname)
1624 (if (vc-registered fname)
1625 (error "This file is already registered")
1626 (unless (y-or-n-p "Previous master file has vanished. Make a new one? ")
1627 (error "Aborted"))))
1628 ;; Watch out for new buffers of size 0: the corresponding file
1629 ;; does not exist yet, even though buffer-modified-p is nil.
1630 (when bname
1631 (with-current-buffer bname
1632 (if (and (not (buffer-modified-p))
1633 (zerop (buffer-size))
1634 (not (file-exists-p buffer-file-name)))
1635 (set-buffer-modified-p t))
1636 (vc-buffer-sync)))
1637 (vc-start-entry (list fname)
1638 (if set-revision
1639 (read-string (format "Initial revision level for %s: "
1640 fname))
1641 (vc-call-backend (vc-responsible-backend fname)
1642 'init-revision))
1643 (or comment (not vc-initial-comment))
1645 "Enter initial comment."
1646 (lambda (files rev comment)
1647 (dolist (file files)
1648 (message "Registering %s... " file)
1649 (let ((backend (vc-responsible-backend file t)))
1650 (vc-file-clearprops file)
1651 (vc-call-backend backend 'register (list file) rev comment)
1652 (vc-file-setprop file 'vc-backend backend)
1653 (unless vc-make-backup-files
1654 (make-local-variable 'backup-inhibited)
1655 (setq backup-inhibited t)))
1656 (message "Registering %s... done" file))))))
1658 (defun vc-register-with (backend)
1659 "Register the current file with a specified back end."
1660 (interactive "SBackend: ")
1661 (if (not (member backend vc-handled-backends))
1662 (error "Unknown back end."))
1663 (let ((vc-handled-backends (list backend)))
1664 (call-interactively 'vc-register)))
1666 (declare-function view-mode-exit "view" (&optional return-to-alist exit-action all-win))
1668 (defun vc-resynch-window (file &optional keep noquery)
1669 "If FILE is in the current buffer, either revert or unvisit it.
1670 The choice between revert (to see expanded keywords) and unvisit depends on
1671 `vc-keep-workfiles'. NOQUERY if non-nil inhibits confirmation for
1672 reverting. NOQUERY should be t *only* if it is known the only
1673 difference between the buffer and the file is due to version control
1674 rather than user editing!"
1675 (and (string= buffer-file-name file)
1676 (if keep
1677 (progn
1678 (vc-revert-buffer-internal t noquery)
1679 ;; TODO: Adjusting view mode might no longer be necessary
1680 ;; after RMS change to files.el of 1999-08-08. Investigate
1681 ;; this when we install the new VC.
1682 (and view-read-only
1683 (if (file-writable-p file)
1684 (and view-mode
1685 (let ((view-old-buffer-read-only nil))
1686 (view-mode-exit)))
1687 (and (not view-mode)
1688 (not (eq (get major-mode 'mode-class) 'special))
1689 (view-mode-enter))))
1690 (vc-mode-line buffer-file-name))
1691 (kill-buffer (current-buffer)))))
1693 (defun vc-resynch-buffer (file &optional keep noquery)
1694 "If FILE is currently visited, resynch its buffer."
1695 (if (string= buffer-file-name file)
1696 (vc-resynch-window file keep noquery)
1697 (let ((buffer (get-file-buffer file)))
1698 (if buffer
1699 (with-current-buffer buffer
1700 (vc-resynch-window file keep noquery)))))
1701 (vc-dired-resynch-file file))
1703 (defun vc-start-entry (files rev comment initial-contents msg action &optional after-hook)
1704 "Accept a comment for an operation on FILES revision REV.
1705 If COMMENT is nil, pop up a VC-log buffer, emit MSG, and set the
1706 action on close to ACTION. If COMMENT is a string and
1707 INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial
1708 contents of the log entry buffer. If COMMENT is a string and
1709 INITIAL-CONTENTS is nil, do action immediately as if the user had
1710 entered COMMENT. If COMMENT is t, also do action immediately with an
1711 empty comment. Remember the file's buffer in `vc-parent-buffer'
1712 \(current one if no file). AFTER-HOOK specifies the local value
1713 for `vc-log-after-operation-hook'."
1714 (let ((parent
1715 (if (eq major-mode 'vc-dired-mode)
1716 ;; If we are called from VC dired, the parent buffer is
1717 ;; the current buffer.
1718 (current-buffer)
1719 (if (and files (equal (length files) 1))
1720 (get-file-buffer (car files))
1721 (current-buffer)))))
1722 (when vc-before-checkin-hook
1723 (if files
1724 (with-current-buffer parent
1725 (run-hooks 'vc-before-checkin-hook))
1726 (run-hooks 'vc-before-checkin-hook)))
1727 (if (and comment (not initial-contents))
1728 (set-buffer (get-buffer-create "*VC-log*"))
1729 (pop-to-buffer (get-buffer-create "*VC-log*")))
1730 (set (make-local-variable 'vc-parent-buffer) parent)
1731 (set (make-local-variable 'vc-parent-buffer-name)
1732 (concat " from " (buffer-name vc-parent-buffer)))
1733 ;;(if file (vc-mode-line file))
1734 (vc-log-edit files)
1735 (make-local-variable 'vc-log-after-operation-hook)
1736 (when after-hook
1737 (setq vc-log-after-operation-hook after-hook))
1738 (setq vc-log-operation action)
1739 (setq vc-log-revision rev)
1740 (when comment
1741 (erase-buffer)
1742 (when (stringp comment) (insert comment)))
1743 (if (or (not comment) initial-contents)
1744 (message "%s Type C-c C-c when done" msg)
1745 (vc-finish-logentry (eq comment t)))))
1747 (defun vc-checkout (file &optional writable rev)
1748 "Retrieve a copy of the revision REV of FILE.
1749 If WRITABLE is non-nil, make sure the retrieved file is writable.
1750 REV defaults to the latest revision.
1752 After check-out, runs the normal hook `vc-checkout-hook'."
1753 (and writable
1754 (not rev)
1755 (vc-call make-version-backups-p file)
1756 (vc-up-to-date-p file)
1757 (vc-make-version-backup file))
1758 (with-vc-properties
1759 (list file)
1760 (condition-case err
1761 (vc-call checkout file writable rev)
1762 (file-error
1763 ;; Maybe the backend is not installed ;-(
1764 (when writable
1765 (let ((buf (get-file-buffer file)))
1766 (when buf (with-current-buffer buf (toggle-read-only -1)))))
1767 (signal (car err) (cdr err))))
1768 `((vc-state . ,(if (or (eq (vc-checkout-model file) 'implicit)
1769 (not writable))
1770 (if (vc-call latest-on-branch-p file)
1771 'up-to-date
1772 'needs-patch)
1773 'edited))
1774 (vc-checkout-time . ,(nth 5 (file-attributes file)))))
1775 (vc-resynch-buffer file t t)
1776 (run-hooks 'vc-checkout-hook))
1778 (defun vc-steal-lock (file rev owner)
1779 "Steal the lock on FILE."
1780 (let (file-description)
1781 (if rev
1782 (setq file-description (format "%s:%s" file rev))
1783 (setq file-description file))
1784 (if (not (yes-or-no-p (format "Steal the lock on %s from %s? "
1785 file-description owner)))
1786 (error "Steal canceled"))
1787 (message "Stealing lock on %s..." file)
1788 (with-vc-properties
1789 (list file)
1790 (vc-call steal-lock file rev)
1791 `((vc-state . edited)))
1792 (vc-resynch-buffer file t t)
1793 (message "Stealing lock on %s...done" file)
1794 ;; Write mail after actually stealing, because if the stealing
1795 ;; goes wrong, we don't want to send any mail.
1796 (compose-mail owner (format "Stolen lock on %s" file-description))
1797 (setq default-directory (expand-file-name "~/"))
1798 (goto-char (point-max))
1799 (insert
1800 (format "I stole the lock on %s, " file-description)
1801 (current-time-string)
1802 ".\n")
1803 (message "Please explain why you stole the lock. Type C-c C-c when done.")))
1805 (defun vc-checkin (files &optional rev comment initial-contents)
1806 "Check in FILES.
1807 The optional argument REV may be a string specifying the new revision
1808 level (if nil increment the current level). COMMENT is a comment
1809 string; if omitted, a buffer is popped up to accept a comment. If
1810 INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial contents
1811 of the log entry buffer.
1813 If `vc-keep-workfiles' is nil, FILE is deleted afterwards, provided
1814 that the version control system supports this mode of operation.
1816 Runs the normal hook `vc-checkin-hook'."
1817 (vc-start-entry
1818 files rev comment initial-contents
1819 "Enter a change comment."
1820 (lambda (files rev comment)
1821 (message "Checking in %s..." (vc-delistify files))
1822 ;; "This log message intentionally left almost blank".
1823 ;; RCS 5.7 gripes about white-space-only comments too.
1824 (or (and comment (string-match "[^\t\n ]" comment))
1825 (setq comment "*** empty log message ***"))
1826 (with-vc-properties
1827 files
1828 ;; We used to change buffers to get local value of vc-checkin-switches,
1829 ;; but 'the' local buffer is not a well-defined concept for filesets.
1830 (progn
1831 (vc-call checkin files rev comment)
1832 (mapc 'vc-delete-automatic-version-backups files))
1833 `((vc-state . up-to-date)
1834 (vc-checkout-time . ,(nth 5 (file-attributes file)))
1835 (vc-working-revision . nil)))
1836 (message "Checking in %s...done" (vc-delistify files)))
1837 'vc-checkin-hook))
1839 (defun vc-finish-logentry (&optional nocomment)
1840 "Complete the operation implied by the current log entry.
1841 Use the contents of the current buffer as a check-in or registration
1842 comment. If the optional arg NOCOMMENT is non-nil, then don't check
1843 the buffer contents as a comment."
1844 (interactive)
1845 ;; Check and record the comment, if any.
1846 (unless nocomment
1847 ;; Comment too long?
1848 (vc-call-backend (or (if vc-log-fileset (vc-backend vc-log-fileset))
1849 (vc-responsible-backend default-directory))
1850 'logentry-check)
1851 (run-hooks 'vc-logentry-check-hook))
1852 ;; Sync parent buffer in case the user modified it while editing the comment.
1853 ;; But not if it is a vc-dired buffer.
1854 (with-current-buffer vc-parent-buffer
1855 (or vc-dired-mode (vc-buffer-sync)))
1856 (if (not vc-log-operation)
1857 (error "No log operation is pending"))
1858 ;; save the parameters held in buffer-local variables
1859 (let ((log-operation vc-log-operation)
1860 (log-fileset vc-log-fileset)
1861 (log-revision vc-log-revision)
1862 (log-entry (buffer-string))
1863 (after-hook vc-log-after-operation-hook)
1864 (tmp-vc-parent-buffer vc-parent-buffer))
1865 (pop-to-buffer vc-parent-buffer)
1866 ;; OK, do it to it
1867 (save-excursion
1868 (funcall log-operation
1869 log-fileset
1870 log-revision
1871 log-entry))
1872 ;; Remove checkin window (after the checkin so that if that fails
1873 ;; we don't zap the *VC-log* buffer and the typing therein).
1874 (let ((logbuf (get-buffer "*VC-log*")))
1875 (cond ((and logbuf vc-delete-logbuf-window)
1876 (delete-windows-on logbuf (selected-frame))
1877 ;; Kill buffer and delete any other dedicated windows/frames.
1878 (kill-buffer logbuf))
1879 (logbuf (pop-to-buffer "*VC-log*")
1880 (bury-buffer)
1881 (pop-to-buffer tmp-vc-parent-buffer))))
1882 ;; Now make sure we see the expanded headers
1883 (if log-fileset
1884 (mapc
1885 (lambda (file) (vc-resynch-buffer file vc-keep-workfiles t))
1886 log-fileset))
1887 (if vc-dired-mode
1888 (dired-move-to-filename))
1889 (run-hooks after-hook 'vc-finish-logentry-hook)))
1891 ;;; Additional entry points for examining version histories
1893 ;; (defun vc-default-diff-tree (backend dir rev1 rev2)
1894 ;; "List differences for all registered files at and below DIR.
1895 ;; The meaning of REV1 and REV2 is the same as for `vc-revision-diff'."
1896 ;; ;; This implementation does an explicit tree walk, and calls
1897 ;; ;; vc-BACKEND-diff directly for each file. An optimization
1898 ;; ;; would be to use `vc-diff-internal', so that diffs can be local,
1899 ;; ;; and to call it only for files that are actually changed.
1900 ;; ;; However, this is expensive for some backends, and so it is left
1901 ;; ;; to backend-specific implementations.
1902 ;; (setq default-directory dir)
1903 ;; (vc-file-tree-walk
1904 ;; default-directory
1905 ;; (lambda (f)
1906 ;; (vc-exec-after
1907 ;; `(let ((coding-system-for-read (vc-coding-system-for-diff ',f)))
1908 ;; (message "Looking at %s" ',f)
1909 ;; (vc-call-backend ',(vc-backend f)
1910 ;; 'diff (list ',f) ',rev1 ',rev2))))))
1912 (defun vc-coding-system-for-diff (file)
1913 "Return the coding system for reading diff output for FILE."
1914 (or coding-system-for-read
1915 ;; if we already have this file open,
1916 ;; use the buffer's coding system
1917 (let ((buf (find-buffer-visiting file)))
1918 (if buf (with-current-buffer buf
1919 buffer-file-coding-system)))
1920 ;; otherwise, try to find one based on the file name
1921 (car (find-operation-coding-system 'insert-file-contents file))
1922 ;; and a final fallback
1923 'undecided))
1925 (defun vc-switches (backend op)
1926 (let ((switches
1927 (or (if backend
1928 (let ((sym (vc-make-backend-sym
1929 backend (intern (concat (symbol-name op)
1930 "-switches")))))
1931 (if (boundp sym) (symbol-value sym))))
1932 (let ((sym (intern (format "vc-%s-switches" (symbol-name op)))))
1933 (if (boundp sym) (symbol-value sym)))
1934 (cond
1935 ((eq op 'diff) diff-switches)))))
1936 (if (stringp switches) (list switches)
1937 ;; If not a list, return nil.
1938 ;; This is so we can set vc-diff-switches to t to override
1939 ;; any switches in diff-switches.
1940 (if (listp switches) switches))))
1942 ;; Old def for compatibility with Emacs-21.[123].
1943 (defmacro vc-diff-switches-list (backend) `(vc-switches ',backend 'diff))
1944 (make-obsolete 'vc-diff-switches-list 'vc-switches "22.1")
1946 (defun vc-diff-sentinel (verbose rev1-name rev2-name)
1947 ;; The empty sync output case has already been handled, so the only
1948 ;; possibility of an empty output is for an async process, in which case
1949 ;; it's important to insert the "diffs end here" message in the buffer
1950 ;; since the user may miss a message in the echo area.
1951 (when verbose
1952 (let ((inhibit-read-only t))
1953 (if (eq (buffer-size) 0)
1954 (insert "No differences found.\n")
1955 (insert (format "\n\nDiffs between %s and %s end here." rev1-name rev2-name)))))
1956 (goto-char (point-min))
1957 (shrink-window-if-larger-than-buffer))
1959 (defvar vc-diff-added-files nil
1960 "If non-nil, diff added files by comparing them to /dev/null.")
1962 (defun vc-diff-internal (async files rev1 rev2 &optional verbose)
1963 "Report diffs between two revisions of a fileset.
1964 Diff output goes to the *vc-diff* buffer. The function
1965 returns t if the buffer had changes, nil otherwise."
1966 (let* ((filenames (vc-delistify files))
1967 (rev1-name (or rev1 "working revision"))
1968 (rev2-name (or rev2 "workfile"))
1969 ;; Set coding system based on the first file. It's a kluge,
1970 ;; but the only way to set it for each file included would
1971 ;; be to call the back end separately for each file.
1972 (coding-system-for-read
1973 (if files (vc-coding-system-for-diff (car files)) 'undecided)))
1974 (vc-setup-buffer "*vc-diff*")
1975 (message "Finding changes in %s..." filenames)
1976 ;; Many backends don't handle well the case of a file that has been
1977 ;; added but not yet committed to the repo (notably CVS and Subversion).
1978 ;; Do that work here so the backends don't have to futz with it. --ESR
1980 ;; Actually most backends (including CVS) have options to control the
1981 ;; behavior since which one is better depends on the user and on the
1982 ;; situation). Worse yet: this code does not handle the case where
1983 ;; `file' is a directory which contains added files.
1984 ;; I made it conditional on vc-diff-added-files but it should probably
1985 ;; just be removed (or copied/moved to specific backends). --Stef.
1986 (when vc-diff-added-files
1987 (let ((filtered '()))
1988 (dolist (file files)
1989 (if (or (file-directory-p file)
1990 (not (string= (vc-working-revision file) "0")))
1991 (push file filtered)
1992 ;; This file is added but not yet committed;
1993 ;; there is no master file to diff against.
1994 (if (or rev1 rev2)
1995 (error "No revisions of %s exist" file)
1996 ;; We regard this as "changed".
1997 ;; Diff it against /dev/null.
1998 (apply 'vc-do-command "*vc-diff*"
1999 1 "diff" file
2000 (append (vc-switches nil 'diff) '("/dev/null"))))))
2001 (setq files (nreverse filtered))))
2002 (let ((vc-disable-async-diff (not async)))
2003 (vc-call diff files rev1 rev2 "*vc-diff*"))
2004 (set-buffer "*vc-diff*")
2005 (if (and (zerop (buffer-size))
2006 (not (get-buffer-process (current-buffer))))
2007 ;; Treat this case specially so as not to pop the buffer.
2008 (progn
2009 (message "No changes between %s and %s" rev1-name rev2-name)
2010 nil)
2011 (diff-mode)
2012 ;; Make the *vc-diff* buffer read only, the diff-mode key
2013 ;; bindings are nicer for read only buffers. pcl-cvs does the
2014 ;; same thing.
2015 (setq buffer-read-only t)
2016 (vc-exec-after `(vc-diff-sentinel ,verbose ,rev1-name ,rev2-name))
2017 ;; Display the buffer, but at the end because it can change point.
2018 (pop-to-buffer (current-buffer))
2019 ;; In the async case, we return t even if there are no differences
2020 ;; because we don't know that yet.
2021 t)))
2023 ;;;###autoload
2024 (defun vc-version-diff (files rev1 rev2)
2025 "Report diffs between revisions of the fileset in the repository history."
2026 (interactive
2027 (let* ((files (vc-deduce-fileset t))
2028 (first (car files))
2029 (completion-table
2030 (vc-call revision-completion-table files))
2031 (rev1-default nil)
2032 (rev2-default nil))
2033 (cond
2034 ;; someday we may be able to do revision completion on non-singleton
2035 ;; filesets, but not yet.
2036 ((/= (length files) 1)
2037 nil)
2038 ;; if it's a directory, don't supply any revision default
2039 ((file-directory-p first)
2040 nil)
2041 ;; if the file is not up-to-date, use working revision as older revision
2042 ((not (vc-up-to-date-p first))
2043 (setq rev1-default (vc-working-revision first)))
2044 ;; if the file is not locked, use last and previous revisions as defaults
2046 (setq rev1-default (vc-call previous-revision first
2047 (vc-working-revision first)))
2048 (if (string= rev1-default "") (setq rev1-default nil))
2049 (setq rev2-default (vc-working-revision first))))
2050 ;; construct argument list
2051 (let* ((rev1-prompt (if rev1-default
2052 (concat "Older revision (default "
2053 rev1-default "): ")
2054 "Older revision: "))
2055 (rev2-prompt (concat "Newer revision (default "
2056 (or rev2-default "current source") "): "))
2057 (rev1 (if completion-table
2058 (completing-read rev1-prompt completion-table
2059 nil nil nil nil rev1-default)
2060 (read-string rev1-prompt nil nil rev1-default)))
2061 (rev2 (if completion-table
2062 (completing-read rev2-prompt completion-table
2063 nil nil nil nil rev2-default)
2064 (read-string rev2-prompt nil nil rev2-default))))
2065 (if (string= rev1 "") (setq rev1 nil))
2066 (if (string= rev2 "") (setq rev2 nil))
2067 (list files rev1 rev2))))
2068 (if (and (not rev1) rev2)
2069 (error "Not a valid revision range."))
2070 (vc-diff-internal t files rev1 rev2 (interactive-p)))
2072 ;; (defun vc-contains-version-controlled-file (dir)
2073 ;; "Return t if DIR contains a version-controlled file, nil otherwise."
2074 ;; (catch 'found
2075 ;; (mapc (lambda (f) (and (not (file-directory-p f)) (vc-backend f) (throw 'found 't))) (directory-files dir))
2076 ;; nil))
2078 ;;;###autoload
2079 (defun vc-diff (historic &optional not-urgent)
2080 "Display diffs between file revisions.
2081 Normally this compares the currently selected fileset with their
2082 working revisions. With a prefix argument HISTORIC, it reads two revision
2083 designators specifying which revisions to compare.
2085 If no current fileset is available (that is, we are not in
2086 VC-Dired mode and the visited file of the current buffer is not
2087 under version control) and we're in a Dired buffer, use
2088 the current directory.
2089 The optional argument NOT-URGENT non-nil means it is ok to say no to
2090 saving the buffer."
2091 (interactive (list current-prefix-arg t))
2092 (if historic
2093 (call-interactively 'vc-version-diff)
2094 (let* ((files (vc-deduce-fileset t)))
2095 (if buffer-file-name (vc-buffer-sync not-urgent))
2096 (vc-diff-internal t files nil nil (interactive-p)))))
2099 ;;;###autoload
2100 (defun vc-revision-other-window (rev)
2101 "Visit revision REV of the current file in another window.
2102 If the current file is named `F', the revision is named `F.~REV~'.
2103 If `F.~REV~' already exists, use it instead of checking it out again."
2104 (interactive
2105 (save-current-buffer
2106 (vc-ensure-vc-buffer)
2107 (let ((completion-table
2108 (vc-call revision-completion-table buffer-file-name))
2109 (prompt "Revision to visit (default is working revision): "))
2110 (list
2111 (if completion-table
2112 (completing-read prompt completion-table)
2113 (read-string prompt))))))
2114 (vc-ensure-vc-buffer)
2115 (let* ((file buffer-file-name)
2116 (revision (if (string-equal rev "")
2117 (vc-working-revision file)
2118 rev)))
2119 (switch-to-buffer-other-window (vc-find-revision file revision))))
2121 (defun vc-find-revision (file revision)
2122 "Read REVISION of FILE into a buffer and return the buffer."
2123 (let ((automatic-backup (vc-version-backup-file-name file revision))
2124 (filebuf (or (get-file-buffer file) (current-buffer)))
2125 (filename (vc-version-backup-file-name file revision 'manual)))
2126 (unless (file-exists-p filename)
2127 (if (file-exists-p automatic-backup)
2128 (rename-file automatic-backup filename nil)
2129 (message "Checking out %s..." filename)
2130 (with-current-buffer filebuf
2131 (let ((failed t))
2132 (unwind-protect
2133 (let ((coding-system-for-read 'no-conversion)
2134 (coding-system-for-write 'no-conversion))
2135 (with-temp-file filename
2136 (let ((outbuf (current-buffer)))
2137 ;; Change buffer to get local value of
2138 ;; vc-checkout-switches.
2139 (with-current-buffer filebuf
2140 (vc-call find-revision file revision outbuf))))
2141 (setq failed nil))
2142 (when (and failed (file-exists-p filename))
2143 (delete-file filename))))
2144 (vc-mode-line file))
2145 (message "Checking out %s...done" filename)))
2146 (let ((result-buf (find-file-noselect filename)))
2147 (with-current-buffer result-buf
2148 ;; Set the parent buffer so that things like
2149 ;; C-x v g, C-x v l, ... etc work.
2150 (setq vc-parent-buffer filebuf))
2151 result-buf)))
2153 ;; Header-insertion code
2155 ;;;###autoload
2156 (defun vc-insert-headers ()
2157 "Insert headers into a file for use with a version control system.
2158 Headers desired are inserted at point, and are pulled from
2159 the variable `vc-BACKEND-header'."
2160 (interactive)
2161 (vc-ensure-vc-buffer)
2162 (save-excursion
2163 (save-restriction
2164 (widen)
2165 (if (or (not (vc-check-headers))
2166 (y-or-n-p "Version headers already exist. Insert another set? "))
2167 (let* ((delims (cdr (assq major-mode vc-comment-alist)))
2168 (comment-start-vc (or (car delims) comment-start "#"))
2169 (comment-end-vc (or (car (cdr delims)) comment-end ""))
2170 (hdsym (vc-make-backend-sym (vc-backend buffer-file-name)
2171 'header))
2172 (hdstrings (and (boundp hdsym) (symbol-value hdsym))))
2173 (dolist (s hdstrings)
2174 (insert comment-start-vc "\t" s "\t"
2175 comment-end-vc "\n"))
2176 (if vc-static-header-alist
2177 (dolist (f vc-static-header-alist)
2178 (if (string-match (car f) buffer-file-name)
2179 (insert (format (cdr f) (car hdstrings)))))))))))
2181 (defun vc-clear-headers (&optional file)
2182 "Clear all version headers in the current buffer (or FILE).
2183 The headers are reset to their non-expanded form."
2184 (let* ((filename (or file buffer-file-name))
2185 (visited (find-buffer-visiting filename))
2186 (backend (vc-backend filename)))
2187 (when (vc-find-backend-function backend 'clear-headers)
2188 (if visited
2189 (let ((context (vc-buffer-context)))
2190 ;; save-excursion may be able to relocate point and mark
2191 ;; properly. If it fails, vc-restore-buffer-context
2192 ;; will give it a second try.
2193 (save-excursion
2194 (vc-call-backend backend 'clear-headers))
2195 (vc-restore-buffer-context context))
2196 (set-buffer (find-file-noselect filename))
2197 (vc-call-backend backend 'clear-headers)
2198 (kill-buffer filename)))))
2200 (defun vc-modify-change-comment (files rev oldcomment)
2201 "Edit the comment associated with the given files and revision."
2202 (vc-start-entry
2203 files rev oldcomment t
2204 "Enter a replacement change comment."
2205 (lambda (files rev comment)
2206 (vc-call-backend
2207 ;; Less of a kluge than it looks like; log-view mode only passes
2208 ;; this function a singleton list. Arguments left in this form in
2209 ;; case the more general operation ever becomes meaningful.
2210 (vc-responsible-backend (car files))
2211 'modify-change-comment files rev comment))))
2213 ;;;###autoload
2214 (defun vc-merge ()
2215 "Merge changes between two revisions into the current buffer's file.
2216 This asks for two revisions to merge from in the minibuffer. If the
2217 first revision is a branch number, then merge all changes from that
2218 branch. If the first revision is empty, merge news, i.e. recent changes
2219 from the current branch.
2221 See Info node `Merging'."
2222 (interactive)
2223 (vc-ensure-vc-buffer)
2224 (vc-buffer-sync)
2225 (let* ((file buffer-file-name)
2226 (backend (vc-backend file))
2227 (state (vc-state file))
2228 first-revision second-revision status)
2229 (cond
2230 ((stringp state) ;; Locking VCses only
2231 (error "File is locked by %s" state))
2232 ((not (vc-editable-p file))
2233 (if (y-or-n-p
2234 "File must be checked out for merging. Check out now? ")
2235 (vc-checkout file t)
2236 (error "Merge aborted"))))
2237 (setq first-revision
2238 (read-string (concat "Branch or revision to merge from "
2239 "(default news on current branch): ")))
2240 (if (string= first-revision "")
2241 (if (not (vc-find-backend-function backend 'merge-news))
2242 (error "Sorry, merging news is not implemented for %s" backend)
2243 (setq status (vc-call merge-news file)))
2244 (if (not (vc-find-backend-function backend 'merge))
2245 (error "Sorry, merging is not implemented for %s" backend)
2246 (if (not (vc-branch-p first-revision))
2247 (setq second-revision
2248 (read-string "Second revision: "
2249 (concat (vc-branch-part first-revision) ".")))
2250 ;; We want to merge an entire branch. Set revisions
2251 ;; accordingly, so that vc-BACKEND-merge understands us.
2252 (setq second-revision first-revision)
2253 ;; first-revision must be the starting point of the branch
2254 (setq first-revision (vc-branch-part first-revision)))
2255 (setq status (vc-call merge file first-revision second-revision))))
2256 (vc-maybe-resolve-conflicts file status "WORKFILE" "MERGE SOURCE")))
2258 (defun vc-maybe-resolve-conflicts (file status &optional name-A name-B)
2259 (vc-resynch-buffer file t (not (buffer-modified-p)))
2260 (if (zerop status) (message "Merge successful")
2261 (smerge-mode 1)
2262 (message "File contains conflicts.")))
2264 ;;;###autoload
2265 (defalias 'vc-resolve-conflicts 'smerge-ediff)
2267 ;; The VC directory major mode. Coopt Dired for this.
2268 ;; All VC commands get mapped into logical equivalents.
2270 (defvar vc-dired-switches)
2271 (defvar vc-dired-terse-mode)
2273 (defvar vc-dired-mode-map
2274 (let ((map (make-sparse-keymap))
2275 (vmap (make-sparse-keymap)))
2276 (define-key map "\C-xv" vmap)
2277 (define-key map "v" vmap)
2278 (set-keymap-parent vmap vc-prefix-map)
2279 (define-key vmap "t" 'vc-dired-toggle-terse-mode)
2280 map))
2282 (define-derived-mode vc-dired-mode dired-mode "Dired under "
2283 "The major mode used in VC directory buffers.
2285 It works like Dired, but lists only files under version control, with
2286 the current VC state of each file being indicated in the place of the
2287 file's link count, owner, group and size. Subdirectories are also
2288 listed, and you may insert them into the buffer as desired, like in
2289 Dired.
2291 All Dired commands operate normally, with the exception of `v', which
2292 is redefined as the version control prefix, so that you can type
2293 `vl', `v=' etc. to invoke `vc-print-log', `vc-diff', and the like on
2294 the file named in the current Dired buffer line. `vv' invokes
2295 `vc-next-action' on this file, or on all files currently marked.
2296 There is a special command, `*l', to mark all files currently locked."
2297 ;; define-derived-mode does it for us in Emacs-21, but not in Emacs-20.
2298 ;; We do it here because dired might not be loaded yet
2299 ;; when vc-dired-mode-map is initialized.
2300 (set-keymap-parent vc-dired-mode-map dired-mode-map)
2301 (add-hook 'dired-after-readin-hook 'vc-dired-hook nil t)
2302 ;; The following is slightly modified from files.el,
2303 ;; because file lines look a bit different in vc-dired-mode
2304 ;; (the column before the date does not end in a digit).
2305 ;; albinus: It should be done in the original declaration. Problem
2306 ;; is the optional empty state-info; otherwise ")" would be good
2307 ;; enough as delimeter.
2308 (set (make-local-variable 'directory-listing-before-filename-regexp)
2309 (let* ((l "\\([A-Za-z]\\|[^\0-\177]\\)")
2310 ;; In some locales, month abbreviations are as short as 2 letters,
2311 ;; and they can be followed by ".".
2312 (month (concat l l "+\\.?"))
2313 (s " ")
2314 (yyyy "[0-9][0-9][0-9][0-9]")
2315 (dd "[ 0-3][0-9]")
2316 (HH:MM "[ 0-2][0-9]:[0-5][0-9]")
2317 (seconds "[0-6][0-9]\\([.,][0-9]+\\)?")
2318 (zone "[-+][0-2][0-9][0-5][0-9]")
2319 (iso-mm-dd "[01][0-9]-[0-3][0-9]")
2320 (iso-time (concat HH:MM "\\(:" seconds "\\( ?" zone "\\)?\\)?"))
2321 (iso (concat "\\(\\(" yyyy "-\\)?" iso-mm-dd "[ T]" iso-time
2322 "\\|" yyyy "-" iso-mm-dd "\\)"))
2323 (western (concat "\\(" month s "+" dd "\\|" dd "\\.?" s month "\\)"
2324 s "+"
2325 "\\(" HH:MM "\\|" yyyy "\\)"))
2326 (western-comma (concat month s "+" dd "," s "+" yyyy))
2327 ;; Japanese MS-Windows ls-lisp has one-digit months, and
2328 ;; omits the Kanji characters after month and day-of-month.
2329 (mm "[ 0-1]?[0-9]")
2330 (japanese
2331 (concat mm l "?" s dd l "?" s "+"
2332 "\\(" HH:MM "\\|" yyyy l "?" "\\)")))
2333 ;; the .* below ensures that we find the last match on a line
2334 (concat ".*" s
2335 "\\(" western "\\|" western-comma "\\|" japanese "\\|" iso "\\)"
2336 s "+")))
2337 (and (boundp 'vc-dired-switches)
2338 vc-dired-switches
2339 (set (make-local-variable 'dired-actual-switches)
2340 vc-dired-switches))
2341 (set (make-local-variable 'vc-dired-terse-mode) vc-dired-terse-display)
2342 (let ((backend-name (symbol-name (vc-responsible-backend
2343 default-directory))))
2344 (setq mode-name (concat mode-name backend-name))
2345 ;; Add menu after `vc-dired-mode-map' has `dired-mode-map' as the parent.
2346 (let ((vc-dire-menu-map (copy-keymap vc-menu-map)))
2347 (define-key-after (lookup-key vc-dired-mode-map [menu-bar]) [vc]
2348 (cons backend-name vc-dire-menu-map) 'subdir)))
2349 (setq vc-dired-mode t))
2351 (defun vc-dired-toggle-terse-mode ()
2352 "Toggle terse display in VC Dired."
2353 (interactive)
2354 (if (not vc-dired-mode)
2356 (setq vc-dired-terse-mode (not vc-dired-terse-mode))
2357 (if vc-dired-terse-mode
2358 (vc-dired-hook)
2359 (revert-buffer))))
2361 (defun vc-dired-mark-locked ()
2362 "Mark all files currently locked."
2363 (interactive)
2364 (dired-mark-if (let ((f (dired-get-filename nil t)))
2365 (and f
2366 (not (file-directory-p f))
2367 (not (vc-up-to-date-p f))))
2368 "locked file"))
2370 (define-key vc-dired-mode-map "*l" 'vc-dired-mark-locked)
2372 (defun vc-dired-reformat-line (vc-info)
2373 "Reformat a directory-listing line.
2374 Replace various columns with version control information, VC-INFO.
2375 This code, like dired, assumes UNIX -l format."
2376 (beginning-of-line)
2377 (when (re-search-forward
2378 ;; Match link count, owner, group, size. Group may be missing,
2379 ;; and only the size is present in OS/2 -l format.
2380 "^..[drwxlts-]+ \\( *[0-9]+\\( [^ ]+ +\\([^ ]+ +\\)?[0-9]+\\)?\\) "
2381 (line-end-position) t)
2382 (replace-match (substring (concat vc-info " ") 0 10)
2383 t t nil 1)))
2385 (defun vc-dired-ignorable-p (filename)
2386 "Should FILENAME be ignored in VC-Dired listings?"
2387 (catch t
2388 ;; Ignore anything that wouldn't be found by completion (.o, .la, etc.)
2389 (dolist (ignorable completion-ignored-extensions)
2390 (let ((ext (substring filename
2391 (- (length filename)
2392 (length ignorable)))))
2393 (if (string= ignorable ext) (throw t t))))
2394 ;; Ignore Makefiles derived from something else
2395 (when (string= (file-name-nondirectory filename) "Makefile")
2396 (let* ((dir (file-name-directory filename))
2397 (peers (directory-files (or dir default-directory))))
2398 (if (or (member "Makefile.in" peers) (member "Makefile.am" peers))
2399 (throw t t))))
2400 nil))
2402 (defun vc-dired-hook ()
2403 "Reformat the listing according to version control.
2404 Called by dired after any portion of a vc-dired buffer has been read in."
2405 (message "Getting version information... ")
2406 ;; if the backend supports it, get the state
2407 ;; of all files in this directory at once
2408 (let ((backend (vc-responsible-backend default-directory)))
2409 ;; check `backend' can really handle `default-directory'.
2410 (if (and (vc-call-backend backend 'responsible-p default-directory)
2411 (vc-find-backend-function backend 'dir-state))
2412 (vc-call-backend backend 'dir-state default-directory)))
2413 (let (filename
2414 (inhibit-read-only t)
2415 (buffer-undo-list t))
2416 (goto-char (point-min))
2417 (while (not (eobp))
2418 (cond
2419 ;; subdir header line
2420 ((dired-get-subdir)
2421 (forward-line 1)
2422 ;; erase (but don't remove) the "total" line
2423 (delete-region (point) (line-end-position))
2424 (beginning-of-line)
2425 (forward-line 1))
2426 ;; file line
2427 ((setq filename (dired-get-filename nil t))
2428 (cond
2429 ;; subdir
2430 ((file-directory-p filename)
2431 (cond
2432 ((member (file-name-nondirectory filename)
2433 vc-directory-exclusion-list)
2434 (let ((pos (point)))
2435 (dired-kill-tree filename)
2436 (goto-char pos)
2437 (dired-kill-line)))
2438 (vc-dired-terse-mode
2439 ;; Don't show directories in terse mode. Don't use
2440 ;; dired-kill-line to remove it, because in recursive listings,
2441 ;; that would remove the directory contents as well.
2442 (delete-region (line-beginning-position)
2443 (progn (forward-line 1) (point))))
2444 ((string-match "\\`\\.\\.?\\'" (file-name-nondirectory filename))
2445 (dired-kill-line))
2447 (vc-dired-reformat-line nil)
2448 (forward-line 1))))
2449 ;; Try to head off calling the expensive state query -
2450 ;; ignore object files, TeX intermediate files, and so forth.
2451 ((vc-dired-ignorable-p filename)
2452 (dired-kill-line))
2453 ;; Ordinary file -- call the (possibly expensive) state query
2455 ;; First case: unregistered or unknown. (Unknown shouldn't happen here)
2456 ((member (vc-state filename) '(nil unregistered))
2457 (if vc-dired-terse-mode
2458 (dired-kill-line)
2459 (vc-dired-reformat-line "?")
2460 (forward-line 1)))
2461 ;; Either we're in non-terse mode or it's out of date
2462 ((not (and vc-dired-terse-mode (vc-up-to-date-p filename)))
2463 (vc-dired-reformat-line (vc-call dired-state-info filename))
2464 (forward-line 1))
2465 ;; Remaining cases are under version control but uninteresting
2467 (dired-kill-line))))
2468 ;; any other line
2469 (t (forward-line 1))))
2470 (vc-dired-purge))
2471 (message "Getting version information... done")
2472 (save-restriction
2473 (widen)
2474 (cond ((eq (count-lines (point-min) (point-max)) 1)
2475 (goto-char (point-min))
2476 (message "No changes pending under %s" default-directory)))))
2478 (defun vc-dired-purge ()
2479 "Remove empty subdirs."
2480 (goto-char (point-min))
2481 (while (dired-get-subdir)
2482 (forward-line 2)
2483 (if (dired-get-filename nil t)
2484 (if (not (dired-next-subdir 1 t))
2485 (goto-char (point-max)))
2486 (forward-line -2)
2487 (if (not (string= (dired-current-directory) default-directory))
2488 (dired-do-kill-lines t "")
2489 ;; We cannot remove the top level directory.
2490 ;; Just make it look a little nicer.
2491 (forward-line 1)
2492 (or (eobp) (kill-line))
2493 (if (not (dired-next-subdir 1 t))
2494 (goto-char (point-max))))))
2495 (goto-char (point-min)))
2497 (defun vc-dired-buffers-for-dir (dir)
2498 "Return a list of all vc-dired buffers that currently display DIR."
2499 (let (result)
2500 ;; Check whether dired is loaded.
2501 (when (fboundp 'dired-buffers-for-dir)
2502 (dolist (buffer (dired-buffers-for-dir dir))
2503 (with-current-buffer buffer
2504 (if vc-dired-mode
2505 (push buffer result)))))
2506 (nreverse result)))
2508 (defun vc-dired-resynch-file (file)
2509 "Update the entries for FILE in any VC Dired buffers that list it."
2510 (let ((buffers (vc-dired-buffers-for-dir (file-name-directory file))))
2511 (when buffers
2512 (mapcar (lambda (buffer)
2513 (with-current-buffer buffer
2514 (if (dired-goto-file file)
2515 ;; bind vc-dired-terse-mode to nil so that
2516 ;; files won't vanish when they are checked in
2517 (let ((vc-dired-terse-mode nil))
2518 (dired-do-redisplay 1)))))
2519 buffers))))
2521 ;;;###autoload
2522 (defun vc-directory (dir read-switches)
2523 "Create a buffer in VC Dired Mode for directory DIR.
2525 See Info node `VC Dired Mode'.
2527 With prefix arg READ-SWITCHES, specify a value to override
2528 `dired-listing-switches' when generating the listing."
2529 (interactive "DDired under VC (directory): \nP")
2530 (let ((vc-dired-switches (concat vc-dired-listing-switches
2531 (if vc-dired-recurse "R" ""))))
2532 (if (eq (string-match tramp-file-name-regexp dir) 0)
2533 (error "Sorry, vc-directory does not work over Tramp"))
2534 (if read-switches
2535 (setq vc-dired-switches
2536 (read-string "Dired listing switches: "
2537 vc-dired-switches)))
2538 (require 'dired)
2539 (require 'dired-aux)
2540 (switch-to-buffer
2541 (dired-internal-noselect (expand-file-name (file-name-as-directory dir))
2542 vc-dired-switches
2543 'vc-dired-mode))))
2545 ;;; Experimental code for the vc-dired replacement
2546 (require 'ewoc)
2548 (defstruct (vc-status-fileinfo
2549 (:copier nil)
2550 (:constructor vc-status-create-fileinfo (state name &optional marked))
2551 (:conc-name vc-status-fileinfo->))
2552 marked
2553 state
2554 name)
2556 (defvar vc-status nil)
2558 (defun vc-status-headers (backend dir)
2559 (concat
2560 (format "VC backend : %s\n" backend)
2561 "Repository : The repository goes here\n"
2562 (format "Working dir: %s\n" dir)))
2564 (defun vc-status-printer (fileentry)
2565 "Pretty print FILEENTRY."
2566 (insert
2567 ;; If you change this, change vc-status-move-to-goal-column.
2568 (format "%c %-20s %s"
2569 (if (vc-status-fileinfo->marked fileentry) ?* ? )
2570 (vc-status-fileinfo->state fileentry)
2571 (vc-status-fileinfo->name fileentry))))
2573 (defun vc-status-move-to-goal-column ()
2574 (beginning-of-line)
2575 ;; Must be in sync with vc-status-printer.
2576 (forward-char 25))
2578 ;;;###autoload
2579 (defun vc-status (dir)
2580 "Show the VC status for DIR."
2581 (interactive "DVC status for directory: ")
2582 (vc-setup-buffer "*vc-status*")
2583 (switch-to-buffer "*vc-status*")
2584 (cd dir)
2585 (vc-status-mode))
2587 (defvar vc-status-mode-map
2588 (let ((map (make-keymap)))
2589 (suppress-keymap map)
2590 ;; Marking.
2591 (define-key map "m" 'vc-status-mark-file)
2592 (define-key map "M" 'vc-status-mark-all-files)
2593 (define-key map "u" 'vc-status-unmark-file)
2594 (define-key map "\C-?" 'vc-status-unmark-file-up)
2595 (define-key map "\M-\C-?" 'vc-status-unmark-all-files)
2596 ;; Movement.
2597 (define-key map "n" 'vc-status-next-line)
2598 (define-key map " " 'vc-status-next-line)
2599 (define-key map "\t" 'vc-status-next-line)
2600 (define-key map "p" 'vc-status-previous-line)
2601 (define-key map [backtab] 'vc-status-previous-line)
2602 ;; VC commands.
2603 (define-key map "=" 'vc-diff)
2604 (define-key map "a" 'vc-status-register)
2605 ;; Can't be "g" (as in vc map), so "A" for "Annotate".
2606 (define-key map "A" 'vc-annotate)
2607 ;; vc-print-log uses the current buffer, not a file.
2608 ;; (define-key map "l" 'vc-status-print-log)
2609 ;; The remainder.
2610 (define-key map "f" 'vc-status-find-file)
2611 (define-key map "o" 'vc-status-find-file-other-window)
2612 (define-key map "q" 'bury-buffer)
2613 (define-key map "g" 'vc-status-refresh)
2614 map)
2615 "Keymap for VC status")
2617 (defun vc-status-mode ()
2618 "Major mode for VC status.
2619 \\{vc-status-mode-map}"
2620 (setq mode-name "*VC Status*")
2621 (setq major-mode 'vc-status-mode)
2622 (setq buffer-read-only t)
2623 (use-local-map vc-status-mode-map)
2624 (let ((buffer-read-only nil)
2625 (backend (vc-responsible-backend default-directory))
2626 entries)
2627 (erase-buffer)
2628 (set (make-local-variable 'vc-status)
2629 (ewoc-create #'vc-status-printer
2630 (vc-status-headers backend default-directory)))
2631 (vc-status-refresh)))
2633 (put 'vc-status-mode 'mode-class 'special)
2635 (defun vc-update-vc-status-buffer (entries buffer)
2636 (with-current-buffer buffer
2637 (dolist (entry entries)
2638 (ewoc-enter-last vc-status
2639 (vc-status-create-fileinfo (cdr entry) (car entry))))
2640 (ewoc-goto-node vc-status (ewoc-nth vc-status 0))))
2642 (defun vc-status-refresh ()
2643 "Refresh the contents of the VC status buffer."
2644 (interactive)
2645 ;; This is not very efficient; ewoc could use a new function here.
2646 (ewoc-filter vc-status (lambda (node) nil))
2647 (let ((backend (vc-responsible-backend default-directory)))
2648 ;; Call the dir-status backend function. dir-status is supposed to
2649 ;; be asynchronous. It should compute the results and call the
2650 ;; function passed as a an arg to update the vc-status buffer with
2651 ;; the results.
2652 (vc-call-backend
2653 backend 'dir-status default-directory
2654 #'vc-update-vc-status-buffer (current-buffer))))
2656 (defun vc-status-next-line (arg)
2657 "Go to the next line.
2658 If a prefix argument is given, move by that many lines."
2659 (interactive "p")
2660 (ewoc-goto-next vc-status arg)
2661 (vc-status-move-to-goal-column))
2663 (defun vc-status-previous-line (arg)
2664 "Go to the previous line.
2665 If a prefix argument is given, move by that many lines."
2666 (interactive "p")
2667 (ewoc-goto-prev vc-status arg)
2668 (vc-status-move-to-goal-column))
2670 (defun vc-status-mark-file ()
2671 "Mark the current file and move to the next line."
2672 (interactive)
2673 (let* ((crt (ewoc-locate vc-status))
2674 (file (ewoc-data crt)))
2675 (setf (vc-status-fileinfo->marked file) t)
2676 (ewoc-invalidate vc-status crt)
2677 (vc-status-next-line 1)))
2679 (defun vc-status-mark-all-files ()
2680 "Mark all files."
2681 (interactive)
2682 (ewoc-map
2683 (lambda (file)
2684 (unless (vc-status-fileinfo->marked file)
2685 (setf (vc-status-fileinfo->marked file) t)
2687 vc-status))
2689 (defun vc-status-unmark-file ()
2690 "Unmark the current file and move to the next line."
2691 (interactive)
2692 (let* ((crt (ewoc-locate vc-status))
2693 (file (ewoc-data crt)))
2694 (setf (vc-status-fileinfo->marked file) nil)
2695 (ewoc-invalidate vc-status crt)
2696 (vc-status-next-line 1)))
2698 (defun vc-status-unmark-file-up ()
2699 "Move to the previous line and unmark the file."
2700 (interactive)
2701 ;; If we're on the first line, we won't move up, but we will still
2702 ;; remove the mark. This seems a bit odd but it is what buffer-menu
2703 ;; does.
2704 (let* ((prev (ewoc-goto-prev vc-status 1))
2705 (file (ewoc-data prev)))
2706 (setf (vc-status-fileinfo->marked file) nil)
2707 (ewoc-invalidate vc-status prev)
2708 (vc-status-move-to-goal-column)))
2710 (defun vc-status-unmark-all-files ()
2711 "Unmark all files."
2712 (interactive)
2713 (ewoc-map
2714 (lambda (file)
2715 (when (vc-status-fileinfo->marked file)
2716 (setf (vc-status-fileinfo->marked file) nil)
2718 vc-status))
2720 (defun vc-status-register ()
2721 "Register the marked files, or the current file if no marks."
2722 (interactive)
2723 (let ((files (or (vc-status-marked-files)
2724 (list (vc-status-current-file)))))
2725 (dolist (file files)
2726 (vc-register file))))
2728 (defun vc-status-find-file ()
2729 "Find the file on the current line."
2730 (interactive)
2731 (find-file (vc-status-current-file)))
2733 (defun vc-status-find-file-other-window ()
2734 "Find the file on the current line, in another window."
2735 (interactive)
2736 (find-file-other-window (vc-status-current-file)))
2738 (defun vc-status-current-file ()
2739 (let ((node (ewoc-locate vc-status)))
2740 (unless node
2741 (error "No file available."))
2742 (expand-file-name (vc-status-fileinfo->name (ewoc-data node)))))
2744 (defun vc-status-marked-files ()
2745 "Return the list of marked files"
2746 (mapcar
2747 (lambda (elem)
2748 (expand-file-name (vc-status-fileinfo->name elem)))
2749 (ewoc-collect
2750 vc-status
2751 (lambda (crt) (vc-status-fileinfo->marked crt)))))
2753 ;;; End experimental code.
2755 ;; Named-configuration entry points
2757 (defun vc-snapshot-precondition (dir)
2758 "Scan the tree below DIR, looking for files not up-to-date.
2759 If any file is not up-to-date, return the name of the first such file.
2760 \(This means, neither snapshot creation nor retrieval is allowed.\)
2761 If one or more of the files are currently visited, return `visited'.
2762 Otherwise, return nil."
2763 (let ((status nil))
2764 (catch 'vc-locked-example
2765 (vc-file-tree-walk
2767 (lambda (f)
2768 (if (not (vc-up-to-date-p f)) (throw 'vc-locked-example f)
2769 (if (get-file-buffer f) (setq status 'visited)))))
2770 status)))
2772 ;;;###autoload
2773 (defun vc-create-snapshot (dir name branchp)
2774 "Descending recursively from DIR, make a snapshot called NAME.
2775 For each registered file, the working revision becomes part of
2776 the named configuration. If the prefix argument BRANCHP is
2777 given, the snapshot is made as a new branch and the files are
2778 checked out in that new branch."
2779 (interactive
2780 (list (read-file-name "Directory: " default-directory default-directory t)
2781 (read-string "New snapshot name: ")
2782 current-prefix-arg))
2783 (message "Making %s... " (if branchp "branch" "snapshot"))
2784 (if (file-directory-p dir) (setq dir (file-name-as-directory dir)))
2785 (vc-call-backend (vc-responsible-backend dir)
2786 'create-snapshot dir name branchp)
2787 (message "Making %s... done" (if branchp "branch" "snapshot")))
2789 ;;;###autoload
2790 (defun vc-retrieve-snapshot (dir name)
2791 "Descending recursively from DIR, retrieve the snapshot called NAME.
2792 If NAME is empty, it refers to the latest revisions.
2793 If locking is used for the files in DIR, then there must not be any
2794 locked files at or below DIR (but if NAME is empty, locked files are
2795 allowed and simply skipped)."
2796 (interactive
2797 (list (read-file-name "Directory: " default-directory default-directory t)
2798 (read-string "Snapshot name to retrieve (default latest revisions): ")))
2799 (let ((update (yes-or-no-p "Update any affected buffers? "))
2800 (msg (if (or (not name) (string= name ""))
2801 (format "Updating %s... " (abbreviate-file-name dir))
2802 (format "Retrieving snapshot into %s... "
2803 (abbreviate-file-name dir)))))
2804 (message "%s" msg)
2805 (vc-call-backend (vc-responsible-backend dir)
2806 'retrieve-snapshot dir name update)
2807 (message "%s" (concat msg "done"))))
2809 ;; Miscellaneous other entry points
2811 ;;;###autoload
2812 (defun vc-print-log (&optional working-revision)
2813 "List the change log of the current fileset in a window.
2814 If WORKING-REVISION is non-nil, leave the point at that revision."
2815 (interactive)
2816 (let* ((files (vc-deduce-fileset))
2817 (backend (vc-backend files))
2818 (working-revision (or working-revision (vc-working-revision (car files)))))
2819 ;; Don't switch to the output buffer before running the command,
2820 ;; so that any buffer-local settings in the vc-controlled
2821 ;; buffer can be accessed by the command.
2822 (vc-call-backend backend 'print-log files "*vc-change-log*")
2823 (pop-to-buffer "*vc-change-log*")
2824 (vc-exec-after
2825 `(let ((inhibit-read-only t))
2826 (vc-call-backend ',backend 'log-view-mode)
2827 (goto-char (point-max)) (forward-line -1)
2828 (while (looking-at "=*\n")
2829 (delete-char (- (match-end 0) (match-beginning 0)))
2830 (forward-line -1))
2831 (goto-char (point-min))
2832 (if (looking-at "[\b\t\n\v\f\r ]+")
2833 (delete-char (- (match-end 0) (match-beginning 0))))
2834 (shrink-window-if-larger-than-buffer)
2835 ;; move point to the log entry for the working revision
2836 (vc-call-backend ',backend 'show-log-entry ',working-revision)
2837 (setq vc-sentinel-movepoint (point))
2838 (set-buffer-modified-p nil)))))
2840 ;;;###autoload
2841 (defun vc-revert ()
2842 "Revert working copies of the selected fileset to their repository contents.
2843 This asks for confirmation if the buffer contents are not identical
2844 to the working revision (except for keyword expansion)."
2845 (interactive)
2846 (let* ((files (vc-deduce-fileset)))
2847 ;; If any of the files is visited by the current buffer, make
2848 ;; sure buffer is saved. If the user says `no', abort since
2849 ;; we cannot show the changes and ask for confirmation to
2850 ;; discard them.
2851 (if (or (not files) (memq (buffer-file-name) files))
2852 (vc-buffer-sync nil))
2853 (dolist (file files)
2854 (let ((buf (get-file-buffer file)))
2855 (if (and buf (buffer-modified-p buf))
2856 (error "Please kill or save all modified buffers before reverting.")))
2857 (if (vc-up-to-date-p file)
2858 (unless (yes-or-no-p (format "%s seems up-to-date. Revert anyway? " file))
2859 (error "Revert canceled"))))
2860 (if (vc-diff-internal vc-allow-async-revert files nil nil)
2861 (progn
2862 (unless (yes-or-no-p (format "Discard changes in %s? " (vc-delistify files)))
2863 (error "Revert canceled"))
2864 (delete-windows-on "*vc-diff*")
2865 (kill-buffer "*vc-diff*")))
2866 (dolist (file files)
2867 (progn
2868 (message "Reverting %s..." (vc-delistify files))
2869 (vc-revert-file file)
2870 (message "Reverting %s...done" (vc-delistify files))))))
2872 ;;;###autoload
2873 (defun vc-rollback ()
2874 "Roll back (remove) the most recent changeset committed to the repository.
2875 This may be either a file-level or a repository-level operation,
2876 depending on the underlying version-control system."
2877 (interactive)
2878 (let* ((files (vc-deduce-fileset))
2879 (backend (vc-backend files))
2880 (granularity (vc-call-backend backend 'revision-granularity)))
2881 (unless (vc-find-backend-function backend 'rollback)
2882 (error "Rollback is not supported in %s" backend))
2883 (if (and (not (eq granularity 'repository)) (/= (length files) 1))
2884 (error "Rollback requires a singleton fileset or repository versioning"))
2885 (if (not (vc-call latest-on-branch-p (car files)))
2886 (error "Rollback is only possible at the tip revision."))
2887 ;; If any of the files is visited by the current buffer, make
2888 ;; sure buffer is saved. If the user says `no', abort since
2889 ;; we cannot show the changes and ask for confirmation to
2890 ;; discard them.
2891 (if (or (not files) (memq (buffer-file-name) files))
2892 (vc-buffer-sync nil))
2893 (dolist (file files)
2894 (if (buffer-modified-p (get-file-buffer file))
2895 (error "Please kill or save all modified buffers before rollback."))
2896 (if (not (vc-up-to-date-p file))
2897 (error "Please revert all modified workfiles before rollback.")))
2898 ;; Accumulate changes associated with the fileset
2899 (vc-setup-buffer "*vc-diff*")
2900 (not-modified)
2901 (message "Finding changes...")
2902 (let* ((tip (vc-working-revision (car files)))
2903 (previous (vc-call previous-revision (car files) tip)))
2904 (vc-diff-internal nil files previous tip))
2905 ;; Display changes
2906 (unless (yes-or-no-p "Discard these revisions? ")
2907 (error "Rollback canceled"))
2908 (delete-windows-on "*vc-diff*")
2909 (kill-buffer"*vc-diff*")
2910 ;; Do the actual reversions
2911 (message "Rolling back %s..." (vc-delistify files))
2912 (with-vc-properties
2913 files
2914 (vc-call-backend backend 'rollback files)
2915 `((vc-state . ,'up-to-date)
2916 (vc-checkout-time . , (nth 5 (file-attributes file)))
2917 (vc-working-revision . nil)))
2918 (dolist (f files) (vc-resynch-buffer f t t))
2919 (message "Rolling back %s...done" (vc-delistify files))))
2921 ;;;###autoload
2922 (define-obsolete-function-alias 'vc-revert-buffer 'vc-revert "23.1")
2924 ;;;###autoload
2925 (defun vc-update ()
2926 "Update the current fileset's files to their tip revisions.
2927 For each one that contains no changes, and is not locked, then this simply
2928 replaces the work file with the latest revision on its branch. If the file
2929 contains changes, and the backend supports merging news, then any recent
2930 changes from the current branch are merged into the working file."
2931 (interactive)
2932 (dolist (file (vc-deduce-fileset))
2933 (if (buffer-modified-p (get-file-buffer file))
2934 (error "Please kill or save all modified buffers before updating."))
2935 (if (vc-up-to-date-p file)
2936 (vc-checkout file nil "")
2937 (if (eq (vc-checkout-model file) 'locking)
2938 (if (eq (vc-state file) 'edited)
2939 (error "%s"
2940 (substitute-command-keys
2941 "File is locked--type \\[vc-revert] to discard changes"))
2942 (error "Unexpected file state (%s) -- type %s"
2943 (vc-state file)
2944 (substitute-command-keys
2945 "\\[vc-next-action] to correct")))
2946 (if (not (vc-find-backend-function (vc-backend file) 'merge-news))
2947 (error "Sorry, merging news is not implemented for %s"
2948 (vc-backend file))
2949 (vc-maybe-resolve-conflicts file (vc-call merge-news file)))))))
2951 (defun vc-version-backup-file (file &optional rev)
2952 "Return name of backup file for revision REV of FILE.
2953 If version backups should be used for FILE, and there exists
2954 such a backup for REV or the working revision of file, return
2955 its name; otherwise return nil."
2956 (when (vc-call make-version-backups-p file)
2957 (let ((backup-file (vc-version-backup-file-name file rev)))
2958 (if (file-exists-p backup-file)
2959 backup-file
2960 ;; there is no automatic backup, but maybe the user made one manually
2961 (setq backup-file (vc-version-backup-file-name file rev 'manual))
2962 (if (file-exists-p backup-file)
2963 backup-file)))))
2965 (defun vc-revert-file (file)
2966 "Revert FILE back to the repository working revision it was based on."
2967 (with-vc-properties
2968 (list file)
2969 (let ((backup-file (vc-version-backup-file file)))
2970 (when backup-file
2971 (copy-file backup-file file 'ok-if-already-exists 'keep-date)
2972 (vc-delete-automatic-version-backups file))
2973 (vc-call revert file backup-file))
2974 `((vc-state . up-to-date)
2975 (vc-checkout-time . ,(nth 5 (file-attributes file)))))
2976 (vc-resynch-buffer file t t))
2978 ;;;###autoload
2979 (defun vc-switch-backend (file backend)
2980 "Make BACKEND the current version control system for FILE.
2981 FILE must already be registered in BACKEND. The change is not
2982 permanent, only for the current session. This function only changes
2983 VC's perspective on FILE, it does not register or unregister it.
2984 By default, this command cycles through the registered backends.
2985 To get a prompt, use a prefix argument."
2986 (interactive
2987 (list
2988 (or buffer-file-name
2989 (error "There is no version-controlled file in this buffer"))
2990 (let ((backend (vc-backend buffer-file-name))
2991 (backends nil))
2992 (unless backend
2993 (error "File %s is not under version control" buffer-file-name))
2994 ;; Find the registered backends.
2995 (dolist (backend vc-handled-backends)
2996 (when (vc-call-backend backend 'registered buffer-file-name)
2997 (push backend backends)))
2998 ;; Find the next backend.
2999 (let ((def (car (delq backend (append (memq backend backends) backends))))
3000 (others (delete backend backends)))
3001 (cond
3002 ((null others) (error "No other backend to switch to"))
3003 (current-prefix-arg
3004 (intern
3005 (upcase
3006 (completing-read
3007 (format "Switch to backend [%s]: " def)
3008 (mapcar (lambda (b) (list (downcase (symbol-name b)))) backends)
3009 nil t nil nil (downcase (symbol-name def))))))
3010 (t def))))))
3011 (unless (eq backend (vc-backend file))
3012 (vc-file-clearprops file)
3013 (vc-file-setprop file 'vc-backend backend)
3014 ;; Force recomputation of the state
3015 (unless (vc-call-backend backend 'registered file)
3016 (vc-file-clearprops file)
3017 (error "%s is not registered in %s" file backend))
3018 (vc-mode-line file)))
3020 ;;;###autoload
3021 (defun vc-transfer-file (file new-backend)
3022 "Transfer FILE to another version control system NEW-BACKEND.
3023 If NEW-BACKEND has a higher precedence than FILE's current backend
3024 \(i.e. it comes earlier in `vc-handled-backends'), then register FILE in
3025 NEW-BACKEND, using the revision number from the current backend as the
3026 base level. If NEW-BACKEND has a lower precedence than the current
3027 backend, then commit all changes that were made under the current
3028 backend to NEW-BACKEND, and unregister FILE from the current backend.
3029 \(If FILE is not yet registered under NEW-BACKEND, register it.)"
3030 (let* ((old-backend (vc-backend file))
3031 (edited (memq (vc-state file) '(edited needs-merge)))
3032 (registered (vc-call-backend new-backend 'registered file))
3033 (move
3034 (and registered ; Never move if not registered in new-backend yet.
3035 ;; move if new-backend comes later in vc-handled-backends
3036 (or (memq new-backend (memq old-backend vc-handled-backends))
3037 (y-or-n-p "Final transfer? "))))
3038 (comment nil))
3039 (if (eq old-backend new-backend)
3040 (error "%s is the current backend of %s" new-backend file))
3041 (if registered
3042 (set-file-modes file (logior (file-modes file) 128))
3043 ;; `registered' might have switched under us.
3044 (vc-switch-backend file old-backend)
3045 (let* ((rev (vc-working-revision file))
3046 (modified-file (and edited (make-temp-file file)))
3047 (unmodified-file (and modified-file (vc-version-backup-file file))))
3048 ;; Go back to the base unmodified file.
3049 (unwind-protect
3050 (progn
3051 (when modified-file
3052 (copy-file file modified-file 'ok-if-already-exists)
3053 ;; If we have a local copy of the unmodified file, handle that
3054 ;; here and not in vc-revert-file because we don't want to
3055 ;; delete that copy -- it is still useful for OLD-BACKEND.
3056 (if unmodified-file
3057 (copy-file unmodified-file file
3058 'ok-if-already-exists 'keep-date)
3059 (if (y-or-n-p "Get base revision from master? ")
3060 (vc-revert-file file))))
3061 (vc-call-backend new-backend 'receive-file file rev))
3062 (when modified-file
3063 (vc-switch-backend file new-backend)
3064 (unless (eq (vc-checkout-model file) 'implicit)
3065 (vc-checkout file t nil))
3066 (rename-file modified-file file 'ok-if-already-exists)
3067 (vc-file-setprop file 'vc-checkout-time nil)))))
3068 (when move
3069 (vc-switch-backend file old-backend)
3070 (setq comment (vc-call comment-history file))
3071 (vc-call unregister file))
3072 (vc-switch-backend file new-backend)
3073 (when (or move edited)
3074 (vc-file-setprop file 'vc-state 'edited)
3075 (vc-mode-line file)
3076 (vc-checkin file nil comment (stringp comment)))))
3078 (defun vc-rename-master (oldmaster newfile templates)
3079 "Rename OLDMASTER to be the master file for NEWFILE based on TEMPLATES."
3080 (let* ((dir (file-name-directory (expand-file-name oldmaster)))
3081 (newdir (or (file-name-directory newfile) ""))
3082 (newbase (file-name-nondirectory newfile))
3083 (masters
3084 ;; List of potential master files for `newfile'
3085 (mapcar
3086 (lambda (s) (vc-possible-master s newdir newbase))
3087 templates)))
3088 (if (or (file-symlink-p oldmaster)
3089 (file-symlink-p (file-name-directory oldmaster)))
3090 (error "This is unsafe in the presence of symbolic links"))
3091 (rename-file
3092 oldmaster
3093 (catch 'found
3094 ;; If possible, keep the master file in the same directory.
3095 (dolist (f masters)
3096 (if (and f (string= (file-name-directory (expand-file-name f)) dir))
3097 (throw 'found f)))
3098 ;; If not, just use the first possible place.
3099 (dolist (f masters)
3100 (and f (or (not (setq dir (file-name-directory f)))
3101 (file-directory-p dir))
3102 (throw 'found f)))
3103 (error "New file lacks a version control directory")))))
3105 (defun vc-delete-file (file)
3106 "Delete file and mark it as such in the version control system."
3107 (interactive "fVC delete file: ")
3108 (let ((buf (get-file-buffer file))
3109 (backend (vc-backend file)))
3110 (unless backend
3111 (error "File %s is not under version control"
3112 (file-name-nondirectory file)))
3113 (unless (vc-find-backend-function backend 'delete-file)
3114 (error "Deleting files under %s is not supported in VC" backend))
3115 (if (and buf (buffer-modified-p buf))
3116 (error "Please save files before deleting them"))
3117 (unless (y-or-n-p (format "Really want to delete %s? "
3118 (file-name-nondirectory file)))
3119 (error "Abort!"))
3120 (unless (or (file-directory-p file) (null make-backup-files))
3121 (with-current-buffer (or buf (find-file-noselect file))
3122 (let ((backup-inhibited nil))
3123 (backup-buffer))))
3124 (vc-call delete-file file)
3125 ;; If the backend hasn't deleted the file itself, let's do it for him.
3126 (if (file-exists-p file) (delete-file file))))
3128 ;;;###autoload
3129 (defun vc-rename-file (old new)
3130 "Rename file OLD to NEW, and rename its master file likewise."
3131 (interactive "fVC rename file: \nFRename to: ")
3132 (let ((oldbuf (get-file-buffer old)))
3133 (if (and oldbuf (buffer-modified-p oldbuf))
3134 (error "Please save files before moving them"))
3135 (if (get-file-buffer new)
3136 (error "Already editing new file name"))
3137 (if (file-exists-p new)
3138 (error "New file already exists"))
3139 (let ((state (vc-state old)))
3140 (unless (memq state '(up-to-date edited))
3141 (error "Please %s files before moving them"
3142 (if (stringp state) "check in" "update"))))
3143 (vc-call rename-file old new)
3144 (vc-file-clearprops old)
3145 ;; Move the actual file (unless the backend did it already)
3146 (if (file-exists-p old) (rename-file old new))
3147 ;; ?? Renaming a file might change its contents due to keyword expansion.
3148 ;; We should really check out a new copy if the old copy was precisely equal
3149 ;; to some checked-in revision. However, testing for this is tricky....
3150 (if oldbuf
3151 (with-current-buffer oldbuf
3152 (let ((buffer-read-only buffer-read-only))
3153 (set-visited-file-name new))
3154 (vc-backend new)
3155 (vc-mode-line new)
3156 (set-buffer-modified-p nil)))))
3158 ;;;###autoload
3159 (defun vc-update-change-log (&rest args)
3160 "Find change log file and add entries from recent version control logs.
3161 Normally, find log entries for all registered files in the default
3162 directory.
3164 With prefix arg of \\[universal-argument], only find log entries for the current buffer's file.
3166 With any numeric prefix arg, find log entries for all currently visited
3167 files that are under version control. This puts all the entries in the
3168 log for the default directory, which may not be appropriate.
3170 From a program, any ARGS are assumed to be filenames for which
3171 log entries should be gathered."
3172 (interactive
3173 (cond ((consp current-prefix-arg) ;C-u
3174 (list buffer-file-name))
3175 (current-prefix-arg ;Numeric argument.
3176 (let ((files nil)
3177 (buffers (buffer-list))
3178 file)
3179 (while buffers
3180 (setq file (buffer-file-name (car buffers)))
3181 (and file (vc-backend file)
3182 (setq files (cons file files)))
3183 (setq buffers (cdr buffers)))
3184 files))
3186 ;; Don't supply any filenames to backend; this means
3187 ;; it should find all relevant files relative to
3188 ;; the default-directory.
3189 nil)))
3190 (dolist (file (or args (list default-directory)))
3191 (if (eq (string-match tramp-file-name-regexp file) 0)
3192 (error "Sorry, vc-update-change-log does not work over Tramp")))
3193 (vc-call-backend (vc-responsible-backend default-directory)
3194 'update-changelog args))
3196 ;;; The default back end. Assumes RCS-like revision numbering.
3198 (defun vc-default-revision-granularity ()
3199 (error "Your backend will not work with this version of VC mode."))
3201 ;; functions that operate on RCS revision numbers. This code should
3202 ;; also be moved into the backends. It stays for now, however, since
3203 ;; it is used in code below.
3204 ;;;###autoload
3205 (defun vc-trunk-p (rev)
3206 "Return t if REV is a revision on the trunk."
3207 (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev))))
3209 (defun vc-branch-p (rev)
3210 "Return t if REV is a branch revision."
3211 (not (eq nil (string-match "\\`[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*\\'" rev))))
3213 ;;;###autoload
3214 (defun vc-branch-part (rev)
3215 "Return the branch part of a revision number REV."
3216 (let ((index (string-match "\\.[0-9]+\\'" rev)))
3217 (if index
3218 (substring rev 0 index))))
3220 (defun vc-minor-part (rev)
3221 "Return the minor revision number of a revision number REV."
3222 (string-match "[0-9]+\\'" rev)
3223 (substring rev (match-beginning 0) (match-end 0)))
3225 (defun vc-default-previous-revision (backend file rev)
3226 "Return the revision number immediately preceding REV for FILE,
3227 or nil if there is no previous revision. This default
3228 implementation works for MAJOR.MINOR-style revision numbers as
3229 used by RCS and CVS."
3230 (let ((branch (vc-branch-part rev))
3231 (minor-num (string-to-number (vc-minor-part rev))))
3232 (when branch
3233 (if (> minor-num 1)
3234 ;; revision does probably not start a branch or release
3235 (concat branch "." (number-to-string (1- minor-num)))
3236 (if (vc-trunk-p rev)
3237 ;; we are at the beginning of the trunk --
3238 ;; don't know anything to return here
3240 ;; we are at the beginning of a branch --
3241 ;; return revision of starting point
3242 (vc-branch-part branch))))))
3244 (defun vc-default-next-revision (backend file rev)
3245 "Return the revision number immediately following REV for FILE,
3246 or nil if there is no next revision. This default implementation
3247 works for MAJOR.MINOR-style revision numbers as used by RCS
3248 and CVS."
3249 (when (not (string= rev (vc-working-revision file)))
3250 (let ((branch (vc-branch-part rev))
3251 (minor-num (string-to-number (vc-minor-part rev))))
3252 (concat branch "." (number-to-string (1+ minor-num))))))
3254 (defun vc-default-responsible-p (backend file)
3255 "Indicate whether BACKEND is reponsible for FILE.
3256 The default is to return nil always."
3257 nil)
3259 (defun vc-default-could-register (backend file)
3260 "Return non-nil if BACKEND could be used to register FILE.
3261 The default implementation returns t for all files."
3264 (defun vc-default-latest-on-branch-p (backend file)
3265 "Return non-nil if FILE is the latest on its branch.
3266 This default implementation always returns non-nil, which means that
3267 editing non-current revisions is not supported by default."
3270 (defun vc-default-init-revision (backend) vc-default-init-revision)
3272 (defalias 'vc-cvs-update-changelog 'vc-update-changelog-rcs2log)
3273 (defalias 'vc-rcs-update-changelog 'vc-update-changelog-rcs2log)
3274 ;; FIXME: This should probably be moved to vc-rcs.el and replaced in
3275 ;; vc-cvs.el by code using cvs2cl.
3276 (defun vc-update-changelog-rcs2log (files)
3277 "Default implementation of update-changelog.
3278 Uses `rcs2log' which only works for RCS and CVS."
3279 ;; FIXME: We (c|sh)ould add support for cvs2cl
3280 (let ((odefault default-directory)
3281 (changelog (find-change-log))
3282 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
3283 (tempfile (make-temp-file
3284 (expand-file-name "vc"
3285 (or small-temporary-file-directory
3286 temporary-file-directory))))
3287 (login-name (or user-login-name
3288 (format "uid%d" (number-to-string (user-uid)))))
3289 (full-name (or add-log-full-name
3290 (user-full-name)
3291 (user-login-name)
3292 (format "uid%d" (number-to-string (user-uid)))))
3293 (mailing-address (or add-log-mailing-address
3294 user-mail-address)))
3295 (find-file-other-window changelog)
3296 (barf-if-buffer-read-only)
3297 (vc-buffer-sync)
3298 (undo-boundary)
3299 (goto-char (point-min))
3300 (push-mark)
3301 (message "Computing change log entries...")
3302 (message "Computing change log entries... %s"
3303 (unwind-protect
3304 (progn
3305 (setq default-directory odefault)
3306 (if (eq 0 (apply 'call-process
3307 (expand-file-name "rcs2log"
3308 exec-directory)
3309 nil (list t tempfile) nil
3310 "-c" changelog
3311 "-u" (concat login-name
3312 "\t" full-name
3313 "\t" mailing-address)
3314 (mapcar
3315 (lambda (f)
3316 (file-relative-name
3317 (expand-file-name f odefault)))
3318 files)))
3319 "done"
3320 (pop-to-buffer (get-buffer-create "*vc*"))
3321 (erase-buffer)
3322 (insert-file-contents tempfile)
3323 "failed"))
3324 (setq default-directory (file-name-directory changelog))
3325 (delete-file tempfile)))))
3327 (defun vc-default-find-revision (backend file rev buffer)
3328 "Provide the new `find-revision' op based on the old `checkout' op.
3329 This is only for compatibility with old backends. They should be updated
3330 to provide the `find-revision' operation instead."
3331 (let ((tmpfile (make-temp-file (expand-file-name file))))
3332 (unwind-protect
3333 (progn
3334 (vc-call-backend backend 'checkout file nil rev tmpfile)
3335 (with-current-buffer buffer
3336 (insert-file-contents-literally tmpfile)))
3337 (delete-file tmpfile))))
3339 (defun vc-default-dired-state-info (backend file)
3340 (let* ((state (vc-state file))
3341 (statestring
3342 (cond
3343 ((stringp state) (concat "(" state ")"))
3344 ((eq state 'edited) (concat "(" (vc-user-login-name file) ")"))
3345 ((eq state 'needs-merge) "(merge)")
3346 ((eq state 'needs-patch) "(patch)")
3347 ((eq state 'added) "(added)")
3348 ((eq state 'removed) "(removed)")
3349 ((eq state 'ignored) "(ignored)") ;; dired-hook filters this out
3350 ((eq state 'unregistered) "?")
3351 ((eq state 'unlocked-changes) "(stale)")
3352 ((not state) "(unknown)")))
3353 (buffer
3354 (get-file-buffer file))
3355 (modflag
3356 (if (and buffer (buffer-modified-p buffer)) "+" "")))
3357 (concat statestring modflag)))
3359 (defun vc-default-rename-file (backend old new)
3360 (condition-case nil
3361 (add-name-to-file old new)
3362 (error (rename-file old new)))
3363 (vc-delete-file old)
3364 (with-current-buffer (find-file-noselect new)
3365 (vc-register)))
3367 (defalias 'vc-default-logentry-check 'ignore)
3368 (defalias 'vc-default-check-headers 'ignore)
3370 (defun vc-default-log-view-mode (backend) (log-view-mode))
3372 (defun vc-default-show-log-entry (backend rev)
3373 (with-no-warnings
3374 (log-view-goto-rev rev)))
3376 (defun vc-default-comment-history (backend file)
3377 "Return a string with all log entries stored in BACKEND for FILE."
3378 (if (vc-find-backend-function backend 'print-log)
3379 (with-current-buffer "*vc*"
3380 (vc-call print-log (list file))
3381 (vc-call-backend backend 'wash-log)
3382 (buffer-string))))
3384 (defun vc-default-receive-file (backend file rev)
3385 "Let BACKEND receive FILE from another version control system."
3386 (vc-call-backend backend 'register file rev ""))
3388 (defun vc-default-create-snapshot (backend dir name branchp)
3389 (when branchp
3390 (error "VC backend %s does not support module branches" backend))
3391 (let ((result (vc-snapshot-precondition dir)))
3392 (if (stringp result)
3393 (error "File %s is not up-to-date" result)
3394 (vc-file-tree-walk
3396 (lambda (f)
3397 (vc-call assign-name f name))))))
3399 (defun vc-default-retrieve-snapshot (backend dir name update)
3400 (if (string= name "")
3401 (progn
3402 (vc-file-tree-walk
3404 (lambda (f) (and
3405 (vc-up-to-date-p f)
3406 (vc-error-occurred
3407 (vc-call checkout f nil "")
3408 (if update (vc-resynch-buffer f t t)))))))
3409 (let ((result (vc-snapshot-precondition dir)))
3410 (if (stringp result)
3411 (error "File %s is locked" result)
3412 (setq update (and (eq result 'visited) update))
3413 (vc-file-tree-walk
3415 (lambda (f) (vc-error-occurred
3416 (vc-call checkout f nil name)
3417 (if update (vc-resynch-buffer f t t)))))))))
3419 (defun vc-default-revert (backend file contents-done)
3420 (unless contents-done
3421 (let ((rev (vc-working-revision file))
3422 (file-buffer (or (get-file-buffer file) (current-buffer))))
3423 (message "Checking out %s..." file)
3424 (let ((failed t)
3425 (backup-name (car (find-backup-file-name file))))
3426 (when backup-name
3427 (copy-file file backup-name 'ok-if-already-exists 'keep-date)
3428 (unless (file-writable-p file)
3429 (set-file-modes file (logior (file-modes file) 128))))
3430 (unwind-protect
3431 (let ((coding-system-for-read 'no-conversion)
3432 (coding-system-for-write 'no-conversion))
3433 (with-temp-file file
3434 (let ((outbuf (current-buffer)))
3435 ;; Change buffer to get local value of vc-checkout-switches.
3436 (with-current-buffer file-buffer
3437 (let ((default-directory (file-name-directory file)))
3438 (vc-call find-revision file rev outbuf)))))
3439 (setq failed nil))
3440 (when backup-name
3441 (if failed
3442 (rename-file backup-name file 'ok-if-already-exists)
3443 (and (not vc-make-backup-files) (delete-file backup-name))))))
3444 (message "Checking out %s...done" file))))
3446 (defalias 'vc-default-revision-completion-table 'ignore)
3448 (defun vc-check-headers ()
3449 "Check if the current file has any headers in it."
3450 (interactive)
3451 (vc-call-backend (vc-backend buffer-file-name) 'check-headers))
3453 ;;; Annotate functionality
3455 ;; Declare globally instead of additional parameter to
3456 ;; temp-buffer-show-function (not possible to pass more than one
3457 ;; parameter). The use of annotate-ratio is deprecated in favor of
3458 ;; annotate-mode, which replaces it with the more sensible "span-to
3459 ;; days", along with autoscaling support.
3460 (defvar vc-annotate-ratio nil "Global variable.")
3462 ;; internal buffer-local variables
3463 (defvar vc-annotate-backend nil)
3464 (defvar vc-annotate-parent-file nil)
3465 (defvar vc-annotate-parent-rev nil)
3466 (defvar vc-annotate-parent-display-mode nil)
3468 (defconst vc-annotate-font-lock-keywords
3469 ;; The fontification is done by vc-annotate-lines instead of font-lock.
3470 '((vc-annotate-lines)))
3472 (define-derived-mode vc-annotate-mode fundamental-mode "Annotate"
3473 "Major mode for output buffers of the `vc-annotate' command.
3475 You can use the mode-specific menu to alter the time-span of the used
3476 colors. See variable `vc-annotate-menu-elements' for customizing the
3477 menu items."
3478 ;; Frob buffer-invisibility-spec so that if it is originally a naked t,
3479 ;; it will become a list, to avoid initial annotations being invisible.
3480 (add-to-invisibility-spec 'foo)
3481 (remove-from-invisibility-spec 'foo)
3482 (set (make-local-variable 'truncate-lines) t)
3483 (set (make-local-variable 'font-lock-defaults)
3484 '(vc-annotate-font-lock-keywords t))
3485 (view-mode 1))
3487 (defun vc-annotate-toggle-annotation-visibility ()
3488 "Toggle whether or not the annotation is visible."
3489 (interactive)
3490 (funcall (if (memq 'vc-annotate-annotation buffer-invisibility-spec)
3491 'remove-from-invisibility-spec
3492 'add-to-invisibility-spec)
3493 'vc-annotate-annotation)
3494 (force-window-update (current-buffer)))
3496 (defun vc-annotate-display-default (ratio)
3497 "Display the output of \\[vc-annotate] using the default color range.
3498 The color range is given by `vc-annotate-color-map', scaled by RATIO.
3499 The current time is used as the offset."
3500 (interactive (progn (kill-local-variable 'vc-annotate-color-map) '(1.0)))
3501 (message "Redisplaying annotation...")
3502 (vc-annotate-display ratio)
3503 (message "Redisplaying annotation...done"))
3505 (defun vc-annotate-oldest-in-map (color-map)
3506 "Return the oldest time in the COLOR-MAP."
3507 ;; Since entries should be sorted, we can just use the last one.
3508 (caar (last color-map)))
3510 (defun vc-annotate-get-time-set-line-props ()
3511 (let ((bol (point))
3512 (date (vc-call-backend vc-annotate-backend 'annotate-time))
3513 (inhibit-read-only t))
3514 (assert (>= (point) bol))
3515 (put-text-property bol (point) 'invisible 'vc-annotate-annotation)
3516 date))
3518 (defun vc-annotate-display-autoscale (&optional full)
3519 "Highlight the output of \\[vc-annotate] using an autoscaled color map.
3520 Autoscaling means that the map is scaled from the current time to the
3521 oldest annotation in the buffer, or, with prefix argument FULL, to
3522 cover the range from the oldest annotation to the newest."
3523 (interactive "P")
3524 (let ((newest 0.0)
3525 (oldest 999999.) ;Any CVS users at the founding of Rome?
3526 (current (vc-annotate-convert-time (current-time)))
3527 date)
3528 (message "Redisplaying annotation...")
3529 ;; Run through this file and find the oldest and newest dates annotated.
3530 (save-excursion
3531 (goto-char (point-min))
3532 (while (not (eobp))
3533 (when (setq date (vc-annotate-get-time-set-line-props))
3534 (if (> date newest)
3535 (setq newest date))
3536 (if (< date oldest)
3537 (setq oldest date)))
3538 (forward-line 1)))
3539 (vc-annotate-display
3540 (/ (- (if full newest current) oldest)
3541 (vc-annotate-oldest-in-map vc-annotate-color-map))
3542 (if full newest))
3543 (message "Redisplaying annotation...done \(%s\)"
3544 (if full
3545 (format "Spanned from %.1f to %.1f days old"
3546 (- current oldest)
3547 (- current newest))
3548 (format "Spanned to %.1f days old" (- current oldest))))))
3550 ;; Menu -- Using easymenu.el
3551 (easy-menu-define vc-annotate-mode-menu vc-annotate-mode-map
3552 "VC Annotate Display Menu"
3553 `("VC-Annotate"
3554 ["By Color Map Range" (unless (null vc-annotate-display-mode)
3555 (setq vc-annotate-display-mode nil)
3556 (vc-annotate-display-select))
3557 :style toggle :selected (null vc-annotate-display-mode)]
3558 ,@(let ((oldest-in-map (vc-annotate-oldest-in-map vc-annotate-color-map)))
3559 (mapcar (lambda (element)
3560 (let ((days (* element oldest-in-map)))
3561 `[,(format "Span %.1f days" days)
3562 (vc-annotate-display-select nil ,days)
3563 :style toggle :selected
3564 (eql vc-annotate-display-mode ,days) ]))
3565 vc-annotate-menu-elements))
3566 ["Span ..."
3567 (vc-annotate-display-select
3568 nil (float (string-to-number (read-string "Span how many days? "))))]
3569 "--"
3570 ["Span to Oldest"
3571 (unless (eq vc-annotate-display-mode 'scale)
3572 (vc-annotate-display-select nil 'scale))
3573 :style toggle :selected
3574 (eq vc-annotate-display-mode 'scale)]
3575 ["Span Oldest->Newest"
3576 (unless (eq vc-annotate-display-mode 'fullscale)
3577 (vc-annotate-display-select nil 'fullscale))
3578 :style toggle :selected
3579 (eq vc-annotate-display-mode 'fullscale)]
3580 "--"
3581 ["Toggle annotation visibility" vc-annotate-toggle-annotation-visibility]
3582 ["Annotate previous revision" vc-annotate-prev-revision]
3583 ["Annotate next revision" vc-annotate-next-revision]
3584 ["Annotate revision at line" vc-annotate-revision-at-line]
3585 ["Annotate revision previous to line" vc-annotate-revision-previous-to-line]
3586 ["Annotate latest revision" vc-annotate-working-revision]
3587 ["Show log of revision at line" vc-annotate-show-log-revision-at-line]
3588 ["Show diff of revision at line" vc-annotate-show-diff-revision-at-line]))
3590 (defun vc-annotate-display-select (&optional buffer mode)
3591 "Highlight the output of \\[vc-annotate].
3592 By default, the current buffer is highlighted, unless overridden by
3593 BUFFER. `vc-annotate-display-mode' specifies the highlighting mode to
3594 use; you may override this using the second optional arg MODE."
3595 (interactive)
3596 (if mode (setq vc-annotate-display-mode mode))
3597 (pop-to-buffer (or buffer (current-buffer)))
3598 (cond ((null vc-annotate-display-mode)
3599 ;; The ratio is global, thus relative to the global color-map.
3600 (kill-local-variable 'vc-annotate-color-map)
3601 (vc-annotate-display-default (or vc-annotate-ratio 1.0)))
3602 ;; One of the auto-scaling modes
3603 ((eq vc-annotate-display-mode 'scale)
3604 (vc-exec-after `(vc-annotate-display-autoscale)))
3605 ((eq vc-annotate-display-mode 'fullscale)
3606 (vc-exec-after `(vc-annotate-display-autoscale t)))
3607 ((numberp vc-annotate-display-mode) ; A fixed number of days lookback
3608 (vc-annotate-display-default
3609 (/ vc-annotate-display-mode
3610 (vc-annotate-oldest-in-map vc-annotate-color-map))))
3611 (t (error "No such display mode: %s"
3612 vc-annotate-display-mode))))
3614 ;;;###autoload
3615 (defun vc-annotate (file rev &optional display-mode buf)
3616 "Display the edit history of the current file using colors.
3618 This command creates a buffer that shows, for each line of the current
3619 file, when it was last edited and by whom. Additionally, colors are
3620 used to show the age of each line--blue means oldest, red means
3621 youngest, and intermediate colors indicate intermediate ages. By
3622 default, the time scale stretches back one year into the past;
3623 everything that is older than that is shown in blue.
3625 With a prefix argument, this command asks two questions in the
3626 minibuffer. First, you may enter a revision number; then the buffer
3627 displays and annotates that revision instead of the working revision
3628 \(type RET in the minibuffer to leave that default unchanged). Then,
3629 you are prompted for the time span in days which the color range
3630 should cover. For example, a time span of 20 days means that changes
3631 over the past 20 days are shown in red to blue, according to their
3632 age, and everything that is older than that is shown in blue.
3634 Customization variables:
3636 `vc-annotate-menu-elements' customizes the menu elements of the
3637 mode-specific menu. `vc-annotate-color-map' and
3638 `vc-annotate-very-old-color' define the mapping of time to colors.
3639 `vc-annotate-background' specifies the background color."
3640 (interactive
3641 (save-current-buffer
3642 (vc-ensure-vc-buffer)
3643 (list buffer-file-name
3644 (let ((def (vc-working-revision buffer-file-name)))
3645 (if (null current-prefix-arg) def
3646 (read-string
3647 (format "Annotate from revision (default %s): " def)
3648 nil nil def)))
3649 (if (null current-prefix-arg)
3650 vc-annotate-display-mode
3651 (float (string-to-number
3652 (read-string "Annotate span days (default 20): "
3653 nil nil "20")))))))
3654 (vc-ensure-vc-buffer)
3655 (setq vc-annotate-display-mode display-mode) ;Not sure why. --Stef
3656 (let* ((temp-buffer-name (format "*Annotate %s (rev %s)*" (buffer-name) rev))
3657 (temp-buffer-show-function 'vc-annotate-display-select)
3658 ;; If BUF is specified, we presume the caller maintains current line,
3659 ;; so we don't need to do it here. This implementation may give
3660 ;; strange results occasionally in the case of REV != WORKFILE-REV.
3661 (current-line (unless buf (line-number-at-pos))))
3662 (message "Annotating...")
3663 ;; If BUF is specified it tells in which buffer we should put the
3664 ;; annotations. This is used when switching annotations to another
3665 ;; revision, so we should update the buffer's name.
3666 (if buf (with-current-buffer buf
3667 (rename-buffer temp-buffer-name t)
3668 ;; In case it had to be uniquified.
3669 (setq temp-buffer-name (buffer-name))))
3670 (with-output-to-temp-buffer temp-buffer-name
3671 (vc-call annotate-command file (get-buffer temp-buffer-name) rev)
3672 ;; we must setup the mode first, and then set our local
3673 ;; variables before the show-function is called at the exit of
3674 ;; with-output-to-temp-buffer
3675 (with-current-buffer temp-buffer-name
3676 (if (not (equal major-mode 'vc-annotate-mode))
3677 (vc-annotate-mode))
3678 (set (make-local-variable 'vc-annotate-backend) (vc-backend file))
3679 (set (make-local-variable 'vc-annotate-parent-file) file)
3680 (set (make-local-variable 'vc-annotate-parent-rev) rev)
3681 (set (make-local-variable 'vc-annotate-parent-display-mode)
3682 display-mode)))
3684 (with-current-buffer temp-buffer-name
3685 (vc-exec-after
3686 `(progn
3687 ;; Ideally, we'd rather not move point if the user has already
3688 ;; moved it elsewhere, but really point here is not the position
3689 ;; of the user's cursor :-(
3690 (when ,current-line ;(and (bobp))
3691 (goto-line ,current-line)
3692 (setq vc-sentinel-movepoint (point)))
3693 (unless (active-minibuffer-window)
3694 (message "Annotating... done")))))))
3696 (defun vc-annotate-prev-revision (prefix)
3697 "Visit the annotation of the revision previous to this one.
3699 With a numeric prefix argument, annotate the revision that many
3700 revisions previous."
3701 (interactive "p")
3702 (vc-annotate-warp-revision (- 0 prefix)))
3704 (defun vc-annotate-next-revision (prefix)
3705 "Visit the annotation of the revision after this one.
3707 With a numeric prefix argument, annotate the revision that many
3708 revisions after."
3709 (interactive "p")
3710 (vc-annotate-warp-revision prefix))
3712 (defun vc-annotate-working-revision ()
3713 "Visit the annotation of the working revision of this file."
3714 (interactive)
3715 (if (not (equal major-mode 'vc-annotate-mode))
3716 (message "Cannot be invoked outside of a vc annotate buffer")
3717 (let ((warp-rev (vc-working-revision vc-annotate-parent-file)))
3718 (if (equal warp-rev vc-annotate-parent-rev)
3719 (message "Already at revision %s" warp-rev)
3720 (vc-annotate-warp-revision warp-rev)))))
3722 (defun vc-annotate-extract-revision-at-line ()
3723 "Extract the revision number of the current line."
3724 ;; This function must be invoked from a buffer in vc-annotate-mode
3725 (vc-call-backend vc-annotate-backend 'annotate-extract-revision-at-line))
3727 (defun vc-annotate-revision-at-line ()
3728 "Visit the annotation of the revision identified in the current line."
3729 (interactive)
3730 (if (not (equal major-mode 'vc-annotate-mode))
3731 (message "Cannot be invoked outside of a vc annotate buffer")
3732 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
3733 (if (not rev-at-line)
3734 (message "Cannot extract revision number from the current line")
3735 (if (equal rev-at-line vc-annotate-parent-rev)
3736 (message "Already at revision %s" rev-at-line)
3737 (vc-annotate-warp-revision rev-at-line))))))
3739 (defun vc-annotate-revision-previous-to-line ()
3740 "Visit the annotation of the revision before the revision at line."
3741 (interactive)
3742 (if (not (equal major-mode 'vc-annotate-mode))
3743 (message "Cannot be invoked outside of a vc annotate buffer")
3744 (let ((rev-at-line (vc-annotate-extract-revision-at-line))
3745 (prev-rev nil))
3746 (if (not rev-at-line)
3747 (message "Cannot extract revision number from the current line")
3748 (setq prev-rev
3749 (vc-call previous-revision vc-annotate-parent-file rev-at-line))
3750 (vc-annotate-warp-revision prev-rev)))))
3752 (defun vc-annotate-show-log-revision-at-line ()
3753 "Visit the log of the revision at line."
3754 (interactive)
3755 (if (not (equal major-mode 'vc-annotate-mode))
3756 (message "Cannot be invoked outside of a vc annotate buffer")
3757 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
3758 (if (not rev-at-line)
3759 (message "Cannot extract revision number from the current line")
3760 (vc-print-log rev-at-line)))))
3762 (defun vc-annotate-show-diff-revision-at-line ()
3763 "Visit the diff of the revision at line from its previous revision."
3764 (interactive)
3765 (if (not (equal major-mode 'vc-annotate-mode))
3766 (message "Cannot be invoked outside of a vc annotate buffer")
3767 (let ((rev-at-line (vc-annotate-extract-revision-at-line))
3768 (prev-rev nil))
3769 (if (not rev-at-line)
3770 (message "Cannot extract revision number from the current line")
3771 (setq prev-rev
3772 (vc-call previous-revision vc-annotate-parent-file rev-at-line))
3773 (if (not prev-rev)
3774 (message "Cannot diff from any revision prior to %s" rev-at-line)
3775 (save-window-excursion
3776 (vc-diff-internal nil (list vc-annotate-parent-file)
3777 prev-rev rev-at-line))
3778 (switch-to-buffer "*vc-diff*"))))))
3780 (defun vc-annotate-warp-revision (revspec)
3781 "Annotate the revision described by REVSPEC.
3783 If REVSPEC is a positive integer, warp that many revisions
3784 forward, if possible, otherwise echo a warning message. If
3785 REVSPEC is a negative integer, warp that many revisions backward,
3786 if possible, otherwise echo a warning message. If REVSPEC is a
3787 string, then it describes a revision number, so warp to that
3788 revision."
3789 (if (not (equal major-mode 'vc-annotate-mode))
3790 (message "Cannot be invoked outside of a vc annotate buffer")
3791 (let* ((buf (current-buffer))
3792 (oldline (line-number-at-pos))
3793 (revspeccopy revspec)
3794 (newrev nil))
3795 (cond
3796 ((and (integerp revspec) (> revspec 0))
3797 (setq newrev vc-annotate-parent-rev)
3798 (while (and (> revspec 0) newrev)
3799 (setq newrev (vc-call next-revision
3800 vc-annotate-parent-file newrev))
3801 (setq revspec (1- revspec)))
3802 (if (not newrev)
3803 (message "Cannot increment %d revisions from revision %s"
3804 revspeccopy vc-annotate-parent-rev)))
3805 ((and (integerp revspec) (< revspec 0))
3806 (setq newrev vc-annotate-parent-rev)
3807 (while (and (< revspec 0) newrev)
3808 (setq newrev (vc-call previous-revision
3809 vc-annotate-parent-file newrev))
3810 (setq revspec (1+ revspec)))
3811 (if (not newrev)
3812 (message "Cannot decrement %d revisions from revision %s"
3813 (- 0 revspeccopy) vc-annotate-parent-rev)))
3814 ((stringp revspec) (setq newrev revspec))
3815 (t (error "Invalid argument to vc-annotate-warp-revision")))
3816 (when newrev
3817 (vc-annotate vc-annotate-parent-file newrev
3818 vc-annotate-parent-display-mode
3819 buf)
3820 (goto-line (min oldline (progn (goto-char (point-max))
3821 (forward-line -1)
3822 (line-number-at-pos))) buf)))))
3824 (defun vc-annotate-compcar (threshold a-list)
3825 "Test successive cons cells of A-LIST against THRESHOLD.
3826 Return the first cons cell with a car that is not less than THRESHOLD,
3827 nil if no such cell exists."
3828 (let ((i 1)
3829 (tmp-cons (car a-list)))
3830 (while (and tmp-cons (< (car tmp-cons) threshold))
3831 (setq tmp-cons (car (nthcdr i a-list)))
3832 (setq i (+ i 1)))
3833 tmp-cons)) ; Return the appropriate value
3835 (defun vc-annotate-convert-time (time)
3836 "Convert a time value to a floating-point number of days.
3837 The argument TIME is a list as returned by `current-time' or
3838 `encode-time', only the first two elements of that list are considered."
3839 (/ (+ (* (float (car time)) (lsh 1 16)) (cadr time)) 24 3600))
3841 (defun vc-annotate-difference (&optional offset)
3842 "Return the time span in days to the next annotation.
3843 This calls the backend function annotate-time, and returns the
3844 difference in days between the time returned and the current time,
3845 or OFFSET if present."
3846 (let ((next-time (vc-annotate-get-time-set-line-props)))
3847 (if next-time
3848 (- (or offset
3849 (vc-call-backend vc-annotate-backend 'annotate-current-time))
3850 next-time))))
3852 (defun vc-default-annotate-current-time (backend)
3853 "Return the current time, encoded as fractional days."
3854 (vc-annotate-convert-time (current-time)))
3856 (defvar vc-annotate-offset nil)
3858 (defun vc-annotate-display (ratio &optional offset)
3859 "Highlight `vc-annotate' output in the current buffer.
3860 RATIO, is the expansion that should be applied to `vc-annotate-color-map'.
3861 The annotations are relative to the current time, unless overridden by OFFSET."
3862 (if (/= ratio 1.0)
3863 (set (make-local-variable 'vc-annotate-color-map)
3864 (mapcar (lambda (elem) (cons (* (car elem) ratio) (cdr elem)))
3865 vc-annotate-color-map)))
3866 (set (make-local-variable 'vc-annotate-offset) offset)
3867 (font-lock-mode 1))
3869 (defun vc-annotate-lines (limit)
3870 (while (< (point) limit)
3871 (let ((difference (vc-annotate-difference vc-annotate-offset))
3872 (start (point))
3873 (end (progn (forward-line 1) (point))))
3874 (when difference
3875 (let* ((color (or (vc-annotate-compcar difference vc-annotate-color-map)
3876 (cons nil vc-annotate-very-old-color)))
3877 ;; substring from index 1 to remove any leading `#' in the name
3878 (face-name (concat "vc-annotate-face-"
3879 (if (string-equal
3880 (substring (cdr color) 0 1) "#")
3881 (substring (cdr color) 1)
3882 (cdr color))))
3883 ;; Make the face if not done.
3884 (face (or (intern-soft face-name)
3885 (let ((tmp-face (make-face (intern face-name))))
3886 (set-face-foreground tmp-face (cdr color))
3887 (if vc-annotate-background
3888 (set-face-background tmp-face
3889 vc-annotate-background))
3890 tmp-face)))) ; Return the face
3891 (put-text-property start end 'face face)))))
3892 ;; Pretend to font-lock there were no matches.
3893 nil)
3896 ;; Set up key bindings for use while editing log messages
3898 (defun vc-log-edit (fileset)
3899 "Set up `log-edit' for use with VC on FILE."
3900 (setq default-directory
3901 (with-current-buffer vc-parent-buffer default-directory))
3902 (log-edit 'vc-finish-logentry
3904 `((log-edit-listfun . (lambda () ',fileset))
3905 (log-edit-diff-function . (lambda () (vc-diff nil)))))
3906 (set (make-local-variable 'vc-log-fileset) fileset)
3907 (make-local-variable 'vc-log-revision)
3908 (set-buffer-modified-p nil)
3909 (setq buffer-file-name nil))
3911 ;; These things should probably be generally available
3913 (defun vc-file-tree-walk (dirname func &rest args)
3914 "Walk recursively through DIRNAME.
3915 Invoke FUNC f ARGS on each VC-managed file f underneath it."
3916 (vc-file-tree-walk-internal (expand-file-name dirname) func args)
3917 (message "Traversing directory %s...done" dirname))
3919 (defun vc-file-tree-walk-internal (file func args)
3920 (if (not (file-directory-p file))
3921 (if (vc-backend file) (apply func file args))
3922 (message "Traversing directory %s..." (abbreviate-file-name file))
3923 (let ((dir (file-name-as-directory file)))
3924 (mapcar
3925 (lambda (f) (or
3926 (string-equal f ".")
3927 (string-equal f "..")
3928 (member f vc-directory-exclusion-list)
3929 (let ((dirf (expand-file-name f dir)))
3931 (file-symlink-p dirf) ;; Avoid possible loops.
3932 (vc-file-tree-walk-internal dirf func args)))))
3933 (directory-files dir)))))
3935 (provide 'vc)
3937 ;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
3939 ;; These may be useful to anyone who has to debug or extend the package.
3940 ;; (Note that this information corresponds to versions 5.x. Some of it
3941 ;; might have been invalidated by the additions to support branching
3942 ;; and RCS keyword lookup. AS, 1995/03/24)
3944 ;; A fundamental problem in VC is that there are time windows between
3945 ;; vc-next-action's computations of the file's version-control state and
3946 ;; the actions that change it. This is a window open to lossage in a
3947 ;; multi-user environment; someone else could nip in and change the state
3948 ;; of the master during it.
3950 ;; The performance problem is that rlog/prs calls are very expensive; we want
3951 ;; to avoid them as much as possible.
3953 ;; ANALYSIS:
3955 ;; The performance problem, it turns out, simplifies in practice to the
3956 ;; problem of making vc-state fast. The two other functions that call
3957 ;; prs/rlog will not be so commonly used that the slowdown is a problem; one
3958 ;; makes snapshots, the other deletes the calling user's last change in the
3959 ;; master.
3961 ;; The race condition implies that we have to either (a) lock the master
3962 ;; during the entire execution of vc-next-action, or (b) detect and
3963 ;; recover from errors resulting from dispatch on an out-of-date state.
3965 ;; Alternative (a) appears to be infeasible. The problem is that we can't
3966 ;; guarantee that the lock will ever be removed. Suppose a user starts a
3967 ;; checkin, the change message buffer pops up, and the user, having wandered
3968 ;; off to do something else, simply forgets about it?
3970 ;; Alternative (b), on the other hand, works well with a cheap way to speed up
3971 ;; vc-state. Usually, if a file is registered, we can read its locked/
3972 ;; unlocked state and its current owner from its permissions.
3974 ;; This shortcut will fail if someone has manually changed the workfile's
3975 ;; permissions; also if developers are munging the workfile in several
3976 ;; directories, with symlinks to a master (in this latter case, the
3977 ;; permissions shortcut will fail to detect a lock asserted from another
3978 ;; directory).
3980 ;; Note that these cases correspond exactly to the errors which could happen
3981 ;; because of a competing checkin/checkout race in between two instances of
3982 ;; vc-next-action.
3984 ;; For VC's purposes, a workfile/master pair may have the following states:
3986 ;; A. Unregistered. There is a workfile, there is no master.
3988 ;; B. Registered and not locked by anyone.
3990 ;; C. Locked by calling user and unchanged.
3992 ;; D. Locked by the calling user and changed.
3994 ;; E. Locked by someone other than the calling user.
3996 ;; This makes for 25 states and 20 error conditions. Here's the matrix:
3998 ;; VC's idea of state
3999 ;; |
4000 ;; V Actual state RCS action SCCS action Effect
4001 ;; A B C D E
4002 ;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
4003 ;; B 5 . 6 7 8 co -l get -e checkout
4004 ;; C 9 10 . 11 12 co -u unget; get revert
4005 ;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
4006 ;; E 17 18 19 20 . rcs -u -M -l unget -n ; get -g steal lock
4008 ;; All commands take the master file name as a last argument (not shown).
4010 ;; In the discussion below, a "self-race" is a pathological situation in
4011 ;; which VC operations are being attempted simultaneously by two or more
4012 ;; Emacsen running under the same username.
4014 ;; The vc-next-action code has the following windows:
4016 ;; Window P:
4017 ;; Between the check for existence of a master file and the call to
4018 ;; admin/checkin in vc-buffer-admin (apparent state A). This window may
4019 ;; never close if the initial-comment feature is on.
4021 ;; Window Q:
4022 ;; Between the call to vc-workfile-unchanged-p in and the immediately
4023 ;; following revert (apparent state C).
4025 ;; Window R:
4026 ;; Between the call to vc-workfile-unchanged-p in and the following
4027 ;; checkin (apparent state D). This window may never close.
4029 ;; Window S:
4030 ;; Between the unlock and the immediately following checkout during a
4031 ;; revert operation (apparent state C). Included in window Q.
4033 ;; Window T:
4034 ;; Between vc-state and the following checkout (apparent state B).
4036 ;; Window U:
4037 ;; Between vc-state and the following revert (apparent state C).
4038 ;; Includes windows Q and S.
4040 ;; Window V:
4041 ;; Between vc-state and the following checkin (apparent state
4042 ;; D). This window may never be closed if the user fails to complete the
4043 ;; checkin message. Includes window R.
4045 ;; Window W:
4046 ;; Between vc-state and the following steal-lock (apparent
4047 ;; state E). This window may never close if the user fails to complete
4048 ;; the steal-lock message. Includes window X.
4050 ;; Window X:
4051 ;; Between the unlock and the immediately following re-lock during a
4052 ;; steal-lock operation (apparent state E). This window may never close
4053 ;; if the user fails to complete the steal-lock message.
4055 ;; Errors:
4057 ;; Apparent state A ---
4059 ;; 1. File looked unregistered but is actually registered and not locked.
4061 ;; Potential cause: someone else's admin during window P, with
4062 ;; caller's admin happening before their checkout.
4064 ;; RCS: Prior to version 5.6.4, ci fails with message
4065 ;; "no lock set by <user>". From 5.6.4 onwards, VC uses the new
4066 ;; ci -i option and the message is "<file>,v: already exists".
4067 ;; SCCS: admin will fail with error (ad19).
4069 ;; We can let these errors be passed up to the user.
4071 ;; 2. File looked unregistered but is actually locked by caller, unchanged.
4073 ;; Potential cause: self-race during window P.
4075 ;; RCS: Prior to version 5.6.4, reverts the file to the last saved
4076 ;; version and unlocks it. From 5.6.4 onwards, VC uses the new
4077 ;; ci -i option, failing with message "<file>,v: already exists".
4078 ;; SCCS: will fail with error (ad19).
4080 ;; Either of these consequences is acceptable.
4082 ;; 3. File looked unregistered but is actually locked by caller, changed.
4084 ;; Potential cause: self-race during window P.
4086 ;; RCS: Prior to version 5.6.4, VC registers the caller's workfile as
4087 ;; a delta with a null change comment (the -t- switch will be
4088 ;; ignored). From 5.6.4 onwards, VC uses the new ci -i option,
4089 ;; failing with message "<file>,v: already exists".
4090 ;; SCCS: will fail with error (ad19).
4092 ;; 4. File looked unregistered but is locked by someone else.
4094 ;; Potential cause: someone else's admin during window P, with
4095 ;; caller's admin happening *after* their checkout.
4097 ;; RCS: Prior to version 5.6.4, ci fails with a
4098 ;; "no lock set by <user>" message. From 5.6.4 onwards,
4099 ;; VC uses the new ci -i option, failing with message
4100 ;; "<file>,v: already exists".
4101 ;; SCCS: will fail with error (ad19).
4103 ;; We can let these errors be passed up to the user.
4105 ;; Apparent state B ---
4107 ;; 5. File looked registered and not locked, but is actually unregistered.
4109 ;; Potential cause: master file got nuked during window P.
4111 ;; RCS: will fail with "RCS/<file>: No such file or directory"
4112 ;; SCCS: will fail with error ut4.
4114 ;; We can let these errors be passed up to the user.
4116 ;; 6. File looked registered and not locked, but is actually locked by the
4117 ;; calling user and unchanged.
4119 ;; Potential cause: self-race during window T.
4121 ;; RCS: in the same directory as the previous workfile, co -l will fail
4122 ;; with "co error: writable foo exists; checkout aborted". In any other
4123 ;; directory, checkout will succeed.
4124 ;; SCCS: will fail with ge17.
4126 ;; Either of these consequences is acceptable.
4128 ;; 7. File looked registered and not locked, but is actually locked by the
4129 ;; calling user and changed.
4131 ;; As case 6.
4133 ;; 8. File looked registered and not locked, but is actually locked by another
4134 ;; user.
4136 ;; Potential cause: someone else checks it out during window T.
4138 ;; RCS: co error: revision 1.3 already locked by <user>
4139 ;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
4141 ;; We can let these errors be passed up to the user.
4143 ;; Apparent state C ---
4145 ;; 9. File looks locked by calling user and unchanged, but is unregistered.
4147 ;; As case 5.
4149 ;; 10. File looks locked by calling user and unchanged, but is actually not
4150 ;; locked.
4152 ;; Potential cause: a self-race in window U, or by the revert's
4153 ;; landing during window X of some other user's steal-lock or window S
4154 ;; of another user's revert.
4156 ;; RCS: succeeds, refreshing the file from the identical version in
4157 ;; the master.
4158 ;; SCCS: fails with error ut4 (p file nonexistent).
4160 ;; Either of these consequences is acceptable.
4162 ;; 11. File is locked by calling user. It looks unchanged, but is actually
4163 ;; changed.
4165 ;; Potential cause: the file would have to be touched by a self-race
4166 ;; during window Q.
4168 ;; The revert will succeed, removing whatever changes came with
4169 ;; the touch. It is theoretically possible that work could be lost.
4171 ;; 12. File looks like it's locked by the calling user and unchanged, but
4172 ;; it's actually locked by someone else.
4174 ;; Potential cause: a steal-lock in window V.
4176 ;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
4177 ;; SCCS: fails with error un2
4179 ;; We can pass these errors up to the user.
4181 ;; Apparent state D ---
4183 ;; 13. File looks like it's locked by the calling user and changed, but it's
4184 ;; actually unregistered.
4186 ;; Potential cause: master file got nuked during window P.
4188 ;; RCS: Prior to version 5.6.4, checks in the user's version as an
4189 ;; initial delta. From 5.6.4 onwards, VC uses the new ci -j
4190 ;; option, failing with message "no such file or directory".
4191 ;; SCCS: will fail with error ut4.
4193 ;; This case is kind of nasty. Under RCS prior to version 5.6.4,
4194 ;; VC may fail to detect the loss of previous version information.
4196 ;; 14. File looks like it's locked by the calling user and changed, but it's
4197 ;; actually unlocked.
4199 ;; Potential cause: self-race in window V, or the checkin happening
4200 ;; during the window X of someone else's steal-lock or window S of
4201 ;; someone else's revert.
4203 ;; RCS: ci will fail with "no lock set by <user>".
4204 ;; SCCS: delta will fail with error ut4.
4206 ;; 15. File looks like it's locked by the calling user and changed, but it's
4207 ;; actually locked by the calling user and unchanged.
4209 ;; Potential cause: another self-race --- a whole checkin/checkout
4210 ;; sequence by the calling user would have to land in window R.
4212 ;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
4213 ;; RCS: reverts to the file state as of the second user's checkin, leaving
4214 ;; the file unlocked.
4216 ;; It is theoretically possible that work could be lost under RCS.
4218 ;; 16. File looks like it's locked by the calling user and changed, but it's
4219 ;; actually locked by a different user.
4221 ;; RCS: ci error: no lock set by <user>
4222 ;; SCCS: unget will fail with error un2
4224 ;; We can pass these errors up to the user.
4226 ;; Apparent state E ---
4228 ;; 17. File looks like it's locked by some other user, but it's actually
4229 ;; unregistered.
4231 ;; As case 13.
4233 ;; 18. File looks like it's locked by some other user, but it's actually
4234 ;; unlocked.
4236 ;; Potential cause: someone released a lock during window W.
4238 ;; RCS: The calling user will get the lock on the file.
4239 ;; SCCS: unget -n will fail with cm4.
4241 ;; Either of these consequences will be OK.
4243 ;; 19. File looks like it's locked by some other user, but it's actually
4244 ;; locked by the calling user and unchanged.
4246 ;; Potential cause: the other user relinquishing a lock followed by
4247 ;; a self-race, both in window W.
4249 ;; Under both RCS and SCCS, both unlock and lock will succeed, making
4250 ;; the sequence a no-op.
4252 ;; 20. File looks like it's locked by some other user, but it's actually
4253 ;; locked by the calling user and changed.
4255 ;; As case 19.
4257 ;; PROBLEM CASES:
4259 ;; In order of decreasing severity:
4261 ;; Cases 11 and 15 are the only ones that potentially lose work.
4262 ;; They would require a self-race for this to happen.
4264 ;; Case 13 in RCS loses information about previous deltas, retaining
4265 ;; only the information in the current workfile. This can only happen
4266 ;; if the master file gets nuked in window P.
4268 ;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
4269 ;; no change comment in the master. This would require a self-race in
4270 ;; window P or R respectively.
4272 ;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
4274 ;; Unfortunately, it appears to me that no recovery is possible in these
4275 ;; cases. They don't yield error messages, so there's no way to tell that
4276 ;; a race condition has occurred.
4278 ;; All other cases don't change either the workfile or the master, and
4279 ;; trigger command errors which the user will see.
4281 ;; Thus, there is no explicit recovery code.
4283 ;; arch-tag: ca82c1de-3091-4e26-af92-460abc6213a6
4284 ;;; vc.el ends here