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