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