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