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