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