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