Eliminate an unuted function argument.
[emacs.git] / lisp / vc / vc.el
blobc4810cf8b8b4cb47c9c54158d90011eabc1827ef
1 ;;; vc.el --- drive a version-control system from within Emacs -*- lexical-binding:t -*-
3 ;; Copyright (C) 1992-1998, 2000-2014 Free Software Foundation, Inc.
5 ;; Author: FSF (see below for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
7 ;; Keywords: vc tools
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Credits:
26 ;; VC was initially designed and implemented by Eric S. Raymond
27 ;; <esr@thyrsus.com> in 1992. Over the years, many other people have
28 ;; contributed substantial amounts of work to VC. These include:
30 ;; Per Cederqvist <ceder@lysator.liu.se>
31 ;; Paul Eggert <eggert@twinsun.com>
32 ;; Sebastian Kremer <sk@thp.uni-koeln.de>
33 ;; Martin Lorentzson <martinl@gnu.org>
34 ;; Dave Love <fx@gnu.org>
35 ;; Stefan Monnier <monnier@cs.yale.edu>
36 ;; Thien-Thi Nguyen <ttn@gnu.org>
37 ;; Dan Nicolaescu <dann@ics.uci.edu>
38 ;; J.D. Smith <jdsmith@alum.mit.edu>
39 ;; Andre Spiegel <spiegel@gnu.org>
40 ;; Richard Stallman <rms@gnu.org>
42 ;; In July 2007 ESR returned and redesigned the mode to cope better
43 ;; with modern version-control systems that do commits by fileset
44 ;; rather than per individual file.
46 ;; If you maintain a client of the mode or customize it in your .emacs,
47 ;; note that some backend functions which formerly took single file arguments
48 ;; now take a list of files. These include: register, checkin, print-log,
49 ;; rollback, and diff.
51 ;;; Commentary:
53 ;; This mode is fully documented in the Emacs user's manual.
55 ;; Supported version-control systems presently include CVS, RCS, SRC, GNU
56 ;; Arch, Subversion, Bzr, Git, Mercurial, Monotone and SCCS
57 ;; (or its free replacement, CSSC).
59 ;; If your site uses the ChangeLog convention supported by Emacs, the
60 ;; function `log-edit-comment-to-change-log' could prove a useful checkin hook,
61 ;; although you might prefer to use C-c C-a (i.e. `log-edit-insert-changelog')
62 ;; from the commit buffer instead or to set `log-edit-setup-invert'.
64 ;; When using SCCS, RCS, CVS: be careful not to do repo surgery, or
65 ;; operations like registrations and deletions and renames, outside VC
66 ;; while VC is running. The support for these systems was designed
67 ;; when disks were much slower, and the code maintains a lot of
68 ;; internal state in order to reduce expensive operations to a
69 ;; minimum. Thus, if you mess with the repo while VC's back is turned,
70 ;; VC may get seriously confused.
72 ;; When using Subversion or a later system, anything you do outside VC
73 ;; *through the VCS tools* should safely interlock with VC
74 ;; operations. Under these VC does little state caching, because local
75 ;; operations are assumed to be fast.
77 ;; The 'assumed to be fast' category includes SRC, even though it's
78 ;; a wrapper around RCS.
80 ;; ADDING SUPPORT FOR OTHER BACKENDS
82 ;; VC can use arbitrary version control systems as a backend. To add
83 ;; support for a new backend named SYS, write a library vc-sys.el that
84 ;; contains functions of the form `vc-sys-...' (note that SYS is in lower
85 ;; case for the function and library names). VC will use that library if
86 ;; you put the symbol SYS somewhere into the list of
87 ;; `vc-handled-backends'. Then, for example, if `vc-sys-registered'
88 ;; returns non-nil for a file, all SYS-specific versions of VC commands
89 ;; will be available for that file.
91 ;; VC keeps some per-file information in the form of properties (see
92 ;; vc-file-set/getprop in vc-hooks.el). The backend-specific functions
93 ;; do not generally need to be aware of these properties. For example,
94 ;; `vc-sys-working-revision' should compute the working revision and
95 ;; return it; it should not look it up in the property, and it needn't
96 ;; store it there either. However, if a backend-specific function does
97 ;; store a value in a property, that value takes precedence over any
98 ;; value that the generic code might want to set (check for uses of
99 ;; the macro `with-vc-properties' in vc.el).
101 ;; In the list of functions below, each identifier needs to be prepended
102 ;; with `vc-sys-'. Some of the functions are mandatory (marked with a
103 ;; `*'), others are optional (`-').
105 ;; BACKEND PROPERTIES
107 ;; * revision-granularity
109 ;; Takes no arguments. Returns either 'file or 'repository. Backends
110 ;; that return 'file have per-file revision numbering; backends
111 ;; that return 'repository have per-repository revision numbering,
112 ;; so a revision level implicitly identifies a changeset
114 ;; STATE-QUERYING FUNCTIONS
116 ;; * registered (file)
118 ;; Return non-nil if FILE is registered in this backend. Both this
119 ;; function as well as `state' should be careful to fail gracefully
120 ;; in the event that the backend executable is absent. It is
121 ;; preferable that this function's *body* is autoloaded, that way only
122 ;; calling vc-registered does not cause the backend to be loaded
123 ;; (all the vc-FOO-registered functions are called to try to find
124 ;; the controlling backend for FILE).
126 ;; * state (file)
128 ;; Return the current version control state of FILE. For a list of
129 ;; possible values, see `vc-state'. This function should do a full and
130 ;; reliable state computation; it is usually called immediately after
131 ;; C-x v v.
133 ;; - dir-status (dir update-function)
135 ;; Produce RESULT: a list of lists of the form (FILE VC-STATE EXTRA)
136 ;; for the files in DIR.
137 ;; EXTRA can be used for backend specific information about FILE.
138 ;; If a command needs to be run to compute this list, it should be
139 ;; run asynchronously using (current-buffer) as the buffer for the
140 ;; command. When RESULT is computed, it should be passed back by
141 ;; doing: (funcall UPDATE-FUNCTION RESULT nil).
142 ;; If the backend uses a process filter, hence it produces partial results,
143 ;; they can be passed back by doing:
144 ;; (funcall UPDATE-FUNCTION RESULT t)
145 ;; and then do a (funcall UPDATE-FUNCTION RESULT nil)
146 ;; when all the results have been computed.
147 ;; To provide more backend specific functionality for `vc-dir'
148 ;; the following functions might be needed: `dir-extra-headers',
149 ;; `dir-printer', `extra-dir-menu' and `dir-status-files'.
151 ;; - dir-status-files (dir files update-function)
153 ;; This function is identical to dir-status except that it should
154 ;; only report status for the specified FILES. Also it needs to
155 ;; report on all requested files, including up-to-date or ignored
156 ;; files. If not provided, the default is to consider that the files
157 ;; are in 'up-to-date state.
159 ;; - dir-extra-headers (dir)
161 ;; Return a string that will be added to the *vc-dir* buffer header.
163 ;; - dir-printer (fileinfo)
165 ;; Pretty print the `vc-dir-fileinfo' FILEINFO.
166 ;; If a backend needs to show more information than the default FILE
167 ;; and STATE in the vc-dir listing, it can store that extra
168 ;; information in `vc-dir-fileinfo->extra'. This function can be
169 ;; used to display that extra information in the *vc-dir* buffer.
171 ;; - status-fileinfo-extra (file)
173 ;; Compute `vc-dir-fileinfo->extra' for FILE.
175 ;; * working-revision (file)
177 ;; Return the working revision of FILE. This is the revision fetched
178 ;; by the last checkout or update, not necessarily the same thing as the
179 ;; head or tip revision. Should return "0" for a file added but not yet
180 ;; committed.
182 ;; - latest-on-branch-p (file)
184 ;; Return non-nil if the working revision of FILE is the latest revision
185 ;; on its branch (many VCSes call this the 'tip' or 'head' revision).
186 ;; The default implementation always returns t, which means that
187 ;; working with non-current revisions is not supported by default.
189 ;; * checkout-model (files)
191 ;; Indicate whether FILES need to be "checked out" before they can be
192 ;; edited. See `vc-checkout-model' for a list of possible values.
194 ;; - mode-line-string (file)
196 ;; If provided, this function should return the VC-specific mode
197 ;; line string for FILE. The returned string should have a
198 ;; `help-echo' property which is the text to be displayed as a
199 ;; tooltip when the mouse hovers over the VC entry on the mode-line.
200 ;; The default implementation deals well with all states that
201 ;; `vc-state' can return.
203 ;; STATE-CHANGING FUNCTIONS
205 ;; * create-repo (backend)
207 ;; Create an empty repository in the current directory and initialize
208 ;; it so VC mode can add files to it. For file-oriented systems, this
209 ;; need do no more than create a subdirectory with the right name.
211 ;; * register (files &optional comment)
213 ;; Register FILES in this backend. Optionally, an initial
214 ;; description of the file, COMMENT, may be specified, but it is not
215 ;; guaranteed that the backend will do anything with this. The
216 ;; implementation should pass the value of vc-register-switches to
217 ;; the backend command. (Note: in older versions of VC, this
218 ;; command had an optional revision first argument that was
219 ;; not used; in still older ones it took a single file argument and
220 ;; not a list.)
222 ;; - responsible-p (file)
224 ;; Return non-nil if this backend considers itself "responsible" for
225 ;; FILE, which can also be a directory. This function is used to find
226 ;; out what backend to use for registration of new files and for things
227 ;; like change log generation. The default implementation always
228 ;; returns nil.
230 ;; - receive-file (file rev)
232 ;; Let this backend "receive" a file that is already registered under
233 ;; another backend. The default implementation simply calls `register'
234 ;; for FILE, but it can be overridden to do something more specific,
235 ;; e.g. keep revision numbers consistent or choose editing modes for
236 ;; FILE that resemble those of the other backend.
238 ;; - unregister (file)
240 ;; Unregister FILE from this backend. This is only needed if this
241 ;; backend may be used as a "more local" backend for temporary editing.
243 ;; * checkin (files comment)
245 ;; Commit changes in FILES to this backend. COMMENT is used as a
246 ;; check-in comment. The implementation should pass the value of
247 ;; vc-checkin-switches to the backend command. The revision argument
248 ;; of some older VC versions is no longer supported.
250 ;; * find-revision (file rev buffer)
252 ;; Fetch revision REV of file FILE and put it into BUFFER.
253 ;; If REV is the empty string, fetch the head of the trunk.
254 ;; The implementation should pass the value of vc-checkout-switches
255 ;; to the backend command.
257 ;; * checkout (file &optional rev)
259 ;; Check out revision REV of FILE into the working area. FILE
260 ;; should be writable by the user and if locking is used for FILE, a
261 ;; lock should also be set. If REV is non-nil, that is the revision
262 ;; to check out (default is the working revision). If REV is t,
263 ;; that means to check out the head of the current branch; if it is
264 ;; the empty string, check out the head of the trunk. The
265 ;; implementation should pass the value of vc-checkout-switches to
266 ;; the backend command. The 'editable' argument of older VC versions
267 ;; is gone; all files are checked out editable.
269 ;; * revert (file &optional contents-done)
271 ;; Revert FILE back to the working revision. If optional
272 ;; arg CONTENTS-DONE is non-nil, then the contents of FILE have
273 ;; already been reverted from a version backup, and this function
274 ;; only needs to update the status of FILE within the backend.
275 ;; If FILE is in the `added' state it should be returned to the
276 ;; `unregistered' state.
278 ;; - rollback (files)
280 ;; Remove the tip revision of each of FILES from the repository. If
281 ;; this function is not provided, trying to cancel a revision is
282 ;; caught as an error. (Most backends don't provide it.) (Also
283 ;; note that older versions of this backend command were called
284 ;; 'cancel-version' and took a single file arg, not a list of
285 ;; files.)
287 ;; - merge-file (file rev1 rev2)
289 ;; Merge the changes between REV1 and REV2 into the current working
290 ;; file (for non-distributed VCS). It is expected that with an
291 ;; empty first revision this will behave like the merge-news method.
293 ;; - merge-branch ()
295 ;; Merge another branch into the current one, prompting for a
296 ;; location to merge from.
298 ;; - merge-news (file)
300 ;; Merge recent changes from the current branch into FILE.
301 ;; (for non-distributed VCS).
303 ;; - pull (prompt)
305 ;; Pull "upstream" changes into the current branch (for distributed
306 ;; VCS). If PROMPT is non-nil, or if necessary, prompt for a
307 ;; location to pull from.
309 ;; - steal-lock (file &optional revision)
311 ;; Steal any lock on the working revision of FILE, or on REVISION if
312 ;; that is provided. This function is only needed if locking is
313 ;; used for files under this backend, and if files can indeed be
314 ;; locked by other users.
316 ;; - modify-change-comment (files rev comment)
318 ;; Modify the change comments associated with the files at the
319 ;; given revision. This is optional, many backends do not support it.
321 ;; - mark-resolved (files)
323 ;; Mark conflicts as resolved. Some VC systems need to run a
324 ;; command to mark conflicts as resolved.
326 ;; - find-admin-dir (file)
328 ;; Return the administrative directory of FILE.
330 ;; HISTORY FUNCTIONS
332 ;; * print-log (files buffer &optional shortlog start-revision limit)
334 ;; Insert the revision log for FILES into BUFFER.
335 ;; If SHORTLOG is true insert a short version of the log.
336 ;; If LIMIT is true insert only insert LIMIT log entries. If the
337 ;; backend does not support limiting the number of entries to show
338 ;; it should return `limit-unsupported'.
339 ;; If START-REVISION is given, then show the log starting from that
340 ;; revision ("starting" in the sense of it being the _newest_
341 ;; revision shown, rather than the working revision, which is normally
342 ;; the case). Not all backends support this. At present, this is
343 ;; only ever used with LIMIT = 1 (by vc-annotate-show-log-revision-at-line).
345 ;; * log-outgoing (backend remote-location)
347 ;; Insert in BUFFER the revision log for the changes that will be
348 ;; sent when performing a push operation to REMOTE-LOCATION.
350 ;; * log-incoming (backend remote-location)
352 ;; Insert in BUFFER the revision log for the changes that will be
353 ;; received when performing a pull operation from REMOTE-LOCATION.
355 ;; - log-view-mode ()
357 ;; Mode to use for the output of print-log. This defaults to
358 ;; `log-view-mode' and is expected to be changed (if at all) to a derived
359 ;; mode of `log-view-mode'.
361 ;; - show-log-entry (revision)
363 ;; If provided, search the log entry for REVISION in the current buffer,
364 ;; and make sure it is displayed in the buffer's window. The default
365 ;; implementation of this function works for RCS-style logs.
367 ;; - comment-history (file)
369 ;; Return a string containing all log entries that were made for FILE.
370 ;; This is used for transferring a file from one backend to another,
371 ;; retaining comment information.
373 ;; - update-changelog (files)
375 ;; Using recent log entries, create ChangeLog entries for FILES, or for
376 ;; all files at or below the default-directory if FILES is nil. The
377 ;; default implementation runs rcs2log, which handles RCS- and
378 ;; CVS-style logs.
380 ;; * diff (files &optional async rev1 rev2 buffer)
382 ;; Insert the diff for FILE into BUFFER, or the *vc-diff* buffer if
383 ;; BUFFER is nil. If ASYNC is non-nil, run asynchronously.If REV1
384 ;; and REV2 are non-nil, report differences from REV1 to REV2. If
385 ;; REV1 is nil, use the working revision (as found in the
386 ;; repository) as the older revision; if REV2 is nil, use the
387 ;; current working-copy contents as the newer revision. This
388 ;; function should pass the value of (vc-switches BACKEND 'diff) to
389 ;; the backend command. It should return a status of either 0 (no
390 ;; differences found), or 1 (either non-empty diff or the diff is
391 ;; run asynchronously).
394 ;; - revision-completion-table (files)
396 ;; Return a completion table for existing revisions of FILES.
397 ;; The default is to not use any completion table.
399 ;; - annotate-command (file buf &optional rev)
401 ;; If this function is provided, it should produce an annotated display
402 ;; of FILE in BUF, relative to revision REV. Annotation means each line
403 ;; of FILE displayed is prefixed with version information associated with
404 ;; its addition (deleted lines leave no history) and that the text of the
405 ;; file is fontified according to age.
407 ;; - annotate-time ()
409 ;; Only required if `annotate-command' is defined for the backend.
410 ;; Return the time of the next line of annotation at or after point,
411 ;; as a floating point fractional number of days. The helper
412 ;; function `vc-annotate-convert-time' may be useful for converting
413 ;; multi-part times as returned by `current-time' and `encode-time'
414 ;; to this format. Return nil if no more lines of annotation appear
415 ;; in the buffer. You can safely assume that point is placed at the
416 ;; beginning of each line, starting at `point-min'. The buffer that
417 ;; point is placed in is the Annotate output, as defined by the
418 ;; relevant backend. This function also affects how much of the line
419 ;; is fontified; where it leaves point is where fontification begins.
421 ;; - annotate-current-time ()
423 ;; Only required if `annotate-command' is defined for the backend,
424 ;; AND you'd like the current time considered to be anything besides
425 ;; (vc-annotate-convert-time (current-time)) -- i.e. the current
426 ;; time with hours, minutes, and seconds included. Probably safe to
427 ;; ignore. Return the current-time, in units of fractional days.
429 ;; - annotate-extract-revision-at-line ()
431 ;; Only required if `annotate-command' is defined for the backend.
432 ;; Invoked from a buffer in vc-annotate-mode, return the revision
433 ;; corresponding to the current line, or nil if there is no revision
434 ;; corresponding to the current line.
435 ;; If the backend supports annotating through copies and renames,
436 ;; and displays a file name and a revision, then return a cons
437 ;; (REVISION . FILENAME).
439 ;; - region-history (FILE BUFFER LFROM LTO)
441 ;; Insert into BUFFER the history (log comments and diffs) of the content of
442 ;; FILE between lines LFROM and LTO. This is typically done asynchronously.
444 ;; - region-history-mode ()
446 ;; Major mode to use for the output of `region-history'.
448 ;; TAG SYSTEM
450 ;; - create-tag (dir name branchp)
452 ;; Attach the tag NAME to the state of the working copy. This
453 ;; should make sure that files are up-to-date before proceeding with
454 ;; the action. DIR can also be a file and if BRANCHP is specified,
455 ;; NAME should be created as a branch and DIR should be checked out
456 ;; under this new branch. The default implementation does not
457 ;; support branches but does a sanity check, a tree traversal and
458 ;; assigns the tag to each file.
460 ;; - retrieve-tag (dir name update)
462 ;; Retrieve the version tagged by NAME of all registered files at or below DIR.
463 ;; If UPDATE is non-nil, then update buffers of any files in the
464 ;; tag that are currently visited. The default implementation
465 ;; does a sanity check whether there aren't any uncommitted changes at
466 ;; or below DIR, and then performs a tree walk, using the `checkout'
467 ;; function to retrieve the corresponding revisions.
469 ;; MISCELLANEOUS
471 ;; - make-version-backups-p (file)
473 ;; Return non-nil if unmodified repository revisions of FILE should be
474 ;; backed up locally. If this is done, VC can perform `diff' and
475 ;; `revert' operations itself, without calling the backend system. The
476 ;; default implementation always returns nil.
478 ;; - root (file)
480 ;; Return the root of the VC controlled hierarchy for file.
482 ;; - ignore (file &optional directory)
484 ;; Ignore FILE under the VCS of DIRECTORY (default is `default-directory').
485 ;; FILE is a file wildcard.
486 ;; When called interactively and with a prefix argument, remove FILE
487 ;; from ignored files.
488 ;; When called from Lisp code, if DIRECTORY is non-nil, the
489 ;; repository to use will be deduced by DIRECTORY.
491 ;; - ignore-completion-table
493 ;; Return the completion table for files ignored by the current
494 ;; version control system, e.g., the entries in `.gitignore' and
495 ;; `.bzrignore'.
497 ;; - previous-revision (file rev)
499 ;; Return the revision number that precedes REV for FILE, or nil if no such
500 ;; revision exists.
502 ;; - next-revision (file rev)
504 ;; Return the revision number that follows REV for FILE, or nil if no such
505 ;; revision exists.
507 ;; - log-edit-mode ()
509 ;; Turn on the mode used for editing the check in log. This
510 ;; defaults to `log-edit-mode'. If changed, it should use a mode
511 ;; derived from`log-edit-mode'.
513 ;; - check-headers ()
515 ;; Return non-nil if the current buffer contains any version headers.
517 ;; - delete-file (file)
519 ;; Delete FILE and mark it as deleted in the repository. If this
520 ;; function is not provided, the command `vc-delete-file' will
521 ;; signal an error.
523 ;; - rename-file (old new)
525 ;; Rename file OLD to NEW, both in the working area and in the
526 ;; repository. If this function is not provided, the renaming
527 ;; will be done by (vc-delete-file old) and (vc-register new).
529 ;; - find-file-hook ()
531 ;; Operation called in current buffer when opening a file. This can
532 ;; be used by the backend to setup some local variables it might need.
534 ;; - extra-menu ()
536 ;; Return a menu keymap, the items in the keymap will appear at the
537 ;; end of the Version Control menu. The goal is to allow backends
538 ;; to specify extra menu items that appear in the VC menu. This way
539 ;; you can provide menu entries for functionality that is specific
540 ;; to your backend and which does not map to any of the VC generic
541 ;; concepts.
543 ;; - extra-dir-menu ()
545 ;; Return a menu keymap, the items in the keymap will appear at the
546 ;; end of the VC Status menu. The goal is to allow backends to
547 ;; specify extra menu items that appear in the VC Status menu. This
548 ;; makes it possible to provide menu entries for functionality that
549 ;; is specific to a backend and which does not map to any of the VC
550 ;; generic concepts.
552 ;; - conflicted-files (dir)
554 ;; Return the list of files where conflict resolution is needed in
555 ;; the project that contains DIR.
556 ;; FIXME: what should it do with non-text conflicts?
558 ;;; Changes from the pre-25.1 API:
560 ;; - INCOMPATIBLE CHANGE: The 'editable' optional argument of
561 ;; vc-checkout is gone. The upper level assumes that all files are
562 ;; checked out editable. This moves closer to emulating modern
563 ;; non-locking behavior even on very old VCSes.
565 ;; - INCOMPATIBLE CHANGE: The vc-register function and its backend
566 ;; implementations no longer take a first optional revision
567 ;; argument, since on no system since RCS has setting the initial
568 ;; revision been even possible, let alone sane.
570 ;; INCOMPATIBLE CHANGE: In older versions of the API, vc-diff did
571 ;; not take an async-mode flag as a first optional argument. (This
572 ;; change eliminated a particularly ugly global.)
574 ;; - INCOMPATIBLE CHANGE: The backend operation for non-distributed
575 ;; VCSes formerly called "merge" is now "merge-file" (to contrast
576 ;; with merge-branch), and does its own prompting for revisions.
577 ;; (This fixes a layer violation that produced bad behavior under
578 ;; SVN.)
580 ;; - INCOMPATIBLE CHANGE: The old fourth 'default-state' argument of
581 ;; vc-dir-status-files is gone; none of the back ends actually used it.
583 ;; - vc-state-heuristic is no longer a public method (the CVS backend
584 ;; retains it as a private one).
586 ;; - the vc-mistrust-permissions configuration variable is gone; the
587 ;; code no longer relies on permissions except in one corner case where
588 ;; CVS leaves no alternative (which was not gated by this variable). The
589 ;; only affected back ends were SCCS and RCS.
591 ;; - vc-stay-local-p and repository-hostname are no longer part
592 ;; of the public API. The vc-stay-local configuration variable
593 ;; remains but only affects the CVS back end.
595 ;; - The init-revision function and the default-initial-revision
596 ;; variable are gone. These have't made sense on anything shipped
597 ;; since RCS, and using them was a dumb stunt even on RCS.
599 ;; workfile-unchanged-p is no longer a public back-end method. It
600 ;; was redundant with vc-state and usually implemented with a trivial
601 ;; call to it. A few older back ends retain versions for internal use in
602 ;; their vc-state functions.
604 ;; could-register is no longer a public method. Only vc-cvs ever used it
606 ;;; Todo:
608 ;;;; New Primitives:
610 ;; - deal with push operations.
612 ;;;; Primitives that need changing:
614 ;; - vc-update/vc-merge should deal with VC systems that don't do
615 ;; update/merge on a file basis, but on a whole repository basis.
616 ;; vc-update and vc-merge assume the arguments are always files,
617 ;; they don't deal with directories. Make sure the *vc-dir* buffer
618 ;; is updated after these operations.
619 ;; At least bzr, git and hg should benefit from this.
621 ;;;; Improved branch and tag handling:
623 ;; - Make sure the *vc-dir* buffer is updated after merge-branch operations.
625 ;; - add a generic mechanism for remembering the current branch names,
626 ;; display the branch name in the mode-line. Replace
627 ;; vc-cvs-sticky-tag with that.
629 ;; - Add a primitives for switching to a branch (creating it if required.
631 ;; - Add the ability to list tags and branches.
633 ;;;; Internal cleanups:
635 ;; - Another important thing: merge all the status-like backend operations.
636 ;; We should remove dir-status, state, and dir-status-files, and
637 ;; replace them with just `status' which takes a fileset and a continuation
638 ;; (like dir-status) and returns a buffer in which the process(es) are run
639 ;; (or nil if it worked synchronously). Hopefully we can define the old
640 ;; 4 operations in term of this one.
642 ;;;; Unify two different versions of the amend capability
644 ;; - Some back ends (SCCS/RCS/SVN/SRC), have an amend capability that can
645 ;; be invoked from log-view.
647 ;; - The git backend supports amending, but in a different
648 ;; way (press `C-c C-e' in log-edit buffer, when making a new commit).
650 ;; - Second, `log-view-modify-change-comment' doesn't seem to support
651 ;; modern backends at all because `log-view-extract-comment'
652 ;; unconditionally calls `log-view-current-file'. This should be easy to
653 ;; fix.
655 ;; - Third, doing message editing in log-view might be a natural way to go
656 ;; about it, but editing any but the last commit (and even it, if it's
657 ;; been pushed) is a dangerous operation in Git, which we shouldn't make
658 ;; too easy for users to perform.
660 ;; There should be a check that the given comment is not reachable
661 ;; from any of the "remote" refs?
663 ;;;; Other
665 ;; - asynchronous checkin and commit, so you can keep working in other
666 ;; buffers while the repo operation happens.
668 ;; - Direct support for stash/shelve.
670 ;; - when a file is in `conflict' state, turn on smerge-mode.
672 ;; - figure out what to do with conflicts that are not caused by the
673 ;; file contents, but by metadata or other causes. Example: File A
674 ;; gets renamed to B in one branch and to C in another and you merge
675 ;; the two branches. Or you locally add file FOO and then pull a
676 ;; change that also adds a new file FOO, ...
678 ;; - make it easier to write logs. Maybe C-x 4 a should add to the log
679 ;; buffer, if one is present, instead of adding to the ChangeLog.
681 ;; - When vc-next-action calls vc-checkin it could pre-fill the
682 ;; *vc-log* buffer with some obvious items: the list of files that
683 ;; were added, the list of files that were removed. If the diff is
684 ;; available, maybe it could even call something like
685 ;; `diff-add-change-log-entries-other-window' to create a detailed
686 ;; skeleton for the log...
688 ;; - most vc-dir backends need more work. They might need to
689 ;; provide custom headers, use the `extra' field and deal with all
690 ;; possible VC states.
692 ;; - add a function that calls vc-dir to `find-directory-functions'.
694 ;; - vc-diff, vc-annotate, etc. need to deal better with unregistered
695 ;; files. Now that unregistered and ignored files are shown in
696 ;; vc-dir, it is possible that these commands are called
697 ;; for unregistered/ignored files.
699 ;; - vc-next-action needs work in order to work with multiple
700 ;; backends: `vc-state' returns the state for the default backend,
701 ;; not for the backend in the current *vc-dir* buffer.
703 ;; - vc-dir-kill-dir-status-process should not be specific to dir-status,
704 ;; it should work for other async commands done through vc-do-command
705 ;; as well,
707 ;; - vc-dir toolbar needs more icons.
709 ;; - The backends should avoid using `vc-file-setprop' and `vc-file-getprop'.
711 ;;; Code:
713 (require 'vc-hooks)
714 (require 'vc-dispatcher)
715 (require 'cl-lib)
717 (declare-function diff-setup-whitespace "diff-mode" ())
719 (eval-when-compile
720 (require 'dired))
722 (declare-function dired-get-filename "dired" (&optional localp noerror))
723 (declare-function dired-move-to-filename "dired" (&optional err eol))
724 (declare-function dired-marker-regexp "dired" ())
726 (unless (assoc 'vc-parent-buffer minor-mode-alist)
727 (setq minor-mode-alist
728 (cons '(vc-parent-buffer vc-parent-buffer-name)
729 minor-mode-alist)))
731 ;; General customization
733 (defgroup vc nil
734 "Emacs interface to version control systems."
735 :group 'tools)
737 (defcustom vc-initial-comment nil
738 "If non-nil, prompt for initial comment when a file is registered."
739 :type 'boolean
740 :group 'vc)
742 (make-obsolete-variable 'vc-initial-comment "it has no effect." "23.2")
744 (defcustom vc-checkin-switches nil
745 "A string or list of strings specifying extra switches for checkin.
746 These are passed to the checkin program by \\[vc-checkin]."
747 :type '(choice (const :tag "None" nil)
748 (string :tag "Argument String")
749 (repeat :tag "Argument List"
750 :value ("")
751 string))
752 :group 'vc)
754 (defcustom vc-checkout-switches nil
755 "A string or list of strings specifying extra switches for checkout.
756 These are passed to the checkout program by \\[vc-checkout]."
757 :type '(choice (const :tag "None" nil)
758 (string :tag "Argument String")
759 (repeat :tag "Argument List"
760 :value ("")
761 string))
762 :group 'vc)
764 (defcustom vc-register-switches nil
765 "A string or list of strings; extra switches for registering a file.
766 These are passed to the checkin program by \\[vc-register]."
767 :type '(choice (const :tag "None" nil)
768 (string :tag "Argument String")
769 (repeat :tag "Argument List"
770 :value ("")
771 string))
772 :group 'vc)
774 (defcustom vc-diff-switches nil
775 "A string or list of strings specifying switches for diff under VC.
776 When running diff under a given BACKEND, VC uses the first
777 non-nil value of `vc-BACKEND-diff-switches', `vc-diff-switches',
778 and `diff-switches', in that order. Since nil means to check the
779 next variable in the sequence, either of the first two may use
780 the value t to mean no switches at all. `vc-diff-switches'
781 should contain switches that are specific to version control, but
782 not specific to any particular backend."
783 :type '(choice (const :tag "Unspecified" nil)
784 (const :tag "None" t)
785 (string :tag "Argument String")
786 (repeat :tag "Argument List" :value ("") string))
787 :group 'vc
788 :version "21.1")
790 (defcustom vc-log-show-limit 2000
791 "Limit the number of items shown by the VC log commands.
792 Zero means unlimited.
793 Not all VC backends are able to support this feature."
794 :type 'integer
795 :group 'vc)
797 (defcustom vc-allow-async-revert nil
798 "Specifies whether the diff during \\[vc-revert] may be asynchronous.
799 Enabling this option means that you can confirm a revert operation even
800 if the local changes in the file have not been found and displayed yet."
801 :type '(choice (const :tag "No" nil)
802 (const :tag "Yes" t))
803 :group 'vc
804 :version "22.1")
806 ;;;###autoload
807 (defcustom vc-checkout-hook nil
808 "Normal hook (list of functions) run after checking out a file.
809 See `run-hooks'."
810 :type 'hook
811 :group 'vc
812 :version "21.1")
814 ;;;###autoload
815 (defcustom vc-checkin-hook nil
816 "Normal hook (list of functions) run after commit or file checkin.
817 See also `log-edit-done-hook'."
818 :type 'hook
819 :options '(log-edit-comment-to-change-log)
820 :group 'vc)
822 ;;;###autoload
823 (defcustom vc-before-checkin-hook nil
824 "Normal hook (list of functions) run before a commit or a file checkin.
825 See `run-hooks'."
826 :type 'hook
827 :group 'vc)
829 (defcustom vc-revert-show-diff t
830 "If non-nil, `vc-revert' shows a `vc-diff' buffer before querying."
831 :type 'boolean
832 :group 'vc
833 :version "24.1")
835 ;; Header-insertion hair
837 (defcustom vc-static-header-alist
838 '(("\\.c\\'" .
839 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
840 "Associate static header string templates with file types.
841 A \%s in the template is replaced with the first string associated with
842 the file's version control type in `vc-BACKEND-header'."
843 :type '(repeat (cons :format "%v"
844 (regexp :tag "File Type")
845 (string :tag "Header String")))
846 :group 'vc)
848 (defcustom vc-comment-alist
849 '((nroff-mode ".\\\"" ""))
850 "Special comment delimiters for generating VC headers.
851 Add an entry in this list if you need to override the normal `comment-start'
852 and `comment-end' variables. This will only be necessary if the mode language
853 is sensitive to blank lines."
854 :type '(repeat (list :format "%v"
855 (symbol :tag "Mode")
856 (string :tag "Comment Start")
857 (string :tag "Comment End")))
858 :group 'vc)
861 ;; File property caching
863 (defun vc-clear-context ()
864 "Clear all cached file properties."
865 (interactive)
866 (fillarray vc-file-prop-obarray 0))
868 (defmacro with-vc-properties (files form settings)
869 "Execute FORM, then maybe set per-file properties for FILES.
870 If any of FILES is actually a directory, then do the same for all
871 buffers for files in that directory.
872 SETTINGS is an association list of property/value pairs. After
873 executing FORM, set those properties from SETTINGS that have not yet
874 been updated to their corresponding values."
875 (declare (debug t))
876 `(let ((vc-touched-properties (list t))
877 (flist nil))
878 (dolist (file ,files)
879 (if (file-directory-p file)
880 (dolist (buffer (buffer-list))
881 (let ((fname (buffer-file-name buffer)))
882 (when (and fname (string-prefix-p file fname))
883 (push fname flist))))
884 (push file flist)))
885 ,form
886 (dolist (file flist)
887 (dolist (setting ,settings)
888 (let ((property (car setting)))
889 (unless (memq property vc-touched-properties)
890 (put (intern file vc-file-prop-obarray)
891 property (cdr setting))))))))
893 ;;; Code for deducing what fileset and backend to assume
895 (defun vc-backend-for-registration (file)
896 "Return a backend that can be used for registering FILE.
898 If no backend declares itself responsible for FILE, then FILE
899 must not be in a version controlled directory, so try to create a
900 repository, prompting for the directory and the VC backend to
901 use."
902 (catch 'found
903 ;; First try: find a responsible backend, it must be a backend
904 ;; under which FILE is not yet registered.
905 (dolist (backend vc-handled-backends)
906 (and (not (vc-call-backend backend 'registered file))
907 (vc-call-backend backend 'responsible-p file)
908 (throw 'found backend)))
909 ;; no responsible backend
910 (let* ((possible-backends
911 (let (pos)
912 (dolist (crt vc-handled-backends)
913 (when (vc-find-backend-function crt 'create-repo)
914 (push crt pos)))
915 pos))
917 (intern
918 ;; Read the VC backend from the user, only
919 ;; complete with the backends that have the
920 ;; 'create-repo method.
921 (completing-read
922 (format "%s is not in a version controlled directory.\nUse VC backend: " file)
923 (mapcar 'symbol-name possible-backends) nil t)))
924 (repo-dir
925 (let ((def-dir (file-name-directory file)))
926 ;; read the directory where to create the
927 ;; repository, make sure it's a parent of
928 ;; file.
929 (read-file-name
930 (format "create %s repository in: " bk)
931 default-directory def-dir t nil
932 (lambda (arg)
933 (message "arg %s" arg)
934 (and (file-directory-p arg)
935 (string-prefix-p (expand-file-name arg) def-dir)))))))
936 (let ((default-directory repo-dir))
937 (vc-call-backend bk 'create-repo))
938 (throw 'found bk))))
940 (defun vc-responsible-backend (file)
941 "Return the name of a backend system that is responsible for FILE.
943 If FILE is already registered, return the
944 backend of FILE. If FILE is not registered, then the
945 first backend in `vc-handled-backends' that declares itself
946 responsible for FILE is returned."
947 (or (and (not (file-directory-p file)) (vc-backend file))
948 (catch 'found
949 ;; First try: find a responsible backend. If this is for registration,
950 ;; it must be a backend under which FILE is not yet registered.
951 (dolist (backend vc-handled-backends)
952 (and (vc-call-backend backend 'responsible-p file)
953 (throw 'found backend))))
954 (error "No VC backend is responsible for %s" file)))
956 (defun vc-expand-dirs (file-or-dir-list backend)
957 "Expands directories in a file list specification.
958 Within directories, only files already under version control are noticed."
959 (let ((flattened '()))
960 (dolist (node file-or-dir-list)
961 (when (file-directory-p node)
962 (vc-file-tree-walk
963 node (lambda (f) (when (eq (vc-backend f) backend) (push f flattened)))))
964 (unless (file-directory-p node) (push node flattened)))
965 (nreverse flattened)))
967 (defvar vc-dir-backend)
968 (defvar log-view-vc-backend)
969 (defvar log-edit-vc-backend)
970 (defvar diff-vc-backend)
972 (defun vc-deduce-backend ()
973 (cond ((derived-mode-p 'vc-dir-mode) vc-dir-backend)
974 ((derived-mode-p 'log-view-mode) log-view-vc-backend)
975 ((derived-mode-p 'log-edit-mode) log-edit-vc-backend)
976 ((derived-mode-p 'diff-mode) diff-vc-backend)
977 ;; Maybe we could even use comint-mode rather than shell-mode?
978 ((derived-mode-p 'dired-mode 'shell-mode 'compilation-mode)
979 (vc-responsible-backend default-directory))
980 (vc-mode (vc-backend buffer-file-name))))
982 (declare-function vc-dir-current-file "vc-dir" ())
983 (declare-function vc-dir-deduce-fileset "vc-dir" (&optional state-model-only-files))
985 (defun vc-deduce-fileset (&optional observer allow-unregistered
986 state-model-only-files)
987 "Deduce a set of files and a backend to which to apply an operation.
988 Return (BACKEND FILESET FILESET-ONLY-FILES STATE CHECKOUT-MODEL).
990 If we're in VC-dir mode, FILESET is the list of marked files,
991 or the directory if no files are marked.
992 Otherwise, if in a buffer visiting a version-controlled file,
993 FILESET is a single-file fileset containing that file.
994 Otherwise, if ALLOW-UNREGISTERED is non-nil and the visited file
995 is unregistered, FILESET is a single-file fileset containing it.
996 Otherwise, throw an error.
998 STATE-MODEL-ONLY-FILES if non-nil, means that the caller needs
999 the FILESET-ONLY-FILES STATE and MODEL info. Otherwise, that
1000 part may be skipped.
1002 BEWARE: this function may change the current buffer."
1003 ;; FIXME: OBSERVER is unused. The name is not intuitive and is not
1004 ;; documented. It's set to t when called from diff and print-log.
1005 (let (backend)
1006 (cond
1007 ((derived-mode-p 'vc-dir-mode)
1008 (vc-dir-deduce-fileset state-model-only-files))
1009 ((derived-mode-p 'dired-mode)
1010 (if observer
1011 (vc-dired-deduce-fileset)
1012 (error "State changing VC operations not supported in `dired-mode'")))
1013 ((and (derived-mode-p 'log-view-mode)
1014 (setq backend (vc-responsible-backend default-directory)))
1015 (list backend default-directory))
1016 ((setq backend (vc-backend buffer-file-name))
1017 (if state-model-only-files
1018 (list backend (list buffer-file-name)
1019 (list buffer-file-name)
1020 (vc-state buffer-file-name)
1021 (vc-checkout-model backend buffer-file-name))
1022 (list backend (list buffer-file-name))))
1023 ((and (buffer-live-p vc-parent-buffer)
1024 ;; FIXME: Why this test? --Stef
1025 (or (buffer-file-name vc-parent-buffer)
1026 (with-current-buffer vc-parent-buffer
1027 (derived-mode-p 'vc-dir-mode))))
1028 (progn ;FIXME: Why not `with-current-buffer'? --Stef.
1029 (set-buffer vc-parent-buffer)
1030 (vc-deduce-fileset observer allow-unregistered state-model-only-files)))
1031 ((not buffer-file-name)
1032 (error "Buffer %s is not associated with a file" (buffer-name)))
1033 ((and allow-unregistered (not (vc-registered buffer-file-name)))
1034 (if state-model-only-files
1035 (list (vc-backend-for-registration (buffer-file-name))
1036 (list buffer-file-name)
1037 (list buffer-file-name)
1038 (when state-model-only-files 'unregistered)
1039 nil)
1040 (list (vc-backend-for-registration (buffer-file-name))
1041 (list buffer-file-name))))
1042 (t (error "File is not under version control")))))
1044 (defun vc-dired-deduce-fileset ()
1045 (let ((backend (vc-responsible-backend default-directory)))
1046 (unless backend (error "Directory not under VC"))
1047 (list backend
1048 (dired-map-over-marks (dired-get-filename nil t) nil))))
1050 (defun vc-ensure-vc-buffer ()
1051 "Make sure that the current buffer visits a version-controlled file."
1052 (cond
1053 ((derived-mode-p 'vc-dir-mode)
1054 (set-buffer (find-file-noselect (vc-dir-current-file))))
1056 (while (and vc-parent-buffer
1057 (buffer-live-p vc-parent-buffer)
1058 ;; Avoid infinite looping when vc-parent-buffer and
1059 ;; current buffer are the same buffer.
1060 (not (eq vc-parent-buffer (current-buffer))))
1061 (set-buffer vc-parent-buffer))
1062 (if (not buffer-file-name)
1063 (error "Buffer %s is not associated with a file" (buffer-name))
1064 (unless (vc-backend buffer-file-name)
1065 (error "File %s is not under version control" buffer-file-name))))))
1067 ;;; Support for the C-x v v command.
1068 ;; This is where all the single-file-oriented code from before the fileset
1069 ;; rewrite lives.
1071 (defsubst vc-editable-p (file)
1072 "Return non-nil if FILE can be edited."
1073 (let ((backend (vc-backend file)))
1074 (and backend
1075 (or (eq (vc-checkout-model backend (list file)) 'implicit)
1076 (memq (vc-state file) '(edited needs-merge conflict))))))
1078 (defun vc-compatible-state (p q)
1079 "Controls which states can be in the same commit."
1081 (eq p q)
1082 (and (member p '(edited added removed)) (member q '(edited added removed)))))
1084 (defun vc-read-backend (prompt)
1085 (intern
1086 (completing-read prompt (mapcar 'symbol-name vc-handled-backends)
1087 nil 'require-match)))
1089 ;; Here's the major entry point.
1091 ;;;###autoload
1092 (defun vc-next-action (verbose)
1093 "Do the next logical version control operation on the current fileset.
1094 This requires that all files in the current VC fileset be in the
1095 same state. If not, signal an error.
1097 For merging-based version control systems:
1098 If every file in the VC fileset is not registered for version
1099 control, register the fileset (but don't commit).
1100 If every work file in the VC fileset is added or changed, pop
1101 up a *vc-log* buffer to commit the fileset.
1102 For a centralized version control system, if any work file in
1103 the VC fileset is out of date, offer to update the fileset.
1105 For old-style locking-based version control systems, like RCS:
1106 If every file is not registered, register the file(s).
1107 If every file is registered and unlocked, check out (lock)
1108 the file(s) for editing.
1109 If every file is locked by you and has changes, pop up a
1110 *vc-log* buffer to check in the changes. If the variable
1111 `vc-keep-workfiles' is non-nil (the default), leave a
1112 read-only copy of each changed file after checking in.
1113 If every file is locked by you and unchanged, unlock them.
1114 If every file is locked by someone else, offer to steal the lock."
1115 (interactive "P")
1116 (let* ((vc-fileset (vc-deduce-fileset nil t 'state-model-only-files))
1117 (backend (car vc-fileset))
1118 (files (nth 1 vc-fileset))
1119 ;; (fileset-only-files (nth 2 vc-fileset))
1120 ;; FIXME: We used to call `vc-recompute-state' here.
1121 (state (nth 3 vc-fileset))
1122 ;; The backend should check that the checkout-model is consistent
1123 ;; among all the `files'.
1124 (model (nth 4 vc-fileset)))
1126 ;; If a buffer has unsaved changes, a checkout would discard those
1127 ;; changes, so treat the buffer as having unlocked changes.
1128 (when (and (not (eq model 'implicit)) (eq state 'up-to-date))
1129 (dolist (file files)
1130 (let ((buffer (get-file-buffer file)))
1131 (and buffer
1132 (buffer-modified-p buffer)
1133 (setq state 'unlocked-changes)))))
1135 ;; Do the right thing.
1136 (cond
1137 ((eq state 'missing)
1138 (error "Fileset files are missing, so cannot be operated on"))
1139 ((eq state 'ignored)
1140 (error "Fileset files are ignored by the version-control system"))
1141 ((or (null state) (eq state 'unregistered))
1142 (vc-register vc-fileset))
1143 ;; Files are up-to-date, or need a merge and user specified a revision
1144 ((or (eq state 'up-to-date) (and verbose (eq state 'needs-update)))
1145 (cond
1146 (verbose
1147 ;; Go to a different revision.
1148 (let* ((revision
1149 ;; FIXME: Provide completion.
1150 (read-string "Branch, revision, or backend to move to: "))
1151 (revision-downcase (downcase revision)))
1152 (if (member
1153 revision-downcase
1154 (mapcar (lambda (arg) (downcase (symbol-name arg)))
1155 vc-handled-backends))
1156 (let ((vsym (intern-soft revision-downcase)))
1157 (dolist (file files) (vc-transfer-file file vsym)))
1158 (dolist (file files)
1159 (vc-checkout file revision)))))
1160 ((not (eq model 'implicit))
1161 ;; check the files out
1162 (dolist (file files) (vc-checkout file)))
1164 ;; do nothing
1165 (message "Fileset is up-to-date"))))
1166 ;; Files have local changes
1167 ((vc-compatible-state state 'edited)
1168 (let ((ready-for-commit files))
1169 ;; CVS, SVN and bzr don't care about read-only (bug#9781).
1170 ;; RCS does, SCCS might (someone should check...).
1171 (when (memq backend '(RCS SCCS))
1172 ;; If files are edited but read-only, give user a chance to correct.
1173 (dolist (file files)
1174 ;; If committing a mix of removed and edited files, the
1175 ;; fileset has state = 'edited. Rather than checking the
1176 ;; state of each individual file in the fileset, it seems
1177 ;; simplest to just check if the file exists. Bug#9781.
1178 (when (and (file-exists-p file) (not (file-writable-p file)))
1179 ;; Make the file-buffer read-write.
1180 (unless (y-or-n-p (format "%s is edited but read-only; make it writable and continue? " file))
1181 (error "Aborted"))
1182 ;; Maybe we somehow lost permissions on the directory.
1183 (condition-case nil
1184 (set-file-modes file (logior (file-modes file) 128))
1185 (error (error "Unable to make file writable")))
1186 (let ((visited (get-file-buffer file)))
1187 (when visited
1188 (with-current-buffer visited
1189 (read-only-mode -1)))))))
1190 ;; Allow user to revert files with no changes
1191 (save-excursion
1192 (dolist (file files)
1193 (let ((visited (get-file-buffer file)))
1194 ;; For files with locking, if the file does not contain
1195 ;; any changes, just let go of the lock, i.e. revert.
1196 (when (and (not (eq model 'implicit))
1197 (eq state 'up-to-date)
1198 ;; If buffer is modified, that means the user just
1199 ;; said no to saving it; in that case, don't revert,
1200 ;; because the user might intend to save after
1201 ;; finishing the log entry and committing.
1202 (not (and visited (buffer-modified-p))))
1203 (vc-revert-file file)
1204 (setq ready-for-commit (delete file ready-for-commit))))))
1205 ;; Remaining files need to be committed
1206 (if (not ready-for-commit)
1207 (message "No files remain to be committed")
1208 (if (not verbose)
1209 (vc-checkin ready-for-commit backend)
1210 (let ((new-backend (vc-read-backend "New backend: ")))
1211 (if new-backend
1212 (dolist (file files)
1213 (vc-transfer-file file new-backend))))))))
1214 ;; locked by somebody else (locking VCSes only)
1215 ((stringp state)
1216 ;; In the old days, we computed the revision once and used it on
1217 ;; the single file. Then, for the 2007-2008 fileset rewrite, we
1218 ;; computed the revision once (incorrectly, using a free var) and
1219 ;; used it on all files. To fix the free var bug, we can either
1220 ;; use `(car files)' or do what we do here: distribute the
1221 ;; revision computation among `files'. Although this may be
1222 ;; tedious for those backends where a "revision" is a trans-file
1223 ;; concept, it is nonetheless correct for both those and (more
1224 ;; importantly) for those where "revision" is a per-file concept.
1225 ;; If the intersection of the former group and "locking VCSes" is
1226 ;; non-empty [I vaguely doubt it --ttn], we can reinstate the
1227 ;; pre-computation approach of yore.
1228 (dolist (file files)
1229 (vc-steal-lock
1230 file (if verbose
1231 (read-string (format "%s revision to steal: " file))
1232 (vc-working-revision file))
1233 state)))
1234 ;; conflict
1235 ((eq state 'conflict)
1236 ;; FIXME: Is it really the UI we want to provide?
1237 ;; In my experience, the conflicted files should be marked as resolved
1238 ;; one-by-one when saving the file after resolving the conflicts.
1239 ;; I.e. stating explicitly that the conflicts are resolved is done
1240 ;; very rarely.
1241 (vc-mark-resolved backend files))
1242 ;; needs-update
1243 ((eq state 'needs-update)
1244 (dolist (file files)
1245 (if (yes-or-no-p (format
1246 "%s is not up-to-date. Get latest revision? "
1247 (file-name-nondirectory file)))
1248 (vc-checkout file t)
1249 (when (and (not (eq model 'implicit))
1250 (yes-or-no-p "Lock this revision? "))
1251 (vc-checkout file)))))
1252 ;; needs-merge
1253 ((eq state 'needs-merge)
1254 (dolist (file files)
1255 (when (yes-or-no-p (format
1256 "%s is not up-to-date. Merge in changes now? "
1257 (file-name-nondirectory file)))
1258 (vc-maybe-resolve-conflicts
1259 file (vc-call-backend backend 'merge-news file)))))
1261 ;; unlocked-changes
1262 ((eq state 'unlocked-changes)
1263 (dolist (file files)
1264 (when (not (equal buffer-file-name file))
1265 (find-file-other-window file))
1266 (if (save-window-excursion
1267 (vc-diff-internal nil
1268 (cons (car vc-fileset) (cons (cadr vc-fileset) (list file)))
1269 (vc-working-revision file) nil)
1270 (goto-char (point-min))
1271 (let ((inhibit-read-only t))
1272 (insert
1273 (format "Changes to %s since last lock:\n\n" file)))
1274 (not (beep))
1275 (yes-or-no-p (concat "File has unlocked changes. "
1276 "Claim lock retaining changes? ")))
1277 (progn (vc-call-backend backend 'steal-lock file)
1278 (clear-visited-file-modtime)
1279 (write-file buffer-file-name)
1280 (vc-mode-line file backend))
1281 (if (not (yes-or-no-p
1282 "Revert to checked-in revision, instead? "))
1283 (error "Checkout aborted")
1284 (vc-revert-buffer-internal t t)
1285 (vc-checkout file)))))
1286 ;; Unknown fileset state
1288 (error "Fileset is in an unknown state %s" state)))))
1290 (defun vc-create-repo (backend)
1291 "Create an empty repository in the current directory."
1292 (interactive
1293 (list
1294 (intern
1295 (upcase
1296 (completing-read
1297 "Create repository for: "
1298 (mapcar (lambda (b) (list (downcase (symbol-name b)))) vc-handled-backends)
1299 nil t)))))
1300 (vc-call-backend backend 'create-repo))
1302 (declare-function vc-dir-move-to-goal-column "vc-dir" ())
1304 ;;;###autoload
1305 (defun vc-register (&optional vc-fileset comment)
1306 "Register into a version control system.
1307 If VC-FILESET is given, register the files in that fileset.
1308 Otherwise register the current file.
1309 If COMMENT is present, use that as an initial comment.
1311 The version control system to use is found by cycling through the list
1312 `vc-handled-backends'. The first backend in that list which declares
1313 itself responsible for the file (usually because other files in that
1314 directory are already registered under that backend) will be used to
1315 register the file. If no backend declares itself responsible, the
1316 first backend that could register the file is used."
1317 (interactive "P")
1318 (let* ((fileset-arg (or vc-fileset (vc-deduce-fileset nil t)))
1319 (backend (car fileset-arg))
1320 (files (nth 1 fileset-arg)))
1321 ;; We used to operate on `only-files', but VC wants to provide the
1322 ;; possibility to register directories rather than files only, since
1323 ;; many VCS allow that as well.
1324 (dolist (fname files)
1325 (let ((bname (get-file-buffer fname)))
1326 (unless fname
1327 (setq fname buffer-file-name))
1328 (when (vc-call-backend backend 'registered fname)
1329 (error "This file is already registered"))
1330 ;; Watch out for new buffers of size 0: the corresponding file
1331 ;; does not exist yet, even though buffer-modified-p is nil.
1332 (when bname
1333 (with-current-buffer bname
1334 (when (and (not (buffer-modified-p))
1335 (zerop (buffer-size))
1336 (not (file-exists-p buffer-file-name)))
1337 (set-buffer-modified-p t))
1338 (vc-buffer-sync)))))
1339 (message "Registering %s... " files)
1340 (mapc 'vc-file-clearprops files)
1341 (vc-call-backend backend 'register files comment)
1342 (mapc
1343 (lambda (file)
1344 (vc-file-setprop file 'vc-backend backend)
1345 ;; FIXME: This is wrong: it should set `backup-inhibited' in all
1346 ;; the buffers visiting files affected by this `vc-register', not
1347 ;; in the current-buffer.
1348 ;; (unless vc-make-backup-files
1349 ;; (make-local-variable 'backup-inhibited)
1350 ;; (setq backup-inhibited t))
1352 (vc-resynch-buffer file vc-keep-workfiles t))
1353 files)
1354 (when (derived-mode-p 'vc-dir-mode)
1355 (vc-dir-move-to-goal-column))
1356 (message "Registering %s... done" files)))
1358 (defun vc-register-with (backend)
1359 "Register the current file with a specified back end."
1360 (interactive "SBackend: ")
1361 (when (not (member backend vc-handled-backends))
1362 (error "Unknown back end"))
1363 (let ((vc-handled-backends (list backend)))
1364 (call-interactively 'vc-register)))
1366 (defun vc-ignore (file &optional directory remove)
1367 "Ignore FILE under the VCS of DIRECTORY.
1369 Normally, FILE is a wildcard specification that matches the files
1370 to be ignored. When REMOVE is non-nil, remove FILE from the list
1371 of ignored files.
1373 DIRECTORY defaults to `default-directory' and is used to
1374 determine the responsible VC backend.
1376 When called interactively, prompt for a FILE to ignore, unless a
1377 prefix argument is given, in which case prompt for a file FILE to
1378 remove from the list of ignored files."
1379 (interactive
1380 (list
1381 (if (not current-prefix-arg)
1382 (read-file-name "File to ignore: ")
1383 (completing-read
1384 "File to remove: "
1385 (vc-call-backend
1386 (or (vc-responsible-backend default-directory)
1387 (error "Unknown backend"))
1388 'ignore-completion-table default-directory)))
1389 nil current-prefix-arg))
1390 (let* ((directory (or directory default-directory))
1391 (backend (or (vc-responsible-backend default-directory)
1392 (error "Unknown backend"))))
1393 (vc-call-backend backend 'ignore file directory remove)))
1395 (defun vc-default-ignore (backend file &optional directory remove)
1396 "Ignore FILE under the VCS of DIRECTORY (default is `default-directory').
1397 FILE is a file wildcard, relative to the root directory of DIRECTORY.
1398 When called from Lisp code, if DIRECTORY is non-nil, the
1399 repository to use will be deduced by DIRECTORY; if REMOVE is
1400 non-nil, remove FILE from ignored files.
1401 Argument BACKEND is the backend you are using."
1402 (let ((ignore
1403 (vc-call-backend backend 'find-ignore-file (or directory default-directory)))
1404 (pattern (file-relative-name
1405 (expand-file-name file) (file-name-directory file))))
1406 (if remove
1407 (vc--remove-regexp pattern ignore)
1408 (vc--add-line pattern ignore))))
1410 (defun vc-default-ignore-completion-table (backend file)
1411 "Return the list of ignored files under BACKEND."
1412 (vc--read-lines
1413 (vc-call-backend backend 'find-ignore-file file)))
1415 (defun vc--read-lines (file)
1416 "Return a list of lines of FILE."
1417 (with-temp-buffer
1418 (insert-file-contents file)
1419 (split-string (buffer-string) "\n" t)))
1421 ;; Subroutine for `vc-git-ignore' and `vc-hg-ignore'.
1422 (defun vc--add-line (string file)
1423 "Add STRING as a line to FILE."
1424 (with-temp-buffer
1425 (insert-file-contents file)
1426 (unless (re-search-forward (concat "^" (regexp-quote string) "$") nil t)
1427 (goto-char (point-max))
1428 (insert (concat "\n" string))
1429 (write-region (point-min) (point-max) file))))
1431 (defun vc--remove-regexp (regexp file)
1432 "Remove all matching for REGEXP in FILE."
1433 (with-temp-buffer
1434 (insert-file-contents file)
1435 (while (re-search-forward regexp nil t)
1436 (replace-match ""))
1437 (write-region (point-min) (point-max) file)))
1439 (defun vc-checkout (file &optional rev)
1440 "Retrieve a copy of the revision REV of FILE.
1441 REV defaults to the latest revision.
1443 After check-out, runs the normal hook `vc-checkout-hook'."
1444 (and (not rev)
1445 (vc-call make-version-backups-p file)
1446 (vc-up-to-date-p file)
1447 (vc-make-version-backup file))
1448 (let ((backend (vc-backend file)))
1449 (with-vc-properties (list file)
1450 (condition-case err
1451 (vc-call-backend backend 'checkout file rev)
1452 (file-error
1453 ;; Maybe the backend is not installed ;-(
1454 (when t
1455 (let ((buf (get-file-buffer file)))
1456 (when buf (with-current-buffer buf (read-only-mode -1)))))
1457 (signal (car err) (cdr err))))
1458 `((vc-state . ,(if (or (eq (vc-checkout-model backend (list file)) 'implicit)
1459 nil)
1460 (if (vc-call-backend backend 'latest-on-branch-p file)
1461 'up-to-date
1462 'needs-update)
1463 'edited))
1464 (vc-checkout-time . ,(nth 5 (file-attributes file))))))
1465 (vc-resynch-buffer file t t)
1466 (run-hooks 'vc-checkout-hook))
1468 (defun vc-mark-resolved (backend files)
1469 (prog1 (with-vc-properties
1470 files
1471 (vc-call-backend backend 'mark-resolved files)
1472 ;; FIXME: Is this TRTD? Might not be.
1473 `((vc-state . edited)))
1474 (message
1475 (substitute-command-keys
1476 "Conflicts have been resolved in %s. \
1477 Type \\[vc-next-action] to check in changes.")
1478 (if (> (length files) 1)
1479 (format "%d files" (length files))
1480 "this file"))))
1482 (defun vc-steal-lock (file rev owner)
1483 "Steal the lock on FILE."
1484 (let (file-description)
1485 (if rev
1486 (setq file-description (format "%s:%s" file rev))
1487 (setq file-description file))
1488 (when (not (yes-or-no-p (format "Steal the lock on %s from %s? "
1489 file-description owner)))
1490 (error "Steal canceled"))
1491 (message "Stealing lock on %s..." file)
1492 (with-vc-properties
1493 (list file)
1494 (vc-call steal-lock file rev)
1495 `((vc-state . edited)))
1496 (vc-resynch-buffer file t t)
1497 (message "Stealing lock on %s...done" file)
1498 ;; Write mail after actually stealing, because if the stealing
1499 ;; goes wrong, we don't want to send any mail.
1500 (compose-mail owner (format "Stolen lock on %s" file-description))
1501 (setq default-directory (expand-file-name "~/"))
1502 (goto-char (point-max))
1503 (insert
1504 (format "I stole the lock on %s, " file-description)
1505 (current-time-string)
1506 ".\n")
1507 (message "Please explain why you stole the lock. Type C-c C-c when done.")))
1509 (defun vc-checkin (files backend &optional comment initial-contents)
1510 "Check in FILES. COMMENT is a comment string; if omitted, a
1511 buffer is popped up to accept a comment. If INITIAL-CONTENTS is
1512 non-nil, then COMMENT is used as the initial contents of the log
1513 entry buffer.
1515 If `vc-keep-workfiles' is nil, FILE is deleted afterwards, provided
1516 that the version control system supports this mode of operation.
1518 Runs the normal hooks `vc-before-checkin-hook' and `vc-checkin-hook'."
1519 (when vc-before-checkin-hook
1520 (run-hooks 'vc-before-checkin-hook))
1521 (vc-start-logentry
1522 files comment initial-contents
1523 "Enter a change comment."
1524 "*vc-log*"
1525 (lambda ()
1526 (vc-call-backend backend 'log-edit-mode))
1527 (lambda (files comment)
1528 (message "Checking in %s..." (vc-delistify files))
1529 ;; "This log message intentionally left almost blank".
1530 ;; RCS 5.7 gripes about white-space-only comments too.
1531 (or (and comment (string-match "[^\t\n ]" comment))
1532 (setq comment "*** empty log message ***"))
1533 (with-vc-properties
1534 files
1535 ;; We used to change buffers to get local value of
1536 ;; vc-checkin-switches, but 'the' local buffer is
1537 ;; not a well-defined concept for filesets.
1538 (progn
1539 (vc-call-backend backend 'checkin files comment)
1540 (mapc 'vc-delete-automatic-version-backups files))
1541 `((vc-state . up-to-date)
1542 (vc-checkout-time . ,(nth 5 (file-attributes file)))
1543 (vc-working-revision . nil)))
1544 (message "Checking in %s...done" (vc-delistify files)))
1545 'vc-checkin-hook
1546 backend))
1548 ;;; Additional entry points for examining version histories
1550 ;; (defun vc-default-diff-tree (backend dir rev1 rev2)
1551 ;; "List differences for all registered files at and below DIR.
1552 ;; The meaning of REV1 and REV2 is the same as for `vc-revision-diff'."
1553 ;; ;; This implementation does an explicit tree walk, and calls
1554 ;; ;; vc-BACKEND-diff directly for each file. An optimization
1555 ;; ;; would be to use `vc-diff-internal', so that diffs can be local,
1556 ;; ;; and to call it only for files that are actually changed.
1557 ;; ;; However, this is expensive for some backends, and so it is left
1558 ;; ;; to backend-specific implementations.
1559 ;; (setq default-directory dir)
1560 ;; (vc-file-tree-walk
1561 ;; default-directory
1562 ;; (lambda (f)
1563 ;; (vc-run-delayed
1564 ;; (let ((coding-system-for-read (vc-coding-system-for-diff f)))
1565 ;; (message "Looking at %s" f)
1566 ;; (vc-call-backend (vc-backend f)
1567 ;; 'diff (list f) rev1 rev2))))))
1569 (defvar vc-coding-system-inherit-eol t
1570 "When non-nil, inherit the EOL format for reading Diff output from the file.
1572 Used in `vc-coding-system-for-diff' to determine the EOL format to use
1573 for reading Diff output for a file. If non-nil, the EOL format is
1574 inherited from the file itself.
1575 Set this variable to nil if your Diff tool might use a different
1576 EOL. Then Emacs will auto-detect the EOL format in Diff output, which
1577 gives better results.") ;; Cf. bug#4451.
1579 (defun vc-coding-system-for-diff (file)
1580 "Return the coding system for reading diff output for FILE."
1581 (or coding-system-for-read
1582 ;; if we already have this file open,
1583 ;; use the buffer's coding system
1584 (let ((buf (find-buffer-visiting file)))
1585 (when buf (with-current-buffer buf
1586 (if vc-coding-system-inherit-eol
1587 buffer-file-coding-system
1588 ;; Don't inherit the EOL part of the coding-system,
1589 ;; because some Diff tools may choose to use
1590 ;; a different one. bug#4451.
1591 (coding-system-base buffer-file-coding-system)))))
1592 ;; otherwise, try to find one based on the file name
1593 (car (find-operation-coding-system 'insert-file-contents file))
1594 ;; and a final fallback
1595 'undecided))
1597 (defun vc-switches (backend op)
1598 "Return a list of vc-BACKEND switches for operation OP.
1599 BACKEND is a symbol such as `CVS', which will be downcased.
1600 OP is a symbol such as `diff'.
1602 In decreasing order of preference, return the value of:
1603 vc-BACKEND-OP-switches (e.g. `vc-cvs-diff-switches');
1604 vc-OP-switches (e.g. `vc-diff-switches'); or, in the case of
1605 diff only, `diff-switches'.
1607 If the chosen value is not a string or a list, return nil.
1608 This is so that you may set, e.g. `vc-svn-diff-switches' to t in order
1609 to override the value of `vc-diff-switches' and `diff-switches'."
1610 (let ((switches
1611 (or (when backend
1612 (let ((sym (vc-make-backend-sym
1613 backend (intern (concat (symbol-name op)
1614 "-switches")))))
1615 (when (boundp sym) (symbol-value sym))))
1616 (let ((sym (intern (format "vc-%s-switches" (symbol-name op)))))
1617 (when (boundp sym) (symbol-value sym)))
1618 (cond
1619 ((eq op 'diff) diff-switches)))))
1620 (if (stringp switches) (list switches)
1621 ;; If not a list, return nil.
1622 ;; This is so we can set vc-diff-switches to t to override
1623 ;; any switches in diff-switches.
1624 (when (listp switches) switches))))
1626 ;; Old def for compatibility with Emacs-21.[123].
1627 (defmacro vc-diff-switches-list (backend)
1628 (declare (obsolete vc-switches "22.1"))
1629 `(vc-switches ',backend 'diff))
1631 (defun vc-diff-finish (buffer messages)
1632 ;; The empty sync output case has already been handled, so the only
1633 ;; possibility of an empty output is for an async process.
1634 (when (buffer-live-p buffer)
1635 (let ((window (get-buffer-window buffer t))
1636 (emptyp (zerop (buffer-size buffer))))
1637 (with-current-buffer buffer
1638 (and messages emptyp
1639 (let ((inhibit-read-only t))
1640 (insert (cdr messages) ".\n")
1641 (message "%s" (cdr messages))))
1642 (diff-setup-whitespace)
1643 (goto-char (point-min))
1644 (when window
1645 (shrink-window-if-larger-than-buffer window)))
1646 (when (and messages (not emptyp))
1647 (message "%sdone" (car messages))))))
1649 (defvar vc-diff-added-files nil
1650 "If non-nil, diff added files by comparing them to /dev/null.")
1652 (defun vc-diff-internal (async vc-fileset rev1 rev2 &optional verbose buffer)
1653 "Report diffs between two revisions of a fileset.
1654 Output goes to the buffer BUFFER, which defaults to *vc-diff*.
1655 BUFFER, if non-nil, should be a buffer or a buffer name.
1656 Return t if the buffer had changes, nil otherwise."
1657 (unless buffer
1658 (setq buffer "*vc-diff*"))
1659 (let* ((files (cadr vc-fileset))
1660 (messages (cons (format "Finding changes in %s..."
1661 (vc-delistify files))
1662 (format "No changes between %s and %s"
1663 (or rev1 "working revision")
1664 (or rev2 "workfile"))))
1665 ;; Set coding system based on the first file. It's a kluge,
1666 ;; but the only way to set it for each file included would
1667 ;; be to call the back end separately for each file.
1668 (coding-system-for-read
1669 (if files (vc-coding-system-for-diff (car files)) 'undecided)))
1670 ;; On MS-Windows and MS-DOS, Diff is likely to produce DOS-style
1671 ;; EOLs, which will look ugly if (car files) happens to have Unix
1672 ;; EOLs.
1673 (if (memq system-type '(windows-nt ms-dos))
1674 (setq coding-system-for-read
1675 (coding-system-change-eol-conversion coding-system-for-read
1676 'dos)))
1677 (vc-setup-buffer buffer)
1678 (message "%s" (car messages))
1679 ;; Many backends don't handle well the case of a file that has been
1680 ;; added but not yet committed to the repo (notably CVS and Subversion).
1681 ;; Do that work here so the backends don't have to futz with it. --ESR
1683 ;; Actually most backends (including CVS) have options to control the
1684 ;; behavior since which one is better depends on the user and on the
1685 ;; situation). Worse yet: this code does not handle the case where
1686 ;; `file' is a directory which contains added files.
1687 ;; I made it conditional on vc-diff-added-files but it should probably
1688 ;; just be removed (or copied/moved to specific backends). --Stef.
1689 (when vc-diff-added-files
1690 (let ((filtered '())
1691 process-file-side-effects)
1692 (dolist (file files)
1693 (if (or (file-directory-p file)
1694 (not (string= (vc-working-revision file) "0")))
1695 (push file filtered)
1696 ;; This file is added but not yet committed;
1697 ;; there is no repository version to diff against.
1698 (if (or rev1 rev2)
1699 (error "No revisions of %s exist" file)
1700 ;; We regard this as "changed".
1701 ;; Diff it against /dev/null.
1702 (apply 'vc-do-command buffer
1703 (if async 'async 1) "diff" file
1704 (append (vc-switches nil 'diff) '("/dev/null"))))))
1705 (setq files (nreverse filtered))))
1706 (vc-call-backend (car vc-fileset) 'diff files async rev1 rev2 buffer)
1707 (set-buffer buffer)
1708 (diff-mode)
1709 (set (make-local-variable 'diff-vc-backend) (car vc-fileset))
1710 (set (make-local-variable 'revert-buffer-function)
1711 (lambda (_ignore-auto _noconfirm)
1712 (vc-diff-internal async vc-fileset rev1 rev2 verbose)))
1713 ;; Make the *vc-diff* buffer read only, the diff-mode key
1714 ;; bindings are nicer for read only buffers. pcl-cvs does the
1715 ;; same thing.
1716 (setq buffer-read-only t)
1717 (if (and (zerop (buffer-size))
1718 (not (get-buffer-process (current-buffer))))
1719 ;; Treat this case specially so as not to pop the buffer.
1720 (progn
1721 (message "%s" (cdr messages))
1722 nil)
1723 ;; Display the buffer, but at the end because it can change point.
1724 (pop-to-buffer (current-buffer))
1725 ;; The diff process may finish early, so call `vc-diff-finish'
1726 ;; after `pop-to-buffer'; the former assumes the diff buffer is
1727 ;; shown in some window.
1728 (let ((buf (current-buffer)))
1729 (vc-run-delayed (vc-diff-finish buf (when verbose messages))))
1730 ;; In the async case, we return t even if there are no differences
1731 ;; because we don't know that yet.
1732 t)))
1734 (defun vc-read-revision (prompt &optional files backend default initial-input)
1735 (cond
1736 ((null files)
1737 (let ((vc-fileset (vc-deduce-fileset t))) ;FIXME: why t? --Stef
1738 (setq files (cadr vc-fileset))
1739 (setq backend (car vc-fileset))))
1740 ((null backend) (setq backend (vc-backend (car files)))))
1741 (let ((completion-table
1742 (vc-call-backend backend 'revision-completion-table files)))
1743 (if completion-table
1744 (completing-read prompt completion-table
1745 nil nil initial-input nil default)
1746 (read-string prompt initial-input nil default))))
1748 (defun vc-diff-build-argument-list-internal ()
1749 "Build argument list for calling internal diff functions."
1750 (let* ((vc-fileset (vc-deduce-fileset t)) ;FIXME: why t? --Stef
1751 (files (cadr vc-fileset))
1752 (backend (car vc-fileset))
1753 (first (car files))
1754 (rev1-default nil)
1755 (rev2-default nil))
1756 (cond
1757 ;; someday we may be able to do revision completion on non-singleton
1758 ;; filesets, but not yet.
1759 ((/= (length files) 1)
1760 nil)
1761 ;; if it's a directory, don't supply any revision default
1762 ((file-directory-p first)
1763 nil)
1764 ;; if the file is not up-to-date, use working revision as older revision
1765 ((not (vc-up-to-date-p first))
1766 (setq rev1-default (vc-working-revision first)))
1767 ;; if the file is not locked, use last revision and current source as defaults
1769 (setq rev1-default (ignore-errors ;If `previous-revision' doesn't work.
1770 (vc-call-backend backend 'previous-revision first
1771 (vc-working-revision first))))
1772 (when (string= rev1-default "") (setq rev1-default nil))))
1773 ;; construct argument list
1774 (let* ((rev1-prompt (if rev1-default
1775 (concat "Older revision (default "
1776 rev1-default "): ")
1777 "Older revision: "))
1778 (rev2-prompt (concat "Newer revision (default "
1779 (or rev2-default "current source") "): "))
1780 (rev1 (vc-read-revision rev1-prompt files backend rev1-default))
1781 (rev2 (vc-read-revision rev2-prompt files backend rev2-default)))
1782 (when (string= rev1 "") (setq rev1 nil))
1783 (when (string= rev2 "") (setq rev2 nil))
1784 (list files rev1 rev2))))
1786 ;;;###autoload
1787 (defun vc-version-diff (_files rev1 rev2)
1788 "Report diffs between revisions of the fileset in the repository history."
1789 (interactive (vc-diff-build-argument-list-internal))
1790 ;; All that was just so we could do argument completion!
1791 (when (and (not rev1) rev2)
1792 (error "Not a valid revision range"))
1793 ;; Yes, it's painful to call (vc-deduce-fileset) again. Alas, the
1794 ;; placement rules for (interactive) don't actually leave us a choice.
1795 (vc-diff-internal t (vc-deduce-fileset t) rev1 rev2
1796 (called-interactively-p 'interactive)))
1798 ;;;###autoload
1799 (defun vc-diff (&optional historic not-urgent)
1800 "Display diffs between file revisions.
1801 Normally this compares the currently selected fileset with their
1802 working revisions. With a prefix argument HISTORIC, it reads two revision
1803 designators specifying which revisions to compare.
1805 The optional argument NOT-URGENT non-nil means it is ok to say no to
1806 saving the buffer."
1807 (interactive (list current-prefix-arg t))
1808 (if historic
1809 (call-interactively 'vc-version-diff)
1810 (when buffer-file-name (vc-buffer-sync not-urgent))
1811 (vc-diff-internal t (vc-deduce-fileset t) nil nil
1812 (called-interactively-p 'interactive))))
1814 (declare-function ediff-load-version-control "ediff" (&optional silent))
1815 (declare-function ediff-vc-internal "ediff-vers"
1816 (rev1 rev2 &optional startup-hooks))
1818 ;;;###autoload
1819 (defun vc-version-ediff (files rev1 rev2)
1820 "Show differences between revisions of the fileset in the
1821 repository history using ediff."
1822 (interactive (vc-diff-build-argument-list-internal))
1823 ;; All that was just so we could do argument completion!
1824 (when (and (not rev1) rev2)
1825 (error "Not a valid revision range"))
1827 (message "%s" (format "Finding changes in %s..." (vc-delistify files)))
1829 ;; Functions ediff-(vc|rcs)-internal use "" instead of nil.
1830 (when (null rev1) (setq rev1 ""))
1831 (when (null rev2) (setq rev2 ""))
1833 (cond
1834 ;; FIXME We only support running ediff on one file for now.
1835 ;; We could spin off an ediff session per file in the file set.
1836 ((= (length files) 1)
1837 (require 'ediff)
1838 (ediff-load-version-control) ; loads ediff-vers
1839 (find-file (car files)) ;FIXME: find-file from Elisp is bad.
1840 (ediff-vc-internal rev1 rev2 nil))
1842 (error "More than one file is not supported"))))
1844 ;;;###autoload
1845 (defun vc-ediff (historic &optional not-urgent)
1846 "Display diffs between file revisions using ediff.
1847 Normally this compares the currently selected fileset with their
1848 working revisions. With a prefix argument HISTORIC, it reads two revision
1849 designators specifying which revisions to compare.
1851 The optional argument NOT-URGENT non-nil means it is ok to say no to
1852 saving the buffer."
1853 (interactive (list current-prefix-arg t))
1854 (if historic
1855 (call-interactively 'vc-version-ediff)
1856 (when buffer-file-name (vc-buffer-sync not-urgent))
1857 (vc-version-ediff (cadr (vc-deduce-fileset t)) nil nil)))
1859 ;;;###autoload
1860 (defun vc-root-diff (historic &optional not-urgent)
1861 "Display diffs between VC-controlled whole tree revisions.
1862 Normally, this compares the tree corresponding to the current
1863 fileset with the working revision.
1864 With a prefix argument HISTORIC, prompt for two revision
1865 designators specifying which revisions to compare.
1867 The optional argument NOT-URGENT non-nil means it is ok to say no to
1868 saving the buffer."
1869 (interactive (list current-prefix-arg t))
1870 (if historic
1871 ;; FIXME: this does not work right, `vc-version-diff' ends up
1872 ;; calling `vc-deduce-fileset' to find the files to diff, and
1873 ;; that's not what we want here, we want the diff for the VC root dir.
1874 (call-interactively 'vc-version-diff)
1875 (when buffer-file-name (vc-buffer-sync not-urgent))
1876 (let ((backend (vc-deduce-backend))
1877 (default-directory default-directory)
1878 rootdir working-revision)
1879 (if backend
1880 (setq rootdir (vc-call-backend backend 'root default-directory))
1881 (setq rootdir (read-directory-name "Directory for VC root-diff: "))
1882 (setq backend (vc-responsible-backend rootdir))
1883 (if backend
1884 (setq default-directory rootdir)
1885 (error "Directory is not version controlled")))
1886 (setq working-revision (vc-working-revision rootdir))
1887 ;; VC diff for the root directory produces output that is
1888 ;; relative to it. Bind default-directory to the root directory
1889 ;; here, this way the *vc-diff* buffer is setup correctly, so
1890 ;; relative file names work.
1891 (let ((default-directory rootdir))
1892 (vc-diff-internal
1893 t (list backend (list rootdir) working-revision) nil nil
1894 (called-interactively-p 'interactive))))))
1896 ;;;###autoload
1897 (defun vc-root-dir ()
1898 "Return the root directory for the current VC tree.
1899 Return nil if the root directory cannot be identified."
1900 (let ((backend (vc-deduce-backend)))
1901 (if backend
1902 (condition-case err
1903 (vc-call-backend backend 'root default-directory)
1904 (vc-not-supported
1905 (unless (eq (cadr err) 'root)
1906 (signal (car err) (cdr err)))
1907 nil)))))
1909 ;;;###autoload
1910 (defun vc-revision-other-window (rev)
1911 "Visit revision REV of the current file in another window.
1912 If the current file is named `F', the revision is named `F.~REV~'.
1913 If `F.~REV~' already exists, use it instead of checking it out again."
1914 (interactive
1915 (save-current-buffer
1916 (vc-ensure-vc-buffer)
1917 (list
1918 (vc-read-revision "Revision to visit (default is working revision): "
1919 (list buffer-file-name)))))
1920 (vc-ensure-vc-buffer)
1921 (let* ((file buffer-file-name)
1922 (revision (if (string-equal rev "")
1923 (vc-working-revision file)
1924 rev)))
1925 (switch-to-buffer-other-window (vc-find-revision file revision))))
1927 (defun vc-find-revision (file revision &optional backend)
1928 "Read REVISION of FILE into a buffer and return the buffer.
1929 Use BACKEND as the VC backend if specified."
1930 (let ((automatic-backup (vc-version-backup-file-name file revision))
1931 (filebuf (or (get-file-buffer file) (current-buffer)))
1932 (filename (vc-version-backup-file-name file revision 'manual)))
1933 (unless (file-exists-p filename)
1934 (if (file-exists-p automatic-backup)
1935 (rename-file automatic-backup filename nil)
1936 (message "Checking out %s..." filename)
1937 (with-current-buffer filebuf
1938 (let ((failed t))
1939 (unwind-protect
1940 (let ((coding-system-for-read 'no-conversion)
1941 (coding-system-for-write 'no-conversion))
1942 (with-temp-file filename
1943 (let ((outbuf (current-buffer)))
1944 ;; Change buffer to get local value of
1945 ;; vc-checkout-switches.
1946 (with-current-buffer filebuf
1947 (if backend
1948 (vc-call-backend backend 'find-revision file revision outbuf)
1949 (vc-call find-revision file revision outbuf)))))
1950 (setq failed nil))
1951 (when (and failed (file-exists-p filename))
1952 (delete-file filename))))
1953 (vc-mode-line file))
1954 (message "Checking out %s...done" filename)))
1955 (let ((result-buf (find-file-noselect filename)))
1956 (with-current-buffer result-buf
1957 ;; Set the parent buffer so that things like
1958 ;; C-x v g, C-x v l, ... etc work.
1959 (set (make-local-variable 'vc-parent-buffer) filebuf))
1960 result-buf)))
1962 ;; Header-insertion code
1964 ;;;###autoload
1965 (defun vc-insert-headers ()
1966 "Insert headers into a file for use with a version control system.
1967 Headers desired are inserted at point, and are pulled from
1968 the variable `vc-BACKEND-header'."
1969 (interactive)
1970 (vc-ensure-vc-buffer)
1971 (save-excursion
1972 (save-restriction
1973 (widen)
1974 (when (or (not (vc-check-headers))
1975 (y-or-n-p "Version headers already exist. Insert another set? "))
1976 (let* ((delims (cdr (assq major-mode vc-comment-alist)))
1977 (comment-start-vc (or (car delims) comment-start "#"))
1978 (comment-end-vc (or (car (cdr delims)) comment-end ""))
1979 (hdsym (vc-make-backend-sym (vc-backend buffer-file-name)
1980 'header))
1981 (hdstrings (and (boundp hdsym) (symbol-value hdsym))))
1982 (dolist (s hdstrings)
1983 (insert comment-start-vc "\t" s "\t"
1984 comment-end-vc "\n"))
1985 (when vc-static-header-alist
1986 (dolist (f vc-static-header-alist)
1987 (when (string-match (car f) buffer-file-name)
1988 (insert (format (cdr f) (car hdstrings)))))))))))
1990 (defun vc-modify-change-comment (files rev oldcomment)
1991 "Edit the comment associated with the given files and revision."
1992 ;; Less of a kluge than it looks like; log-view mode only passes
1993 ;; this function a singleton list. Arguments left in this form in
1994 ;; case the more general operation ever becomes meaningful.
1995 (let ((backend (vc-responsible-backend (car files))))
1996 (vc-start-logentry
1997 files oldcomment t
1998 "Enter a replacement change comment."
1999 "*vc-log*"
2000 (lambda () (vc-call-backend backend 'log-edit-mode))
2001 (lambda (files comment)
2002 (vc-call-backend backend
2003 'modify-change-comment files rev comment)))))
2005 ;;;###autoload
2006 (defun vc-merge ()
2007 "Perform a version control merge operation.
2008 You must be visiting a version controlled file, or in a `vc-dir' buffer.
2009 On a distributed version control system, this runs a \"merge\"
2010 operation to incorporate changes from another branch onto the
2011 current branch, prompting for an argument list.
2013 On a non-distributed version control system, this merges changes
2014 between two revisions into the current fileset. This asks for
2015 two revisions to merge from in the minibuffer. If the first
2016 revision is a branch number, then merge all changes from that
2017 branch. If the first revision is empty, merge the most recent
2018 changes from the current branch."
2019 (interactive)
2020 (let* ((vc-fileset (vc-deduce-fileset t))
2021 (backend (car vc-fileset))
2022 (files (cadr vc-fileset)))
2023 (cond
2024 ;; If a branch-merge operation is defined, use it.
2025 ((vc-find-backend-function backend 'merge-branch)
2026 (vc-call-backend backend 'merge-branch))
2027 ;; Otherwise, do a per-file merge.
2028 ((vc-find-backend-function backend 'merge)
2029 (vc-buffer-sync)
2030 (dolist (file files)
2031 (let* ((state (vc-state file))
2032 status)
2033 (cond
2034 ((stringp state) ;; Locking VCses only
2035 (error "File %s is locked by %s" file state))
2036 ((not (vc-editable-p file))
2037 (vc-checkout file t)))
2038 (setq status (vc-call-backend backend 'merge-file file))
2039 (vc-maybe-resolve-conflicts file status "WORKFILE" "MERGE SOURCE"))))
2041 (error "Sorry, merging is not implemented for %s" backend)))))
2043 (defun vc-maybe-resolve-conflicts (file status &optional _name-A _name-B)
2044 (vc-resynch-buffer file t (not (buffer-modified-p)))
2045 (if (zerop status) (message "Merge successful")
2046 (smerge-mode 1)
2047 (message "File contains conflicts.")))
2049 ;;;###autoload
2050 (defalias 'vc-resolve-conflicts 'smerge-ediff)
2052 ;; TODO: This is OK but maybe we could integrate it better.
2053 ;; E.g. it could be run semi-automatically (via a prompt?) when saving a file
2054 ;; that was conflicted (i.e. upon mark-resolved).
2055 ;; FIXME: should we add an "other-window" version? Or maybe we should
2056 ;; hook it inside find-file so it automatically works for
2057 ;; find-file-other-window as well. E.g. find-file could use a new
2058 ;; `default-next-file' variable for its default file (M-n), and
2059 ;; we could then set it upon mark-resolve, so C-x C-s C-x C-f M-n would
2060 ;; automatically offer the next conflicted file.
2061 (defun vc-find-conflicted-file ()
2062 "Visit the next conflicted file in the current project."
2063 (interactive)
2064 (let* ((backend (or (if buffer-file-name (vc-backend buffer-file-name))
2065 (vc-responsible-backend default-directory)
2066 (error "No VC backend")))
2067 (root (vc-root-dir))
2068 (files (vc-call-backend backend
2069 'conflicted-files (or root default-directory))))
2070 ;; Don't try and visit the current file.
2071 (if (equal (car files) buffer-file-name) (pop files))
2072 (if (null files)
2073 (message "No more conflicted files")
2074 (find-file (pop files))
2075 (message "%s more conflicted files after this one"
2076 (if files (length files) "No")))))
2078 ;; Named-configuration entry points
2080 (defun vc-tag-precondition (dir)
2081 "Scan the tree below DIR, looking for files not up-to-date.
2082 If any file is not up-to-date, return the name of the first such file.
2083 \(This means, neither tag creation nor retrieval is allowed.\)
2084 If one or more of the files are currently visited, return `visited'.
2085 Otherwise, return nil."
2086 (let ((status nil))
2087 (catch 'vc-locked-example
2088 (vc-file-tree-walk
2090 (lambda (f)
2091 (if (not (vc-up-to-date-p f)) (throw 'vc-locked-example f)
2092 (when (get-file-buffer f) (setq status 'visited)))))
2093 status)))
2095 ;;;###autoload
2096 (defun vc-create-tag (dir name branchp)
2097 "Descending recursively from DIR, make a tag called NAME.
2098 For each registered file, the working revision becomes part of
2099 the named configuration. If the prefix argument BRANCHP is
2100 given, the tag is made as a new branch and the files are
2101 checked out in that new branch."
2102 (interactive
2103 (let ((granularity
2104 (vc-call-backend (vc-responsible-backend default-directory)
2105 'revision-granularity)))
2106 (list
2107 (if (eq granularity 'repository)
2108 ;; For VC's that do not work at file level, it's pointless
2109 ;; to ask for a directory, branches are created at repository level.
2110 default-directory
2111 (read-directory-name "Directory: " default-directory default-directory t))
2112 (read-string (if current-prefix-arg "New branch name: " "New tag name: "))
2113 current-prefix-arg)))
2114 (message "Making %s... " (if branchp "branch" "tag"))
2115 (when (file-directory-p dir) (setq dir (file-name-as-directory dir)))
2116 (vc-call-backend (vc-responsible-backend dir)
2117 'create-tag dir name branchp)
2118 (vc-resynch-buffer dir t t t)
2119 (message "Making %s... done" (if branchp "branch" "tag")))
2121 ;;;###autoload
2122 (defun vc-retrieve-tag (dir name)
2123 "For each file in or below DIR, retrieve their tagged version NAME.
2124 NAME can name a branch, in which case this command will switch to the
2125 named branch in the directory DIR.
2126 Interactively, prompt for DIR only for VCS that works at file level;
2127 otherwise use the default directory of the current buffer.
2128 If NAME is empty, it refers to the latest revisions of the current branch.
2129 If locking is used for the files in DIR, then there must not be any
2130 locked files at or below DIR (but if NAME is empty, locked files are
2131 allowed and simply skipped)."
2132 (interactive
2133 (let ((granularity
2134 (vc-call-backend (vc-responsible-backend default-directory)
2135 'revision-granularity)))
2136 (list
2137 (if (eq granularity 'repository)
2138 ;; For VC's that do not work at file level, it's pointless
2139 ;; to ask for a directory, branches are created at repository level.
2140 default-directory
2141 (read-directory-name "Directory: " default-directory default-directory t))
2142 (read-string "Tag name to retrieve (default latest revisions): "))))
2143 (let ((update (yes-or-no-p "Update any affected buffers? "))
2144 (msg (if (or (not name) (string= name ""))
2145 (format "Updating %s... " (abbreviate-file-name dir))
2146 (format "Retrieving tag into %s... "
2147 (abbreviate-file-name dir)))))
2148 (message "%s" msg)
2149 (vc-call-backend (vc-responsible-backend dir)
2150 'retrieve-tag dir name update)
2151 (vc-resynch-buffer dir t t t)
2152 (message "%s" (concat msg "done"))))
2155 ;; Miscellaneous other entry points
2157 ;; FIXME: this should be a defcustom
2158 ;; FIXME: maybe add another choice:
2159 ;; `root-directory' (or somesuch), which would mean show a short log
2160 ;; for the root directory.
2161 (defvar vc-log-short-style '(directory)
2162 "Whether or not to show a short log.
2163 If it contains `directory' then if the fileset contains a directory show a short log.
2164 If it contains `file' then show short logs for files.
2165 Not all VC backends support short logs!")
2167 (defvar log-view-vc-fileset)
2169 (defun vc-print-log-setup-buttons (working-revision is-start-revision limit pl-return)
2170 "Insert at the end of the current buffer buttons to show more log entries.
2171 In the new log, leave point at WORKING-REVISION (if non-nil).
2172 LIMIT is the number of entries currently shown.
2173 Does nothing if IS-START-REVISION is non-nil, or if LIMIT is nil,
2174 or if PL-RETURN is 'limit-unsupported."
2175 (when (and limit (not (eq 'limit-unsupported pl-return))
2176 (not is-start-revision))
2177 (goto-char (point-max))
2178 (insert "\n")
2179 (insert-text-button "Show 2X entries"
2180 'action (lambda (&rest _ignore)
2181 (vc-print-log-internal
2182 log-view-vc-backend log-view-vc-fileset
2183 working-revision nil (* 2 limit)))
2184 'help-echo "Show the log again, and double the number of log entries shown")
2185 (insert " ")
2186 (insert-text-button "Show unlimited entries"
2187 'action (lambda (&rest _ignore)
2188 (vc-print-log-internal
2189 log-view-vc-backend log-view-vc-fileset
2190 working-revision nil nil))
2191 'help-echo "Show the log again, including all entries")))
2193 (defun vc-print-log-internal (backend files working-revision
2194 &optional is-start-revision limit)
2195 "For specified BACKEND and FILES, show the VC log.
2196 Leave point at WORKING-REVISION, if it is non-nil.
2197 If IS-START-REVISION is non-nil, start the log from WORKING-REVISION
2198 \(not all backends support this); i.e., show only WORKING-REVISION and
2199 earlier revisions. Show up to LIMIT entries (non-nil means unlimited)."
2200 ;; As of 2013/04 the only thing that passes IS-START-REVISION non-nil
2201 ;; is vc-annotate-show-log-revision-at-line, which sets LIMIT = 1.
2203 ;; Don't switch to the output buffer before running the command,
2204 ;; so that any buffer-local settings in the vc-controlled
2205 ;; buffer can be accessed by the command.
2206 (let* ((dir-present (cl-some #'file-directory-p files))
2207 (shortlog (not (null (memq (if dir-present 'directory 'file)
2208 vc-log-short-style))))
2209 (buffer-name "*vc-change-log*")
2210 (type (if shortlog 'short 'long)))
2211 (vc-log-internal-common
2212 backend buffer-name files type
2213 (lambda (bk buf _type-arg files-arg)
2214 (vc-call-backend bk 'print-log files-arg buf shortlog
2215 (when is-start-revision working-revision) limit))
2216 (lambda (_bk _files-arg ret)
2217 (vc-print-log-setup-buttons working-revision
2218 is-start-revision limit ret))
2219 (lambda (bk)
2220 (vc-call-backend bk 'show-log-entry working-revision))
2221 (lambda (_ignore-auto _noconfirm)
2222 (vc-print-log-internal backend files working-revision
2223 is-start-revision limit)))))
2225 (defvar vc-log-view-type nil
2226 "Set this to differentiate the different types of logs.")
2227 (put 'vc-log-view-type 'permanent-local t)
2228 (defvar vc-sentinel-movepoint)
2230 (defun vc-log-internal-common (backend
2231 buffer-name
2232 files
2233 type
2234 backend-func
2235 setup-buttons-func
2236 goto-location-func
2237 rev-buff-func)
2238 (let (retval)
2239 (with-current-buffer (get-buffer-create buffer-name)
2240 (set (make-local-variable 'vc-log-view-type) type))
2241 (setq retval (funcall backend-func backend buffer-name type files))
2242 (with-current-buffer (get-buffer buffer-name)
2243 (let ((inhibit-read-only t))
2244 ;; log-view-mode used to be called with inhibit-read-only bound
2245 ;; to t, so let's keep doing it, just in case.
2246 (vc-call-backend backend 'log-view-mode)
2247 (set (make-local-variable 'log-view-vc-backend) backend)
2248 (set (make-local-variable 'log-view-vc-fileset) files)
2249 (set (make-local-variable 'revert-buffer-function)
2250 rev-buff-func)))
2251 ;; Display after setting up major-mode, so display-buffer-alist can know
2252 ;; the major-mode.
2253 (pop-to-buffer buffer-name)
2254 (vc-run-delayed
2255 (let ((inhibit-read-only t))
2256 (funcall setup-buttons-func backend files retval)
2257 (shrink-window-if-larger-than-buffer)
2258 (funcall goto-location-func backend)
2259 (setq vc-sentinel-movepoint (point))
2260 (set-buffer-modified-p nil)))))
2262 (defun vc-incoming-outgoing-internal (backend remote-location buffer-name type)
2263 (vc-log-internal-common
2264 backend buffer-name nil type
2265 (lambda (bk buf type-arg _files)
2266 (vc-call-backend bk type-arg buf remote-location))
2267 (lambda (_bk _files-arg _ret) nil)
2268 (lambda (_bk) (goto-char (point-min)))
2269 (lambda (_ignore-auto _noconfirm)
2270 (vc-incoming-outgoing-internal backend remote-location buffer-name type))))
2272 ;;;###autoload
2273 (defun vc-print-log (&optional working-revision limit)
2274 "List the change log of the current fileset in a window.
2275 If WORKING-REVISION is non-nil, leave point at that revision.
2276 If LIMIT is non-nil, it should be a number specifying the maximum
2277 number of revisions to show; the default is `vc-log-show-limit'.
2279 When called interactively with a prefix argument, prompt for
2280 WORKING-REVISION and LIMIT."
2281 (interactive
2282 (cond
2283 (current-prefix-arg
2284 (let ((rev (read-from-minibuffer "Leave point at revision (default: last revision): " nil
2285 nil nil nil))
2286 (lim (string-to-number
2287 (read-from-minibuffer
2288 "Limit display (unlimited: 0): "
2289 (format "%s" vc-log-show-limit)
2290 nil nil nil))))
2291 (when (string= rev "") (setq rev nil))
2292 (when (<= lim 0) (setq lim nil))
2293 (list rev lim)))
2295 (list nil (when (> vc-log-show-limit 0) vc-log-show-limit)))))
2296 (let* ((vc-fileset (vc-deduce-fileset t)) ;FIXME: Why t? --Stef
2297 (backend (car vc-fileset))
2298 (files (cadr vc-fileset))
2299 ;; (working-revision (or working-revision (vc-working-revision (car files))))
2301 (vc-print-log-internal backend files working-revision nil limit)))
2303 ;;;###autoload
2304 (defun vc-print-root-log (&optional limit)
2305 "List the change log for the current VC controlled tree in a window.
2306 If LIMIT is non-nil, it should be a number specifying the maximum
2307 number of revisions to show; the default is `vc-log-show-limit'.
2308 When called interactively with a prefix argument, prompt for LIMIT."
2309 (interactive
2310 (cond
2311 (current-prefix-arg
2312 (let ((lim (string-to-number
2313 (read-from-minibuffer
2314 "Limit display (unlimited: 0): "
2315 (format "%s" vc-log-show-limit)
2316 nil nil nil))))
2317 (when (<= lim 0) (setq lim nil))
2318 (list lim)))
2320 (list (when (> vc-log-show-limit 0) vc-log-show-limit)))))
2321 (let ((backend (vc-deduce-backend))
2322 (default-directory default-directory)
2323 rootdir working-revision)
2324 (if backend
2325 (setq rootdir (vc-call-backend backend 'root default-directory))
2326 (setq rootdir (read-directory-name "Directory for VC root-log: "))
2327 (setq backend (vc-responsible-backend rootdir))
2328 (unless backend
2329 (error "Directory is not version controlled")))
2330 (setq working-revision (vc-working-revision rootdir)
2331 default-directory rootdir)
2332 (vc-print-log-internal backend (list rootdir) working-revision nil limit)))
2334 ;;;###autoload
2335 (defun vc-log-incoming (&optional remote-location)
2336 "Show a log of changes that will be received with a pull operation from REMOTE-LOCATION.
2337 When called interactively with a prefix argument, prompt for REMOTE-LOCATION."
2338 (interactive
2339 (when current-prefix-arg
2340 (list (read-string "Remote location (empty for default): "))))
2341 (let ((backend (vc-deduce-backend)))
2342 (unless backend
2343 (error "Buffer is not version controlled"))
2344 (vc-incoming-outgoing-internal backend remote-location "*vc-incoming*"
2345 'log-incoming)))
2347 ;;;###autoload
2348 (defun vc-log-outgoing (&optional remote-location)
2349 "Show a log of changes that will be sent with a push operation to REMOTE-LOCATION.
2350 When called interactively with a prefix argument, prompt for REMOTE-LOCATION."
2351 (interactive
2352 (when current-prefix-arg
2353 (list (read-string "Remote location (empty for default): "))))
2354 (let ((backend (vc-deduce-backend)))
2355 (unless backend
2356 (error "Buffer is not version controlled"))
2357 (vc-incoming-outgoing-internal backend remote-location "*vc-outgoing*"
2358 'log-outgoing)))
2360 ;;;###autoload
2361 (defun vc-region-history (from to)
2362 "Show the history of the region FROM..TO."
2363 (interactive "r")
2364 (let* ((lfrom (line-number-at-pos from))
2365 (lto (line-number-at-pos to))
2366 (file buffer-file-name)
2367 (backend (vc-backend file))
2368 (buf (get-buffer-create "*VC-history*")))
2369 (with-current-buffer buf
2370 (setq-local vc-log-view-type 'long))
2371 (vc-call region-history file buf lfrom lto)
2372 (with-current-buffer buf
2373 (vc-call-backend backend 'region-history-mode)
2374 (set (make-local-variable 'log-view-vc-backend) backend)
2375 (set (make-local-variable 'log-view-vc-fileset) file)
2376 (set (make-local-variable 'revert-buffer-function)
2377 (lambda (_ignore-auto _noconfirm)
2378 (with-current-buffer buf
2379 (let ((inhibit-read-only t)) (erase-buffer)))
2380 (vc-call region-history file buf lfrom lto))))
2381 (display-buffer buf)))
2383 ;;;###autoload
2384 (defun vc-revert ()
2385 "Revert working copies of the selected fileset to their repository contents.
2386 This asks for confirmation if the buffer contents are not identical
2387 to the working revision (except for keyword expansion)."
2388 (interactive)
2389 (let* ((vc-fileset (vc-deduce-fileset))
2390 (files (cadr vc-fileset))
2391 (queried nil)
2392 diff-buffer)
2393 ;; If any of the files is visited by the current buffer, make sure
2394 ;; buffer is saved. If the user says `no', abort since we cannot
2395 ;; show the changes and ask for confirmation to discard them.
2396 (when (or (not files) (memq (buffer-file-name) files))
2397 (vc-buffer-sync nil))
2398 (dolist (file files)
2399 (let ((buf (get-file-buffer file)))
2400 (when (and buf (buffer-modified-p buf))
2401 (error "Please kill or save all modified buffers before reverting")))
2402 (when (vc-up-to-date-p file)
2403 (if (yes-or-no-p (format "%s seems up-to-date. Revert anyway? " file))
2404 (setq queried t)
2405 (error "Revert canceled"))))
2406 (unwind-protect
2407 (when (if vc-revert-show-diff
2408 (progn
2409 (setq diff-buffer (generate-new-buffer-name "*vc-diff*"))
2410 (vc-diff-internal vc-allow-async-revert vc-fileset
2411 nil nil nil diff-buffer))
2412 ;; Avoid querying the user again.
2413 (null queried))
2414 (unless (yes-or-no-p
2415 (format "Discard changes in %s? "
2416 (let ((str (vc-delistify files))
2417 (nfiles (length files)))
2418 (if (< (length str) 50)
2420 (format "%d file%s" nfiles
2421 (if (= nfiles 1) "" "s"))))))
2422 (error "Revert canceled")))
2423 (when diff-buffer
2424 (quit-windows-on diff-buffer)))
2425 (dolist (file files)
2426 (message "Reverting %s..." (vc-delistify files))
2427 (vc-revert-file file)
2428 (message "Reverting %s...done" (vc-delistify files)))))
2430 ;;;###autoload
2431 (defun vc-rollback ()
2432 "Roll back (remove) the most recent changeset committed to the repository.
2433 This may be either a file-level or a repository-level operation,
2434 depending on the underlying version-control system."
2435 (interactive)
2436 (let* ((vc-fileset (vc-deduce-fileset))
2437 (backend (car vc-fileset))
2438 (files (cadr vc-fileset))
2439 (granularity (vc-call-backend backend 'revision-granularity)))
2440 (unless (vc-find-backend-function backend 'rollback)
2441 (error "Rollback is not supported in %s" backend))
2442 (when (and (not (eq granularity 'repository)) (/= (length files) 1))
2443 (error "Rollback requires a singleton fileset or repository versioning"))
2444 ;; FIXME: latest-on-branch-p should take the fileset.
2445 (when (not (vc-call-backend backend 'latest-on-branch-p (car files)))
2446 (error "Rollback is only possible at the tip revision"))
2447 ;; If any of the files is visited by the current buffer, make
2448 ;; sure buffer is saved. If the user says `no', abort since
2449 ;; we cannot show the changes and ask for confirmation to
2450 ;; discard them.
2451 (when (or (not files) (memq (buffer-file-name) files))
2452 (vc-buffer-sync nil))
2453 (dolist (file files)
2454 (when (buffer-modified-p (get-file-buffer file))
2455 (error "Please kill or save all modified buffers before rollback"))
2456 (when (not (vc-up-to-date-p file))
2457 (error "Please revert all modified workfiles before rollback")))
2458 ;; Accumulate changes associated with the fileset
2459 (vc-setup-buffer "*vc-diff*")
2460 (set-buffer-modified-p nil)
2461 (message "Finding changes...")
2462 (let* ((tip (vc-working-revision (car files)))
2463 ;; FIXME: `previous-revision' should take the fileset.
2464 (previous (vc-call-backend backend 'previous-revision
2465 (car files) tip)))
2466 (vc-diff-internal nil vc-fileset previous tip))
2467 ;; Display changes
2468 (unless (yes-or-no-p "Discard these revisions? ")
2469 (error "Rollback canceled"))
2470 (quit-windows-on "*vc-diff*")
2471 ;; Do the actual reversions
2472 (message "Rolling back %s..." (vc-delistify files))
2473 (with-vc-properties
2474 files
2475 (vc-call-backend backend 'rollback files)
2476 `((vc-state . ,'up-to-date)
2477 (vc-checkout-time . , (nth 5 (file-attributes file)))
2478 (vc-working-revision . nil)))
2479 (dolist (f files) (vc-resynch-buffer f t t))
2480 (message "Rolling back %s...done" (vc-delistify files))))
2482 ;;;###autoload
2483 (define-obsolete-function-alias 'vc-revert-buffer 'vc-revert "23.1")
2485 ;;;###autoload
2486 (defun vc-pull (&optional arg)
2487 "Update the current fileset or branch.
2488 You must be visiting a version controlled file, or in a `vc-dir' buffer.
2489 On a distributed version control system, this runs a \"pull\"
2490 operation to update the current branch, prompting for an argument
2491 list if required. Optional prefix ARG forces a prompt.
2493 On a non-distributed version control system, update the current
2494 fileset to the tip revisions. For each unchanged and unlocked
2495 file, this simply replaces the work file with the latest revision
2496 on its branch. If the file contains changes, any changes in the
2497 tip revision are merged into the working file."
2498 (interactive "P")
2499 (let* ((vc-fileset (vc-deduce-fileset t))
2500 (backend (car vc-fileset))
2501 (files (cadr vc-fileset)))
2502 (cond
2503 ;; If a pull operation is defined, use it.
2504 ((vc-find-backend-function backend 'pull)
2505 (vc-call-backend backend 'pull arg))
2506 ;; If VCS has `merge-news' functionality (CVS and SVN), use it.
2507 ((vc-find-backend-function backend 'merge-news)
2508 (save-some-buffers ; save buffers visiting files
2509 nil (lambda ()
2510 (and (buffer-modified-p)
2511 (let ((file (buffer-file-name)))
2512 (and file (member file files))))))
2513 (dolist (file files)
2514 (if (vc-up-to-date-p file)
2515 (vc-checkout file t)
2516 (vc-maybe-resolve-conflicts
2517 file (vc-call-backend backend 'merge-news file)))))
2518 ;; For a locking VCS, check out each file.
2519 ((eq (vc-checkout-model backend files) 'locking)
2520 (dolist (file files)
2521 (if (vc-up-to-date-p file)
2522 (vc-checkout file t))))
2524 (error "VC update is unsupported for `%s'" backend)))))
2526 ;;;###autoload
2527 (defalias 'vc-update 'vc-pull)
2529 (defun vc-version-backup-file (file &optional rev)
2530 "Return name of backup file for revision REV of FILE.
2531 If version backups should be used for FILE, and there exists
2532 such a backup for REV or the working revision of file, return
2533 its name; otherwise return nil."
2534 (when (vc-call make-version-backups-p file)
2535 (let ((backup-file (vc-version-backup-file-name file rev)))
2536 (if (file-exists-p backup-file)
2537 backup-file
2538 ;; there is no automatic backup, but maybe the user made one manually
2539 (setq backup-file (vc-version-backup-file-name file rev 'manual))
2540 (when (file-exists-p backup-file)
2541 backup-file)))))
2543 (defun vc-revert-file (file)
2544 "Revert FILE back to the repository working revision it was based on."
2545 (with-vc-properties
2546 (list file)
2547 (let ((backup-file (vc-version-backup-file file)))
2548 (when backup-file
2549 (copy-file backup-file file 'ok-if-already-exists)
2550 (vc-delete-automatic-version-backups file))
2551 (vc-call revert file backup-file))
2552 `((vc-state . up-to-date)
2553 (vc-checkout-time . ,(nth 5 (file-attributes file)))))
2554 (vc-resynch-buffer file t t))
2556 ;;;###autoload
2557 (defun vc-switch-backend (file backend)
2558 "Make BACKEND the current version control system for FILE.
2559 FILE must already be registered in BACKEND. The change is not
2560 permanent, only for the current session. This function only changes
2561 VC's perspective on FILE, it does not register or unregister it.
2562 By default, this command cycles through the registered backends.
2563 To get a prompt, use a prefix argument."
2564 (interactive
2565 (list
2566 (or buffer-file-name
2567 (error "There is no version-controlled file in this buffer"))
2568 (let ((crt-bk (vc-backend buffer-file-name))
2569 (backends nil))
2570 (unless crt-bk
2571 (error "File %s is not under version control" buffer-file-name))
2572 ;; Find the registered backends.
2573 (dolist (crt vc-handled-backends)
2574 (when (and (vc-call-backend crt 'registered buffer-file-name)
2575 (not (eq crt-bk crt)))
2576 (push crt backends)))
2577 ;; Find the next backend.
2578 (let ((def (car backends))
2579 (others backends))
2580 (cond
2581 ((null others) (error "No other backend to switch to"))
2582 (current-prefix-arg
2583 (intern
2584 (upcase
2585 (completing-read
2586 (format "Switch to backend [%s]: " def)
2587 (mapcar (lambda (b) (list (downcase (symbol-name b)))) backends)
2588 nil t nil nil (downcase (symbol-name def))))))
2589 (t def))))))
2590 (unless (eq backend (vc-backend file))
2591 (vc-file-clearprops file)
2592 (vc-file-setprop file 'vc-backend backend)
2593 ;; Force recomputation of the state
2594 (unless (vc-call-backend backend 'registered file)
2595 (vc-file-clearprops file)
2596 (error "%s is not registered in %s" file backend))
2597 (vc-mode-line file)))
2599 ;;;###autoload
2600 (defun vc-transfer-file (file new-backend)
2601 "Transfer FILE to another version control system NEW-BACKEND.
2602 If NEW-BACKEND has a higher precedence than FILE's current backend
2603 \(i.e. it comes earlier in `vc-handled-backends'), then register FILE in
2604 NEW-BACKEND, using the revision number from the current backend as the
2605 base level. If NEW-BACKEND has a lower precedence than the current
2606 backend, then commit all changes that were made under the current
2607 backend to NEW-BACKEND, and unregister FILE from the current backend.
2608 \(If FILE is not yet registered under NEW-BACKEND, register it.)"
2609 (let* ((old-backend (vc-backend file))
2610 (edited (memq (vc-state file) '(edited needs-merge)))
2611 (registered (vc-call-backend new-backend 'registered file))
2612 (move
2613 (and registered ; Never move if not registered in new-backend yet.
2614 ;; move if new-backend comes later in vc-handled-backends
2615 (or (memq new-backend (memq old-backend vc-handled-backends))
2616 (y-or-n-p "Final transfer? "))))
2617 (comment nil))
2618 (when (eq old-backend new-backend)
2619 (error "%s is the current backend of %s" new-backend file))
2620 (if registered
2621 (set-file-modes file (logior (file-modes file) 128))
2622 ;; `registered' might have switched under us.
2623 (vc-switch-backend file old-backend)
2624 (let* ((rev (vc-working-revision file))
2625 (modified-file (and edited (make-temp-file file)))
2626 (unmodified-file (and modified-file (vc-version-backup-file file))))
2627 ;; Go back to the base unmodified file.
2628 (unwind-protect
2629 (progn
2630 (when modified-file
2631 (copy-file file modified-file 'ok-if-already-exists)
2632 ;; If we have a local copy of the unmodified file, handle that
2633 ;; here and not in vc-revert-file because we don't want to
2634 ;; delete that copy -- it is still useful for OLD-BACKEND.
2635 (if unmodified-file
2636 (copy-file unmodified-file file
2637 'ok-if-already-exists 'keep-date)
2638 (when (y-or-n-p "Get base revision from repository? ")
2639 (vc-revert-file file))))
2640 (vc-call-backend new-backend 'receive-file file rev))
2641 (when modified-file
2642 (vc-switch-backend file new-backend)
2643 (unless (eq (vc-checkout-model new-backend (list file)) 'implicit)
2644 (vc-checkout file))
2645 (rename-file modified-file file 'ok-if-already-exists)
2646 (vc-file-setprop file 'vc-checkout-time nil)))))
2647 (when move
2648 (vc-switch-backend file old-backend)
2649 (setq comment (vc-call-backend old-backend 'comment-history file))
2650 (vc-call-backend old-backend 'unregister file))
2651 (vc-switch-backend file new-backend)
2652 (when (or move edited)
2653 (vc-file-setprop file 'vc-state 'edited)
2654 (vc-mode-line file new-backend)
2655 (vc-checkin file new-backend comment (stringp comment)))))
2657 ;;;###autoload
2658 (defun vc-delete-file (file)
2659 "Delete file and mark it as such in the version control system.
2660 If called interactively, read FILE, defaulting to the current
2661 buffer's file name if it's under version control."
2662 (interactive (list (read-file-name "VC delete file: " nil
2663 (when (vc-backend buffer-file-name)
2664 buffer-file-name) t)))
2665 (setq file (expand-file-name file))
2666 (let ((buf (get-file-buffer file))
2667 (backend (vc-backend file)))
2668 (unless backend
2669 (error "File %s is not under version control"
2670 (file-name-nondirectory file)))
2671 (unless (vc-find-backend-function backend 'delete-file)
2672 (error "Deleting files under %s is not supported in VC" backend))
2673 (when (and buf (buffer-modified-p buf))
2674 (error "Please save or undo your changes before deleting %s" file))
2675 (let ((state (vc-state file)))
2676 (when (eq state 'edited)
2677 (error "Please commit or undo your changes before deleting %s" file))
2678 (when (eq state 'conflict)
2679 (error "Please resolve the conflicts before deleting %s" file)))
2680 (unless (y-or-n-p (format "Really want to delete %s? "
2681 (file-name-nondirectory file)))
2682 (error "Abort!"))
2683 (unless (or (file-directory-p file) (null make-backup-files)
2684 (not (file-exists-p file)))
2685 (with-current-buffer (or buf (find-file-noselect file))
2686 (let ((backup-inhibited nil))
2687 (backup-buffer))))
2688 ;; Bind `default-directory' so that the command that the backend
2689 ;; runs to remove the file is invoked in the correct context.
2690 (let ((default-directory (file-name-directory file)))
2691 (vc-call-backend backend 'delete-file file))
2692 ;; If the backend hasn't deleted the file itself, let's do it for him.
2693 (when (file-exists-p file) (delete-file file))
2694 ;; Forget what VC knew about the file.
2695 (vc-file-clearprops file)
2696 ;; Make sure the buffer is deleted and the *vc-dir* buffers are
2697 ;; updated after this.
2698 (vc-resynch-buffer file nil t)))
2700 ;;;###autoload
2701 (defun vc-rename-file (old new)
2702 "Rename file OLD to NEW in both work area and repository.
2703 If called interactively, read OLD and NEW, defaulting OLD to the
2704 current buffer's file name if it's under version control."
2705 (interactive (list (read-file-name "VC rename file: " nil
2706 (when (vc-backend buffer-file-name)
2707 buffer-file-name) t)
2708 (read-file-name "Rename to: ")))
2709 ;; in CL I would have said (setq new (merge-pathnames new old))
2710 (let ((old-base (file-name-nondirectory old)))
2711 (when (and (not (string= "" old-base))
2712 (string= "" (file-name-nondirectory new)))
2713 (setq new (concat new old-base))))
2714 (let ((oldbuf (get-file-buffer old)))
2715 (when (and oldbuf (buffer-modified-p oldbuf))
2716 (error "Please save files before moving them"))
2717 (when (get-file-buffer new)
2718 (error "Already editing new file name"))
2719 (when (file-exists-p new)
2720 (error "New file already exists"))
2721 (let ((state (vc-state old)))
2722 (unless (memq state '(up-to-date edited))
2723 (error "Please %s files before moving them"
2724 (if (stringp state) "check in" "update"))))
2725 (vc-call rename-file old new)
2726 (vc-file-clearprops old)
2727 ;; Move the actual file (unless the backend did it already)
2728 (when (file-exists-p old) (rename-file old new))
2729 ;; ?? Renaming a file might change its contents due to keyword expansion.
2730 ;; We should really check out a new copy if the old copy was precisely equal
2731 ;; to some checked-in revision. However, testing for this is tricky....
2732 (when oldbuf
2733 (with-current-buffer oldbuf
2734 (let ((buffer-read-only buffer-read-only))
2735 (set-visited-file-name new))
2736 (vc-mode-line new (vc-backend new))
2737 (set-buffer-modified-p nil)))))
2739 ;;;###autoload
2740 (defun vc-update-change-log (&rest args)
2741 "Find change log file and add entries from recent version control logs.
2742 Normally, find log entries for all registered files in the default
2743 directory.
2745 With prefix arg of \\[universal-argument], only find log entries for the current buffer's file.
2747 With any numeric prefix arg, find log entries for all currently visited
2748 files that are under version control. This puts all the entries in the
2749 log for the default directory, which may not be appropriate.
2751 From a program, any ARGS are assumed to be filenames for which
2752 log entries should be gathered."
2753 (interactive
2754 (cond ((consp current-prefix-arg) ;C-u
2755 (list buffer-file-name))
2756 (current-prefix-arg ;Numeric argument.
2757 (let ((files nil))
2758 (dolist (buffer (buffer-list))
2759 (let ((file (buffer-file-name buffer)))
2760 (and file (vc-backend file)
2761 (setq files (cons file files)))))
2762 files))
2764 ;; Don't supply any filenames to backend; this means
2765 ;; it should find all relevant files relative to
2766 ;; the default-directory.
2767 nil)))
2768 (vc-call-backend (vc-responsible-backend default-directory)
2769 'update-changelog args))
2771 ;; functions that operate on RCS revision numbers. This code should
2772 ;; also be moved into the backends. It stays for now, however, since
2773 ;; it is used in code below.
2774 (defun vc-branch-p (rev)
2775 "Return t if REV is a branch revision."
2776 (not (eq nil (string-match "\\`[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*\\'" rev))))
2778 ;;;###autoload
2779 (defun vc-branch-part (rev)
2780 "Return the branch part of a revision number REV."
2781 (let ((index (string-match "\\.[0-9]+\\'" rev)))
2782 (when index
2783 (substring rev 0 index))))
2785 (defun vc-default-responsible-p (_backend _file)
2786 "Indicate whether BACKEND is responsible for FILE.
2787 The default is to return nil always."
2788 nil)
2790 (defun vc-default-latest-on-branch-p (_backend _file)
2791 "Return non-nil if FILE is the latest on its branch.
2792 This default implementation always returns non-nil, which means that
2793 editing non-current revisions is not supported by default."
2796 (defun vc-default-find-revision (backend file rev buffer)
2797 "Provide the new `find-revision' op based on the old `checkout' op.
2798 This is only for compatibility with old backends. They should be updated
2799 to provide the `find-revision' operation instead."
2800 (let ((tmpfile (make-temp-file (expand-file-name file))))
2801 (unwind-protect
2802 (progn
2803 (vc-call-backend backend 'checkout file nil rev tmpfile)
2804 (with-current-buffer buffer
2805 (insert-file-contents-literally tmpfile)))
2806 (delete-file tmpfile))))
2808 (defun vc-default-rename-file (_backend old new)
2809 (condition-case nil
2810 (add-name-to-file old new)
2811 (error (rename-file old new)))
2812 (vc-delete-file old)
2813 (with-current-buffer (find-file-noselect new)
2814 (vc-register)))
2816 (defalias 'vc-default-check-headers 'ignore)
2818 (declare-function log-edit-mode "log-edit" ())
2820 (defun vc-default-log-edit-mode (_backend) (log-edit-mode))
2822 (defun vc-default-log-view-mode (_backend) (log-view-mode))
2824 (defun vc-default-show-log-entry (_backend rev)
2825 (with-no-warnings
2826 (log-view-goto-rev rev)))
2828 (defun vc-default-comment-history (backend file)
2829 "Return a string with all log entries stored in BACKEND for FILE."
2830 (when (vc-find-backend-function backend 'print-log)
2831 (with-current-buffer "*vc*"
2832 (vc-call-backend backend 'print-log (list file))
2833 (buffer-string))))
2835 (defun vc-default-receive-file (backend file rev)
2836 "Let BACKEND receive FILE from another version control system."
2837 (vc-call-backend backend 'register (list file) rev ""))
2839 (defun vc-default-retrieve-tag (backend dir name update)
2840 (if (string= name "")
2841 (progn
2842 (vc-file-tree-walk
2844 (lambda (f) (and
2845 (vc-up-to-date-p f)
2846 (vc-error-occurred
2847 (vc-call-backend backend 'checkout f nil "")
2848 (when update (vc-resynch-buffer f t t)))))))
2849 (let ((result (vc-tag-precondition dir)))
2850 (if (stringp result)
2851 (error "File %s is locked" result)
2852 (setq update (and (eq result 'visited) update))
2853 (vc-file-tree-walk
2855 (lambda (f) (vc-error-occurred
2856 (vc-call-backend backend 'checkout f nil name)
2857 (when update (vc-resynch-buffer f t t)))))))))
2859 (defun vc-default-revert (backend file contents-done)
2860 (unless contents-done
2861 (let ((rev (vc-working-revision file))
2862 (file-buffer (or (get-file-buffer file) (current-buffer))))
2863 (message "Checking out %s..." file)
2864 (let ((failed t)
2865 (backup-name (car (find-backup-file-name file))))
2866 (when backup-name
2867 (copy-file file backup-name 'ok-if-already-exists 'keep-date)
2868 (unless (file-writable-p file)
2869 (set-file-modes file (logior (file-modes file) 128))))
2870 (unwind-protect
2871 (let ((coding-system-for-read 'no-conversion)
2872 (coding-system-for-write 'no-conversion))
2873 (with-temp-file file
2874 (let ((outbuf (current-buffer)))
2875 ;; Change buffer to get local value of vc-checkout-switches.
2876 (with-current-buffer file-buffer
2877 (let ((default-directory (file-name-directory file)))
2878 (vc-call-backend backend 'find-revision
2879 file rev outbuf)))))
2880 (setq failed nil))
2881 (when backup-name
2882 (if failed
2883 (rename-file backup-name file 'ok-if-already-exists)
2884 (and (not vc-make-backup-files) (delete-file backup-name))))))
2885 (message "Checking out %s...done" file))))
2887 (defalias 'vc-default-revision-completion-table 'ignore)
2888 (defalias 'vc-default-mark-resolved 'ignore)
2890 (defun vc-default-dir-status-files (_backend _dir files update-function)
2891 (funcall update-function
2892 (mapcar (lambda (file) (list file 'up-to-date)) files)))
2894 (defun vc-check-headers ()
2895 "Check if the current file has any headers in it."
2896 (interactive)
2897 (vc-call-backend (vc-backend buffer-file-name) 'check-headers))
2901 ;; These things should probably be generally available
2902 (define-obsolete-function-alias 'vc-string-prefix-p 'string-prefix-p "24.3")
2904 (defun vc-file-tree-walk (dirname func &rest args)
2905 "Walk recursively through DIRNAME.
2906 Invoke FUNC f ARGS on each VC-managed file f underneath it."
2907 (vc-file-tree-walk-internal (expand-file-name dirname) func args)
2908 (message "Traversing directory %s...done" dirname))
2910 (defun vc-file-tree-walk-internal (file func args)
2911 (if (not (file-directory-p file))
2912 (when (vc-backend file) (apply func file args))
2913 (message "Traversing directory %s..." (abbreviate-file-name file))
2914 (let ((dir (file-name-as-directory file)))
2915 (mapcar
2916 (lambda (f) (or
2917 (string-equal f ".")
2918 (string-equal f "..")
2919 (member f vc-directory-exclusion-list)
2920 (let ((dirf (expand-file-name f dir)))
2922 (file-symlink-p dirf) ;; Avoid possible loops.
2923 (vc-file-tree-walk-internal dirf func args)))))
2924 (directory-files dir)))))
2926 (provide 'vc)
2928 ;;; vc.el ends here