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