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