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