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