* log-view.el (log-view-diff-changeset): New function.
[bpt/emacs.git] / lisp / vc.el
1 ;;; vc.el --- drive a version-control system from within Emacs
2
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
5 ;; Free Software Foundation, Inc.
6
7 ;; Author: FSF (see below for full credits)
8 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
9 ;; Keywords: tools
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
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) 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
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25
26 ;;; Credits:
27
28 ;; VC was initially designed and implemented by Eric S. Raymond
29 ;; <esr@thyrsus.com> in 1992. Over the years, many other people have
30 ;; contributed substantial amounts of work to VC. These include:
31 ;;
32 ;; Per Cederqvist <ceder@lysator.liu.se>
33 ;; Paul Eggert <eggert@twinsun.com>
34 ;; Sebastian Kremer <sk@thp.uni-koeln.de>
35 ;; Martin Lorentzson <martinl@gnu.org>
36 ;; Dave Love <fx@gnu.org>
37 ;; Stefan Monnier <monnier@cs.yale.edu>
38 ;; Thien-Thi Nguyen <ttn@gnu.org>
39 ;; Dan Nicolaescu <dann@ics.uci.edu>
40 ;; J.D. Smith <jdsmith@alum.mit.edu>
41 ;; Andre Spiegel <spiegel@gnu.org>
42 ;; Richard Stallman <rms@gnu.org>
43 ;;
44 ;; In July 2007 ESR returned and redesigned the mode to cope better
45 ;; with modern version-control systems that do commits by fileset
46 ;; rather than per individual file.
47 ;;
48 ;; If you maintain a client of the mode or customize it in your .emacs,
49 ;; note that some backend functions which formerly took single file arguments
50 ;; now take a list of files. These include: register, checkin, print-log,
51 ;; rollback, and diff.
52
53 ;;; Commentary:
54
55 ;; This mode is fully documented in the Emacs user's manual.
56 ;;
57 ;; Supported version-control systems presently include CVS, RCS, GNU
58 ;; Arch, Subversion, Bzr, Git, Mercurial, Monotone and SCCS
59 ;; (or its free replacement, CSSC).
60 ;;
61 ;; Some features will not work with old RCS versions. Where
62 ;; appropriate, VC finds out which version you have, and allows or
63 ;; disallows those features (stealing locks, for example, works only
64 ;; from 5.6.2 onwards).
65 ;; Even initial checkins will fail if your RCS version is so old that ci
66 ;; doesn't understand -t-; this has been known to happen to people running
67 ;; NExTSTEP 3.0.
68 ;;
69 ;; You can support the RCS -x option by customizing vc-rcs-master-templates.
70 ;;
71 ;; Proper function of the SCCS diff commands requires the shellscript vcdiff
72 ;; to be installed somewhere on Emacs's path for executables.
73 ;;
74 ;; If your site uses the ChangeLog convention supported by Emacs, the
75 ;; function `log-edit-comment-to-change-log' could prove a useful checkin hook,
76 ;; although you might prefer to use C-c C-a (i.e. `log-edit-insert-changelog')
77 ;; from the commit buffer instead or to set `log-edit-setup-invert'.
78 ;;
79 ;; The vc code maintains some internal state in order to reduce expensive
80 ;; version-control operations to a minimum. Some names are only computed
81 ;; once. If you perform version control operations with the backend while
82 ;; vc's back is turned, or move/rename master files while vc is running,
83 ;; vc may get seriously confused. Don't do these things!
84 ;;
85 ;; Developer's notes on some concurrency issues are included at the end of
86 ;; the file.
87 ;;
88 ;; ADDING SUPPORT FOR OTHER BACKENDS
89 ;;
90 ;; VC can use arbitrary version control systems as a backend. To add
91 ;; support for a new backend named SYS, write a library vc-sys.el that
92 ;; contains functions of the form `vc-sys-...' (note that SYS is in lower
93 ;; case for the function and library names). VC will use that library if
94 ;; you put the symbol SYS somewhere into the list of
95 ;; `vc-handled-backends'. Then, for example, if `vc-sys-registered'
96 ;; returns non-nil for a file, all SYS-specific versions of VC commands
97 ;; will be available for that file.
98 ;;
99 ;; VC keeps some per-file information in the form of properties (see
100 ;; vc-file-set/getprop in vc-hooks.el). The backend-specific functions
101 ;; do not generally need to be aware of these properties. For example,
102 ;; `vc-sys-working-revision' should compute the working revision and
103 ;; return it; it should not look it up in the property, and it needn't
104 ;; store it there either. However, if a backend-specific function does
105 ;; store a value in a property, that value takes precedence over any
106 ;; value that the generic code might want to set (check for uses of
107 ;; the macro `with-vc-properties' in vc.el).
108 ;;
109 ;; In the list of functions below, each identifier needs to be prepended
110 ;; with `vc-sys-'. Some of the functions are mandatory (marked with a
111 ;; `*'), others are optional (`-').
112 ;;
113 ;; BACKEND PROPERTIES
114 ;;
115 ;; * revision-granularity
116 ;;
117 ;; Takes no arguments. Returns either 'file or 'repository. Backends
118 ;; that return 'file have per-file revision numbering; backends
119 ;; that return 'repository have per-repository revision numbering,
120 ;; so a revision level implicitly identifies a changeset
121 ;;
122 ;; STATE-QUERYING FUNCTIONS
123 ;;
124 ;; * registered (file)
125 ;;
126 ;; Return non-nil if FILE is registered in this backend. Both this
127 ;; function as well as `state' should be careful to fail gracefully
128 ;; in the event that the backend executable is absent. It is
129 ;; preferable that this function's body is autoloaded, that way only
130 ;; calling vc-registered does not cause the backend to be loaded
131 ;; (all the vc-FOO-registered functions are called to try to find
132 ;; the controlling backend for FILE.
133 ;;
134 ;; * state (file)
135 ;;
136 ;; Return the current version control state of FILE. For a list of
137 ;; possible values, see `vc-state'. This function should do a full and
138 ;; reliable state computation; it is usually called immediately after
139 ;; C-x v v. If you want to use a faster heuristic when visiting a
140 ;; file, put that into `state-heuristic' below. Note that under most
141 ;; VCSes this won't be called at all, dir-status is used instead.
142 ;;
143 ;; - state-heuristic (file)
144 ;;
145 ;; If provided, this function is used to estimate the version control
146 ;; state of FILE at visiting time. It should be considerably faster
147 ;; than the implementation of `state'. For a list of possible values,
148 ;; see the doc string of `vc-state'.
149 ;;
150 ;; - dir-status (dir update-function)
151 ;;
152 ;; Produce RESULT: a list of lists of the form (FILE VC-STATE EXTRA)
153 ;; for the files in DIR.
154 ;; EXTRA can be used for backend specific information about FILE.
155 ;; If a command needs to be run to compute this list, it should be
156 ;; run asynchronously using (current-buffer) as the buffer for the
157 ;; command. When RESULT is computed, it should be passed back by
158 ;; doing: (funcall UPDATE-FUNCTION RESULT nil).
159 ;; If the backend uses a process filter, hence it produces partial results,
160 ;; they can be passed back by doing:
161 ;; (funcall UPDATE-FUNCTION RESULT t)
162 ;; and then do a (funcall UPDATE-FUNCTION RESULT nil)
163 ;; when all the results have been computed.
164 ;; To provide more backend specific functionality for `vc-dir'
165 ;; the following functions might be needed: `status-extra-headers',
166 ;; `status-printer', `extra-status-menu' and `dir-status-files'.
167 ;;
168 ;; - dir-status-files (dir files default-state update-function)
169 ;;
170 ;; This function is identical to dir-status except that it should
171 ;; only report status for the specified FILES. Also it needs to
172 ;; report on all requested files, including up-to-date or ignored
173 ;; files. If not provided, the default is to consider that the files
174 ;; are in DEFAULT-STATE.
175 ;;
176 ;; - status-extra-headers (dir)
177 ;;
178 ;; Return a string that will be added to the *vc-dir* buffer header.
179 ;;
180 ;; - status-printer (fileinfo)
181 ;;
182 ;; Pretty print the `vc-dir-fileinfo' FILEINFO.
183 ;; If a backend needs to show more information than the default FILE
184 ;; and STATE in the vc-dir listing, it can store that extra
185 ;; information in `vc-dir-fileinfo->extra'. This function can be
186 ;; used to display that extra information in the *vc-dir* buffer.
187 ;;
188 ;; - status-fileinfo-extra (file)
189 ;;
190 ;; Compute `vc-dir-fileinfo->extra' for FILE.
191 ;;
192 ;; * working-revision (file)
193 ;;
194 ;; Return the working revision of FILE. This is the revision fetched
195 ;; by the last checkout or upate, not necessarily the same thing as the
196 ;; head or tip revision. Should return "0" for a file added but not yet
197 ;; committed.
198 ;;
199 ;; - latest-on-branch-p (file)
200 ;;
201 ;; Return non-nil if the working revision of FILE is the latest revision
202 ;; on its branch (many VCSes call this the 'tip' or 'head' revision).
203 ;; The default implementation always returns t, which means that
204 ;; working with non-current revisions is not supported by default.
205 ;;
206 ;; * checkout-model (files)
207 ;;
208 ;; Indicate whether FILES need to be "checked out" before they can be
209 ;; edited. See `vc-checkout-model' for a list of possible values.
210 ;;
211 ;; - workfile-unchanged-p (file)
212 ;;
213 ;; Return non-nil if FILE is unchanged from the working revision.
214 ;; This function should do a brief comparison of FILE's contents
215 ;; with those of the repository master of the working revision. If
216 ;; the backend does not have such a brief-comparison feature, the
217 ;; default implementation of this function can be used, which
218 ;; delegates to a full vc-BACKEND-diff. (Note that vc-BACKEND-diff
219 ;; must not run asynchronously in this case, see variable
220 ;; `vc-disable-async-diff'.)
221 ;;
222 ;; - mode-line-string (file)
223 ;;
224 ;; If provided, this function should return the VC-specific mode
225 ;; line string for FILE. The returned string should have a
226 ;; `help-echo' property which is the text to be displayed as a
227 ;; tooltip when the mouse hovers over the VC entry on the mode-line.
228 ;; The default implementation deals well with all states that
229 ;; `vc-state' can return.
230 ;;
231 ;; - prettify-state-info (file)
232 ;;
233 ;; Translate the `vc-state' property of FILE into a string that can be
234 ;; used in a human-readable buffer. The default implementation deals well
235 ;; with all states that `vc-state' can return.
236 ;;
237 ;; STATE-CHANGING FUNCTIONS
238 ;;
239 ;; * create-repo (backend)
240 ;;
241 ;; Create an empty repository in the current directory and initialize
242 ;; it so VC mode can add files to it. For file-oriented systems, this
243 ;; need do no more than create a subdirectory with the right name.
244 ;;
245 ;; * register (files &optional rev comment)
246 ;;
247 ;; Register FILES in this backend. Optionally, an initial revision REV
248 ;; and an initial description of the file, COMMENT, may be specified,
249 ;; but it is not guaranteed that the backend will do anything with this.
250 ;; The implementation should pass the value of vc-register-switches
251 ;; to the backend command. (Note: in older versions of VC, this
252 ;; command took a single file argument and not a list.)
253 ;;
254 ;; - init-revision (file)
255 ;;
256 ;; The initial revision to use when registering FILE if one is not
257 ;; specified by the user. If not provided, the variable
258 ;; vc-default-init-revision is used instead.
259 ;;
260 ;; - responsible-p (file)
261 ;;
262 ;; Return non-nil if this backend considers itself "responsible" for
263 ;; FILE, which can also be a directory. This function is used to find
264 ;; out what backend to use for registration of new files and for things
265 ;; like change log generation. The default implementation always
266 ;; returns nil.
267 ;;
268 ;; - could-register (file)
269 ;;
270 ;; Return non-nil if FILE could be registered under this backend. The
271 ;; default implementation always returns t.
272 ;;
273 ;; - receive-file (file rev)
274 ;;
275 ;; Let this backend "receive" a file that is already registered under
276 ;; another backend. The default implementation simply calls `register'
277 ;; for FILE, but it can be overridden to do something more specific,
278 ;; e.g. keep revision numbers consistent or choose editing modes for
279 ;; FILE that resemble those of the other backend.
280 ;;
281 ;; - unregister (file)
282 ;;
283 ;; Unregister FILE from this backend. This is only needed if this
284 ;; backend may be used as a "more local" backend for temporary editing.
285 ;;
286 ;; * checkin (files rev comment)
287 ;;
288 ;; Commit changes in FILES to this backend. If REV is non-nil, that
289 ;; should become the new revision number (not all backends do
290 ;; anything with it). COMMENT is used as a check-in comment. The
291 ;; implementation should pass the value of vc-checkin-switches to
292 ;; the backend command. (Note: in older versions of VC, this
293 ;; command took a single file argument and not a list.)
294 ;;
295 ;; * find-revision (file rev buffer)
296 ;;
297 ;; Fetch revision REV of file FILE and put it into BUFFER.
298 ;; If REV is the empty string, fetch the head of the trunk.
299 ;; The implementation should pass the value of vc-checkout-switches
300 ;; to the backend command.
301 ;;
302 ;; * checkout (file &optional editable rev)
303 ;;
304 ;; Check out revision REV of FILE into the working area. If EDITABLE
305 ;; is non-nil, FILE should be writable by the user and if locking is
306 ;; used for FILE, a lock should also be set. If REV is non-nil, that
307 ;; is the revision to check out (default is the working revision).
308 ;; If REV is t, that means to check out the head of the current branch;
309 ;; if it is the empty string, check out the head of the trunk.
310 ;; The implementation should pass the value of vc-checkout-switches
311 ;; to the backend command.
312 ;;
313 ;; * revert (file &optional contents-done)
314 ;;
315 ;; Revert FILE back to the working revision. If optional
316 ;; arg CONTENTS-DONE is non-nil, then the contents of FILE have
317 ;; already been reverted from a version backup, and this function
318 ;; only needs to update the status of FILE within the backend.
319 ;;
320 ;; - rollback (files)
321 ;;
322 ;; Remove the tip revision of each of FILES from the repository. If
323 ;; this function is not provided, trying to cancel a revision is
324 ;; caught as an error. (Most backends don't provide it.) (Also
325 ;; note that older versions of this backend command were called
326 ;; 'cancel-version' and took a single file arg, not a list of
327 ;; files.)
328 ;;
329 ;; - merge (file rev1 rev2)
330 ;;
331 ;; Merge the changes between REV1 and REV2 into the current working file.
332 ;;
333 ;; - merge-news (file)
334 ;;
335 ;; Merge recent changes from the current branch into FILE.
336 ;;
337 ;; - steal-lock (file &optional revision)
338 ;;
339 ;; Steal any lock on the working revision of FILE, or on REVISION if
340 ;; that is provided. This function is only needed if locking is
341 ;; used for files under this backend, and if files can indeed be
342 ;; locked by other users.
343 ;;
344 ;; - modify-change-comment (files rev comment)
345 ;;
346 ;; Modify the change comments associated with the files at the
347 ;; given revision. This is optional, many backends do not support it.
348 ;;
349 ;; - mark-resolved (files)
350 ;;
351 ;; Mark conflicts as resolved. Some VC systems need to run a
352 ;; command to mark conflicts as resolved.
353 ;;
354 ;; HISTORY FUNCTIONS
355 ;;
356 ;; * print-log (files &optional buffer)
357 ;;
358 ;; Insert the revision log for FILES into BUFFER, or the *vc* buffer
359 ;; if BUFFER is nil. (Note: older versions of this function expected
360 ;; only a single file argument.)
361 ;;
362 ;; - log-view-mode ()
363 ;;
364 ;; Mode to use for the output of print-log. This defaults to
365 ;; `log-view-mode' and is expected to be changed (if at all) to a derived
366 ;; mode of `log-view-mode'.
367 ;;
368 ;; - show-log-entry (revision)
369 ;;
370 ;; If provided, search the log entry for REVISION in the current buffer,
371 ;; and make sure it is displayed in the buffer's window. The default
372 ;; implementation of this function works for RCS-style logs.
373 ;;
374 ;; - comment-history (file)
375 ;;
376 ;; Return a string containing all log entries that were made for FILE.
377 ;; This is used for transferring a file from one backend to another,
378 ;; retaining comment information.
379 ;;
380 ;; - update-changelog (files)
381 ;;
382 ;; Using recent log entries, create ChangeLog entries for FILES, or for
383 ;; all files at or below the default-directory if FILES is nil. The
384 ;; default implementation runs rcs2log, which handles RCS- and
385 ;; CVS-style logs.
386 ;;
387 ;; * diff (files &optional rev1 rev2 buffer)
388 ;;
389 ;; Insert the diff for FILE into BUFFER, or the *vc-diff* buffer if
390 ;; BUFFER is nil. If REV1 and REV2 are non-nil, report differences
391 ;; from REV1 to REV2. If REV1 is nil, use the working revision (as
392 ;; found in the repository) as the older revision; if REV2 is nil,
393 ;; use the current working-copy contents as the newer revision. This
394 ;; function should pass the value of (vc-switches BACKEND 'diff) to
395 ;; the backend command. It should return a status of either 0 (no
396 ;; differences found), or 1 (either non-empty diff or the diff is
397 ;; run asynchronously).
398 ;;
399 ;; - revision-completion-table (files)
400 ;;
401 ;; Return a completion table for existing revisions of FILES.
402 ;; The default is to not use any completion table.
403 ;;
404 ;; - annotate-command (file buf &optional rev)
405 ;;
406 ;; If this function is provided, it should produce an annotated display
407 ;; of FILE in BUF, relative to revision REV. Annotation means each line
408 ;; of FILE displayed is prefixed with version information associated with
409 ;; its addition (deleted lines leave no history) and that the text of the
410 ;; file is fontified according to age.
411 ;;
412 ;; - annotate-time ()
413 ;;
414 ;; Only required if `annotate-command' is defined for the backend.
415 ;; Return the time of the next line of annotation at or after point,
416 ;; as a floating point fractional number of days. The helper
417 ;; function `vc-annotate-convert-time' may be useful for converting
418 ;; multi-part times as returned by `current-time' and `encode-time'
419 ;; to this format. Return nil if no more lines of annotation appear
420 ;; in the buffer. You can safely assume that point is placed at the
421 ;; beginning of each line, starting at `point-min'. The buffer that
422 ;; point is placed in is the Annotate output, as defined by the
423 ;; relevant backend. This function also affects how much of the line
424 ;; is fontified; where it leaves point is where fontification begins.
425 ;;
426 ;; - annotate-current-time ()
427 ;;
428 ;; Only required if `annotate-command' is defined for the backend,
429 ;; AND you'd like the current time considered to be anything besides
430 ;; (vc-annotate-convert-time (current-time)) -- i.e. the current
431 ;; time with hours, minutes, and seconds included. Probably safe to
432 ;; ignore. Return the current-time, in units of fractional days.
433 ;;
434 ;; - annotate-extract-revision-at-line ()
435 ;;
436 ;; Only required if `annotate-command' is defined for the backend.
437 ;; Invoked from a buffer in vc-annotate-mode, return the revision
438 ;; corresponding to the current line, or nil if there is no revision
439 ;; corresponding to the current line.
440 ;;
441 ;; TAG SYSTEM
442 ;;
443 ;; - create-tag (dir name branchp)
444 ;;
445 ;; Attach the tag NAME to the state of the working copy. This
446 ;; should make sure that files are up-to-date before proceeding with
447 ;; the action. DIR can also be a file and if BRANCHP is specified,
448 ;; NAME should be created as a branch and DIR should be checked out
449 ;; under this new branch. The default implementation does not
450 ;; support branches but does a sanity check, a tree traversal and
451 ;; assigns the tag to each file.
452 ;;
453 ;; - retrieve-tag (dir name update)
454 ;;
455 ;; Retrieve the version tagged by NAME of all registered files at or below DIR.
456 ;; If UPDATE is non-nil, then update buffers of any files in the
457 ;; tag that are currently visited. The default implementation
458 ;; does a sanity check whether there aren't any uncommitted changes at
459 ;; or below DIR, and then performs a tree walk, using the `checkout'
460 ;; function to retrieve the corresponding revisions.
461 ;;
462 ;; MISCELLANEOUS
463 ;;
464 ;; - root (dir)
465 ;;
466 ;; Return DIR's "root" directory, that is, a parent directory of
467 ;; DIR for which the same backend as used for DIR applies. If no
468 ;; such parent exists, this function should return DIR.
469 ;;
470 ;; - make-version-backups-p (file)
471 ;;
472 ;; Return non-nil if unmodified repository revisions of FILE should be
473 ;; backed up locally. If this is done, VC can perform `diff' and
474 ;; `revert' operations itself, without calling the backend system. The
475 ;; default implementation always returns nil.
476 ;;
477 ;; - repository-hostname (dirname)
478 ;;
479 ;; Return the hostname that the backend will have to contact
480 ;; in order to operate on a file in DIRNAME. If the return value
481 ;; is nil, it means that the repository is local.
482 ;; This function is used in `vc-stay-local-p' which backends can use
483 ;; for their convenience.
484 ;;
485 ;; - previous-revision (file rev)
486 ;;
487 ;; Return the revision number that precedes REV for FILE, or nil if no such
488 ;; revision exists.
489 ;;
490 ;; - next-revision (file rev)
491 ;;
492 ;; Return the revision number that follows REV for FILE, or nil if no such
493 ;; revision exists.
494 ;;
495 ;; - check-headers ()
496 ;;
497 ;; Return non-nil if the current buffer contains any version headers.
498 ;;
499 ;; - clear-headers ()
500 ;;
501 ;; In the current buffer, reset all version headers to their unexpanded
502 ;; form. This function should be provided if the state-querying code
503 ;; for this backend uses the version headers to determine the state of
504 ;; a file. This function will then be called whenever VC changes the
505 ;; version control state in such a way that the headers would give
506 ;; wrong information.
507 ;;
508 ;; - delete-file (file)
509 ;;
510 ;; Delete FILE and mark it as deleted in the repository. If this
511 ;; function is not provided, the command `vc-delete-file' will
512 ;; signal an error.
513 ;;
514 ;; - rename-file (old new)
515 ;;
516 ;; Rename file OLD to NEW, both in the working area and in the
517 ;; repository. If this function is not provided, the renaming
518 ;; will be done by (vc-delete-file old) and (vc-register new).
519 ;;
520 ;; - find-file-hook ()
521 ;;
522 ;; Operation called in current buffer when opening a file. This can
523 ;; be used by the backend to setup some local variables it might need.
524 ;;
525 ;; - find-file-not-found-hook ()
526 ;;
527 ;; Operation called in current buffer when opening a non-existing file.
528 ;; By default, this asks the user if she wants to check out the file.
529 ;;
530 ;; - extra-menu ()
531 ;;
532 ;; Return a menu keymap, the items in the keymap will appear at the
533 ;; end of the Version Control menu. The goal is to allow backends
534 ;; to specify extra menu items that appear in the VC menu. This way
535 ;; you can provide menu entries for functionality that is specific
536 ;; to your backend and which does not map to any of the VC generic
537 ;; concepts.
538 ;;
539 ;; - extra-status-menu ()
540 ;;
541 ;; Return a menu keymap, the items in the keymap will appear at the
542 ;; end of the VC Status menu. The goal is to allow backends to
543 ;; specify extra menu items that appear in the VC Status menu. This
544 ;; makes it possible to provide menu entries for functionality that
545 ;; is specific to a backend and which does not map to any of the VC
546 ;; generic concepts.
547
548 ;;; Todo:
549
550 ;; - Add key-binding for vc-delete-file.
551
552 ;;;; New Primitives:
553 ;;
554 ;; - deal with push/pull operations.
555 ;;
556 ;; - add a mechanism for editing the underlying VCS's list of files
557 ;; to be ignored, when that's possible.
558 ;;
559 ;;;; Primitives that need changing:
560 ;;
561 ;; - vc-update/vc-merge should deal with VC systems that don't
562 ;; update/merge on a file basis, but on a whole repository basis.
563 ;; vc-update and vc-merge assume the arguments are always files,
564 ;; they don't deal with directories. Make sure the *vc-dir* buffer
565 ;; is updated after these operations.
566 ;; At least bzr, git and hg should benefit from this.
567 ;;
568 ;;;; Improved branch and tag handling:
569 ;;
570 ;; - add a generic mechanism for remembering the current branch names,
571 ;; display the branch name in the mode-line. Replace
572 ;; vc-cvs-sticky-tag with that.
573 ;;
574 ;; - C-x v b does switch to a different backend, but the mode line is not
575 ;; adapted accordingly. Also, it considers RCS and CVS to be the same,
576 ;; which is pretty confusing.
577 ;;
578 ;; - vc-create-tag and vc-retrieve-tag should update the
579 ;; buffers that might be visiting the affected files.
580 ;;
581 ;;;; Default Behavior:
582 ;;
583 ;; - do not default to RCS anymore when the current directory is not
584 ;; controlled by any VCS and the user does C-x v v
585 ;;
586 ;; - vc-responsible-backend should not return RCS if no backend
587 ;; declares itself responsible.
588 ;;
589 ;;;; Internal cleanups:
590 ;;
591 ;; - backends that care about vc-stay-local should try to take it into
592 ;; account for vc-dir. Is this likely to be useful??? YES!
593 ;;
594 ;; - vc-expand-dirs should take a backend parameter and only look for
595 ;; files managed by that backend.
596 ;;
597 ;; - Another important thing: merge all the status-like backend operations.
598 ;; We should remove dir-status, state, and dir-status-files, and
599 ;; replace them with just `status' which takes a fileset and a continuation
600 ;; (like dir-status) and returns a buffer in which the process(es) are run
601 ;; (or nil if it worked synchronously). Hopefully we can define the old
602 ;; 4 operations in term of this one.
603 ;;
604 ;;;; Other
605 ;;
606 ;; - when a file is in `conflict' state, turn on smerge-mode.
607 ;;
608 ;; - figure out what to do with conflicts that are not caused by the
609 ;; file contents, but by metadata or other causes. Example: File A
610 ;; gets renamed to B in one branch and to C in another and you merge
611 ;; the two branches. Or you locally add file FOO and then pull a
612 ;; change that also adds a new file FOO, ...
613 ;;
614 ;; - C-x v l should insert the file set in the *VC-log* buffer so that
615 ;; log-view can recognize it and use it for its commands.
616 ;;
617 ;; - vc-diff should be able to show the diff for all files in a
618 ;; changeset, especially for VC systems that have per repository
619 ;; version numbers. log-view should take advantage of this.
620 ;;
621 ;; - make it easier to write logs. Maybe C-x 4 a should add to the log
622 ;; buffer, if one is present, instead of adding to the ChangeLog.
623 ;;
624 ;; - When vc-next-action calls vc-checkin it could pre-fill the
625 ;; *VC-log* buffer with some obvious items: the list of files that
626 ;; were added, the list of files that were removed. If the diff is
627 ;; available, maybe it could even call something like
628 ;; `diff-add-change-log-entries-other-window' to create a detailed
629 ;; skeleton for the log...
630 ;;
631 ;; - The *vc-dir* buffer needs to be updated properly after VC
632 ;; operations on directories that change the file VC state.
633 ;;
634 ;; - most vc-dir backends need more work. They might need to
635 ;; provide custom headers, use the `extra' field and deal with all
636 ;; possible VC states.
637 ;;
638 ;; - add a function that calls vc-dir to `find-directory-functions'.
639 ;;
640 ;; - vc-diff, vc-annotate, etc. need to deal better with unregistered
641 ;; files. Now that unregistered and ignored files are shown in
642 ;; vc-dir, it is possible that these commands are called
643 ;; for unregistered/ignored files.
644 ;;
645 ;; - Using multiple backends needs work. Given a CVS directory with some
646 ;; files checked into git (but not all), using C-x v l to get a log file
647 ;; from a file only present in git, and then typing RET on some log entry,
648 ;; vc will bombs out because it wants to see the file being in CVS.
649 ;; Those logs should likely use a local variable to hardware the VC they
650 ;; are supposed to work with.
651 ;;
652 ;;;; Problems:
653 ;;
654 ;; - the *vc-dir* buffer is not updated correctly anymore after VC
655 ;; operations that change the file state.
656 ;;
657 ;;; Code:
658
659 (require 'vc-hooks)
660 (require 'vc-dispatcher)
661 (require 'tool-bar)
662 (require 'ewoc)
663
664 (eval-when-compile
665 (require 'cl))
666
667 (unless (assoc 'vc-parent-buffer minor-mode-alist)
668 (setq minor-mode-alist
669 (cons '(vc-parent-buffer vc-parent-buffer-name)
670 minor-mode-alist)))
671
672 ;; General customization
673
674 (defgroup vc nil
675 "Version-control system in Emacs."
676 :group 'tools)
677
678 (defcustom vc-initial-comment nil
679 "If non-nil, prompt for initial comment when a file is registered."
680 :type 'boolean
681 :group 'vc)
682
683 (defcustom vc-default-init-revision "1.1"
684 "A string used as the default revision number when a new file is registered.
685 This can be overridden by giving a prefix argument to \\[vc-register]. This
686 can also be overridden by a particular VC backend."
687 :type 'string
688 :group 'vc
689 :version "20.3")
690
691 (defcustom vc-checkin-switches nil
692 "A string or list of strings specifying extra switches for checkin.
693 These are passed to the checkin program by \\[vc-checkin]."
694 :type '(choice (const :tag "None" nil)
695 (string :tag "Argument String")
696 (repeat :tag "Argument List"
697 :value ("")
698 string))
699 :group 'vc)
700
701 (defcustom vc-checkout-switches nil
702 "A string or list of strings specifying extra switches for checkout.
703 These are passed to the checkout program by \\[vc-checkout]."
704 :type '(choice (const :tag "None" nil)
705 (string :tag "Argument String")
706 (repeat :tag "Argument List"
707 :value ("")
708 string))
709 :group 'vc)
710
711 (defcustom vc-register-switches nil
712 "A string or list of strings; extra switches for registering a file.
713 These are passed to the checkin program by \\[vc-register]."
714 :type '(choice (const :tag "None" nil)
715 (string :tag "Argument String")
716 (repeat :tag "Argument List"
717 :value ("")
718 string))
719 :group 'vc)
720
721 (defcustom vc-diff-switches nil
722 "A string or list of strings specifying switches for diff under VC.
723 When running diff under a given BACKEND, VC concatenates the values of
724 `diff-switches', `vc-diff-switches', and `vc-BACKEND-diff-switches' to
725 get the switches for that command. Thus, `vc-diff-switches' should
726 contain switches that are specific to version control, but not
727 specific to any particular backend."
728 :type '(choice (const :tag "None" nil)
729 (string :tag "Argument String")
730 (repeat :tag "Argument List"
731 :value ("")
732 string))
733 :group 'vc
734 :version "21.1")
735
736 (defcustom vc-diff-knows-L nil
737 "*Indicates whether diff understands the -L option.
738 The value is either `yes', `no', or nil. If it is nil, VC tries
739 to use -L and sets this variable to remember whether it worked."
740 :type '(choice (const :tag "Work out" nil) (const yes) (const no))
741 :group 'vc)
742
743 (defcustom vc-allow-async-revert nil
744 "Specifies whether the diff during \\[vc-revert] may be asynchronous.
745 Enabling this option means that you can confirm a revert operation even
746 if the local changes in the file have not been found and displayed yet."
747 :type '(choice (const :tag "No" nil)
748 (const :tag "Yes" t))
749 :group 'vc
750 :version "22.1")
751
752 ;;;###autoload
753 (defcustom vc-checkout-hook nil
754 "Normal hook (list of functions) run after checking out a file.
755 See `run-hooks'."
756 :type 'hook
757 :group 'vc
758 :version "21.1")
759
760 (defcustom vc-annotate-display-mode 'fullscale
761 "Which mode to color the output of \\[vc-annotate] with by default."
762 :type '(choice (const :tag "By Color Map Range" nil)
763 (const :tag "Scale to Oldest" scale)
764 (const :tag "Scale Oldest->Newest" fullscale)
765 (number :tag "Specify Fractional Number of Days"
766 :value "20.5"))
767 :group 'vc)
768
769 ;;;###autoload
770 (defcustom vc-checkin-hook nil
771 "Normal hook (list of functions) run after commit or file checkin.
772 See also `log-edit-done-hook'."
773 :type 'hook
774 :options '(log-edit-comment-to-change-log)
775 :group 'vc)
776
777 ;;;###autoload
778 (defcustom vc-before-checkin-hook nil
779 "Normal hook (list of functions) run before a commit or a file checkin.
780 See `run-hooks'."
781 :type 'hook
782 :group 'vc)
783
784 ;; Annotate customization
785 (defcustom vc-annotate-color-map
786 (if (and (tty-display-color-p) (<= (display-color-cells) 8))
787 ;; A custom sorted TTY colormap
788 (let* ((colors
789 (sort
790 (delq nil
791 (mapcar (lambda (x)
792 (if (not (or
793 (string-equal (car x) "white")
794 (string-equal (car x) "black") ))
795 (car x)))
796 (tty-color-alist)))
797 (lambda (a b)
798 (cond
799 ((or (string-equal a "red") (string-equal b "blue")) t)
800 ((or (string-equal b "red") (string-equal a "blue")) nil)
801 ((string-equal a "yellow") t)
802 ((string-equal b "yellow") nil)
803 ((string-equal a "cyan") t)
804 ((string-equal b "cyan") nil)
805 ((string-equal a "green") t)
806 ((string-equal b "green") nil)
807 ((string-equal a "magenta") t)
808 ((string-equal b "magenta") nil)
809 (t (string< a b))))))
810 (date 20.)
811 (delta (/ (- 360. date) (1- (length colors)))))
812 (mapcar (lambda (x)
813 (prog1
814 (cons date x)
815 (setq date (+ date delta)))) colors))
816 ;; Normal colormap: hue stepped from 0-240deg, value=1., saturation=0.75
817 '(( 20. . "#FF3F3F")
818 ( 40. . "#FF6C3F")
819 ( 60. . "#FF993F")
820 ( 80. . "#FFC63F")
821 (100. . "#FFF33F")
822 (120. . "#DDFF3F")
823 (140. . "#B0FF3F")
824 (160. . "#83FF3F")
825 (180. . "#56FF3F")
826 (200. . "#3FFF56")
827 (220. . "#3FFF83")
828 (240. . "#3FFFB0")
829 (260. . "#3FFFDD")
830 (280. . "#3FF3FF")
831 (300. . "#3FC6FF")
832 (320. . "#3F99FF")
833 (340. . "#3F6CFF")
834 (360. . "#3F3FFF")))
835 "Association list of age versus color, for \\[vc-annotate].
836 Ages are given in units of fractional days. Default is eighteen
837 steps using a twenty day increment, from red to blue. For TTY
838 displays with 8 or fewer colors, the default is red to blue with
839 all other colors between (excluding black and white)."
840 :type 'alist
841 :group 'vc)
842
843 (defcustom vc-annotate-very-old-color "#3F3FFF"
844 "Color for lines older than the current color range in \\[vc-annotate]]."
845 :type 'string
846 :group 'vc)
847
848 (defcustom vc-annotate-background "black"
849 "Background color for \\[vc-annotate].
850 Default color is used if nil."
851 :type '(choice (const :tag "Default background" nil) (color))
852 :group 'vc)
853
854 (defcustom vc-annotate-menu-elements '(2 0.5 0.1 0.01)
855 "Menu elements for the mode-specific menu of VC-Annotate mode.
856 List of factors, used to expand/compress the time scale. See `vc-annotate'."
857 :type '(repeat number)
858 :group 'vc)
859
860 (defvar vc-annotate-mode-map
861 (let ((m (make-sparse-keymap)))
862 (define-key m "A" 'vc-annotate-revision-previous-to-line)
863 (define-key m "D" 'vc-annotate-show-diff-revision-at-line)
864 (define-key m "f" 'vc-annotate-find-revision-at-line)
865 (define-key m "J" 'vc-annotate-revision-at-line)
866 (define-key m "L" 'vc-annotate-show-log-revision-at-line)
867 (define-key m "N" 'vc-annotate-next-revision)
868 (define-key m "P" 'vc-annotate-prev-revision)
869 (define-key m "W" 'vc-annotate-working-revision)
870 (define-key m "V" 'vc-annotate-toggle-annotation-visibility)
871 m)
872 "Local keymap used for VC-Annotate mode.")
873
874 ;; Header-insertion hair
875
876 (defcustom vc-static-header-alist
877 '(("\\.c\\'" .
878 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
879 "*Associate static header string templates with file types.
880 A \%s in the template is replaced with the first string associated with
881 the file's version control type in `vc-header-alist'."
882 :type '(repeat (cons :format "%v"
883 (regexp :tag "File Type")
884 (string :tag "Header String")))
885 :group 'vc)
886
887 (defcustom vc-comment-alist
888 '((nroff-mode ".\\\"" ""))
889 "*Special comment delimiters for generating VC headers.
890 Add an entry in this list if you need to override the normal `comment-start'
891 and `comment-end' variables. This will only be necessary if the mode language
892 is sensitive to blank lines."
893 :type '(repeat (list :format "%v"
894 (symbol :tag "Mode")
895 (string :tag "Comment Start")
896 (string :tag "Comment End")))
897 :group 'vc)
898
899 (defcustom vc-checkout-carefully (= (user-uid) 0)
900 "*Non-nil means be extra-careful in checkout.
901 Verify that the file really is not locked
902 and that its contents match what the master file says."
903 :type 'boolean
904 :group 'vc)
905 (make-obsolete-variable 'vc-checkout-carefully
906 "the corresponding checks are always done now."
907 "21.1")
908
909 \f
910 ;; Variables users don't need to see
911
912 (defvar vc-disable-async-diff nil
913 "VC sets this to t locally to disable some async diff operations.
914 Backends that offer asynchronous diffs should respect this variable
915 in their implementation of vc-BACKEND-diff.")
916
917 ;; File property caching
918
919 (defun vc-clear-context ()
920 "Clear all cached file properties."
921 (interactive)
922 (fillarray vc-file-prop-obarray 0))
923
924 (defmacro with-vc-properties (files form settings)
925 "Execute FORM, then maybe set per-file properties for FILES.
926 SETTINGS is an association list of property/value pairs. After
927 executing FORM, set those properties from SETTINGS that have not yet
928 been updated to their corresponding values."
929 (declare (debug t))
930 `(let ((vc-touched-properties (list t)))
931 ,form
932 (dolist (file ,files)
933 (dolist (setting ,settings)
934 (let ((property (car setting)))
935 (unless (memq property vc-touched-properties)
936 (put (intern file vc-file-prop-obarray)
937 property (cdr setting))))))))
938
939 ;;; Code for deducing what fileset and backend to assume
940
941 (defun vc-responsible-backend (file &optional register)
942 "Return the name of a backend system that is responsible for FILE.
943 The optional argument REGISTER means that a backend suitable for
944 registration should be found.
945
946 If REGISTER is nil, then if FILE is already registered, return the
947 backend of FILE. If FILE is not registered, or a directory, then the
948 first backend in `vc-handled-backends' that declares itself
949 responsible for FILE is returned. If no backend declares itself
950 responsible, return the first backend.
951
952 If REGISTER is non-nil, return the first responsible backend under
953 which FILE is not yet registered. If there is no such backend, return
954 the first backend under which FILE is not yet registered, but could
955 be registered."
956 (when (not vc-handled-backends)
957 (error "No handled backends"))
958 (or (and (not (file-directory-p file)) (not register) (vc-backend file))
959 (catch 'found
960 ;; First try: find a responsible backend. If this is for registration,
961 ;; it must be a backend under which FILE is not yet registered.
962 (dolist (backend vc-handled-backends)
963 (and (or (not register)
964 (not (vc-call-backend backend 'registered file)))
965 (vc-call-backend backend 'responsible-p file)
966 (throw 'found backend)))
967 ;; no responsible backend
968 (if (not register)
969 ;; if this is not for registration, the first backend must do
970 (car vc-handled-backends)
971 ;; for registration, we need to find a new backend that
972 ;; could register FILE
973 (dolist (backend vc-handled-backends)
974 (and (not (vc-call-backend backend 'registered file))
975 (vc-call-backend backend 'could-register file)
976 (throw 'found backend)))
977 (error "No backend that could register")))))
978
979 (defun vc-expand-dirs (file-or-dir-list)
980 "Expands directories in a file list specification.
981 Within directories, only files already under version control are noticed."
982 (let ((flattened '()))
983 (dolist (node file-or-dir-list)
984 (when (file-directory-p node)
985 (vc-file-tree-walk
986 node (lambda (f) (when (vc-backend f) (push f flattened)))))
987 (unless (file-directory-p node) (push node flattened)))
988 (nreverse flattened)))
989
990 (defun vc-derived-from-dir-mode (&optional buffer)
991 "Are we in a VC-directory buffer, or do we have one as an ancestor?"
992 (let ((buffer (or buffer (current-buffer))))
993 (cond ((derived-mode-p 'vc-dir-mode) t)
994 (vc-parent-buffer (vc-derived-from-dir-mode vc-parent-buffer))
995 (t nil))))
996
997 (defvar vc-dir-backend nil
998 "The backend used by the current *vc-dir* buffer.")
999
1000 ;; FIXME: this is not functional, commented out.
1001 ;; (defun vc-deduce-fileset (&optional observer)
1002 ;; "Deduce a set of files and a backend to which to apply an operation and
1003 ;; the common state of the fileset. Return (BACKEND . FILESET)."
1004 ;; (let* ((selection (vc-dispatcher-selection-set observer))
1005 ;; (raw (car selection)) ;; Selection as user made it
1006 ;; (cooked (cdr selection)) ;; Files only
1007 ;; ;; FIXME: Store the backend in a buffer-local variable.
1008 ;; (backend (if (vc-derived-from-dir-mode (current-buffer))
1009 ;; ;; FIXME: this should use vc-dir-backend from
1010 ;; ;; the *vc-dir* buffer.
1011 ;; (vc-responsible-backend default-directory)
1012 ;; (assert (and (= 1 (length raw))
1013 ;; (not (file-directory-p (car raw)))))
1014 ;; (vc-backend (car cooked)))))
1015 ;; (cons backend selection)))
1016
1017 (defun vc-deduce-fileset (&optional observer allow-unregistered)
1018 "Deduce a set of files and a backend to which to apply an operation.
1019
1020 Return (BACKEND FILESET FILESET_ONLY_FILES).
1021 If we're in VC-dir mode, the fileset is the list of marked files.
1022 Otherwise, if we're looking at a buffer visiting a version-controlled file,
1023 the fileset is a singleton containing this file.
1024 If none of these conditions is met, but ALLOW_UNREGISTERED is on and the
1025 visited file is not registered, return a singleton fileset containing it.
1026 Otherwise, throw an error."
1027 ;; FIXME: OBSERVER is unused. The name is not intuitive and is not
1028 ;; documented.
1029 (let (backend)
1030 (cond
1031 ((derived-mode-p 'vc-dir-mode)
1032 (let ((marked (vc-dir-marked-files)))
1033 (if marked
1034 (list vc-dir-backend marked (vc-dir-marked-only-files))
1035 (let ((crt (vc-dir-current-file)))
1036 (list vc-dir-backend (list crt) (vc-dir-child-files))))))
1037 ((setq backend (vc-backend buffer-file-name))
1038 (list backend (list buffer-file-name) (list buffer-file-name)))
1039 ((and vc-parent-buffer (or (buffer-file-name vc-parent-buffer)
1040 (with-current-buffer vc-parent-buffer
1041 (eq major-mode 'vc-dir-mode))))
1042 (progn
1043 (set-buffer vc-parent-buffer)
1044 (vc-deduce-fileset)))
1045 ((not buffer-file-name)
1046 (error "Buffer %s is not associated with a file" (buffer-name)))
1047 ((and allow-unregistered (not (vc-registered buffer-file-name)))
1048 (list (vc-responsible-backend
1049 (file-name-directory (buffer-file-name)))
1050 (list buffer-file-name) (list buffer-file-name)))
1051 (t (error "No fileset is available here.")))))
1052
1053 (defun vc-ensure-vc-buffer ()
1054 "Make sure that the current buffer visits a version-controlled file."
1055 (cond
1056 ((vc-dispatcher-browsing)
1057 (set-buffer (find-file-noselect (vc-dir-current-file))))
1058 (t
1059 (while (and vc-parent-buffer
1060 (buffer-live-p vc-parent-buffer)
1061 ;; Avoid infinite looping when vc-parent-buffer and
1062 ;; current buffer are the same buffer.
1063 (not (eq vc-parent-buffer (current-buffer))))
1064 (set-buffer vc-parent-buffer))
1065 (if (not buffer-file-name)
1066 (error "Buffer %s is not associated with a file" (buffer-name))
1067 (unless (vc-backend buffer-file-name)
1068 (error "File %s is not under version control" buffer-file-name))))))
1069
1070 ;;; Support for the C-x v v command.
1071 ;; This is where all the single-file-oriented code from before the fileset
1072 ;; rewrite lives.
1073
1074 (defsubst vc-editable-p (file)
1075 "Return non-nil if FILE can be edited."
1076 (let ((backend (vc-backend file)))
1077 (and backend
1078 (or (eq (vc-checkout-model backend (list file)) 'implicit)
1079 (memq (vc-state file) '(edited needs-merge conflict))))))
1080
1081 (defun vc-compatible-state (p q)
1082 "Controls which states can be in the same commit."
1083 (or
1084 (eq p q)
1085 (and (member p '(edited added removed)) (member q '(edited added removed)))))
1086
1087 ;; Here's the major entry point.
1088
1089 ;;;###autoload
1090 (defun vc-next-action (verbose)
1091 "Do the next logical version control operation on the current fileset.
1092 This requires that all files in the fileset be in the same state.
1093
1094 For locking systems:
1095 If every file is not already registered, this registers each for version
1096 control.
1097 If every file is registered and not locked by anyone, this checks out
1098 a writable and locked file of each ready for editing.
1099 If every file is checked out and locked by the calling user, this
1100 first checks to see if each file has changed since checkout. If not,
1101 it performs a revert on that file.
1102 If every file has been changed, this pops up a buffer for entry
1103 of a log message; when the message has been entered, it checks in the
1104 resulting changes along with the log message as change commentary. If
1105 the variable `vc-keep-workfiles' is non-nil (which is its default), a
1106 read-only copy of each changed file is left in place afterwards.
1107 If the affected file is registered and locked by someone else, you are
1108 given the option to steal the lock(s).
1109
1110 For merging systems:
1111 If every file is not already registered, this registers each one for version
1112 control. This does an add, but not a commit.
1113 If every file is added but not committed, each one is committed.
1114 If every working file is changed, but the corresponding repository file is
1115 unchanged, this pops up a buffer for entry of a log message; when the
1116 message has been entered, it checks in the resulting changes along
1117 with the logmessage as change commentary. A writable file is retained.
1118 If the repository file is changed, you are asked if you want to
1119 merge in the changes into your working copy."
1120 (interactive "P")
1121 (let* ((vc-fileset (vc-deduce-fileset nil t))
1122 (backend (car vc-fileset))
1123 (files (nth 1 vc-fileset))
1124 (fileset-only-files (nth 2 vc-fileset))
1125 ;; FIXME: We used to call `vc-recompute-state' here.
1126 (state (vc-state (car fileset-only-files)))
1127 ;; The backend should check that the checkout-model is consistent
1128 ;; among all the `files'.
1129 (model
1130 ;; FIXME: This is not very elegant...
1131 (when (and state (not (eq state 'unregistered)))
1132 (vc-checkout-model backend files)))
1133 revision)
1134
1135 ;; Check that all files are in a consistent state, since we use that
1136 ;; state to decide which operation to perform.
1137 (dolist (file (cdr fileset-only-files))
1138 (unless (vc-compatible-state (vc-state file) state)
1139 (error "%s:%s clashes with %s:%s"
1140 file (vc-state file) (car fileset-only-files) state)))
1141
1142 ;; Do the right thing
1143 (cond
1144 ((eq state 'missing)
1145 (error "Fileset files are missing, so cannot be operated on."))
1146 ((eq state 'ignored)
1147 (error "Fileset files are ignored by the version-control system."))
1148 ((or (null state) (eq state 'unregistered))
1149 (vc-register nil vc-fileset))
1150 ;; Files are up-to-date, or need a merge and user specified a revision
1151 ((or (eq state 'up-to-date) (and verbose (eq state 'needs-update)))
1152 (cond
1153 (verbose
1154 ;; go to a different revision
1155 (setq revision (read-string "Branch, revision, or backend to move to: "))
1156 (let ((vsym (intern-soft (upcase revision))))
1157 (if (member vsym vc-handled-backends)
1158 (dolist (file files) (vc-transfer-file file vsym))
1159 (dolist (file files)
1160 (vc-checkout file (eq model 'implicit) revision)))))
1161 ((not (eq model 'implicit))
1162 ;; check the files out
1163 (dolist (file files) (vc-checkout file t)))
1164 (t
1165 ;; do nothing
1166 (message "Fileset is up-to-date"))))
1167 ;; Files have local changes
1168 ((vc-compatible-state state 'edited)
1169 (let ((ready-for-commit files))
1170 ;; If files are edited but read-only, give user a chance to correct
1171 (dolist (file files)
1172 (unless (file-writable-p file)
1173 ;; Make the file+buffer read-write.
1174 (unless (y-or-n-p (format "%s is edited but read-only; make it writable and continue?" file))
1175 (error "Aborted"))
1176 (set-file-modes file (logior (file-modes file) 128))
1177 (let ((visited (get-file-buffer file)))
1178 (when visited
1179 (with-current-buffer visited
1180 (toggle-read-only -1))))))
1181 ;; Allow user to revert files with no changes
1182 (save-excursion
1183 (dolist (file files)
1184 (let ((visited (get-file-buffer file)))
1185 ;; For files with locking, if the file does not contain
1186 ;; any changes, just let go of the lock, i.e. revert.
1187 (when (and (not (eq model 'implicit))
1188 (vc-workfile-unchanged-p file)
1189 ;; If buffer is modified, that means the user just
1190 ;; said no to saving it; in that case, don't revert,
1191 ;; because the user might intend to save after
1192 ;; finishing the log entry and committing.
1193 (not (and visited (buffer-modified-p))))
1194 (vc-revert-file file)
1195 (delete file ready-for-commit)))))
1196 ;; Remaining files need to be committed
1197 (if (not ready-for-commit)
1198 (message "No files remain to be committed")
1199 (if (not verbose)
1200 (vc-checkin ready-for-commit)
1201 (progn
1202 (setq revision (read-string "New revision or backend: "))
1203 (let ((vsym (intern (upcase revision))))
1204 (if (member vsym vc-handled-backends)
1205 (dolist (file files) (vc-transfer-file file vsym))
1206 (vc-checkin ready-for-commit revision))))))))
1207 ;; locked by somebody else (locking VCSes only)
1208 ((stringp state)
1209 ;; In the old days, we computed the revision once and used it on
1210 ;; the single file. Then, for the 2007-2008 fileset rewrite, we
1211 ;; computed the revision once (incorrectly, using a free var) and
1212 ;; used it on all files. To fix the free var bug, we can either
1213 ;; use `(car files)' or do what we do here: distribute the
1214 ;; revision computation among `files'. Although this may be
1215 ;; tedious for those backends where a "revision" is a trans-file
1216 ;; concept, it is nonetheless correct for both those and (more
1217 ;; importantly) for those where "revision" is a per-file concept.
1218 ;; If the intersection of the former group and "locking VCSes" is
1219 ;; non-empty [I vaguely doubt it --ttn], we can reinstate the
1220 ;; pre-computation approach of yore.
1221 (dolist (file files)
1222 (vc-steal-lock
1223 file (if verbose
1224 (read-string (format "%s revision to steal: " file))
1225 (vc-working-revision file))
1226 state)))
1227 ;; conflict
1228 ((eq state 'conflict)
1229 ;; FIXME: Is it really the UI we want to provide?
1230 ;; In my experience, the conflicted files should be marked as resolved
1231 ;; one-by-one when saving the file after resolving the conflicts.
1232 ;; I.e. stating explicitly that the conflicts are resolved is done
1233 ;; very rarely.
1234 (vc-mark-resolved backend files))
1235 ;; needs-update
1236 ((eq state 'needs-update)
1237 (dolist (file files)
1238 (if (yes-or-no-p (format
1239 "%s is not up-to-date. Get latest revision? "
1240 (file-name-nondirectory file)))
1241 (vc-checkout file (eq model 'implicit) t)
1242 (when (and (not (eq model 'implicit))
1243 (yes-or-no-p "Lock this revision? "))
1244 (vc-checkout file t)))))
1245 ;; needs-merge
1246 ((eq state 'needs-merge)
1247 (dolist (file files)
1248 (when (yes-or-no-p (format
1249 "%s is not up-to-date. Merge in changes now? "
1250 (file-name-nondirectory file)))
1251 (vc-maybe-resolve-conflicts
1252 file (vc-call-backend backend 'merge-news file)))))
1253
1254 ;; unlocked-changes
1255 ((eq state 'unlocked-changes)
1256 (dolist (file files)
1257 (when (not (equal buffer-file-name file))
1258 (find-file-other-window file))
1259 (if (save-window-excursion
1260 (vc-diff-internal nil
1261 (cons (car vc-fileset) (cons (cadr vc-fileset) (list file)))
1262 (vc-working-revision file) nil)
1263 (goto-char (point-min))
1264 (let ((inhibit-read-only t))
1265 (insert
1266 (format "Changes to %s since last lock:\n\n" file)))
1267 (not (beep))
1268 (yes-or-no-p (concat "File has unlocked changes. "
1269 "Claim lock retaining changes? ")))
1270 (progn (vc-call-backend backend 'steal-lock file)
1271 (clear-visited-file-modtime)
1272 ;; Must clear any headers here because they wouldn't
1273 ;; show that the file is locked now.
1274 (vc-clear-headers file)
1275 (write-file buffer-file-name)
1276 (vc-mode-line file))
1277 (if (not (yes-or-no-p
1278 "Revert to checked-in revision, instead? "))
1279 (error "Checkout aborted")
1280 (vc-revert-buffer-internal t t)
1281 (vc-checkout file t)))))
1282 ;; Unknown fileset state
1283 (t
1284 (error "Fileset is in an unknown state %s" state)))))
1285
1286 (defun vc-create-repo (backend)
1287 "Create an empty repository in the current directory."
1288 (interactive
1289 (list
1290 (intern
1291 (upcase
1292 (completing-read
1293 "Create repository for: "
1294 (mapcar (lambda (b) (list (downcase (symbol-name b)))) vc-handled-backends)
1295 nil t)))))
1296 (vc-call-backend backend 'create-repo))
1297
1298 ;;;###autoload
1299 (defun vc-register (&optional set-revision vc-fileset comment)
1300 "Register into a version control system.
1301 If VC-FILESET is given, register the files in that fileset.
1302 Otherwise register the current file.
1303 With prefix argument SET-REVISION, allow user to specify initial revision
1304 level. If COMMENT is present, use that as an initial comment.
1305
1306 The version control system to use is found by cycling through the list
1307 `vc-handled-backends'. The first backend in that list which declares
1308 itself responsible for the file (usually because other files in that
1309 directory are already registered under that backend) will be used to
1310 register the file. If no backend declares itself responsible, the
1311 first backend that could register the file is used."
1312 (interactive "P")
1313 (let* ((fileset-arg (or vc-fileset (vc-deduce-fileset nil t)))
1314 (backend (car fileset-arg))
1315 (files (nth 1 fileset-arg))
1316 (fileset-only-files (nth 2 fileset-arg)))
1317 (dolist (fname fileset-only-files)
1318 (let ((bname (get-file-buffer fname)))
1319 (unless fname (setq fname buffer-file-name))
1320 (when (vc-backend fname)
1321 (if (vc-registered fname)
1322 (error "This file is already registered")
1323 (unless (y-or-n-p "Previous master file has vanished. Make a new one? ")
1324 (error "Aborted"))))
1325 ;; Watch out for new buffers of size 0: the corresponding file
1326 ;; does not exist yet, even though buffer-modified-p is nil.
1327 (when bname
1328 (with-current-buffer bname
1329 (when (and (not (buffer-modified-p))
1330 (zerop (buffer-size))
1331 (not (file-exists-p buffer-file-name)))
1332 (set-buffer-modified-p t))
1333 (vc-buffer-sync)))))
1334 (lexical-let ((backend backend)
1335 (files fileset-only-files))
1336 (vc-start-logentry
1337 files
1338 (if set-revision
1339 (read-string (format "Initial revision level for %s: "
1340 files))
1341 (vc-call-backend backend 'init-revision))
1342 (or comment (not vc-initial-comment))
1343 nil
1344 "Enter initial comment."
1345 "*VC-log*"
1346 (lambda (files rev comment)
1347 (message "Registering %s... " files)
1348 (dolist (file files)
1349 (vc-file-clearprops file))
1350 (vc-call-backend backend 'register files rev comment)
1351 (dolist (file files)
1352 (vc-file-setprop file 'vc-backend backend)
1353 (unless vc-make-backup-files
1354 ;; FIXME: Is this code right? What is it supposed to do?
1355 (make-local-variable 'backup-inhibited)
1356 (setq backup-inhibited t)))
1357 (message "Registering %s... done" files))))))
1358
1359 (defun vc-register-with (backend)
1360 "Register the current file with a specified back end."
1361 (interactive "SBackend: ")
1362 (when (not (member backend vc-handled-backends))
1363 (error "Unknown back end."))
1364 (let ((vc-handled-backends (list backend)))
1365 (call-interactively 'vc-register)))
1366
1367 (defun vc-checkout (file &optional writable rev)
1368 "Retrieve a copy of the revision REV of FILE.
1369 If WRITABLE is non-nil, make sure the retrieved file is writable.
1370 REV defaults to the latest revision.
1371
1372 After check-out, runs the normal hook `vc-checkout-hook'."
1373 (and writable
1374 (not rev)
1375 (vc-call make-version-backups-p file)
1376 (vc-up-to-date-p file)
1377 (vc-make-version-backup file))
1378 (let ((backend (vc-backend file)))
1379 (with-vc-properties (list file)
1380 (condition-case err
1381 (vc-call-backend backend 'checkout file writable rev)
1382 (file-error
1383 ;; Maybe the backend is not installed ;-(
1384 (when writable
1385 (let ((buf (get-file-buffer file)))
1386 (when buf (with-current-buffer buf (toggle-read-only -1)))))
1387 (signal (car err) (cdr err))))
1388 `((vc-state . ,(if (or (eq (vc-checkout-model backend (list file)) 'implicit)
1389 (not writable))
1390 (if (vc-call-backend backend 'latest-on-branch-p file)
1391 'up-to-date
1392 'needs-update)
1393 'edited))
1394 (vc-checkout-time . ,(nth 5 (file-attributes file))))))
1395 (vc-resynch-buffer file t t)
1396 (run-hooks 'vc-checkout-hook))
1397
1398 (defun vc-mark-resolved (backend files)
1399 (with-vc-properties
1400 files
1401 (vc-call-backend backend 'mark-resolved files)
1402 ;; XXX: Is this TRTD? Might not be.
1403 `((vc-state . edited))))
1404
1405 (defun vc-steal-lock (file rev owner)
1406 "Steal the lock on FILE."
1407 (let (file-description)
1408 (if rev
1409 (setq file-description (format "%s:%s" file rev))
1410 (setq file-description file))
1411 (when (not (yes-or-no-p (format "Steal the lock on %s from %s? "
1412 file-description owner)))
1413 (error "Steal canceled"))
1414 (message "Stealing lock on %s..." file)
1415 (with-vc-properties
1416 (list file)
1417 (vc-call steal-lock file rev)
1418 `((vc-state . edited)))
1419 (vc-resynch-buffer file t t)
1420 (message "Stealing lock on %s...done" file)
1421 ;; Write mail after actually stealing, because if the stealing
1422 ;; goes wrong, we don't want to send any mail.
1423 (compose-mail owner (format "Stolen lock on %s" file-description))
1424 (setq default-directory (expand-file-name "~/"))
1425 (goto-char (point-max))
1426 (insert
1427 (format "I stole the lock on %s, " file-description)
1428 (current-time-string)
1429 ".\n")
1430 (message "Please explain why you stole the lock. Type C-c C-c when done.")))
1431
1432 (defun vc-checkin (files &optional rev comment initial-contents)
1433 "Check in FILES.
1434 The optional argument REV may be a string specifying the new revision
1435 level (if nil increment the current level). COMMENT is a comment
1436 string; if omitted, a buffer is popped up to accept a comment. If
1437 INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial contents
1438 of the log entry buffer.
1439
1440 If `vc-keep-workfiles' is nil, FILE is deleted afterwards, provided
1441 that the version control system supports this mode of operation.
1442
1443 Runs the normal hooks `vc-before-checkin-hook' and `vc-checkin-hook'."
1444 (when vc-before-checkin-hook
1445 (run-hooks 'vc-before-checkin-hook))
1446 (vc-start-logentry
1447 files rev comment initial-contents
1448 "Enter a change comment."
1449 "*VC-log*"
1450 (lambda (files rev comment)
1451 (message "Checking in %s..." (vc-delistify files))
1452 ;; "This log message intentionally left almost blank".
1453 ;; RCS 5.7 gripes about white-space-only comments too.
1454 (or (and comment (string-match "[^\t\n ]" comment))
1455 (setq comment "*** empty log message ***"))
1456 (with-vc-properties
1457 files
1458 ;; We used to change buffers to get local value of vc-checkin-switches,
1459 ;; but 'the' local buffer is not a well-defined concept for filesets.
1460 (progn
1461 (vc-call checkin files rev comment)
1462 (mapc 'vc-delete-automatic-version-backups files))
1463 `((vc-state . up-to-date)
1464 (vc-checkout-time . ,(nth 5 (file-attributes file)))
1465 (vc-working-revision . nil)))
1466 (message "Checking in %s...done" (vc-delistify files)))
1467 'vc-checkin-hook))
1468
1469 ;;; Additional entry points for examining version histories
1470
1471 ;; (defun vc-default-diff-tree (backend dir rev1 rev2)
1472 ;; "List differences for all registered files at and below DIR.
1473 ;; The meaning of REV1 and REV2 is the same as for `vc-revision-diff'."
1474 ;; ;; This implementation does an explicit tree walk, and calls
1475 ;; ;; vc-BACKEND-diff directly for each file. An optimization
1476 ;; ;; would be to use `vc-diff-internal', so that diffs can be local,
1477 ;; ;; and to call it only for files that are actually changed.
1478 ;; ;; However, this is expensive for some backends, and so it is left
1479 ;; ;; to backend-specific implementations.
1480 ;; (setq default-directory dir)
1481 ;; (vc-file-tree-walk
1482 ;; default-directory
1483 ;; (lambda (f)
1484 ;; (vc-exec-after
1485 ;; `(let ((coding-system-for-read (vc-coding-system-for-diff ',f)))
1486 ;; (message "Looking at %s" ',f)
1487 ;; (vc-call-backend ',(vc-backend f)
1488 ;; 'diff (list ',f) ',rev1 ',rev2))))))
1489
1490 (defun vc-coding-system-for-diff (file)
1491 "Return the coding system for reading diff output for FILE."
1492 (or coding-system-for-read
1493 ;; if we already have this file open,
1494 ;; use the buffer's coding system
1495 (let ((buf (find-buffer-visiting file)))
1496 (when buf (with-current-buffer buf
1497 buffer-file-coding-system)))
1498 ;; otherwise, try to find one based on the file name
1499 (car (find-operation-coding-system 'insert-file-contents file))
1500 ;; and a final fallback
1501 'undecided))
1502
1503 (defun vc-switches (backend op)
1504 (let ((switches
1505 (or (when backend
1506 (let ((sym (vc-make-backend-sym
1507 backend (intern (concat (symbol-name op)
1508 "-switches")))))
1509 (when (boundp sym) (symbol-value sym))))
1510 (let ((sym (intern (format "vc-%s-switches" (symbol-name op)))))
1511 (when (boundp sym) (symbol-value sym)))
1512 (cond
1513 ((eq op 'diff) diff-switches)))))
1514 (if (stringp switches) (list switches)
1515 ;; If not a list, return nil.
1516 ;; This is so we can set vc-diff-switches to t to override
1517 ;; any switches in diff-switches.
1518 (when (listp switches) switches))))
1519
1520 ;; Old def for compatibility with Emacs-21.[123].
1521 (defmacro vc-diff-switches-list (backend) `(vc-switches ',backend 'diff))
1522 (make-obsolete 'vc-diff-switches-list 'vc-switches "22.1")
1523
1524 (defun vc-diff-finish (buffer messages)
1525 ;; The empty sync output case has already been handled, so the only
1526 ;; possibility of an empty output is for an async process.
1527 (when (buffer-live-p buffer)
1528 (let ((window (get-buffer-window buffer t))
1529 (emptyp (zerop (buffer-size buffer))))
1530 (with-current-buffer buffer
1531 (and messages emptyp
1532 (let ((inhibit-read-only t))
1533 (insert (cdr messages) ".\n")
1534 (message "%s" (cdr messages))))
1535 (goto-char (point-min))
1536 (when window
1537 (shrink-window-if-larger-than-buffer window)))
1538 (when (and messages (not emptyp))
1539 (message "%sdone" (car messages))))))
1540
1541 (defvar vc-diff-added-files nil
1542 "If non-nil, diff added files by comparing them to /dev/null.")
1543
1544 (defun vc-diff-internal (async vc-fileset rev1 rev2 &optional verbose)
1545 "Report diffs between two revisions of a fileset.
1546 Diff output goes to the *vc-diff* buffer. The function
1547 returns t if the buffer had changes, nil otherwise."
1548 (let* ((files (cadr vc-fileset))
1549 (messages (cons (format "Finding changes in %s..."
1550 (vc-delistify files))
1551 (format "No changes between %s and %s"
1552 (or rev1 "working revision")
1553 (or rev2 "workfile"))))
1554 ;; Set coding system based on the first file. It's a kluge,
1555 ;; but the only way to set it for each file included would
1556 ;; be to call the back end separately for each file.
1557 (coding-system-for-read
1558 (if files (vc-coding-system-for-diff (car files)) 'undecided)))
1559 (vc-setup-buffer "*vc-diff*")
1560 (message "%s" (car messages))
1561 ;; Many backends don't handle well the case of a file that has been
1562 ;; added but not yet committed to the repo (notably CVS and Subversion).
1563 ;; Do that work here so the backends don't have to futz with it. --ESR
1564 ;;
1565 ;; Actually most backends (including CVS) have options to control the
1566 ;; behavior since which one is better depends on the user and on the
1567 ;; situation). Worse yet: this code does not handle the case where
1568 ;; `file' is a directory which contains added files.
1569 ;; I made it conditional on vc-diff-added-files but it should probably
1570 ;; just be removed (or copied/moved to specific backends). --Stef.
1571 (when vc-diff-added-files
1572 (let ((filtered '()))
1573 (dolist (file files)
1574 (if (or (file-directory-p file)
1575 (not (string= (vc-working-revision file) "0")))
1576 (push file filtered)
1577 ;; This file is added but not yet committed;
1578 ;; there is no master file to diff against.
1579 (if (or rev1 rev2)
1580 (error "No revisions of %s exist" file)
1581 ;; We regard this as "changed".
1582 ;; Diff it against /dev/null.
1583 (apply 'vc-do-command "*vc-diff*"
1584 1 "diff" file
1585 (append (vc-switches nil 'diff) '("/dev/null"))))))
1586 (setq files (nreverse filtered))))
1587 (let ((vc-disable-async-diff (not async)))
1588 (vc-call-backend (car vc-fileset) 'diff files rev1 rev2 "*vc-diff*"))
1589 (set-buffer "*vc-diff*")
1590 (if (and (zerop (buffer-size))
1591 (not (get-buffer-process (current-buffer))))
1592 ;; Treat this case specially so as not to pop the buffer.
1593 (progn
1594 (message "%s" (cdr messages))
1595 nil)
1596 (diff-mode)
1597 ;; Make the *vc-diff* buffer read only, the diff-mode key
1598 ;; bindings are nicer for read only buffers. pcl-cvs does the
1599 ;; same thing.
1600 (setq buffer-read-only t)
1601 (vc-exec-after `(vc-diff-finish ,(current-buffer) ',(when verbose
1602 messages)))
1603 ;; Display the buffer, but at the end because it can change point.
1604 (pop-to-buffer (current-buffer))
1605 ;; In the async case, we return t even if there are no differences
1606 ;; because we don't know that yet.
1607 t)))
1608
1609 ;;;###autoload
1610 (defun vc-version-diff (files rev1 rev2)
1611 "Report diffs between revisions of the fileset in the repository history."
1612 (interactive
1613 (let* ((vc-fileset (vc-deduce-fileset t))
1614 (files (cadr vc-fileset))
1615 (backend (car vc-fileset))
1616 (first (car files))
1617 (completion-table
1618 (vc-call-backend backend 'revision-completion-table files))
1619 (rev1-default nil)
1620 (rev2-default nil))
1621 (cond
1622 ;; someday we may be able to do revision completion on non-singleton
1623 ;; filesets, but not yet.
1624 ((/= (length files) 1)
1625 nil)
1626 ;; if it's a directory, don't supply any revision default
1627 ((file-directory-p first)
1628 nil)
1629 ;; if the file is not up-to-date, use working revision as older revision
1630 ((not (vc-up-to-date-p first))
1631 (setq rev1-default (vc-working-revision first)))
1632 ;; if the file is not locked, use last and previous revisions as defaults
1633 (t
1634 (setq rev1-default (vc-call-backend backend 'previous-revision first
1635 (vc-working-revision first)))
1636 (when (string= rev1-default "") (setq rev1-default nil))
1637 (setq rev2-default (vc-working-revision first))))
1638 ;; construct argument list
1639 (let* ((rev1-prompt (if rev1-default
1640 (concat "Older revision (default "
1641 rev1-default "): ")
1642 "Older revision: "))
1643 (rev2-prompt (concat "Newer revision (default "
1644 (or rev2-default "current source") "): "))
1645 (rev1 (if completion-table
1646 (completing-read rev1-prompt completion-table
1647 nil nil nil nil rev1-default)
1648 (read-string rev1-prompt nil nil rev1-default)))
1649 (rev2 (if completion-table
1650 (completing-read rev2-prompt completion-table
1651 nil nil nil nil rev2-default)
1652 (read-string rev2-prompt nil nil rev2-default))))
1653 (when (string= rev1 "") (setq rev1 nil))
1654 (when (string= rev2 "") (setq rev2 nil))
1655 (list files rev1 rev2))))
1656 ;; All that was just so we could do argument completion!
1657 (when (and (not rev1) rev2)
1658 (error "Not a valid revision range."))
1659 ;; Yes, it's painful to call (vc-deduce-fileset) again. Alas, the
1660 ;; placement rules for (interactive) don't actually leave us a choice.
1661 (vc-diff-internal t (vc-deduce-fileset) rev1 rev2 (interactive-p)))
1662
1663 ;; (defun vc-contains-version-controlled-file (dir)
1664 ;; "Return t if DIR contains a version-controlled file, nil otherwise."
1665 ;; (catch 'found
1666 ;; (mapc (lambda (f) (and (not (file-directory-p f)) (vc-backend f) (throw 'found 't))) (directory-files dir))
1667 ;; nil))
1668
1669 ;;;###autoload
1670 (defun vc-diff (historic &optional not-urgent)
1671 "Display diffs between file revisions.
1672 Normally this compares the currently selected fileset with their
1673 working revisions. With a prefix argument HISTORIC, it reads two revision
1674 designators specifying which revisions to compare.
1675
1676 The optional argument NOT-URGENT non-nil means it is ok to say no to
1677 saving the buffer."
1678 (interactive (list current-prefix-arg t))
1679 (if historic
1680 (call-interactively 'vc-version-diff)
1681 (when buffer-file-name (vc-buffer-sync not-urgent))
1682 (vc-diff-internal t (vc-deduce-fileset) nil nil (interactive-p))))
1683
1684 ;;;###autoload
1685 (defun vc-revision-other-window (rev)
1686 "Visit revision REV of the current file in another window.
1687 If the current file is named `F', the revision is named `F.~REV~'.
1688 If `F.~REV~' already exists, use it instead of checking it out again."
1689 (interactive
1690 (save-current-buffer
1691 (vc-ensure-vc-buffer)
1692 (let ((completion-table
1693 (vc-call revision-completion-table buffer-file-name))
1694 (prompt "Revision to visit (default is working revision): "))
1695 (list
1696 (if completion-table
1697 (completing-read prompt completion-table)
1698 (read-string prompt))))))
1699 (vc-ensure-vc-buffer)
1700 (let* ((file buffer-file-name)
1701 (revision (if (string-equal rev "")
1702 (vc-working-revision file)
1703 rev)))
1704 (switch-to-buffer-other-window (vc-find-revision file revision))))
1705
1706 (defun vc-find-revision (file revision)
1707 "Read REVISION of FILE into a buffer and return the buffer."
1708 (let ((automatic-backup (vc-version-backup-file-name file revision))
1709 (filebuf (or (get-file-buffer file) (current-buffer)))
1710 (filename (vc-version-backup-file-name file revision 'manual)))
1711 (unless (file-exists-p filename)
1712 (if (file-exists-p automatic-backup)
1713 (rename-file automatic-backup filename nil)
1714 (message "Checking out %s..." filename)
1715 (with-current-buffer filebuf
1716 (let ((failed t))
1717 (unwind-protect
1718 (let ((coding-system-for-read 'no-conversion)
1719 (coding-system-for-write 'no-conversion))
1720 (with-temp-file filename
1721 (let ((outbuf (current-buffer)))
1722 ;; Change buffer to get local value of
1723 ;; vc-checkout-switches.
1724 (with-current-buffer filebuf
1725 (vc-call find-revision file revision outbuf))))
1726 (setq failed nil))
1727 (when (and failed (file-exists-p filename))
1728 (delete-file filename))))
1729 (vc-mode-line file))
1730 (message "Checking out %s...done" filename)))
1731 (let ((result-buf (find-file-noselect filename)))
1732 (with-current-buffer result-buf
1733 ;; Set the parent buffer so that things like
1734 ;; C-x v g, C-x v l, ... etc work.
1735 (set (make-local-variable 'vc-parent-buffer) filebuf))
1736 result-buf)))
1737
1738 ;; Header-insertion code
1739
1740 ;;;###autoload
1741 (defun vc-insert-headers ()
1742 "Insert headers into a file for use with a version control system.
1743 Headers desired are inserted at point, and are pulled from
1744 the variable `vc-BACKEND-header'."
1745 (interactive)
1746 (vc-ensure-vc-buffer)
1747 (save-excursion
1748 (save-restriction
1749 (widen)
1750 (when (or (not (vc-check-headers))
1751 (y-or-n-p "Version headers already exist. Insert another set? "))
1752 (let* ((delims (cdr (assq major-mode vc-comment-alist)))
1753 (comment-start-vc (or (car delims) comment-start "#"))
1754 (comment-end-vc (or (car (cdr delims)) comment-end ""))
1755 (hdsym (vc-make-backend-sym (vc-backend buffer-file-name)
1756 'header))
1757 (hdstrings (and (boundp hdsym) (symbol-value hdsym))))
1758 (dolist (s hdstrings)
1759 (insert comment-start-vc "\t" s "\t"
1760 comment-end-vc "\n"))
1761 (when vc-static-header-alist
1762 (dolist (f vc-static-header-alist)
1763 (when (string-match (car f) buffer-file-name)
1764 (insert (format (cdr f) (car hdstrings)))))))))))
1765
1766 (defun vc-clear-headers (&optional file)
1767 "Clear all version headers in the current buffer (or FILE).
1768 The headers are reset to their non-expanded form."
1769 (let* ((filename (or file buffer-file-name))
1770 (visited (find-buffer-visiting filename))
1771 (backend (vc-backend filename)))
1772 (when (vc-find-backend-function backend 'clear-headers)
1773 (if visited
1774 (let ((context (vc-buffer-context)))
1775 ;; save-excursion may be able to relocate point and mark
1776 ;; properly. If it fails, vc-restore-buffer-context
1777 ;; will give it a second try.
1778 (save-excursion
1779 (vc-call-backend backend 'clear-headers))
1780 (vc-restore-buffer-context context))
1781 (set-buffer (find-file-noselect filename))
1782 (vc-call-backend backend 'clear-headers)
1783 (kill-buffer filename)))))
1784
1785 (defun vc-modify-change-comment (files rev oldcomment)
1786 "Edit the comment associated with the given files and revision."
1787 (vc-start-logentry
1788 files rev oldcomment t
1789 "Enter a replacement change comment."
1790 "*VC-log*"
1791 (lambda (files rev comment)
1792 (vc-call-backend
1793 ;; Less of a kluge than it looks like; log-view mode only passes
1794 ;; this function a singleton list. Arguments left in this form in
1795 ;; case the more general operation ever becomes meaningful.
1796 (vc-responsible-backend (car files))
1797 'modify-change-comment files rev comment))))
1798
1799 ;;;###autoload
1800 (defun vc-merge ()
1801 "Merge changes between two revisions into the current buffer's file.
1802 This asks for two revisions to merge from in the minibuffer. If the
1803 first revision is a branch number, then merge all changes from that
1804 branch. If the first revision is empty, merge news, i.e. recent changes
1805 from the current branch.
1806
1807 See Info node `Merging'."
1808 (interactive)
1809 (vc-ensure-vc-buffer)
1810 (vc-buffer-sync)
1811 (let* ((file buffer-file-name)
1812 (backend (vc-backend file))
1813 (state (vc-state file))
1814 first-revision second-revision status)
1815 (cond
1816 ((stringp state) ;; Locking VCses only
1817 (error "File is locked by %s" state))
1818 ((not (vc-editable-p file))
1819 (if (y-or-n-p
1820 "File must be checked out for merging. Check out now? ")
1821 (vc-checkout file t)
1822 (error "Merge aborted"))))
1823 (setq first-revision
1824 (read-string (concat "Branch or revision to merge from "
1825 "(default news on current branch): ")))
1826 (if (string= first-revision "")
1827 (setq status (vc-call-backend backend 'merge-news file))
1828 (if (not (vc-find-backend-function backend 'merge))
1829 (error "Sorry, merging is not implemented for %s" backend)
1830 (if (not (vc-branch-p first-revision))
1831 (setq second-revision
1832 (read-string "Second revision: "
1833 (concat (vc-branch-part first-revision) ".")))
1834 ;; We want to merge an entire branch. Set revisions
1835 ;; accordingly, so that vc-BACKEND-merge understands us.
1836 (setq second-revision first-revision)
1837 ;; first-revision must be the starting point of the branch
1838 (setq first-revision (vc-branch-part first-revision)))
1839 (setq status (vc-call-backend backend 'merge file
1840 first-revision second-revision))))
1841 (vc-maybe-resolve-conflicts file status "WORKFILE" "MERGE SOURCE")))
1842
1843 (defun vc-maybe-resolve-conflicts (file status &optional name-A name-B)
1844 (vc-resynch-buffer file t (not (buffer-modified-p)))
1845 (if (zerop status) (message "Merge successful")
1846 (smerge-mode 1)
1847 (message "File contains conflicts.")))
1848
1849 ;;;###autoload
1850 (defalias 'vc-resolve-conflicts 'smerge-ediff)
1851
1852 ;; VC status implementation
1853
1854 (defun vc-default-status-extra-headers (backend dir)
1855 ;; Be loud by default to remind people to add code to display
1856 ;; backend specific headers.
1857 ;; XXX: change this to return nil before the release.
1858 (concat
1859 (propertize "Extra : " 'face 'font-lock-type-face)
1860 (propertize "Please add backend specific headers here. It's easy!"
1861 'face 'font-lock-warning-face)))
1862
1863 (defun vc-dir-headers (backend dir)
1864 "Display the headers in the *VC dir* buffer.
1865 It calls the `status-extra-headers' backend method to display backend
1866 specific headers."
1867 (concat
1868 (propertize "VC backend : " 'face 'font-lock-type-face)
1869 (propertize (format "%s\n" backend) 'face 'font-lock-variable-name-face)
1870 (propertize "Working dir: " 'face 'font-lock-type-face)
1871 (propertize (format "%s\n" dir) 'face 'font-lock-variable-name-face)
1872 (vc-call-backend backend 'status-extra-headers dir)
1873 "\n"))
1874
1875 (defun vc-default-status-printer (backend fileentry)
1876 "Pretty print FILEENTRY."
1877 ;; If you change the layout here, change vc-dir-move-to-goal-column.
1878 (let* ((isdir (vc-dir-fileinfo->directory fileentry))
1879 (state (if isdir 'DIRECTORY (vc-dir-fileinfo->state fileentry)))
1880 (filename (vc-dir-fileinfo->name fileentry)))
1881 ;; FIXME: Backends that want to print the state in a different way
1882 ;; can do it by defining the `status-printer' function. Using
1883 ;; `prettify-state-info' adds two extra vc-calls per item, which
1884 ;; is too expensive.
1885 ;;(prettified (if isdir state (vc-call-backend backend 'prettify-state-info filename))))
1886 (insert
1887 (propertize
1888 (format "%c" (if (vc-dir-fileinfo->marked fileentry) ?* ? ))
1889 'face 'font-lock-type-face)
1890 " "
1891 (propertize
1892 (format "%-20s" state)
1893 'face (cond ((eq state 'up-to-date) 'font-lock-builtin-face)
1894 ((memq state '(missing conflict)) 'font-lock-warning-face)
1895 (t 'font-lock-variable-name-face))
1896 'mouse-face 'highlight)
1897 " "
1898 (propertize
1899 (format "%s" filename)
1900 'face 'font-lock-function-name-face
1901 'mouse-face 'highlight))))
1902
1903 (defun vc-default-extra-status-menu (backend)
1904 nil)
1905
1906 (defun vc-dir-refresh-files (files default-state)
1907 "Refresh some files in the *VC-dir* buffer."
1908 (let ((def-dir default-directory)
1909 (backend vc-dir-backend))
1910 (vc-set-mode-line-busy-indicator)
1911 ;; Call the `dir-status-file' backend function.
1912 ;; `dir-status-file' is supposed to be asynchronous.
1913 ;; It should compute the results, and then call the function
1914 ;; passed as an argument in order to update the vc-dir buffer
1915 ;; with the results.
1916 (unless (buffer-live-p vc-dir-process-buffer)
1917 (setq vc-dir-process-buffer
1918 (generate-new-buffer (format " *VC-%s* tmp status" backend))))
1919 (lexical-let ((buffer (current-buffer)))
1920 (with-current-buffer vc-dir-process-buffer
1921 (cd def-dir)
1922 (erase-buffer)
1923 (vc-call-backend
1924 backend 'dir-status-files def-dir files default-state
1925 (lambda (entries &optional more-to-come)
1926 ;; ENTRIES is a list of (FILE VC_STATE EXTRA) items.
1927 ;; If MORE-TO-COME is true, then more updates will come from
1928 ;; the asynchronous process.
1929 (with-current-buffer buffer
1930 (vc-dir-update entries buffer)
1931 (unless more-to-come
1932 (setq mode-line-process nil)
1933 ;; Remove the ones that haven't been updated at all.
1934 ;; Those not-updated are those whose state is nil because the
1935 ;; file/dir doesn't exist and isn't versioned.
1936 (ewoc-filter vc-ewoc
1937 (lambda (info)
1938 ;; The state for directory entries might
1939 ;; have been changed to 'up-to-date,
1940 ;; reset it, othewise it will be removed when doing 'x'
1941 ;; next time.
1942 ;; FIXME: There should be a more elegant way to do this.
1943 (when (and (vc-dir-fileinfo->directory info)
1944 (eq (vc-dir-fileinfo->state info)
1945 'up-to-date))
1946 (setf (vc-dir-fileinfo->state info) nil))
1947
1948 (not (vc-dir-fileinfo->needs-update info))))))))))))
1949
1950 (defun vc-dir-refresh ()
1951 "Refresh the contents of the *VC-dir* buffer.
1952 Throw an error if another update process is in progress."
1953 (interactive)
1954 (if (vc-dir-busy)
1955 (error "Another update process is in progress, cannot run two at a time")
1956 (let ((def-dir default-directory)
1957 (backend vc-dir-backend))
1958 (vc-set-mode-line-busy-indicator)
1959 ;; Call the `dir-status' backend function.
1960 ;; `dir-status' is supposed to be asynchronous.
1961 ;; It should compute the results, and then call the function
1962 ;; passed as an argument in order to update the vc-dir buffer
1963 ;; with the results.
1964
1965 ;; Create a buffer that can be used by `dir-status' and call
1966 ;; `dir-status' with this buffer as the current buffer. Use
1967 ;; `vc-dir-process-buffer' to remember this buffer, so that
1968 ;; it can be used later to kill the update process in case it
1969 ;; takes too long.
1970 (unless (buffer-live-p vc-dir-process-buffer)
1971 (setq vc-dir-process-buffer
1972 (generate-new-buffer (format " *VC-%s* tmp status" backend))))
1973 ;; set the needs-update flag on all entries
1974 (ewoc-map (lambda (info) (setf (vc-dir-fileinfo->needs-update info) t) nil)
1975 vc-ewoc)
1976 (lexical-let ((buffer (current-buffer)))
1977 (with-current-buffer vc-dir-process-buffer
1978 (cd def-dir)
1979 (erase-buffer)
1980 (vc-call-backend
1981 backend 'dir-status def-dir
1982 (lambda (entries &optional more-to-come)
1983 ;; ENTRIES is a list of (FILE VC_STATE EXTRA) items.
1984 ;; If MORE-TO-COME is true, then more updates will come from
1985 ;; the asynchronous process.
1986 (with-current-buffer buffer
1987 (vc-dir-update entries buffer)
1988 (unless more-to-come
1989 (let ((remaining
1990 (ewoc-collect
1991 vc-ewoc 'vc-dir-fileinfo->needs-update)))
1992 (if remaining
1993 (vc-dir-refresh-files
1994 (mapcar 'vc-dir-fileinfo->name remaining)
1995 'up-to-date)
1996 (setq mode-line-process nil))))))))))))
1997
1998 (defun vc-dir-show-fileentry (file)
1999 "Insert an entry for a specific file into the current *VC-dir* listing.
2000 This is typically used if the file is up-to-date (or has been added
2001 outside of VC) and one wants to do some operation on it."
2002 (interactive "fShow file: ")
2003 (vc-dir-update (list (list (file-relative-name file) (vc-state file))) (current-buffer)))
2004
2005 (defun vc-dir-hide-up-to-date ()
2006 "Hide up-to-date items from display."
2007 (interactive)
2008 (ewoc-filter
2009 vc-ewoc
2010 (lambda (crt) (not (eq (vc-dir-fileinfo->state crt) 'up-to-date)))))
2011
2012 (defun vc-default-status-fileinfo-extra (backend file)
2013 "Default absence of extra information returned for a file."
2014 nil)
2015
2016 ;; FIXME: Replace these with a more efficient dispatch
2017
2018 (defun vc-generic-status-printer (fileentry)
2019 (vc-call-backend vc-dir-backend 'status-printer fileentry))
2020
2021 (defun vc-generic-state (file)
2022 (vc-call-backend vc-dir-backend 'state file))
2023
2024 (defun vc-generic-status-fileinfo-extra (file)
2025 (vc-call-backend vc-dir-backend 'status-fileinfo-extra file))
2026
2027 (defun vc-dir-extra-menu ()
2028 (vc-call-backend vc-dir-backend 'extra-status-menu))
2029
2030 (defun vc-make-backend-object (file-or-dir)
2031 "Create the backend capability object needed by vc-dispatcher."
2032 (vc-create-client-object
2033 "VC dir"
2034 (vc-dir-headers vc-dir-backend file-or-dir)
2035 #'vc-generic-status-printer
2036 #'vc-generic-state
2037 #'vc-generic-status-fileinfo-extra
2038 #'vc-dir-refresh
2039 #'vc-dir-extra-menu))
2040
2041 ;;;###autoload
2042 (defun vc-dir (dir)
2043 "Show the VC status for DIR."
2044 (interactive "DVC status for directory: ")
2045 (pop-to-buffer (vc-dir-prepare-status-buffer "*vc-dir*" dir))
2046 (if (and (derived-mode-p 'vc-dir-mode) (boundp 'client-object))
2047 (vc-dir-refresh)
2048 ;; Otherwise, initialize a new view using the dispatcher layer
2049 (progn
2050 (set (make-local-variable 'vc-dir-backend) (vc-responsible-backend dir))
2051 ;; Build a capability object and hand it to the dispatcher initializer
2052 (vc-dir-mode (vc-make-backend-object dir))
2053 ;; FIXME: Make a derived-mode instead.
2054 ;; Add VC-specific keybindings
2055 (let ((map (current-local-map)))
2056 (define-key map "v" 'vc-next-action) ;; C-x v v
2057 (define-key map "=" 'vc-diff) ;; C-x v =
2058 (define-key map "i" 'vc-register) ;; C-x v i
2059 (define-key map "+" 'vc-update) ;; C-x v +
2060 (define-key map "l" 'vc-print-log) ;; C-x v l
2061 ;; More confusing than helpful, probably
2062 ;(define-key map "R" 'vc-revert) ;; u is taken by dispatcher unmark.
2063 ;(define-key map "A" 'vc-annotate) ;; g is taken by dispatcher refresh
2064 (define-key map "x" 'vc-dir-hide-up-to-date))
2065 )
2066 ;; FIXME: Needs to alter a buffer-local map, otherwise clients may clash
2067 (let ((map vc-dir-menu-map))
2068 ;; VC info details
2069 (define-key map [sepvcdet] '("--"))
2070 (define-key map [remup]
2071 '(menu-item "Hide up-to-date" vc-dir-hide-up-to-date
2072 :help "Hide up-to-date items from display"))
2073 ;; FIXME: This needs a key binding. And maybe a better name
2074 ;; ("Insert" like PCL-CVS uses does not sound that great either)...
2075 (define-key map [ins]
2076 '(menu-item "Show File" vc-dir-show-fileentry
2077 :help "Show a file in the VC status listing even though it might be up to date"))
2078 (define-key map [annotate]
2079 '(menu-item "Annotate" vc-annotate
2080 :help "Display the edit history of the current file using colors"))
2081 (define-key map [diff]
2082 '(menu-item "Compare with Base Version" vc-diff
2083 :help "Compare file set with the base version"))
2084 (define-key map [log]
2085 '(menu-item "Show history" vc-print-log
2086 :help "List the change log of the current file set in a window"))
2087 ;; VC commands.
2088 (define-key map [sepvccmd] '("--"))
2089 (define-key map [update]
2090 '(menu-item "Update to latest version" vc-update
2091 :help "Update the current fileset's files to their tip revisions"))
2092 (define-key map [revert]
2093 '(menu-item "Revert to base version" vc-revert
2094 :help "Revert working copies of the selected fileset to their repository contents."))
2095 (define-key map [next-action]
2096 ;; FIXME: This really really really needs a better name!
2097 ;; And a key binding too.
2098 '(menu-item "Check In/Out" vc-next-action
2099 :help "Do the next logical version control operation on the current fileset"))
2100 (define-key map [register]
2101 '(menu-item "Register" vc-dir-register
2102 :help "Register file set into the version control system"))
2103 )))
2104
2105 ;; Named-configuration entry points
2106
2107 (defun vc-tag-precondition (dir)
2108 "Scan the tree below DIR, looking for files not up-to-date.
2109 If any file is not up-to-date, return the name of the first such file.
2110 \(This means, neither tag creation nor retrieval is allowed.\)
2111 If one or more of the files are currently visited, return `visited'.
2112 Otherwise, return nil."
2113 (let ((status nil))
2114 (catch 'vc-locked-example
2115 (vc-file-tree-walk
2116 dir
2117 (lambda (f)
2118 (if (not (vc-up-to-date-p f)) (throw 'vc-locked-example f)
2119 (when (get-file-buffer f) (setq status 'visited)))))
2120 status)))
2121
2122 ;;;###autoload
2123 (defun vc-create-tag (dir name branchp)
2124 "Descending recursively from DIR, make a tag called NAME.
2125 For each registered file, the working revision becomes part of
2126 the named configuration. If the prefix argument BRANCHP is
2127 given, the tag is made as a new branch and the files are
2128 checked out in that new branch."
2129 (interactive
2130 (list (read-file-name "Directory: " default-directory default-directory t)
2131 (read-string "New tag name: ")
2132 current-prefix-arg))
2133 (message "Making %s... " (if branchp "branch" "tag"))
2134 (when (file-directory-p dir) (setq dir (file-name-as-directory dir)))
2135 (vc-call-backend (vc-responsible-backend dir)
2136 'create-tag dir name branchp)
2137 (message "Making %s... done" (if branchp "branch" "tag")))
2138
2139 ;;;###autoload
2140 (defun vc-retrieve-tag (dir name)
2141 "Descending recursively from DIR, retrieve the tag called NAME.
2142 If NAME is empty, it refers to the latest revisions.
2143 If locking is used for the files in DIR, then there must not be any
2144 locked files at or below DIR (but if NAME is empty, locked files are
2145 allowed and simply skipped)."
2146 (interactive
2147 (list (read-file-name "Directory: " default-directory default-directory t)
2148 (read-string "Tag name to retrieve (default latest revisions): ")))
2149 (let ((update (yes-or-no-p "Update any affected buffers? "))
2150 (msg (if (or (not name) (string= name ""))
2151 (format "Updating %s... " (abbreviate-file-name dir))
2152 (format "Retrieving tag into %s... "
2153 (abbreviate-file-name dir)))))
2154 (message "%s" msg)
2155 (vc-call-backend (vc-responsible-backend dir)
2156 'retrieve-tag dir name update)
2157 (message "%s" (concat msg "done"))))
2158
2159 ;; Miscellaneous other entry points
2160
2161 ;;;###autoload
2162 (defun vc-print-log (&optional working-revision)
2163 "List the change log of the current fileset in a window.
2164 If WORKING-REVISION is non-nil, leave the point at that revision."
2165 (interactive)
2166 (let* ((vc-fileset (vc-deduce-fileset t))
2167 (backend (car vc-fileset))
2168 (files (cadr vc-fileset))
2169 (working-revision (or working-revision (vc-working-revision (car files)))))
2170 ;; Don't switch to the output buffer before running the command,
2171 ;; so that any buffer-local settings in the vc-controlled
2172 ;; buffer can be accessed by the command.
2173 (vc-call-backend backend 'print-log files "*vc-change-log*")
2174 (pop-to-buffer "*vc-change-log*")
2175 (vc-exec-after
2176 `(let ((inhibit-read-only t))
2177 (vc-call-backend ',backend 'log-view-mode)
2178 (set (make-local-variable 'log-view-vc-backend) ',backend)
2179 (set (make-local-variable 'log-view-vc-fileset) ',files)
2180 (goto-char (point-max)) (forward-line -1)
2181 (while (looking-at "=*\n")
2182 (delete-char (- (match-end 0) (match-beginning 0)))
2183 (forward-line -1))
2184 (goto-char (point-min))
2185 (when (looking-at "[\b\t\n\v\f\r ]+")
2186 (delete-char (- (match-end 0) (match-beginning 0))))
2187 (shrink-window-if-larger-than-buffer)
2188 ;; move point to the log entry for the working revision
2189 (vc-call-backend ',backend 'show-log-entry ',working-revision)
2190 (setq vc-sentinel-movepoint (point))
2191 (set-buffer-modified-p nil)))))
2192
2193 ;;;###autoload
2194 (defun vc-revert ()
2195 "Revert working copies of the selected fileset to their repository contents.
2196 This asks for confirmation if the buffer contents are not identical
2197 to the working revision (except for keyword expansion)."
2198 (interactive)
2199 (let* ((vc-fileset (vc-deduce-fileset))
2200 (files (cadr vc-fileset)))
2201 ;; If any of the files is visited by the current buffer, make
2202 ;; sure buffer is saved. If the user says `no', abort since
2203 ;; we cannot show the changes and ask for confirmation to
2204 ;; discard them.
2205 (when (or (not files) (memq (buffer-file-name) files))
2206 (vc-buffer-sync nil))
2207 (dolist (file files)
2208 (let ((buf (get-file-buffer file)))
2209 (when (and buf (buffer-modified-p buf))
2210 (error "Please kill or save all modified buffers before reverting.")))
2211 (when (vc-up-to-date-p file)
2212 (unless (yes-or-no-p (format "%s seems up-to-date. Revert anyway? " file))
2213 (error "Revert canceled"))))
2214 (when (vc-diff-internal vc-allow-async-revert vc-fileset nil nil)
2215 (unless (yes-or-no-p (format "Discard changes in %s? " (vc-delistify files)))
2216 (error "Revert canceled"))
2217 (delete-windows-on "*vc-diff*")
2218 (kill-buffer "*vc-diff*"))
2219 (dolist (file files)
2220 (message "Reverting %s..." (vc-delistify files))
2221 (vc-revert-file file)
2222 (message "Reverting %s...done" (vc-delistify files)))))
2223
2224 ;;;###autoload
2225 (defun vc-rollback ()
2226 "Roll back (remove) the most recent changeset committed to the repository.
2227 This may be either a file-level or a repository-level operation,
2228 depending on the underlying version-control system."
2229 (interactive)
2230 (let* ((vc-fileset (vc-deduce-fileset))
2231 (backend (car vc-fileset))
2232 (files (cadr vc-fileset))
2233 (granularity (vc-call-backend backend 'revision-granularity)))
2234 (unless (vc-find-backend-function backend 'rollback)
2235 (error "Rollback is not supported in %s" backend))
2236 (when (and (not (eq granularity 'repository)) (/= (length files) 1))
2237 (error "Rollback requires a singleton fileset or repository versioning"))
2238 ;; FIXME: latest-on-branch-p should take the fileset.
2239 (when (not (vc-call-backend backend 'latest-on-branch-p (car files)))
2240 (error "Rollback is only possible at the tip revision."))
2241 ;; If any of the files is visited by the current buffer, make
2242 ;; sure buffer is saved. If the user says `no', abort since
2243 ;; we cannot show the changes and ask for confirmation to
2244 ;; discard them.
2245 (when (or (not files) (memq (buffer-file-name) files))
2246 (vc-buffer-sync nil))
2247 (dolist (file files)
2248 (when (buffer-modified-p (get-file-buffer file))
2249 (error "Please kill or save all modified buffers before rollback."))
2250 (when (not (vc-up-to-date-p file))
2251 (error "Please revert all modified workfiles before rollback.")))
2252 ;; Accumulate changes associated with the fileset
2253 (vc-setup-buffer "*vc-diff*")
2254 (not-modified)
2255 (message "Finding changes...")
2256 (let* ((tip (vc-working-revision (car files)))
2257 ;; FIXME: `previous-revision' should take the fileset.
2258 (previous (vc-call-backend backend 'previous-revision
2259 (car files) tip)))
2260 (vc-diff-internal nil vc-fileset previous tip))
2261 ;; Display changes
2262 (unless (yes-or-no-p "Discard these revisions? ")
2263 (error "Rollback canceled"))
2264 (delete-windows-on "*vc-diff*")
2265 (kill-buffer"*vc-diff*")
2266 ;; Do the actual reversions
2267 (message "Rolling back %s..." (vc-delistify files))
2268 (with-vc-properties
2269 files
2270 (vc-call-backend backend 'rollback files)
2271 `((vc-state . ,'up-to-date)
2272 (vc-checkout-time . , (nth 5 (file-attributes file)))
2273 (vc-working-revision . nil)))
2274 (dolist (f files) (vc-resynch-buffer f t t))
2275 (message "Rolling back %s...done" (vc-delistify files))))
2276
2277 ;;;###autoload
2278 (define-obsolete-function-alias 'vc-revert-buffer 'vc-revert "23.1")
2279
2280 ;;;###autoload
2281 (defun vc-update ()
2282 "Update the current fileset's files to their tip revisions.
2283 For each one that contains no changes, and is not locked, then this simply
2284 replaces the work file with the latest revision on its branch. If the file
2285 contains changes, and the backend supports merging news, then any recent
2286 changes from the current branch are merged into the working file."
2287 (interactive)
2288 (let* ((vc-fileset (vc-deduce-fileset))
2289 (backend (car vc-fileset))
2290 (files (cadr vc-fileset)))
2291 (save-some-buffers ; save buffers visiting files
2292 nil (lambda ()
2293 (and (buffer-modified-p)
2294 (let ((file (buffer-file-name)))
2295 (and file (member file files))))))
2296 (dolist (file files)
2297 (if (vc-up-to-date-p file)
2298 (vc-checkout file nil t)
2299 (if (eq (vc-checkout-model backend (list file)) 'locking)
2300 (if (eq (vc-state file) 'edited)
2301 (error "%s"
2302 (substitute-command-keys
2303 "File is locked--type \\[vc-revert] to discard changes"))
2304 (error "Unexpected file state (%s) -- type %s"
2305 (vc-state file)
2306 (substitute-command-keys
2307 "\\[vc-next-action] to correct")))
2308 (vc-maybe-resolve-conflicts
2309 file (vc-call-backend backend 'merge-news file)))))))
2310
2311 (defun vc-version-backup-file (file &optional rev)
2312 "Return name of backup file for revision REV of FILE.
2313 If version backups should be used for FILE, and there exists
2314 such a backup for REV or the working revision of file, return
2315 its name; otherwise return nil."
2316 (when (vc-call make-version-backups-p file)
2317 (let ((backup-file (vc-version-backup-file-name file rev)))
2318 (if (file-exists-p backup-file)
2319 backup-file
2320 ;; there is no automatic backup, but maybe the user made one manually
2321 (setq backup-file (vc-version-backup-file-name file rev 'manual))
2322 (when (file-exists-p backup-file)
2323 backup-file)))))
2324
2325 (defun vc-revert-file (file)
2326 "Revert FILE back to the repository working revision it was based on."
2327 (with-vc-properties
2328 (list file)
2329 (let ((backup-file (vc-version-backup-file file)))
2330 (when backup-file
2331 (copy-file backup-file file 'ok-if-already-exists 'keep-date)
2332 (vc-delete-automatic-version-backups file))
2333 (vc-call revert file backup-file))
2334 `((vc-state . up-to-date)
2335 (vc-checkout-time . ,(nth 5 (file-attributes file)))))
2336 (vc-resynch-buffer file t t))
2337
2338 ;;;###autoload
2339 (defun vc-switch-backend (file backend)
2340 "Make BACKEND the current version control system for FILE.
2341 FILE must already be registered in BACKEND. The change is not
2342 permanent, only for the current session. This function only changes
2343 VC's perspective on FILE, it does not register or unregister it.
2344 By default, this command cycles through the registered backends.
2345 To get a prompt, use a prefix argument."
2346 (interactive
2347 (list
2348 (or buffer-file-name
2349 (error "There is no version-controlled file in this buffer"))
2350 (let ((backend (vc-backend buffer-file-name))
2351 (backends nil))
2352 (unless backend
2353 (error "File %s is not under version control" buffer-file-name))
2354 ;; Find the registered backends.
2355 (dolist (backend vc-handled-backends)
2356 (when (vc-call-backend backend 'registered buffer-file-name)
2357 (push backend backends)))
2358 ;; Find the next backend.
2359 (let ((def (car (delq backend (append (memq backend backends) backends))))
2360 (others (delete backend backends)))
2361 (cond
2362 ((null others) (error "No other backend to switch to"))
2363 (current-prefix-arg
2364 (intern
2365 (upcase
2366 (completing-read
2367 (format "Switch to backend [%s]: " def)
2368 (mapcar (lambda (b) (list (downcase (symbol-name b)))) backends)
2369 nil t nil nil (downcase (symbol-name def))))))
2370 (t def))))))
2371 (unless (eq backend (vc-backend file))
2372 (vc-file-clearprops file)
2373 (vc-file-setprop file 'vc-backend backend)
2374 ;; Force recomputation of the state
2375 (unless (vc-call-backend backend 'registered file)
2376 (vc-file-clearprops file)
2377 (error "%s is not registered in %s" file backend))
2378 (vc-mode-line file)))
2379
2380 ;;;###autoload
2381 (defun vc-transfer-file (file new-backend)
2382 "Transfer FILE to another version control system NEW-BACKEND.
2383 If NEW-BACKEND has a higher precedence than FILE's current backend
2384 \(i.e. it comes earlier in `vc-handled-backends'), then register FILE in
2385 NEW-BACKEND, using the revision number from the current backend as the
2386 base level. If NEW-BACKEND has a lower precedence than the current
2387 backend, then commit all changes that were made under the current
2388 backend to NEW-BACKEND, and unregister FILE from the current backend.
2389 \(If FILE is not yet registered under NEW-BACKEND, register it.)"
2390 (let* ((old-backend (vc-backend file))
2391 (edited (memq (vc-state file) '(edited needs-merge)))
2392 (registered (vc-call-backend new-backend 'registered file))
2393 (move
2394 (and registered ; Never move if not registered in new-backend yet.
2395 ;; move if new-backend comes later in vc-handled-backends
2396 (or (memq new-backend (memq old-backend vc-handled-backends))
2397 (y-or-n-p "Final transfer? "))))
2398 (comment nil))
2399 (when (eq old-backend new-backend)
2400 (error "%s is the current backend of %s" new-backend file))
2401 (if registered
2402 (set-file-modes file (logior (file-modes file) 128))
2403 ;; `registered' might have switched under us.
2404 (vc-switch-backend file old-backend)
2405 (let* ((rev (vc-working-revision file))
2406 (modified-file (and edited (make-temp-file file)))
2407 (unmodified-file (and modified-file (vc-version-backup-file file))))
2408 ;; Go back to the base unmodified file.
2409 (unwind-protect
2410 (progn
2411 (when modified-file
2412 (copy-file file modified-file 'ok-if-already-exists)
2413 ;; If we have a local copy of the unmodified file, handle that
2414 ;; here and not in vc-revert-file because we don't want to
2415 ;; delete that copy -- it is still useful for OLD-BACKEND.
2416 (if unmodified-file
2417 (copy-file unmodified-file file
2418 'ok-if-already-exists 'keep-date)
2419 (when (y-or-n-p "Get base revision from master? ")
2420 (vc-revert-file file))))
2421 (vc-call-backend new-backend 'receive-file file rev))
2422 (when modified-file
2423 (vc-switch-backend file new-backend)
2424 (unless (eq (vc-checkout-model new-backend (list file)) 'implicit)
2425 (vc-checkout file t nil))
2426 (rename-file modified-file file 'ok-if-already-exists)
2427 (vc-file-setprop file 'vc-checkout-time nil)))))
2428 (when move
2429 (vc-switch-backend file old-backend)
2430 (setq comment (vc-call-backend old-backend 'comment-history file))
2431 (vc-call-backend old-backend 'unregister file))
2432 (vc-switch-backend file new-backend)
2433 (when (or move edited)
2434 (vc-file-setprop file 'vc-state 'edited)
2435 (vc-mode-line file)
2436 (vc-checkin file nil comment (stringp comment)))))
2437
2438 (defun vc-rename-master (oldmaster newfile templates)
2439 "Rename OLDMASTER to be the master file for NEWFILE based on TEMPLATES."
2440 (let* ((dir (file-name-directory (expand-file-name oldmaster)))
2441 (newdir (or (file-name-directory newfile) ""))
2442 (newbase (file-name-nondirectory newfile))
2443 (masters
2444 ;; List of potential master files for `newfile'
2445 (mapcar
2446 (lambda (s) (vc-possible-master s newdir newbase))
2447 templates)))
2448 (when (or (file-symlink-p oldmaster)
2449 (file-symlink-p (file-name-directory oldmaster)))
2450 (error "This is unsafe in the presence of symbolic links"))
2451 (rename-file
2452 oldmaster
2453 (catch 'found
2454 ;; If possible, keep the master file in the same directory.
2455 (dolist (f masters)
2456 (when (and f (string= (file-name-directory (expand-file-name f)) dir))
2457 (throw 'found f)))
2458 ;; If not, just use the first possible place.
2459 (dolist (f masters)
2460 (and f (or (not (setq dir (file-name-directory f)))
2461 (file-directory-p dir))
2462 (throw 'found f)))
2463 (error "New file lacks a version control directory")))))
2464
2465 (defun vc-delete-file (file)
2466 "Delete file and mark it as such in the version control system."
2467 (interactive "fVC delete file: ")
2468 (setq file (expand-file-name file))
2469 (let ((buf (get-file-buffer file))
2470 (backend (vc-backend file)))
2471 (unless backend
2472 (error "File %s is not under version control"
2473 (file-name-nondirectory file)))
2474 (unless (vc-find-backend-function backend 'delete-file)
2475 (error "Deleting files under %s is not supported in VC" backend))
2476 (when (and buf (buffer-modified-p buf))
2477 (error "Please save or undo your changes before deleting %s" file))
2478 (let ((state (vc-state file)))
2479 (when (eq state 'edited)
2480 (error "Please commit or undo your changes before deleting %s" file))
2481 (when (eq state 'conflict)
2482 (error "Please resolve the conflicts before deleting %s" file)))
2483 (unless (y-or-n-p (format "Really want to delete %s? "
2484 (file-name-nondirectory file)))
2485 (error "Abort!"))
2486 (unless (or (file-directory-p file) (null make-backup-files)
2487 (not (file-exists-p file)))
2488 (with-current-buffer (or buf (find-file-noselect file))
2489 (let ((backup-inhibited nil))
2490 (backup-buffer))))
2491 ;; Bind `default-directory' so that the command that the backend
2492 ;; runs to remove the file is invoked in the correct context.
2493 (let ((default-directory (file-name-directory file)))
2494 (vc-call-backend backend 'delete-file file))
2495 ;; If the backend hasn't deleted the file itself, let's do it for him.
2496 (when (file-exists-p file) (delete-file file))
2497 ;; Forget what VC knew about the file.
2498 (vc-file-clearprops file)
2499 ;; Make sure the buffer is deleted and the *vc-dir* buffers are
2500 ;; updated after this.
2501 (vc-resynch-buffer file nil t)))
2502
2503 ;;;###autoload
2504 (defun vc-rename-file (old new)
2505 "Rename file OLD to NEW, and rename its master file likewise."
2506 (interactive "fVC rename file: \nFRename to: ")
2507 ;; in CL I would have said (setq new (merge-pathnames new old))
2508 (let ((old-base (file-name-nondirectory old)))
2509 (when (and (not (string= "" old-base))
2510 (string= "" (file-name-nondirectory new)))
2511 (setq new (concat new old-base))))
2512 (let ((oldbuf (get-file-buffer old)))
2513 (when (and oldbuf (buffer-modified-p oldbuf))
2514 (error "Please save files before moving them"))
2515 (when (get-file-buffer new)
2516 (error "Already editing new file name"))
2517 (when (file-exists-p new)
2518 (error "New file already exists"))
2519 (let ((state (vc-state old)))
2520 (unless (memq state '(up-to-date edited))
2521 (error "Please %s files before moving them"
2522 (if (stringp state) "check in" "update"))))
2523 (vc-call rename-file old new)
2524 (vc-file-clearprops old)
2525 ;; Move the actual file (unless the backend did it already)
2526 (when (file-exists-p old) (rename-file old new))
2527 ;; ?? Renaming a file might change its contents due to keyword expansion.
2528 ;; We should really check out a new copy if the old copy was precisely equal
2529 ;; to some checked-in revision. However, testing for this is tricky....
2530 (when oldbuf
2531 (with-current-buffer oldbuf
2532 (let ((buffer-read-only buffer-read-only))
2533 (set-visited-file-name new))
2534 (vc-backend new)
2535 (vc-mode-line new)
2536 (set-buffer-modified-p nil)))))
2537
2538 ;;;###autoload
2539 (defun vc-update-change-log (&rest args)
2540 "Find change log file and add entries from recent version control logs.
2541 Normally, find log entries for all registered files in the default
2542 directory.
2543
2544 With prefix arg of \\[universal-argument], only find log entries for the current buffer's file.
2545
2546 With any numeric prefix arg, find log entries for all currently visited
2547 files that are under version control. This puts all the entries in the
2548 log for the default directory, which may not be appropriate.
2549
2550 From a program, any ARGS are assumed to be filenames for which
2551 log entries should be gathered."
2552 (interactive
2553 (cond ((consp current-prefix-arg) ;C-u
2554 (list buffer-file-name))
2555 (current-prefix-arg ;Numeric argument.
2556 (let ((files nil)
2557 (buffers (buffer-list))
2558 file)
2559 (while buffers
2560 (setq file (buffer-file-name (car buffers)))
2561 (and file (vc-backend file)
2562 (setq files (cons file files)))
2563 (setq buffers (cdr buffers)))
2564 files))
2565 (t
2566 ;; Don't supply any filenames to backend; this means
2567 ;; it should find all relevant files relative to
2568 ;; the default-directory.
2569 nil)))
2570 (vc-call-backend (vc-responsible-backend default-directory)
2571 'update-changelog args))
2572
2573 ;;; The default back end. Assumes RCS-like revision numbering.
2574
2575 (defun vc-default-revision-granularity ()
2576 (error "Your backend will not work with this version of VC mode."))
2577
2578 ;; functions that operate on RCS revision numbers. This code should
2579 ;; also be moved into the backends. It stays for now, however, since
2580 ;; it is used in code below.
2581 ;;;###autoload
2582 (defun vc-trunk-p (rev)
2583 "Return t if REV is a revision on the trunk."
2584 (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev))))
2585
2586 (defun vc-branch-p (rev)
2587 "Return t if REV is a branch revision."
2588 (not (eq nil (string-match "\\`[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*\\'" rev))))
2589
2590 ;;;###autoload
2591 (defun vc-branch-part (rev)
2592 "Return the branch part of a revision number REV."
2593 (let ((index (string-match "\\.[0-9]+\\'" rev)))
2594 (when index
2595 (substring rev 0 index))))
2596
2597 (defun vc-minor-part (rev)
2598 "Return the minor revision number of a revision number REV."
2599 (string-match "[0-9]+\\'" rev)
2600 (substring rev (match-beginning 0) (match-end 0)))
2601
2602 (defun vc-default-previous-revision (backend file rev)
2603 "Return the revision number immediately preceding REV for FILE,
2604 or nil if there is no previous revision. This default
2605 implementation works for MAJOR.MINOR-style revision numbers as
2606 used by RCS and CVS."
2607 (let ((branch (vc-branch-part rev))
2608 (minor-num (string-to-number (vc-minor-part rev))))
2609 (when branch
2610 (if (> minor-num 1)
2611 ;; revision does probably not start a branch or release
2612 (concat branch "." (number-to-string (1- minor-num)))
2613 (if (vc-trunk-p rev)
2614 ;; we are at the beginning of the trunk --
2615 ;; don't know anything to return here
2616 nil
2617 ;; we are at the beginning of a branch --
2618 ;; return revision of starting point
2619 (vc-branch-part branch))))))
2620
2621 (defun vc-default-next-revision (backend file rev)
2622 "Return the revision number immediately following REV for FILE,
2623 or nil if there is no next revision. This default implementation
2624 works for MAJOR.MINOR-style revision numbers as used by RCS
2625 and CVS."
2626 (when (not (string= rev (vc-working-revision file)))
2627 (let ((branch (vc-branch-part rev))
2628 (minor-num (string-to-number (vc-minor-part rev))))
2629 (concat branch "." (number-to-string (1+ minor-num))))))
2630
2631 (defun vc-default-responsible-p (backend file)
2632 "Indicate whether BACKEND is reponsible for FILE.
2633 The default is to return nil always."
2634 nil)
2635
2636 (defun vc-default-could-register (backend file)
2637 "Return non-nil if BACKEND could be used to register FILE.
2638 The default implementation returns t for all files."
2639 t)
2640
2641 (defun vc-default-latest-on-branch-p (backend file)
2642 "Return non-nil if FILE is the latest on its branch.
2643 This default implementation always returns non-nil, which means that
2644 editing non-current revisions is not supported by default."
2645 t)
2646
2647 (defun vc-default-init-revision (backend) vc-default-init-revision)
2648
2649 (defalias 'vc-cvs-update-changelog 'vc-update-changelog-rcs2log)
2650
2651 (defalias 'vc-rcs-update-changelog 'vc-update-changelog-rcs2log)
2652
2653 ;; FIXME: This should probably be moved to vc-rcs.el and replaced in
2654 ;; vc-cvs.el by code using cvs2cl.
2655 (defun vc-update-changelog-rcs2log (files)
2656 "Default implementation of update-changelog.
2657 Uses `rcs2log' which only works for RCS and CVS."
2658 ;; FIXME: We (c|sh)ould add support for cvs2cl
2659 (let ((odefault default-directory)
2660 (changelog (find-change-log))
2661 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
2662 (tempfile (make-temp-file
2663 (expand-file-name "vc"
2664 (or small-temporary-file-directory
2665 temporary-file-directory))))
2666 (login-name (or user-login-name
2667 (format "uid%d" (number-to-string (user-uid)))))
2668 (full-name (or add-log-full-name
2669 (user-full-name)
2670 (user-login-name)
2671 (format "uid%d" (number-to-string (user-uid)))))
2672 (mailing-address (or add-log-mailing-address
2673 user-mail-address)))
2674 (find-file-other-window changelog)
2675 (barf-if-buffer-read-only)
2676 (vc-buffer-sync)
2677 (undo-boundary)
2678 (goto-char (point-min))
2679 (push-mark)
2680 (message "Computing change log entries...")
2681 (message "Computing change log entries... %s"
2682 (unwind-protect
2683 (progn
2684 (setq default-directory odefault)
2685 (if (eq 0 (apply 'call-process
2686 (expand-file-name "rcs2log"
2687 exec-directory)
2688 nil (list t tempfile) nil
2689 "-c" changelog
2690 "-u" (concat login-name
2691 "\t" full-name
2692 "\t" mailing-address)
2693 (mapcar
2694 (lambda (f)
2695 (file-relative-name
2696 (expand-file-name f odefault)))
2697 files)))
2698 "done"
2699 (pop-to-buffer (get-buffer-create "*vc*"))
2700 (erase-buffer)
2701 (insert-file-contents tempfile)
2702 "failed"))
2703 (setq default-directory (file-name-directory changelog))
2704 (delete-file tempfile)))))
2705
2706 (defun vc-default-find-revision (backend file rev buffer)
2707 "Provide the new `find-revision' op based on the old `checkout' op.
2708 This is only for compatibility with old backends. They should be updated
2709 to provide the `find-revision' operation instead."
2710 (let ((tmpfile (make-temp-file (expand-file-name file))))
2711 (unwind-protect
2712 (progn
2713 (vc-call-backend backend 'checkout file nil rev tmpfile)
2714 (with-current-buffer buffer
2715 (insert-file-contents-literally tmpfile)))
2716 (delete-file tmpfile))))
2717
2718 (defun vc-default-prettify-state-info (backend file)
2719 (let* ((state (vc-state file))
2720 (statestring
2721 (cond
2722 ((stringp state) (concat "(locked:" state ")"))
2723 ((eq state 'edited) "(modified)")
2724 ((eq state 'needs-merge) "(merge)")
2725 ((eq state 'needs-update) "(update)")
2726 ((eq state 'added) "(added)")
2727 ((eq state 'removed) "(removed)")
2728 ((eq state 'ignored) "(ignored)")
2729 ((eq state 'unregistered) "(unregistered)")
2730 ((eq state 'unlocked-changes) "(stale)")
2731 (t (format "(unknown:%s)" state))))
2732 (buffer
2733 (get-file-buffer file))
2734 (modflag
2735 (if (and buffer (buffer-modified-p buffer)) "+" "")))
2736 (concat statestring modflag)))
2737
2738 (defun vc-default-rename-file (backend old new)
2739 (condition-case nil
2740 (add-name-to-file old new)
2741 (error (rename-file old new)))
2742 (vc-delete-file old)
2743 (with-current-buffer (find-file-noselect new)
2744 (vc-register)))
2745
2746 (defalias 'vc-default-check-headers 'ignore)
2747
2748 (defun vc-default-log-view-mode (backend) (log-view-mode))
2749
2750 (defun vc-default-show-log-entry (backend rev)
2751 (with-no-warnings
2752 (log-view-goto-rev rev)))
2753
2754 (defun vc-default-comment-history (backend file)
2755 "Return a string with all log entries stored in BACKEND for FILE."
2756 (when (vc-find-backend-function backend 'print-log)
2757 (with-current-buffer "*vc*"
2758 (vc-call-backend backend 'print-log (list file))
2759 (buffer-string))))
2760
2761 (defun vc-default-receive-file (backend file rev)
2762 "Let BACKEND receive FILE from another version control system."
2763 (vc-call-backend backend 'register file rev ""))
2764
2765 (defun vc-default-retrieve-tag (backend dir name update)
2766 (if (string= name "")
2767 (progn
2768 (vc-file-tree-walk
2769 dir
2770 (lambda (f) (and
2771 (vc-up-to-date-p f)
2772 (vc-error-occurred
2773 (vc-call-backend backend 'checkout f nil "")
2774 (when update (vc-resynch-buffer f t t)))))))
2775 (let ((result (vc-tag-precondition dir)))
2776 (if (stringp result)
2777 (error "File %s is locked" result)
2778 (setq update (and (eq result 'visited) update))
2779 (vc-file-tree-walk
2780 dir
2781 (lambda (f) (vc-error-occurred
2782 (vc-call-backend backend 'checkout f nil name)
2783 (when update (vc-resynch-buffer f t t)))))))))
2784
2785 (defun vc-default-revert (backend file contents-done)
2786 (unless contents-done
2787 (let ((rev (vc-working-revision file))
2788 (file-buffer (or (get-file-buffer file) (current-buffer))))
2789 (message "Checking out %s..." file)
2790 (let ((failed t)
2791 (backup-name (car (find-backup-file-name file))))
2792 (when backup-name
2793 (copy-file file backup-name 'ok-if-already-exists 'keep-date)
2794 (unless (file-writable-p file)
2795 (set-file-modes file (logior (file-modes file) 128))))
2796 (unwind-protect
2797 (let ((coding-system-for-read 'no-conversion)
2798 (coding-system-for-write 'no-conversion))
2799 (with-temp-file file
2800 (let ((outbuf (current-buffer)))
2801 ;; Change buffer to get local value of vc-checkout-switches.
2802 (with-current-buffer file-buffer
2803 (let ((default-directory (file-name-directory file)))
2804 (vc-call-backend backend 'find-revision
2805 file rev outbuf)))))
2806 (setq failed nil))
2807 (when backup-name
2808 (if failed
2809 (rename-file backup-name file 'ok-if-already-exists)
2810 (and (not vc-make-backup-files) (delete-file backup-name))))))
2811 (message "Checking out %s...done" file))))
2812
2813 (defalias 'vc-default-revision-completion-table 'ignore)
2814
2815 (defun vc-default-dir-status-files (backend dir files default-state update-function)
2816 (funcall update-function
2817 (mapcar (lambda (file) (list file default-state)) files)))
2818
2819 (defun vc-check-headers ()
2820 "Check if the current file has any headers in it."
2821 (interactive)
2822 (vc-call-backend (vc-backend buffer-file-name) 'check-headers))
2823
2824 ;;; Annotate functionality
2825
2826 ;; Declare globally instead of additional parameter to
2827 ;; temp-buffer-show-function (not possible to pass more than one
2828 ;; parameter). The use of annotate-ratio is deprecated in favor of
2829 ;; annotate-mode, which replaces it with the more sensible "span-to
2830 ;; days", along with autoscaling support.
2831 (defvar vc-annotate-ratio nil "Global variable.")
2832
2833 ;; internal buffer-local variables
2834 (defvar vc-annotate-backend nil)
2835 (defvar vc-annotate-parent-file nil)
2836 (defvar vc-annotate-parent-rev nil)
2837 (defvar vc-annotate-parent-display-mode nil)
2838
2839 (defconst vc-annotate-font-lock-keywords
2840 ;; The fontification is done by vc-annotate-lines instead of font-lock.
2841 '((vc-annotate-lines)))
2842
2843 (define-derived-mode vc-annotate-mode fundamental-mode "Annotate"
2844 "Major mode for output buffers of the `vc-annotate' command.
2845
2846 You can use the mode-specific menu to alter the time-span of the used
2847 colors. See variable `vc-annotate-menu-elements' for customizing the
2848 menu items."
2849 ;; Frob buffer-invisibility-spec so that if it is originally a naked t,
2850 ;; it will become a list, to avoid initial annotations being invisible.
2851 (add-to-invisibility-spec 'foo)
2852 (remove-from-invisibility-spec 'foo)
2853 (set (make-local-variable 'truncate-lines) t)
2854 (set (make-local-variable 'font-lock-defaults)
2855 '(vc-annotate-font-lock-keywords t))
2856 (view-mode 1))
2857
2858 (defun vc-annotate-toggle-annotation-visibility ()
2859 "Toggle whether or not the annotation is visible."
2860 (interactive)
2861 (funcall (if (memq 'vc-annotate-annotation buffer-invisibility-spec)
2862 'remove-from-invisibility-spec
2863 'add-to-invisibility-spec)
2864 'vc-annotate-annotation)
2865 (force-window-update (current-buffer)))
2866
2867 (defun vc-annotate-display-default (ratio)
2868 "Display the output of \\[vc-annotate] using the default color range.
2869 The color range is given by `vc-annotate-color-map', scaled by RATIO.
2870 The current time is used as the offset."
2871 (interactive (progn (kill-local-variable 'vc-annotate-color-map) '(1.0)))
2872 (message "Redisplaying annotation...")
2873 (vc-annotate-display ratio)
2874 (message "Redisplaying annotation...done"))
2875
2876 (defun vc-annotate-oldest-in-map (color-map)
2877 "Return the oldest time in the COLOR-MAP."
2878 ;; Since entries should be sorted, we can just use the last one.
2879 (caar (last color-map)))
2880
2881 (defun vc-annotate-get-time-set-line-props ()
2882 (let ((bol (point))
2883 (date (vc-call-backend vc-annotate-backend 'annotate-time))
2884 (inhibit-read-only t))
2885 (assert (>= (point) bol))
2886 (put-text-property bol (point) 'invisible 'vc-annotate-annotation)
2887 date))
2888
2889 (defun vc-annotate-display-autoscale (&optional full)
2890 "Highlight the output of \\[vc-annotate] using an autoscaled color map.
2891 Autoscaling means that the map is scaled from the current time to the
2892 oldest annotation in the buffer, or, with prefix argument FULL, to
2893 cover the range from the oldest annotation to the newest."
2894 (interactive "P")
2895 (let ((newest 0.0)
2896 (oldest 999999.) ;Any CVS users at the founding of Rome?
2897 (current (vc-annotate-convert-time (current-time)))
2898 date)
2899 (message "Redisplaying annotation...")
2900 ;; Run through this file and find the oldest and newest dates annotated.
2901 (save-excursion
2902 (goto-char (point-min))
2903 (while (not (eobp))
2904 (when (setq date (vc-annotate-get-time-set-line-props))
2905 (when (> date newest)
2906 (setq newest date))
2907 (when (< date oldest)
2908 (setq oldest date)))
2909 (forward-line 1)))
2910 (vc-annotate-display
2911 (/ (- (if full newest current) oldest)
2912 (vc-annotate-oldest-in-map vc-annotate-color-map))
2913 (if full newest))
2914 (message "Redisplaying annotation...done \(%s\)"
2915 (if full
2916 (format "Spanned from %.1f to %.1f days old"
2917 (- current oldest)
2918 (- current newest))
2919 (format "Spanned to %.1f days old" (- current oldest))))))
2920
2921 ;; Menu -- Using easymenu.el
2922 (easy-menu-define vc-annotate-mode-menu vc-annotate-mode-map
2923 "VC Annotate Display Menu"
2924 `("VC-Annotate"
2925 ["By Color Map Range" (unless (null vc-annotate-display-mode)
2926 (setq vc-annotate-display-mode nil)
2927 (vc-annotate-display-select))
2928 :style toggle :selected (null vc-annotate-display-mode)]
2929 ,@(let ((oldest-in-map (vc-annotate-oldest-in-map vc-annotate-color-map)))
2930 (mapcar (lambda (element)
2931 (let ((days (* element oldest-in-map)))
2932 `[,(format "Span %.1f days" days)
2933 (vc-annotate-display-select nil ,days)
2934 :style toggle :selected
2935 (eql vc-annotate-display-mode ,days) ]))
2936 vc-annotate-menu-elements))
2937 ["Span ..."
2938 (vc-annotate-display-select
2939 nil (float (string-to-number (read-string "Span how many days? "))))]
2940 "--"
2941 ["Span to Oldest"
2942 (unless (eq vc-annotate-display-mode 'scale)
2943 (vc-annotate-display-select nil 'scale))
2944 :help
2945 "Use an autoscaled color map from the oldest annotation to the current time"
2946 :style toggle :selected
2947 (eq vc-annotate-display-mode 'scale)]
2948 ["Span Oldest->Newest"
2949 (unless (eq vc-annotate-display-mode 'fullscale)
2950 (vc-annotate-display-select nil 'fullscale))
2951 :help
2952 "Use an autoscaled color map from the oldest to the newest annotation"
2953 :style toggle :selected
2954 (eq vc-annotate-display-mode 'fullscale)]
2955 "--"
2956 ["Toggle annotation visibility" vc-annotate-toggle-annotation-visibility
2957 :help
2958 "Toggle whether the annotation is visible or not"]
2959 ["Annotate previous revision" vc-annotate-prev-revision
2960 :help "Visit the annotation of the revision previous to this one"]
2961 ["Annotate next revision" vc-annotate-next-revision
2962 :help "Visit the annotation of the revision after this one"]
2963 ["Annotate revision at line" vc-annotate-revision-at-line
2964 :help
2965 "Visit the annotation of the revision identified in the current line"]
2966 ["Annotate revision previous to line" vc-annotate-revision-previous-to-line
2967 :help "Visit the annotation of the revision before the revision at line"]
2968 ["Annotate latest revision" vc-annotate-working-revision
2969 :help "Visit the annotation of the working revision of this file"]
2970 ["Show log of revision at line" vc-annotate-show-log-revision-at-line
2971 :help "Visit the log of the revision at line"]
2972 ["Show diff of revision at line" vc-annotate-show-diff-revision-at-line
2973 :help "Visit the diff of the revision at line from its previous revision"]
2974 ["Show changeset diff of revision at line"
2975 vc-annotate-show-changeset-diff-revision-at-line
2976 :enable
2977 (eq 'repository (vc-call-backend ,vc-annotate-backend 'revision-granularity))
2978 :help "Visit the diff of the revision at line from its previous revision"]
2979 ["Visit revision at line" vc-annotate-find-revision-at-line
2980 :help "Visit the revision identified in the current line"]))
2981
2982 (defun vc-annotate-display-select (&optional buffer mode)
2983 "Highlight the output of \\[vc-annotate].
2984 By default, the current buffer is highlighted, unless overridden by
2985 BUFFER. `vc-annotate-display-mode' specifies the highlighting mode to
2986 use; you may override this using the second optional arg MODE."
2987 (interactive)
2988 (when mode (setq vc-annotate-display-mode mode))
2989 (pop-to-buffer (or buffer (current-buffer)))
2990 (cond ((null vc-annotate-display-mode)
2991 ;; The ratio is global, thus relative to the global color-map.
2992 (kill-local-variable 'vc-annotate-color-map)
2993 (vc-annotate-display-default (or vc-annotate-ratio 1.0)))
2994 ;; One of the auto-scaling modes
2995 ((eq vc-annotate-display-mode 'scale)
2996 (vc-exec-after `(vc-annotate-display-autoscale)))
2997 ((eq vc-annotate-display-mode 'fullscale)
2998 (vc-exec-after `(vc-annotate-display-autoscale t)))
2999 ((numberp vc-annotate-display-mode) ; A fixed number of days lookback
3000 (vc-annotate-display-default
3001 (/ vc-annotate-display-mode
3002 (vc-annotate-oldest-in-map vc-annotate-color-map))))
3003 (t (error "No such display mode: %s"
3004 vc-annotate-display-mode))))
3005
3006 ;;;###autoload
3007 (defun vc-annotate (file rev &optional display-mode buf move-point-to)
3008 "Display the edit history of the current file using colors.
3009
3010 This command creates a buffer that shows, for each line of the current
3011 file, when it was last edited and by whom. Additionally, colors are
3012 used to show the age of each line--blue means oldest, red means
3013 youngest, and intermediate colors indicate intermediate ages. By
3014 default, the time scale stretches back one year into the past;
3015 everything that is older than that is shown in blue.
3016
3017 With a prefix argument, this command asks two questions in the
3018 minibuffer. First, you may enter a revision number; then the buffer
3019 displays and annotates that revision instead of the working revision
3020 \(type RET in the minibuffer to leave that default unchanged). Then,
3021 you are prompted for the time span in days which the color range
3022 should cover. For example, a time span of 20 days means that changes
3023 over the past 20 days are shown in red to blue, according to their
3024 age, and everything that is older than that is shown in blue.
3025
3026 If MOVE-POINT-TO is given, move the point to that line.
3027
3028 Customization variables:
3029
3030 `vc-annotate-menu-elements' customizes the menu elements of the
3031 mode-specific menu. `vc-annotate-color-map' and
3032 `vc-annotate-very-old-color' define the mapping of time to colors.
3033 `vc-annotate-background' specifies the background color."
3034 (interactive
3035 (save-current-buffer
3036 (vc-ensure-vc-buffer)
3037 (list buffer-file-name
3038 (let ((def (vc-working-revision buffer-file-name)))
3039 (if (null current-prefix-arg) def
3040 (read-string
3041 (format "Annotate from revision (default %s): " def)
3042 nil nil def)))
3043 (if (null current-prefix-arg)
3044 vc-annotate-display-mode
3045 (float (string-to-number
3046 (read-string "Annotate span days (default 20): "
3047 nil nil "20")))))))
3048 (vc-ensure-vc-buffer)
3049 (setq vc-annotate-display-mode display-mode) ;Not sure why. --Stef
3050 (let* ((temp-buffer-name (format "*Annotate %s (rev %s)*" (buffer-name) rev))
3051 (temp-buffer-show-function 'vc-annotate-display-select)
3052 ;; If BUF is specified, we presume the caller maintains current line,
3053 ;; so we don't need to do it here. This implementation may give
3054 ;; strange results occasionally in the case of REV != WORKFILE-REV.
3055 (current-line (or move-point-to (unless buf (line-number-at-pos)))))
3056 (message "Annotating...")
3057 ;; If BUF is specified it tells in which buffer we should put the
3058 ;; annotations. This is used when switching annotations to another
3059 ;; revision, so we should update the buffer's name.
3060 (when buf (with-current-buffer buf
3061 (rename-buffer temp-buffer-name t)
3062 ;; In case it had to be uniquified.
3063 (setq temp-buffer-name (buffer-name))))
3064 (with-output-to-temp-buffer temp-buffer-name
3065 (let ((backend (vc-backend file)))
3066 (vc-call-backend backend 'annotate-command file
3067 (get-buffer temp-buffer-name) rev)
3068 ;; we must setup the mode first, and then set our local
3069 ;; variables before the show-function is called at the exit of
3070 ;; with-output-to-temp-buffer
3071 (with-current-buffer temp-buffer-name
3072 (unless (equal major-mode 'vc-annotate-mode)
3073 (vc-annotate-mode))
3074 (set (make-local-variable 'vc-annotate-backend) backend)
3075 (set (make-local-variable 'vc-annotate-parent-file) file)
3076 (set (make-local-variable 'vc-annotate-parent-rev) rev)
3077 (set (make-local-variable 'vc-annotate-parent-display-mode)
3078 display-mode))))
3079
3080 (with-current-buffer temp-buffer-name
3081 (vc-exec-after
3082 `(progn
3083 ;; Ideally, we'd rather not move point if the user has already
3084 ;; moved it elsewhere, but really point here is not the position
3085 ;; of the user's cursor :-(
3086 (when ,current-line ;(and (bobp))
3087 (goto-line ,current-line)
3088 (setq vc-sentinel-movepoint (point)))
3089 (unless (active-minibuffer-window)
3090 (message "Annotating... done")))))))
3091
3092 (defun vc-annotate-prev-revision (prefix)
3093 "Visit the annotation of the revision previous to this one.
3094
3095 With a numeric prefix argument, annotate the revision that many
3096 revisions previous."
3097 (interactive "p")
3098 (vc-annotate-warp-revision (- 0 prefix)))
3099
3100 (defun vc-annotate-next-revision (prefix)
3101 "Visit the annotation of the revision after this one.
3102
3103 With a numeric prefix argument, annotate the revision that many
3104 revisions after."
3105 (interactive "p")
3106 (vc-annotate-warp-revision prefix))
3107
3108 (defun vc-annotate-working-revision ()
3109 "Visit the annotation of the working revision of this file."
3110 (interactive)
3111 (if (not (equal major-mode 'vc-annotate-mode))
3112 (message "Cannot be invoked outside of a vc annotate buffer")
3113 (let ((warp-rev (vc-working-revision vc-annotate-parent-file)))
3114 (if (equal warp-rev vc-annotate-parent-rev)
3115 (message "Already at revision %s" warp-rev)
3116 (vc-annotate-warp-revision warp-rev)))))
3117
3118 (defun vc-annotate-extract-revision-at-line ()
3119 "Extract the revision number of the current line."
3120 ;; This function must be invoked from a buffer in vc-annotate-mode
3121 (vc-call-backend vc-annotate-backend 'annotate-extract-revision-at-line))
3122
3123 (defun vc-annotate-revision-at-line ()
3124 "Visit the annotation of the revision identified in the current line."
3125 (interactive)
3126 (if (not (equal major-mode 'vc-annotate-mode))
3127 (message "Cannot be invoked outside of a vc annotate buffer")
3128 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
3129 (if (not rev-at-line)
3130 (message "Cannot extract revision number from the current line")
3131 (if (equal rev-at-line vc-annotate-parent-rev)
3132 (message "Already at revision %s" rev-at-line)
3133 (vc-annotate-warp-revision rev-at-line))))))
3134
3135 (defun vc-annotate-find-revision-at-line ()
3136 "Visit the revision identified in the current line."
3137 (interactive)
3138 (if (not (equal major-mode 'vc-annotate-mode))
3139 (message "Cannot be invoked outside of a vc annotate buffer")
3140 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
3141 (if (not rev-at-line)
3142 (message "Cannot extract revision number from the current line")
3143 (vc-revision-other-window rev-at-line)))))
3144
3145 (defun vc-annotate-revision-previous-to-line ()
3146 "Visit the annotation of the revision before the revision at line."
3147 (interactive)
3148 (if (not (equal major-mode 'vc-annotate-mode))
3149 (message "Cannot be invoked outside of a vc annotate buffer")
3150 (let ((rev-at-line (vc-annotate-extract-revision-at-line))
3151 (prev-rev nil))
3152 (if (not rev-at-line)
3153 (message "Cannot extract revision number from the current line")
3154 (setq prev-rev
3155 (vc-call-backend vc-annotate-backend 'previous-revision
3156 vc-annotate-parent-file rev-at-line))
3157 (vc-annotate-warp-revision prev-rev)))))
3158
3159 (defun vc-annotate-show-log-revision-at-line ()
3160 "Visit the log of the revision at line."
3161 (interactive)
3162 (if (not (equal major-mode 'vc-annotate-mode))
3163 (message "Cannot be invoked outside of a vc annotate buffer")
3164 (let ((rev-at-line (vc-annotate-extract-revision-at-line)))
3165 (if (not rev-at-line)
3166 (message "Cannot extract revision number from the current line")
3167 (vc-print-log rev-at-line)))))
3168
3169 (defun vc-annotate-show-diff-revision-at-line-internal (fileset)
3170 (if (not (equal major-mode 'vc-annotate-mode))
3171 (message "Cannot be invoked outside of a vc annotate buffer")
3172 (let ((rev-at-line (vc-annotate-extract-revision-at-line))
3173 (prev-rev nil))
3174 (if (not rev-at-line)
3175 (message "Cannot extract revision number from the current line")
3176 (setq prev-rev
3177 (vc-call-backend vc-annotate-backend 'previous-revision
3178 vc-annotate-parent-file rev-at-line))
3179 (if (not prev-rev)
3180 (message "Cannot diff from any revision prior to %s" rev-at-line)
3181 (save-window-excursion
3182 (vc-diff-internal
3183 nil
3184 ;; The value passed here should follow what
3185 ;; `vc-deduce-fileset' returns.
3186 (cons vc-annotate-backend (cons fileset nil))
3187 prev-rev rev-at-line))
3188 (switch-to-buffer "*vc-diff*"))))))
3189
3190 (defun vc-annotate-show-diff-revision-at-line ()
3191 "Visit the diff of the revision at line from its previous revision."
3192 (interactive)
3193 (vc-annotate-show-diff-revision-at-line-internal (list vc-annotate-parent-file)))
3194
3195 (defun vc-annotate-show-changeset-diff-revision-at-line ()
3196 "Visit the diff of the revision at line from its previous revision for all files in the changeset."
3197 (interactive)
3198 (when (eq 'file (vc-call-backend vc-annotate-backend 'revision-granularity))
3199 (error "The %s backend does not support changeset diffs" vc-annotate-backend))
3200 (vc-annotate-show-diff-revision-at-line-internal nil))
3201
3202 (defun vc-annotate-warp-revision (revspec)
3203 "Annotate the revision described by REVSPEC.
3204
3205 If REVSPEC is a positive integer, warp that many revisions
3206 forward, if possible, otherwise echo a warning message. If
3207 REVSPEC is a negative integer, warp that many revisions backward,
3208 if possible, otherwise echo a warning message. If REVSPEC is a
3209 string, then it describes a revision number, so warp to that
3210 revision."
3211 (if (not (equal major-mode 'vc-annotate-mode))
3212 (message "Cannot be invoked outside of a vc annotate buffer")
3213 (let* ((buf (current-buffer))
3214 (oldline (line-number-at-pos))
3215 (revspeccopy revspec)
3216 (newrev nil))
3217 (cond
3218 ((and (integerp revspec) (> revspec 0))
3219 (setq newrev vc-annotate-parent-rev)
3220 (while (and (> revspec 0) newrev)
3221 (setq newrev (vc-call-backend vc-annotate-backend 'next-revision
3222 vc-annotate-parent-file newrev))
3223 (setq revspec (1- revspec)))
3224 (unless newrev
3225 (message "Cannot increment %d revisions from revision %s"
3226 revspeccopy vc-annotate-parent-rev)))
3227 ((and (integerp revspec) (< revspec 0))
3228 (setq newrev vc-annotate-parent-rev)
3229 (while (and (< revspec 0) newrev)
3230 (setq newrev (vc-call-backend vc-annotate-backend 'previous-revision
3231 vc-annotate-parent-file newrev))
3232 (setq revspec (1+ revspec)))
3233 (unless newrev
3234 (message "Cannot decrement %d revisions from revision %s"
3235 (- 0 revspeccopy) vc-annotate-parent-rev)))
3236 ((stringp revspec) (setq newrev revspec))
3237 (t (error "Invalid argument to vc-annotate-warp-revision")))
3238 (when newrev
3239 (vc-annotate vc-annotate-parent-file newrev
3240 vc-annotate-parent-display-mode
3241 buf
3242 ;; Pass the current line so that vc-annotate will
3243 ;; place the point in the line.
3244 (min oldline (progn (goto-char (point-max))
3245 (forward-line -1)
3246 (line-number-at-pos))))))))
3247
3248 (defun vc-annotate-compcar (threshold a-list)
3249 "Test successive cons cells of A-LIST against THRESHOLD.
3250 Return the first cons cell with a car that is not less than THRESHOLD,
3251 nil if no such cell exists."
3252 (let ((i 1)
3253 (tmp-cons (car a-list)))
3254 (while (and tmp-cons (< (car tmp-cons) threshold))
3255 (setq tmp-cons (car (nthcdr i a-list)))
3256 (setq i (+ i 1)))
3257 tmp-cons)) ; Return the appropriate value
3258
3259 (defun vc-annotate-convert-time (time)
3260 "Convert a time value to a floating-point number of days.
3261 The argument TIME is a list as returned by `current-time' or
3262 `encode-time', only the first two elements of that list are considered."
3263 (/ (+ (* (float (car time)) (lsh 1 16)) (cadr time)) 24 3600))
3264
3265 (defun vc-annotate-difference (&optional offset)
3266 "Return the time span in days to the next annotation.
3267 This calls the backend function annotate-time, and returns the
3268 difference in days between the time returned and the current time,
3269 or OFFSET if present."
3270 (let ((next-time (vc-annotate-get-time-set-line-props)))
3271 (when next-time
3272 (- (or offset
3273 (vc-call-backend vc-annotate-backend 'annotate-current-time))
3274 next-time))))
3275
3276 (defun vc-default-annotate-current-time (backend)
3277 "Return the current time, encoded as fractional days."
3278 (vc-annotate-convert-time (current-time)))
3279
3280 (defvar vc-annotate-offset nil)
3281
3282 (defun vc-annotate-display (ratio &optional offset)
3283 "Highlight `vc-annotate' output in the current buffer.
3284 RATIO, is the expansion that should be applied to `vc-annotate-color-map'.
3285 The annotations are relative to the current time, unless overridden by OFFSET."
3286 (when (/= ratio 1.0)
3287 (set (make-local-variable 'vc-annotate-color-map)
3288 (mapcar (lambda (elem) (cons (* (car elem) ratio) (cdr elem)))
3289 vc-annotate-color-map)))
3290 (set (make-local-variable 'vc-annotate-offset) offset)
3291 (font-lock-mode 1))
3292
3293 (defun vc-annotate-lines (limit)
3294 (while (< (point) limit)
3295 (let ((difference (vc-annotate-difference vc-annotate-offset))
3296 (start (point))
3297 (end (progn (forward-line 1) (point))))
3298 (when difference
3299 (let* ((color (or (vc-annotate-compcar difference vc-annotate-color-map)
3300 (cons nil vc-annotate-very-old-color)))
3301 ;; substring from index 1 to remove any leading `#' in the name
3302 (face-name (concat "vc-annotate-face-"
3303 (if (string-equal
3304 (substring (cdr color) 0 1) "#")
3305 (substring (cdr color) 1)
3306 (cdr color))))
3307 ;; Make the face if not done.
3308 (face (or (intern-soft face-name)
3309 (let ((tmp-face (make-face (intern face-name))))
3310 (set-face-foreground tmp-face (cdr color))
3311 (when vc-annotate-background
3312 (set-face-background tmp-face
3313 vc-annotate-background))
3314 tmp-face)))) ; Return the face
3315 (put-text-property start end 'face face)))))
3316 ;; Pretend to font-lock there were no matches.
3317 nil)
3318 \f
3319
3320 ;; These things should probably be generally available
3321
3322 (defun vc-file-tree-walk (dirname func &rest args)
3323 "Walk recursively through DIRNAME.
3324 Invoke FUNC f ARGS on each VC-managed file f underneath it."
3325 (vc-file-tree-walk-internal (expand-file-name dirname) func args)
3326 (message "Traversing directory %s...done" dirname))
3327
3328 (defun vc-file-tree-walk-internal (file func args)
3329 (if (not (file-directory-p file))
3330 (when (vc-backend file) (apply func file args))
3331 (message "Traversing directory %s..." (abbreviate-file-name file))
3332 (let ((dir (file-name-as-directory file)))
3333 (mapcar
3334 (lambda (f) (or
3335 (string-equal f ".")
3336 (string-equal f "..")
3337 (member f vc-directory-exclusion-list)
3338 (let ((dirf (expand-file-name f dir)))
3339 (or
3340 (file-symlink-p dirf) ;; Avoid possible loops.
3341 (vc-file-tree-walk-internal dirf func args)))))
3342 (directory-files dir)))))
3343
3344 (provide 'vc)
3345
3346 ;; arch-tag: ca82c1de-3091-4e26-af92-460abc6213a6
3347 ;;; vc.el ends here