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