(print-quoted): Docstring update.
[bpt/emacs.git] / lisp / vc.el
CommitLineData
66321b2f 1;;; vc.el --- drive a version-control system from within Emacs
594722a8 2
0d30b337 3;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
f52749ed
GM
4;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
5;; Free Software Foundation, Inc.
594722a8 6
0e362f54
GM
7;; Author: FSF (see below for full credits)
8;; Maintainer: Andre Spiegel <spiegel@gnu.org>
284b3043 9;; Keywords: tools
594722a8
ER
10
11;; This file is part of GNU Emacs.
12
13;; GNU Emacs is free software; you can redistribute it and/or modify
14;; it under the terms of the GNU General Public License as published by
b4aa6026 15;; the Free Software Foundation; either version 3, or (at your option)
594722a8
ER
16;; any later version.
17
18;; GNU Emacs is distributed in the hope that it will be useful,
19;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;; GNU General Public License for more details.
22
23;; You should have received a copy of the GNU General Public License
b578f267 24;; along with GNU Emacs; see the file COPYING. If not, write to the
086add15
LK
25;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26;; Boston, MA 02110-1301, USA.
594722a8 27
0e362f54
GM
28;;; Credits:
29
30;; VC was initially designed and implemented by Eric S. Raymond
61de26cb 31;; <esr@thyrsus.com> in 1992. Over the years, many other people have
0e362f54 32;; contributed substantial amounts of work to VC. These include:
61de26cb 33;;
0e362f54
GM
34;; Per Cederqvist <ceder@lysator.liu.se>
35;; Paul Eggert <eggert@twinsun.com>
36;; Sebastian Kremer <sk@thp.uni-koeln.de>
37;; Martin Lorentzson <martinl@gnu.org>
166a0ef7 38;; Dave Love <fx@gnu.org>
0e362f54 39;; Stefan Monnier <monnier@cs.yale.edu>
7fbb4797
DN
40;; Thien-Thi Nguyen <ttn@gnu.org>
41;; Dan Nicolaescu <dann@ics.uci.edu>
6f1ecae4 42;; J.D. Smith <jdsmith@alum.mit.edu>
0e362f54
GM
43;; Andre Spiegel <spiegel@gnu.org>
44;; Richard Stallman <rms@gnu.org>
61de26cb
ER
45;;
46;; In July 2007 ESR returned and redesigned the mode to cope better
47;; with modern version-control systems that do commits by fileset
48;; rather than per individual file.
49;;
50;; Features in the new version:
51;; * Key commands (vc-next-action = C-x v v, vc-print-log = C-x v l, vc-revert
a7192ddb 52;; = C-x v u, vc-rollback = C-x v c, vc-diff = C-x v =, vc-update = C-x v +)
61de26cb
ER
53;; now operate on filesets rather than individual files.
54;; * The fileset for a command is either (a) all marked files in VC-dired
55;; mode, (b) the currently visited file if it's under version control,
56;; or (c) the current directory if the visited buffer is not under
a7192ddb 57;; version control and a wildcarding-enable flag has been set.
61de26cb 58;;
a7192ddb
SM
59;; If you maintain a client of the mode or customize it in your .emacs,
60;; note that some backend functions which formerly took single file arguments
61de26cb
ER
61;; now take a list of files. These include: register, checkin, print-log,
62;; rollback, and diff.
0e362f54 63
594722a8
ER
64;;; Commentary:
65
1a2f456b
ER
66;; This mode is fully documented in the Emacs user's manual.
67;;
c0edfa75 68;; Supported version-control systems presently include CVS, RCS, GNU
5e8c0b8b
DN
69;; Arch, Subversion, Bzr, Git, Mercurial, Meta-CVS, Monotone and SCCS
70;; (or its free replacement, CSSC).
b0c9bc8c
AS
71;;
72;; Some features will not work with old RCS versions. Where
73;; appropriate, VC finds out which version you have, and allows or
0e362f54 74;; disallows those features (stealing locks, for example, works only
b0c9bc8c 75;; from 5.6.2 onwards).
632e9525
RS
76;; Even initial checkins will fail if your RCS version is so old that ci
77;; doesn't understand -t-; this has been known to happen to people running
0e362f54 78;; NExTSTEP 3.0.
594722a8 79;;
0e362f54 80;; You can support the RCS -x option by customizing vc-rcs-master-templates.
594722a8
ER
81;;
82;; Proper function of the SCCS diff commands requires the shellscript vcdiff
83;; to be installed somewhere on Emacs's path for executables.
84;;
1a2f456b 85;; If your site uses the ChangeLog convention supported by Emacs, the
93a142e1
DN
86;; function `log-edit-comment-to-change-log' could prove a useful checkin hook,
87;; although you might prefer to use C-c C-a (i.e. `log-edit-insert-changelog')
1cca5da4 88;; from the commit buffer instead or to set `log-edit-setup-invert'.
1a2f456b 89;;
594722a8
ER
90;; The vc code maintains some internal state in order to reduce expensive
91;; version-control operations to a minimum. Some names are only computed
3b37b179 92;; once. If you perform version control operations with the backend while
594722a8
ER
93;; vc's back is turned, or move/rename master files while vc is running,
94;; vc may get seriously confused. Don't do these things!
95;;
96;; Developer's notes on some concurrency issues are included at the end of
97;; the file.
0e362f54 98;;
fcb500ea
AS
99;; ADDING SUPPORT FOR OTHER BACKENDS
100;;
101;; VC can use arbitrary version control systems as a backend. To add
102;; support for a new backend named SYS, write a library vc-sys.el that
103;; contains functions of the form `vc-sys-...' (note that SYS is in lower
104;; case for the function and library names). VC will use that library if
105;; you put the symbol SYS somewhere into the list of
106;; `vc-handled-backends'. Then, for example, if `vc-sys-registered'
107;; returns non-nil for a file, all SYS-specific versions of VC commands
108;; will be available for that file.
109;;
110;; VC keeps some per-file information in the form of properties (see
111;; vc-file-set/getprop in vc-hooks.el). The backend-specific functions
112;; do not generally need to be aware of these properties. For example,
ac3f4c6f 113;; `vc-sys-working-revision' should compute the working revision and
fcb500ea
AS
114;; return it; it should not look it up in the property, and it needn't
115;; store it there either. However, if a backend-specific function does
116;; store a value in a property, that value takes precedence over any
99cb8c8b 117;; value that the generic code might want to set (check for uses of
fcb500ea
AS
118;; the macro `with-vc-properties' in vc.el).
119;;
120;; In the list of functions below, each identifier needs to be prepended
121;; with `vc-sys-'. Some of the functions are mandatory (marked with a
122;; `*'), others are optional (`-').
123;;
8cdd17b4
ER
124;; BACKEND PROPERTIES
125;;
126;; * revision-granularity
127;;
61de26cb
ER
128;; Takes no arguments. Returns either 'file or 'repository. Backends
129;; that return 'file have per-file revision numbering; backends
130;; that return 'repository have per-repository revision numbering,
131;; so a revision level implicitly identifies a changeset
a7192ddb 132;;
fcb500ea
AS
133;; STATE-QUERYING FUNCTIONS
134;;
0e362f54 135;; * registered (file)
fcb500ea 136;;
37a5e97a 137;; Return non-nil if FILE is registered in this backend. Both this
73770b03
DN
138;; function as well as `state' should be careful to fail gracefully
139;; in the event that the backend executable is absent. It is
140;; preferable that this function's body is autoloaded, that way only
141;; calling vc-registered does not cause the backend to be loaded
142;; (all the vc-FOO-registered functions are called to try to find
143;; the controlling backend for FILE.
fcb500ea 144;;
99cb8c8b 145;; * state (file)
fcb500ea
AS
146;;
147;; Return the current version control state of FILE. For a list of
148;; possible values, see `vc-state'. This function should do a full and
149;; reliable state computation; it is usually called immediately after
150;; C-x v v. If you want to use a faster heuristic when visiting a
151;; file, put that into `state-heuristic' below.
152;;
0e362f54 153;; - state-heuristic (file)
fcb500ea
AS
154;;
155;; If provided, this function is used to estimate the version control
156;; state of FILE at visiting time. It should be considerably faster
157;; than the implementation of `state'. For a list of possible values,
158;; see the doc string of `vc-state'.
159;;
0e362f54 160;; - dir-state (dir)
fcb500ea 161;;
484c1b1f 162;; If provided, this function is used to find the version control
df49d02e 163;; state of as many files as possible in DIR, and all subdirectories
484c1b1f
ER
164;; of DIR, in a fast way; it is used to avoid expensive indivitual
165;; vc-state calls. The function should not return anything, but
55adbcc2
DN
166;; rather store the files' states into the corresponding properties.
167;; Two properties are required: `vc-backend' and `vc-state'. (Note:
168;; in older versions this method was not required to recurse into
169;; subdirectories.)
fcb500ea 170;;
c1b51374 171;; - dir-status (dir update-function)
00ca5ce2 172;;
1b3f2d4e
DN
173;; Produce RESULT: a list of lists of the form (FILE VC-STATE EXTRA)
174;; for the files in DIR.
175;; EXTRA can be used for backend specific information about FILE.
176;; If a command needs to be run to compute this list, it should be
177;; run asynchronously using (current-buffer) as the buffer for the
178;; command. When RESULT is computed, it should be passed back by
c1b51374 179;; doing: (funcall UPDATE-FUNCTION RESULT nil).
5a84a937
DN
180;; If the backend uses a process filter, hence it produces partial results,
181;; they can be passed back by doing:
c1b51374
SM
182;; (funcall UPDATE-FUNCTION RESULT t)
183;; and then do a (funcall UPDATE-FUNCTION RESULT nil)
5a84a937
DN
184;; when all the results have been computed.
185;; To provide more backend specific functionality for `vc-status'
186;; the following functions might be needed: `status-extra-headers',
fb0ac090 187;; `status-printer', `extra-status-menu' and `dir-status-files'.
5a84a937
DN
188;; This function is used by `vc-status', a replacement for
189;; `vc-dired'. vc-status is still under development, and is NOT
190;; feature complete. As such, the requirements for this function
191;; might change. This is a replacement for `dir-state'.
00ca5ce2 192;;
fb0ac090
AJ
193;; - dir-status-files (dir files default-state update-function)
194;;
195;; This function is identical to dir-status except that it should
196;; only report status for the specified FILES. Also it needs to
197;; report on all requested files, including up-to-date or ignored
198;; files. If not provided, the default is to consider that the files
199;; are in DEFAULT-STATE.
200;;
15c5c970 201;; - status-extra-headers (dir)
115c0061 202;;
15c5c970
DN
203;; Return a string that will be added to the *vc-status* buffer header.
204;;
58f10bff
DN
205;; - status-printer (fileinfo)
206;;
207;; Pretty print the `vc-status-fileinfo' FILEINFO.
208;; If a backend needs to show more information than the default FILE
209;; and STATE in the vc-status listing, it can store that extra
210;; information in `vc-status-fileinfo->extra'. This function can be
7fbb4797 211;; used to display that extra information in the *vc-status* buffer.
58f10bff 212;;
5a84a937
DN
213;; - status-fileinfo-extra (file)
214;;
215;; Compute `vc-status-fileinfo->extra' for FILE.
216;;
ac3f4c6f 217;; * working-revision (file)
fcb500ea 218;;
ac3f4c6f 219;; Return the working revision of FILE. This is the revision fetched
61de26cb 220;; by the last checkout or upate, not necessarily the same thing as the
a7192ddb 221;; head or tip revision. Should return "0" for a file added but not yet
61de26cb 222;; committed.
fcb500ea
AS
223;;
224;; - latest-on-branch-p (file)
225;;
ac3f4c6f
ER
226;; Return non-nil if the working revision of FILE is the latest revision
227;; on its branch (many VCSes call this the 'tip' or 'head' revision).
0d0e9356 228;; The default implementation always returns t, which means that
ac3f4c6f 229;; working with non-current revisions is not supported by default.
fcb500ea 230;;
0e362f54 231;; * checkout-model (file)
fcb500ea
AS
232;;
233;; Indicate whether FILE needs to be "checked out" before it can be
234;; edited. See `vc-checkout-model' for a list of possible values.
235;;
aae91380 236;; - workfile-unchanged-p (file)
fcb500ea 237;;
ac3f4c6f
ER
238;; Return non-nil if FILE is unchanged from the working revision.
239;; This function should do a brief comparison of FILE's contents
240;; with those of the repository master of the working revision. If
241;; the backend does not have such a brief-comparison feature, the
242;; default implementation of this function can be used, which
243;; delegates to a full vc-BACKEND-diff. (Note that vc-BACKEND-diff
244;; must not run asynchronously in this case, see variable
0d0e9356 245;; `vc-disable-async-diff'.)
fcb500ea 246;;
0e362f54 247;; - mode-line-string (file)
fcb500ea 248;;
3a12f9f8 249;; If provided, this function should return the VC-specific mode
a7192ddb 250;; line string for FILE. The returned string should have a
3a12f9f8
DN
251;; `help-echo' property which is the text to be displayed as a
252;; tooltip when the mouse hovers over the VC entry on the mode-line.
253;; The default implementation deals well with all states that
254;; `vc-state' can return.
fcb500ea 255;;
aae91380 256;; - dired-state-info (file)
fcb500ea
AS
257;;
258;; Translate the `vc-state' property of FILE into a string that can be
259;; used in a vc-dired buffer. The default implementation deals well
260;; with all states that `vc-state' can return.
261;;
262;; STATE-CHANGING FUNCTIONS
263;;
61de26cb 264;; * create-repo (backend)
8cdd17b4 265;;
a7192ddb
SM
266;; Create an empty repository in the current directory and initialize
267;; it so VC mode can add files to it. For file-oriented systems, this
8cdd17b4
ER
268;; need do no more than create a subdirectory with the right name.
269;;
270;; * register (files &optional rev comment)
fcb500ea 271;;
8cdd17b4
ER
272;; Register FILES in this backend. Optionally, an initial revision REV
273;; and an initial description of the file, COMMENT, may be specified,
274;; but it is not guaranteed that the backend will do anything with this.
ecd50f65 275;; The implementation should pass the value of vc-register-switches
a7192ddb 276;; to the backend command. (Note: in older versions of VC, this
8cdd17b4 277;; command took a single file argument and not a list.)
fcb500ea 278;;
ac3f4c6f 279;; - init-revision (file)
b470cb65 280;;
ac3f4c6f 281;; The initial revision to use when registering FILE if one is not
b470cb65 282;; specified by the user. If not provided, the variable
ac3f4c6f 283;; vc-default-init-revision is used instead.
b470cb65 284;;
099bd78a 285;; - responsible-p (file)
fcb500ea
AS
286;;
287;; Return non-nil if this backend considers itself "responsible" for
288;; FILE, which can also be a directory. This function is used to find
289;; out what backend to use for registration of new files and for things
290;; like change log generation. The default implementation always
291;; returns nil.
292;;
0e362f54 293;; - could-register (file)
fcb500ea
AS
294;;
295;; Return non-nil if FILE could be registered under this backend. The
296;; default implementation always returns t.
297;;
aae91380 298;; - receive-file (file rev)
fcb500ea
AS
299;;
300;; Let this backend "receive" a file that is already registered under
301;; another backend. The default implementation simply calls `register'
302;; for FILE, but it can be overridden to do something more specific,
303;; e.g. keep revision numbers consistent or choose editing modes for
304;; FILE that resemble those of the other backend.
305;;
306;; - unregister (file)
307;;
308;; Unregister FILE from this backend. This is only needed if this
309;; backend may be used as a "more local" backend for temporary editing.
310;;
8cdd17b4 311;; * checkin (files rev comment)
fcb500ea 312;;
8cdd17b4
ER
313;; Commit changes in FILES to this backend. If REV is non-nil, that
314;; should become the new revision number (not all backends do
315;; anything with it). COMMENT is used as a check-in comment. The
316;; implementation should pass the value of vc-checkin-switches to
a7192ddb 317;; the backend command. (Note: in older versions of VC, this
8cdd17b4 318;; command took a single file argument and not a list.)
fcb500ea 319;;
ac3f4c6f 320;; * find-revision (file rev buffer)
fd8160f7
SM
321;;
322;; Fetch revision REV of file FILE and put it into BUFFER.
323;; If REV is the empty string, fetch the head of the trunk.
324;; The implementation should pass the value of vc-checkout-switches
325;; to the backend command.
326;;
9e6da495 327;; * checkout (file &optional editable rev)
fcb500ea
AS
328;;
329;; Check out revision REV of FILE into the working area. If EDITABLE
330;; is non-nil, FILE should be writable by the user and if locking is
331;; used for FILE, a lock should also be set. If REV is non-nil, that
ac3f4c6f 332;; is the revision to check out (default is the working revision).
4279775b
AS
333;; If REV is t, that means to check out the head of the current branch;
334;; if it is the empty string, check out the head of the trunk.
335;; The implementation should pass the value of vc-checkout-switches
fd8160f7 336;; to the backend command.
fcb500ea 337;;
bbfc07d3 338;; * revert (file &optional contents-done)
fcb500ea 339;;
ac3f4c6f 340;; Revert FILE back to the working revision. If optional
bbfc07d3
AS
341;; arg CONTENTS-DONE is non-nil, then the contents of FILE have
342;; already been reverted from a version backup, and this function
343;; only needs to update the status of FILE within the backend.
fcb500ea 344;;
8cdd17b4 345;; - rollback (files)
fcb500ea 346;;
ac3f4c6f
ER
347;; Remove the tip revision of each of FILES from the repository. If
348;; this function is not provided, trying to cancel a revision is
8cdd17b4
ER
349;; caught as an error. (Most backends don't provide it.) (Also
350;; note that older versions of this backend command were called
351;; 'cancel-version' and took a single file arg, not a list of
352;; files.)
fcb500ea 353;;
aae91380 354;; - merge (file rev1 rev2)
fcb500ea
AS
355;;
356;; Merge the changes between REV1 and REV2 into the current working file.
357;;
aae91380 358;; - merge-news (file)
fcb500ea
AS
359;;
360;; Merge recent changes from the current branch into FILE.
361;;
ac3f4c6f 362;; - steal-lock (file &optional revision)
fcb500ea 363;;
ac3f4c6f 364;; Steal any lock on the working revision of FILE, or on REVISION if
0d0e9356
ER
365;; that is provided. This function is only needed if locking is
366;; used for files under this backend, and if files can indeed be
367;; locked by other users.
fcb500ea 368;;
9b64a7f0
ER
369;; - modify-change-comment (files rev comment)
370;;
df49d02e 371;; Modify the change comments associated with the files at the
9b64a7f0
ER
372;; given revision. This is optional, many backends do not support it.
373;;
7fbb4797
DN
374;; - mark-resolved (files)
375;;
376;; Mark conflicts as resolved. Some VC systems need to run a
377;; command to mark conflicts as resolved.
378;;
fcb500ea
AS
379;; HISTORY FUNCTIONS
380;;
8cdd17b4 381;; * print-log (files &optional buffer)
fcb500ea 382;;
8cdd17b4
ER
383;; Insert the revision log for FILES into BUFFER, or the *vc* buffer
384;; if BUFFER is nil. (Note: older versions of this function expected
385;; only a single file argument.)
fcb500ea 386;;
37a5e97a
SM
387;; - log-view-mode ()
388;;
389;; Mode to use for the output of print-log. This defaults to
390;; `log-view-mode' and is expected to be changed (if at all) to a derived
391;; mode of `log-view-mode'.
392;;
ac3f4c6f 393;; - show-log-entry (revision)
fcb500ea 394;;
ac3f4c6f 395;; If provided, search the log entry for REVISION in the current buffer,
fcb500ea
AS
396;; and make sure it is displayed in the buffer's window. The default
397;; implementation of this function works for RCS-style logs.
398;;
aae91380 399;; - wash-log (file)
fcb500ea 400;;
61de26cb 401;; Remove all non-comment information from the output of print-log.
fcb500ea 402;;
0e362f54 403;; - logentry-check ()
fcb500ea
AS
404;;
405;; If defined, this function is run to find out whether the user
406;; entered a valid log entry for check-in. The log entry is in the
407;; current buffer, and if it is not a valid one, the function should
408;; throw an error.
409;;
aae91380 410;; - comment-history (file)
fcb500ea 411;;
d6ba9c39 412;; Return a string containing all log entries that were made for FILE.
fcb500ea
AS
413;; This is used for transferring a file from one backend to another,
414;; retaining comment information. The default implementation of this
415;; function does this by calling print-log and then wash-log, and
416;; returning the resulting buffer contents as a string.
417;;
aae91380 418;; - update-changelog (files)
fcb500ea
AS
419;;
420;; Using recent log entries, create ChangeLog entries for FILES, or for
421;; all files at or below the default-directory if FILES is nil. The
422;; default implementation runs rcs2log, which handles RCS- and
423;; CVS-style logs.
424;;
d7b60083 425;; * diff (files &optional rev1 rev2 buffer)
fcb500ea 426;;
ac9ff209
AS
427;; Insert the diff for FILE into BUFFER, or the *vc-diff* buffer if
428;; BUFFER is nil. If REV1 and REV2 are non-nil, report differences
ac3f4c6f
ER
429;; from REV1 to REV2. If REV1 is nil, use the working revision (as
430;; found in the repository) as the older revision; if REV2 is nil,
431;; use the current working-copy contents as the newer revision. This
432;; function should pass the value of (vc-switches BACKEND 'diff) to
433;; the backend command. It should return a status of either 0 (no
434;; differences found), or 1 (either non-empty diff or the diff is
435;; run asynchronously).
fcb500ea 436;;
a7192ddb 437;; - revision-completion-table (files)
4d83a657 438;;
a7192ddb 439;; Return a completion table for existing revisions of FILES.
4d83a657
SM
440;; The default is to not use any completion table.
441;;
3c42cc64 442;; - annotate-command (file buf &optional rev)
fcb500ea 443;;
3c42cc64 444;; If this function is provided, it should produce an annotated display
ac3f4c6f 445;; of FILE in BUF, relative to revision REV. Annotation means each line
3c42cc64
TTN
446;; of FILE displayed is prefixed with version information associated with
447;; its addition (deleted lines leave no history) and that the text of the
448;; file is fontified according to age.
fcb500ea 449;;
75665141 450;; - annotate-time ()
fcb500ea
AS
451;;
452;; Only required if `annotate-command' is defined for the backend.
75665141
AS
453;; Return the time of the next line of annotation at or after point,
454;; as a floating point fractional number of days. The helper
455;; function `vc-annotate-convert-time' may be useful for converting
456;; multi-part times as returned by `current-time' and `encode-time'
0ff9b955 457;; to this format. Return nil if no more lines of annotation appear
75665141
AS
458;; in the buffer. You can safely assume that point is placed at the
459;; beginning of each line, starting at `point-min'. The buffer that
460;; point is placed in is the Annotate output, as defined by the
946b248f
TTN
461;; relevant backend. This function also affects how much of the line
462;; is fontified; where it leaves point is where fontification begins.
75665141
AS
463;;
464;; - annotate-current-time ()
465;;
466;; Only required if `annotate-command' is defined for the backend,
467;; AND you'd like the current time considered to be anything besides
cb223bba 468;; (vc-annotate-convert-time (current-time)) -- i.e. the current
75665141
AS
469;; time with hours, minutes, and seconds included. Probably safe to
470;; ignore. Return the current-time, in units of fractional days.
fcb500ea 471;;
1b5a7343
AS
472;; - annotate-extract-revision-at-line ()
473;;
474;; Only required if `annotate-command' is defined for the backend.
475;; Invoked from a buffer in vc-annotate-mode, return the revision
476;; corresponding to the current line, or nil if there is no revision
477;; corresponding to the current line.
478;;
fcb500ea
AS
479;; SNAPSHOT SYSTEM
480;;
0e362f54 481;; - create-snapshot (dir name branchp)
fcb500ea
AS
482;;
483;; Take a snapshot of the current state of files under DIR and name it
484;; NAME. This should make sure that files are up-to-date before
485;; proceeding with the action. DIR can also be a file and if BRANCHP
486;; is specified, NAME should be created as a branch and DIR should be
487;; checked out under this new branch. The default implementation does
488;; not support branches but does a sanity check, a tree traversal and
489;; for each file calls `assign-name'.
490;;
491;; - assign-name (file name)
492;;
ac3f4c6f 493;; Give name NAME to the working revision of FILE, assuming it is
fcb500ea
AS
494;; up-to-date. Only used by the default version of `create-snapshot'.
495;;
0e362f54 496;; - retrieve-snapshot (dir name update)
fcb500ea
AS
497;;
498;; Retrieve a named snapshot of all registered files at or below DIR.
499;; If UPDATE is non-nil, then update buffers of any files in the
500;; snapshot that are currently visited. The default implementation
501;; does a sanity check whether there aren't any uncommitted changes at
502;; or below DIR, and then performs a tree walk, using the `checkout'
ac3f4c6f 503;; function to retrieve the corresponding revisions.
fcb500ea
AS
504;;
505;; MISCELLANEOUS
506;;
f4263e47
TTN
507;; - root (dir)
508;;
509;; Return DIR's "root" directory, that is, a parent directory of
510;; DIR for which the same backend as used for DIR applies. If no
511;; such parent exists, this function should return DIR.
512;;
aae91380 513;; - make-version-backups-p (file)
fcb500ea 514;;
ac3f4c6f 515;; Return non-nil if unmodified repository revisions of FILE should be
fcb500ea
AS
516;; backed up locally. If this is done, VC can perform `diff' and
517;; `revert' operations itself, without calling the backend system. The
518;; default implementation always returns nil.
519;;
a36319a4
SM
520;; - repository-hostname (dirname)
521;;
522;; Return the hostname that the backend will have to contact
523;; in order to operate on a file in DIRNAME. If the return value
0452b6e7 524;; is nil, it means that the repository is local.
a36319a4
SM
525;; This function is used in `vc-stay-local-p' which backends can use
526;; for their convenience.
527;;
ac3f4c6f 528;; - previous-revision (file rev)
869131a5 529;;
ac3f4c6f
ER
530;; Return the revision number that precedes REV for FILE, or nil if no such
531;; revision exists.
1b5a7343 532;;
ac3f4c6f 533;; - next-revision (file rev)
1b5a7343 534;;
ac3f4c6f
ER
535;; Return the revision number that follows REV for FILE, or nil if no such
536;; revision exists.
869131a5 537;;
aae91380 538;; - check-headers ()
fcb500ea
AS
539;;
540;; Return non-nil if the current buffer contains any version headers.
541;;
aae91380 542;; - clear-headers ()
fcb500ea
AS
543;;
544;; In the current buffer, reset all version headers to their unexpanded
545;; form. This function should be provided if the state-querying code
546;; for this backend uses the version headers to determine the state of
547;; a file. This function will then be called whenever VC changes the
548;; version control state in such a way that the headers would give
549;; wrong information.
550;;
a36319a4
SM
551;; - delete-file (file)
552;;
553;; Delete FILE and mark it as deleted in the repository. If this
554;; function is not provided, the command `vc-delete-file' will
555;; signal an error.
556;;
099bd78a 557;; - rename-file (old new)
fcb500ea
AS
558;;
559;; Rename file OLD to NEW, both in the working area and in the
a36319a4
SM
560;; repository. If this function is not provided, the renaming
561;; will be done by (vc-delete-file old) and (vc-register new).
86a65190 562;;
6e54fa53
SM
563;; - find-file-hook ()
564;;
81c63b50 565;; Operation called in current buffer when opening a file. This can
6e54fa53 566;; be used by the backend to setup some local variables it might need.
cb223bba 567;;
81c63b50
SM
568;; - find-file-not-found-hook ()
569;;
570;; Operation called in current buffer when opening a non-existing file.
571;; By default, this asks the user if she wants to check out the file.
cb223bba
DN
572;;
573;; - extra-menu ()
574;;
575;; Return a menu keymap, the items in the keymap will appear at the
576;; end of the Version Control menu. The goal is to allow backends
577;; to specify extra menu items that appear in the VC menu. This way
578;; you can provide menu entries for functionality that is specific
579;; to your backend and which does not map to any of the VC generic
580;; concepts.
6656ecaa
DN
581;;
582;; - extra-status-menu ()
583;;
25a4ea6d
DN
584;; Return a menu keymap, the items in the keymap will appear at the
585;; end of the VC Status menu. The goal is to allow backends to
586;; specify extra menu items that appear in the VC Status menu. This
587;; makes it possible to provide menu entries for functionality that
588;; is specific to a backend and which does not map to any of the VC
589;; generic concepts.
aae91380 590
ba463d9e
DN
591;;; Todo:
592
c1b51374
SM
593;; - vc-status-kill-dir-status-process should not be specific to dir-status,
594;; it should work for other async commands as well (pull/push/...).
595;;
ba463d9e
DN
596;; - vc-update/vc-merge should deal with VC systems that don't
597;; update/merge on a file basis, but on a whole repository basis.
598;;
fc30d544
DN
599;; - deal with push/pull operations.
600;;
601;; - "snapshots" should be renamed to "branches", and thoroughly reworked.
602;;
7fbb4797
DN
603;; - when a file is in `conflict' state, turn on smerge-mode.
604;;
605;; - figure out what to do with conflicts that are not caused by the
606;; file contents, but by metadata or other causes.
ba463d9e 607;;
fc30d544
DN
608;; - add a generic mechanism for remembering the current branch names,
609;; display the branch name in the mode-line. Replace
610;; vc-cvs-sticky-tag with that.
611;;
5a84a937 612;; - vc-diff should be able to show the diff for all files in a
7fbb4797
DN
613;; changeset, especially for VC systems that have per repository
614;; version numbers. log-view should take advantage of this.
5a84a937 615;;
7fbb4797
DN
616;; - a way to do repository wide log (instead of just per
617;; file/fileset) is needed.
5a84a937 618;;
ba463d9e
DN
619;; - the *VC-log* buffer needs font-locking.
620;;
fc30d544
DN
621;; - make it easier to write logs. Maybe C-x 4 a should add to the log
622;; buffer, if one is present, instead of adding to the ChangeLog.
ba463d9e 623;;
e166638d
DN
624;; - make vc-state for all backends return 'unregistered instead of
625;; nil for unregistered files, then update vc-next-action.
626;;
3b3cb336 627;; - vc-register should register a fileset at a time. The backends
9eef6650 628;; already support this, only the front-end needs to be changed to
3b3cb336
DN
629;; handle multiple files at a time.
630;;
d05665bc 631;; - add a mechanism for ignoring files.
3b3cb336 632;;
d05665bc
DN
633;; - vc-next-action should do something about 'missing files. Maybe
634;; just warn, or offer to checkout.
3b3cb336 635;;
7fbb4797
DN
636;; - display the directory names in vc-status, similar to what PCL-CVS
637;; does.
638;;
639;; - most vc-status backends need more work. They might need to
640;; provide custom headers, use the `extra' field and deal with all
641;; possible VC states.
642;;
643;; - add function that calls vc-status to `find-directory-functions'.
d6f47dff 644;;
d05665bc 645;; - vc-status needs mouse bindings.
4ac7bfcf 646;;
0cc8ac2b
DN
647;; - vc-status needs more key bindings for VC actions.
648;;
d6f47dff 649;; - vc-status toolbar needs more icons.
25a4ea6d 650;;
d3201e0b
DN
651;; - vc-diff, vc-annotate, etc. need to deal better with unregistered
652;; files. Now that unregistered and ignored files are shown in
653;; vc-dired/vc-status, it is possible that these commands are called
654;; for unregistered/ignored files.
655;;
3f08440f
DN
656;; - do not default to RCS anymore when the current directory is not
657;; controlled by any VCS and the user does C-x v v
658;;
ba463d9e 659
fcb500ea 660;;; Code:
0e362f54 661
594722a8 662(require 'vc-hooks)
64db3a90 663(require 'tool-bar)
7fbb4797 664(require 'ewoc)
64db3a90 665
0e362f54 666(eval-when-compile
7849e179 667 (require 'cl)
099bd78a
SM
668 (require 'dired) ; for dired-map-over-marks macro
669 (require 'dired-aux)) ; for dired-kill-{line,tree}
8c0aaf40
ER
670
671(if (not (assoc 'vc-parent-buffer minor-mode-alist))
672 (setq minor-mode-alist
673 (cons '(vc-parent-buffer vc-parent-buffer-name)
674 minor-mode-alist)))
594722a8
ER
675
676;; General customization
677
0101cc40
RS
678(defgroup vc nil
679 "Version-control system in Emacs."
680 :group 'tools)
681
682(defcustom vc-suppress-confirm nil
04864eb0 683 "If non-nil, treat user as expert; suppress yes-no prompts on some things."
0101cc40
RS
684 :type 'boolean
685 :group 'vc)
686
2c4eea90 687(defcustom vc-delete-logbuf-window t
04864eb0 688 "If non-nil, delete the *VC-log* buffer and window after each logical action.
2c4eea90
KH
689If nil, bury that buffer instead.
690This is most useful if you have multiple windows on a frame and would like to
691preserve the setting."
692 :type 'boolean
693 :group 'vc)
694
0101cc40 695(defcustom vc-initial-comment nil
04864eb0 696 "If non-nil, prompt for initial comment when a file is registered."
0101cc40
RS
697 :type 'boolean
698 :group 'vc)
699
ac3f4c6f
ER
700(defcustom vc-default-init-revision "1.1"
701 "A string used as the default revision number when a new file is registered.
b470cb65
AS
702This can be overridden by giving a prefix argument to \\[vc-register]. This
703can also be overridden by a particular VC backend."
0d53f466 704 :type 'string
cd32a7ba
DN
705 :group 'vc
706 :version "20.3")
0d53f466 707
0101cc40 708(defcustom vc-command-messages nil
04864eb0 709 "If non-nil, display run messages from back-end commands."
0101cc40
RS
710 :type 'boolean
711 :group 'vc)
712
713(defcustom vc-checkin-switches nil
04864eb0 714 "A string or list of strings specifying extra switches for checkin.
0101cc40
RS
715These are passed to the checkin program by \\[vc-checkin]."
716 :type '(choice (const :tag "None" nil)
717 (string :tag "Argument String")
718 (repeat :tag "Argument List"
719 :value ("")
720 string))
721 :group 'vc)
722
723(defcustom vc-checkout-switches nil
04864eb0 724 "A string or list of strings specifying extra switches for checkout.
0101cc40
RS
725These are passed to the checkout program by \\[vc-checkout]."
726 :type '(choice (const :tag "None" nil)
727 (string :tag "Argument String")
728 (repeat :tag "Argument List"
729 :value ("")
730 string))
731 :group 'vc)
732
733(defcustom vc-register-switches nil
04864eb0 734 "A string or list of strings; extra switches for registering a file.
0101cc40
RS
735These are passed to the checkin program by \\[vc-register]."
736 :type '(choice (const :tag "None" nil)
737 (string :tag "Argument String")
738 (repeat :tag "Argument List"
739 :value ("")
740 string))
741 :group 'vc)
742
0e362f54 743(defcustom vc-dired-listing-switches "-al"
04864eb0 744 "Switches passed to `ls' for vc-dired. MUST contain the `l' option."
0e362f54
GM
745 :type 'string
746 :group 'vc
6f41eeb5 747 :version "21.1")
0e362f54 748
3b574573 749(defcustom vc-dired-recurse t
04864eb0 750 "If non-nil, show directory trees recursively in VC Dired."
3b574573
AS
751 :type 'boolean
752 :group 'vc
753 :version "20.3")
754
755(defcustom vc-dired-terse-display t
61de26cb 756 "If non-nil, show only locked or locally modified files in VC Dired."
3b574573
AS
757 :type 'boolean
758 :group 'vc
759 :version "20.3")
760
acc5b122 761(defcustom vc-diff-switches nil
04864eb0 762 "A string or list of strings specifying switches for diff under VC.
b453817c
AS
763When running diff under a given BACKEND, VC concatenates the values of
764`diff-switches', `vc-diff-switches', and `vc-BACKEND-diff-switches' to
765get the switches for that command. Thus, `vc-diff-switches' should
766contain switches that are specific to version control, but not
767specific to any particular backend."
acc5b122
AS
768 :type '(choice (const :tag "None" nil)
769 (string :tag "Argument String")
770 (repeat :tag "Argument List"
771 :value ("")
772 string))
773 :group 'vc
774 :version "21.1")
775
48033a08
AS
776(defcustom vc-diff-knows-L nil
777 "*Indicates whether diff understands the -L option.
778The value is either `yes', `no', or nil. If it is nil, VC tries
779to use -L and sets this variable to remember whether it worked."
780 :type '(choice (const :tag "Work out" nil) (const yes) (const no))
781 :group 'vc)
782
f1d1d46a 783(defcustom vc-allow-async-revert nil
e4d26892 784 "Specifies whether the diff during \\[vc-revert] may be asynchronous.
f1d1d46a
AS
785Enabling this option means that you can confirm a revert operation even
786if the local changes in the file have not been found and displayed yet."
787 :type '(choice (const :tag "No" nil)
788 (const :tag "Yes" t))
789 :group 'vc
bf247b6e 790 :version "22.1")
f1d1d46a 791
7cad930d
AS
792;;;###autoload
793(defcustom vc-checkout-hook nil
04864eb0 794 "Normal hook (list of functions) run after checking out a file.
7cad930d
AS
795See `run-hooks'."
796 :type 'hook
797 :group 'vc
798 :version "21.1")
799
da7c8a12 800(defcustom vc-annotate-display-mode 'fullscale
6f1ecae4 801 "Which mode to color the output of \\[vc-annotate] with by default."
da7c8a12 802 :type '(choice (const :tag "By Color Map Range" nil)
75665141
AS
803 (const :tag "Scale to Oldest" scale)
804 (const :tag "Scale Oldest->Newest" fullscale)
805 (number :tag "Specify Fractional Number of Days"
806 :value "20.5"))
807 :group 'vc)
808
0e362f54
GM
809;;;###autoload
810(defcustom vc-checkin-hook nil
61de26cb 811 "Normal hook (list of functions) run after commit or file checkin.
1cca5da4 812See also `log-edit-done-hook'."
0e362f54 813 :type 'hook
1cca5da4 814 :options '(log-edit-comment-to-change-log)
0e362f54
GM
815 :group 'vc)
816
817;;;###autoload
818(defcustom vc-before-checkin-hook nil
61de26cb 819 "Normal hook (list of functions) run before a commit or a file checkin.
0e362f54
GM
820See `run-hooks'."
821 :type 'hook
822 :group 'vc)
823
824(defcustom vc-logentry-check-hook nil
04864eb0 825 "Normal hook run by `vc-backend-logentry-check'.
0e362f54
GM
826Use this to impose your own rules on the entry in addition to any the
827version control backend imposes itself."
828 :type 'hook
829 :group 'vc)
2e810285 830
0e362f54 831;; Annotate customization
7d2d9482 832(defcustom vc-annotate-color-map
da7c8a12
S
833 (if (and (tty-display-color-p) (<= (display-color-cells) 8))
834 ;; A custom sorted TTY colormap
835 (let* ((colors
836 (sort
837 (delq nil
838 (mapcar (lambda (x)
839 (if (not (or
840 (string-equal (car x) "white")
841 (string-equal (car x) "black") ))
842 (car x)))
843 (tty-color-alist)))
844 (lambda (a b)
845 (cond
846 ((or (string-equal a "red") (string-equal b "blue")) t)
847 ((or (string-equal b "red") (string-equal a "blue")) nil)
848 ((string-equal a "yellow") t)
849 ((string-equal b "yellow") nil)
850 ((string-equal a "cyan") t)
851 ((string-equal b "cyan") nil)
852 ((string-equal a "green") t)
853 ((string-equal b "green") nil)
854 ((string-equal a "magenta") t)
855 ((string-equal b "magenta") nil)
856 (t (string< a b))))))
857 (date 20.)
858 (delta (/ (- 360. date) (1- (length colors)))))
859 (mapcar (lambda (x)
860 (prog1
861 (cons date x)
862 (setq date (+ date delta)))) colors))
863 ;; Normal colormap: hue stepped from 0-240deg, value=1., saturation=0.75
864 '(( 20. . "#FF3F3F")
865 ( 40. . "#FF6C3F")
866 ( 60. . "#FF993F")
867 ( 80. . "#FFC63F")
868 (100. . "#FFF33F")
869 (120. . "#DDFF3F")
870 (140. . "#B0FF3F")
871 (160. . "#83FF3F")
872 (180. . "#56FF3F")
873 (200. . "#3FFF56")
874 (220. . "#3FFF83")
875 (240. . "#3FFFB0")
876 (260. . "#3FFFDD")
877 (280. . "#3FF3FF")
878 (300. . "#3FC6FF")
879 (320. . "#3F99FF")
880 (340. . "#3F6CFF")
881 (360. . "#3F3FFF")))
04864eb0 882 "Association list of age versus color, for \\[vc-annotate].
da7c8a12
S
883Ages are given in units of fractional days. Default is eighteen
884steps using a twenty day increment, from red to blue. For TTY
885displays with 8 or fewer colors, the default is red to blue with
886all other colors between (excluding black and white)."
0e362f54 887 :type 'alist
7d2d9482
RS
888 :group 'vc)
889
da7c8a12 890(defcustom vc-annotate-very-old-color "#3F3FFF"
04864eb0 891 "Color for lines older than the current color range in \\[vc-annotate]]."
7d2d9482
RS
892 :type 'string
893 :group 'vc)
894
895(defcustom vc-annotate-background "black"
04864eb0 896 "Background color for \\[vc-annotate].
7d2d9482 897Default color is used if nil."
14b7a0b5 898 :type '(choice (const :tag "Default background" nil) (color))
7d2d9482
RS
899 :group 'vc)
900
901(defcustom vc-annotate-menu-elements '(2 0.5 0.1 0.01)
04864eb0 902 "Menu elements for the mode-specific menu of VC-Annotate mode.
7d2d9482 903List of factors, used to expand/compress the time scale. See `vc-annotate'."
0e362f54 904 :type '(repeat number)
7d2d9482
RS
905 :group 'vc)
906
0e362f54
GM
907(defvar vc-annotate-mode-map
908 (let ((m (make-sparse-keymap)))
04864eb0
SM
909 (define-key m "A" 'vc-annotate-revision-previous-to-line)
910 (define-key m "D" 'vc-annotate-show-diff-revision-at-line)
f3ff0fe9 911 (define-key m "f" 'vc-annotate-find-revision-at-line)
04864eb0
SM
912 (define-key m "J" 'vc-annotate-revision-at-line)
913 (define-key m "L" 'vc-annotate-show-log-revision-at-line)
ac3f4c6f
ER
914 (define-key m "N" 'vc-annotate-next-revision)
915 (define-key m "P" 'vc-annotate-prev-revision)
916 (define-key m "W" 'vc-annotate-working-revision)
5731a8e0 917 (define-key m "V" 'vc-annotate-toggle-annotation-visibility)
0e362f54
GM
918 m)
919 "Local keymap used for VC-Annotate mode.")
67242a23 920
594722a8
ER
921;; Header-insertion hair
922
0101cc40 923(defcustom vc-static-header-alist
04864eb0 924 '(("\\.c\\'" .
594722a8 925 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
0e362f54
GM
926 "*Associate static header string templates with file types.
927A \%s in the template is replaced with the first string associated with
099bd78a 928the file's version control type in `vc-header-alist'."
0101cc40
RS
929 :type '(repeat (cons :format "%v"
930 (regexp :tag "File Type")
931 (string :tag "Header String")))
932 :group 'vc)
7b4f934d 933
0101cc40 934(defcustom vc-comment-alist
594722a8 935 '((nroff-mode ".\\\"" ""))
6f1ecae4 936 "*Special comment delimiters for generating VC headers.
099bd78a
SM
937Add an entry in this list if you need to override the normal `comment-start'
938and `comment-end' variables. This will only be necessary if the mode language
0101cc40
RS
939is sensitive to blank lines."
940 :type '(repeat (list :format "%v"
941 (symbol :tag "Mode")
942 (string :tag "Comment Start")
943 (string :tag "Comment End")))
944 :group 'vc)
594722a8 945
0101cc40 946(defcustom vc-checkout-carefully (= (user-uid) 0)
bf142f28 947 "*Non-nil means be extra-careful in checkout.
bbf97570 948Verify that the file really is not locked
0101cc40
RS
949and that its contents match what the master file says."
950 :type 'boolean
951 :group 'vc)
bf142f28
JB
952(make-obsolete-variable 'vc-checkout-carefully
953 "the corresponding checks are always done now."
954 "21.1")
bbf97570 955
0e362f54 956\f
594722a8 957;; Variables the user doesn't need to know about.
594722a8 958(defvar vc-log-operation nil)
67242a23 959(defvar vc-log-after-operation-hook nil)
04864eb0 960
dbf87856
RS
961;; In a log entry buffer, this is a local variable
962;; that points to the buffer for which it was made
963;; (either a file, or a VC dired buffer).
1a2f456b 964(defvar vc-parent-buffer nil)
0e362f54 965(put 'vc-parent-buffer 'permanent-local t)
8c0aaf40 966(defvar vc-parent-buffer-name nil)
0e362f54 967(put 'vc-parent-buffer-name 'permanent-local t)
594722a8 968
f1d1d46a
AS
969(defvar vc-disable-async-diff nil
970 "VC sets this to t locally to disable some async diff operations.
971Backends that offer asynchronous diffs should respect this variable
972in their implementation of vc-BACKEND-diff.")
973
d7b60083 974(defvar vc-log-fileset)
ac3f4c6f 975(defvar vc-log-revision)
db59472c 976
8c0aaf40 977(defvar vc-dired-mode nil)
e1f297e6
ER
978(make-variable-buffer-local 'vc-dired-mode)
979
594722a8
ER
980;; File property caching
981
8c0aaf40 982(defun vc-clear-context ()
11cdd167 983 "Clear all cached file properties."
8c0aaf40 984 (interactive)
11cdd167 985 (fillarray vc-file-prop-obarray 0))
8c0aaf40 986
d7b60083
ER
987(defmacro with-vc-properties (files form settings)
988 "Execute FORM, then maybe set per-file properties for FILES.
6f1ecae4
AS
989SETTINGS is an association list of property/value pairs. After
990executing FORM, set those properties from SETTINGS that have not yet
991been updated to their corresponding values."
b4e4e3a8 992 (declare (debug t))
169f0cae 993 `(let ((vc-touched-properties (list t)))
099bd78a 994 ,form
d7b60083 995 (dolist (file ,files)
a7192ddb
SM
996 (dolist (setting ,settings)
997 (let ((property (car setting)))
998 (unless (memq property vc-touched-properties)
999 (put (intern file vc-file-prop-obarray)
1000 property (cdr setting))))))))
099bd78a 1001
ec402ad4 1002;; Two macros for elisp programming
61de26cb 1003
709822e8
AS
1004;;;###autoload
1005(defmacro with-vc-file (file comment &rest body)
6f1ecae4 1006 "Check out a writable copy of FILE if necessary, then execute BODY.
0e362f54
GM
1007Check in FILE with COMMENT (a string) after BODY has been executed.
1008FILE is passed through `expand-file-name'; BODY executed within
61de26cb 1009`save-excursion'. If FILE is not under version control, or you are
a7192ddb 1010using a locking version-control system and the file is locked by
709822e8 1011somebody else, signal error."
b4e4e3a8 1012 (declare (debug t) (indent 2))
169f0cae
AS
1013 (let ((filevar (make-symbol "file")))
1014 `(let ((,filevar (expand-file-name ,file)))
1015 (or (vc-backend ,filevar)
2df5044f 1016 (error "File not under version control: `%s'" file))
169f0cae
AS
1017 (unless (vc-editable-p ,filevar)
1018 (let ((state (vc-state ,filevar)))
f1180544 1019 (if (stringp state)
2df5044f 1020 (error "`%s' is locking `%s'" state ,filevar)
169f0cae
AS
1021 (vc-checkout ,filevar t))))
1022 (save-excursion
1023 ,@body)
d7b60083 1024 (vc-checkin (list ,filevar) nil ,comment))))
169f0cae 1025
709822e8
AS
1026;;;###autoload
1027(defmacro edit-vc-file (file comment &rest body)
0e362f54
GM
1028 "Edit FILE under version control, executing body.
1029Checkin with COMMENT after executing BODY.
709822e8
AS
1030This macro uses `with-vc-file', passing args to it.
1031However, before executing BODY, find FILE, and after BODY, save buffer."
b4e4e3a8 1032 (declare (debug t) (indent 2))
169f0cae
AS
1033 (let ((filevar (make-symbol "file")))
1034 `(let ((,filevar (expand-file-name ,file)))
1035 (with-vc-file
1036 ,filevar ,comment
1037 (set-buffer (find-file-noselect ,filevar))
1038 ,@body
1039 (save-buffer)))))
1040
61de26cb
ER
1041;; Common command execution logic to be used by backends
1042
0e362f54 1043(defun vc-process-filter (p s)
099bd78a 1044 "An alternative output filter for async process P.
58ce5535
TTN
1045One difference with the default filter is that this inserts S after markers.
1046Another is that undo information is not kept."
fddde1f0
TTN
1047 (let ((buffer (process-buffer p)))
1048 (when (buffer-live-p buffer)
1049 (with-current-buffer buffer
1050 (save-excursion
1051 (let ((buffer-undo-list t)
1052 (inhibit-read-only t))
1053 (goto-char (process-mark p))
1054 (insert s)
1055 (set-marker (process-mark p) (point))))))))
0e362f54
GM
1056
1057(defun vc-setup-buffer (&optional buf)
6f1ecae4 1058 "Prepare BUF for executing a VC command and make it current.
0e362f54
GM
1059BUF defaults to \"*vc*\", can be a string and will be created if necessary."
1060 (unless buf (setq buf "*vc*"))
1061 (let ((camefrom (current-buffer))
1062 (olddir default-directory))
1063 (set-buffer (get-buffer-create buf))
1064 (kill-all-local-variables)
1065 (set (make-local-variable 'vc-parent-buffer) camefrom)
1066 (set (make-local-variable 'vc-parent-buffer-name)
1067 (concat " from " (buffer-name camefrom)))
1068 (setq default-directory olddir)
58ce5535
TTN
1069 (let ((buffer-undo-list t)
1070 (inhibit-read-only t))
0e362f54
GM
1071 (erase-buffer))))
1072
86e80023
SM
1073(defvar vc-sentinel-movepoint) ;Dynamically scoped.
1074
1075(defun vc-process-sentinel (p s)
b49fd377
TTN
1076 (let ((previous (process-get p 'vc-previous-sentinel))
1077 (buf (process-buffer p)))
b49fd377
TTN
1078 ;; Impatient users sometime kill "slow" buffers; check liveness
1079 ;; to avoid "error in process sentinel: Selecting deleted buffer".
1080 (when (buffer-live-p buf)
fddde1f0 1081 (if previous (funcall previous p s))
b49fd377
TTN
1082 (with-current-buffer buf
1083 (setq mode-line-process
1084 (let ((status (process-status p)))
1085 ;; Leave mode-line uncluttered, normally.
b49fd377
TTN
1086 (unless (eq 'exit status)
1087 (format " (%s)" status))))
1088 (let (vc-sentinel-movepoint)
1089 ;; Normally, we want async code such as sentinels to not move point.
1090 (save-excursion
1091 (goto-char (process-mark p))
1092 (let ((cmds (process-get p 'vc-sentinel-commands)))
1093 (process-put p 'vc-sentinel-commands nil)
1094 (dolist (cmd cmds)
1095 ;; Each sentinel may move point and the next one should be run
1096 ;; at that new point. We could get the same result by having
1097 ;; each sentinel read&set process-mark, but since `cmd' needs
1098 ;; to work both for async and sync processes, this would be
1099 ;; difficult to achieve.
1100 (vc-exec-after cmd))))
1101 ;; But sometimes the sentinels really want to move point.
1102 (if vc-sentinel-movepoint
1103 (let ((win (get-buffer-window (current-buffer) 0)))
1104 (if (not win)
1105 (goto-char vc-sentinel-movepoint)
1106 (with-selected-window win
1107 (goto-char vc-sentinel-movepoint))))))))))
86e80023 1108
d3201e0b
DN
1109(defun vc-set-mode-line-busy-indicator ()
1110 (setq mode-line-process
c2062c3b
GM
1111 (concat " " (propertize "[waiting...]"
1112 'face 'mode-line-emphasis
1113 'help-echo
1114 "A VC command is in progress in this buffer"))))
d3201e0b 1115
0e362f54
GM
1116(defun vc-exec-after (code)
1117 "Eval CODE when the current buffer's process is done.
1118If the current buffer has no process, just evaluate CODE.
1119Else, add CODE to the process' sentinel."
1120 (let ((proc (get-buffer-process (current-buffer))))
1121 (cond
1122 ;; If there's no background process, just execute the code.
0f7ea453
CY
1123 ;; We used to explicitly call delete-process on exited processes,
1124 ;; but this led to timing problems causing process output to be
1125 ;; lost. Terminated processes get deleted automatically
1126 ;; anyway. -- cyd
1127 ((or (null proc) (eq (process-status proc) 'exit))
7c33af85
SM
1128 ;; Make sure we've read the process's output before going further.
1129 (if proc (accept-process-output proc))
0f7ea453 1130 (eval code))
0e362f54
GM
1131 ;; If a process is running, add CODE to the sentinel
1132 ((eq (process-status proc) 'run)
d3201e0b 1133 (vc-set-mode-line-busy-indicator)
86e80023
SM
1134 (let ((previous (process-sentinel proc)))
1135 (unless (eq previous 'vc-process-sentinel)
1136 (process-put proc 'vc-previous-sentinel previous))
1137 (set-process-sentinel proc 'vc-process-sentinel))
1138 (process-put proc 'vc-sentinel-commands
1d5b2149
TTN
1139 ;; We keep the code fragments in the order given
1140 ;; so that vc-diff-finish's message shows up in
1141 ;; the presence of non-nil vc-command-messages.
1142 (append (process-get proc 'vc-sentinel-commands)
1143 (list code))))
0e362f54
GM
1144 (t (error "Unexpected process state"))))
1145 nil)
1146
1147(defvar vc-post-command-functions nil
1148 "Hook run at the end of `vc-do-command'.
1149Each function is called inside the buffer in which the command was run
d7b60083 1150and is passed 3 arguments: the COMMAND, the FILES and the FLAGS.")
0e362f54 1151
2765044b
DN
1152(defvar w32-quote-process-args)
1153
8cdd17b4
ER
1154(defun vc-delistify (filelist)
1155 "Smash a FILELIST into a file list string suitable for info messages."
2765044b 1156 ;; FIXME what about file names with spaces?
d1a607bc 1157 (if (not filelist) "." (mapconcat 'identity filelist " ")))
8cdd17b4 1158
a84b80ba 1159;;;###autoload
8cdd17b4 1160(defun vc-do-command (buffer okstatus command file-or-list &rest flags)
6f1ecae4 1161 "Execute a VC command, notifying user and checking for errors.
ad339989
AS
1162Output from COMMAND goes to BUFFER, or *vc* if BUFFER is nil or the
1163current buffer if BUFFER is t. If the destination buffer is not
1164already current, set it up properly and erase it. The command is
1165considered successful if its exit status does not exceed OKSTATUS (if
c94dca60 1166OKSTATUS is nil, that means to ignore error status, if it is `async', that
11c89a07 1167means not to wait for termination of the subprocess; if it is t it means to
8cdd17b4 1168ignore all execution errors). FILE-OR-LIST is the name of a working file;
a7192ddb 1169it may be a list of files or be nil (to execute commands that don't expect
8cdd17b4 1170a file name or set of files). If an optional list of FLAGS is present,
0e362f54 1171that is inserted into the command line before the filename."
8cdd17b4
ER
1172 ;; FIXME: file-relative-name can return a bogus result because
1173 ;; it doesn't look at the actual file-system to see if symlinks
1174 ;; come into play.
d1a607bc
SM
1175 (let* ((files
1176 (mapcar (lambda (f) (file-relative-name (expand-file-name f)))
1177 (if (listp file-or-list) file-or-list (list file-or-list))))
d7b60083 1178 (full-command
a7192ddb 1179 ;; What we're doing here is preparing a version of the command
d7b60083 1180 ;; for display in a debug-progess message. If it's fewer than
a7192ddb 1181 ;; 20 characters display the entire command (without trailing
d7b60083
ER
1182 ;; newline). Otherwise display the first 20 followed by an ellipsis.
1183 (concat (if (string= (substring command -1) "\n")
1184 (substring command 0 -1)
1185 command)
a7192ddb
SM
1186 " "
1187 (vc-delistify (mapcar (lambda (s) (if (> (length s) 20) (concat (substring s 0 2) "...") s)) flags))
d7b60083 1188 " " (vc-delistify files))))
8cdd17b4
ER
1189 (save-current-buffer
1190 (unless (or (eq buffer t)
1191 (and (stringp buffer)
1192 (string= (buffer-name) buffer))
1193 (eq buffer (current-buffer)))
1194 (vc-setup-buffer buffer))
f605fc58
SM
1195 ;; If there's some previous async process still running, just kill it.
1196 (let ((oldproc (get-buffer-process (current-buffer))))
1197 ;; If we wanted to wait for oldproc to finish before doing
1198 ;; something, we'd have used vc-eval-after.
1199 ;; Use `delete-process' rather than `kill-process' because we don't
1200 ;; want any of its output to appear from now on.
1201 (if oldproc (delete-process oldproc)))
8cdd17b4
ER
1202 (let ((squeezed (remq nil flags))
1203 (inhibit-read-only t)
1204 (status 0))
1205 (when files
1206 (setq squeezed (nconc squeezed files)))
1207 (let ((exec-path (append vc-path exec-path))
1208 ;; Add vc-path to PATH for the execution of this command.
1209 (process-environment
1210 (cons (concat "PATH=" (getenv "PATH")
1211 path-separator
1212 (mapconcat 'identity vc-path path-separator))
1213 process-environment))
1214 (w32-quote-process-args t))
1215 (if (and (eq okstatus 'async) (file-remote-p default-directory))
1216 ;; start-process does not support remote execution
1217 (setq okstatus nil))
1218 (if (eq okstatus 'async)
f605fc58 1219 ;; Run asynchronously.
8cdd17b4
ER
1220 (let ((proc
1221 (let ((process-connection-type nil))
f605fc58
SM
1222 (apply 'start-file-process command (current-buffer)
1223 command squeezed))))
d7b60083
ER
1224 (if vc-command-messages
1225 (message "Running %s in background..." full-command))
8cdd17b4
ER
1226 ;;(set-process-sentinel proc (lambda (p msg) (delete-process p)))
1227 (set-process-filter proc 'vc-process-filter)
1228 (vc-exec-after
d7b60083
ER
1229 `(if vc-command-messages
1230 (message "Running %s in background... done" ',full-command))))
1231 ;; Run synchrously
1232 (if vc-command-messages
1233 (message "Running %s in foreground..." full-command))
8cdd17b4
ER
1234 (let ((buffer-undo-list t))
1235 (setq status (apply 'process-file command nil t nil squeezed)))
1236 (when (and (not (eq t okstatus))
1237 (or (not (integerp status))
1238 (and okstatus (< okstatus status))))
f42d59a5
SM
1239 (unless (eq ?\s (aref (buffer-name (current-buffer)) 0))
1240 (pop-to-buffer (current-buffer))
1241 (goto-char (point-min))
1242 (shrink-window-if-larger-than-buffer))
8cdd17b4
ER
1243 (error "Running %s...FAILED (%s)" full-command
1244 (if (integerp status) (format "status %d" status) status))))
e0752dd7
ER
1245 ;; We're done. But don't emit a status message if running
1246 ;; asychronously, it would just mislead.
1247 (if (and vc-command-messages (not (eq okstatus 'async)))
d7b60083 1248 (message "Running %s...OK = %d" full-command status)))
8cdd17b4 1249 (vc-exec-after
a7192ddb 1250 `(run-hook-with-args 'vc-post-command-functions
d7b60083 1251 ',command ',file-or-list ',flags))
8cdd17b4 1252 status))))
594722a8 1253
c4ae7096 1254(defun vc-position-context (posn)
099bd78a
SM
1255 "Save a bit of the text around POSN in the current buffer.
1256Used to help us find the corresponding position again later
1257if markers are destroyed or corrupted."
0e362f54
GM
1258 ;; A lot of this was shamelessly lifted from Sebastian Kremer's
1259 ;; rcs.el mode.
c4ae7096
JB
1260 (list posn
1261 (buffer-size)
1262 (buffer-substring posn
1263 (min (point-max) (+ posn 100)))))
1264
c4ae7096 1265(defun vc-find-position-by-context (context)
6f1ecae4
AS
1266 "Return the position of CONTEXT in the current buffer.
1267If CONTEXT cannot be found, return nil."
c4ae7096
JB
1268 (let ((context-string (nth 2 context)))
1269 (if (equal "" context-string)
1270 (point-max)
1271 (save-excursion
1272 (let ((diff (- (nth 1 context) (buffer-size))))
1273 (if (< diff 0) (setq diff (- diff)))
1274 (goto-char (nth 0 context))
1275 (if (or (search-forward context-string nil t)
1276 ;; Can't use search-backward since the match may continue
1277 ;; after point.
1278 (progn (goto-char (- (point) diff (length context-string)))
1279 ;; goto-char doesn't signal an error at
1280 ;; beginning of buffer like backward-char would
1281 (search-forward context-string nil t)))
1282 ;; to beginning of OSTRING
1283 (- (point) (length context-string))))))))
1284
4b398f5d 1285(defun vc-context-matches-p (posn context)
099bd78a 1286 "Return t if POSN matches CONTEXT, nil otherwise."
4b398f5d
AS
1287 (let* ((context-string (nth 2 context))
1288 (len (length context-string))
1289 (end (+ posn len)))
1290 (if (> end (1+ (buffer-size)))
1291 nil
1292 (string= context-string (buffer-substring posn end)))))
1293
c8de1d91 1294(defun vc-buffer-context ()
099bd78a
SM
1295 "Return a list (POINT-CONTEXT MARK-CONTEXT REPARSE).
1296Used by `vc-restore-buffer-context' to later restore the context."
c4ae7096 1297 (let ((point-context (vc-position-context (point)))
cfadef63
RS
1298 ;; Use mark-marker to avoid confusion in transient-mark-mode.
1299 (mark-context (if (eq (marker-buffer (mark-marker)) (current-buffer))
1300 (vc-position-context (mark-marker))))
1301 ;; Make the right thing happen in transient-mark-mode.
ab877583 1302 (mark-active nil)
0452b6e7
SM
1303 ;; The new compilation code does not use compilation-error-list any
1304 ;; more, so the code below is now ineffective and might as well
1305 ;; be disabled. -- Stef
1306 ;; ;; We may want to reparse the compilation buffer after revert
1307 ;; (reparse (and (boundp 'compilation-error-list) ;compile loaded
1308 ;; ;; Construct a list; each elt is nil or a buffer
4837b516 1309 ;; ;; if that buffer is a compilation output buffer
0452b6e7
SM
1310 ;; ;; that contains markers into the current buffer.
1311 ;; (save-current-buffer
1312 ;; (mapcar (lambda (buffer)
1313 ;; (set-buffer buffer)
1314 ;; (let ((errors (or
1315 ;; compilation-old-error-list
1316 ;; compilation-error-list))
1317 ;; (buffer-error-marked-p nil))
1318 ;; (while (and (consp errors)
1319 ;; (not buffer-error-marked-p))
1320 ;; (and (markerp (cdr (car errors)))
1321 ;; (eq buffer
1322 ;; (marker-buffer
1323 ;; (cdr (car errors))))
1324 ;; (setq buffer-error-marked-p t))
1325 ;; (setq errors (cdr errors)))
1326 ;; (if buffer-error-marked-p buffer)))
1327 ;; (buffer-list)))))
1328 (reparse nil))
c8de1d91
AS
1329 (list point-context mark-context reparse)))
1330
1331(defun vc-restore-buffer-context (context)
0e362f54 1332 "Restore point/mark, and reparse any affected compilation buffers.
099bd78a 1333CONTEXT is that which `vc-buffer-context' returns."
c8de1d91
AS
1334 (let ((point-context (nth 0 context))
1335 (mark-context (nth 1 context))
a7192ddb
SM
1336 ;; (reparse (nth 2 context))
1337 )
0452b6e7
SM
1338 ;; The new compilation code does not use compilation-error-list any
1339 ;; more, so the code below is now ineffective and might as well
1340 ;; be disabled. -- Stef
1341 ;; ;; Reparse affected compilation buffers.
1342 ;; (while reparse
1343 ;; (if (car reparse)
1344 ;; (with-current-buffer (car reparse)
1345 ;; (let ((compilation-last-buffer (current-buffer)) ;select buffer
1346 ;; ;; Record the position in the compilation buffer of
1347 ;; ;; the last error next-error went to.
1348 ;; (error-pos (marker-position
1349 ;; (car (car-safe compilation-error-list)))))
1350 ;; ;; Reparse the error messages as far as they were parsed before.
1351 ;; (compile-reinitialize-errors '(4) compilation-parsing-end)
1352 ;; ;; Move the pointer up to find the error we were at before
1353 ;; ;; reparsing. Now next-error should properly go to the next one.
1354 ;; (while (and compilation-error-list
1355 ;; (/= error-pos (car (car compilation-error-list))))
1356 ;; (setq compilation-error-list (cdr compilation-error-list))))))
1357 ;; (setq reparse (cdr reparse)))
e1f297e6 1358
4b398f5d
AS
1359 ;; if necessary, restore point and mark
1360 (if (not (vc-context-matches-p (point) point-context))
1361 (let ((new-point (vc-find-position-by-context point-context)))
1362 (if new-point (goto-char new-point))))
01e02ab3
AS
1363 (and mark-active
1364 mark-context
1365 (not (vc-context-matches-p (mark) mark-context))
1366 (let ((new-mark (vc-find-position-by-context mark-context)))
1367 (if new-mark (set-mark new-mark))))))
c4ae7096 1368
d7b60083
ER
1369;;; Code for deducing what fileset and backend to assume
1370
2765044b
DN
1371(defun vc-responsible-backend (file &optional register)
1372 "Return the name of a backend system that is responsible for FILE.
1373The optional argument REGISTER means that a backend suitable for
1374registration should be found.
1375
1376If REGISTER is nil, then if FILE is already registered, return the
1377backend of FILE. If FILE is not registered, or a directory, then the
1378first backend in `vc-handled-backends' that declares itself
1379responsible for FILE is returned. If no backend declares itself
1380responsible, return the first backend.
1381
1382If REGISTER is non-nil, return the first responsible backend under
1383which FILE is not yet registered. If there is no such backend, return
1384the first backend under which FILE is not yet registered, but could
1385be registered."
1386 (if (not vc-handled-backends)
1387 (error "No handled backends"))
1388 (or (and (not (file-directory-p file)) (not register) (vc-backend file))
1389 (catch 'found
1390 ;; First try: find a responsible backend. If this is for registration,
1391 ;; it must be a backend under which FILE is not yet registered.
1392 (dolist (backend vc-handled-backends)
1393 (and (or (not register)
1394 (not (vc-call-backend backend 'registered file)))
1395 (vc-call-backend backend 'responsible-p file)
1396 (throw 'found backend)))
1397 ;; no responsible backend
1398 (if (not register)
1399 ;; if this is not for registration, the first backend must do
1400 (car vc-handled-backends)
1401 ;; for registration, we need to find a new backend that
1402 ;; could register FILE
1403 (dolist (backend vc-handled-backends)
1404 (and (not (vc-call-backend backend 'registered file))
1405 (vc-call-backend backend 'could-register file)
1406 (throw 'found backend)))
1407 (error "No backend that could register")))))
1408
1409(defun vc-expand-dirs (file-or-dir-list)
1410 "Expands directories in a file list specification.
1411Only files already under version control are noticed."
1412 ;; FIXME: Kill this function.
1413 (let ((flattened '()))
1414 (dolist (node file-or-dir-list)
1415 (vc-file-tree-walk
1416 node (lambda (f) (if (vc-backend f) (push f flattened)))))
1417 (nreverse flattened)))
1418
ccd9fab6 1419(defun vc-deduce-fileset (&optional allow-directory-wildcard allow-unregistered)
a7192ddb
SM
1420 "Deduce a set of files and a backend to which to apply an operation.
1421
1422If we're in VC-dired mode, the fileset is the list of marked files.
1423Otherwise, if we're looking at a buffer visiting a version-controlled file,
1424the fileset is a singleton containing this file.
1425If neither of these things is true, but ALLOW-DIRECTORY-WILDCARD is on
1426and we're in a dired buffer, select the current directory.
ccd9fab6
ER
1427If none of these conditions is met, but ALLOW_UNREGISTERED is in and the
1428visited file is not registered, return a singletin fileset containing it.
a7192ddb
SM
1429Otherwise, throw an error."
1430 (cond (vc-dired-mode
1431 (let ((marked (dired-map-over-marks (dired-get-filename) nil)))
d7b60083
ER
1432 (unless marked
1433 (error "No files have been selected."))
1434 ;; All members of the fileset must have the same backend
1435 (let ((firstbackend (vc-backend (car marked))))
a7192ddb
SM
1436 (dolist (f (cdr marked))
1437 (unless (eq (vc-backend f) firstbackend)
1438 (error "All members of a fileset must be under the same version-control system."))))
d7b60083 1439 marked))
e11c1d93 1440 ((eq major-mode 'vc-status-mode)
c1b51374
SM
1441 (or (vc-status-marked-files)
1442 (list (vc-status-current-file))))
e11c1d93 1443 ((vc-backend buffer-file-name)
d7b60083 1444 (list buffer-file-name))
d24182bb
DN
1445 ((and vc-parent-buffer (or (buffer-file-name vc-parent-buffer)
1446 (with-current-buffer vc-parent-buffer
76cdeb7d 1447 (or vc-dired-mode (eq major-mode 'vc-status-mode)))))
d7b60083
ER
1448 (progn
1449 (set-buffer vc-parent-buffer)
1450 (vc-deduce-fileset)))
a7192ddb
SM
1451 ;; This is guarded by an enabling arg so users won't potentially
1452 ;; shoot themselves in the foot by modifying a fileset they can't
d7b60083
ER
1453 ;; verify by eyeball. Allow it for nondestructive commands like
1454 ;; making diffs, or possibly for destructive ones that have
1455 ;; confirmation prompts.
a7192ddb
SM
1456 ((and allow-directory-wildcard
1457 ;; I think this is a misfeature. For now, I'll leave it in, but
1458 ;; I'll disable it anywhere else than in dired buffers. --Stef
1459 (and (derived-mode-p 'dired-mode)
1460 (equal buffer-file-name nil)
1461 (equal list-buffers-directory default-directory)))
d7b60083 1462 (progn
d7b60083
ER
1463 (message "All version-controlled files below %s selected."
1464 default-directory)
1465 (list default-directory)))
01823b77 1466 ((and allow-unregistered (not (vc-registered buffer-file-name)))
ccd9fab6 1467 (list buffer-file-name))
d7b60083
ER
1468 (t (error "No fileset is available here."))))
1469
2765044b
DN
1470(defun vc-ensure-vc-buffer ()
1471 "Make sure that the current buffer visits a version-controlled file."
ca8dfeda
DN
1472 (cond
1473 (vc-dired-mode
1474 (set-buffer (find-file-noselect (dired-get-filename))))
1475 ((eq major-mode 'vc-status-mode)
1476 (set-buffer (find-file-noselect (vc-status-current-file))))
1477 (t
772111be 1478 (while (and vc-parent-buffer
cc72026b 1479 (buffer-live-p vc-parent-buffer)
772111be
MR
1480 ;; Avoid infinite looping when vc-parent-buffer and
1481 ;; current buffer are the same buffer.
1482 (not (eq vc-parent-buffer (current-buffer))))
2765044b
DN
1483 (set-buffer vc-parent-buffer))
1484 (if (not buffer-file-name)
1485 (error "Buffer %s is not associated with a file" (buffer-name))
1486 (if (not (vc-backend buffer-file-name))
ca8dfeda 1487 (error "File %s is not under version control" buffer-file-name))))))
2765044b 1488
61de26cb
ER
1489;;; Support for the C-x v v command. This is where all the single-file-oriented
1490;;; code from before the fileset rewrite lives.
1491
2765044b
DN
1492(defsubst vc-editable-p (file)
1493 "Return non-nil if FILE can be edited."
1494 (or (eq (vc-checkout-model file) 'implicit)
7fbb4797 1495 (memq (vc-state file) '(edited needs-merge conflict))))
2765044b 1496
61de26cb 1497(defun vc-revert-buffer-internal (&optional arg no-confirm)
6f1ecae4 1498 "Revert buffer, keeping point and mark where user expects them.
ac3f4c6f 1499Try to be clever in the face of changes due to expanded version-control
099bd78a
SM
1500key words. This is important for typeahead to work as expected.
1501ARG and NO-CONFIRM are passed on to `revert-buffer'."
c8de1d91
AS
1502 (interactive "P")
1503 (widen)
1504 (let ((context (vc-buffer-context)))
4b398f5d
AS
1505 ;; Use save-excursion here, because it may be able to restore point
1506 ;; and mark properly even in cases where vc-restore-buffer-context
0e362f54 1507 ;; would fail. However, save-excursion might also get it wrong --
4b398f5d
AS
1508 ;; in this case, vc-restore-buffer-context gives it a second try.
1509 (save-excursion
0e362f54 1510 ;; t means don't call normal-mode;
4b398f5d
AS
1511 ;; that's to preserve various minor modes.
1512 (revert-buffer arg no-confirm t))
c8de1d91
AS
1513 (vc-restore-buffer-context context)))
1514
97d3f950 1515(defun vc-buffer-sync (&optional not-urgent)
099bd78a 1516 "Make sure the current buffer and its working file are in sync.
0e362f54 1517NOT-URGENT means it is ok to continue if the user says not to save."
bbf97570 1518 (if (buffer-modified-p)
97d3f950
RS
1519 (if (or vc-suppress-confirm
1520 (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name))))
1521 (save-buffer)
0e362f54 1522 (unless not-urgent
97d3f950
RS
1523 (error "Aborted")))))
1524
2765044b
DN
1525(defvar vc-dired-window-configuration)
1526
484c1b1f
ER
1527(defun vc-compatible-state (p q)
1528 "Controls which states can be in the same commit."
1529 (or
1530 (eq p q)
1531 (and (member p '(edited added removed)) (member q '(edited added removed)))))
1532
2765044b
DN
1533;; Here's the major entry point.
1534
1535;;;###autoload
1536(defun vc-next-action (verbose)
d7b60083
ER
1537 "Do the next logical version control operation on the current fileset.
1538This requires that all files in the fileset be in the same state.
2765044b 1539
d7b60083
ER
1540For locking systems:
1541 If every file is not already registered, this registers each for version
2765044b 1542control.
d7b60083
ER
1543 If every file is registered and not locked by anyone, this checks out
1544a writable and locked file of each ready for editing.
1545 If every file is checked out and locked by the calling user, this
1546first checks to see if each file has changed since checkout. If not,
1547it performs a revert on that file.
1548 If every file has been changed, this pops up a buffer for entry
2765044b
DN
1549of a log message; when the message has been entered, it checks in the
1550resulting changes along with the log message as change commentary. If
1551the variable `vc-keep-workfiles' is non-nil (which is its default), a
d7b60083
ER
1552read-only copy of each changed file is left in place afterwards.
1553 If the affected file is registered and locked by someone else, you are
1554given the option to steal the lock(s).
1555
1556For merging systems:
1557 If every file is not already registered, this registers each one for version
1558control. This does an add, but not a commit.
1559 If every file is added but not committed, each one is committed.
1560 If every working file is changed, but the corresponding repository file is
2765044b
DN
1561unchanged, this pops up a buffer for entry of a log message; when the
1562message has been entered, it checks in the resulting changes along
1563with the logmessage as change commentary. A writable file is retained.
1564 If the repository file is changed, you are asked if you want to
1565merge in the changes into your working copy."
2765044b 1566 (interactive "P")
ccd9fab6 1567 (let* ((files (vc-deduce-fileset nil t))
d7b60083
ER
1568 (state (vc-state (car files)))
1569 (model (vc-checkout-model (car files)))
ac3f4c6f 1570 revision)
9eef6650 1571 ;; Verify that the fileset is homogeneous
d7b60083 1572 (dolist (file (cdr files))
e166638d
DN
1573 (unless (vc-compatible-state (vc-state file) state)
1574 (error "Fileset is in a mixed-up state"))
1575 (unless (eq (vc-checkout-model file) model)
d7b60083
ER
1576 (error "Fileset has mixed checkout models")))
1577 ;; Check for buffers in the fileset not matching the on-disk contents.
1578 (dolist (file files)
1579 (let ((visited (get-file-buffer file)))
1580 (when visited
76cdeb7d 1581 (if (or vc-dired-mode (eq major-mode 'vc-status-mode))
d7b60083
ER
1582 (switch-to-buffer-other-window visited)
1583 (set-buffer visited))
1584 ;; Check relation of buffer and file, and make sure
1585 ;; user knows what he's doing. First, finding the file
1586 ;; will check whether the file on disk is newer.
1587 ;; Ignore buffer-read-only during this test, and
1588 ;; preserve find-file-literally.
1589 (let ((buffer-read-only (not (file-writable-p file))))
1590 (find-file-noselect file nil find-file-literally))
1591 (if (not (verify-visited-file-modtime (current-buffer)))
1592 (if (yes-or-no-p (format "Replace %s on disk with buffer contents? " file))
1593 (write-file buffer-file-name)
1594 (error "Aborted"))
1595 ;; Now, check if we have unsaved changes.
1596 (vc-buffer-sync t)
e166638d
DN
1597 (when (buffer-modified-p)
1598 (or (y-or-n-p (message "Use %s on disk, keeping modified buffer? " file))
1599 (error "Aborted")))))))
0e362f54 1600 ;; Do the right thing
a7192ddb 1601 (cond
d7b60083 1602 ;; Files aren't registered
e166638d
DN
1603 ((or (not state) ;; RCS uses nil for unregistered files.
1604 (eq state 'unregistered)
1605 (eq state 'ignored))
d7b60083 1606 (mapc 'vc-register files))
ac3f4c6f 1607 ;; Files are up-to-date, or need a merge and user specified a revision
d7b60083 1608 ((or (eq state 'up-to-date) (and verbose (eq state 'needs-patch)))
0e362f54 1609 (cond
d7b60083 1610 (verbose
ac3f4c6f
ER
1611 ;; go to a different revision
1612 (setq revision (read-string "Branch, revision, or backend to move to: "))
1613 (let ((vsym (intern-soft (upcase revision))))
d7b60083 1614 (if (member vsym vc-handled-backends)
a7192ddb
SM
1615 (dolist (file files) (vc-transfer-file file vsym))
1616 (dolist (file files)
1617 (vc-checkout file (eq model 'implicit) revision)))))
d7b60083
ER
1618 ((not (eq model 'implicit))
1619 ;; check the files out
a7192ddb 1620 (dolist (file files) (vc-checkout file t)))
d7b60083 1621 (t
a7192ddb
SM
1622 ;; do nothing
1623 (message "Fileset is up-to-date"))))
1624 ;; Files have local changes
484c1b1f 1625 ((vc-compatible-state state 'edited)
d7b60083
ER
1626 (let ((ready-for-commit files))
1627 ;; If files are edited but read-only, give user a chance to correct
1628 (dolist (file files)
e166638d
DN
1629 (unless (file-writable-p file)
1630 ;; Make the file+buffer read-write.
1631 (unless (y-or-n-p (format "%s is edited but read-only; make it writable and continue?" file))
1632 (error "Aborted"))
1633 (set-file-modes file (logior (file-modes file) 128))
1634 (let ((visited (get-file-buffer file)))
1635 (when visited
1636 (with-current-buffer visited
1637 (toggle-read-only -1))))))
d7b60083
ER
1638 ;; Allow user to revert files with no changes
1639 (save-excursion
a7192ddb
SM
1640 (dolist (file files)
1641 (let ((visited (get-file-buffer file)))
1642 ;; For files with locking, if the file does not contain
1643 ;; any changes, just let go of the lock, i.e. revert.
e166638d
DN
1644 (when (and (not (eq model 'implicit))
1645 (vc-workfile-unchanged-p file)
1646 ;; If buffer is modified, that means the user just
1647 ;; said no to saving it; in that case, don't revert,
1648 ;; because the user might intend to save after
1649 ;; finishing the log entry and committing.
1650 (not (and visited (buffer-modified-p))))
1651 (vc-revert-file file)
1652 (delete file ready-for-commit)))))
d7b60083
ER
1653 ;; Remaining files need to be committed
1654 (if (not ready-for-commit)
1655 (message "No files remain to be committed")
1d502d5a 1656 (if (not verbose)
d7b60083
ER
1657 (vc-checkin ready-for-commit)
1658 (progn
ac3f4c6f
ER
1659 (setq revision (read-string "New revision or backend: "))
1660 (let ((vsym (intern (upcase revision))))
d7b60083 1661 (if (member vsym vc-handled-backends)
d36122a2 1662 (dolist (file files) (vc-transfer-file file vsym))
ac3f4c6f 1663 (vc-checkin ready-for-commit revision))))))))
d7b60083
ER
1664 ;; locked by somebody else (locking VCSes only)
1665 ((stringp state)
d36122a2
TTN
1666 ;; In the old days, we computed the revision once and used it on
1667 ;; the single file. Then, for the 2007-2008 fileset rewrite, we
1668 ;; computed the revision once (incorrectly, using a free var) and
1669 ;; used it on all files. To fix the free var bug, we can either
1670 ;; use `(car files)' or do what we do here: distribute the
1671 ;; revision computation among `files'. Although this may be
1672 ;; tedious for those backends where a "revision" is a trans-file
1673 ;; concept, it is nonetheless correct for both those and (more
1674 ;; importantly) for those where "revision" is a per-file concept.
1675 ;; If the intersection of the former group and "locking VCSes" is
1676 ;; non-empty [I vaguely doubt it --ttn], we can reinstate the
1677 ;; pre-computation approach of yore.
1678 (dolist (file files)
1679 (vc-steal-lock
1680 file (if verbose
1681 (read-string (format "%s revision to steal: " file))
1682 (vc-working-revision file))
1683 state)))
7fbb4797
DN
1684 ;; conflict
1685 ((eq state 'conflict)
1686 (vc-mark-resolved files))
a7192ddb 1687 ;; needs-patch
d7b60083
ER
1688 ((eq state 'needs-patch)
1689 (dolist (file files)
6f41eeb5 1690 (if (yes-or-no-p (format
ac3f4c6f 1691 "%s is not up-to-date. Get latest revision? "
0e362f54 1692 (file-name-nondirectory file)))
d7b60083 1693 (vc-checkout file (eq model 'implicit) t)
e166638d
DN
1694 (when (and (not (eq model 'implicit))
1695 (yes-or-no-p "Lock this revision? "))
1696 (vc-checkout file t)))))
d7b60083
ER
1697 ;; needs-merge
1698 ((eq state 'needs-merge)
1699 (dolist (file files)
e166638d 1700 (when (yes-or-no-p (format
0e362f54
GM
1701 "%s is not up-to-date. Merge in changes now? "
1702 (file-name-nondirectory file)))
e166638d 1703 (vc-maybe-resolve-conflicts file (vc-call merge-news file)))))
46e33aee 1704
d7b60083
ER
1705 ;; unlocked-changes
1706 ((eq state 'unlocked-changes)
1707 (dolist (file files)
a7192ddb 1708 (if (not (equal buffer-file-name file))
d7b60083 1709 (find-file-other-window file))
0e362f54 1710 (if (save-window-excursion
a7192ddb 1711 (vc-diff-internal nil (list file) (vc-working-revision file) nil)
0e362f54 1712 (goto-char (point-min))
ceec5a0c 1713 (let ((inhibit-read-only t))
f4f34b33 1714 (insert
ceec5a0c 1715 (format "Changes to %s since last lock:\n\n" file)))
0e362f54
GM
1716 (not (beep))
1717 (yes-or-no-p (concat "File has unlocked changes. "
1718 "Claim lock retaining changes? ")))
1719 (progn (vc-call steal-lock file)
61de26cb 1720 (clear-visited-file-modtime)
0e362f54
GM
1721 ;; Must clear any headers here because they wouldn't
1722 ;; show that the file is locked now.
1723 (vc-clear-headers file)
a36319a4 1724 (write-file buffer-file-name)
0e362f54
GM
1725 (vc-mode-line file))
1726 (if (not (yes-or-no-p
ac3f4c6f 1727 "Revert to checked-in revision, instead? "))
0e362f54 1728 (error "Checkout aborted")
61de26cb 1729 (vc-revert-buffer-internal t t)
0e362f54 1730 (vc-checkout file t))))))))
e1f297e6 1731
61de26cb
ER
1732(defun vc-create-repo (backend)
1733 "Create an empty repository in the current directory."
1734 (interactive
1735 (list
1736 (intern
1737 (upcase
1738 (completing-read
1739 "Create repository for: "
1740 (mapcar (lambda (b) (list (downcase (symbol-name b)))) vc-handled-backends)
1741 nil t)))))
1742 (vc-call-backend backend 'create-repo))
1743
637a8ae9 1744;;;###autoload
30a308aa
DN
1745(defun vc-register (&optional fname set-revision comment)
1746 "Register into a version control system.
1747If FNAME is given register that file, otherwise register the current file.
ac3f4c6f 1748With prefix argument SET-REVISION, allow user to specify initial revision
2765044b 1749level. If COMMENT is present, use that as an initial comment.
0e362f54 1750
2765044b
DN
1751The version control system to use is found by cycling through the list
1752`vc-handled-backends'. The first backend in that list which declares
1753itself responsible for the file (usually because other files in that
1754directory are already registered under that backend) will be used to
1755register the file. If no backend declares itself responsible, the
1756first backend that could register the file is used."
1757 (interactive "P")
30a308aa
DN
1758 (when (and (null fname) (null buffer-file-name)) (error "No visited file"))
1759
5f01100a 1760 (let ((bname (if fname (get-file-buffer fname) (current-buffer))))
30a308aa
DN
1761 (unless fname (setq fname buffer-file-name))
1762 (when (vc-backend fname)
1763 (if (vc-registered fname)
1764 (error "This file is already registered")
1765 (unless (y-or-n-p "Previous master file has vanished. Make a new one? ")
1766 (error "Aborted"))))
1767 ;; Watch out for new buffers of size 0: the corresponding file
1768 ;; does not exist yet, even though buffer-modified-p is nil.
1769 (when bname
1770 (with-current-buffer bname
1771 (if (and (not (buffer-modified-p))
1772 (zerop (buffer-size))
1773 (not (file-exists-p buffer-file-name)))
1774 (set-buffer-modified-p t))
1775 (vc-buffer-sync)))
1776 (vc-start-entry (list fname)
1777 (if set-revision
1778 (read-string (format "Initial revision level for %s: "
1779 fname))
1780 (vc-call-backend (vc-responsible-backend fname)
1781 'init-revision))
1782 (or comment (not vc-initial-comment))
1783 nil
1784 "Enter initial comment."
1785 (lambda (files rev comment)
1786 (dolist (file files)
1787 (message "Registering %s... " file)
1788 (let ((backend (vc-responsible-backend file t)))
1789 (vc-file-clearprops file)
1790 (vc-call-backend backend 'register (list file) rev comment)
1791 (vc-file-setprop file 'vc-backend backend)
1792 (unless vc-make-backup-files
1793 (make-local-variable 'backup-inhibited)
1794 (setq backup-inhibited t)))
1795 (message "Registering %s... done" file))))))
d7b60083
ER
1796
1797(defun vc-register-with (backend)
1798 "Register the current file with a specified back end."
1799 (interactive "SBackend: ")
1800 (if (not (member backend vc-handled-backends))
1801 (error "Unknown back end."))
1802 (let ((vc-handled-backends (list backend)))
1803 (call-interactively 'vc-register)))
8989ab56 1804
73e72da4
DN
1805(declare-function view-mode-exit "view" (&optional return-to-alist exit-action all-win))
1806
624b4662 1807(defun vc-resynch-window (file &optional keep noquery)
099bd78a
SM
1808 "If FILE is in the current buffer, either revert or unvisit it.
1809The choice between revert (to see expanded keywords) and unvisit depends on
1810`vc-keep-workfiles'. NOQUERY if non-nil inhibits confirmation for
0e362f54
GM
1811reverting. NOQUERY should be t *only* if it is known the only
1812difference between the buffer and the file is due to version control
1813rather than user editing!"
594722a8
ER
1814 (and (string= buffer-file-name file)
1815 (if keep
1816 (progn
61de26cb 1817 (vc-revert-buffer-internal t noquery)
0e362f54
GM
1818 ;; TODO: Adjusting view mode might no longer be necessary
1819 ;; after RMS change to files.el of 1999-08-08. Investigate
1820 ;; this when we install the new VC.
f8791ebe
AS
1821 (and view-read-only
1822 (if (file-writable-p file)
1823 (and view-mode
1824 (let ((view-old-buffer-read-only nil))
1825 (view-mode-exit)))
1826 (and (not view-mode)
1827 (not (eq (get major-mode 'mode-class) 'special))
1828 (view-mode-enter))))
594722a8 1829 (vc-mode-line buffer-file-name))
88a2ffaf 1830 (kill-buffer (current-buffer)))))
594722a8 1831
503b5c85 1832(defun vc-resynch-buffer (file &optional keep noquery)
0e362f54 1833 "If FILE is currently visited, resynch its buffer."
4b398f5d
AS
1834 (if (string= buffer-file-name file)
1835 (vc-resynch-window file keep noquery)
1836 (let ((buffer (get-file-buffer file)))
21f3a277
DN
1837 (when buffer
1838 (with-current-buffer buffer
1839 (vc-resynch-window file keep noquery)))))
1840 (vc-dired-resynch-file file)
1841 (when (memq 'vc-status-mark-buffer-changed after-save-hook)
1842 (let ((buffer (get-file-buffer file)))
484c3092 1843 (vc-status-mark-buffer-changed file))))
21f3a277 1844
503b5c85 1845
d7b60083
ER
1846(defun vc-start-entry (files rev comment initial-contents msg action &optional after-hook)
1847 "Accept a comment for an operation on FILES revision REV.
6f41eeb5 1848If COMMENT is nil, pop up a VC-log buffer, emit MSG, and set the
0ab66291
AS
1849action on close to ACTION. If COMMENT is a string and
1850INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial
1851contents of the log entry buffer. If COMMENT is a string and
1852INITIAL-CONTENTS is nil, do action immediately as if the user had
1853entered COMMENT. If COMMENT is t, also do action immediately with an
46e33aee
TTN
1854empty comment. Remember the file's buffer in `vc-parent-buffer'
1855\(current one if no file). AFTER-HOOK specifies the local value
e166638d 1856for `vc-log-after-operation-hook'."
a7192ddb 1857 (let ((parent
76cdeb7d 1858 (if (or (eq major-mode 'vc-dired-mode) (eq major-mode 'vc-status-mode))
c27f56ee
DN
1859 ;; If we are called from VC dired, the parent buffer is
1860 ;; the current buffer.
1861 (current-buffer)
1862 (if (and files (equal (length files) 1))
1863 (get-file-buffer (car files))
1864 (current-buffer)))))
1865 (when vc-before-checkin-hook
1866 (if files
1867 (with-current-buffer parent
1868 (run-hooks 'vc-before-checkin-hook))
1869 (run-hooks 'vc-before-checkin-hook)))
0ab66291 1870 (if (and comment (not initial-contents))
e1f297e6
ER
1871 (set-buffer (get-buffer-create "*VC-log*"))
1872 (pop-to-buffer (get-buffer-create "*VC-log*")))
8c0aaf40
ER
1873 (set (make-local-variable 'vc-parent-buffer) parent)
1874 (set (make-local-variable 'vc-parent-buffer-name)
1875 (concat " from " (buffer-name vc-parent-buffer)))
d7b60083
ER
1876 ;;(if file (vc-mode-line file))
1877 (vc-log-edit files)
b965445f 1878 (make-local-variable 'vc-log-after-operation-hook)
c27f56ee
DN
1879 (when after-hook
1880 (setq vc-log-after-operation-hook after-hook))
e1f297e6 1881 (setq vc-log-operation action)
ac3f4c6f 1882 (setq vc-log-revision rev)
347bef30
SM
1883 (when comment
1884 (erase-buffer)
1885 (when (stringp comment) (insert comment)))
1886 (if (or (not comment) initial-contents)
1887 (message "%s Type C-c C-c when done" msg)
1888 (vc-finish-logentry (eq comment t)))))
e1f297e6 1889
c6d4f628 1890(defun vc-checkout (file &optional writable rev)
099bd78a
SM
1891 "Retrieve a copy of the revision REV of FILE.
1892If WRITABLE is non-nil, make sure the retrieved file is writable.
133a84aa
AS
1893REV defaults to the latest revision.
1894
1895After check-out, runs the normal hook `vc-checkout-hook'."
ffda0460
AS
1896 (and writable
1897 (not rev)
10b48cc4 1898 (vc-call make-version-backups-p file)
ffda0460 1899 (vc-up-to-date-p file)
10b48cc4 1900 (vc-make-version-backup file))
099bd78a 1901 (with-vc-properties
d7b60083 1902 (list file)
099bd78a
SM
1903 (condition-case err
1904 (vc-call checkout file writable rev)
1905 (file-error
1906 ;; Maybe the backend is not installed ;-(
1907 (when writable
1908 (let ((buf (get-file-buffer file)))
1909 (when buf (with-current-buffer buf (toggle-read-only -1)))))
1910 (signal (car err) (cdr err))))
a3255400
SM
1911 `((vc-state . ,(if (or (eq (vc-checkout-model file) 'implicit)
1912 (not writable))
1913 (if (vc-call latest-on-branch-p file)
1914 'up-to-date
1915 'needs-patch)
1916 'edited))
1917 (vc-checkout-time . ,(nth 5 (file-attributes file)))))
7cad930d
AS
1918 (vc-resynch-buffer file t t)
1919 (run-hooks 'vc-checkout-hook))
594722a8 1920
7fbb4797
DN
1921(defun vc-mark-resolved (files)
1922 (with-vc-properties
1923 files
1924 (vc-call mark-resolved files)
1925 ;; XXX: Is this TRTD? Might not be.
1926 `((vc-state . edited))))
1927
0e362f54 1928(defun vc-steal-lock (file rev owner)
099bd78a 1929 "Steal the lock on FILE."
29fc1ce9 1930 (let (file-description)
29fc1ce9
RS
1931 (if rev
1932 (setq file-description (format "%s:%s" file rev))
1933 (setq file-description file))
4bc504c8
RS
1934 (if (not (yes-or-no-p (format "Steal the lock on %s from %s? "
1935 file-description owner)))
0e362f54 1936 (error "Steal canceled"))
869131a5
AS
1937 (message "Stealing lock on %s..." file)
1938 (with-vc-properties
d7b60083 1939 (list file)
869131a5
AS
1940 (vc-call steal-lock file rev)
1941 `((vc-state . edited)))
1942 (vc-resynch-buffer file t t)
1943 (message "Stealing lock on %s...done" file)
1944 ;; Write mail after actually stealing, because if the stealing
1945 ;; goes wrong, we don't want to send any mail.
1946 (compose-mail owner (format "Stolen lock on %s" file-description))
29fc1ce9 1947 (setq default-directory (expand-file-name "~/"))
29fc1ce9
RS
1948 (goto-char (point-max))
1949 (insert
1950 (format "I stole the lock on %s, " file-description)
1951 (current-time-string)
1952 ".\n")
1953 (message "Please explain why you stole the lock. Type C-c C-c when done.")))
594722a8 1954
d7b60083
ER
1955(defun vc-checkin (files &optional rev comment initial-contents)
1956 "Check in FILES.
ac3f4c6f 1957The optional argument REV may be a string specifying the new revision
0e362f54 1958level (if nil increment the current level). COMMENT is a comment
0ab66291
AS
1959string; if omitted, a buffer is popped up to accept a comment. If
1960INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial contents
1961of the log entry buffer.
0e362f54
GM
1962
1963If `vc-keep-workfiles' is nil, FILE is deleted afterwards, provided
1964that the version control system supports this mode of operation.
861f3c29
DL
1965
1966Runs the normal hook `vc-checkin-hook'."
6f41eeb5 1967 (vc-start-entry
d7b60083 1968 files rev comment initial-contents
6f41eeb5 1969 "Enter a change comment."
d7b60083
ER
1970 (lambda (files rev comment)
1971 (message "Checking in %s..." (vc-delistify files))
0e362f54
GM
1972 ;; "This log message intentionally left almost blank".
1973 ;; RCS 5.7 gripes about white-space-only comments too.
1974 (or (and comment (string-match "[^\t\n ]" comment))
1975 (setq comment "*** empty log message ***"))
46e33aee 1976 (with-vc-properties
d7b60083
ER
1977 files
1978 ;; We used to change buffers to get local value of vc-checkin-switches,
1979 ;; but 'the' local buffer is not a well-defined concept for filesets.
1980 (progn
1981 (vc-call checkin files rev comment)
1982 (mapc 'vc-delete-automatic-version-backups files))
a3255400
SM
1983 `((vc-state . up-to-date)
1984 (vc-checkout-time . ,(nth 5 (file-attributes file)))
ac3f4c6f 1985 (vc-working-revision . nil)))
d7b60083 1986 (message "Checking in %s...done" (vc-delistify files)))
0e362f54 1987 'vc-checkin-hook))
594722a8 1988
8c0aaf40 1989(defun vc-finish-logentry (&optional nocomment)
6f1ecae4
AS
1990 "Complete the operation implied by the current log entry.
1991Use the contents of the current buffer as a check-in or registration
1992comment. If the optional arg NOCOMMENT is non-nil, then don't check
11cdd167 1993the buffer contents as a comment."
594722a8 1994 (interactive)
8c0aaf40 1995 ;; Check and record the comment, if any.
0e362f54
GM
1996 (unless nocomment
1997 ;; Comment too long?
a7192ddb 1998 (vc-call-backend (or (if vc-log-fileset (vc-backend vc-log-fileset))
0e362f54
GM
1999 (vc-responsible-backend default-directory))
2000 'logentry-check)
11cdd167 2001 (run-hooks 'vc-logentry-check-hook))
b2396d1f 2002 ;; Sync parent buffer in case the user modified it while editing the comment.
cdaf7a1a 2003 ;; But not if it is a vc-dired buffer.
0e362f54 2004 (with-current-buffer vc-parent-buffer
76cdeb7d 2005 (or vc-dired-mode (eq major-mode 'vc-status-mode) (vc-buffer-sync)))
d6ba9c39
ER
2006 (if (not vc-log-operation)
2007 (error "No log operation is pending"))
61dee1e7
AS
2008 ;; save the parameters held in buffer-local variables
2009 (let ((log-operation vc-log-operation)
d7b60083 2010 (log-fileset vc-log-fileset)
ac3f4c6f 2011 (log-revision vc-log-revision)
61dee1e7 2012 (log-entry (buffer-string))
2c4eea90
KH
2013 (after-hook vc-log-after-operation-hook)
2014 (tmp-vc-parent-buffer vc-parent-buffer))
e2bef5c3 2015 (pop-to-buffer vc-parent-buffer)
61dee1e7
AS
2016 ;; OK, do it to it
2017 (save-excursion
0e362f54 2018 (funcall log-operation
d7b60083 2019 log-fileset
ac3f4c6f 2020 log-revision
61dee1e7 2021 log-entry))
df1e7b91
KH
2022 ;; Remove checkin window (after the checkin so that if that fails
2023 ;; we don't zap the *VC-log* buffer and the typing therein).
2024 (let ((logbuf (get-buffer "*VC-log*")))
2c4eea90
KH
2025 (cond ((and logbuf vc-delete-logbuf-window)
2026 (delete-windows-on logbuf (selected-frame))
262c8cea 2027 ;; Kill buffer and delete any other dedicated windows/frames.
2c4eea90 2028 (kill-buffer logbuf))
0ab66291
AS
2029 (logbuf (pop-to-buffer "*VC-log*")
2030 (bury-buffer)
2031 (pop-to-buffer tmp-vc-parent-buffer))))
e2bef5c3 2032 ;; Now make sure we see the expanded headers
d7b60083 2033 (if log-fileset
a7192ddb
SM
2034 (mapc
2035 (lambda (file) (vc-resynch-buffer file vc-keep-workfiles t))
d7b60083 2036 log-fileset))
76cdeb7d 2037 (if (or vc-dired-mode (eq major-mode 'vc-status-mode))
0ab66291 2038 (dired-move-to-filename))
37667a5c 2039 (run-hooks after-hook 'vc-finish-logentry-hook)))
594722a8 2040
2765044b
DN
2041;;; Additional entry points for examining version histories
2042
a7192ddb
SM
2043;; (defun vc-default-diff-tree (backend dir rev1 rev2)
2044;; "List differences for all registered files at and below DIR.
2045;; The meaning of REV1 and REV2 is the same as for `vc-revision-diff'."
2046;; ;; This implementation does an explicit tree walk, and calls
2047;; ;; vc-BACKEND-diff directly for each file. An optimization
2048;; ;; would be to use `vc-diff-internal', so that diffs can be local,
2049;; ;; and to call it only for files that are actually changed.
2050;; ;; However, this is expensive for some backends, and so it is left
2051;; ;; to backend-specific implementations.
2052;; (setq default-directory dir)
2053;; (vc-file-tree-walk
2054;; default-directory
2055;; (lambda (f)
2056;; (vc-exec-after
2057;; `(let ((coding-system-for-read (vc-coding-system-for-diff ',f)))
2058;; (message "Looking at %s" ',f)
2059;; (vc-call-backend ',(vc-backend f)
2060;; 'diff (list ',f) ',rev1 ',rev2))))))
2765044b
DN
2061
2062(defun vc-coding-system-for-diff (file)
2063 "Return the coding system for reading diff output for FILE."
2064 (or coding-system-for-read
2065 ;; if we already have this file open,
2066 ;; use the buffer's coding system
2067 (let ((buf (find-buffer-visiting file)))
2068 (if buf (with-current-buffer buf
2069 buffer-file-coding-system)))
2070 ;; otherwise, try to find one based on the file name
2071 (car (find-operation-coding-system 'insert-file-contents file))
2072 ;; and a final fallback
2073 'undecided))
2074
2075(defun vc-switches (backend op)
2076 (let ((switches
2077 (or (if backend
2078 (let ((sym (vc-make-backend-sym
2079 backend (intern (concat (symbol-name op)
2080 "-switches")))))
2081 (if (boundp sym) (symbol-value sym))))
2082 (let ((sym (intern (format "vc-%s-switches" (symbol-name op)))))
2083 (if (boundp sym) (symbol-value sym)))
2084 (cond
2085 ((eq op 'diff) diff-switches)))))
2086 (if (stringp switches) (list switches)
2087 ;; If not a list, return nil.
2088 ;; This is so we can set vc-diff-switches to t to override
2089 ;; any switches in diff-switches.
2090 (if (listp switches) switches))))
594722a8 2091
2765044b
DN
2092;; Old def for compatibility with Emacs-21.[123].
2093(defmacro vc-diff-switches-list (backend) `(vc-switches ',backend 'diff))
2094(make-obsolete 'vc-diff-switches-list 'vc-switches "22.1")
2095
1d5b2149 2096(defun vc-diff-finish (buffer messages)
17f3909f 2097 ;; The empty sync output case has already been handled, so the only
fddde1f0 2098 ;; possibility of an empty output is for an async process.
1d5b2149
TTN
2099 (when (buffer-live-p buffer)
2100 (let ((window (get-buffer-window buffer t))
2101 (emptyp (zerop (buffer-size buffer))))
2102 (with-current-buffer buffer
2103 (and messages emptyp
2104 (let ((inhibit-read-only t))
2105 (insert (cdr messages) ".\n")
2106 (message "%s" (cdr messages))))
2107 (goto-char (point-min))
fddde1f0 2108 (when window
1d5b2149
TTN
2109 (shrink-window-if-larger-than-buffer window)))
2110 (when (and messages (not emptyp))
2111 (message "%sdone" (car messages))))))
d7b60083 2112
a7192ddb
SM
2113(defvar vc-diff-added-files nil
2114 "If non-nil, diff added files by comparing them to /dev/null.")
2115
2116(defun vc-diff-internal (async files rev1 rev2 &optional verbose)
d7b60083
ER
2117 "Report diffs between two revisions of a fileset.
2118Diff output goes to the *vc-diff* buffer. The function
2119returns t if the buffer had changes, nil otherwise."
1d5b2149
TTN
2120 (let* ((messages (cons (format "Finding changes in %s..."
2121 (vc-delistify files))
2122 (format "No changes between %s and %s"
2123 (or rev1 "working revision")
2124 (or rev2 "workfile"))))
d7b60083
ER
2125 ;; Set coding system based on the first file. It's a kluge,
2126 ;; but the only way to set it for each file included would
2127 ;; be to call the back end separately for each file.
a7192ddb 2128 (coding-system-for-read
d7b60083
ER
2129 (if files (vc-coding-system-for-diff (car files)) 'undecided)))
2130 (vc-setup-buffer "*vc-diff*")
1d5b2149 2131 (message "%s" (car messages))
a7192ddb
SM
2132 ;; Many backends don't handle well the case of a file that has been
2133 ;; added but not yet committed to the repo (notably CVS and Subversion).
2134 ;; Do that work here so the backends don't have to futz with it. --ESR
2135 ;;
2136 ;; Actually most backends (including CVS) have options to control the
2137 ;; behavior since which one is better depends on the user and on the
2138 ;; situation). Worse yet: this code does not handle the case where
2139 ;; `file' is a directory which contains added files.
2140 ;; I made it conditional on vc-diff-added-files but it should probably
2141 ;; just be removed (or copied/moved to specific backends). --Stef.
2142 (when vc-diff-added-files
2143 (let ((filtered '()))
2144 (dolist (file files)
2145 (if (or (file-directory-p file)
2146 (not (string= (vc-working-revision file) "0")))
2147 (push file filtered)
2148 ;; This file is added but not yet committed;
2149 ;; there is no master file to diff against.
2150 (if (or rev1 rev2)
2151 (error "No revisions of %s exist" file)
2152 ;; We regard this as "changed".
2153 ;; Diff it against /dev/null.
2154 (apply 'vc-do-command "*vc-diff*"
2155 1 "diff" file
2156 (append (vc-switches nil 'diff) '("/dev/null"))))))
2157 (setq files (nreverse filtered))))
2158 (let ((vc-disable-async-diff (not async)))
2159 (vc-call diff files rev1 rev2 "*vc-diff*"))
d7b60083 2160 (set-buffer "*vc-diff*")
17f3909f
SM
2161 (if (and (zerop (buffer-size))
2162 (not (get-buffer-process (current-buffer))))
2163 ;; Treat this case specially so as not to pop the buffer.
2164 (progn
1d5b2149 2165 (message "%s" (cdr messages))
17f3909f 2166 nil)
e83d1fe8 2167 (diff-mode)
fe1919ab
DN
2168 ;; Make the *vc-diff* buffer read only, the diff-mode key
2169 ;; bindings are nicer for read only buffers. pcl-cvs does the
2170 ;; same thing.
2171 (setq buffer-read-only t)
1d5b2149
TTN
2172 (vc-exec-after `(vc-diff-finish ,(current-buffer) ',(when verbose
2173 messages)))
4befebc1
SM
2174 ;; Display the buffer, but at the end because it can change point.
2175 (pop-to-buffer (current-buffer))
17f3909f
SM
2176 ;; In the async case, we return t even if there are no differences
2177 ;; because we don't know that yet.
2178 t)))
594722a8 2179
637a8ae9 2180;;;###autoload
a7192ddb 2181(defun vc-version-diff (files rev1 rev2)
d7b60083 2182 "Report diffs between revisions of the fileset in the repository history."
0e362f54 2183 (interactive
d7b60083
ER
2184 (let* ((files (vc-deduce-fileset t))
2185 (first (car files))
d7b60083 2186 (completion-table
a7192ddb 2187 (vc-call revision-completion-table files))
d7b60083
ER
2188 (rev1-default nil)
2189 (rev2-default nil))
c0d66cb2 2190 (cond
ac3f4c6f 2191 ;; someday we may be able to do revision completion on non-singleton
d7b60083
ER
2192 ;; filesets, but not yet.
2193 ((/= (length files) 1)
2194 nil)
ac3f4c6f 2195 ;; if it's a directory, don't supply any revision default
d7b60083 2196 ((file-directory-p first)
c0d66cb2 2197 nil)
ac3f4c6f 2198 ;; if the file is not up-to-date, use working revision as older revision
d7b60083 2199 ((not (vc-up-to-date-p first))
ac3f4c6f
ER
2200 (setq rev1-default (vc-working-revision first)))
2201 ;; if the file is not locked, use last and previous revisions as defaults
c0d66cb2 2202 (t
ac3f4c6f
ER
2203 (setq rev1-default (vc-call previous-revision first
2204 (vc-working-revision first)))
c63f9a0e 2205 (if (string= rev1-default "") (setq rev1-default nil))
ac3f4c6f 2206 (setq rev2-default (vc-working-revision first))))
c0d66cb2 2207 ;; construct argument list
4d83a657 2208 (let* ((rev1-prompt (if rev1-default
ac3f4c6f 2209 (concat "Older revision (default "
4d83a657 2210 rev1-default "): ")
ac3f4c6f
ER
2211 "Older revision: "))
2212 (rev2-prompt (concat "Newer revision (default "
4d83a657
SM
2213 (or rev2-default "current source") "): "))
2214 (rev1 (if completion-table
2215 (completing-read rev1-prompt completion-table
d7b60083 2216 nil nil nil nil rev1-default)
4d83a657
SM
2217 (read-string rev1-prompt nil nil rev1-default)))
2218 (rev2 (if completion-table
2219 (completing-read rev2-prompt completion-table
d7b60083 2220 nil nil nil nil rev2-default)
4d83a657 2221 (read-string rev2-prompt nil nil rev2-default))))
d7b60083
ER
2222 (if (string= rev1 "") (setq rev1 nil))
2223 (if (string= rev2 "") (setq rev2 nil))
a7192ddb 2224 (list files rev1 rev2))))
d7b60083
ER
2225 (if (and (not rev1) rev2)
2226 (error "Not a valid revision range."))
a7192ddb 2227 (vc-diff-internal t files rev1 rev2 (interactive-p)))
d7b60083 2228
a7192ddb
SM
2229;; (defun vc-contains-version-controlled-file (dir)
2230;; "Return t if DIR contains a version-controlled file, nil otherwise."
2231;; (catch 'found
2232;; (mapc (lambda (f) (and (not (file-directory-p f)) (vc-backend f) (throw 'found 't))) (directory-files dir))
2233;; nil))
727c4443 2234
d7b60083 2235;;;###autoload
a7192ddb 2236(defun vc-diff (historic &optional not-urgent)
ac3f4c6f 2237 "Display diffs between file revisions.
727c4443 2238Normally this compares the currently selected fileset with their
a7192ddb 2239working revisions. With a prefix argument HISTORIC, it reads two revision
727c4443
ER
2240designators specifying which revisions to compare.
2241
2242If no current fileset is available (that is, we are not in
2243VC-Dired mode and the visited file of the current buffer is not
a7192ddb
SM
2244under version control) and we're in a Dired buffer, use
2245the current directory.
2246The optional argument NOT-URGENT non-nil means it is ok to say no to
2247saving the buffer."
2248 (interactive (list current-prefix-arg t))
2249 (if historic
2250 (call-interactively 'vc-version-diff)
2251 (let* ((files (vc-deduce-fileset t)))
2252 (if buffer-file-name (vc-buffer-sync not-urgent))
2253 (vc-diff-internal t files nil nil (interactive-p)))))
727c4443 2254
2c87edc1 2255
f1818994 2256;;;###autoload
ac3f4c6f
ER
2257(defun vc-revision-other-window (rev)
2258 "Visit revision REV of the current file in another window.
2259If the current file is named `F', the revision is named `F.~REV~'.
6f1ecae4 2260If `F.~REV~' already exists, use it instead of checking it out again."
4d83a657
SM
2261 (interactive
2262 (save-current-buffer
2263 (vc-ensure-vc-buffer)
2264 (let ((completion-table
2265 (vc-call revision-completion-table buffer-file-name))
ac3f4c6f 2266 (prompt "Revision to visit (default is working revision): "))
4d83a657
SM
2267 (list
2268 (if completion-table
2269 (completing-read prompt completion-table)
2270 (read-string prompt))))))
b6909007 2271 (vc-ensure-vc-buffer)
5e011cb2 2272 (let* ((file buffer-file-name)
ac3f4c6f
ER
2273 (revision (if (string-equal rev "")
2274 (vc-working-revision file)
ac0aae44 2275 rev)))
ac3f4c6f 2276 (switch-to-buffer-other-window (vc-find-revision file revision))))
ac0aae44 2277
ac3f4c6f
ER
2278(defun vc-find-revision (file revision)
2279 "Read REVISION of FILE into a buffer and return the buffer."
2280 (let ((automatic-backup (vc-version-backup-file-name file revision))
fd8160f7 2281 (filebuf (or (get-file-buffer file) (current-buffer)))
ac3f4c6f 2282 (filename (vc-version-backup-file-name file revision 'manual)))
fd8160f7 2283 (unless (file-exists-p filename)
10b48cc4 2284 (if (file-exists-p automatic-backup)
fd8160f7
SM
2285 (rename-file automatic-backup filename nil)
2286 (message "Checking out %s..." filename)
2287 (with-current-buffer filebuf
2288 (let ((failed t))
2289 (unwind-protect
2290 (let ((coding-system-for-read 'no-conversion)
2291 (coding-system-for-write 'no-conversion))
2292 (with-temp-file filename
2293 (let ((outbuf (current-buffer)))
2294 ;; Change buffer to get local value of
2295 ;; vc-checkout-switches.
2296 (with-current-buffer filebuf
ac3f4c6f 2297 (vc-call find-revision file revision outbuf))))
fd8160f7 2298 (setq failed nil))
48b43130
DN
2299 (when (and failed (file-exists-p filename))
2300 (delete-file filename))))
fd8160f7
SM
2301 (vc-mode-line file))
2302 (message "Checking out %s...done" filename)))
48b43130
DN
2303 (let ((result-buf (find-file-noselect filename)))
2304 (with-current-buffer result-buf
83f1f73b 2305 ;; Set the parent buffer so that things like
48b43130 2306 ;; C-x v g, C-x v l, ... etc work.
25a4ea6d 2307 (set (make-local-variable 'vc-parent-buffer) filebuf))
48b43130 2308 result-buf)))
fd8160f7 2309
594722a8
ER
2310;; Header-insertion code
2311
637a8ae9 2312;;;###autoload
594722a8 2313(defun vc-insert-headers ()
6f1ecae4 2314 "Insert headers into a file for use with a version control system.
b524ce9f 2315Headers desired are inserted at point, and are pulled from
0e362f54 2316the variable `vc-BACKEND-header'."
594722a8 2317 (interactive)
b6909007 2318 (vc-ensure-vc-buffer)
594722a8
ER
2319 (save-excursion
2320 (save-restriction
2321 (widen)
2322 (if (or (not (vc-check-headers))
820bde8d 2323 (y-or-n-p "Version headers already exist. Insert another set? "))
04864eb0
SM
2324 (let* ((delims (cdr (assq major-mode vc-comment-alist)))
2325 (comment-start-vc (or (car delims) comment-start "#"))
2326 (comment-end-vc (or (car (cdr delims)) comment-end ""))
2327 (hdsym (vc-make-backend-sym (vc-backend buffer-file-name)
2328 'header))
2329 (hdstrings (and (boundp hdsym) (symbol-value hdsym))))
2330 (dolist (s hdstrings)
2331 (insert comment-start-vc "\t" s "\t"
2332 comment-end-vc "\n"))
2333 (if vc-static-header-alist
2334 (dolist (f vc-static-header-alist)
2335 (if (string-match (car f) buffer-file-name)
2336 (insert (format (cdr f) (car hdstrings)))))))))))
594722a8 2337
0e362f54 2338(defun vc-clear-headers (&optional file)
099bd78a 2339 "Clear all version headers in the current buffer (or FILE).
6f1ecae4 2340The headers are reset to their non-expanded form."
0e362f54
GM
2341 (let* ((filename (or file buffer-file-name))
2342 (visited (find-buffer-visiting filename))
2343 (backend (vc-backend filename)))
2344 (when (vc-find-backend-function backend 'clear-headers)
6f41eeb5 2345 (if visited
0e362f54
GM
2346 (let ((context (vc-buffer-context)))
2347 ;; save-excursion may be able to relocate point and mark
2348 ;; properly. If it fails, vc-restore-buffer-context
2349 ;; will give it a second try.
2350 (save-excursion
2351 (vc-call-backend backend 'clear-headers))
2352 (vc-restore-buffer-context context))
7849e179 2353 (set-buffer (find-file-noselect filename))
0e362f54
GM
2354 (vc-call-backend backend 'clear-headers)
2355 (kill-buffer filename)))))
c8de1d91 2356
9b64a7f0
ER
2357(defun vc-modify-change-comment (files rev oldcomment)
2358 "Edit the comment associated with the given files and revision."
2359 (vc-start-entry
2360 files rev oldcomment t
2361 "Enter a replacement change comment."
2362 (lambda (files rev comment)
df49d02e 2363 (vc-call-backend
9b64a7f0
ER
2364 ;; Less of a kluge than it looks like; log-view mode only passes
2365 ;; this function a singleton list. Arguments left in this form in
df49d02e
JB
2366 ;; case the more general operation ever becomes meaningful.
2367 (vc-responsible-backend (car files))
9b64a7f0
ER
2368 'modify-change-comment files rev comment))))
2369
b6909007 2370;;;###autoload
099bd78a 2371(defun vc-merge ()
ac3f4c6f
ER
2372 "Merge changes between two revisions into the current buffer's file.
2373This asks for two revisions to merge from in the minibuffer. If the
2374first revision is a branch number, then merge all changes from that
2375branch. If the first revision is empty, merge news, i.e. recent changes
099bd78a 2376from the current branch.
0e362f54
GM
2377
2378See Info node `Merging'."
099bd78a 2379 (interactive)
ccb141e8
AS
2380 (vc-ensure-vc-buffer)
2381 (vc-buffer-sync)
2382 (let* ((file buffer-file-name)
2383 (backend (vc-backend file))
0e362f54 2384 (state (vc-state file))
ac3f4c6f 2385 first-revision second-revision status)
0e362f54 2386 (cond
61de26cb 2387 ((stringp state) ;; Locking VCses only
0e362f54
GM
2388 (error "File is locked by %s" state))
2389 ((not (vc-editable-p file))
2390 (if (y-or-n-p
2391 "File must be checked out for merging. Check out now? ")
2392 (vc-checkout file t)
2393 (error "Merge aborted"))))
ac3f4c6f
ER
2394 (setq first-revision
2395 (read-string (concat "Branch or revision to merge from "
5b76833f 2396 "(default news on current branch): ")))
ac3f4c6f 2397 (if (string= first-revision "")
099bd78a
SM
2398 (if (not (vc-find-backend-function backend 'merge-news))
2399 (error "Sorry, merging news is not implemented for %s" backend)
2400 (setq status (vc-call merge-news file)))
2401 (if (not (vc-find-backend-function backend 'merge))
2402 (error "Sorry, merging is not implemented for %s" backend)
ac3f4c6f
ER
2403 (if (not (vc-branch-p first-revision))
2404 (setq second-revision
2405 (read-string "Second revision: "
2406 (concat (vc-branch-part first-revision) ".")))
2407 ;; We want to merge an entire branch. Set revisions
099bd78a 2408 ;; accordingly, so that vc-BACKEND-merge understands us.
ac3f4c6f
ER
2409 (setq second-revision first-revision)
2410 ;; first-revision must be the starting point of the branch
2411 (setq first-revision (vc-branch-part first-revision)))
2412 (setq status (vc-call merge file first-revision second-revision))))
099bd78a 2413 (vc-maybe-resolve-conflicts file status "WORKFILE" "MERGE SOURCE")))
0e362f54
GM
2414
2415(defun vc-maybe-resolve-conflicts (file status &optional name-A name-B)
2416 (vc-resynch-buffer file t (not (buffer-modified-p)))
2417 (if (zerop status) (message "Merge successful")
28e4e2b4 2418 (smerge-mode 1)
8dc87047 2419 (message "File contains conflicts.")))
ccb141e8
AS
2420
2421;;;###autoload
1168d6c2 2422(defalias 'vc-resolve-conflicts 'smerge-ediff)
18483cf0 2423
2f119435 2424;; The VC directory major mode. Coopt Dired for this.
e1f297e6
ER
2425;; All VC commands get mapped into logical equivalents.
2426
beba4bd9
AS
2427(defvar vc-dired-switches)
2428(defvar vc-dired-terse-mode)
2429
0e362f54
GM
2430(defvar vc-dired-mode-map
2431 (let ((map (make-sparse-keymap))
2432 (vmap (make-sparse-keymap)))
ec402ad4 2433 (define-key map "\C-xv" vmap)
0e362f54 2434 (define-key map "v" vmap)
ec402ad4 2435 (set-keymap-parent vmap vc-prefix-map)
0e362f54
GM
2436 (define-key vmap "t" 'vc-dired-toggle-terse-mode)
2437 map))
2438
3827b532 2439(define-derived-mode vc-dired-mode dired-mode "Dired under "
0e362f54
GM
2440 "The major mode used in VC directory buffers.
2441
2442It works like Dired, but lists only files under version control, with
2443the current VC state of each file being indicated in the place of the
2444file's link count, owner, group and size. Subdirectories are also
2445listed, and you may insert them into the buffer as desired, like in
2446Dired.
2447
2448All Dired commands operate normally, with the exception of `v', which
2449is redefined as the version control prefix, so that you can type
3d30b8bc
RS
2450`vl', `v=' etc. to invoke `vc-print-log', `vc-diff', and the like on
2451the file named in the current Dired buffer line. `vv' invokes
2452`vc-next-action' on this file, or on all files currently marked.
2453There is a special command, `*l', to mark all files currently locked."
099bd78a
SM
2454 ;; define-derived-mode does it for us in Emacs-21, but not in Emacs-20.
2455 ;; We do it here because dired might not be loaded yet
2456 ;; when vc-dired-mode-map is initialized.
2457 (set-keymap-parent vc-dired-mode-map dired-mode-map)
421f0bfe 2458 (add-hook 'dired-after-readin-hook 'vc-dired-hook nil t)
9bc260cf 2459 ;; The following is slightly modified from files.el,
62c2e775
AS
2460 ;; because file lines look a bit different in vc-dired-mode
2461 ;; (the column before the date does not end in a digit).
ead91593
MA
2462 ;; albinus: It should be done in the original declaration. Problem
2463 ;; is the optional empty state-info; otherwise ")" would be good
2464 ;; enough as delimeter.
9bc260cf 2465 (set (make-local-variable 'directory-listing-before-filename-regexp)
62c2e775 2466 (let* ((l "\\([A-Za-z]\\|[^\0-\177]\\)")
570050dc
AS
2467 ;; In some locales, month abbreviations are as short as 2 letters,
2468 ;; and they can be followed by ".".
2469 (month (concat l l "+\\.?"))
2470 (s " ")
2471 (yyyy "[0-9][0-9][0-9][0-9]")
2472 (dd "[ 0-3][0-9]")
2473 (HH:MM "[ 0-2][0-9]:[0-5][0-9]")
2474 (seconds "[0-6][0-9]\\([.,][0-9]+\\)?")
2475 (zone "[-+][0-2][0-9][0-5][0-9]")
2476 (iso-mm-dd "[01][0-9]-[0-3][0-9]")
2477 (iso-time (concat HH:MM "\\(:" seconds "\\( ?" zone "\\)?\\)?"))
2478 (iso (concat "\\(\\(" yyyy "-\\)?" iso-mm-dd "[ T]" iso-time
2479 "\\|" yyyy "-" iso-mm-dd "\\)"))
2480 (western (concat "\\(" month s "+" dd "\\|" dd "\\.?" s month "\\)"
2481 s "+"
2482 "\\(" HH:MM "\\|" yyyy "\\)"))
2483 (western-comma (concat month s "+" dd "," s "+" yyyy))
2484 ;; Japanese MS-Windows ls-lisp has one-digit months, and
2485 ;; omits the Kanji characters after month and day-of-month.
2486 (mm "[ 0-1]?[0-9]")
2487 (japanese
2488 (concat mm l "?" s dd l "?" s "+"
2489 "\\(" HH:MM "\\|" yyyy l "?" "\\)")))
2490 ;; the .* below ensures that we find the last match on a line
62c2e775 2491 (concat ".*" s
570050dc
AS
2492 "\\(" western "\\|" western-comma "\\|" japanese "\\|" iso "\\)"
2493 s "+")))
a0019b45
AS
2494 (and (boundp 'vc-dired-switches)
2495 vc-dired-switches
2496 (set (make-local-variable 'dired-actual-switches)
2497 vc-dired-switches))
3b574573 2498 (set (make-local-variable 'vc-dired-terse-mode) vc-dired-terse-display)
9d2aebf6
MY
2499 (let ((backend-name (symbol-name (vc-responsible-backend
2500 default-directory))))
2501 (setq mode-name (concat mode-name backend-name))
2502 ;; Add menu after `vc-dired-mode-map' has `dired-mode-map' as the parent.
2503 (let ((vc-dire-menu-map (copy-keymap vc-menu-map)))
a7192ddb 2504 (define-key-after (lookup-key vc-dired-mode-map [menu-bar]) [vc]
9d2aebf6 2505 (cons backend-name vc-dire-menu-map) 'subdir)))
2f119435
AS
2506 (setq vc-dired-mode t))
2507
3b574573
AS
2508(defun vc-dired-toggle-terse-mode ()
2509 "Toggle terse display in VC Dired."
2510 (interactive)
2511 (if (not vc-dired-mode)
2512 nil
2513 (setq vc-dired-terse-mode (not vc-dired-terse-mode))
2514 (if vc-dired-terse-mode
2515 (vc-dired-hook)
2516 (revert-buffer))))
2517
3d30b8bc
RS
2518(defun vc-dired-mark-locked ()
2519 "Mark all files currently locked."
2520 (interactive)
2521 (dired-mark-if (let ((f (dired-get-filename nil t)))
2522 (and f
2523 (not (file-directory-p f))
0e362f54 2524 (not (vc-up-to-date-p f))))
3d30b8bc
RS
2525 "locked file"))
2526
2527(define-key vc-dired-mode-map "*l" 'vc-dired-mark-locked)
2528
b9a35ba5 2529(defun vc-dired-reformat-line (vc-info)
0e362f54 2530 "Reformat a directory-listing line.
b9a35ba5 2531Replace various columns with version control information, VC-INFO.
0e362f54 2532This code, like dired, assumes UNIX -l format."
3d30b8bc 2533 (beginning-of-line)
f1180544 2534 (when (re-search-forward
685e7bca
AS
2535 ;; Match link count, owner, group, size. Group may be missing,
2536 ;; and only the size is present in OS/2 -l format.
2537 "^..[drwxlts-]+ \\( *[0-9]+\\( [^ ]+ +\\([^ ]+ +\\)?[0-9]+\\)?\\) "
2538 (line-end-position) t)
2539 (replace-match (substring (concat vc-info " ") 0 10)
2540 t t nil 1)))
3d30b8bc 2541
35d33ce7
ER
2542(defun vc-dired-ignorable-p (filename)
2543 "Should FILENAME be ignored in VC-Dired listings?"
df49d02e 2544 (catch t
9580f1fd 2545 ;; Ignore anything that wouldn't be found by completion (.o, .la, etc.)
35d33ce7 2546 (dolist (ignorable completion-ignored-extensions)
df49d02e 2547 (let ((ext (substring filename
35d33ce7
ER
2548 (- (length filename)
2549 (length ignorable)))))
2550 (if (string= ignorable ext) (throw t t))))
9580f1fd
ER
2551 ;; Ignore Makefiles derived from something else
2552 (when (string= (file-name-nondirectory filename) "Makefile")
2553 (let* ((dir (file-name-directory filename))
2554 (peers (directory-files (or dir default-directory))))
2555 (if (or (member "Makefile.in" peers) (member "Makefile.am" peers))
2556 (throw t t))))
35d33ce7
ER
2557 nil))
2558
3d30b8bc 2559(defun vc-dired-hook ()
0e362f54
GM
2560 "Reformat the listing according to version control.
2561Called by dired after any portion of a vc-dired buffer has been read in."
3d30b8bc 2562 (message "Getting version information... ")
cdce374a
ER
2563 ;; if the backend supports it, get the state
2564 ;; of all files in this directory at once
2565 (let ((backend (vc-responsible-backend default-directory)))
2566 ;; check `backend' can really handle `default-directory'.
2567 (if (and (vc-call-backend backend 'responsible-p default-directory)
2568 (vc-find-backend-function backend 'dir-state))
2569 (vc-call-backend backend 'dir-state default-directory)))
df49d02e 2570 (let (filename
484c1b1f
ER
2571 (inhibit-read-only t)
2572 (buffer-undo-list t))
3d30b8bc 2573 (goto-char (point-min))
0e362f54
GM
2574 (while (not (eobp))
2575 (cond
3d30b8bc 2576 ;; subdir header line
cdce374a 2577 ((dired-get-subdir)
3d30b8bc
RS
2578 (forward-line 1)
2579 ;; erase (but don't remove) the "total" line
0e362f54
GM
2580 (delete-region (point) (line-end-position))
2581 (beginning-of-line)
2582 (forward-line 1))
2583 ;; file line
3d30b8bc
RS
2584 ((setq filename (dired-get-filename nil t))
2585 (cond
3b574573 2586 ;; subdir
3d30b8bc 2587 ((file-directory-p filename)
0e362f54
GM
2588 (cond
2589 ((member (file-name-nondirectory filename)
3b574573
AS
2590 vc-directory-exclusion-list)
2591 (let ((pos (point)))
2592 (dired-kill-tree filename)
2593 (goto-char pos)
2594 (dired-kill-line)))
2595 (vc-dired-terse-mode
633cee46
AS
2596 ;; Don't show directories in terse mode. Don't use
2597 ;; dired-kill-line to remove it, because in recursive listings,
2598 ;; that would remove the directory contents as well.
0e362f54 2599 (delete-region (line-beginning-position)
633cee46 2600 (progn (forward-line 1) (point))))
3b574573
AS
2601 ((string-match "\\`\\.\\.?\\'" (file-name-nondirectory filename))
2602 (dired-kill-line))
2603 (t
3d30b8bc 2604 (vc-dired-reformat-line nil)
3b574573 2605 (forward-line 1))))
c59a2442 2606 ;; Try to head off calling the expensive state query -
35d33ce7
ER
2607 ;; ignore object files, TeX intermediate files, and so forth.
2608 ((vc-dired-ignorable-p filename)
2609 (dired-kill-line))
c59a2442
ER
2610 ;; Ordinary file -- call the (possibly expensive) state query
2611 ;;
2612 ;; First case: unregistered or unknown. (Unknown shouldn't happen here)
2613 ((member (vc-state filename) '(nil unregistered))
2614 (if vc-dired-terse-mode
2615 (dired-kill-line)
2616 (vc-dired-reformat-line "?")
2617 (forward-line 1)))
df49d02e 2618 ;; Either we're in non-terse mode or it's out of date
c59a2442
ER
2619 ((not (and vc-dired-terse-mode (vc-up-to-date-p filename)))
2620 (vc-dired-reformat-line (vc-call dired-state-info filename))
2621 (forward-line 1))
df49d02e
JB
2622 ;; Remaining cases are under version control but uninteresting
2623 (t
c59a2442 2624 (dired-kill-line))))
3d30b8bc 2625 ;; any other line
3b574573
AS
2626 (t (forward-line 1))))
2627 (vc-dired-purge))
2628 (message "Getting version information... done")
2629 (save-restriction
2630 (widen)
633cee46
AS
2631 (cond ((eq (count-lines (point-min) (point-max)) 1)
2632 (goto-char (point-min))
9580f1fd 2633 (message "No changes pending under %s" default-directory)))))
3b574573
AS
2634
2635(defun vc-dired-purge ()
0e362f54 2636 "Remove empty subdirs."
b4e4e3a8
SM
2637 (goto-char (point-min))
2638 (while (dired-get-subdir)
2639 (forward-line 2)
2640 (if (dired-get-filename nil t)
2641 (if (not (dired-next-subdir 1 t))
2642 (goto-char (point-max)))
2643 (forward-line -2)
2644 (if (not (string= (dired-current-directory) default-directory))
2645 (dired-do-kill-lines t "")
2646 ;; We cannot remove the top level directory.
2647 ;; Just make it look a little nicer.
2648 (forward-line 1)
3c85843f 2649 (or (eobp) (kill-line))
b4e4e3a8
SM
2650 (if (not (dired-next-subdir 1 t))
2651 (goto-char (point-max))))))
2652 (goto-char (point-min)))
2f119435 2653
0e362f54
GM
2654(defun vc-dired-buffers-for-dir (dir)
2655 "Return a list of all vc-dired buffers that currently display DIR."
2656 (let (result)
099bd78a
SM
2657 ;; Check whether dired is loaded.
2658 (when (fboundp 'dired-buffers-for-dir)
a7192ddb
SM
2659 (dolist (buffer (dired-buffers-for-dir dir))
2660 (with-current-buffer buffer
2661 (if vc-dired-mode
2662 (push buffer result)))))
2663 (nreverse result)))
0e362f54
GM
2664
2665(defun vc-dired-resynch-file (file)
2666 "Update the entries for FILE in any VC Dired buffers that list it."
2667 (let ((buffers (vc-dired-buffers-for-dir (file-name-directory file))))
2668 (when buffers
2669 (mapcar (lambda (buffer)
2670 (with-current-buffer buffer
2671 (if (dired-goto-file file)
2672 ;; bind vc-dired-terse-mode to nil so that
2673 ;; files won't vanish when they are checked in
2674 (let ((vc-dired-terse-mode nil))
2675 (dired-do-redisplay 1)))))
2676 buffers))))
2677
637a8ae9 2678;;;###autoload
0e362f54
GM
2679(defun vc-directory (dir read-switches)
2680 "Create a buffer in VC Dired Mode for directory DIR.
2681
2682See Info node `VC Dired Mode'.
2683
2684With prefix arg READ-SWITCHES, specify a value to override
2685`dired-listing-switches' when generating the listing."
2f119435 2686 (interactive "DDired under VC (directory): \nP")
0e362f54 2687 (let ((vc-dired-switches (concat vc-dired-listing-switches
3b574573 2688 (if vc-dired-recurse "R" ""))))
0e362f54 2689 (if read-switches
3b574573
AS
2690 (setq vc-dired-switches
2691 (read-string "Dired listing switches: "
2692 vc-dired-switches)))
3d30b8bc
RS
2693 (require 'dired)
2694 (require 'dired-aux)
0e362f54
GM
2695 (switch-to-buffer
2696 (dired-internal-noselect (expand-file-name (file-name-as-directory dir))
2697 vc-dired-switches
3d30b8bc 2698 'vc-dired-mode))))
e70bdc98 2699
7fbb4797 2700;; VC status implementation
5a84a937
DN
2701
2702;; Used to store information for the files displayed in the *VC status* buffer.
2703;; Each item displayed corresponds to one of these defstructs.
8fcaf22f
DN
2704(defstruct (vc-status-fileinfo
2705 (:copier nil)
c1b51374 2706 (:type list) ;So we can use `member' on lists of FIs.
58f10bff 2707 (:constructor
c1b51374
SM
2708 ;; We could define it as an alias for `list'.
2709 vc-status-create-fileinfo (name state &optional extra marked))
8fcaf22f 2710 (:conc-name vc-status-fileinfo->))
c1b51374 2711 name ;Keep it as first, for `member'.
8fcaf22f 2712 state
58f10bff 2713 ;; For storing backend specific information.
c1b51374 2714 extra
fb0ac090
AJ
2715 marked
2716 ;; To keep track of not updated files during a global refresh
e8847be3
DN
2717 needs-update
2718 ;; To distinguish files and directories.
2719 directoryp)
8fcaf22f
DN
2720
2721(defvar vc-status nil)
2722
15c5c970 2723(defun vc-default-status-extra-headers (backend dir)
5a84a937
DN
2724 ;; Be loud by default to remind people to add coded to display
2725 ;; backend specific headers.
2726 ;; XXX: change this to return nil before the release.
15c5c970
DN
2727 "Extra : Add backend specific headers here")
2728
ca8dfeda 2729(defun vc-status-headers (backend dir)
5a84a937
DN
2730 "Display the headers in the *VC status* buffer.
2731It calls the `status-extra-headers' backend method to display backend
2732specific headers."
ca8dfeda 2733 (concat
15c5c970
DN
2734 (propertize "VC backend : " 'face 'font-lock-type-face)
2735 (propertize (format "%s\n" backend) 'face 'font-lock-variable-name-face)
2736 (propertize "Working dir: " 'face 'font-lock-type-face)
2737 (propertize (format "%s\n" dir) 'face 'font-lock-variable-name-face)
2738 (vc-call-backend backend 'status-extra-headers dir)
2739 "\n"))
8fcaf22f 2740
58f10bff 2741(defun vc-default-status-printer (backend fileentry)
8fcaf22f 2742 "Pretty print FILEENTRY."
e8847be3
DN
2743 (if (vc-status-fileinfo->directoryp fileentry)
2744 (insert " Directory: %s" (vc-status-fileinfo->name fileentry))
2745 ;; If you change the layout here, change vc-status-move-to-goal-column.
2746 (let ((state (vc-status-fileinfo->state fileentry)))
2747 (insert
2748 (propertize
2749 (format "%c" (if (vc-status-fileinfo->marked fileentry) ?* ? ))
2750 'face 'font-lock-type-face)
2751 " "
2752 (propertize
2753 (format "%-20s" state)
2754 'face (cond ((eq state 'up-to-date) 'font-lock-builtin-face)
2755 ((memq state '(missing conflict)) 'font-lock-warning-face)
2756 (t 'font-lock-variable-name-face))
2757 'mouse-face 'highlight)
2758 " "
2759 (propertize
2760 (format "%s" (vc-status-fileinfo->name fileentry))
2761 'face 'font-lock-function-name-face
2762 'mouse-face 'highlight)))))
8fcaf22f 2763
58f10bff
DN
2764(defun vc-status-printer (fileentry)
2765 (let ((backend (vc-responsible-backend default-directory)))
2766 (vc-call-backend backend 'status-printer fileentry)))
2767
ca8dfeda 2768(defun vc-status-move-to-goal-column ()
5a84a937 2769 ;; Used to keep the cursor on the file name column.
ca8dfeda 2770 (beginning-of-line)
58f10bff 2771 ;; Must be in sync with vc-default-status-printer.
ca8dfeda
DN
2772 (forward-char 25))
2773
e9e065e5
DN
2774(defun vc-status-prepare-status-buffer (dir &optional create-new)
2775 "Find a *vc-status* buffer showing DIR, or create a new one."
2776 (setq dir (expand-file-name dir))
d39730b8
DN
2777 (let* ((bname "*vc-status*")
2778 ;; Look for another *vc-status* buffer visiting the same directory.
2779 (buf (save-excursion
2780 (unless create-new
2781 (dolist (buffer (buffer-list))
2782 (set-buffer buffer)
2783 (when (and (eq major-mode 'vc-status-mode)
2784 (string= (expand-file-name default-directory) dir))
2785 (return buffer)))))))
2786 (if buf
2787 buf
2788 ;; Create a new *vc-status* buffer.
2789 (with-current-buffer (create-file-buffer bname)
2790 (cd dir)
2791 (vc-setup-buffer (current-buffer))
4dc22208
DN
2792 ;; Reset the vc-parent-buffer-name so that it does not appear
2793 ;; in the mode-line.
2794 (setq vc-parent-buffer-name nil)
d39730b8 2795 (current-buffer)))))
e9e065e5 2796
e166638d 2797;;;###autoload
8fcaf22f
DN
2798(defun vc-status (dir)
2799 "Show the VC status for DIR."
2800 (interactive "DVC status for directory: ")
e9e065e5 2801 (switch-to-buffer (vc-status-prepare-status-buffer dir))
d39730b8
DN
2802 (if (eq major-mode 'vc-status-mode)
2803 (vc-status-refresh)
2804 (vc-status-mode)))
8fcaf22f 2805
25a4ea6d
DN
2806(defvar vc-status-menu-map
2807 (let ((map (make-sparse-keymap "VC-status")))
d39730b8 2808 (define-key map [quit]
25a4ea6d
DN
2809 '(menu-item "Quit" bury-buffer
2810 :help "Quit"))
d39730b8
DN
2811 (define-key map [kill]
2812 '(menu-item "Kill Update Command" vc-status-kill-dir-status-process
c1b51374 2813 :enable (vc-status-busy)
d39730b8
DN
2814 :help "Kill the command that updates VC status buffer"))
2815 (define-key map [refresh]
25a4ea6d 2816 '(menu-item "Refresh" vc-status-refresh
c1b51374 2817 :enable (not (vc-status-busy))
25a4ea6d 2818 :help "Refresh the contents of the VC status buffer"))
d39730b8 2819 (define-key map [remup]
d6f47dff
DN
2820 '(menu-item "Hide up-to-date" vc-status-hide-up-to-date
2821 :help "Hide up-to-date items from display"))
25a4ea6d 2822 ;; Movement.
115c0061 2823 (define-key map [sepmv] '("--"))
d39730b8 2824 (define-key map [next-line]
25a4ea6d
DN
2825 '(menu-item "Next line" vc-status-next-line
2826 :help "Go to the next line" :keys "n"))
d39730b8 2827 (define-key map [previous-line]
25a4ea6d
DN
2828 '(menu-item "Previous line" vc-status-previous-line
2829 :help "Go to the previous line"))
2830 ;; Marking.
115c0061 2831 (define-key map [sepmrk] '("--"))
d39730b8 2832 (define-key map [unmark-all]
25a4ea6d
DN
2833 '(menu-item "Unmark All" vc-status-unmark-all-files
2834 :help "Unmark all files that are in the same state as the current file\
2835\nWith prefix argument unmark all files"))
d39730b8 2836 (define-key map [unmark-previous]
25a4ea6d
DN
2837 '(menu-item "Unmark previous " vc-status-unmark-file-up
2838 :help "Move to the previous line and unmark the file"))
2839
d39730b8 2840 (define-key map [mark-all]
64db3a90 2841 '(menu-item "Mark All" vc-status-mark-all-files
25a4ea6d
DN
2842 :help "Mark all files that are in the same state as the current file\
2843\nWith prefix argument mark all files"))
d39730b8 2844 (define-key map [unmark]
25a4ea6d
DN
2845 '(menu-item "Unmark" vc-status-unmark
2846 :help "Unmark the current file or all files in the region"))
2847
d39730b8 2848 (define-key map [mark]
25a4ea6d 2849 '(menu-item "Mark" vc-status-mark
64db3a90 2850 :help "Mark the current file or all files in the region"))
25a4ea6d 2851
115c0061 2852 (define-key map [sepopn] '("--"))
d39730b8 2853 (define-key map [open-other]
25a4ea6d
DN
2854 '(menu-item "Open in other window" vc-status-find-file-other-window
2855 :help "Find the file on the current line, in another window"))
d39730b8 2856 (define-key map [open]
25a4ea6d
DN
2857 '(menu-item "Open file" vc-status-find-file
2858 :help "Find the file on the current line"))
9eef6650
DN
2859 ;; VC info details
2860 (define-key map [sepvcdet] '("--"))
2861 ;; FIXME: This needs a key binding. And maybe a better name
2862 ;; ("Insert" like PCL-CVS uses does not sound that great either)...
2863 (define-key map [ins]
2864 '(menu-item "Show File" vc-status-show-fileentry
2865 :help "Show a file in the VC status listing even though it might be up to date"))
2866 (define-key map [annotate]
2867 '(menu-item "Annotate" vc-annotate
2868 :help "Display the edit history of the current file using colors"))
2869 (define-key map [diff]
2870 '(menu-item "Compare with Base Version" vc-diff
2871 :help "Compare file set with the base version"))
2872 (define-key map [log]
2873 '(menu-item "Show history" vc-print-log
2874 :help "List the change log of the current file set in a window"))
2875 ;; VC commands.
2876 (define-key map [sepvccmd] '("--"))
2877 (define-key map [update]
2878 '(menu-item "Update to latest version" vc-update
2879 :help "Update the current fileset's files to their tip revisions"))
2880 (define-key map [revert]
2881 '(menu-item "Revert to base version" vc-revert
2882 :help "Revert working copies of the selected fileset to their repository contents."))
2883 (define-key map [next-action]
2884 ;; FIXME: This really really really needs a better name!
2885 ;; And a key binding too.
2886 '(menu-item "Check In/Out" vc-next-action
2887 :help "Do the next logical version control operation on the current fileset"))
2888 (define-key map [register]
2889 '(menu-item "Register" vc-status-register
2890 :help "Register file set into the version control system"))
25a4ea6d
DN
2891 map)
2892 "Menu for VC status")
2893
2894(defalias 'vc-status-menu-map vc-status-menu-map)
2895
d048f3bf 2896(defvar vc-status-mode-map
ca8dfeda
DN
2897 (let ((map (make-keymap)))
2898 (suppress-keymap map)
2899 ;; Marking.
8bb38e87 2900 (define-key map "m" 'vc-status-mark)
b6fe5b19 2901 (define-key map "M" 'vc-status-mark-all-files)
8bb38e87 2902 (define-key map "u" 'vc-status-unmark)
ca8dfeda 2903 (define-key map "\C-?" 'vc-status-unmark-file-up)
b6fe5b19 2904 (define-key map "\M-\C-?" 'vc-status-unmark-all-files)
ca8dfeda
DN
2905 ;; Movement.
2906 (define-key map "n" 'vc-status-next-line)
2907 (define-key map " " 'vc-status-next-line)
2908 (define-key map "\t" 'vc-status-next-line)
2909 (define-key map "p" 'vc-status-previous-line)
2910 (define-key map [backtab] 'vc-status-previous-line)
2911 ;; VC commands.
115c0061 2912 (define-key map "=" 'vc-diff) ;; C-x v =
ca8dfeda 2913 (define-key map "a" 'vc-status-register)
115c0061 2914 (define-key map "+" 'vc-update) ;; C-x v +
5a84a937
DN
2915
2916 ;;XXX: Maybe use something else here, so we can use 'U' for unmark
2917 ;;all, similar to 'M'..
115c0061 2918 (define-key map "U" 'vc-revert) ;; u is taken by unmark.
5a84a937 2919
ca8dfeda
DN
2920 ;; Can't be "g" (as in vc map), so "A" for "Annotate".
2921 (define-key map "A" 'vc-annotate)
115c0061 2922 (define-key map "l" 'vc-print-log) ;; C-x v l
ca8dfeda
DN
2923 ;; The remainder.
2924 (define-key map "f" 'vc-status-find-file)
d6f47dff 2925 (define-key map "\C-m" 'vc-status-find-file)
ca8dfeda 2926 (define-key map "o" 'vc-status-find-file-other-window)
d6f47dff 2927 (define-key map "x" 'vc-status-hide-up-to-date)
ca8dfeda
DN
2928 (define-key map "q" 'bury-buffer)
2929 (define-key map "g" 'vc-status-refresh)
751c9f00 2930 (define-key map "\C-c\C-c" 'vc-status-kill-dir-status-process)
6656ecaa
DN
2931 ;; Not working yet. Functions like vc-status-find-file need to
2932 ;; find the file from the mouse position, not `point'.
2933 ;; (define-key map [(down-mouse-3)] 'vc-status-menu)
25a4ea6d
DN
2934
2935 ;; Hook up the menu.
2936 (define-key map [menu-bar vc-status-mode]
2937 '(menu-item
2938 ;; This is used to that VC backends could add backend specific
2939 ;; menu items to vc-status-menu-map.
2940 "VC Status" vc-status-menu-map :filter vc-status-menu-map-filter))
8fcaf22f
DN
2941 map)
2942 "Keymap for VC status")
2943
7ee8e7eb
DN
2944(defun vc-default-extra-status-menu (backend)
2945 nil)
2946
5a84a937
DN
2947;; This is used to that VC backends could add backend specific menu
2948;; items to vc-status-menu-map.
6656ecaa 2949(defun vc-status-menu-map-filter (orig-binding)
d39730b8
DN
2950 (when (and (symbolp orig-binding) (fboundp orig-binding))
2951 (setq orig-binding (indirect-function orig-binding)))
2952 (let ((ext-binding
2953 (vc-call-backend (vc-responsible-backend default-directory)
2954 'extra-status-menu)))
2955 (if (null ext-binding)
2956 orig-binding
2957 (append orig-binding
2958 '("----")
2959 ext-binding))))
6656ecaa 2960
6656ecaa
DN
2961(defun vc-status-menu (e)
2962 "Popup the VC status menu."
2963 (interactive "e")
25a4ea6d 2964 (popup-menu vc-status-menu-map e))
6656ecaa 2965
934b91bf 2966(defvar vc-status-tool-bar-map
d39730b8
DN
2967 (let ((map (make-sparse-keymap)))
2968 (tool-bar-local-item-from-menu 'vc-status-find-file "open"
2969 map vc-status-mode-map)
2970 (tool-bar-local-item "bookmark_add"
2971 'vc-status-toggle-mark 'vc-status-toggle-mark map
2972 :help "Toggle mark on current item")
2973 (tool-bar-local-item-from-menu 'vc-status-previous-line "left-arrow"
2974 map vc-status-mode-map
2975 :rtl "right-arrow")
2976 (tool-bar-local-item-from-menu 'vc-status-next-line "right-arrow"
2977 map vc-status-mode-map
2978 :rtl "left-arrow")
44a17812
JD
2979 (tool-bar-local-item-from-menu 'vc-print-log "info"
2980 map vc-status-mode-map)
d39730b8
DN
2981 (tool-bar-local-item-from-menu 'vc-status-refresh "refresh"
2982 map vc-status-mode-map)
2983 (tool-bar-local-item-from-menu 'nonincremental-search-forward
2984 "search" map)
2985 (tool-bar-local-item-from-menu 'vc-status-kill-dir-status-process "cancel"
2986 map vc-status-mode-map)
2987 (tool-bar-local-item-from-menu 'bury-buffer "exit"
2988 map vc-status-mode-map)
2989 map))
2990
751c9f00
DN
2991(defvar vc-status-process-buffer nil
2992 "The buffer used for the asynchronous call that computes the VC status.")
2993
8fcaf22f
DN
2994(defun vc-status-mode ()
2995 "Major mode for VC status.
2996\\{vc-status-mode-map}"
7fbb4797 2997 (setq mode-name "VC Status")
8fcaf22f
DN
2998 (setq major-mode 'vc-status-mode)
2999 (setq buffer-read-only t)
3000 (use-local-map vc-status-mode-map)
934b91bf 3001 (set (make-local-variable 'tool-bar-map) vc-status-tool-bar-map)
8fcaf22f
DN
3002 (let ((buffer-read-only nil)
3003 (backend (vc-responsible-backend default-directory))
3004 entries)
3005 (erase-buffer)
751c9f00 3006 (set (make-local-variable 'vc-status-process-buffer) nil)
8fcaf22f 3007 (set (make-local-variable 'vc-status)
ca8dfeda
DN
3008 (ewoc-create #'vc-status-printer
3009 (vc-status-headers backend default-directory)))
9f7ddd67 3010 (add-hook 'after-save-hook 'vc-status-mark-buffer-changed)
9eef6650
DN
3011 ;; Make sure that if the VC status buffer is killed, the update
3012 ;; process running in the background is also killed.
3013 (add-hook 'kill-buffer-query-functions 'vc-status-kill-query nil t)
ca8dfeda
DN
3014 (vc-status-refresh)))
3015
3016(put 'vc-status-mode 'mode-class 'special)
3017
1f3e0cb5
AJ
3018(defun vc-status-update (entries buffer &optional noinsert)
3019 "Update BUFFER's ewoc from the list of ENTRIES.
3020If NOINSERT, ignore elements on ENTRIES which are not in the ewoc."
beac4378
AJ
3021 ;; Add ENTRIES to the vc-status buffer BUFFER.
3022 (with-current-buffer buffer
c1b51374
SM
3023 ;; Insert the entries sorted by name into the ewoc.
3024 ;; We assume the ewoc is sorted too, which should be the
3025 ;; case if we always add entries with vc-status-update.
e8847be3
DN
3026 (setq entries
3027 ;; Sort: first files and then subdirectories.
3028 ;; XXX: this is VERY inefficient, it computes the directory
3029 ;; names too many times
3030 (sort entries
3031 (lambda (entry1 entry2)
3032 (let ((dir1 (file-name-directory (expand-file-name (car entry1))))
3033 (dir2 (file-name-directory (expand-file-name (car entry2)))))
3034 (cond
3035 ((string< dir1 dir2) t)
3036 ((not (string= dir1 dir2)) nil)
3037 ((string< (car entry1) (car entry2))))))))
1f3e0cb5
AJ
3038 (let ((entry (car entries))
3039 (node (ewoc-nth vc-status 0)))
3040 (while (and entry node)
3041 (let ((entryfile (car entry))
3042 (nodefile (vc-status-fileinfo->name (ewoc-data node))))
3043 (cond
3044 ((string-lessp nodefile entryfile)
3045 (setq node (ewoc-next vc-status node)))
fc6dcd06 3046 ((string-lessp entryfile nodefile)
1f3e0cb5
AJ
3047 (unless noinsert
3048 (ewoc-enter-before vc-status node
3049 (apply 'vc-status-create-fileinfo entry)))
3050 (setq entries (cdr entries) entry (car entries)))
3051 (t
3052 (setf (vc-status-fileinfo->state (ewoc-data node)) (nth 1 entry))
3053 (setf (vc-status-fileinfo->extra (ewoc-data node)) (nth 2 entry))
010d9729 3054 (setf (vc-status-fileinfo->needs-update (ewoc-data node)) nil)
1f3e0cb5
AJ
3055 (ewoc-invalidate vc-status node)
3056 (setq entries (cdr entries) entry (car entries))
3057 (setq node (ewoc-next vc-status node))))))
3058 (unless (or node noinsert)
3059 ;; We're past the last node, all remaining entries go to the end.
3060 (while entries
3061 (ewoc-enter-last vc-status
3062 (apply 'vc-status-create-fileinfo (pop entries))))))))
c1b51374
SM
3063
3064(defun vc-status-busy ()
3065 (and (buffer-live-p vc-status-process-buffer)
3066 (get-buffer-process vc-status-process-buffer)))
5ab612e8 3067
fb0ac090
AJ
3068(defun vc-status-refresh-files (files default-state)
3069 "Refresh some files in the VC status buffer."
3070 (let ((backend (vc-responsible-backend default-directory))
3071 (status-buffer (current-buffer))
3072 (def-dir default-directory))
3073 (vc-set-mode-line-busy-indicator)
3074 ;; Call the `dir-status-file' backend function.
3075 ;; `dir-status-file' is supposed to be asynchronous.
3076 ;; It should compute the results, and then call the function
3077 ;; passed as an argument in order to update the vc-status buffer
3078 ;; with the results.
3079 (unless (buffer-live-p vc-status-process-buffer)
3080 (setq vc-status-process-buffer
3081 (generate-new-buffer (format " *VC-%s* tmp status" backend))))
3082 (lexical-let ((buffer (current-buffer)))
3083 (with-current-buffer vc-status-process-buffer
3084 (cd def-dir)
3085 (erase-buffer)
3086 (vc-call-backend
3087 backend 'dir-status-files def-dir files default-state
3088 (lambda (entries &optional more-to-come)
3089 ;; ENTRIES is a list of (FILE VC_STATE EXTRA) items.
3090 ;; If MORE-TO-COME is true, then more updates will come from
3091 ;; the asynchronous process.
3092 (with-current-buffer buffer
3093 (vc-status-update entries buffer)
3094 (unless more-to-come
3095 (setq mode-line-process nil)
3096 ;; Remove the ones that haven't been updated at all
3097 (ewoc-filter vc-status (lambda (info) (not (vc-status-fileinfo->needs-update info))))))))))))
3098
ca8dfeda 3099(defun vc-status-refresh ()
d39730b8
DN
3100 "Refresh the contents of the VC status buffer.
3101Throw an error if another update process is in progress."
ca8dfeda 3102 (interactive)
c1b51374 3103 (if (vc-status-busy)
d39730b8 3104 (error "Another update process is in progress, cannot run two at a time")
115c0061
DN
3105 (let ((backend (vc-responsible-backend default-directory))
3106 (status-buffer (current-buffer))
3107 (def-dir default-directory))
d39730b8 3108 (vc-set-mode-line-busy-indicator)
115c0061
DN
3109 ;; Call the `dir-status' backend function.
3110 ;; `dir-status' is supposed to be asynchronous.
3111 ;; It should compute the results, and then call the function
3112 ;; passed as an argument in order to update the vc-status buffer
3113 ;; with the results.
3114
3115 ;; Create a buffer that can be used by `dir-status' and call
3116 ;; `dir-status' with this buffer as the current buffer. Use
3117 ;; `vc-status-process-buffer' to remember this buffer, so that
3118 ;; it can be used later to kill the update process in case it
3119 ;; takes too long.
c1b51374
SM
3120 (unless (buffer-live-p vc-status-process-buffer)
3121 (setq vc-status-process-buffer
3122 (generate-new-buffer (format " *VC-%s* tmp status" backend))))
fb0ac090 3123 ;; set the needs-update flag on all entries
010d9729
SM
3124 (ewoc-map (lambda (info) (setf (vc-status-fileinfo->needs-update info) t) nil)
3125 vc-status)
fb0ac090 3126 (lexical-let ((buffer (current-buffer)))
c1b51374
SM
3127 (with-current-buffer vc-status-process-buffer
3128 (cd def-dir)
3129 (erase-buffer)
3130 (vc-call-backend
3131 backend 'dir-status def-dir
3132 (lambda (entries &optional more-to-come)
3133 ;; ENTRIES is a list of (FILE VC_STATE EXTRA) items.
3134 ;; If MORE-TO-COME is true, then more updates will come from
3135 ;; the asynchronous process.
3136 (with-current-buffer buffer
c1b51374 3137 (vc-status-update entries buffer)
c1b51374 3138 (unless more-to-come
fb0ac090 3139 (let ((remaining
010d9729
SM
3140 (ewoc-collect
3141 vc-status 'vc-status-fileinfo->needs-update)))
fb0ac090
AJ
3142 (if remaining
3143 (vc-status-refresh-files
010d9729 3144 (mapcar 'vc-status-fileinfo->name remaining)
fb0ac090
AJ
3145 'up-to-date)
3146 (setq mode-line-process nil))))))))))))
751c9f00
DN
3147
3148(defun vc-status-kill-dir-status-process ()
3149 "Kill the temporary buffer and associated process."
3150 (interactive)
f56d71a5 3151 (when (buffer-live-p vc-status-process-buffer)
751c9f00
DN
3152 (let ((proc (get-buffer-process vc-status-process-buffer)))
3153 (when proc (delete-process proc))
d39730b8 3154 (setq vc-status-process-buffer nil)
751c9f00 3155 (setq mode-line-process nil))))
ca8dfeda 3156
9eef6650
DN
3157(defun vc-status-kill-query ()
3158 ;; Make sure that when the VC status buffer is killed the update
3159 ;; process running in background is also killed.
3160 (when (vc-status-busy)
3161 (when (y-or-n-p "Status update process running, really kill status buffer?")
3162 (vc-status-kill-dir-status-process)
3163 t)))
3164
ca8dfeda
DN
3165(defun vc-status-next-line (arg)
3166 "Go to the next line.
3167If a prefix argument is given, move by that many lines."
3168 (interactive "p")
3169 (ewoc-goto-next vc-status arg)
3170 (vc-status-move-to-goal-column))
3171
3172(defun vc-status-previous-line (arg)
3173 "Go to the previous line.
3174If a prefix argument is given, move by that many lines."
3175 (interactive "p")
3176 (ewoc-goto-prev vc-status arg)
3177 (vc-status-move-to-goal-column))
8fcaf22f 3178
8bb38e87
DN
3179(defun vc-status-mark-unmark (mark-unmark-function)
3180 (if (use-region-p)
3181 (let ((firstl (line-number-at-pos (region-beginning)))
3182 (lastl (line-number-at-pos (region-end))))
3183 (save-excursion
3184 (goto-char (region-beginning))
3185 (while (<= (line-number-at-pos) lastl)
3186 (funcall mark-unmark-function))))
3187 (funcall mark-unmark-function)))
3188
8fcaf22f 3189(defun vc-status-mark-file ()
8bb38e87 3190 ;; Mark the current file and move to the next line.
8fcaf22f
DN
3191 (let* ((crt (ewoc-locate vc-status))
3192 (file (ewoc-data crt)))
3193 (setf (vc-status-fileinfo->marked file) t)
3194 (ewoc-invalidate vc-status crt)
ca8dfeda 3195 (vc-status-next-line 1)))
8fcaf22f 3196
8bb38e87
DN
3197(defun vc-status-mark ()
3198 "Mark the current file or all files in the region.
3199If the region is active, mark all the files in the region.
3200Otherwise mark the file on the current line and move to the next
3201line."
3202 (interactive)
3203 (vc-status-mark-unmark 'vc-status-mark-file))
3204
d3201e0b
DN
3205
3206;; XXX: Should this take the region into consideration?
3207(defun vc-status-mark-all-files (arg)
3208 "Mark all files with the same state as the current one.
3209With a prefix argument mark all files.
3210
3211The VC commands operate on files that are on the same state.
3212This command is intended to make it easy to select all files that
3213share the same state."
3214 (interactive "P")
3215 (if arg
3216 (ewoc-map
3217 (lambda (filearg)
3218 (unless (vc-status-fileinfo->marked filearg)
3219 (setf (vc-status-fileinfo->marked filearg) t)
3220 t))
3221 vc-status)
3222 (let* ((crt (ewoc-locate vc-status))
3223 (crt-state (vc-status-fileinfo->state (ewoc-data crt))))
3224 (ewoc-map
3225 (lambda (filearg)
3226 (when (and (not (vc-status-fileinfo->marked filearg))
3227 (eq (vc-status-fileinfo->state filearg) crt-state))
3228 (setf (vc-status-fileinfo->marked filearg) t)
3229 t))
3230 vc-status))))
b6fe5b19 3231
8fcaf22f 3232(defun vc-status-unmark-file ()
8bb38e87 3233 ;; Unmark the current file and move to the next line.
8fcaf22f
DN
3234 (let* ((crt (ewoc-locate vc-status))
3235 (file (ewoc-data crt)))
3236 (setf (vc-status-fileinfo->marked file) nil)
3237 (ewoc-invalidate vc-status crt)
ca8dfeda
DN
3238 (vc-status-next-line 1)))
3239
8bb38e87
DN
3240(defun vc-status-unmark ()
3241 "Unmark the current file or all files in the region.
3242If the region is active, unmark all the files in the region.
3243Otherwise mark the file on the current line and move to the next
3244line."
3245 (interactive)
3246 (vc-status-mark-unmark 'vc-status-unmark-file))
3247
ca8dfeda
DN
3248(defun vc-status-unmark-file-up ()
3249 "Move to the previous line and unmark the file."
3250 (interactive)
3251 ;; If we're on the first line, we won't move up, but we will still
3252 ;; remove the mark. This seems a bit odd but it is what buffer-menu
3253 ;; does.
3254 (let* ((prev (ewoc-goto-prev vc-status 1))
3255 (file (ewoc-data prev)))
3256 (setf (vc-status-fileinfo->marked file) nil)
3257 (ewoc-invalidate vc-status prev)
3258 (vc-status-move-to-goal-column)))
3259
d3201e0b
DN
3260(defun vc-status-unmark-all-files (arg)
3261 "Unmark all files with the same state as the current one.
3262With a prefix argument mark all files.
3263
3264The VC commands operate on files that are on the same state.
3265This command is intended to make it easy to deselect all files
3266that share the same state."
3267 (interactive "P")
3268 (if arg
3269 (ewoc-map
3270 (lambda (filearg)
3271 (when (vc-status-fileinfo->marked filearg)
3272 (setf (vc-status-fileinfo->marked filearg) nil)
3273 t))
3274 vc-status)
3275 (let* ((crt (ewoc-locate vc-status))
3276 (crt-state (vc-status-fileinfo->state (ewoc-data crt))))
3277 (ewoc-map
3278 (lambda (filearg)
3279 (when (and (vc-status-fileinfo->marked filearg)
3280 (eq (vc-status-fileinfo->state filearg) crt-state))
3281 (setf (vc-status-fileinfo->marked filearg) nil)
3282 t))
3283 vc-status))))
b6fe5b19 3284
64db3a90
JD
3285(defun vc-status-toggle-mark-file ()
3286 (let* ((crt (ewoc-locate vc-status))
3287 (file (ewoc-data crt)))
3288 (if (vc-status-fileinfo->marked file)
3289 (vc-status-unmark-file)
3290 (vc-status-mark-file))))
3291
3292(defun vc-status-toggle-mark ()
3293 (interactive)
934b91bf 3294 (vc-status-mark-unmark 'vc-status-toggle-mark-file))
64db3a90 3295
ca8dfeda
DN
3296(defun vc-status-register ()
3297 "Register the marked files, or the current file if no marks."
3298 (interactive)
c1b51374
SM
3299 ;; FIXME: Just pass the fileset to vc-register.
3300 (mapc 'vc-register (or (vc-status-marked-files)
3301 (list (vc-status-current-file)))))
ca8dfeda 3302
9eef6650
DN
3303(defun vc-status-show-fileentry (file)
3304 "Insert an entry for a specific file into the current VC status listing.
3305This is typically used if the file is up-to-date (or has been added
3306outside of VC) and one wants to do some operation on it."
3307 (interactive "fShow file: ")
3308 (vc-status-update (list (list (file-relative-name file) (vc-state file))) (current-buffer)))
3309
ca8dfeda
DN
3310(defun vc-status-find-file ()
3311 "Find the file on the current line."
3312 (interactive)
3313 (find-file (vc-status-current-file)))
3314
3315(defun vc-status-find-file-other-window ()
3316 "Find the file on the current line, in another window."
3317 (interactive)
3318 (find-file-other-window (vc-status-current-file)))
3319
3320(defun vc-status-current-file ()
3321 (let ((node (ewoc-locate vc-status)))
3322 (unless node
3323 (error "No file available."))
3324 (expand-file-name (vc-status-fileinfo->name (ewoc-data node)))))
8fcaf22f
DN
3325
3326(defun vc-status-marked-files ()
3327 "Return the list of marked files"
d048f3bf 3328 (mapcar
c1b51374
SM
3329 (lambda (elem) (expand-file-name (vc-status-fileinfo->name elem)))
3330 (ewoc-collect vc-status 'vc-status-fileinfo->marked)))
8fcaf22f 3331
d6f47dff
DN
3332(defun vc-status-hide-up-to-date ()
3333 "Hide up-to-date items from display."
21f3a277
DN
3334 (interactive)
3335 (ewoc-filter
3336 vc-status
3337 (lambda (crt) (not (eq (vc-status-fileinfo->state crt) 'up-to-date)))))
3338
5a84a937
DN
3339(defun vc-default-status-fileinfo-extra (backend file)
3340 nil)
3341
484c3092
DN
3342(defun vc-status-mark-buffer-changed (&optional fname)
3343 (let* ((file (or fname (expand-file-name buffer-file-name)))
9f7ddd67
DN
3344 (found-vc-status-buf nil))
3345 (save-excursion
3346 (dolist (status-buf (buffer-list))
3347 (set-buffer status-buf)
3348 ;; look for a vc-status buffer that might show this file.
3349 (when (eq major-mode 'vc-status-mode)
3350 (setq found-vc-status-buf t)
21f3a277 3351 (let ((ddir (expand-file-name default-directory)))
9f7ddd67 3352 ;; This test is cvs-string-prefix-p
21f3a277 3353 (when (eq t (compare-strings file nil (length ddir) ddir nil nil))
5a84a937
DN
3354 (let*
3355 ((file-short (substring file (length ddir)))
3356 (backend (vc-backend file))
3357 (state (and backend (vc-state file)))
5a84a937
DN
3358 (extra
3359 (and backend
3360 (vc-call-backend backend 'status-fileinfo-extra file)))
3361 (entry
3362 (list file-short (if state state 'unregistered) extra)))
c1b51374 3363 (vc-status-update (list entry) status-buf))))))
9f7ddd67
DN
3364 ;; We didn't find any vc-status buffers, remove the hook, it is
3365 ;; not needed.
3366 (unless found-vc-status-buf (remove-hook 'after-save-hook 'vc-status-mark-buffer-changed)))))
3367
594722a8
ER
3368;; Named-configuration entry points
3369
0e362f54 3370(defun vc-snapshot-precondition (dir)
6f1ecae4 3371 "Scan the tree below DIR, looking for files not up-to-date.
099bd78a
SM
3372If any file is not up-to-date, return the name of the first such file.
3373\(This means, neither snapshot creation nor retrieval is allowed.\)
3374If one or more of the files are currently visited, return `visited'.
3375Otherwise, return nil."
503b5c85
RS
3376 (let ((status nil))
3377 (catch 'vc-locked-example
3378 (vc-file-tree-walk
0e362f54
GM
3379 dir
3380 (lambda (f)
3381 (if (not (vc-up-to-date-p f)) (throw 'vc-locked-example f)
3382 (if (get-file-buffer f) (setq status 'visited)))))
503b5c85 3383 status)))
594722a8 3384
637a8ae9 3385;;;###autoload
0e362f54 3386(defun vc-create-snapshot (dir name branchp)
6f41eeb5 3387 "Descending recursively from DIR, make a snapshot called NAME.
ac3f4c6f
ER
3388For each registered file, the working revision becomes part of
3389the named configuration. If the prefix argument BRANCHP is
3390given, the snapshot is made as a new branch and the files are
3391checked out in that new branch."
0e362f54
GM
3392 (interactive
3393 (list (read-file-name "Directory: " default-directory default-directory t)
3394 (read-string "New snapshot name: ")
3395 current-prefix-arg))
3396 (message "Making %s... " (if branchp "branch" "snapshot"))
3397 (if (file-directory-p dir) (setq dir (file-name-as-directory dir)))
3398 (vc-call-backend (vc-responsible-backend dir)
3399 'create-snapshot dir name branchp)
3400 (message "Making %s... done" (if branchp "branch" "snapshot")))
3401
637a8ae9 3402;;;###autoload
0e362f54 3403(defun vc-retrieve-snapshot (dir name)
099bd78a 3404 "Descending recursively from DIR, retrieve the snapshot called NAME.
ac3f4c6f 3405If NAME is empty, it refers to the latest revisions.
099bd78a
SM
3406If locking is used for the files in DIR, then there must not be any
3407locked files at or below DIR (but if NAME is empty, locked files are
3408allowed and simply skipped)."
0e362f54
GM
3409 (interactive
3410 (list (read-file-name "Directory: " default-directory default-directory t)
ac3f4c6f 3411 (read-string "Snapshot name to retrieve (default latest revisions): ")))
0e362f54
GM
3412 (let ((update (yes-or-no-p "Update any affected buffers? "))
3413 (msg (if (or (not name) (string= name ""))
3414 (format "Updating %s... " (abbreviate-file-name dir))
3415 (format "Retrieving snapshot into %s... "
3416 (abbreviate-file-name dir)))))
8a26c165 3417 (message "%s" msg)
0e362f54
GM
3418 (vc-call-backend (vc-responsible-backend dir)
3419 'retrieve-snapshot dir name update)
8a26c165 3420 (message "%s" (concat msg "done"))))
0e362f54 3421
594722a8
ER
3422;; Miscellaneous other entry points
3423
637a8ae9 3424;;;###autoload
ac3f4c6f 3425(defun vc-print-log (&optional working-revision)
d7b60083 3426 "List the change log of the current fileset in a window.
ac3f4c6f 3427If WORKING-REVISION is non-nil, leave the point at that revision."
594722a8 3428 (interactive)
d7b60083 3429 (let* ((files (vc-deduce-fileset))
a7192ddb 3430 (backend (vc-backend files))
ac3f4c6f 3431 (working-revision (or working-revision (vc-working-revision (car files)))))
5217a76a
SS
3432 ;; Don't switch to the output buffer before running the command,
3433 ;; so that any buffer-local settings in the vc-controlled
ac9ff209 3434 ;; buffer can be accessed by the command.
d7b60083
ER
3435 (vc-call-backend backend 'print-log files "*vc-change-log*")
3436 (pop-to-buffer "*vc-change-log*")
0e362f54 3437 (vc-exec-after
99cb8c8b 3438 `(let ((inhibit-read-only t))
d7b60083 3439 (vc-call-backend ',backend 'log-view-mode)
0e362f54
GM
3440 (goto-char (point-max)) (forward-line -1)
3441 (while (looking-at "=*\n")
3442 (delete-char (- (match-end 0) (match-beginning 0)))
3443 (forward-line -1))
3444 (goto-char (point-min))
3445 (if (looking-at "[\b\t\n\v\f\r ]+")
3446 (delete-char (- (match-end 0) (match-beginning 0))))
d7b60083 3447 (shrink-window-if-larger-than-buffer)
ac3f4c6f
ER
3448 ;; move point to the log entry for the working revision
3449 (vc-call-backend ',backend 'show-log-entry ',working-revision)
86e80023 3450 (setq vc-sentinel-movepoint (point))
99cb8c8b 3451 (set-buffer-modified-p nil)))))
594722a8 3452
637a8ae9 3453;;;###autoload
e4d26892 3454(defun vc-revert ()
d7b60083 3455 "Revert working copies of the selected fileset to their repository contents.
9c95ac44 3456This asks for confirmation if the buffer contents are not identical
ac3f4c6f 3457to the working revision (except for keyword expansion)."
594722a8 3458 (interactive)
a7192ddb 3459 (let* ((files (vc-deduce-fileset)))
d7b60083
ER
3460 ;; If any of the files is visited by the current buffer, make
3461 ;; sure buffer is saved. If the user says `no', abort since
3462 ;; we cannot show the changes and ask for confirmation to
3463 ;; discard them.
3464 (if (or (not files) (memq (buffer-file-name) files))
3465 (vc-buffer-sync nil))
3466 (dolist (file files)
a7192ddb 3467 (let ((buf (get-file-buffer file)))
d7b60083
ER
3468 (if (and buf (buffer-modified-p buf))
3469 (error "Please kill or save all modified buffers before reverting.")))
3470 (if (vc-up-to-date-p file)
3471 (unless (yes-or-no-p (format "%s seems up-to-date. Revert anyway? " file))
3472 (error "Revert canceled"))))
a7192ddb 3473 (if (vc-diff-internal vc-allow-async-revert files nil nil)
d7b60083
ER
3474 (progn
3475 (unless (yes-or-no-p (format "Discard changes in %s? " (vc-delistify files)))
3476 (error "Revert canceled"))
3477 (delete-windows-on "*vc-diff*")
3478 (kill-buffer "*vc-diff*")))
3479 (dolist (file files)
3480 (progn
3481 (message "Reverting %s..." (vc-delistify files))
3482 (vc-revert-file file)
3483 (message "Reverting %s...done" (vc-delistify files))))))
594722a8 3484
637a8ae9 3485;;;###autoload
d7b60083
ER
3486(defun vc-rollback ()
3487 "Roll back (remove) the most recent changeset committed to the repository.
3488This may be either a file-level or a repository-level operation,
3489depending on the underlying version-control system."
3490 (interactive)
3491 (let* ((files (vc-deduce-fileset))
a7192ddb 3492 (backend (vc-backend files))
d7b60083
ER
3493 (granularity (vc-call-backend backend 'revision-granularity)))
3494 (unless (vc-find-backend-function backend 'rollback)
3495 (error "Rollback is not supported in %s" backend))
3496 (if (and (not (eq granularity 'repository)) (/= (length files) 1))
3497 (error "Rollback requires a singleton fileset or repository versioning"))
3498 (if (not (vc-call latest-on-branch-p (car files)))
3499 (error "Rollback is only possible at the tip revision."))
3500 ;; If any of the files is visited by the current buffer, make
3501 ;; sure buffer is saved. If the user says `no', abort since
3502 ;; we cannot show the changes and ask for confirmation to
3503 ;; discard them.
3504 (if (or (not files) (memq (buffer-file-name) files))
3505 (vc-buffer-sync nil))
3506 (dolist (file files)
3507 (if (buffer-modified-p (get-file-buffer file))
3508 (error "Please kill or save all modified buffers before rollback."))
3509 (if (not (vc-up-to-date-p file))
3510 (error "Please revert all modified workfiles before rollback.")))
3511 ;; Accumulate changes associated with the fileset
3512 (vc-setup-buffer "*vc-diff*")
3513 (not-modified)
3514 (message "Finding changes...")
ac3f4c6f
ER
3515 (let* ((tip (vc-working-revision (car files)))
3516 (previous (vc-call previous-revision (car files) tip)))
a7192ddb
SM
3517 (vc-diff-internal nil files previous tip))
3518 ;; Display changes
d7b60083
ER
3519 (unless (yes-or-no-p "Discard these revisions? ")
3520 (error "Rollback canceled"))
3521 (delete-windows-on "*vc-diff*")
3522 (kill-buffer"*vc-diff*")
3523 ;; Do the actual reversions
3524 (message "Rolling back %s..." (vc-delistify files))
3525 (with-vc-properties
3526 files
3527 (vc-call-backend backend 'rollback files)
3528 `((vc-state . ,'up-to-date)
3529 (vc-checkout-time . , (nth 5 (file-attributes file)))
ac3f4c6f 3530 (vc-working-revision . nil)))
a7192ddb 3531 (dolist (f files) (vc-resynch-buffer f t t))
d7b60083 3532 (message "Rolling back %s...done" (vc-delistify files))))
0e362f54 3533
2765044b
DN
3534;;;###autoload
3535(define-obsolete-function-alias 'vc-revert-buffer 'vc-revert "23.1")
3536
3537;;;###autoload
3538(defun vc-update ()
ac3f4c6f 3539 "Update the current fileset's files to their tip revisions.
a7192ddb
SM
3540For each one that contains no changes, and is not locked, then this simply
3541replaces the work file with the latest revision on its branch. If the file
3542contains changes, and the backend supports merging news, then any recent
d7b60083 3543changes from the current branch are merged into the working file."
2765044b 3544 (interactive)
d7b60083 3545 (dolist (file (vc-deduce-fileset))
20f95df2
DN
3546 (when (let ((buf (get-file-buffer file)))
3547 (and buf (buffer-modified-p buf)))
3548 (error "Please kill or save all modified buffers before updating."))
2765044b 3549 (if (vc-up-to-date-p file)
cea93de3 3550 (vc-checkout file nil t)
2765044b 3551 (if (eq (vc-checkout-model file) 'locking)
d7b60083 3552 (if (eq (vc-state file) 'edited)
8c16bd8c 3553 (error "%s"
1f325d92
DG
3554 (substitute-command-keys
3555 "File is locked--type \\[vc-revert] to discard changes"))
1388485d 3556 (error "Unexpected file state (%s) -- type %s"
1f325d92
DG
3557 (vc-state file)
3558 (substitute-command-keys
3559 "\\[vc-next-action] to correct")))
d7b60083
ER
3560 (if (not (vc-find-backend-function (vc-backend file) 'merge-news))
3561 (error "Sorry, merging news is not implemented for %s"
3562 (vc-backend file))
c6a234ac 3563 (vc-maybe-resolve-conflicts file (vc-call merge-news file)))))))
2765044b
DN
3564
3565(defun vc-version-backup-file (file &optional rev)
3566 "Return name of backup file for revision REV of FILE.
3567If version backups should be used for FILE, and there exists
a7192ddb 3568such a backup for REV or the working revision of file, return
0d0e9356 3569its name; otherwise return nil."
2765044b
DN
3570 (when (vc-call make-version-backups-p file)
3571 (let ((backup-file (vc-version-backup-file-name file rev)))
3572 (if (file-exists-p backup-file)
3573 backup-file
3574 ;; there is no automatic backup, but maybe the user made one manually
3575 (setq backup-file (vc-version-backup-file-name file rev 'manual))
3576 (if (file-exists-p backup-file)
3577 backup-file)))))
3578
3579(defun vc-revert-file (file)
ac3f4c6f 3580 "Revert FILE back to the repository working revision it was based on."
2765044b 3581 (with-vc-properties
d7b60083 3582 (list file)
2765044b
DN
3583 (let ((backup-file (vc-version-backup-file file)))
3584 (when backup-file
3585 (copy-file backup-file file 'ok-if-already-exists 'keep-date)
3586 (vc-delete-automatic-version-backups file))
3587 (vc-call revert file backup-file))
3588 `((vc-state . up-to-date)
3589 (vc-checkout-time . ,(nth 5 (file-attributes file)))))
3590 (vc-resynch-buffer file t t))
3591
76e5906d 3592;;;###autoload
1d502d5a 3593(defun vc-switch-backend (file backend)
7849e179 3594 "Make BACKEND the current version control system for FILE.
1d502d5a
AS
3595FILE must already be registered in BACKEND. The change is not
3596permanent, only for the current session. This function only changes
7849e179
SM
3597VC's perspective on FILE, it does not register or unregister it.
3598By default, this command cycles through the registered backends.
3599To get a prompt, use a prefix argument."
3600 (interactive
1d502d5a 3601 (list
94ca88e3
AS
3602 (or buffer-file-name
3603 (error "There is no version-controlled file in this buffer"))
7849e179
SM
3604 (let ((backend (vc-backend buffer-file-name))
3605 (backends nil))
d7b60083
ER
3606 (unless backend
3607 (error "File %s is not under version control" buffer-file-name))
3608 ;; Find the registered backends.
3609 (dolist (backend vc-handled-backends)
3610 (when (vc-call-backend backend 'registered buffer-file-name)
3611 (push backend backends)))
3612 ;; Find the next backend.
3613 (let ((def (car (delq backend (append (memq backend backends) backends))))
3614 (others (delete backend backends)))
3615 (cond
3616 ((null others) (error "No other backend to switch to"))
3617 (current-prefix-arg
3618 (intern
3619 (upcase
3620 (completing-read
3621 (format "Switch to backend [%s]: " def)
3622 (mapcar (lambda (b) (list (downcase (symbol-name b)))) backends)
3623 nil t nil nil (downcase (symbol-name def))))))
3624 (t def))))))
ceec5a0c 3625 (unless (eq backend (vc-backend file))
ceec5a0c
SM
3626 (vc-file-clearprops file)
3627 (vc-file-setprop file 'vc-backend backend)
3628 ;; Force recomputation of the state
a3255400
SM
3629 (unless (vc-call-backend backend 'registered file)
3630 (vc-file-clearprops file)
3631 (error "%s is not registered in %s" file backend))
ceec5a0c 3632 (vc-mode-line file)))
1d502d5a 3633
21b50296 3634;;;###autoload
1d502d5a 3635(defun vc-transfer-file (file new-backend)
ceec5a0c 3636 "Transfer FILE to another version control system NEW-BACKEND.
1d502d5a 3637If NEW-BACKEND has a higher precedence than FILE's current backend
ceec5a0c 3638\(i.e. it comes earlier in `vc-handled-backends'), then register FILE in
ac3f4c6f 3639NEW-BACKEND, using the revision number from the current backend as the
1d502d5a
AS
3640base level. If NEW-BACKEND has a lower precedence than the current
3641backend, then commit all changes that were made under the current
3642backend to NEW-BACKEND, and unregister FILE from the current backend.
3643\(If FILE is not yet registered under NEW-BACKEND, register it.)"
72cfc5fb
AS
3644 (let* ((old-backend (vc-backend file))
3645 (edited (memq (vc-state file) '(edited needs-merge)))
3646 (registered (vc-call-backend new-backend 'registered file))
3647 (move
3648 (and registered ; Never move if not registered in new-backend yet.
3649 ;; move if new-backend comes later in vc-handled-backends
3650 (or (memq new-backend (memq old-backend vc-handled-backends))
ffda0460 3651 (y-or-n-p "Final transfer? "))))
72cfc5fb 3652 (comment nil))
1d502d5a 3653 (if (eq old-backend new-backend)
72cfc5fb
AS
3654 (error "%s is the current backend of %s" new-backend file))
3655 (if registered
3656 (set-file-modes file (logior (file-modes file) 128))
3657 ;; `registered' might have switched under us.
3658 (vc-switch-backend file old-backend)
ac3f4c6f 3659 (let* ((rev (vc-working-revision file))
c1b1b393 3660 (modified-file (and edited (make-temp-file file)))
ffda0460 3661 (unmodified-file (and modified-file (vc-version-backup-file file))))
72cfc5fb
AS
3662 ;; Go back to the base unmodified file.
3663 (unwind-protect
3664 (progn
ffda0460 3665 (when modified-file
c1b1b393 3666 (copy-file file modified-file 'ok-if-already-exists)
ffda0460
AS
3667 ;; If we have a local copy of the unmodified file, handle that
3668 ;; here and not in vc-revert-file because we don't want to
3669 ;; delete that copy -- it is still useful for OLD-BACKEND.
3670 (if unmodified-file
b4e4e3a8
SM
3671 (copy-file unmodified-file file
3672 'ok-if-already-exists 'keep-date)
ac3f4c6f 3673 (if (y-or-n-p "Get base revision from master? ")
ffda0460 3674 (vc-revert-file file))))
72cfc5fb 3675 (vc-call-backend new-backend 'receive-file file rev))
ffda0460 3676 (when modified-file
72cfc5fb
AS
3677 (vc-switch-backend file new-backend)
3678 (unless (eq (vc-checkout-model file) 'implicit)
3679 (vc-checkout file t nil))
ffda0460
AS
3680 (rename-file modified-file file 'ok-if-already-exists)
3681 (vc-file-setprop file 'vc-checkout-time nil)))))
72cfc5fb
AS
3682 (when move
3683 (vc-switch-backend file old-backend)
3684 (setq comment (vc-call comment-history file))
3685 (vc-call unregister file))
3686 (vc-switch-backend file new-backend)
3687 (when (or move edited)
1d502d5a 3688 (vc-file-setprop file 'vc-state 'edited)
ffda0460 3689 (vc-mode-line file)
0ab66291 3690 (vc-checkin file nil comment (stringp comment)))))
1d502d5a 3691
0e362f54
GM
3692(defun vc-rename-master (oldmaster newfile templates)
3693 "Rename OLDMASTER to be the master file for NEWFILE based on TEMPLATES."
3694 (let* ((dir (file-name-directory (expand-file-name oldmaster)))
3695 (newdir (or (file-name-directory newfile) ""))
3696 (newbase (file-name-nondirectory newfile))
3697 (masters
3698 ;; List of potential master files for `newfile'
3699 (mapcar
3700 (lambda (s) (vc-possible-master s newdir newbase))
3701 templates)))
3702 (if (or (file-symlink-p oldmaster)
3703 (file-symlink-p (file-name-directory oldmaster)))
6f1ecae4 3704 (error "This is unsafe in the presence of symbolic links"))
0e362f54
GM
3705 (rename-file
3706 oldmaster
3707 (catch 'found
3708 ;; If possible, keep the master file in the same directory.
b4e4e3a8
SM
3709 (dolist (f masters)
3710 (if (and f (string= (file-name-directory (expand-file-name f)) dir))
3711 (throw 'found f)))
0e362f54 3712 ;; If not, just use the first possible place.
b4e4e3a8
SM
3713 (dolist (f masters)
3714 (and f (or (not (setq dir (file-name-directory f)))
3715 (file-directory-p dir))
3716 (throw 'found f)))
0e362f54 3717 (error "New file lacks a version control directory")))))
594722a8 3718
a36319a4
SM
3719(defun vc-delete-file (file)
3720 "Delete file and mark it as such in the version control system."
3721 (interactive "fVC delete file: ")
484c3092 3722 (setq file (expand-file-name file))
c6e44350
AS
3723 (let ((buf (get-file-buffer file))
3724 (backend (vc-backend file)))
3725 (unless backend
86a65190 3726 (error "File %s is not under version control"
c6e44350 3727 (file-name-nondirectory file)))
a36319a4 3728 (unless (vc-find-backend-function backend 'delete-file)
c6e44350 3729 (error "Deleting files under %s is not supported in VC" backend))
a36319a4
SM
3730 (if (and buf (buffer-modified-p buf))
3731 (error "Please save files before deleting them"))
ce5a3ac0 3732 (unless (y-or-n-p (format "Really want to delete %s? "
a36319a4
SM
3733 (file-name-nondirectory file)))
3734 (error "Abort!"))
3735 (unless (or (file-directory-p file) (null make-backup-files))
3736 (with-current-buffer (or buf (find-file-noselect file))
3737 (let ((backup-inhibited nil))
484c3092
DN
3738 (backup-buffer))
3739 ;; If we didn't have a buffer visiting the file before this
3740 ;; command, kill the buffer created by the above
3741 ;; `find-file-noselect' call.
3742 (unless buf (kill-buffer (current-buffer)))))
a36319a4
SM
3743 (vc-call delete-file file)
3744 ;; If the backend hasn't deleted the file itself, let's do it for him.
484c3092
DN
3745 (if (file-exists-p file) (delete-file file))
3746 ;; Forget what VC knew about the file.
3747 (vc-file-clearprops file)
3748 (vc-resynch-buffer file buf t)))
a36319a4 3749
29fc1ce9 3750;;;###autoload
594722a8 3751(defun vc-rename-file (old new)
34291cd2
RS
3752 "Rename file OLD to NEW, and rename its master file likewise."
3753 (interactive "fVC rename file: \nFRename to: ")
a36319a4 3754 (let ((oldbuf (get-file-buffer old)))
d52f0de9 3755 (if (and oldbuf (buffer-modified-p oldbuf))
590cc449 3756 (error "Please save files before moving them"))
594722a8 3757 (if (get-file-buffer new)
590cc449 3758 (error "Already editing new file name"))
d52f0de9
RS
3759 (if (file-exists-p new)
3760 (error "New file already exists"))
86a65190 3761 (let ((state (vc-state old)))
a36319a4
SM
3762 (unless (memq state '(up-to-date edited))
3763 (error "Please %s files before moving them"
3764 (if (stringp state) "check in" "update"))))
3765 (vc-call rename-file old new)
b4e4e3a8 3766 (vc-file-clearprops old)
0e362f54 3767 ;; Move the actual file (unless the backend did it already)
a36319a4 3768 (if (file-exists-p old) (rename-file old new))
0e362f54
GM
3769 ;; ?? Renaming a file might change its contents due to keyword expansion.
3770 ;; We should really check out a new copy if the old copy was precisely equal
ac3f4c6f 3771 ;; to some checked-in revision. However, testing for this is tricky....
594722a8 3772 (if oldbuf
0e362f54 3773 (with-current-buffer oldbuf
4c145b9e
RS
3774 (let ((buffer-read-only buffer-read-only))
3775 (set-visited-file-name new))
3776 (vc-backend new)
3777 (vc-mode-line new)
0e362f54
GM
3778 (set-buffer-modified-p nil)))))
3779
637a8ae9 3780;;;###autoload
f35ecf88 3781(defun vc-update-change-log (&rest args)
0e362f54 3782 "Find change log file and add entries from recent version control logs.
d68e6990 3783Normally, find log entries for all registered files in the default
0e362f54 3784directory.
d68e6990 3785
099bd78a 3786With prefix arg of \\[universal-argument], only find log entries for the current buffer's file.
d68e6990
RS
3787
3788With any numeric prefix arg, find log entries for all currently visited
3789files that are under version control. This puts all the entries in the
3790log for the default directory, which may not be appropriate.
3791
099bd78a 3792From a program, any ARGS are assumed to be filenames for which
0e362f54 3793log entries should be gathered."
67242a23
RM
3794 (interactive
3795 (cond ((consp current-prefix-arg) ;C-u
3796 (list buffer-file-name))
3797 (current-prefix-arg ;Numeric argument.
3798 (let ((files nil)
3799 (buffers (buffer-list))
3800 file)
3801 (while buffers
3802 (setq file (buffer-file-name (car buffers)))
f3c61d82 3803 (and file (vc-backend file)
4b40fdea 3804 (setq files (cons file files)))
67242a23 3805 (setq buffers (cdr buffers)))
4b40fdea
PE
3806 files))
3807 (t
0e362f54
GM
3808 ;; Don't supply any filenames to backend; this means
3809 ;; it should find all relevant files relative to
3810 ;; the default-directory.
73a9679c 3811 nil)))
0e362f54
GM
3812 (vc-call-backend (vc-responsible-backend default-directory)
3813 'update-changelog args))
3814
ac3f4c6f 3815;;; The default back end. Assumes RCS-like revision numbering.
61de26cb
ER
3816
3817(defun vc-default-revision-granularity ()
3818 (error "Your backend will not work with this version of VC mode."))
3819
2765044b
DN
3820;; functions that operate on RCS revision numbers. This code should
3821;; also be moved into the backends. It stays for now, however, since
3822;; it is used in code below.
3823;;;###autoload
3824(defun vc-trunk-p (rev)
3825 "Return t if REV is a revision on the trunk."
3826 (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev))))
3827
3828(defun vc-branch-p (rev)
3829 "Return t if REV is a branch revision."
3830 (not (eq nil (string-match "\\`[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*\\'" rev))))
3831
3832;;;###autoload
3833(defun vc-branch-part (rev)
3834 "Return the branch part of a revision number REV."
3835 (let ((index (string-match "\\.[0-9]+\\'" rev)))
3836 (if index
3837 (substring rev 0 index))))
3838
3839(defun vc-minor-part (rev)
ac3f4c6f 3840 "Return the minor revision number of a revision number REV."
2765044b
DN
3841 (string-match "[0-9]+\\'" rev)
3842 (substring rev (match-beginning 0) (match-end 0)))
3843
ac3f4c6f
ER
3844(defun vc-default-previous-revision (backend file rev)
3845 "Return the revision number immediately preceding REV for FILE,
3846or nil if there is no previous revision. This default
3847implementation works for MAJOR.MINOR-style revision numbers as
2765044b
DN
3848used by RCS and CVS."
3849 (let ((branch (vc-branch-part rev))
3850 (minor-num (string-to-number (vc-minor-part rev))))
3851 (when branch
3852 (if (> minor-num 1)
ac3f4c6f 3853 ;; revision does probably not start a branch or release
2765044b
DN
3854 (concat branch "." (number-to-string (1- minor-num)))
3855 (if (vc-trunk-p rev)
3856 ;; we are at the beginning of the trunk --
3857 ;; don't know anything to return here
3858 nil
3859 ;; we are at the beginning of a branch --
ac3f4c6f 3860 ;; return revision of starting point
2765044b
DN
3861 (vc-branch-part branch))))))
3862
ac3f4c6f
ER
3863(defun vc-default-next-revision (backend file rev)
3864 "Return the revision number immediately following REV for FILE,
3865or nil if there is no next revision. This default implementation
3866works for MAJOR.MINOR-style revision numbers as used by RCS
2765044b 3867and CVS."
ac3f4c6f 3868 (when (not (string= rev (vc-working-revision file)))
2765044b
DN
3869 (let ((branch (vc-branch-part rev))
3870 (minor-num (string-to-number (vc-minor-part rev))))
3871 (concat branch "." (number-to-string (1+ minor-num))))))
3872
3873(defun vc-default-responsible-p (backend file)
3874 "Indicate whether BACKEND is reponsible for FILE.
3875The default is to return nil always."
3876 nil)
3877
3878(defun vc-default-could-register (backend file)
3879 "Return non-nil if BACKEND could be used to register FILE.
3880The default implementation returns t for all files."
3881 t)
3882
3883(defun vc-default-latest-on-branch-p (backend file)
3884 "Return non-nil if FILE is the latest on its branch.
3885This default implementation always returns non-nil, which means that
ac3f4c6f 3886editing non-current revisions is not supported by default."
2765044b
DN
3887 t)
3888
ac3f4c6f 3889(defun vc-default-init-revision (backend) vc-default-init-revision)
2765044b 3890
45fd3a00
SM
3891(defalias 'vc-cvs-update-changelog 'vc-update-changelog-rcs2log)
3892(defalias 'vc-rcs-update-changelog 'vc-update-changelog-rcs2log)
3893;; FIXME: This should probably be moved to vc-rcs.el and replaced in
3894;; vc-cvs.el by code using cvs2cl.
0b8dce84 3895(defun vc-update-changelog-rcs2log (files)
099bd78a
SM
3896 "Default implementation of update-changelog.
3897Uses `rcs2log' which only works for RCS and CVS."
0e362f54 3898 ;; FIXME: We (c|sh)ould add support for cvs2cl
449decf5 3899 (let ((odefault default-directory)
124c852b
RS
3900 (changelog (find-change-log))
3901 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
c1b1b393 3902 (tempfile (make-temp-file
57c298c4
EZ
3903 (expand-file-name "vc"
3904 (or small-temporary-file-directory
3905 temporary-file-directory))))
510f6466
AS
3906 (login-name (or user-login-name
3907 (format "uid%d" (number-to-string (user-uid)))))
b91916f3 3908 (full-name (or add-log-full-name
8172cd86
AS
3909 (user-full-name)
3910 (user-login-name)
3911 (format "uid%d" (number-to-string (user-uid)))))
b91916f3
RS
3912 (mailing-address (or add-log-mailing-address
3913 user-mail-address)))
124c852b 3914 (find-file-other-window changelog)
41dfb835
RS
3915 (barf-if-buffer-read-only)
3916 (vc-buffer-sync)
3917 (undo-boundary)
3918 (goto-char (point-min))
3919 (push-mark)
3920 (message "Computing change log entries...")
4b40fdea 3921 (message "Computing change log entries... %s"
124c852b
RS
3922 (unwind-protect
3923 (progn
0e362f54 3924 (setq default-directory odefault)
6f41eeb5
DL
3925 (if (eq 0 (apply 'call-process
3926 (expand-file-name "rcs2log"
3927 exec-directory)
0e362f54
GM
3928 nil (list t tempfile) nil
3929 "-c" changelog
510f6466 3930 "-u" (concat login-name
0e362f54
GM
3931 "\t" full-name
3932 "\t" mailing-address)
3933 (mapcar
3934 (lambda (f)
3935 (file-relative-name
d7b60083 3936 (expand-file-name f odefault)))
0e362f54
GM
3937 files)))
3938 "done"
04864eb0 3939 (pop-to-buffer (get-buffer-create "*vc*"))
124c852b 3940 (erase-buffer)
54ebae28 3941 (insert-file-contents tempfile)
124c852b 3942 "failed"))
0e362f54 3943 (setq default-directory (file-name-directory changelog))
124c852b 3944 (delete-file tempfile)))))
7d2d9482 3945
ac3f4c6f
ER
3946(defun vc-default-find-revision (backend file rev buffer)
3947 "Provide the new `find-revision' op based on the old `checkout' op.
2765044b 3948This is only for compatibility with old backends. They should be updated
ac3f4c6f 3949to provide the `find-revision' operation instead."
2765044b
DN
3950 (let ((tmpfile (make-temp-file (expand-file-name file))))
3951 (unwind-protect
3952 (progn
3953 (vc-call-backend backend 'checkout file nil rev tmpfile)
3954 (with-current-buffer buffer
3955 (insert-file-contents-literally tmpfile)))
3956 (delete-file tmpfile))))
3957
3958(defun vc-default-dired-state-info (backend file)
d7b60083
ER
3959 (let* ((state (vc-state file))
3960 (statestring
3961 (cond
3962 ((stringp state) (concat "(" state ")"))
45b24b4d 3963 ((eq state 'edited) "(modified)")
d7b60083
ER
3964 ((eq state 'needs-merge) "(merge)")
3965 ((eq state 'needs-patch) "(patch)")
0f67cc71 3966 ((eq state 'added) "(added)")
484c1b1f 3967 ((eq state 'removed) "(removed)")
722f037f
ER
3968 ((eq state 'ignored) "(ignored)") ;; dired-hook filters this out
3969 ((eq state 'unregistered) "?")
3970 ((eq state 'unlocked-changes) "(stale)")
3971 ((not state) "(unknown)")))
d7b60083
ER
3972 (buffer
3973 (get-file-buffer file))
3974 (modflag
3975 (if (and buffer (buffer-modified-p buffer)) "+" "")))
3976 (concat statestring modflag)))
2765044b
DN
3977
3978(defun vc-default-rename-file (backend old new)
3979 (condition-case nil
3980 (add-name-to-file old new)
3981 (error (rename-file old new)))
3982 (vc-delete-file old)
3983 (with-current-buffer (find-file-noselect new)
3984 (vc-register)))
3985
3986(defalias 'vc-default-logentry-check 'ignore)
17f3909f 3987(defalias 'vc-default-check-headers 'ignore)
2765044b
DN
3988
3989(defun vc-default-log-view-mode (backend) (log-view-mode))
3990
3991(defun vc-default-show-log-entry (backend rev)
3992 (with-no-warnings
3993 (log-view-goto-rev rev)))
3994
3995(defun vc-default-comment-history (backend file)
3996 "Return a string with all log entries stored in BACKEND for FILE."
7fbb4797
DN
3997 (when (vc-find-backend-function backend 'print-log)
3998 (with-current-buffer "*vc*"
3999 (vc-call print-log (list file))
4000 (vc-call-backend backend 'wash-log)
4001 (buffer-string))))
2765044b 4002
2765044b
DN
4003(defun vc-default-receive-file (backend file rev)
4004 "Let BACKEND receive FILE from another version control system."
4005 (vc-call-backend backend 'register file rev ""))
4006
4007(defun vc-default-create-snapshot (backend dir name branchp)
4008 (when branchp
4009 (error "VC backend %s does not support module branches" backend))
4010 (let ((result (vc-snapshot-precondition dir)))
4011 (if (stringp result)
4012 (error "File %s is not up-to-date" result)
4013 (vc-file-tree-walk
4014 dir
4015 (lambda (f)
4016 (vc-call assign-name f name))))))
4017
4018(defun vc-default-retrieve-snapshot (backend dir name update)
4019 (if (string= name "")
4020 (progn
4021 (vc-file-tree-walk
4022 dir
4023 (lambda (f) (and
4024 (vc-up-to-date-p f)
4025 (vc-error-occurred
4026 (vc-call checkout f nil "")
4027 (if update (vc-resynch-buffer f t t)))))))
4028 (let ((result (vc-snapshot-precondition dir)))
4029 (if (stringp result)
4030 (error "File %s is locked" result)
4031 (setq update (and (eq result 'visited) update))
4032 (vc-file-tree-walk
4033 dir
4034 (lambda (f) (vc-error-occurred
4035 (vc-call checkout f nil name)
4036 (if update (vc-resynch-buffer f t t)))))))))
4037
4038(defun vc-default-revert (backend file contents-done)
4039 (unless contents-done
ac3f4c6f 4040 (let ((rev (vc-working-revision file))
2765044b
DN
4041 (file-buffer (or (get-file-buffer file) (current-buffer))))
4042 (message "Checking out %s..." file)
4043 (let ((failed t)
4044 (backup-name (car (find-backup-file-name file))))
4045 (when backup-name
4046 (copy-file file backup-name 'ok-if-already-exists 'keep-date)
4047 (unless (file-writable-p file)
4048 (set-file-modes file (logior (file-modes file) 128))))
4049 (unwind-protect
4050 (let ((coding-system-for-read 'no-conversion)
4051 (coding-system-for-write 'no-conversion))
4052 (with-temp-file file
4053 (let ((outbuf (current-buffer)))
4054 ;; Change buffer to get local value of vc-checkout-switches.
4055 (with-current-buffer file-buffer
4056 (let ((default-directory (file-name-directory file)))
ac3f4c6f 4057 (vc-call find-revision file rev outbuf)))))
2765044b
DN
4058 (setq failed nil))
4059 (when backup-name
4060 (if failed
4061 (rename-file backup-name file 'ok-if-already-exists)
4062 (and (not vc-make-backup-files) (delete-file backup-name))))))
4063 (message "Checking out %s...done" file))))
4064
17f3909f 4065(defalias 'vc-default-revision-completion-table 'ignore)
2765044b 4066
fb0ac090
AJ
4067(defun vc-default-dir-status-files (backend dir files default-state update-function)
4068 (funcall update-function
4069 (mapcar (lambda (file) (list file default-state)) files)))
4070
2765044b
DN
4071(defun vc-check-headers ()
4072 "Check if the current file has any headers in it."
4073 (interactive)
4074 (vc-call-backend (vc-backend buffer-file-name) 'check-headers))
4075
4076;;; Annotate functionality
7d2d9482 4077
f80f7bc2
RS
4078;; Declare globally instead of additional parameter to
4079;; temp-buffer-show-function (not possible to pass more than one
75665141
AS
4080;; parameter). The use of annotate-ratio is deprecated in favor of
4081;; annotate-mode, which replaces it with the more sensible "span-to
4082;; days", along with autoscaling support.
099bd78a 4083(defvar vc-annotate-ratio nil "Global variable.")
0e362f54 4084
1b5a7343 4085;; internal buffer-local variables
04864eb0 4086(defvar vc-annotate-backend nil)
1b5a7343
AS
4087(defvar vc-annotate-parent-file nil)
4088(defvar vc-annotate-parent-rev nil)
4089(defvar vc-annotate-parent-display-mode nil)
1b5a7343 4090
f66a6225
SM
4091(defconst vc-annotate-font-lock-keywords
4092 ;; The fontification is done by vc-annotate-lines instead of font-lock.
4093 '((vc-annotate-lines)))
4094
93113211 4095(define-derived-mode vc-annotate-mode fundamental-mode "Annotate"
6f1ecae4 4096 "Major mode for output buffers of the `vc-annotate' command.
7d2d9482
RS
4097
4098You can use the mode-specific menu to alter the time-span of the used
4099colors. See variable `vc-annotate-menu-elements' for customizing the
4100menu items."
5731a8e0
TTN
4101 ;; Frob buffer-invisibility-spec so that if it is originally a naked t,
4102 ;; it will become a list, to avoid initial annotations being invisible.
4103 (add-to-invisibility-spec 'foo)
4104 (remove-from-invisibility-spec 'foo)
f66a6225
SM
4105 (set (make-local-variable 'truncate-lines) t)
4106 (set (make-local-variable 'font-lock-defaults)
4107 '(vc-annotate-font-lock-keywords t))
04864eb0 4108 (view-mode 1))
7d2d9482 4109
5731a8e0
TTN
4110(defun vc-annotate-toggle-annotation-visibility ()
4111 "Toggle whether or not the annotation is visible."
4112 (interactive)
4113 (funcall (if (memq 'vc-annotate-annotation buffer-invisibility-spec)
4114 'remove-from-invisibility-spec
4115 'add-to-invisibility-spec)
4116 'vc-annotate-annotation)
4117 (force-window-update (current-buffer)))
4118
97461c84 4119(defun vc-annotate-display-default (ratio)
6f1ecae4 4120 "Display the output of \\[vc-annotate] using the default color range.
97461c84
SM
4121The color range is given by `vc-annotate-color-map', scaled by RATIO.
4122The current time is used as the offset."
4123 (interactive (progn (kill-local-variable 'vc-annotate-color-map) '(1.0)))
f80f7bc2 4124 (message "Redisplaying annotation...")
97461c84 4125 (vc-annotate-display ratio)
f80f7bc2 4126 (message "Redisplaying annotation...done"))
7d2d9482 4127
97461c84
SM
4128(defun vc-annotate-oldest-in-map (color-map)
4129 "Return the oldest time in the COLOR-MAP."
4130 ;; Since entries should be sorted, we can just use the last one.
4131 (caar (last color-map)))
6149bbfb 4132
5731a8e0
TTN
4133(defun vc-annotate-get-time-set-line-props ()
4134 (let ((bol (point))
4135 (date (vc-call-backend vc-annotate-backend 'annotate-time))
4136 (inhibit-read-only t))
f605fc58 4137 (assert (>= (point) bol))
5731a8e0
TTN
4138 (put-text-property bol (point) 'invisible 'vc-annotate-annotation)
4139 date))
4140
75665141 4141(defun vc-annotate-display-autoscale (&optional full)
946b248f 4142 "Highlight the output of \\[vc-annotate] using an autoscaled color map.
6f1ecae4 4143Autoscaling means that the map is scaled from the current time to the
f36e4afe 4144oldest annotation in the buffer, or, with prefix argument FULL, to
6f1ecae4 4145cover the range from the oldest annotation to the newest."
f36e4afe 4146 (interactive "P")
75665141
AS
4147 (let ((newest 0.0)
4148 (oldest 999999.) ;Any CVS users at the founding of Rome?
4149 (current (vc-annotate-convert-time (current-time)))
4150 date)
4151 (message "Redisplaying annotation...")
4152 ;; Run through this file and find the oldest and newest dates annotated.
4153 (save-excursion
4154 (goto-char (point-min))
7c33af85 4155 (while (not (eobp))
5731a8e0 4156 (when (setq date (vc-annotate-get-time-set-line-props))
7c33af85
SM
4157 (if (> date newest)
4158 (setq newest date))
4159 (if (< date oldest)
4160 (setq oldest date)))
4161 (forward-line 1)))
75665141 4162 (vc-annotate-display
97461c84
SM
4163 (/ (- (if full newest current) oldest)
4164 (vc-annotate-oldest-in-map vc-annotate-color-map))
75665141 4165 (if full newest))
99cb8c8b
SS
4166 (message "Redisplaying annotation...done \(%s\)"
4167 (if full
4168 (format "Spanned from %.1f to %.1f days old"
75665141
AS
4169 (- current oldest)
4170 (- current newest))
4171 (format "Spanned to %.1f days old" (- current oldest))))))
4172
4173;; Menu -- Using easymenu.el
04864eb0
SM
4174(easy-menu-define vc-annotate-mode-menu vc-annotate-mode-map
4175 "VC Annotate Display Menu"
4176 `("VC-Annotate"
da7c8a12 4177 ["By Color Map Range" (unless (null vc-annotate-display-mode)
04864eb0
SM
4178 (setq vc-annotate-display-mode nil)
4179 (vc-annotate-display-select))
4180 :style toggle :selected (null vc-annotate-display-mode)]
97461c84 4181 ,@(let ((oldest-in-map (vc-annotate-oldest-in-map vc-annotate-color-map)))
04864eb0
SM
4182 (mapcar (lambda (element)
4183 (let ((days (* element oldest-in-map)))
07a95b81
SM
4184 `[,(format "Span %.1f days" days)
4185 (vc-annotate-display-select nil ,days)
4186 :style toggle :selected
4187 (eql vc-annotate-display-mode ,days) ]))
04864eb0
SM
4188 vc-annotate-menu-elements))
4189 ["Span ..."
07a95b81
SM
4190 (vc-annotate-display-select
4191 nil (float (string-to-number (read-string "Span how many days? "))))]
04864eb0
SM
4192 "--"
4193 ["Span to Oldest"
4194 (unless (eq vc-annotate-display-mode 'scale)
4195 (vc-annotate-display-select nil 'scale))
df04e22c 4196 :help
f3ff0fe9 4197 "Use an autoscaled color map from the oldest annotation to the current time"
04864eb0
SM
4198 :style toggle :selected
4199 (eq vc-annotate-display-mode 'scale)]
4200 ["Span Oldest->Newest"
4201 (unless (eq vc-annotate-display-mode 'fullscale)
4202 (vc-annotate-display-select nil 'fullscale))
df04e22c 4203 :help
f3ff0fe9 4204 "Use an autoscaled color map from the oldest to the newest annotation"
04864eb0
SM
4205 :style toggle :selected
4206 (eq vc-annotate-display-mode 'fullscale)]
4207 "--"
f3ff0fe9 4208 ["Toggle annotation visibility" vc-annotate-toggle-annotation-visibility
df04e22c 4209 :help
f3ff0fe9
DN
4210 "Toggle whether the annotation is visible or not"]
4211 ["Annotate previous revision" vc-annotate-prev-revision
4212 :help "Visit the annotation of the revision previous to this one"]
4213 ["Annotate next revision" vc-annotate-next-revision
4214 :help "Visit the annotation of the revision after this one"]
4215 ["Annotate revision at line" vc-annotate-revision-at-line
df04e22c 4216 :help
f3ff0fe9
DN
4217 "Visit the annotation of the revision identified in the current line"]
4218 ["Annotate revision previous to line" vc-annotate-revision-previous-to-line
4219 :help "Visit the annotation of the revision before the revision at line"]
4220 ["Annotate latest revision" vc-annotate-working-revision
4221 :help "Visit the annotation of the working revision of this file"]
4222 ["Show log of revision at line" vc-annotate-show-log-revision-at-line
4223 :help "Visit the log of the revision at line"]
4224 ["Show diff of revision at line" vc-annotate-show-diff-revision-at-line
df04e22c 4225 :help
f3ff0fe9
DN
4226 "Visit the diff of the revision at line from its previous revision"]
4227 ["Visit revision at line" vc-annotate-find-revision-at-line
4228 :help "Visit the revision identified in the current line"]))
75665141
AS
4229
4230(defun vc-annotate-display-select (&optional buffer mode)
6f1ecae4
AS
4231 "Highlight the output of \\[vc-annotate].
4232By default, the current buffer is highlighted, unless overridden by
4233BUFFER. `vc-annotate-display-mode' specifies the highlighting mode to
4234use; you may override this using the second optional arg MODE."
4235 (interactive)
75665141 4236 (if mode (setq vc-annotate-display-mode mode))
8a8f8697 4237 (pop-to-buffer (or buffer (current-buffer)))
f66a6225 4238 (cond ((null vc-annotate-display-mode)
07a95b81
SM
4239 ;; The ratio is global, thus relative to the global color-map.
4240 (kill-local-variable 'vc-annotate-color-map)
97461c84
SM
4241 (vc-annotate-display-default (or vc-annotate-ratio 1.0)))
4242 ;; One of the auto-scaling modes
f66a6225 4243 ((eq vc-annotate-display-mode 'scale)
7c33af85 4244 (vc-exec-after `(vc-annotate-display-autoscale)))
f66a6225 4245 ((eq vc-annotate-display-mode 'fullscale)
7c33af85 4246 (vc-exec-after `(vc-annotate-display-autoscale t)))
75665141
AS
4247 ((numberp vc-annotate-display-mode) ; A fixed number of days lookback
4248 (vc-annotate-display-default
97461c84
SM
4249 (/ vc-annotate-display-mode
4250 (vc-annotate-oldest-in-map vc-annotate-color-map))))
f66a6225
SM
4251 (t (error "No such display mode: %s"
4252 vc-annotate-display-mode))))
0e362f54 4253
7d2d9482 4254;;;###autoload
bae9f9e3 4255(defun vc-annotate (file rev &optional display-mode buf move-point-to)
aa406465 4256 "Display the edit history of the current file using colors.
1cec418c
AS
4257
4258This command creates a buffer that shows, for each line of the current
aa406465 4259file, when it was last edited and by whom. Additionally, colors are
1cec418c 4260used to show the age of each line--blue means oldest, red means
aa406465 4261youngest, and intermediate colors indicate intermediate ages. By
1cec418c
AS
4262default, the time scale stretches back one year into the past;
4263everything that is older than that is shown in blue.
4264
4265With a prefix argument, this command asks two questions in the
ac3f4c6f
ER
4266minibuffer. First, you may enter a revision number; then the buffer
4267displays and annotates that revision instead of the working revision
eb407e67 4268\(type RET in the minibuffer to leave that default unchanged). Then,
ecd50f65
AS
4269you are prompted for the time span in days which the color range
4270should cover. For example, a time span of 20 days means that changes
4271over the past 20 days are shown in red to blue, according to their
4272age, and everything that is older than that is shown in blue.
1cec418c 4273
bae9f9e3
DN
4274If MOVE-POINT-TO is given, move the point to that line.
4275
1cec418c 4276Customization variables:
7d2d9482
RS
4277
4278`vc-annotate-menu-elements' customizes the menu elements of the
a7192ddb
SM
4279mode-specific menu. `vc-annotate-color-map' and
4280`vc-annotate-very-old-color' define the mapping of time to colors.
4281`vc-annotate-background' specifies the background color."
04864eb0
SM
4282 (interactive
4283 (save-current-buffer
4284 (vc-ensure-vc-buffer)
4285 (list buffer-file-name
ac3f4c6f 4286 (let ((def (vc-working-revision buffer-file-name)))
04864eb0
SM
4287 (if (null current-prefix-arg) def
4288 (read-string
ac3f4c6f 4289 (format "Annotate from revision (default %s): " def)
04864eb0
SM
4290 nil nil def)))
4291 (if (null current-prefix-arg)
4292 vc-annotate-display-mode
4293 (float (string-to-number
4294 (read-string "Annotate span days (default 20): "
4295 nil nil "20")))))))
b6909007 4296 (vc-ensure-vc-buffer)
04864eb0
SM
4297 (setq vc-annotate-display-mode display-mode) ;Not sure why. --Stef
4298 (let* ((temp-buffer-name (format "*Annotate %s (rev %s)*" (buffer-name) rev))
1867d8cb
TTN
4299 (temp-buffer-show-function 'vc-annotate-display-select)
4300 ;; If BUF is specified, we presume the caller maintains current line,
4301 ;; so we don't need to do it here. This implementation may give
4302 ;; strange results occasionally in the case of REV != WORKFILE-REV.
bae9f9e3 4303 (current-line (or move-point-to (unless buf (line-number-at-pos)))))
afe35502 4304 (message "Annotating...")
04864eb0
SM
4305 ;; If BUF is specified it tells in which buffer we should put the
4306 ;; annotations. This is used when switching annotations to another
4307 ;; revision, so we should update the buffer's name.
4308 (if buf (with-current-buffer buf
4309 (rename-buffer temp-buffer-name t)
4310 ;; In case it had to be uniquified.
4311 (setq temp-buffer-name (buffer-name))))
46e33aee 4312 (with-output-to-temp-buffer temp-buffer-name
da7c8a12
S
4313 (vc-call annotate-command file (get-buffer temp-buffer-name) rev)
4314 ;; we must setup the mode first, and then set our local
4315 ;; variables before the show-function is called at the exit of
4316 ;; with-output-to-temp-buffer
4317 (with-current-buffer temp-buffer-name
4318 (if (not (equal major-mode 'vc-annotate-mode))
4319 (vc-annotate-mode))
4320 (set (make-local-variable 'vc-annotate-backend) (vc-backend file))
4321 (set (make-local-variable 'vc-annotate-parent-file) file)
4322 (set (make-local-variable 'vc-annotate-parent-rev) rev)
4323 (set (make-local-variable 'vc-annotate-parent-display-mode)
4324 display-mode)))
cd42ec7d 4325
ebaac04d
SM
4326 (with-current-buffer temp-buffer-name
4327 (vc-exec-after
4328 `(progn
4329 ;; Ideally, we'd rather not move point if the user has already
4330 ;; moved it elsewhere, but really point here is not the position
4331 ;; of the user's cursor :-(
4332 (when ,current-line ;(and (bobp))
86e80023 4333 (goto-line ,current-line)
01823b77 4334 (setq vc-sentinel-movepoint (point)))
ebaac04d
SM
4335 (unless (active-minibuffer-window)
4336 (message "Annotating... done")))))))
7d2d9482 4337
ac3f4c6f
ER
4338(defun vc-annotate-prev-revision (prefix)
4339 "Visit the annotation of the revision previous to this one.
1b5a7343 4340
ac3f4c6f
ER
4341With a numeric prefix argument, annotate the revision that many
4342revisions previous."
1b5a7343 4343 (interactive "p")
ac3f4c6f 4344 (vc-annotate-warp-revision (- 0 prefix)))
1b5a7343 4345
ac3f4c6f
ER
4346(defun vc-annotate-next-revision (prefix)
4347 "Visit the annotation of the revision after this one.
1b5a7343 4348
ac3f4c6f
ER
4349With a numeric prefix argument, annotate the revision that many
4350revisions after."
1b5a7343 4351 (interactive "p")
ac3f4c6f 4352 (vc-annotate-warp-revision prefix))
1b5a7343 4353
ac3f4c6f
ER
4354(defun vc-annotate-working-revision ()
4355 "Visit the annotation of the working revision of this file."
1b5a7343
AS
4356 (interactive)
4357 (if (not (equal major-mode 'vc-annotate-mode))
4358 (message "Cannot be invoked outside of a vc annotate buffer")
ac3f4c6f 4359 (let ((warp-rev (vc-working-revision vc-annotate-parent-file)))
1b5a7343 4360 (if (equal warp-rev vc-annotate-parent-rev)
ac3f4c6f
ER
4361 (message "Already at revision %s" warp-rev)
4362 (vc-annotate-warp-revision warp-rev)))))
1b5a7343
AS
4363
4364(defun vc-annotate-extract-revision-at-line ()
4365 "Extract the revision number of the current line."
4366 ;; This function must be invoked from a buffer in vc-annotate-mode
1b5a7343
AS
4367 (vc-call-backend vc-annotate-backend 'annotate-extract-revision-at-line))
4368
4369(defun vc-annotate-revision-at-line ()
ac3f4c6f 4370 "Visit the annotation of the revision identified in the current line."
1b5a7343
AS
4371 (interactive)
4372 (if (not (equal major-mode 'vc-annotate-mode))
4373 (message "Cannot be invoked outside of a vc annotate buffer")
4374 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
4375 (if (not rev-at-line)
4376 (message "Cannot extract revision number from the current line")
4377 (if (equal rev-at-line vc-annotate-parent-rev)
ac3f4c6f
ER
4378 (message "Already at revision %s" rev-at-line)
4379 (vc-annotate-warp-revision rev-at-line))))))
1b5a7343 4380
f3ff0fe9
DN
4381(defun vc-annotate-find-revision-at-line ()
4382 "Visit the revision identified in the current line."
4383 (interactive)
4384 (if (not (equal major-mode 'vc-annotate-mode))
4385 (message "Cannot be invoked outside of a vc annotate buffer")
4386 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
4387 (if (not rev-at-line)
4388 (message "Cannot extract revision number from the current line")
4389 (vc-revision-other-window rev-at-line)))))
4390
1b5a7343 4391(defun vc-annotate-revision-previous-to-line ()
ac3f4c6f 4392 "Visit the annotation of the revision before the revision at line."
1b5a7343
AS
4393 (interactive)
4394 (if (not (equal major-mode 'vc-annotate-mode))
4395 (message "Cannot be invoked outside of a vc annotate buffer")
4396 (let ((rev-at-line (vc-annotate-extract-revision-at-line))
4397 (prev-rev nil))
4398 (if (not rev-at-line)
4399 (message "Cannot extract revision number from the current line")
4400 (setq prev-rev
ac3f4c6f
ER
4401 (vc-call previous-revision vc-annotate-parent-file rev-at-line))
4402 (vc-annotate-warp-revision prev-rev)))))
1b5a7343
AS
4403
4404(defun vc-annotate-show-log-revision-at-line ()
ac3f4c6f 4405 "Visit the log of the revision at line."
1b5a7343
AS
4406 (interactive)
4407 (if (not (equal major-mode 'vc-annotate-mode))
4408 (message "Cannot be invoked outside of a vc annotate buffer")
4409 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
4410 (if (not rev-at-line)
4411 (message "Cannot extract revision number from the current line")
4412 (vc-print-log rev-at-line)))))
4413
4414(defun vc-annotate-show-diff-revision-at-line ()
ac3f4c6f 4415 "Visit the diff of the revision at line from its previous revision."
1b5a7343
AS
4416 (interactive)
4417 (if (not (equal major-mode 'vc-annotate-mode))
4418 (message "Cannot be invoked outside of a vc annotate buffer")
4419 (let ((rev-at-line (vc-annotate-extract-revision-at-line))
4420 (prev-rev nil))
4421 (if (not rev-at-line)
4422 (message "Cannot extract revision number from the current line")
4423 (setq prev-rev
ac3f4c6f 4424 (vc-call previous-revision vc-annotate-parent-file rev-at-line))
1b5a7343 4425 (if (not prev-rev)
ac3f4c6f 4426 (message "Cannot diff from any revision prior to %s" rev-at-line)
1b5a7343 4427 (save-window-excursion
a7192ddb
SM
4428 (vc-diff-internal nil (list vc-annotate-parent-file)
4429 prev-rev rev-at-line))
1b5a7343
AS
4430 (switch-to-buffer "*vc-diff*"))))))
4431
ac3f4c6f
ER
4432(defun vc-annotate-warp-revision (revspec)
4433 "Annotate the revision described by REVSPEC.
1b5a7343 4434
ac3f4c6f 4435If REVSPEC is a positive integer, warp that many revisions
1b5a7343 4436forward, if possible, otherwise echo a warning message. If
ac3f4c6f 4437REVSPEC is a negative integer, warp that many revisions backward,
1b5a7343
AS
4438if possible, otherwise echo a warning message. If REVSPEC is a
4439string, then it describes a revision number, so warp to that
4440revision."
4441 (if (not (equal major-mode 'vc-annotate-mode))
4442 (message "Cannot be invoked outside of a vc annotate buffer")
da7c8a12
S
4443 (let* ((buf (current-buffer))
4444 (oldline (line-number-at-pos))
1b5a7343
AS
4445 (revspeccopy revspec)
4446 (newrev nil))
4447 (cond
4448 ((and (integerp revspec) (> revspec 0))
4449 (setq newrev vc-annotate-parent-rev)
4450 (while (and (> revspec 0) newrev)
ac3f4c6f 4451 (setq newrev (vc-call next-revision
1b5a7343
AS
4452 vc-annotate-parent-file newrev))
4453 (setq revspec (1- revspec)))
4454 (if (not newrev)
ac3f4c6f 4455 (message "Cannot increment %d revisions from revision %s"
1b5a7343
AS
4456 revspeccopy vc-annotate-parent-rev)))
4457 ((and (integerp revspec) (< revspec 0))
4458 (setq newrev vc-annotate-parent-rev)
4459 (while (and (< revspec 0) newrev)
ac3f4c6f 4460 (setq newrev (vc-call previous-revision
1b5a7343
AS
4461 vc-annotate-parent-file newrev))
4462 (setq revspec (1+ revspec)))
4463 (if (not newrev)
ac3f4c6f 4464 (message "Cannot decrement %d revisions from revision %s"
1b5a7343
AS
4465 (- 0 revspeccopy) vc-annotate-parent-rev)))
4466 ((stringp revspec) (setq newrev revspec))
ac3f4c6f 4467 (t (error "Invalid argument to vc-annotate-warp-revision")))
1b5a7343 4468 (when newrev
04864eb0
SM
4469 (vc-annotate vc-annotate-parent-file newrev
4470 vc-annotate-parent-display-mode
bae9f9e3
DN
4471 buf
4472 ;; Pass the current line so that vc-annotate will
4473 ;; place the point in the line.
4474 (min oldline (progn (goto-char (point-max))
4475 (forward-line -1)
4476 (line-number-at-pos))))))))
1b5a7343 4477
f70419a8 4478(defun vc-annotate-compcar (threshold a-list)
6f1ecae4
AS
4479 "Test successive cons cells of A-LIST against THRESHOLD.
4480Return the first cons cell with a car that is not less than THRESHOLD,
4481nil if no such cell exists."
f70419a8
RS
4482 (let ((i 1)
4483 (tmp-cons (car a-list)))
4484 (while (and tmp-cons (< (car tmp-cons) threshold))
4485 (setq tmp-cons (car (nthcdr i a-list)))
4486 (setq i (+ i 1)))
4487 tmp-cons)) ; Return the appropriate value
4488
75665141 4489(defun vc-annotate-convert-time (time)
6f1ecae4
AS
4490 "Convert a time value to a floating-point number of days.
4491The argument TIME is a list as returned by `current-time' or
4492`encode-time', only the first two elements of that list are considered."
75665141
AS
4493 (/ (+ (* (float (car time)) (lsh 1 16)) (cadr time)) 24 3600))
4494
4495(defun vc-annotate-difference (&optional offset)
6f1ecae4
AS
4496 "Return the time span in days to the next annotation.
4497This calls the backend function annotate-time, and returns the
4498difference in days between the time returned and the current time,
4499or OFFSET if present."
5731a8e0 4500 (let ((next-time (vc-annotate-get-time-set-line-props)))
75665141 4501 (if next-time
99cb8c8b 4502 (- (or offset
75665141
AS
4503 (vc-call-backend vc-annotate-backend 'annotate-current-time))
4504 next-time))))
4505
4506(defun vc-default-annotate-current-time (backend)
4507 "Return the current time, encoded as fractional days."
4508 (vc-annotate-convert-time (current-time)))
99cb8c8b 4509
07577777
JPW
4510(defvar vc-annotate-offset nil)
4511
97461c84 4512(defun vc-annotate-display (ratio &optional offset)
6f1ecae4 4513 "Highlight `vc-annotate' output in the current buffer.
97461c84 4514RATIO, is the expansion that should be applied to `vc-annotate-color-map'.
bf142f28 4515The annotations are relative to the current time, unless overridden by OFFSET."
97461c84
SM
4516 (if (/= ratio 1.0)
4517 (set (make-local-variable 'vc-annotate-color-map)
4518 (mapcar (lambda (elem) (cons (* (car elem) ratio) (cdr elem)))
4519 vc-annotate-color-map)))
f66a6225
SM
4520 (set (make-local-variable 'vc-annotate-offset) offset)
4521 (font-lock-mode 1))
4522
f66a6225 4523(defun vc-annotate-lines (limit)
7c33af85
SM
4524 (while (< (point) limit)
4525 (let ((difference (vc-annotate-difference vc-annotate-offset))
4526 (start (point))
4527 (end (progn (forward-line 1) (point))))
4528 (when difference
4529 (let* ((color (or (vc-annotate-compcar difference vc-annotate-color-map)
4530 (cons nil vc-annotate-very-old-color)))
4531 ;; substring from index 1 to remove any leading `#' in the name
4532 (face-name (concat "vc-annotate-face-"
4533 (if (string-equal
4534 (substring (cdr color) 0 1) "#")
4535 (substring (cdr color) 1)
4536 (cdr color))))
4537 ;; Make the face if not done.
4538 (face (or (intern-soft face-name)
4539 (let ((tmp-face (make-face (intern face-name))))
4540 (set-face-foreground tmp-face (cdr color))
4541 (if vc-annotate-background
4542 (set-face-background tmp-face
4543 vc-annotate-background))
4544 tmp-face)))) ; Return the face
4545 (put-text-property start end 'face face)))))
4546 ;; Pretend to font-lock there were no matches.
4547 nil)
7d2d9482 4548\f
594722a8
ER
4549
4550;; Set up key bindings for use while editing log messages
4551
d7b60083 4552(defun vc-log-edit (fileset)
928ef6d9 4553 "Set up `log-edit' for use with VC on FILE."
099bd78a 4554 (setq default-directory
d7b60083 4555 (with-current-buffer vc-parent-buffer default-directory))
93a142e1
DN
4556 (log-edit 'vc-finish-logentry
4557 nil
4558 `((log-edit-listfun . (lambda () ',fileset))
4559 (log-edit-diff-function . (lambda () (vc-diff nil)))))
d7b60083 4560 (set (make-local-variable 'vc-log-fileset) fileset)
ac3f4c6f 4561 (make-local-variable 'vc-log-revision)
099bd78a 4562 (set-buffer-modified-p nil)
0e362f54 4563 (setq buffer-file-name nil))
594722a8 4564
ec402ad4 4565;; These things should probably be generally available
594722a8 4566
2f119435
AS
4567(defun vc-file-tree-walk (dirname func &rest args)
4568 "Walk recursively through DIRNAME.
0e362f54 4569Invoke FUNC f ARGS on each VC-managed file f underneath it."
2f119435
AS
4570 (vc-file-tree-walk-internal (expand-file-name dirname) func args)
4571 (message "Traversing directory %s...done" dirname))
02da6253
PE
4572
4573(defun vc-file-tree-walk-internal (file func args)
4574 (if (not (file-directory-p file))
0e362f54 4575 (if (vc-backend file) (apply func file args))
993a1a44 4576 (message "Traversing directory %s..." (abbreviate-file-name file))
02da6253
PE
4577 (let ((dir (file-name-as-directory file)))
4578 (mapcar
0e362f54 4579 (lambda (f) (or
d1a607bc
SM
4580 (string-equal f ".")
4581 (string-equal f "..")
4582 (member f vc-directory-exclusion-list)
4583 (let ((dirf (expand-file-name f dir)))
4584 (or
4585 (file-symlink-p dirf) ;; Avoid possible loops.
4586 (vc-file-tree-walk-internal dirf func args)))))
02da6253 4587 (directory-files dir)))))
594722a8
ER
4588
4589(provide 'vc)
4590
ec402ad4
SM
4591;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
4592;;
ec402ad4
SM
4593;; These may be useful to anyone who has to debug or extend the package.
4594;; (Note that this information corresponds to versions 5.x. Some of it
4595;; might have been invalidated by the additions to support branching
4596;; and RCS keyword lookup. AS, 1995/03/24)
4597;;
4598;; A fundamental problem in VC is that there are time windows between
4599;; vc-next-action's computations of the file's version-control state and
4600;; the actions that change it. This is a window open to lossage in a
4601;; multi-user environment; someone else could nip in and change the state
4602;; of the master during it.
4603;;
4604;; The performance problem is that rlog/prs calls are very expensive; we want
4605;; to avoid them as much as possible.
4606;;
4607;; ANALYSIS:
4608;;
4609;; The performance problem, it turns out, simplifies in practice to the
4610;; problem of making vc-state fast. The two other functions that call
4611;; prs/rlog will not be so commonly used that the slowdown is a problem; one
4612;; makes snapshots, the other deletes the calling user's last change in the
4613;; master.
4614;;
4615;; The race condition implies that we have to either (a) lock the master
4616;; during the entire execution of vc-next-action, or (b) detect and
4617;; recover from errors resulting from dispatch on an out-of-date state.
4618;;
4619;; Alternative (a) appears to be infeasible. The problem is that we can't
4620;; guarantee that the lock will ever be removed. Suppose a user starts a
4621;; checkin, the change message buffer pops up, and the user, having wandered
4622;; off to do something else, simply forgets about it?
4623;;
4624;; Alternative (b), on the other hand, works well with a cheap way to speed up
4625;; vc-state. Usually, if a file is registered, we can read its locked/
4626;; unlocked state and its current owner from its permissions.
4627;;
4628;; This shortcut will fail if someone has manually changed the workfile's
4629;; permissions; also if developers are munging the workfile in several
4630;; directories, with symlinks to a master (in this latter case, the
4631;; permissions shortcut will fail to detect a lock asserted from another
4632;; directory).
4633;;
4634;; Note that these cases correspond exactly to the errors which could happen
4635;; because of a competing checkin/checkout race in between two instances of
4636;; vc-next-action.
4637;;
4638;; For VC's purposes, a workfile/master pair may have the following states:
4639;;
4640;; A. Unregistered. There is a workfile, there is no master.
4641;;
4642;; B. Registered and not locked by anyone.
4643;;
4644;; C. Locked by calling user and unchanged.
4645;;
4646;; D. Locked by the calling user and changed.
4647;;
4648;; E. Locked by someone other than the calling user.
4649;;
4650;; This makes for 25 states and 20 error conditions. Here's the matrix:
4651;;
4652;; VC's idea of state
4653;; |
4654;; V Actual state RCS action SCCS action Effect
4655;; A B C D E
4656;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
4657;; B 5 . 6 7 8 co -l get -e checkout
4658;; C 9 10 . 11 12 co -u unget; get revert
4659;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
4660;; E 17 18 19 20 . rcs -u -M -l unget -n ; get -g steal lock
4661;;
4662;; All commands take the master file name as a last argument (not shown).
4663;;
4664;; In the discussion below, a "self-race" is a pathological situation in
4665;; which VC operations are being attempted simultaneously by two or more
4666;; Emacsen running under the same username.
4667;;
4668;; The vc-next-action code has the following windows:
4669;;
4670;; Window P:
4671;; Between the check for existence of a master file and the call to
4672;; admin/checkin in vc-buffer-admin (apparent state A). This window may
4673;; never close if the initial-comment feature is on.
4674;;
4675;; Window Q:
4676;; Between the call to vc-workfile-unchanged-p in and the immediately
4677;; following revert (apparent state C).
4678;;
4679;; Window R:
4680;; Between the call to vc-workfile-unchanged-p in and the following
4681;; checkin (apparent state D). This window may never close.
4682;;
4683;; Window S:
4684;; Between the unlock and the immediately following checkout during a
4685;; revert operation (apparent state C). Included in window Q.
4686;;
4687;; Window T:
4688;; Between vc-state and the following checkout (apparent state B).
4689;;
4690;; Window U:
4691;; Between vc-state and the following revert (apparent state C).
4692;; Includes windows Q and S.
4693;;
4694;; Window V:
4695;; Between vc-state and the following checkin (apparent state
4696;; D). This window may never be closed if the user fails to complete the
4697;; checkin message. Includes window R.
4698;;
4699;; Window W:
4700;; Between vc-state and the following steal-lock (apparent
4701;; state E). This window may never close if the user fails to complete
4702;; the steal-lock message. Includes window X.
4703;;
4704;; Window X:
4705;; Between the unlock and the immediately following re-lock during a
4706;; steal-lock operation (apparent state E). This window may never close
4707;; if the user fails to complete the steal-lock message.
4708;;
4709;; Errors:
4710;;
4711;; Apparent state A ---
4712;;
4713;; 1. File looked unregistered but is actually registered and not locked.
4714;;
4715;; Potential cause: someone else's admin during window P, with
4716;; caller's admin happening before their checkout.
4717;;
4718;; RCS: Prior to version 5.6.4, ci fails with message
4719;; "no lock set by <user>". From 5.6.4 onwards, VC uses the new
4720;; ci -i option and the message is "<file>,v: already exists".
4721;; SCCS: admin will fail with error (ad19).
4722;;
4723;; We can let these errors be passed up to the user.
4724;;
4725;; 2. File looked unregistered but is actually locked by caller, unchanged.
4726;;
4727;; Potential cause: self-race during window P.
4728;;
4729;; RCS: Prior to version 5.6.4, reverts the file to the last saved
4730;; version and unlocks it. From 5.6.4 onwards, VC uses the new
4731;; ci -i option, failing with message "<file>,v: already exists".
4732;; SCCS: will fail with error (ad19).
4733;;
4734;; Either of these consequences is acceptable.
4735;;
4736;; 3. File looked unregistered but is actually locked by caller, changed.
4737;;
4738;; Potential cause: self-race during window P.
4739;;
4740;; RCS: Prior to version 5.6.4, VC registers the caller's workfile as
4741;; a delta with a null change comment (the -t- switch will be
4742;; ignored). From 5.6.4 onwards, VC uses the new ci -i option,
4743;; failing with message "<file>,v: already exists".
4744;; SCCS: will fail with error (ad19).
4745;;
4746;; 4. File looked unregistered but is locked by someone else.
0e362f54 4747;;;
ec402ad4
SM
4748;; Potential cause: someone else's admin during window P, with
4749;; caller's admin happening *after* their checkout.
4750;;
4751;; RCS: Prior to version 5.6.4, ci fails with a
4752;; "no lock set by <user>" message. From 5.6.4 onwards,
4753;; VC uses the new ci -i option, failing with message
4754;; "<file>,v: already exists".
4755;; SCCS: will fail with error (ad19).
4756;;
4757;; We can let these errors be passed up to the user.
4758;;
4759;; Apparent state B ---
4760;;
4761;; 5. File looked registered and not locked, but is actually unregistered.
4762;;
4763;; Potential cause: master file got nuked during window P.
4764;;
4765;; RCS: will fail with "RCS/<file>: No such file or directory"
4766;; SCCS: will fail with error ut4.
4767;;
4768;; We can let these errors be passed up to the user.
4769;;
4770;; 6. File looked registered and not locked, but is actually locked by the
4771;; calling user and unchanged.
4772;;
4773;; Potential cause: self-race during window T.
4774;;
4775;; RCS: in the same directory as the previous workfile, co -l will fail
4776;; with "co error: writable foo exists; checkout aborted". In any other
4777;; directory, checkout will succeed.
4778;; SCCS: will fail with ge17.
4779;;
4780;; Either of these consequences is acceptable.
4781;;
4782;; 7. File looked registered and not locked, but is actually locked by the
4783;; calling user and changed.
4784;;
4785;; As case 6.
4786;;
4787;; 8. File looked registered and not locked, but is actually locked by another
4788;; user.
4789;;
4790;; Potential cause: someone else checks it out during window T.
4791;;
4792;; RCS: co error: revision 1.3 already locked by <user>
4793;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
4794;;
4795;; We can let these errors be passed up to the user.
4796;;
4797;; Apparent state C ---
4798;;
4799;; 9. File looks locked by calling user and unchanged, but is unregistered.
4800;;
4801;; As case 5.
4802;;
4803;; 10. File looks locked by calling user and unchanged, but is actually not
4804;; locked.
4805;;
4806;; Potential cause: a self-race in window U, or by the revert's
4807;; landing during window X of some other user's steal-lock or window S
4808;; of another user's revert.
4809;;
4810;; RCS: succeeds, refreshing the file from the identical version in
4811;; the master.
4812;; SCCS: fails with error ut4 (p file nonexistent).
4813;;
4814;; Either of these consequences is acceptable.
4815;;
4816;; 11. File is locked by calling user. It looks unchanged, but is actually
4817;; changed.
4818;;
4819;; Potential cause: the file would have to be touched by a self-race
4820;; during window Q.
4821;;
4822;; The revert will succeed, removing whatever changes came with
4823;; the touch. It is theoretically possible that work could be lost.
4824;;
4825;; 12. File looks like it's locked by the calling user and unchanged, but
4826;; it's actually locked by someone else.
4827;;
4828;; Potential cause: a steal-lock in window V.
4829;;
4830;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
4831;; SCCS: fails with error un2
4832;;
4833;; We can pass these errors up to the user.
4834;;
4835;; Apparent state D ---
4836;;
4837;; 13. File looks like it's locked by the calling user and changed, but it's
4838;; actually unregistered.
4839;;
4840;; Potential cause: master file got nuked during window P.
4841;;
4842;; RCS: Prior to version 5.6.4, checks in the user's version as an
4843;; initial delta. From 5.6.4 onwards, VC uses the new ci -j
4844;; option, failing with message "no such file or directory".
4845;; SCCS: will fail with error ut4.
4846;;
4847;; This case is kind of nasty. Under RCS prior to version 5.6.4,
4848;; VC may fail to detect the loss of previous version information.
4849;;
4850;; 14. File looks like it's locked by the calling user and changed, but it's
4851;; actually unlocked.
4852;;
4853;; Potential cause: self-race in window V, or the checkin happening
4854;; during the window X of someone else's steal-lock or window S of
4855;; someone else's revert.
4856;;
4857;; RCS: ci will fail with "no lock set by <user>".
4858;; SCCS: delta will fail with error ut4.
4859;;
4860;; 15. File looks like it's locked by the calling user and changed, but it's
4861;; actually locked by the calling user and unchanged.
4862;;
4863;; Potential cause: another self-race --- a whole checkin/checkout
4864;; sequence by the calling user would have to land in window R.
4865;;
4866;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
4867;; RCS: reverts to the file state as of the second user's checkin, leaving
4868;; the file unlocked.
4869;;
4870;; It is theoretically possible that work could be lost under RCS.
4871;;
4872;; 16. File looks like it's locked by the calling user and changed, but it's
4873;; actually locked by a different user.
4874;;
4875;; RCS: ci error: no lock set by <user>
4876;; SCCS: unget will fail with error un2
4877;;
4878;; We can pass these errors up to the user.
4879;;
4880;; Apparent state E ---
4881;;
4882;; 17. File looks like it's locked by some other user, but it's actually
4883;; unregistered.
4884;;
4885;; As case 13.
4886;;
4887;; 18. File looks like it's locked by some other user, but it's actually
4888;; unlocked.
4889;;
4890;; Potential cause: someone released a lock during window W.
4891;;
4892;; RCS: The calling user will get the lock on the file.
4893;; SCCS: unget -n will fail with cm4.
4894;;
4895;; Either of these consequences will be OK.
4896;;
4897;; 19. File looks like it's locked by some other user, but it's actually
4898;; locked by the calling user and unchanged.
4899;;
4900;; Potential cause: the other user relinquishing a lock followed by
4901;; a self-race, both in window W.
4902;;
4903;; Under both RCS and SCCS, both unlock and lock will succeed, making
4904;; the sequence a no-op.
4905;;
4906;; 20. File looks like it's locked by some other user, but it's actually
4907;; locked by the calling user and changed.
4908;;
4909;; As case 19.
4910;;
4911;; PROBLEM CASES:
4912;;
4913;; In order of decreasing severity:
4914;;
4915;; Cases 11 and 15 are the only ones that potentially lose work.
4916;; They would require a self-race for this to happen.
4917;;
4918;; Case 13 in RCS loses information about previous deltas, retaining
4919;; only the information in the current workfile. This can only happen
4920;; if the master file gets nuked in window P.
4921;;
4922;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
4923;; no change comment in the master. This would require a self-race in
4924;; window P or R respectively.
4925;;
4926;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
4927;;
4928;; Unfortunately, it appears to me that no recovery is possible in these
4929;; cases. They don't yield error messages, so there's no way to tell that
4930;; a race condition has occurred.
4931;;
4932;; All other cases don't change either the workfile or the master, and
4933;; trigger command errors which the user will see.
4934;;
4935;; Thus, there is no explicit recovery code.
594722a8 4936
0452b6e7 4937;; arch-tag: ca82c1de-3091-4e26-af92-460abc6213a6
594722a8 4938;;; vc.el ends here