1 ;;; vc.el --- drive a version-control system from within Emacs
3 ;; Copyright (C) 1992,93,94,95,96,97,98,2000,2001 Free Software Foundation, Inc.
5 ;; Author: FSF (see below for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
9 ;; $Id: vc.el,v 1.332 2002/07/16 17:47:33 spiegel Exp $
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
30 ;; VC was initially designed and implemented by Eric S. Raymond
31 ;; <esr@snark.thyrsus.com>. Over the years, many people have
32 ;; contributed substantial amounts of work to VC. These include:
33 ;; Per Cederqvist <ceder@lysator.liu.se>
34 ;; Paul Eggert <eggert@twinsun.com>
35 ;; Sebastian Kremer <sk@thp.uni-koeln.de>
36 ;; Martin Lorentzson <martinl@gnu.org>
37 ;; Dave Love <fx@gnu.org>
38 ;; Stefan Monnier <monnier@cs.yale.edu>
39 ;; J.D. Smith <jdsmith@alum.mit.edu>
40 ;; Andre Spiegel <spiegel@gnu.org>
41 ;; Richard Stallman <rms@gnu.org>
42 ;; Thien-Thi Nguyen <ttn@gnu.org>
46 ;; This mode is fully documented in the Emacs user's manual.
48 ;; Supported version-control systems presently include SCCS, RCS, and CVS.
50 ;; Some features will not work with old RCS versions. Where
51 ;; appropriate, VC finds out which version you have, and allows or
52 ;; disallows those features (stealing locks, for example, works only
53 ;; from 5.6.2 onwards).
54 ;; Even initial checkins will fail if your RCS version is so old that ci
55 ;; doesn't understand -t-; this has been known to happen to people running
58 ;; You can support the RCS -x option by customizing vc-rcs-master-templates.
60 ;; Proper function of the SCCS diff commands requires the shellscript vcdiff
61 ;; to be installed somewhere on Emacs's path for executables.
63 ;; If your site uses the ChangeLog convention supported by Emacs, the
64 ;; function vc-comment-to-change-log should prove a useful checkin hook.
66 ;; The vc code maintains some internal state in order to reduce expensive
67 ;; version-control operations to a minimum. Some names are only computed
68 ;; once. If you perform version control operations with RCS/SCCS/CVS while
69 ;; vc's back is turned, or move/rename master files while vc is running,
70 ;; vc may get seriously confused. Don't do these things!
72 ;; Developer's notes on some concurrency issues are included at the end of
75 ;; ADDING SUPPORT FOR OTHER BACKENDS
77 ;; VC can use arbitrary version control systems as a backend. To add
78 ;; support for a new backend named SYS, write a library vc-sys.el that
79 ;; contains functions of the form `vc-sys-...' (note that SYS is in lower
80 ;; case for the function and library names). VC will use that library if
81 ;; you put the symbol SYS somewhere into the list of
82 ;; `vc-handled-backends'. Then, for example, if `vc-sys-registered'
83 ;; returns non-nil for a file, all SYS-specific versions of VC commands
84 ;; will be available for that file.
86 ;; VC keeps some per-file information in the form of properties (see
87 ;; vc-file-set/getprop in vc-hooks.el). The backend-specific functions
88 ;; do not generally need to be aware of these properties. For example,
89 ;; `vc-sys-workfile-version' should compute the workfile version and
90 ;; return it; it should not look it up in the property, and it needn't
91 ;; store it there either. However, if a backend-specific function does
92 ;; store a value in a property, that value takes precedence over any
93 ;; value that the generic code might want to set (check for uses of
94 ;; the macro `with-vc-properties' in vc.el).
96 ;; In the list of functions below, each identifier needs to be prepended
97 ;; with `vc-sys-'. Some of the functions are mandatory (marked with a
98 ;; `*'), others are optional (`-').
100 ;; STATE-QUERYING FUNCTIONS
102 ;; * registered (file)
104 ;; Return non-nil if FILE is registered in this backend.
108 ;; Return the current version control state of FILE. For a list of
109 ;; possible values, see `vc-state'. This function should do a full and
110 ;; reliable state computation; it is usually called immediately after
111 ;; C-x v v. If you want to use a faster heuristic when visiting a
112 ;; file, put that into `state-heuristic' below.
114 ;; - state-heuristic (file)
116 ;; If provided, this function is used to estimate the version control
117 ;; state of FILE at visiting time. It should be considerably faster
118 ;; than the implementation of `state'. For a list of possible values,
119 ;; see the doc string of `vc-state'.
123 ;; If provided, this function is used to find the version control state
124 ;; of all files in DIR in a fast way. The function should not return
125 ;; anything, but rather store the files' states into the corresponding
126 ;; `vc-state' properties.
128 ;; * workfile-version (file)
130 ;; Return the current workfile version of FILE.
132 ;; - latest-on-branch-p (file)
134 ;; Return non-nil if the current workfile version of FILE is the latest
135 ;; on its branch. The default implementation always returns t, which
136 ;; means that working with non-current versions is not supported by
139 ;; * checkout-model (file)
141 ;; Indicate whether FILE needs to be "checked out" before it can be
142 ;; edited. See `vc-checkout-model' for a list of possible values.
144 ;; - workfile-unchanged-p (file)
146 ;; Return non-nil if FILE is unchanged from its current workfile
147 ;; version. This function should do a brief comparison of FILE's
148 ;; contents with those of the master version. If the backend does not
149 ;; have such a brief-comparison feature, the default implementation of
150 ;; this function can be used, which delegates to a full
153 ;; - mode-line-string (file)
155 ;; If provided, this function should return the VC-specific mode line
156 ;; string for FILE. The default implementation deals well with all
157 ;; states that `vc-state' can return.
159 ;; - dired-state-info (file)
161 ;; Translate the `vc-state' property of FILE into a string that can be
162 ;; used in a vc-dired buffer. The default implementation deals well
163 ;; with all states that `vc-state' can return.
165 ;; STATE-CHANGING FUNCTIONS
167 ;; * register (file &optional rev comment)
169 ;; Register FILE in this backend. Optionally, an initial revision REV
170 ;; and an initial description of the file, COMMENT, may be specified.
171 ;; The implementation should pass the value of vc-register-switches
172 ;; to the backend command.
174 ;; - init-version (file)
176 ;; The initial version to use when registering FILE if one is not
177 ;; specified by the user. If not provided, the variable
178 ;; vc-default-init-version is used instead.
180 ;; - responsible-p (file)
182 ;; Return non-nil if this backend considers itself "responsible" for
183 ;; FILE, which can also be a directory. This function is used to find
184 ;; out what backend to use for registration of new files and for things
185 ;; like change log generation. The default implementation always
188 ;; - could-register (file)
190 ;; Return non-nil if FILE could be registered under this backend. The
191 ;; default implementation always returns t.
193 ;; - receive-file (file rev)
195 ;; Let this backend "receive" a file that is already registered under
196 ;; another backend. The default implementation simply calls `register'
197 ;; for FILE, but it can be overridden to do something more specific,
198 ;; e.g. keep revision numbers consistent or choose editing modes for
199 ;; FILE that resemble those of the other backend.
201 ;; - unregister (file)
203 ;; Unregister FILE from this backend. This is only needed if this
204 ;; backend may be used as a "more local" backend for temporary editing.
206 ;; * checkin (file rev comment)
208 ;; Commit changes in FILE to this backend. If REV is non-nil, that
209 ;; should become the new revision number. COMMENT is used as a
210 ;; check-in comment. The implementation should pass the value of
211 ;; vc-checkin-switches to the backend command.
213 ;; * checkout (file &optional editable rev destfile)
215 ;; Check out revision REV of FILE into the working area. If EDITABLE
216 ;; is non-nil, FILE should be writable by the user and if locking is
217 ;; used for FILE, a lock should also be set. If REV is non-nil, that
218 ;; is the revision to check out (default is current workfile version);
219 ;; if REV is the empty string, that means to check out the head of the
220 ;; trunk. If optional arg DESTFILE is given, it is an alternate
221 ;; filename to write the contents to. The implementation should
222 ;; pass the value of vc-checkout-switches to the backend command.
224 ;; * revert (file &optional contents-done)
226 ;; Revert FILE back to the current workfile version. If optional
227 ;; arg CONTENTS-DONE is non-nil, then the contents of FILE have
228 ;; already been reverted from a version backup, and this function
229 ;; only needs to update the status of FILE within the backend.
231 ;; - cancel-version (file editable)
233 ;; Cancel the current workfile version of FILE, i.e. remove it from the
234 ;; master. EDITABLE non-nil means that FILE should be writable
235 ;; afterwards, and if locking is used for FILE, then a lock should also
236 ;; be set. If this function is not provided, trying to cancel a
237 ;; version is caught as an error.
239 ;; - merge (file rev1 rev2)
241 ;; Merge the changes between REV1 and REV2 into the current working file.
243 ;; - merge-news (file)
245 ;; Merge recent changes from the current branch into FILE.
247 ;; - steal-lock (file &optional version)
249 ;; Steal any lock on the current workfile version of FILE, or on
250 ;; VERSION if that is provided. This function is only needed if
251 ;; locking is used for files under this backend, and if files can
252 ;; indeed be locked by other users.
256 ;; * print-log (file)
258 ;; Insert the revision log of FILE into the *vc* buffer.
260 ;; - show-log-entry (version)
262 ;; If provided, search the log entry for VERSION in the current buffer,
263 ;; and make sure it is displayed in the buffer's window. The default
264 ;; implementation of this function works for RCS-style logs.
268 ;; Remove all non-comment information from the output of print-log. The
269 ;; default implementation of this function works for RCS-style logs.
271 ;; - logentry-check ()
273 ;; If defined, this function is run to find out whether the user
274 ;; entered a valid log entry for check-in. The log entry is in the
275 ;; current buffer, and if it is not a valid one, the function should
278 ;; - comment-history (file)
280 ;; Return a string containing all log entries that were made for FILE.
281 ;; This is used for transferring a file from one backend to another,
282 ;; retaining comment information. The default implementation of this
283 ;; function does this by calling print-log and then wash-log, and
284 ;; returning the resulting buffer contents as a string.
286 ;; - update-changelog (files)
288 ;; Using recent log entries, create ChangeLog entries for FILES, or for
289 ;; all files at or below the default-directory if FILES is nil. The
290 ;; default implementation runs rcs2log, which handles RCS- and
293 ;; * diff (file &optional rev1 rev2)
295 ;; Insert the diff for FILE into the *vc-diff* buffer. If REV1 and
296 ;; REV2 are non-nil, report differences from REV1 to REV2. If REV1
297 ;; is nil, use the current workfile version (as found in the
298 ;; repository) as the older version; if REV2 is nil, use the current
299 ;; workfile contents as the newer version. This function should
300 ;; pass the value of (vc-diff-switches-list BACKEND) to the backend
301 ;; command. It should return a status of either 0 (no differences
302 ;; found), or 1 (either non-empty diff or the diff is run
305 ;; - diff-tree (dir &optional rev1 rev2)
307 ;; Insert the diff for all files at and below DIR into the *vc-diff*
308 ;; buffer. The meaning of REV1 and REV2 is the same as for
309 ;; vc-BACKEND-diff. The default implementation does an explicit tree
310 ;; walk, calling vc-BACKEND-diff for each individual file.
312 ;; - annotate-command (file buf rev)
314 ;; If this function is provided, it should produce an annotated version
315 ;; of FILE in BUF, relative to version REV. This is currently only
316 ;; implemented for CVS, using the `cvs annotate' command.
318 ;; - annotate-time ()
320 ;; Only required if `annotate-command' is defined for the backend.
321 ;; Return the time of the next line of annotation at or after point,
322 ;; as a floating point fractional number of days. The helper
323 ;; function `vc-annotate-convert-time' may be useful for converting
324 ;; multi-part times as returned by `current-time' and `encode-time'
325 ;; to this format. Return nil if no more lines of annotation appear
326 ;; in the buffer. You can safely assume that point is placed at the
327 ;; beginning of each line, starting at `point-min'. The buffer that
328 ;; point is placed in is the Annotate output, as defined by the
331 ;; - annotate-current-time ()
333 ;; Only required if `annotate-command' is defined for the backend,
334 ;; AND you'd like the current time considered to be anything besides
335 ;; (vs-annotate-convert-time (current-time)) -- i.e. the current
336 ;; time with hours, minutes, and seconds included. Probably safe to
337 ;; ignore. Return the current-time, in units of fractional days.
341 ;; - create-snapshot (dir name branchp)
343 ;; Take a snapshot of the current state of files under DIR and name it
344 ;; NAME. This should make sure that files are up-to-date before
345 ;; proceeding with the action. DIR can also be a file and if BRANCHP
346 ;; is specified, NAME should be created as a branch and DIR should be
347 ;; checked out under this new branch. The default implementation does
348 ;; not support branches but does a sanity check, a tree traversal and
349 ;; for each file calls `assign-name'.
351 ;; - assign-name (file name)
353 ;; Give name NAME to the current version of FILE, assuming it is
354 ;; up-to-date. Only used by the default version of `create-snapshot'.
356 ;; - retrieve-snapshot (dir name update)
358 ;; Retrieve a named snapshot of all registered files at or below DIR.
359 ;; If UPDATE is non-nil, then update buffers of any files in the
360 ;; snapshot that are currently visited. The default implementation
361 ;; does a sanity check whether there aren't any uncommitted changes at
362 ;; or below DIR, and then performs a tree walk, using the `checkout'
363 ;; function to retrieve the corresponding versions.
367 ;; - make-version-backups-p (file)
369 ;; Return non-nil if unmodified repository versions of FILE should be
370 ;; backed up locally. If this is done, VC can perform `diff' and
371 ;; `revert' operations itself, without calling the backend system. The
372 ;; default implementation always returns nil.
374 ;; - previous-version (file rev)
376 ;; Return the version number that precedes REV for FILE.
378 ;; - check-headers ()
380 ;; Return non-nil if the current buffer contains any version headers.
382 ;; - clear-headers ()
384 ;; In the current buffer, reset all version headers to their unexpanded
385 ;; form. This function should be provided if the state-querying code
386 ;; for this backend uses the version headers to determine the state of
387 ;; a file. This function will then be called whenever VC changes the
388 ;; version control state in such a way that the headers would give
389 ;; wrong information.
391 ;; - rename-file (old new)
393 ;; Rename file OLD to NEW, both in the working area and in the
394 ;; repository. If this function is not provided, the command
395 ;; `vc-rename-file' will signal an error.
404 (require 'dired
) ; for dired-map-over-marks macro
405 (require 'dired-aux
)) ; for dired-kill-{line,tree}
407 (if (not (assoc 'vc-parent-buffer minor-mode-alist
))
408 (setq minor-mode-alist
409 (cons '(vc-parent-buffer vc-parent-buffer-name
)
412 ;; General customization
415 "Version-control system in Emacs."
418 (defcustom vc-suppress-confirm nil
419 "*If non-nil, treat user as expert; suppress yes-no prompts on some things."
423 (defcustom vc-delete-logbuf-window t
424 "*If non-nil, delete the *VC-log* buffer and window after each logical action.
425 If nil, bury that buffer instead.
426 This is most useful if you have multiple windows on a frame and would like to
427 preserve the setting."
431 (defcustom vc-initial-comment nil
432 "*If non-nil, prompt for initial comment when a file is registered."
436 (defcustom vc-default-init-version
"1.1"
437 "*A string used as the default version number when a new file is registered.
438 This can be overridden by giving a prefix argument to \\[vc-register]. This
439 can also be overridden by a particular VC backend."
444 (defcustom vc-command-messages nil
445 "*If non-nil, display run messages from back-end commands."
449 (defcustom vc-checkin-switches nil
450 "*A string or list of strings specifying extra switches for checkin.
451 These are passed to the checkin program by \\[vc-checkin]."
452 :type
'(choice (const :tag
"None" nil
)
453 (string :tag
"Argument String")
454 (repeat :tag
"Argument List"
459 (defcustom vc-checkout-switches nil
460 "*A string or list of strings specifying extra switches for checkout.
461 These are passed to the checkout program by \\[vc-checkout]."
462 :type
'(choice (const :tag
"None" nil
)
463 (string :tag
"Argument String")
464 (repeat :tag
"Argument List"
469 (defcustom vc-register-switches nil
470 "*A string or list of strings; extra switches for registering a file.
471 These are passed to the checkin program by \\[vc-register]."
472 :type
'(choice (const :tag
"None" nil
)
473 (string :tag
"Argument String")
474 (repeat :tag
"Argument List"
479 (defcustom vc-dired-listing-switches
"-al"
480 "*Switches passed to `ls' for vc-dired. MUST contain the `l' option."
485 (defcustom vc-dired-recurse t
486 "*If non-nil, show directory trees recursively in VC Dired."
491 (defcustom vc-dired-terse-display t
492 "*If non-nil, show only locked files in VC Dired."
497 (defcustom vc-directory-exclusion-list
'("SCCS" "RCS" "CVS")
498 "*List of directory names to be ignored when walking directory trees."
499 :type
'(repeat string
)
502 (defconst vc-maximum-comment-ring-size
32
503 "Maximum number of saved comments in the comment ring.")
505 (defcustom vc-diff-switches nil
506 "*A string or list of strings specifying switches for diff under VC.
507 When running diff under a given BACKEND, VC concatenates the values of
508 `diff-switches', `vc-diff-switches', and `vc-BACKEND-diff-switches' to
509 get the switches for that command. Thus, `vc-diff-switches' should
510 contain switches that are specific to version control, but not
511 specific to any particular backend."
512 :type
'(choice (const :tag
"None" nil
)
513 (string :tag
"Argument String")
514 (repeat :tag
"Argument List"
521 (defcustom vc-checkout-hook nil
522 "*Normal hook (list of functions) run after checking out a file.
528 (defcustom vc-annotate-display-mode nil
529 "Which mode to color the output of \\[vc-annotate] with by default."
530 :type
'(choice (const :tag
"Default" nil
)
531 (const :tag
"Scale to Oldest" scale
)
532 (const :tag
"Scale Oldest->Newest" fullscale
)
533 (number :tag
"Specify Fractional Number of Days"
538 (defcustom vc-checkin-hook nil
539 "*Normal hook (list of functions) run after a checkin is done.
542 :options
'(vc-comment-to-change-log)
546 (defcustom vc-before-checkin-hook nil
547 "*Normal hook (list of functions) run before a file is checked in.
552 (defcustom vc-logentry-check-hook nil
553 "*Normal hook run by `vc-backend-logentry-check'.
554 Use this to impose your own rules on the entry in addition to any the
555 version control backend imposes itself."
559 ;; Annotate customization
560 (defcustom vc-annotate-color-map
578 "*Association list of age versus color, for \\[vc-annotate].
579 Ages are given in units of fractional days. Default is eighteen steps
580 using a twenty day increment."
584 (defcustom vc-annotate-very-old-color
"#0046FF"
585 "*Color for lines older than the current color range in \\[vc-annotate]]."
589 (defcustom vc-annotate-background
"black"
590 "*Background color for \\[vc-annotate].
591 Default color is used if nil."
595 (defcustom vc-annotate-menu-elements
'(2 0.5 0.1 0.01)
596 "*Menu elements for the mode-specific menu of VC-Annotate mode.
597 List of factors, used to expand/compress the time scale. See `vc-annotate'."
598 :type
'(repeat number
)
601 ;; vc-annotate functionality (CVS only).
602 (defvar vc-annotate-mode nil
603 "Variable indicating if VC-Annotate mode is active.")
605 (defvar vc-annotate-mode-map
606 (let ((m (make-sparse-keymap)))
607 (define-key m
[menu-bar
] (make-sparse-keymap "VC-Annotate"))
609 "Local keymap used for VC-Annotate mode.")
611 (defvar vc-annotate-mode-menu nil
612 "Local keymap used for VC-Annotate mode's menu bar menu.")
614 ;; Header-insertion hair
616 (defcustom vc-static-header-alist
618 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
619 "*Associate static header string templates with file types.
620 A \%s in the template is replaced with the first string associated with
621 the file's version control type in `vc-header-alist'."
622 :type
'(repeat (cons :format
"%v"
623 (regexp :tag
"File Type")
624 (string :tag
"Header String")))
627 (defcustom vc-comment-alist
628 '((nroff-mode ".\\\"" ""))
629 "*Special comment delimiters for generating VC headers.
630 Add an entry in this list if you need to override the normal `comment-start'
631 and `comment-end' variables. This will only be necessary if the mode language
632 is sensitive to blank lines."
633 :type
'(repeat (list :format
"%v"
635 (string :tag
"Comment Start")
636 (string :tag
"Comment End")))
639 (defcustom vc-checkout-carefully
(= (user-uid) 0)
640 "*This variable is obsolete
641 The corresponding checks are always done now.
642 From the old doc string:
644 Non-nil means be extra-careful in checkout.
645 Verify that the file really is not locked
646 and that its contents match what the master file says."
653 ;; Initialization code, to be done just once at load-time
654 (defvar vc-log-mode-map
655 (let ((map (make-sparse-keymap)))
656 (define-key map
"\M-n" 'vc-next-comment
)
657 (define-key map
"\M-p" 'vc-previous-comment
)
658 (define-key map
"\M-r" 'vc-comment-search-reverse
)
659 (define-key map
"\M-s" 'vc-comment-search-forward
)
660 (define-key map
"\C-c\C-c" 'vc-finish-logentry
)
662 ;; Compatibility with old name. Should we bother ?
663 (defvar vc-log-entry-mode vc-log-mode-map
)
666 ;; Variables the user doesn't need to know about.
667 (defvar vc-log-operation nil
)
668 (defvar vc-log-after-operation-hook nil
)
669 (defvar vc-annotate-buffers nil
670 "Alist of current \"Annotate\" buffers and their corresponding backends.
671 The keys are \(BUFFER . BACKEND\). See also `vc-annotate-get-backend'.")
672 ;; In a log entry buffer, this is a local variable
673 ;; that points to the buffer for which it was made
674 ;; (either a file, or a VC dired buffer).
675 (defvar vc-parent-buffer nil
)
676 (put 'vc-parent-buffer
'permanent-local t
)
677 (defvar vc-parent-buffer-name nil
)
678 (put 'vc-parent-buffer-name
'permanent-local t
)
681 (defvar vc-log-version
)
683 (defvar vc-dired-mode nil
)
684 (make-variable-buffer-local 'vc-dired-mode
)
686 (defvar vc-comment-ring
(make-ring vc-maximum-comment-ring-size
))
687 (defvar vc-comment-ring-index nil
)
688 (defvar vc-last-comment-match
"")
690 ;; functions that operate on RCS revision numbers. This code should
691 ;; also be moved into the backends. It stays for now, however, since
692 ;; it is used in code below.
693 (defun vc-trunk-p (rev)
694 "Return t if REV is a revision on the trunk."
695 (not (eq nil
(string-match "\\`[0-9]+\\.[0-9]+\\'" rev
))))
697 (defun vc-branch-p (rev)
698 "Return t if REV is a branch revision."
699 (not (eq nil
(string-match "\\`[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*\\'" rev
))))
702 (defun vc-branch-part (rev)
703 "Return the branch part of a revision number REV."
704 (let ((index (string-match "\\.[0-9]+\\'" rev
)))
706 (substring rev
0 index
))))
708 (defun vc-minor-part (rev)
709 "Return the minor version number of a revision number REV."
710 (string-match "[0-9]+\\'" rev
)
711 (substring rev
(match-beginning 0) (match-end 0)))
713 (defun vc-default-previous-version (backend file rev
)
714 "Guess the version number immediately preceding REV for FILE.
715 This default implementation works for <major>.<minor>-style version numbers
716 as used by RCS and CVS."
717 (let ((branch (vc-branch-part rev
))
718 (minor-num (string-to-number (vc-minor-part rev
))))
721 ;; version does probably not start a branch or release
722 (concat branch
"." (number-to-string (1- minor-num
)))
724 ;; we are at the beginning of the trunk --
725 ;; don't know anything to return here
727 ;; we are at the beginning of a branch --
728 ;; return version of starting point
729 (vc-branch-part branch
))))))
731 ;; File property caching
733 (defun vc-clear-context ()
734 "Clear all cached file properties and the comment ring."
736 (fillarray vc-file-prop-obarray
0)
737 ;; Note: there is potential for minor lossage here if there is an open
738 ;; log buffer with a nonzero local value of vc-comment-ring-index.
739 (setq vc-comment-ring
(make-ring vc-maximum-comment-ring-size
)))
741 (defmacro with-vc-properties
(file form settings
)
742 "Execute FORM, then maybe set per-file properties for FILE.
743 SETTINGS is an association list of property/value pairs. After
744 executing FORM, set those properties from SETTINGS that have not yet
745 been updated to their corresponding values."
746 `(let ((vc-touched-properties (list t
)))
748 (mapcar (lambda (setting)
749 (let ((property (car setting
)))
750 (unless (memq property vc-touched-properties
)
751 (put (intern ,file vc-file-prop-obarray
)
752 property
(cdr setting
)))))
755 ;; Random helper functions
757 (defsubst vc-editable-p
(file)
758 "Return non-nil if FILE can be edited."
759 (or (eq (vc-checkout-model file
) 'implicit
)
760 (memq (vc-state file
) '(edited needs-merge
))))
762 ;; Two macros for elisp programming
764 (defmacro with-vc-file
(file comment
&rest body
)
765 "Check out a writable copy of FILE if necessary, then execute BODY.
766 Check in FILE with COMMENT (a string) after BODY has been executed.
767 FILE is passed through `expand-file-name'; BODY executed within
768 `save-excursion'. If FILE is not under version control, or locked by
769 somebody else, signal error."
770 (let ((filevar (make-symbol "file")))
771 `(let ((,filevar
(expand-file-name ,file
)))
772 (or (vc-backend ,filevar
)
773 (error (format "File not under version control: `%s'" file
)))
774 (unless (vc-editable-p ,filevar
)
775 (let ((state (vc-state ,filevar
)))
777 (error (format "`%s' is locking `%s'" state
,filevar
))
778 (vc-checkout ,filevar t
))))
781 (vc-checkin ,filevar nil
,comment
))))
783 (put 'with-vc-file
'lisp-indent-function
2)
786 (defmacro edit-vc-file
(file comment
&rest body
)
787 "Edit FILE under version control, executing body.
788 Checkin with COMMENT after executing BODY.
789 This macro uses `with-vc-file', passing args to it.
790 However, before executing BODY, find FILE, and after BODY, save buffer."
791 (let ((filevar (make-symbol "file")))
792 `(let ((,filevar
(expand-file-name ,file
)))
795 (set-buffer (find-file-noselect ,filevar
))
799 (put 'edit-vc-file
'lisp-indent-function
2)
801 (defun vc-ensure-vc-buffer ()
802 "Make sure that the current buffer visits a version-controlled file."
804 (set-buffer (find-file-noselect (dired-get-filename)))
805 (while vc-parent-buffer
806 (pop-to-buffer vc-parent-buffer
))
807 (if (not (buffer-file-name))
808 (error "Buffer %s is not associated with a file" (buffer-name))
809 (if (not (vc-backend (buffer-file-name)))
810 (error "File %s is not under version control" (buffer-file-name))))))
812 (defvar vc-binary-assoc nil
)
813 (defvar vc-binary-suffixes
814 (if (memq system-type
'(ms-dos windows-nt
))
815 '(".exe" ".com" ".bat" ".cmd" ".btm" "")
818 (defun vc-process-filter (p s
)
819 "An alternative output filter for async process P.
820 The only difference with the default filter is to insert S after markers."
821 (with-current-buffer (process-buffer p
)
823 (let ((inhibit-read-only t
))
824 (goto-char (process-mark p
))
826 (set-marker (process-mark p
) (point))))))
828 (defun vc-setup-buffer (&optional buf
)
829 "Prepare BUF for executing a VC command and make it current.
830 BUF defaults to \"*vc*\", can be a string and will be created if necessary."
831 (unless buf
(setq buf
"*vc*"))
832 (let ((camefrom (current-buffer))
833 (olddir default-directory
))
834 (set-buffer (get-buffer-create buf
))
835 (kill-all-local-variables)
836 (set (make-local-variable 'vc-parent-buffer
) camefrom
)
837 (set (make-local-variable 'vc-parent-buffer-name
)
838 (concat " from " (buffer-name camefrom
)))
839 (setq default-directory olddir
)
840 (let ((inhibit-read-only t
))
843 (defun vc-exec-after (code)
844 "Eval CODE when the current buffer's process is done.
845 If the current buffer has no process, just evaluate CODE.
846 Else, add CODE to the process' sentinel."
847 (let ((proc (get-buffer-process (current-buffer))))
849 ;; If there's no background process, just execute the code.
850 ((null proc
) (eval code
))
851 ;; If the background process has exited, reap it and try again
852 ((eq (process-status proc
) 'exit
)
853 (delete-process proc
)
854 (vc-exec-after code
))
855 ;; If a process is running, add CODE to the sentinel
856 ((eq (process-status proc
) 'run
)
857 (let ((sentinel (process-sentinel proc
)))
858 (set-process-sentinel proc
860 (with-current-buffer ',(current-buffer)
861 (goto-char (process-mark p
))
862 ,@(append (cdr (cdr (cdr ;strip off `with-current-buffer buf
864 (car (cdr (cdr ;strip off `lambda (p s)'
866 (list `(vc-exec-after ',code
))))))))
867 (t (error "Unexpected process state"))))
870 (defvar vc-post-command-functions nil
871 "Hook run at the end of `vc-do-command'.
872 Each function is called inside the buffer in which the command was run
873 and is passed 3 arguments: the COMMAND, the FILE and the FLAGS.")
876 (defun vc-do-command (buffer okstatus command file
&rest flags
)
877 "Execute a VC command, notifying user and checking for errors.
878 Output from COMMAND goes to BUFFER, or *vc* if BUFFER is nil or the
879 current buffer if BUFFER is t. If the destination buffer is not
880 already current, set it up properly and erase it. The command is
881 considered successful if its exit status does not exceed OKSTATUS (if
882 OKSTATUS is nil, that means to ignore errors, if it is 'async, that
883 means not to wait for termination of the subprocess). FILE is the
884 name of the working file (may also be nil, to execute commands that
885 don't expect a file name). If an optional list of FLAGS is present,
886 that is inserted into the command line before the filename."
887 (and file
(setq file
(expand-file-name file
)))
888 (if vc-command-messages
889 (message "Running %s on %s..." command file
))
891 (unless (or (eq buffer t
)
892 (and (stringp buffer
)
893 (string= (buffer-name) buffer
))
894 (eq buffer
(current-buffer)))
895 (vc-setup-buffer buffer
))
897 (inhibit-read-only t
)
899 (setq squeezed
(delq nil
(copy-sequence flags
)))
901 ;; FIXME: file-relative-name can return a bogus result because
902 ;; it doesn't look at the actual file-system to see if symlinks
904 (setq squeezed
(append squeezed
(list (file-relative-name file
)))))
905 (let ((exec-path (append vc-path exec-path
))
906 ;; Add vc-path to PATH for the execution of this command.
908 (cons (concat "PATH=" (getenv "PATH")
910 (mapconcat 'identity vc-path path-separator
))
911 process-environment
))
912 (w32-quote-process-args t
))
913 (if (eq okstatus
'async
)
914 (let ((proc (apply 'start-process command
(current-buffer) command
916 (unless (active-minibuffer-window)
917 (message "Running %s in the background..." command
))
918 ;;(set-process-sentinel proc (lambda (p msg) (delete-process p)))
919 (set-process-filter proc
'vc-process-filter
)
921 `(unless (active-minibuffer-window)
922 (message "Running %s in the background... done" ',command
))))
923 (setq status
(apply 'call-process command nil t nil squeezed
))
924 (when (or (not (integerp status
)) (and okstatus
(< okstatus status
)))
925 (pop-to-buffer (current-buffer))
926 (goto-char (point-min))
927 (shrink-window-if-larger-than-buffer)
928 (error "Running %s...FAILED (%s)" command
929 (if (integerp status
) (format "status %d" status
) status
))))
930 (if vc-command-messages
931 (message "Running %s...OK" command
)))
933 `(run-hook-with-args 'vc-post-command-functions
',command
',file
',flags
))
936 (defun vc-position-context (posn)
937 "Save a bit of the text around POSN in the current buffer.
938 Used to help us find the corresponding position again later
939 if markers are destroyed or corrupted."
940 ;; A lot of this was shamelessly lifted from Sebastian Kremer's
944 (buffer-substring posn
945 (min (point-max) (+ posn
100)))))
947 (defun vc-find-position-by-context (context)
948 "Return the position of CONTEXT in the current buffer.
949 If CONTEXT cannot be found, return nil."
950 (let ((context-string (nth 2 context
)))
951 (if (equal "" context-string
)
954 (let ((diff (- (nth 1 context
) (buffer-size))))
955 (if (< diff
0) (setq diff
(- diff
)))
956 (goto-char (nth 0 context
))
957 (if (or (search-forward context-string nil t
)
958 ;; Can't use search-backward since the match may continue
960 (progn (goto-char (- (point) diff
(length context-string
)))
961 ;; goto-char doesn't signal an error at
962 ;; beginning of buffer like backward-char would
963 (search-forward context-string nil t
)))
964 ;; to beginning of OSTRING
965 (- (point) (length context-string
))))))))
967 (defun vc-context-matches-p (posn context
)
968 "Return t if POSN matches CONTEXT, nil otherwise."
969 (let* ((context-string (nth 2 context
))
970 (len (length context-string
))
972 (if (> end
(1+ (buffer-size)))
974 (string= context-string
(buffer-substring posn end
)))))
976 (defun vc-buffer-context ()
977 "Return a list (POINT-CONTEXT MARK-CONTEXT REPARSE).
978 Used by `vc-restore-buffer-context' to later restore the context."
979 (let ((point-context (vc-position-context (point)))
980 ;; Use mark-marker to avoid confusion in transient-mark-mode.
981 (mark-context (if (eq (marker-buffer (mark-marker)) (current-buffer))
982 (vc-position-context (mark-marker))))
983 ;; Make the right thing happen in transient-mark-mode.
985 ;; We may want to reparse the compilation buffer after revert
986 (reparse (and (boundp 'compilation-error-list
) ;compile loaded
987 (let ((curbuf (current-buffer)))
988 ;; Construct a list; each elt is nil or a buffer
989 ;; iff that buffer is a compilation output buffer
990 ;; that contains markers into the current buffer.
992 (mapcar (lambda (buffer)
995 compilation-old-error-list
996 compilation-error-list
))
997 (buffer-error-marked-p nil
))
998 (while (and (consp errors
)
999 (not buffer-error-marked-p
))
1000 (and (markerp (cdr (car errors
)))
1003 (cdr (car errors
))))
1004 (setq buffer-error-marked-p t
))
1005 (setq errors
(cdr errors
)))
1006 (if buffer-error-marked-p buffer
)))
1008 (list point-context mark-context reparse
)))
1010 (defun vc-restore-buffer-context (context)
1011 "Restore point/mark, and reparse any affected compilation buffers.
1012 CONTEXT is that which `vc-buffer-context' returns."
1013 (let ((point-context (nth 0 context
))
1014 (mark-context (nth 1 context
))
1015 (reparse (nth 2 context
)))
1016 ;; Reparse affected compilation buffers.
1019 (with-current-buffer (car reparse
)
1020 (let ((compilation-last-buffer (current-buffer)) ;select buffer
1021 ;; Record the position in the compilation buffer of
1022 ;; the last error next-error went to.
1023 (error-pos (marker-position
1024 (car (car-safe compilation-error-list
)))))
1025 ;; Reparse the error messages as far as they were parsed before.
1026 (compile-reinitialize-errors '(4) compilation-parsing-end
)
1027 ;; Move the pointer up to find the error we were at before
1028 ;; reparsing. Now next-error should properly go to the next one.
1029 (while (and compilation-error-list
1030 (/= error-pos
(car (car compilation-error-list
))))
1031 (setq compilation-error-list
(cdr compilation-error-list
))))))
1032 (setq reparse
(cdr reparse
)))
1034 ;; if necessary, restore point and mark
1035 (if (not (vc-context-matches-p (point) point-context
))
1036 (let ((new-point (vc-find-position-by-context point-context
)))
1037 (if new-point
(goto-char new-point
))))
1040 (not (vc-context-matches-p (mark) mark-context
))
1041 (let ((new-mark (vc-find-position-by-context mark-context
)))
1042 (if new-mark
(set-mark new-mark
))))))
1044 (defun vc-revert-buffer1 (&optional arg no-confirm
)
1045 "Revert buffer, keeping point and mark where user expects them.
1046 Try to be clever in the face of changes due to expanded version control
1047 key words. This is important for typeahead to work as expected.
1048 ARG and NO-CONFIRM are passed on to `revert-buffer'."
1051 (let ((context (vc-buffer-context)))
1052 ;; Use save-excursion here, because it may be able to restore point
1053 ;; and mark properly even in cases where vc-restore-buffer-context
1054 ;; would fail. However, save-excursion might also get it wrong --
1055 ;; in this case, vc-restore-buffer-context gives it a second try.
1057 ;; t means don't call normal-mode;
1058 ;; that's to preserve various minor modes.
1059 (revert-buffer arg no-confirm t
))
1060 (vc-restore-buffer-context context
)))
1063 (defun vc-buffer-sync (&optional not-urgent
)
1064 "Make sure the current buffer and its working file are in sync.
1065 NOT-URGENT means it is ok to continue if the user says not to save."
1066 (if (buffer-modified-p)
1067 (if (or vc-suppress-confirm
1068 (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name))))
1071 (error "Aborted")))))
1073 (defun vc-workfile-unchanged-p (file)
1074 "Return non-nil if FILE has not changed since the last checkout."
1075 (let ((checkout-time (vc-file-getprop file
'vc-checkout-time
))
1076 (lastmod (nth 5 (file-attributes file
))))
1078 (equal checkout-time lastmod
)
1079 (let ((unchanged (vc-call workfile-unchanged-p file
)))
1080 (vc-file-setprop file
'vc-checkout-time
(if unchanged lastmod
0))
1083 (defun vc-default-workfile-unchanged-p (backend file
)
1084 "Check if FILE is unchanged by diffing against the master version.
1085 Return non-nil if FILE is unchanged."
1086 (zerop (vc-call diff file
(vc-workfile-version file
))))
1088 (defun vc-default-latest-on-branch-p (backend file
)
1089 "Return non-nil if FILE is the latest on its branch.
1090 This default implementation always returns non-nil, which means that
1091 editing non-current versions is not supported by default."
1094 (defun vc-recompute-state (file)
1095 "Force a recomputation of the version control state of FILE.
1096 The state is computed using the exact, and possibly expensive
1097 function `vc-BACKEND-state', not the heuristic."
1098 (vc-file-setprop file
'vc-state
(vc-call state file
)))
1100 (defun vc-next-action-on-file (file verbose
&optional comment
)
1101 "Do The Right Thing for a given FILE under version control.
1102 If COMMENT is specified, it will be used as an admin or checkin comment.
1103 If VERBOSE is non-nil, query the user rather than using default parameters."
1104 (let ((visited (get-file-buffer file
))
1107 ;; Check relation of buffer and file, and make sure
1108 ;; user knows what he's doing. First, finding the file
1109 ;; will check whether the file on disk is newer.
1110 (set-buffer visited
)
1111 ;; ignore buffer-read-only during this test
1112 (let ((buffer-read-only (not (file-writable-p file
))))
1114 (find-file-other-window file
)
1115 (find-file-noselect file
)))
1116 (if (not (verify-visited-file-modtime (current-buffer)))
1117 (if (yes-or-no-p "Replace file on disk with buffer contents? ")
1118 (write-file (buffer-file-name))
1120 ;; Now, check if we have unsaved changes.
1122 (if (buffer-modified-p)
1123 (or (y-or-n-p "Operate on disk file, keeping modified buffer? ")
1124 (error "Aborted")))))
1126 ;; Do the right thing
1127 (if (not (vc-registered file
))
1128 (vc-register verbose comment
)
1129 (vc-recompute-state file
)
1130 (if visited
(vc-mode-line file
))
1131 (setq state
(vc-state file
))
1134 ((or (eq state
'up-to-date
)
1135 (and verbose
(eq state
'needs-patch
)))
1138 ;; go to a different version
1140 (read-string "Branch, version, or backend to move to: "))
1141 (let ((vsym (intern-soft (upcase version
))))
1142 (if (member vsym vc-handled-backends
)
1143 (vc-transfer-file file vsym
)
1144 (vc-checkout file
(eq (vc-checkout-model file
) 'implicit
)
1146 ((not (eq (vc-checkout-model file
) 'implicit
))
1147 ;; check the file out
1148 (vc-checkout file t
))
1151 (message "%s is up-to-date" file
))))
1153 ;; Abnormal: edited but read-only
1154 ((and visited
(eq state
'edited
)
1155 buffer-read-only
(not (file-writable-p file
)))
1156 ;; Make the file+buffer read-write. If the user really wanted to
1157 ;; commit, he'll get a chance to do that next time around, anyway.
1158 (message "File is edited but read-only; making it writable")
1159 (set-file-modes buffer-file-name
1160 (logior (file-modes buffer-file-name
) 128))
1161 (toggle-read-only -
1))
1166 ;; For files with locking, if the file does not contain
1167 ;; any changes, just let go of the lock, i.e. revert.
1168 ((and (not (eq (vc-checkout-model file
) 'implicit
))
1169 (vc-workfile-unchanged-p file
)
1170 ;; If buffer is modified, that means the user just
1171 ;; said no to saving it; in that case, don't revert,
1172 ;; because the user might intend to save after
1173 ;; finishing the log entry.
1174 (not (and visited
(buffer-modified-p))))
1175 ;; DO NOT revert the file without asking the user!
1176 (if (not visited
) (find-file-other-window file
))
1177 (if (yes-or-no-p "Revert to master version? ")
1178 (vc-revert-buffer)))
1181 (vc-checkin file nil comment
)
1182 (setq version
(read-string "New version or backend: "))
1183 (let ((vsym (intern (upcase version
))))
1184 (if (member vsym vc-handled-backends
)
1185 (vc-transfer-file file vsym
)
1186 (vc-checkin file version comment
)))))))
1188 ;; locked by somebody else
1191 (error "Sorry, you can't steal the lock on %s this way"
1192 (file-name-nondirectory file
)))
1194 (if verbose
(read-string "Version to steal: ")
1195 (vc-workfile-version file
))
1199 ((eq state
'needs-patch
)
1200 (if (yes-or-no-p (format
1201 "%s is not up-to-date. Get latest version? "
1202 (file-name-nondirectory file
)))
1203 (vc-checkout file
(eq (vc-checkout-model file
) 'implicit
) "")
1204 (if (and (not (eq (vc-checkout-model file
) 'implicit
))
1205 (yes-or-no-p "Lock this version? "))
1206 (vc-checkout file t
)
1207 (error "Aborted"))))
1210 ((eq state
'needs-merge
)
1211 (if (yes-or-no-p (format
1212 "%s is not up-to-date. Merge in changes now? "
1213 (file-name-nondirectory file
)))
1214 (vc-maybe-resolve-conflicts file
(vc-call merge-news file
))
1218 ((eq state
'unlocked-changes
)
1219 (if (not visited
) (find-file-other-window file
))
1220 (if (save-window-excursion
1221 (vc-version-diff file
(vc-workfile-version file
) nil
)
1222 (goto-char (point-min))
1223 (let ((inhibit-read-only t
))
1225 (format "Changes to %s since last lock:\n\n" file
)))
1227 (yes-or-no-p (concat "File has unlocked changes. "
1228 "Claim lock retaining changes? ")))
1229 (progn (vc-call steal-lock file
)
1230 (clear-visited-file-modtime)
1231 ;; Must clear any headers here because they wouldn't
1232 ;; show that the file is locked now.
1233 (vc-clear-headers file
)
1234 (write-file (buffer-file-name))
1235 (vc-mode-line file
))
1236 (if (not (yes-or-no-p
1237 "Revert to checked-in version, instead? "))
1238 (error "Checkout aborted")
1239 (vc-revert-buffer1 t t
)
1240 (vc-checkout file t
))))))))
1242 (defvar vc-dired-window-configuration
)
1244 (defun vc-next-action-dired (file rev comment
)
1245 "Call `vc-next-action-on-file' on all the marked files.
1246 Ignores FILE and REV, but passes on COMMENT."
1247 (let ((dired-buffer (current-buffer))
1248 (dired-dir default-directory
))
1249 (dired-map-over-marks
1250 (let ((file (dired-get-filename)))
1251 (message "Processing %s..." file
)
1252 (vc-next-action-on-file file nil comment
)
1253 (set-buffer dired-buffer
)
1254 (set-window-configuration vc-dired-window-configuration
)
1255 (message "Processing %s...done" file
))
1257 (dired-move-to-filename))
1259 ;; Here's the major entry point.
1262 (defun vc-next-action (verbose)
1263 "Do the next logical version control operation on the current file.
1265 If you call this from within a VC dired buffer with no files marked,
1266 it will operate on the file in the current line.
1268 If you call this from within a VC dired buffer, and one or more
1269 files are marked, it will accept a log message and then operate on
1270 each one. The log message will be used as a comment for any register
1271 or checkin operations, but ignored when doing checkouts. Attempted
1272 lock steals will raise an error.
1274 A prefix argument lets you specify the version number to use.
1276 For RCS and SCCS files:
1277 If the file is not already registered, this registers it for version
1279 If the file is registered and not locked by anyone, this checks out
1280 a writable and locked file ready for editing.
1281 If the file is checked out and locked by the calling user, this
1282 first checks to see if the file has changed since checkout. If not,
1283 it performs a revert.
1284 If the file has been changed, this pops up a buffer for entry
1285 of a log message; when the message has been entered, it checks in the
1286 resulting changes along with the log message as change commentary. If
1287 the variable `vc-keep-workfiles' is non-nil (which is its default), a
1288 read-only copy of the changed file is left in place afterwards.
1289 If the file is registered and locked by someone else, you are given
1290 the option to steal the lock.
1293 If the file is not already registered, this registers it for version
1294 control. This does a \"cvs add\", but no \"cvs commit\".
1295 If the file is added but not committed, it is committed.
1296 If your working file is changed, but the repository file is
1297 unchanged, this pops up a buffer for entry of a log message; when the
1298 message has been entered, it checks in the resulting changes along
1299 with the logmessage as change commentary. A writable file is retained.
1300 If the repository file is changed, you are asked if you want to
1301 merge in the changes into your working copy."
1306 (let ((files (dired-get-marked-files)))
1307 (set (make-local-variable 'vc-dired-window-configuration
)
1308 (current-window-configuration))
1312 (if (not (vc-up-to-date-p f
)) "@" ""))
1314 (vc-next-action-dired nil nil
"dummy")
1315 (vc-start-entry nil nil nil nil
1316 "Enter a change comment for the marked files."
1317 'vc-next-action-dired
))
1319 (while vc-parent-buffer
1320 (pop-to-buffer vc-parent-buffer
))
1321 (if buffer-file-name
1322 (vc-next-action-on-file buffer-file-name verbose
)
1323 (error "Buffer %s is not associated with a file" (buffer-name)))))
1325 ;; These functions help the vc-next-action entry point
1328 (defun vc-register (&optional set-version comment
)
1329 "Register the current file into a version control system.
1330 With prefix argument SET-VERSION, allow user to specify initial version
1331 level. If COMMENT is present, use that as an initial comment.
1333 The version control system to use is found by cycling through the list
1334 `vc-handled-backends'. The first backend in that list which declares
1335 itself responsible for the file (usually because other files in that
1336 directory are already registered under that backend) will be used to
1337 register the file. If no backend declares itself responsible, the
1338 first backend that could register the file is used."
1340 (unless buffer-file-name
(error "No visited file"))
1341 (when (vc-backend buffer-file-name
)
1342 (if (vc-registered buffer-file-name
)
1343 (error "This file is already registered")
1344 (unless (y-or-n-p "Previous master file has vanished. Make a new one? ")
1345 (error "Aborted"))))
1346 ;; Watch out for new buffers of size 0: the corresponding file
1347 ;; does not exist yet, even though buffer-modified-p is nil.
1348 (if (and (not (buffer-modified-p))
1349 (zerop (buffer-size))
1350 (not (file-exists-p buffer-file-name
)))
1351 (set-buffer-modified-p t
))
1354 (vc-start-entry buffer-file-name
1356 (read-string (format "Initial version level for %s: "
1358 (let ((backend (vc-responsible-backend buffer-file-name
)))
1359 (if (vc-find-backend-function backend
'init-version
)
1360 (vc-call-backend backend
'init-version
)
1361 vc-default-init-version
)))
1362 (or comment
(not vc-initial-comment
))
1364 "Enter initial comment."
1365 (lambda (file rev comment
)
1366 (message "Registering %s... " file
)
1367 (let ((backend (vc-responsible-backend file t
)))
1368 (vc-file-clearprops file
)
1369 (vc-call-backend backend
'register file rev comment
)
1370 (vc-file-setprop file
'vc-backend backend
)
1371 (unless vc-make-backup-files
1372 (make-local-variable 'backup-inhibited
)
1373 (setq backup-inhibited t
)))
1374 (message "Registering %s... done" file
))))
1377 (defun vc-responsible-backend (file &optional register
)
1378 "Return the name of a backend system that is responsible for FILE.
1379 The optional argument REGISTER means that a backend suitable for
1380 registration should be found.
1382 If REGISTER is nil, then if FILE is already registered, return the
1383 backend of FILE. If FILE is not registered, or a directory, then the
1384 first backend in `vc-handled-backends' that declares itself
1385 responsible for FILE is returned. If no backend declares itself
1386 responsible, return the first backend.
1388 If REGISTER is non-nil, return the first responsible backend under
1389 which FILE is not yet registered. If there is no such backend, return
1390 the first backend under which FILE is not yet registered, but could
1392 (if (not vc-handled-backends
)
1393 (error "No handled backends"))
1394 (or (and (not (file-directory-p file
)) (not register
) (vc-backend file
))
1396 ;; First try: find a responsible backend. If this is for registration,
1397 ;; it must be a backend under which FILE is not yet registered.
1398 (dolist (backend vc-handled-backends
)
1399 (and (or (not register
)
1400 (not (vc-call-backend backend
'registered file
)))
1401 (vc-call-backend backend
'responsible-p file
)
1402 (throw 'found backend
)))
1403 ;; no responsible backend
1405 ;; if this is not for registration, the first backend must do
1406 (car vc-handled-backends
)
1407 ;; for registration, we need to find a new backend that
1408 ;; could register FILE
1409 (dolist (backend vc-handled-backends
)
1410 (and (not (vc-call-backend backend
'registered file
))
1411 (vc-call-backend backend
'could-register file
)
1412 (throw 'found backend
)))
1413 (error "No backend that could register")))))
1415 (defun vc-default-responsible-p (backend file
)
1416 "Indicate whether BACKEND is reponsible for FILE.
1417 The default is to return nil always."
1420 (defun vc-default-could-register (backend file
)
1421 "Return non-nil if BACKEND could be used to register FILE.
1422 The default implementation returns t for all files."
1425 (defun vc-resynch-window (file &optional keep noquery
)
1426 "If FILE is in the current buffer, either revert or unvisit it.
1427 The choice between revert (to see expanded keywords) and unvisit depends on
1428 `vc-keep-workfiles'. NOQUERY if non-nil inhibits confirmation for
1429 reverting. NOQUERY should be t *only* if it is known the only
1430 difference between the buffer and the file is due to version control
1431 rather than user editing!"
1432 (and (string= buffer-file-name file
)
1435 (vc-revert-buffer1 t noquery
)
1436 ;; TODO: Adjusting view mode might no longer be necessary
1437 ;; after RMS change to files.el of 1999-08-08. Investigate
1438 ;; this when we install the new VC.
1440 (if (file-writable-p file
)
1442 (let ((view-old-buffer-read-only nil
))
1444 (and (not view-mode
)
1445 (not (eq (get major-mode
'mode-class
) 'special
))
1446 (view-mode-enter))))
1447 (vc-mode-line buffer-file-name
))
1448 (kill-buffer (current-buffer)))))
1450 (defun vc-resynch-buffer (file &optional keep noquery
)
1451 "If FILE is currently visited, resynch its buffer."
1452 (if (string= buffer-file-name file
)
1453 (vc-resynch-window file keep noquery
)
1454 (let ((buffer (get-file-buffer file
)))
1456 (with-current-buffer buffer
1457 (vc-resynch-window file keep noquery
)))))
1458 (vc-dired-resynch-file file
))
1460 (defun vc-start-entry (file rev comment initial-contents msg action
&optional after-hook
)
1461 "Accept a comment for an operation on FILE revision REV.
1462 If COMMENT is nil, pop up a VC-log buffer, emit MSG, and set the
1463 action on close to ACTION. If COMMENT is a string and
1464 INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial
1465 contents of the log entry buffer. If COMMENT is a string and
1466 INITIAL-CONTENTS is nil, do action immediately as if the user had
1467 entered COMMENT. If COMMENT is t, also do action immediately with an
1468 empty comment. Remember the file's buffer in `vc-parent-buffer'
1469 \(current one if no file). AFTER-HOOK specifies the local value
1470 for vc-log-operation-hook."
1471 (let ((parent (or (and file
(get-file-buffer file
)) (current-buffer))))
1472 (if vc-before-checkin-hook
1474 (with-current-buffer parent
1475 (run-hooks 'vc-before-checkin-hook
))
1476 (run-hooks 'vc-before-checkin-hook
)))
1477 (if (and comment
(not initial-contents
))
1478 (set-buffer (get-buffer-create "*VC-log*"))
1479 (pop-to-buffer (get-buffer-create "*VC-log*")))
1480 (set (make-local-variable 'vc-parent-buffer
) parent
)
1481 (set (make-local-variable 'vc-parent-buffer-name
)
1482 (concat " from " (buffer-name vc-parent-buffer
)))
1483 (if file
(vc-mode-line file
))
1485 (make-local-variable 'vc-log-after-operation-hook
)
1487 (setq vc-log-after-operation-hook after-hook
))
1488 (setq vc-log-operation action
)
1489 (setq vc-log-version rev
)
1492 (when (stringp comment
) (insert comment
)))
1493 (if (or (not comment
) initial-contents
)
1494 (message "%s Type C-c C-c when done" msg
)
1495 (vc-finish-logentry (eq comment t
)))))
1497 (defun vc-checkout (file &optional writable rev
)
1498 "Retrieve a copy of the revision REV of FILE.
1499 If WRITABLE is non-nil, make sure the retrieved file is writable.
1500 REV defaults to the latest revision.
1502 After check-out, runs the normal hook `vc-checkout-hook'."
1505 (vc-call make-version-backups-p file
)
1506 (vc-up-to-date-p file
)
1507 (vc-make-version-backup file
))
1511 (vc-call checkout file writable rev
)
1513 ;; Maybe the backend is not installed ;-(
1515 (let ((buf (get-file-buffer file
)))
1516 (when buf
(with-current-buffer buf
(toggle-read-only -
1)))))
1517 (signal (car err
) (cdr err
))))
1518 `((vc-state .
,(if (or (eq (vc-checkout-model file
) 'implicit
)
1520 (if (vc-call latest-on-branch-p file
)
1524 (vc-checkout-time .
,(nth 5 (file-attributes file
)))))
1525 (vc-resynch-buffer file t t
)
1526 (run-hooks 'vc-checkout-hook
))
1528 (defun vc-steal-lock (file rev owner
)
1529 "Steal the lock on FILE."
1530 (let (file-description)
1532 (setq file-description
(format "%s:%s" file rev
))
1533 (setq file-description file
))
1534 (if (not (yes-or-no-p (format "Steal the lock on %s from %s? "
1535 file-description owner
)))
1536 (error "Steal canceled"))
1537 (message "Stealing lock on %s..." file
)
1540 (vc-call steal-lock file rev
)
1541 `((vc-state . edited
)))
1542 (vc-resynch-buffer file t t
)
1543 (message "Stealing lock on %s...done" file
)
1544 ;; Write mail after actually stealing, because if the stealing
1545 ;; goes wrong, we don't want to send any mail.
1546 (compose-mail owner
(format "Stolen lock on %s" file-description
))
1547 (setq default-directory
(expand-file-name "~/"))
1548 (goto-char (point-max))
1550 (format "I stole the lock on %s, " file-description
)
1551 (current-time-string)
1553 (message "Please explain why you stole the lock. Type C-c C-c when done.")))
1555 (defun vc-checkin (file &optional rev comment initial-contents
)
1557 The optional argument REV may be a string specifying the new version
1558 level (if nil increment the current level). COMMENT is a comment
1559 string; if omitted, a buffer is popped up to accept a comment. If
1560 INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial contents
1561 of the log entry buffer.
1563 If `vc-keep-workfiles' is nil, FILE is deleted afterwards, provided
1564 that the version control system supports this mode of operation.
1566 Runs the normal hook `vc-checkin-hook'."
1568 file rev comment initial-contents
1569 "Enter a change comment."
1570 (lambda (file rev comment
)
1571 (message "Checking in %s..." file
)
1572 ;; "This log message intentionally left almost blank".
1573 ;; RCS 5.7 gripes about white-space-only comments too.
1574 (or (and comment
(string-match "[^\t\n ]" comment
))
1575 (setq comment
"*** empty log message ***"))
1578 ;; Change buffers to get local value of vc-checkin-switches.
1579 (with-current-buffer (or (get-file-buffer file
) (current-buffer))
1581 (vc-call checkin file rev comment
)
1582 (vc-delete-automatic-version-backups file
)))
1583 `((vc-state . up-to-date
)
1584 (vc-checkout-time .
,(nth 5 (file-attributes file
)))
1585 (vc-workfile-version . nil
)))
1586 (message "Checking in %s...done" file
))
1589 (defun vc-comment-to-change-log (&optional whoami file-name
)
1590 "Enter last VC comment into the change log for the current file.
1591 WHOAMI (interactive prefix) non-nil means prompt for user name
1592 and site. FILE-NAME is the name of the change log; if nil, use
1593 `change-log-default-name'.
1595 This may be useful as a `vc-checkin-hook' to update change logs
1597 (interactive (if current-prefix-arg
1598 (list current-prefix-arg
1599 (prompt-for-change-log-name))))
1600 ;; Make sure the defvar for add-log-current-defun-function has been executed
1601 ;; before binding it.
1603 (let (;; Extract the comment first so we get any error before doing anything.
1604 (comment (ring-ref vc-comment-ring
0))
1605 ;; Don't let add-change-log-entry insert a defun name.
1606 (add-log-current-defun-function 'ignore
)
1608 ;; Call add-log to do half the work.
1609 (add-change-log-entry whoami file-name t t
)
1610 ;; Insert the VC comment, leaving point before it.
1611 (setq end
(save-excursion (insert comment
) (point-marker)))
1612 (if (looking-at "\\s *\\s(")
1613 ;; It starts with an open-paren, as in "(foo): Frobbed."
1614 ;; So remove the ": " add-log inserted.
1616 ;; Canonicalize the white space between the file name and comment.
1618 ;; Indent rest of the text the same way add-log indented the first line.
1619 (let ((indentation (current-indentation)))
1621 (while (< (point) end
)
1623 (indent-to indentation
))
1624 (setq end
(point))))
1625 ;; Fill the inserted text, preserving open-parens at bol.
1626 (let ((paragraph-separate (concat paragraph-separate
"\\|\\s *\\s("))
1627 (paragraph-start (concat paragraph-start
"\\|\\s *\\s(")))
1629 (fill-region (point) end
))
1630 ;; Canonicalize the white space at the end of the entry so it is
1631 ;; separated from the next entry by a single blank line.
1632 (skip-syntax-forward " " end
)
1633 (delete-char (- (skip-syntax-backward " ")))
1634 (or (eobp) (looking-at "\n\n")
1637 (defun vc-finish-logentry (&optional nocomment
)
1638 "Complete the operation implied by the current log entry.
1639 Use the contents of the current buffer as a check-in or registration
1640 comment. If the optional arg NOCOMMENT is non-nil, then don't check
1641 the buffer contents as a comment, and don't add it to
1644 ;; Check and record the comment, if any.
1646 ;; Comment too long?
1647 (vc-call-backend (or (and vc-log-file
(vc-backend vc-log-file
))
1648 (vc-responsible-backend default-directory
))
1650 (run-hooks 'vc-logentry-check-hook
)
1651 ;; Record the comment in the comment ring
1652 (let ((comment (buffer-string)))
1653 (unless (and (ring-p vc-comment-ring
)
1654 (not (ring-empty-p vc-comment-ring
))
1655 (equal comment
(ring-ref vc-comment-ring
0)))
1656 (ring-insert vc-comment-ring comment
))))
1657 ;; Sync parent buffer in case the user modified it while editing the comment.
1658 ;; But not if it is a vc-dired buffer.
1659 (with-current-buffer vc-parent-buffer
1660 (or vc-dired-mode
(vc-buffer-sync)))
1661 (if (not vc-log-operation
) (error "No log operation is pending"))
1662 ;; save the parameters held in buffer-local variables
1663 (let ((log-operation vc-log-operation
)
1664 (log-file vc-log-file
)
1665 (log-version vc-log-version
)
1666 (log-entry (buffer-string))
1667 (after-hook vc-log-after-operation-hook
)
1668 (tmp-vc-parent-buffer vc-parent-buffer
))
1669 (pop-to-buffer vc-parent-buffer
)
1672 (funcall log-operation
1676 ;; Remove checkin window (after the checkin so that if that fails
1677 ;; we don't zap the *VC-log* buffer and the typing therein).
1678 (let ((logbuf (get-buffer "*VC-log*")))
1679 (cond ((and logbuf vc-delete-logbuf-window
)
1680 (delete-windows-on logbuf
(selected-frame))
1681 ;; Kill buffer and delete any other dedicated windows/frames.
1682 (kill-buffer logbuf
))
1683 (logbuf (pop-to-buffer "*VC-log*")
1685 (pop-to-buffer tmp-vc-parent-buffer
))))
1686 ;; Now make sure we see the expanded headers
1688 (vc-resynch-buffer log-file vc-keep-workfiles t
))
1690 (dired-move-to-filename))
1691 (run-hooks after-hook
'vc-finish-logentry-hook
)))
1693 ;; Code for access to the comment ring
1695 (defun vc-new-comment-index (stride len
)
1696 "Return the comment index STRIDE elements from the current one.
1697 LEN is the length of `vc-comment-ring'."
1699 (vc-comment-ring-index (+ vc-comment-ring-index stride
))
1700 ;; Initialize the index on the first use of this command
1701 ;; so that the first M-p gets index 0, and the first M-n gets
1703 ((> stride
0) (1- stride
))
1707 (defun vc-previous-comment (arg)
1708 "Cycle backwards through comment history.
1709 With a numeric prefix ARG, go back ARG comments."
1711 (let ((len (ring-length vc-comment-ring
)))
1713 (progn (message "Empty comment ring") (ding))
1715 (setq vc-comment-ring-index
(vc-new-comment-index arg len
))
1716 (message "Comment %d" (1+ vc-comment-ring-index
))
1717 (insert (ring-ref vc-comment-ring vc-comment-ring-index
)))))
1719 (defun vc-next-comment (arg)
1720 "Cycle forwards through comment history.
1721 With a numeric prefix ARG, go forward ARG comments."
1723 (vc-previous-comment (- arg
)))
1725 (defun vc-comment-search-reverse (str &optional stride
)
1726 "Search backwards through comment history for substring match of STR.
1727 If the optional argument STRIDE is present, that is a step-width to use
1728 when going through the comment ring."
1729 ;; Why substring rather than regexp ? -sm
1731 (list (read-string "Comment substring: " nil nil vc-last-comment-match
)))
1732 (unless stride
(setq stride
1))
1733 (if (string= str
"")
1734 (setq str vc-last-comment-match
)
1735 (setq vc-last-comment-match str
))
1736 (let* ((str (regexp-quote str
))
1737 (len (ring-length vc-comment-ring
))
1738 (n (vc-new-comment-index stride len
)))
1739 (while (progn (when (or (>= n len
) (< n
0)) (error "Not found"))
1740 (not (string-match str
(ring-ref vc-comment-ring n
))))
1741 (setq n
(+ n stride
)))
1742 (setq vc-comment-ring-index n
)
1743 (vc-previous-comment 0)))
1745 (defun vc-comment-search-forward (str)
1746 "Search forwards through comment history for a substring match of STR."
1748 (list (read-string "Comment substring: " nil nil vc-last-comment-match
)))
1749 (vc-comment-search-reverse str -
1))
1751 ;; Additional entry points for examining version histories
1754 (defun vc-diff (historic &optional not-urgent
)
1755 "Display diffs between file versions.
1756 Normally this compares the current file and buffer with the most
1757 recent checked in version of that file. This uses no arguments. With
1758 a prefix argument HISTORIC, it reads the file name to use and two
1759 version designators specifying which versions to compare. The
1760 optional argument NOT-URGENT non-nil means it is ok to say no to
1762 (interactive (list current-prefix-arg t
))
1764 (call-interactively 'vc-version-diff
)
1765 (vc-ensure-vc-buffer)
1766 (let ((file buffer-file-name
))
1767 (vc-buffer-sync not-urgent
)
1768 (if (vc-workfile-unchanged-p buffer-file-name
)
1769 (message "No changes to %s since latest version" file
)
1770 (vc-version-diff file nil nil
)))))
1772 (defun vc-version-diff (file rel1 rel2
)
1773 "List the differences between FILE's versions REL1 and REL2.
1774 If REL1 is empty or nil it means to use the current workfile version;
1775 REL2 empty or nil means the current file contents. FILE may also be
1776 a directory, in that case, generate diffs between the correponding
1777 versions of all registered files in or below it."
1779 (let ((file (expand-file-name
1780 (read-file-name (if buffer-file-name
1781 "File or dir to diff: (default visited file) "
1782 "File or dir to diff: ")
1783 default-directory buffer-file-name t
)))
1784 (rel1-default nil
) (rel2-default nil
))
1785 ;; compute default versions based on the file state
1787 ;; if it's a directory, don't supply any version default
1788 ((file-directory-p file
)
1790 ;; if the file is not up-to-date, use current version as older version
1791 ((not (vc-up-to-date-p file
))
1792 (setq rel1-default
(vc-workfile-version file
)))
1793 ;; if the file is not locked, use last and previous version as default
1795 (setq rel1-default
(vc-call previous-version file
1796 (vc-workfile-version file
)))
1797 (if (string= rel1-default
"") (setq rel1-default nil
))
1798 (setq rel2-default
(vc-workfile-version file
))))
1799 ;; construct argument list
1801 (read-string (if rel1-default
1802 (concat "Older version: (default "
1805 nil nil rel1-default
)
1806 (read-string (if rel2-default
1807 (concat "Newer version: (default "
1809 "Newer version (default: current source): ")
1810 nil nil rel2-default
))))
1811 (if (file-directory-p file
)
1812 ;; recursive directory diff
1814 (vc-setup-buffer "*vc-diff*")
1815 (if (string-equal rel1
"") (setq rel1 nil
))
1816 (if (string-equal rel2
"") (setq rel2 nil
))
1817 (let ((inhibit-read-only t
))
1818 (insert "Diffs between "
1819 (or rel1
"last version checked in")
1821 (or rel2
"current workfile(s)")
1823 (let ((dir (file-name-as-directory file
)))
1824 (vc-call-backend (vc-responsible-backend dir
)
1825 'diff-tree dir rel1 rel2
))
1826 (vc-exec-after `(let ((inhibit-read-only t
))
1827 (insert "\nEnd of diffs.\n"))))
1829 (vc-diff-internal file rel1 rel2
))
1830 (set-buffer "*vc-diff*")
1831 (if (and (zerop (buffer-size))
1832 (not (get-buffer-process (current-buffer))))
1836 (message "No changes to %s between %s and %s" file rel1 rel2
)
1837 (message "No changes to %s since %s" file rel1
))
1838 (message "No changes to %s since latest version" file
))
1840 (pop-to-buffer (current-buffer))
1841 ;; Gnus-5.8.5 sets up an autoload for diff-mode, even if it's
1842 ;; not available. Work around that.
1843 (if (require 'diff-mode nil t
) (diff-mode))
1844 (vc-exec-after '(let ((inhibit-read-only t
))
1845 (if (eq (buffer-size) 0)
1846 (insert "No differences found.\n"))
1847 (goto-char (point-min))
1848 (shrink-window-if-larger-than-buffer)))
1851 (defun vc-diff-internal (file rel1 rel2
)
1852 "Run diff to compare FILE's revisions REL1 and REL2.
1853 Output goes to the current buffer, which is assumed properly set up.
1854 The exit status of the diff command is returned.
1856 This function takes care to set up a proper coding system for diff output.
1857 If both revisions are available as local files, then it also does not
1858 actually call the backend, but performs a local diff."
1859 (if (or (not rel1
) (string-equal rel1
""))
1860 (setq rel1
(vc-workfile-version file
)))
1861 (if (string-equal rel2
"")
1863 (let ((file-rel1 (vc-version-backup-file file rel1
))
1864 (file-rel2 (if (not rel2
)
1866 (vc-version-backup-file file rel2
)))
1867 (coding-system-for-read (vc-coding-system-for-diff file
)))
1868 (if (and file-rel1 file-rel2
)
1869 (apply 'vc-do-command
"*vc-diff*" 1 "diff" nil
1870 (append (if (listp diff-switches
)
1872 (list diff-switches
))
1873 (if (listp vc-diff-switches
)
1875 (list vc-diff-switches
))
1876 (list (file-relative-name file-rel1
)
1877 (file-relative-name file-rel2
))))
1878 (vc-call diff file rel1 rel2
))))
1880 (defmacro vc-diff-switches-list
(backend)
1881 "Return the list of switches to use for executing diff under BACKEND."
1883 (if (listp diff-switches
) diff-switches
(list diff-switches
))
1884 (if (listp vc-diff-switches
) vc-diff-switches
(list vc-diff-switches
))
1885 (let* ((backend-switches-symbol
1886 (intern (concat "vc-" (downcase (symbol-name ,backend
))
1889 (if (boundp backend-switches-symbol
)
1890 (eval backend-switches-symbol
)
1892 (if (listp backend-switches
) backend-switches
(list backend-switches
)))))
1894 (defun vc-default-diff-tree (backend dir rel1 rel2
)
1895 "List differences for all registered files at and below DIR.
1896 The meaning of REL1 and REL2 is the same as for `vc-version-diff'."
1897 ;; This implementation does an explicit tree walk, and calls
1898 ;; vc-BACKEND-diff directly for each file. An optimization
1899 ;; would be to use `vc-diff-internal', so that diffs can be local,
1900 ;; and to call it only for files that are actually changed.
1901 ;; However, this is expensive for some backends, and so it is left
1902 ;; to backend-specific implementations.
1903 (setq default-directory dir
)
1908 `(let ((coding-system-for-read (vc-coding-system-for-diff ',f
)))
1909 (message "Looking at %s" ',f
)
1910 (vc-call-backend ',(vc-backend f
)
1911 'diff
',f
',rel1
',rel2
))))))
1913 (defun vc-coding-system-for-diff (file)
1914 "Return the coding system for reading diff output for FILE."
1915 (or coding-system-for-read
1916 ;; if we already have this file open,
1917 ;; use the buffer's coding system
1918 (let ((buf (find-buffer-visiting file
)))
1919 (if buf
(with-current-buffer buf
1920 buffer-file-coding-system
)))
1921 ;; otherwise, try to find one based on the file name
1922 (car (find-operation-coding-system 'insert-file-contents file
))
1923 ;; and a final fallback
1927 (defun vc-version-other-window (rev)
1928 "Visit version REV of the current file in another window.
1929 If the current file is named `F', the version is named `F.~REV~'.
1930 If `F.~REV~' already exists, use it instead of checking it out again."
1931 (interactive "sVersion to visit (default is workfile version): ")
1932 (vc-ensure-vc-buffer)
1933 (let* ((file buffer-file-name
)
1934 (version (if (string-equal rev
"")
1935 (vc-workfile-version file
)
1937 (switch-to-buffer-other-window (vc-find-version file version
))))
1939 (defun vc-find-version (file version
)
1940 "Read VERSION of FILE into a buffer and return the buffer."
1941 (let ((automatic-backup (vc-version-backup-file-name file version
))
1942 (manual-backup (vc-version-backup-file-name file version
'manual
)))
1943 (unless (file-exists-p manual-backup
)
1944 (if (file-exists-p automatic-backup
)
1945 (rename-file automatic-backup manual-backup nil
)
1946 (vc-call checkout file nil version manual-backup
)))
1947 (find-file-noselect manual-backup
)))
1949 ;; Header-insertion code
1952 (defun vc-insert-headers ()
1953 "Insert headers into a file for use with a version control system.
1954 Headers desired are inserted at point, and are pulled from
1955 the variable `vc-BACKEND-header'."
1957 (vc-ensure-vc-buffer)
1961 (if (or (not (vc-check-headers))
1962 (y-or-n-p "Version headers already exist. Insert another set? "))
1964 (let* ((delims (cdr (assq major-mode vc-comment-alist
)))
1965 (comment-start-vc (or (car delims
) comment-start
"#"))
1966 (comment-end-vc (or (car (cdr delims
)) comment-end
""))
1967 (hdsym (vc-make-backend-sym (vc-backend (buffer-file-name))
1969 (hdstrings (and (boundp hdsym
) (symbol-value hdsym
))))
1971 (insert comment-start-vc
"\t" s
"\t"
1972 comment-end-vc
"\n"))
1974 (if vc-static-header-alist
1976 (if (string-match (car f
) buffer-file-name
)
1977 (insert (format (cdr f
) (car hdstrings
)))))
1978 vc-static-header-alist
))
1982 (defun vc-clear-headers (&optional file
)
1983 "Clear all version headers in the current buffer (or FILE).
1984 The headers are reset to their non-expanded form."
1985 (let* ((filename (or file buffer-file-name
))
1986 (visited (find-buffer-visiting filename
))
1987 (backend (vc-backend filename
)))
1988 (when (vc-find-backend-function backend
'clear-headers
)
1990 (let ((context (vc-buffer-context)))
1991 ;; save-excursion may be able to relocate point and mark
1992 ;; properly. If it fails, vc-restore-buffer-context
1993 ;; will give it a second try.
1995 (vc-call-backend backend
'clear-headers
))
1996 (vc-restore-buffer-context context
))
1997 (set-buffer (find-file-noselect filename
))
1998 (vc-call-backend backend
'clear-headers
)
1999 (kill-buffer filename
)))))
2003 "Merge changes between two versions into the current buffer's file.
2004 This asks for two versions to merge from in the minibuffer. If the
2005 first version is a branch number, then merge all changes from that
2006 branch. If the first version is empty, merge news, i.e. recent changes
2007 from the current branch.
2009 See Info node `Merging'."
2011 (vc-ensure-vc-buffer)
2013 (let* ((file buffer-file-name
)
2014 (backend (vc-backend file
))
2015 (state (vc-state file
))
2016 first-version second-version status
)
2019 (error "File is locked by %s" state
))
2020 ((not (vc-editable-p file
))
2022 "File must be checked out for merging. Check out now? ")
2023 (vc-checkout file t
)
2024 (error "Merge aborted"))))
2026 (read-string (concat "Branch or version to merge from "
2027 "(default: news on current branch): ")))
2028 (if (string= first-version
"")
2029 (if (not (vc-find-backend-function backend
'merge-news
))
2030 (error "Sorry, merging news is not implemented for %s" backend
)
2031 (setq status
(vc-call merge-news file
)))
2032 (if (not (vc-find-backend-function backend
'merge
))
2033 (error "Sorry, merging is not implemented for %s" backend
)
2034 (if (not (vc-branch-p first-version
))
2035 (setq second-version
2036 (read-string "Second version: "
2037 (concat (vc-branch-part first-version
) ".")))
2038 ;; We want to merge an entire branch. Set versions
2039 ;; accordingly, so that vc-BACKEND-merge understands us.
2040 (setq second-version first-version
)
2041 ;; first-version must be the starting point of the branch
2042 (setq first-version
(vc-branch-part first-version
)))
2043 (setq status
(vc-call merge file first-version second-version
))))
2044 (vc-maybe-resolve-conflicts file status
"WORKFILE" "MERGE SOURCE")))
2046 (defun vc-maybe-resolve-conflicts (file status
&optional name-A name-B
)
2047 (vc-resynch-buffer file t
(not (buffer-modified-p)))
2048 (if (zerop status
) (message "Merge successful")
2049 (if (fboundp 'smerge-mode
) (smerge-mode 1))
2050 (if (y-or-n-p "Conflicts detected. Resolve them now? ")
2051 (if (fboundp 'smerge-ediff
)
2053 (vc-resolve-conflicts name-A name-B
))
2054 (message "File contains conflict markers"))))
2056 (defvar vc-ediff-windows
)
2057 (defvar vc-ediff-result
)
2059 (defvar ediff-buffer-A
)
2060 (defvar ediff-buffer-B
)
2061 (defvar ediff-buffer-C
)
2062 (require 'ediff-util
))
2064 (defun vc-resolve-conflicts (&optional name-A name-B
)
2065 "Invoke ediff to resolve conflicts in the current buffer.
2066 The conflicts must be marked with rcsmerge conflict markers."
2068 (vc-ensure-vc-buffer)
2070 (file-name (file-name-nondirectory buffer-file-name
))
2071 (your-buffer (generate-new-buffer
2072 (concat "*" file-name
2073 " " (or name-A
"WORKFILE") "*")))
2074 (other-buffer (generate-new-buffer
2075 (concat "*" file-name
2076 " " (or name-B
"CHECKED-IN") "*")))
2077 (result-buffer (current-buffer)))
2079 (set-buffer your-buffer
)
2081 (insert-buffer result-buffer
)
2082 (goto-char (point-min))
2083 (while (re-search-forward (concat "^<<<<<<< "
2084 (regexp-quote file-name
) "\n") nil t
)
2087 (if (not (re-search-forward "^=======\n" nil t
))
2088 (error "Malformed conflict marker"))
2090 (let ((start (point)))
2091 (if (not (re-search-forward "^>>>>>>> [0-9.]+\n" nil t
))
2092 (error "Malformed conflict marker"))
2093 (delete-region start
(point))))
2096 (kill-buffer your-buffer
)
2097 (kill-buffer other-buffer
)
2098 (error "No conflict markers found")))
2099 (set-buffer other-buffer
)
2101 (insert-buffer result-buffer
)
2102 (goto-char (point-min))
2103 (while (re-search-forward (concat "^<<<<<<< "
2104 (regexp-quote file-name
) "\n") nil t
)
2105 (let ((start (match-beginning 0)))
2106 (if (not (re-search-forward "^=======\n" nil t
))
2107 (error "Malformed conflict marker"))
2108 (delete-region start
(point))
2109 (if (not (re-search-forward "^>>>>>>> [0-9.]+\n" nil t
))
2110 (error "Malformed conflict marker"))
2111 (replace-match "")))
2112 (let ((config (current-window-configuration))
2113 (ediff-default-variant 'default-B
))
2117 (set-buffer (ediff-merge-buffers your-buffer other-buffer
))
2119 ;; Ediff is now set up, and we are in the control buffer.
2120 ;; Do a few further adjustments and take precautions for exit.
2122 (make-local-variable 'vc-ediff-windows
)
2123 (setq vc-ediff-windows config
)
2124 (make-local-variable 'vc-ediff-result
)
2125 (setq vc-ediff-result result-buffer
)
2126 (make-local-variable 'ediff-quit-hook
)
2127 (setq ediff-quit-hook
2129 (let ((buffer-A ediff-buffer-A
)
2130 (buffer-B ediff-buffer-B
)
2131 (buffer-C ediff-buffer-C
)
2132 (result vc-ediff-result
)
2133 (windows vc-ediff-windows
))
2134 (ediff-cleanup-mess)
2137 (insert-buffer buffer-C
)
2138 (kill-buffer buffer-A
)
2139 (kill-buffer buffer-B
)
2140 (kill-buffer buffer-C
)
2141 (set-window-configuration windows
)
2142 (message "Conflict resolution finished; you may save the buffer"))))
2143 (message "Please resolve conflicts now; exit ediff when done")
2146 ;; The VC directory major mode. Coopt Dired for this.
2147 ;; All VC commands get mapped into logical equivalents.
2149 (defvar vc-dired-switches
)
2150 (defvar vc-dired-terse-mode
)
2152 (defvar vc-dired-mode-map
2153 (let ((map (make-sparse-keymap))
2154 (vmap (make-sparse-keymap)))
2155 (define-key map
"\C-xv" vmap
)
2156 (define-key map
"v" vmap
)
2157 (set-keymap-parent vmap vc-prefix-map
)
2158 (define-key vmap
"t" 'vc-dired-toggle-terse-mode
)
2161 (define-derived-mode vc-dired-mode dired-mode
"Dired under VC"
2162 "The major mode used in VC directory buffers.
2164 It works like Dired, but lists only files under version control, with
2165 the current VC state of each file being indicated in the place of the
2166 file's link count, owner, group and size. Subdirectories are also
2167 listed, and you may insert them into the buffer as desired, like in
2170 All Dired commands operate normally, with the exception of `v', which
2171 is redefined as the version control prefix, so that you can type
2172 `vl', `v=' etc. to invoke `vc-print-log', `vc-diff', and the like on
2173 the file named in the current Dired buffer line. `vv' invokes
2174 `vc-next-action' on this file, or on all files currently marked.
2175 There is a special command, `*l', to mark all files currently locked."
2176 ;; define-derived-mode does it for us in Emacs-21, but not in Emacs-20.
2177 ;; We do it here because dired might not be loaded yet
2178 ;; when vc-dired-mode-map is initialized.
2179 (set-keymap-parent vc-dired-mode-map dired-mode-map
)
2180 (add-hook 'dired-after-readin-hook
'vc-dired-hook nil t
)
2181 ;; The following is slightly modified from dired.el,
2182 ;; because file lines look a bit different in vc-dired-mode.
2183 (set (make-local-variable 'dired-move-to-filename-regexp
)
2185 ((l "\\([A-Za-z]\\|[^\0-\177]\\)")
2186 ;; In some locales, month abbreviations are as short as 2 letters,
2187 ;; and they can be padded on the right with spaces.
2188 (month (concat l l
"+ *"))
2189 ;; Recognize any non-ASCII character.
2190 ;; The purpose is to match a Kanji character.
2192 ;; (k "[^\x00-\x7f\x80-\xff]")
2194 (yyyy "[0-9][0-9][0-9][0-9]")
2197 (HH:MM
"[ 0-2][0-9]:[0-5][0-9]")
2198 (western (concat "\\(" month s dd
"\\|" dd s month
"\\)"
2199 s
"\\(" HH
:MM
"\\|" s yyyy
"\\|" yyyy s
"\\)"))
2200 (japanese (concat mm k s dd k s
"\\(" s HH
:MM
"\\|" yyyy k
"\\)")))
2201 ;; the .* below ensures that we find the last match on a line
2202 (concat ".*" s
"\\(" western
"\\|" japanese
"\\)" s
)))
2203 (and (boundp 'vc-dired-switches
)
2205 (set (make-local-variable 'dired-actual-switches
)
2207 (set (make-local-variable 'vc-dired-terse-mode
) vc-dired-terse-display
)
2208 (setq vc-dired-mode t
))
2210 (defun vc-dired-toggle-terse-mode ()
2211 "Toggle terse display in VC Dired."
2213 (if (not vc-dired-mode
)
2215 (setq vc-dired-terse-mode
(not vc-dired-terse-mode
))
2216 (if vc-dired-terse-mode
2220 (defun vc-dired-mark-locked ()
2221 "Mark all files currently locked."
2223 (dired-mark-if (let ((f (dired-get-filename nil t
)))
2225 (not (file-directory-p f
))
2226 (not (vc-up-to-date-p f
))))
2229 (define-key vc-dired-mode-map
"*l" 'vc-dired-mark-locked
)
2231 (defun vc-default-dired-state-info (backend file
)
2232 (let ((state (vc-state file
)))
2234 ((stringp state
) (concat "(" state
")"))
2235 ((eq state
'edited
) (concat "(" (vc-user-login-name) ")"))
2236 ((eq state
'needs-merge
) "(merge)")
2237 ((eq state
'needs-patch
) "(patch)")
2238 ((eq state
'unlocked-changes
) "(stale)"))))
2240 (defun vc-dired-reformat-line (x)
2241 "Reformat a directory-listing line.
2242 Replace various columns with version control information.
2243 This code, like dired, assumes UNIX -l format."
2245 (let ((pos (point)) limit perm date-and-file
)
2247 (setq limit
(point))
2251 (re-search-forward ;; owner and group
2252 "^\\(..[drwxlts-]+ \\) *[0-9]+ [^ ]+ +[^ ]+ +[0-9]+\\( .*\\)"
2254 (re-search-forward ;; only owner displayed
2255 "^\\(..[drwxlts-]+ \\) *[0-9]+ [^ ]+ +[0-9]+\\( .*\\)"
2257 (re-search-forward ;; OS/2 -l format, no links, owner, group
2258 "^\\(..[drwxlts-]+ \\) *[0-9]+\\( .*\\)"
2260 (setq perm
(match-string 1)
2261 date-and-file
(match-string 2))
2262 (setq x
(substring (concat x
" ") 0 10))
2263 (replace-match (concat perm x date-and-file
)))))
2265 (defun vc-dired-hook ()
2266 "Reformat the listing according to version control.
2267 Called by dired after any portion of a vc-dired buffer has been read in."
2268 (message "Getting version information... ")
2269 (let (subdir filename
(buffer-read-only nil
) cvs-dir
)
2270 (goto-char (point-min))
2273 ;; subdir header line
2274 ((setq subdir
(dired-get-subdir))
2275 ;; if the backend supports it, get the state
2276 ;; of all files in this directory at once
2277 (let ((backend (vc-responsible-backend subdir
)))
2278 (if (vc-find-backend-function backend
'dir-state
)
2279 (vc-call-backend backend
'dir-state subdir
)))
2281 ;; erase (but don't remove) the "total" line
2282 (delete-region (point) (line-end-position))
2286 ((setq filename
(dired-get-filename nil t
))
2289 ((file-directory-p filename
)
2291 ((member (file-name-nondirectory filename
)
2292 vc-directory-exclusion-list
)
2293 (let ((pos (point)))
2294 (dired-kill-tree filename
)
2297 (vc-dired-terse-mode
2298 ;; Don't show directories in terse mode. Don't use
2299 ;; dired-kill-line to remove it, because in recursive listings,
2300 ;; that would remove the directory contents as well.
2301 (delete-region (line-beginning-position)
2302 (progn (forward-line 1) (point))))
2303 ((string-match "\\`\\.\\.?\\'" (file-name-nondirectory filename
))
2306 (vc-dired-reformat-line nil
)
2309 ((and (vc-backend filename
)
2310 (not (and vc-dired-terse-mode
2311 (vc-up-to-date-p filename
))))
2312 (vc-dired-reformat-line (vc-call dired-state-info filename
))
2315 (dired-kill-line))))
2317 (t (forward-line 1))))
2319 (message "Getting version information... done")
2322 (cond ((eq (count-lines (point-min) (point-max)) 1)
2323 (goto-char (point-min))
2324 (message "No files locked under %s" default-directory
)))))
2326 (defun vc-dired-purge ()
2327 "Remove empty subdirs."
2329 (goto-char (point-min))
2330 (while (setq subdir
(dired-get-subdir))
2332 (if (dired-get-filename nil t
)
2333 (if (not (dired-next-subdir 1 t
))
2334 (goto-char (point-max)))
2336 (if (not (string= (dired-current-directory) default-directory
))
2337 (dired-do-kill-lines t
"")
2338 ;; We cannot remove the top level directory.
2339 ;; Just make it look a little nicer.
2342 (if (not (dired-next-subdir 1 t
))
2343 (goto-char (point-max))))))
2344 (goto-char (point-min))))
2346 (defun vc-dired-buffers-for-dir (dir)
2347 "Return a list of all vc-dired buffers that currently display DIR."
2349 ;; Check whether dired is loaded.
2350 (when (fboundp 'dired-buffers-for-dir
)
2351 (mapcar (lambda (buffer)
2352 (with-current-buffer buffer
2354 (setq result
(append result
(list buffer
))))))
2355 (dired-buffers-for-dir dir
)))
2358 (defun vc-dired-resynch-file (file)
2359 "Update the entries for FILE in any VC Dired buffers that list it."
2360 (let ((buffers (vc-dired-buffers-for-dir (file-name-directory file
))))
2362 (mapcar (lambda (buffer)
2363 (with-current-buffer buffer
2364 (if (dired-goto-file file
)
2365 ;; bind vc-dired-terse-mode to nil so that
2366 ;; files won't vanish when they are checked in
2367 (let ((vc-dired-terse-mode nil
))
2368 (dired-do-redisplay 1)))))
2372 (defun vc-directory (dir read-switches
)
2373 "Create a buffer in VC Dired Mode for directory DIR.
2375 See Info node `VC Dired Mode'.
2377 With prefix arg READ-SWITCHES, specify a value to override
2378 `dired-listing-switches' when generating the listing."
2379 (interactive "DDired under VC (directory): \nP")
2380 (let ((vc-dired-switches (concat vc-dired-listing-switches
2381 (if vc-dired-recurse
"R" ""))))
2383 (setq vc-dired-switches
2384 (read-string "Dired listing switches: "
2385 vc-dired-switches
)))
2387 (require 'dired-aux
)
2389 (dired-internal-noselect (expand-file-name (file-name-as-directory dir
))
2394 ;; Named-configuration entry points
2396 (defun vc-snapshot-precondition (dir)
2397 "Scan the tree below DIR, looking for files not up-to-date.
2398 If any file is not up-to-date, return the name of the first such file.
2399 \(This means, neither snapshot creation nor retrieval is allowed.\)
2400 If one or more of the files are currently visited, return `visited'.
2401 Otherwise, return nil."
2403 (catch 'vc-locked-example
2407 (if (not (vc-up-to-date-p f
)) (throw 'vc-locked-example f
)
2408 (if (get-file-buffer f
) (setq status
'visited
)))))
2412 (defun vc-create-snapshot (dir name branchp
)
2413 "Descending recursively from DIR, make a snapshot called NAME.
2414 For each registered file, the version level of its latest version
2415 becomes part of the named configuration. If the prefix argument
2416 BRANCHP is given, the snapshot is made as a new branch and the files
2417 are checked out in that new branch."
2419 (list (read-file-name "Directory: " default-directory default-directory t
)
2420 (read-string "New snapshot name: ")
2421 current-prefix-arg
))
2422 (message "Making %s... " (if branchp
"branch" "snapshot"))
2423 (if (file-directory-p dir
) (setq dir
(file-name-as-directory dir
)))
2424 (vc-call-backend (vc-responsible-backend dir
)
2425 'create-snapshot dir name branchp
)
2426 (message "Making %s... done" (if branchp
"branch" "snapshot")))
2428 (defun vc-default-create-snapshot (backend dir name branchp
)
2430 (error "VC backend %s does not support module branches" backend
))
2431 (let ((result (vc-snapshot-precondition dir
)))
2432 (if (stringp result
)
2433 (error "File %s is not up-to-date" result
)
2437 (vc-call assign-name f name
))))))
2440 (defun vc-retrieve-snapshot (dir name
)
2441 "Descending recursively from DIR, retrieve the snapshot called NAME.
2442 If NAME is empty, it refers to the latest versions.
2443 If locking is used for the files in DIR, then there must not be any
2444 locked files at or below DIR (but if NAME is empty, locked files are
2445 allowed and simply skipped)."
2447 (list (read-file-name "Directory: " default-directory default-directory t
)
2448 (read-string "Snapshot name to retrieve (default latest versions): ")))
2449 (let ((update (yes-or-no-p "Update any affected buffers? "))
2450 (msg (if (or (not name
) (string= name
""))
2451 (format "Updating %s... " (abbreviate-file-name dir
))
2452 (format "Retrieving snapshot into %s... "
2453 (abbreviate-file-name dir
)))))
2455 (vc-call-backend (vc-responsible-backend dir
)
2456 'retrieve-snapshot dir name update
)
2457 (message (concat msg
"done"))))
2459 (defun vc-default-retrieve-snapshot (backend dir name update
)
2460 (if (string= name
"")
2467 (vc-call checkout f nil
"")
2468 (if update
(vc-resynch-buffer f t t
)))))))
2469 (let ((result (vc-snapshot-precondition dir
)))
2470 (if (stringp result
)
2471 (error "File %s is locked" result
)
2472 (setq update
(and (eq result
'visited
) update
))
2475 (lambda (f) (vc-error-occurred
2476 (vc-call checkout f nil name
)
2477 (if update
(vc-resynch-buffer f t t
)))))))))
2479 ;; Miscellaneous other entry points
2482 (defun vc-print-log ()
2483 "List the change log of the current buffer in a window."
2485 (vc-ensure-vc-buffer)
2486 (let ((file buffer-file-name
))
2487 (vc-call print-log file
)
2489 (pop-to-buffer (current-buffer))
2490 (if (fboundp 'log-view-mode
) (log-view-mode))
2492 `(let ((inhibit-read-only t
))
2493 (goto-char (point-max)) (forward-line -
1)
2494 (while (looking-at "=*\n")
2495 (delete-char (- (match-end 0) (match-beginning 0)))
2497 (goto-char (point-min))
2498 (if (looking-at "[\b\t\n\v\f\r ]+")
2499 (delete-char (- (match-end 0) (match-beginning 0))))
2500 (shrink-window-if-larger-than-buffer)
2501 ;; move point to the log entry for the current version
2502 (if (fboundp 'log-view-goto-rev
)
2503 (log-view-goto-rev ',(vc-workfile-version file
))
2504 (if (vc-find-backend-function ',(vc-backend file
) 'show-log-entry
)
2505 (vc-call-backend ',(vc-backend file
)
2507 ',(vc-workfile-version file
))))
2508 (set-buffer-modified-p nil
)))))
2510 (defun vc-default-comment-history (backend file
)
2511 "Return a string with all log entries stored in BACKEND for FILE."
2512 (if (vc-find-backend-function backend
'print-log
)
2513 (with-current-buffer "*vc*"
2514 (vc-call print-log file
)
2515 (vc-call wash-log file
)
2518 (defun vc-default-wash-log (backend file
)
2519 "Remove all non-comment information from log output.
2520 This default implementation works for RCS logs; backends should override
2521 it if their logs are not in RCS format."
2522 (let ((separator (concat "^-+\nrevision [0-9.]+\ndate: .*\n"
2523 "\\(branches: .*;\n\\)?"
2524 "\\(\\*\\*\\* empty log message \\*\\*\\*\n\\)?")))
2525 (goto-char (point-max)) (forward-line -
1)
2526 (while (looking-at "=*\n")
2527 (delete-char (- (match-end 0) (match-beginning 0)))
2529 (goto-char (point-min))
2530 (if (looking-at "[\b\t\n\v\f\r ]+")
2531 (delete-char (- (match-end 0) (match-beginning 0))))
2532 (goto-char (point-min))
2533 (re-search-forward separator nil t
)
2534 (delete-region (point-min) (point))
2535 (while (re-search-forward separator nil t
)
2536 (delete-region (match-beginning 0) (match-end 0)))))
2539 (defun vc-revert-buffer ()
2540 "Revert the current buffer's file to the version it was based on.
2541 This asks for confirmation if the buffer contents are not identical
2542 to that version. This function does not automatically pick up newer
2543 changes found in the master file; use \\[universal-argument] \\[vc-next-action] to do so."
2545 (vc-ensure-vc-buffer)
2546 ;; Make sure buffer is saved. If the user says `no', abort since
2547 ;; we cannot show the changes and ask for confirmation to discard them.
2548 (vc-buffer-sync nil
)
2549 (let ((file buffer-file-name
)
2550 ;; This operation should always ask for confirmation.
2551 (vc-suppress-confirm nil
)
2552 (obuf (current-buffer))
2554 (if (vc-up-to-date-p file
)
2555 (unless (yes-or-no-p "File seems up-to-date. Revert anyway? ")
2556 (error "Revert canceled")))
2557 (unless (vc-workfile-unchanged-p file
)
2558 ;; vc-diff selects the new window, which is not what we want:
2559 ;; if the new window is on another frame, that'd require the user
2560 ;; moving her mouse to answer the yes-or-no-p question.
2561 (let ((win (save-selected-window
2562 (setq status
(vc-diff nil t
)) (selected-window))))
2563 (vc-exec-after `(message nil
))
2566 (unless (yes-or-no-p "Discard changes? ")
2567 (error "Revert canceled"))
2569 (if (one-window-p t
)
2570 (if (window-dedicated-p (selected-window))
2571 (make-frame-invisible))
2572 (delete-window))))))
2575 (message "Reverting %s..." file
)
2576 (vc-revert-file file
)
2577 (message "Reverting %s...done" file
)))
2581 "Update the current buffer's file to the latest version on its branch.
2582 If the file contains no changes, and is not locked, then this simply replaces
2583 the working file with the latest version on its branch. If the file contains
2584 changes, and the backend supports merging news, then any recent changes from
2585 the current branch are merged into the working file."
2587 (vc-ensure-vc-buffer)
2588 (vc-buffer-sync nil
)
2589 (let ((file buffer-file-name
))
2590 (if (vc-up-to-date-p file
)
2591 (vc-checkout file nil
"")
2592 (if (eq (vc-checkout-model file
) 'locking
)
2593 (if (eq (vc-state file
) 'edited
)
2595 (substitute-command-keys
2596 "File is locked--type \\[vc-revert-buffer] to discard changes"))
2598 (substitute-command-keys
2599 "Unexpected file state (%s)--type \\[vc-next-action] to correct")
2601 (if (not (vc-find-backend-function (vc-backend file
) 'merge-news
))
2602 (error "Sorry, merging news is not implemented for %s"
2604 (vc-call merge-news file
)
2605 (vc-resynch-window file t t
))))))
2607 (defun vc-version-backup-file (file &optional rev
)
2608 "Return name of backup file for revision REV of FILE.
2609 If version backups should be used for FILE, and there exists
2610 such a backup for REV or the current workfile version of file,
2611 return its name; otherwise return nil."
2612 (when (vc-call make-version-backups-p file
)
2613 (let ((backup-file (vc-version-backup-file-name file rev
)))
2614 (if (file-exists-p backup-file
)
2616 ;; there is no automatic backup, but maybe the user made one manually
2617 (setq backup-file
(vc-version-backup-file-name file rev
'manual
))
2618 (if (file-exists-p backup-file
)
2621 (defun vc-revert-file (file)
2622 "Revert FILE back to the version it was based on."
2625 (let ((backup-file (vc-version-backup-file file
)))
2627 (copy-file backup-file file
'ok-if-already-exists
'keep-date
)
2628 (vc-delete-automatic-version-backups file
))
2629 (vc-call revert file backup-file
))
2630 `((vc-state . up-to-date
)
2631 (vc-checkout-time .
,(nth 5 (file-attributes file
)))))
2632 (vc-resynch-buffer file t t
))
2635 (defun vc-cancel-version (norevert)
2636 "Get rid of most recently checked in version of this file.
2637 A prefix argument NOREVERT means do not revert the buffer afterwards."
2639 (vc-ensure-vc-buffer)
2640 (let* ((file (buffer-file-name))
2641 (backend (vc-backend file
))
2642 (target (vc-workfile-version file
))
2643 (config (current-window-configuration)) done
)
2645 ((not (vc-find-backend-function backend
'cancel-version
))
2646 (error "Sorry, canceling versions is not supported under %s" backend
))
2647 ((not (vc-call latest-on-branch-p file
))
2648 (error "This is not the latest version; VC cannot cancel it"))
2649 ((not (vc-up-to-date-p file
))
2650 (error (substitute-command-keys "File is not up to date; use \\[vc-revert-buffer] to discard changes"))))
2651 (if (null (yes-or-no-p (format "Remove version %s from master? " target
)))
2653 (setq norevert
(or norevert
(not
2654 (yes-or-no-p "Revert buffer to most recent remaining version? "))))
2656 (message "Removing last change from %s..." file
)
2659 (vc-call cancel-version file norevert
)
2660 `((vc-state .
,(if norevert
'edited
'up-to-date
))
2661 (vc-checkout-time .
,(if norevert
2663 (nth 5 (file-attributes file
))))
2664 (vc-workfile-version . nil
)))
2665 (message "Removing last change from %s...done" file
)
2668 (norevert ;; clear version headers and mark the buffer modified
2669 (set-visited-file-name file
)
2670 (when (not vc-make-backup-files
)
2671 ;; inhibit backup for this buffer
2672 (make-local-variable 'backup-inhibited
)
2673 (setq backup-inhibited t
))
2674 (setq buffer-read-only nil
)
2677 (vc-dired-resynch-file file
))
2678 (t ;; revert buffer to file on disk
2679 (vc-resynch-buffer file t t
)))
2680 (message "Version %s has been removed from the master" target
))))
2683 (defun vc-switch-backend (file backend
)
2684 "Make BACKEND the current version control system for FILE.
2685 FILE must already be registered in BACKEND. The change is not
2686 permanent, only for the current session. This function only changes
2687 VC's perspective on FILE, it does not register or unregister it.
2688 By default, this command cycles through the registered backends.
2689 To get a prompt, use a prefix argument."
2693 (let ((backend (vc-backend buffer-file-name
))
2695 ;; Find the registered backends.
2696 (dolist (backend vc-handled-backends
)
2697 (when (vc-call-backend backend
'registered buffer-file-name
)
2698 (push backend backends
)))
2699 ;; Find the next backend.
2700 (let ((def (car (delq backend
(append (memq backend backends
) backends
))))
2701 (others (delete backend backends
)))
2703 ((null others
) (error "No other backend to switch to"))
2708 (format "Switch to backend [%s]: " def
)
2709 (mapcar (lambda (b) (list (downcase (symbol-name b
)))) backends
)
2710 nil t nil nil
(downcase (symbol-name def
))))))
2712 (unless (eq backend
(vc-backend file
))
2713 (vc-file-clearprops file
)
2714 (vc-file-setprop file
'vc-backend backend
)
2715 ;; Force recomputation of the state
2716 (unless (vc-call-backend backend
'registered file
)
2717 (vc-file-clearprops file
)
2718 (error "%s is not registered in %s" file backend
))
2719 (vc-mode-line file
)))
2722 (defun vc-transfer-file (file new-backend
)
2723 "Transfer FILE to another version control system NEW-BACKEND.
2724 If NEW-BACKEND has a higher precedence than FILE's current backend
2725 \(i.e. it comes earlier in `vc-handled-backends'), then register FILE in
2726 NEW-BACKEND, using the version number from the current backend as the
2727 base level. If NEW-BACKEND has a lower precedence than the current
2728 backend, then commit all changes that were made under the current
2729 backend to NEW-BACKEND, and unregister FILE from the current backend.
2730 \(If FILE is not yet registered under NEW-BACKEND, register it.)"
2731 (let* ((old-backend (vc-backend file
))
2732 (edited (memq (vc-state file
) '(edited needs-merge
)))
2733 (registered (vc-call-backend new-backend
'registered file
))
2735 (and registered
; Never move if not registered in new-backend yet.
2736 ;; move if new-backend comes later in vc-handled-backends
2737 (or (memq new-backend
(memq old-backend vc-handled-backends
))
2738 (y-or-n-p "Final transfer? "))))
2740 (if (eq old-backend new-backend
)
2741 (error "%s is the current backend of %s" new-backend file
))
2743 (set-file-modes file
(logior (file-modes file
) 128))
2744 ;; `registered' might have switched under us.
2745 (vc-switch-backend file old-backend
)
2746 (let* ((rev (vc-workfile-version file
))
2747 (modified-file (and edited
(make-temp-file file
)))
2748 (unmodified-file (and modified-file
(vc-version-backup-file file
))))
2749 ;; Go back to the base unmodified file.
2753 (copy-file file modified-file
'ok-if-already-exists
)
2754 ;; If we have a local copy of the unmodified file, handle that
2755 ;; here and not in vc-revert-file because we don't want to
2756 ;; delete that copy -- it is still useful for OLD-BACKEND.
2758 (copy-file unmodified-file file
'ok-if-already-exists
)
2759 (if (y-or-n-p "Get base version from master? ")
2760 (vc-revert-file file
))))
2761 (vc-call-backend new-backend
'receive-file file rev
))
2763 (vc-switch-backend file new-backend
)
2764 (unless (eq (vc-checkout-model file
) 'implicit
)
2765 (vc-checkout file t nil
))
2766 (rename-file modified-file file
'ok-if-already-exists
)
2767 (vc-file-setprop file
'vc-checkout-time nil
)))))
2769 (vc-switch-backend file old-backend
)
2770 (setq comment
(vc-call comment-history file
))
2771 (vc-call unregister file
))
2772 (vc-switch-backend file new-backend
)
2773 (when (or move edited
)
2774 (vc-file-setprop file
'vc-state
'edited
)
2776 (vc-checkin file nil comment
(stringp comment
)))))
2778 (defun vc-default-unregister (backend file
)
2779 "Default implementation of `vc-unregister', signals an error."
2780 (error "Unregistering files is not supported for %s" backend
))
2782 (defun vc-default-receive-file (backend file rev
)
2783 "Let BACKEND receive FILE from another version control system."
2784 (vc-call-backend backend
'register file rev
""))
2786 (defun vc-rename-master (oldmaster newfile templates
)
2787 "Rename OLDMASTER to be the master file for NEWFILE based on TEMPLATES."
2788 (let* ((dir (file-name-directory (expand-file-name oldmaster
)))
2789 (newdir (or (file-name-directory newfile
) ""))
2790 (newbase (file-name-nondirectory newfile
))
2792 ;; List of potential master files for `newfile'
2794 (lambda (s) (vc-possible-master s newdir newbase
))
2796 (if (or (file-symlink-p oldmaster
)
2797 (file-symlink-p (file-name-directory oldmaster
)))
2798 (error "This is unsafe in the presence of symbolic links"))
2802 ;; If possible, keep the master file in the same directory.
2804 (if (and f
(string= (file-name-directory (expand-file-name f
))
2808 ;; If not, just use the first possible place.
2811 (or (not (setq dir
(file-name-directory f
)))
2812 (file-directory-p dir
))
2815 (error "New file lacks a version control directory")))))
2818 (defun vc-rename-file (old new
)
2819 "Rename file OLD to NEW, and rename its master file likewise."
2820 (interactive "fVC rename file: \nFRename to: ")
2821 (let ((oldbuf (get-file-buffer old
))
2822 (backend (vc-backend old
)))
2823 (unless (or (null backend
) (vc-find-backend-function backend
'rename-file
))
2824 (error "Renaming files under %s is not supported in VC" backend
))
2825 (if (and oldbuf
(buffer-modified-p oldbuf
))
2826 (error "Please save files before moving them"))
2827 (if (get-file-buffer new
)
2828 (error "Already editing new file name"))
2829 (if (file-exists-p new
)
2830 (error "New file already exists"))
2832 (if (and backend
(not (vc-up-to-date-p old
)))
2833 (error "Please check in files before moving them"))
2834 (vc-call-backend backend
'rename-file old new
))
2835 ;; Move the actual file (unless the backend did it already)
2836 (if (or (not backend
) (file-exists-p old
))
2837 (rename-file old new
))
2838 ;; ?? Renaming a file might change its contents due to keyword expansion.
2839 ;; We should really check out a new copy if the old copy was precisely equal
2840 ;; to some checked in version. However, testing for this is tricky....
2842 (with-current-buffer oldbuf
2843 (let ((buffer-read-only buffer-read-only
))
2844 (set-visited-file-name new
))
2847 (set-buffer-modified-p nil
)))))
2849 ;; Only defined in very recent Emacsen
2850 (defvar small-temporary-file-directory nil
)
2853 (defun vc-update-change-log (&rest args
)
2854 "Find change log file and add entries from recent version control logs.
2855 Normally, find log entries for all registered files in the default
2858 With prefix arg of \\[universal-argument], only find log entries for the current buffer's file.
2860 With any numeric prefix arg, find log entries for all currently visited
2861 files that are under version control. This puts all the entries in the
2862 log for the default directory, which may not be appropriate.
2864 From a program, any ARGS are assumed to be filenames for which
2865 log entries should be gathered."
2867 (cond ((consp current-prefix-arg
) ;C-u
2868 (list buffer-file-name
))
2869 (current-prefix-arg ;Numeric argument.
2871 (buffers (buffer-list))
2874 (setq file
(buffer-file-name (car buffers
)))
2875 (and file
(vc-backend file
)
2876 (setq files
(cons file files
)))
2877 (setq buffers
(cdr buffers
)))
2880 ;; Don't supply any filenames to backend; this means
2881 ;; it should find all relevant files relative to
2882 ;; the default-directory.
2884 (vc-call-backend (vc-responsible-backend default-directory
)
2885 'update-changelog args
))
2887 (defun vc-default-update-changelog (backend files
)
2888 "Default implementation of update-changelog.
2889 Uses `rcs2log' which only works for RCS and CVS."
2890 ;; FIXME: We (c|sh)ould add support for cvs2cl
2891 (let ((odefault default-directory
)
2892 (changelog (find-change-log))
2893 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
2894 (tempfile (make-temp-file
2895 (expand-file-name "vc"
2896 (or small-temporary-file-directory
2897 temporary-file-directory
))))
2898 (full-name (or add-log-full-name
2901 (format "uid%d" (number-to-string (user-uid)))))
2902 (mailing-address (or add-log-mailing-address
2903 user-mail-address
)))
2904 (find-file-other-window changelog
)
2905 (barf-if-buffer-read-only)
2908 (goto-char (point-min))
2910 (message "Computing change log entries...")
2911 (message "Computing change log entries... %s"
2914 (setq default-directory odefault
)
2915 (if (eq 0 (apply 'call-process
2916 (expand-file-name "rcs2log"
2918 nil
(list t tempfile
) nil
2920 "-u" (concat (vc-user-login-name)
2922 "\t" mailing-address
)
2926 (if (file-name-absolute-p f
)
2928 (concat odefault f
))))
2932 (set-buffer (get-buffer-create "*vc*")))
2934 (insert-file tempfile
)
2936 (setq default-directory
(file-name-directory changelog
))
2937 (delete-file tempfile
)))))
2939 ;; Annotate functionality
2941 ;; Declare globally instead of additional parameter to
2942 ;; temp-buffer-show-function (not possible to pass more than one
2943 ;; parameter). The use of annotate-ratio is deprecated in favor of
2944 ;; annotate-mode, which replaces it with the more sensible "span-to
2945 ;; days", along with autoscaling support.
2946 (defvar vc-annotate-ratio nil
"Global variable.")
2947 (defvar vc-annotate-backend nil
"Global variable.")
2949 (defconst vc-annotate-font-lock-keywords
2950 ;; The fontification is done by vc-annotate-lines instead of font-lock.
2951 '((vc-annotate-lines)))
2953 (defun vc-annotate-get-backend (buffer)
2954 "Return the backend matching \"Annotate\" buffer BUFFER.
2955 Return nil if no match made. Associations are made based on
2956 `vc-annotate-buffers'."
2957 (cdr (assoc buffer vc-annotate-buffers
)))
2959 (define-derived-mode vc-annotate-mode fundamental-mode
"Annotate"
2960 "Major mode for output buffers of the `vc-annotate' command.
2962 You can use the mode-specific menu to alter the time-span of the used
2963 colors. See variable `vc-annotate-menu-elements' for customizing the
2965 (set (make-local-variable 'truncate-lines
) t
)
2966 (set (make-local-variable 'font-lock-defaults
)
2967 '(vc-annotate-font-lock-keywords t
))
2968 (vc-annotate-add-menu))
2970 (defun vc-annotate-display-default (&optional ratio
)
2971 "Display the output of \\[vc-annotate] using the default color range.
2972 The color range is given by `vc-annotate-color-map', scaled by RATIO
2973 if present. The current time is used as the offset."
2975 (message "Redisplaying annotation...")
2976 (vc-annotate-display
2977 (if ratio
(vc-annotate-time-span vc-annotate-color-map ratio
)))
2978 (message "Redisplaying annotation...done"))
2980 (defun vc-annotate-display-autoscale (&optional full
)
2981 "Highlight the output of \\[vc-annotate]] using an autoscaled color map.
2982 Autoscaling means that the map is scaled from the current time to the
2983 oldest annotation in the buffer, or, with argument FULL non-nil, to
2984 cover the range from the oldest annotation to the newest."
2987 (oldest 999999.
) ;Any CVS users at the founding of Rome?
2988 (current (vc-annotate-convert-time (current-time)))
2990 (message "Redisplaying annotation...")
2991 ;; Run through this file and find the oldest and newest dates annotated.
2993 (goto-char (point-min))
2994 (while (setq date
(vc-call-backend vc-annotate-backend
'annotate-time
))
2998 (setq oldest date
))))
2999 (vc-annotate-display
3000 (vc-annotate-time-span ;return the scaled colormap.
3001 vc-annotate-color-map
3002 (/ (- (if full newest current
) oldest
)
3003 (vc-annotate-car-last-cons vc-annotate-color-map
)))
3005 (message "Redisplaying annotation...done \(%s\)"
3007 (format "Spanned from %.1f to %.1f days old"
3010 (format "Spanned to %.1f days old" (- current oldest
))))))
3012 ;; Menu -- Using easymenu.el
3013 (defun vc-annotate-add-menu ()
3014 "Add the menu 'Annotate' to the menu bar in VC-Annotate mode."
3015 (let ((menu-elements vc-annotate-menu-elements
)
3018 ["Default" (unless (null vc-annotate-display-mode
)
3019 (setq vc-annotate-display-mode nil
)
3020 (vc-annotate-display-select))
3021 :style toggle
:selected
(null vc-annotate-display-mode
)]))
3022 (oldest-in-map (vc-annotate-car-last-cons vc-annotate-color-map
)))
3023 (while menu-elements
3024 (let* ((element (car menu-elements
))
3025 (days (* element oldest-in-map
)))
3026 (setq menu-elements
(cdr menu-elements
))
3029 `([,(format "Span %.1f days" days
)
3030 (unless (and (numberp vc-annotate-display-mode
)
3031 (= vc-annotate-display-mode
,days
))
3032 (vc-annotate-display-select nil
,days
))
3033 :style toggle
:selected
3034 (and (numberp vc-annotate-display-mode
)
3035 (= vc-annotate-display-mode
,days
)) ])))))
3041 (float (string-to-number
3042 (read-string "Span how many days? ")))))
3043 (vc-annotate-display-select nil days
)) t
])
3047 (unless (eq vc-annotate-display-mode
'scale
)
3048 (vc-annotate-display-select nil
'scale
))
3049 :style toggle
:selected
3050 (eq vc-annotate-display-mode
'scale
)])
3052 ["Span Oldest->Newest"
3053 (unless (eq vc-annotate-display-mode
'fullscale
)
3054 (vc-annotate-display-select nil
'fullscale
))
3055 :style toggle
:selected
3056 (eq vc-annotate-display-mode
'fullscale
)])))
3058 (if (or (featurep 'easymenu
) (load "easymenu" t
))
3059 (easy-menu-define vc-annotate-mode-menu vc-annotate-mode-map
3060 "VC Annotate Display Menu" menu-def
))))
3062 (defun vc-annotate-display-select (&optional buffer mode
)
3063 "Highlight the output of \\[vc-annotate].
3064 By default, the current buffer is highlighted, unless overridden by
3065 BUFFER. `vc-annotate-display-mode' specifies the highlighting mode to
3066 use; you may override this using the second optional arg MODE."
3068 (if mode
(setq vc-annotate-display-mode mode
))
3071 (display-buffer buffer
))
3072 (if (not vc-annotate-mode
) ; Turn on vc-annotate-mode if not done
3074 (cond ((null vc-annotate-display-mode
)
3075 (vc-annotate-display-default vc-annotate-ratio
))
3076 ;; One of the auto-scaling modes
3077 ((eq vc-annotate-display-mode
'scale
)
3078 (vc-annotate-display-autoscale))
3079 ((eq vc-annotate-display-mode
'fullscale
)
3080 (vc-annotate-display-autoscale t
))
3081 ((numberp vc-annotate-display-mode
) ; A fixed number of days lookback
3082 (vc-annotate-display-default
3083 (/ vc-annotate-display-mode
(vc-annotate-car-last-cons
3084 vc-annotate-color-map
))))
3085 (t (error "No such display mode: %s"
3086 vc-annotate-display-mode
))))
3088 ;;;; (defun vc-BACKEND-annotate-command (file buffer) ...)
3089 ;;;; Execute "annotate" on FILE by using `call-process' and insert
3090 ;;;; the contents in BUFFER.
3093 (defun vc-annotate (prefix)
3094 "Display the edit history of the current file using colours.
3096 This command creates a buffer that shows, for each line of the current
3097 file, when it was last edited and by whom. Additionally, colours are
3098 used to show the age of each line--blue means oldest, red means
3099 youngest, and intermediate colours indicate intermediate ages. By
3100 default, the time scale stretches back one year into the past;
3101 everything that is older than that is shown in blue.
3103 With a prefix argument, this command asks two questions in the
3104 minibuffer. First, you may enter a version number; then the buffer
3105 displays and annotates that version instead of the current version
3106 \(type RET in the minibuffer to leave that default unchanged). Then,
3107 you are prompted for the time span in days which the color range
3108 should cover. For example, a time span of 20 days means that changes
3109 over the past 20 days are shown in red to blue, according to their
3110 age, and everything that is older than that is shown in blue.
3112 Customization variables:
3114 `vc-annotate-menu-elements' customizes the menu elements of the
3115 mode-specific menu. `vc-annotate-color-map' and
3116 `vc-annotate-very-old-color' defines the mapping of time to
3117 colors. `vc-annotate-background' specifies the background color."
3119 (vc-ensure-vc-buffer)
3120 (let* ((temp-buffer-name (concat "*Annotate " (buffer-name) "*"))
3121 (temp-buffer-show-function 'vc-annotate-display-select
)
3122 (rev (vc-workfile-version (buffer-file-name)))
3123 (vc-annotate-version
3124 (if prefix
(read-string
3125 (format "Annotate from version: (default %s) " rev
)
3129 (setq vc-annotate-display-mode
3130 (float (string-to-number
3131 (read-string "Annotate span days: (default 20) "
3133 (setq vc-annotate-backend
(vc-backend (buffer-file-name)))
3134 (message "Annotating...")
3135 (if (not (vc-find-backend-function vc-annotate-backend
'annotate-command
))
3136 (error "Sorry, annotating is not implemented for %s"
3137 vc-annotate-backend
))
3138 (with-output-to-temp-buffer temp-buffer-name
3139 (vc-call-backend vc-annotate-backend
'annotate-command
3140 (file-name-nondirectory (buffer-file-name))
3141 (get-buffer temp-buffer-name
)
3142 vc-annotate-version
))
3143 ;; Don't use the temp-buffer-name until the buffer is created
3144 ;; (only after `with-output-to-temp-buffer'.)
3145 (setq vc-annotate-buffers
3146 (append vc-annotate-buffers
3147 (list (cons (get-buffer temp-buffer-name
) vc-annotate-backend
))))
3148 (message "Annotating... done")))
3150 (defun vc-annotate-car-last-cons (a-list)
3151 "Return car of last cons in association list A-LIST."
3152 (if (not (eq nil
(cdr a-list
)))
3153 (vc-annotate-car-last-cons (cdr a-list
))
3154 (car (car a-list
))))
3156 (defun vc-annotate-time-span (a-list span
&optional quantize
)
3157 "Apply factor SPAN to the time-span of association list A-LIST.
3158 Return the new alist.
3159 Optionally quantize to the factor of QUANTIZE."
3160 ;; Apply span to each car of every cons
3161 (if (not (eq nil a-list
))
3162 (append (list (cons (* (car (car a-list
)) span
)
3163 (cdr (car a-list
))))
3164 (vc-annotate-time-span (nthcdr (or quantize
; optional
3166 a-list
) span quantize
))))
3168 (defun vc-annotate-compcar (threshold a-list
)
3169 "Test successive cons cells of A-LIST against THRESHOLD.
3170 Return the first cons cell with a car that is not less than THRESHOLD,
3171 nil if no such cell exists."
3173 (tmp-cons (car a-list
)))
3174 (while (and tmp-cons
(< (car tmp-cons
) threshold
))
3175 (setq tmp-cons
(car (nthcdr i a-list
)))
3177 tmp-cons
)) ; Return the appropriate value
3179 (defun vc-annotate-convert-time (time)
3180 "Convert a time value to a floating-point number of days.
3181 The argument TIME is a list as returned by `current-time' or
3182 `encode-time', only the first two elements of that list are considered."
3183 (/ (+ (* (float (car time
)) (lsh 1 16)) (cadr time
)) 24 3600))
3185 (defun vc-annotate-difference (&optional offset
)
3186 "Return the time span in days to the next annotation.
3187 This calls the backend function annotate-time, and returns the
3188 difference in days between the time returned and the current time,
3189 or OFFSET if present."
3190 (let ((next-time (vc-call-backend vc-annotate-backend
'annotate-time
)))
3193 (vc-call-backend vc-annotate-backend
'annotate-current-time
))
3196 (defun vc-default-annotate-current-time (backend)
3197 "Return the current time, encoded as fractional days."
3198 (vc-annotate-convert-time (current-time)))
3200 (defun vc-annotate-display (&optional color-map offset
)
3201 "Highlight `vc-annotate' output in the current buffer.
3202 COLOR-MAP, if present, overrides `vc-annotate-color-map'.
3203 The annotations are relative to the current time, unless overridden by OFFSET.
3205 This function is obsolete, and has been replaced by
3206 `vc-annotate-display-select'."
3207 (if (and color-map
(not (eq color-map vc-annotate-color-map
)))
3208 (set (make-local-variable 'vc-annotate-color-map
) color-map
))
3209 (set (make-local-variable 'vc-annotate-offset
) offset
)
3212 (defvar vc-annotate-offset nil
)
3214 (defun vc-annotate-lines (limit)
3216 (while (and (< (point) limit
)
3217 (setq difference
(vc-annotate-difference vc-annotate-offset
)))
3218 (let* ((color (or (vc-annotate-compcar difference vc-annotate-color-map
)
3219 (cons nil vc-annotate-very-old-color
)))
3220 ;; substring from index 1 to remove any leading `#' in the name
3221 (face-name (concat "vc-annotate-face-" (substring (cdr color
) 1)))
3222 ;; Make the face if not done.
3223 (face (or (intern-soft face-name
)
3224 (let ((tmp-face (make-face (intern face-name
))))
3225 (set-face-foreground tmp-face
(cdr color
))
3226 (if vc-annotate-background
3227 (set-face-background tmp-face
3228 vc-annotate-background
))
3229 tmp-face
))) ; Return the face
3233 (put-text-property point
(point) 'face face
)))
3234 ;; Pretend to font-lock there were no matches.
3237 ;; Collect back-end-dependent stuff here
3239 (defalias 'vc-default-logentry-check
'ignore
)
3241 (defun vc-check-headers ()
3242 "Check if the current file has any headers in it."
3244 (vc-call-backend (vc-backend buffer-file-name
) 'check-headers
))
3246 (defun vc-default-check-headers (backend)
3247 "Default implementation of check-headers; always returns nil."
3250 ;; Back-end-dependent stuff ends here.
3252 ;; Set up key bindings for use while editing log messages
3254 (define-derived-mode vc-log-mode text-mode
"VC-Log"
3255 "Major mode for editing VC log entries.
3256 These bindings are added to the global keymap when you enter this mode:
3257 \\[vc-next-action] perform next logical version-control operation on current file
3258 \\[vc-register] register current file
3259 \\[vc-insert-headers] insert version-control headers in current file
3260 \\[vc-print-log] display change history of current file
3261 \\[vc-revert-buffer] revert buffer to latest version
3262 \\[vc-cancel-version] undo latest checkin
3263 \\[vc-diff] show diffs between file versions
3264 \\[vc-version-other-window] visit old version in another window
3265 \\[vc-directory] show all files locked by any user in or below .
3266 \\[vc-annotate] colorful display of the cvs annotate command
3267 \\[vc-update-change-log] add change log entry from recent checkins
3269 While you are entering a change log message for a version, the following
3270 additional bindings will be in effect.
3272 \\[vc-finish-logentry] proceed with check in, ending log message entry
3274 Whenever you do a checkin, your log comment is added to a ring of
3275 saved comments. These can be recalled as follows:
3277 \\[vc-next-comment] replace region with next message in comment ring
3278 \\[vc-previous-comment] replace region with previous message in comment ring
3279 \\[vc-comment-search-reverse] search backward for regexp in the comment ring
3280 \\[vc-comment-search-forward] search backward for regexp in the comment ring
3282 Entry to the change-log submode calls the value of `text-mode-hook', then
3283 the value of `vc-log-mode-hook'.
3285 Global user options:
3286 `vc-initial-comment' If non-nil, require user to enter a change
3287 comment upon first checkin of the file.
3289 `vc-keep-workfiles' Non-nil value prevents workfiles from being
3290 deleted when changes are checked in
3292 `vc-suppress-confirm' Suppresses some confirmation prompts.
3294 vc-BACKEND-header Which keywords to insert when adding headers
3295 with \\[vc-insert-headers]. Defaults to
3296 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under
3299 `vc-static-header-alist' By default, version headers inserted in C files
3300 get stuffed in a static string area so that
3301 ident(RCS/CVS) or what(SCCS) can see them in
3302 the compiled object code. You can override
3303 this by setting this variable to nil, or change
3304 the header template by changing it.
3306 `vc-command-messages' if non-nil, display run messages from the
3307 actual version-control utilities (this is
3308 intended primarily for people hacking vc
3310 (make-local-variable 'vc-comment-ring-index
))
3312 (defun vc-log-edit (file)
3313 "Set up `log-edit' for use with VC on FILE.
3314 If `log-edit' is not available, resort to `vc-log-mode'."
3315 (setq default-directory
3316 (if file
(file-name-directory file
)
3317 (with-current-buffer vc-parent-buffer default-directory
)))
3318 (if (fboundp 'log-edit
)
3319 (log-edit 'vc-finish-logentry nil
3320 (if file
`(lambda () ',(list (file-name-nondirectory file
)))
3321 ;; If FILE is nil, we were called from vc-dired.
3323 (with-current-buffer vc-parent-buffer
3324 (dired-get-marked-files t
)))))
3326 (set (make-local-variable 'vc-log-file
) file
)
3327 (make-local-variable 'vc-log-version
)
3328 (set-buffer-modified-p nil
)
3329 (setq buffer-file-name nil
))
3331 ;; These things should probably be generally available
3333 (defun vc-file-tree-walk (dirname func
&rest args
)
3334 "Walk recursively through DIRNAME.
3335 Invoke FUNC f ARGS on each VC-managed file f underneath it."
3336 (vc-file-tree-walk-internal (expand-file-name dirname
) func args
)
3337 (message "Traversing directory %s...done" dirname
))
3339 (defun vc-file-tree-walk-internal (file func args
)
3340 (if (not (file-directory-p file
))
3341 (if (vc-backend file
) (apply func file args
))
3342 (message "Traversing directory %s..." (abbreviate-file-name file
))
3343 (let ((dir (file-name-as-directory file
)))
3346 (string-equal f
".")
3347 (string-equal f
"..")
3348 (member f vc-directory-exclusion-list
)
3349 (let ((dirf (expand-file-name f dir
)))
3351 (file-symlink-p dirf
);; Avoid possible loops
3352 (vc-file-tree-walk-internal dirf func args
)))))
3353 (directory-files dir
)))))
3357 ;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
3359 ;; These may be useful to anyone who has to debug or extend the package.
3360 ;; (Note that this information corresponds to versions 5.x. Some of it
3361 ;; might have been invalidated by the additions to support branching
3362 ;; and RCS keyword lookup. AS, 1995/03/24)
3364 ;; A fundamental problem in VC is that there are time windows between
3365 ;; vc-next-action's computations of the file's version-control state and
3366 ;; the actions that change it. This is a window open to lossage in a
3367 ;; multi-user environment; someone else could nip in and change the state
3368 ;; of the master during it.
3370 ;; The performance problem is that rlog/prs calls are very expensive; we want
3371 ;; to avoid them as much as possible.
3375 ;; The performance problem, it turns out, simplifies in practice to the
3376 ;; problem of making vc-state fast. The two other functions that call
3377 ;; prs/rlog will not be so commonly used that the slowdown is a problem; one
3378 ;; makes snapshots, the other deletes the calling user's last change in the
3381 ;; The race condition implies that we have to either (a) lock the master
3382 ;; during the entire execution of vc-next-action, or (b) detect and
3383 ;; recover from errors resulting from dispatch on an out-of-date state.
3385 ;; Alternative (a) appears to be infeasible. The problem is that we can't
3386 ;; guarantee that the lock will ever be removed. Suppose a user starts a
3387 ;; checkin, the change message buffer pops up, and the user, having wandered
3388 ;; off to do something else, simply forgets about it?
3390 ;; Alternative (b), on the other hand, works well with a cheap way to speed up
3391 ;; vc-state. Usually, if a file is registered, we can read its locked/
3392 ;; unlocked state and its current owner from its permissions.
3394 ;; This shortcut will fail if someone has manually changed the workfile's
3395 ;; permissions; also if developers are munging the workfile in several
3396 ;; directories, with symlinks to a master (in this latter case, the
3397 ;; permissions shortcut will fail to detect a lock asserted from another
3400 ;; Note that these cases correspond exactly to the errors which could happen
3401 ;; because of a competing checkin/checkout race in between two instances of
3404 ;; For VC's purposes, a workfile/master pair may have the following states:
3406 ;; A. Unregistered. There is a workfile, there is no master.
3408 ;; B. Registered and not locked by anyone.
3410 ;; C. Locked by calling user and unchanged.
3412 ;; D. Locked by the calling user and changed.
3414 ;; E. Locked by someone other than the calling user.
3416 ;; This makes for 25 states and 20 error conditions. Here's the matrix:
3418 ;; VC's idea of state
3420 ;; V Actual state RCS action SCCS action Effect
3422 ;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
3423 ;; B 5 . 6 7 8 co -l get -e checkout
3424 ;; C 9 10 . 11 12 co -u unget; get revert
3425 ;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
3426 ;; E 17 18 19 20 . rcs -u -M -l unget -n ; get -g steal lock
3428 ;; All commands take the master file name as a last argument (not shown).
3430 ;; In the discussion below, a "self-race" is a pathological situation in
3431 ;; which VC operations are being attempted simultaneously by two or more
3432 ;; Emacsen running under the same username.
3434 ;; The vc-next-action code has the following windows:
3437 ;; Between the check for existence of a master file and the call to
3438 ;; admin/checkin in vc-buffer-admin (apparent state A). This window may
3439 ;; never close if the initial-comment feature is on.
3442 ;; Between the call to vc-workfile-unchanged-p in and the immediately
3443 ;; following revert (apparent state C).
3446 ;; Between the call to vc-workfile-unchanged-p in and the following
3447 ;; checkin (apparent state D). This window may never close.
3450 ;; Between the unlock and the immediately following checkout during a
3451 ;; revert operation (apparent state C). Included in window Q.
3454 ;; Between vc-state and the following checkout (apparent state B).
3457 ;; Between vc-state and the following revert (apparent state C).
3458 ;; Includes windows Q and S.
3461 ;; Between vc-state and the following checkin (apparent state
3462 ;; D). This window may never be closed if the user fails to complete the
3463 ;; checkin message. Includes window R.
3466 ;; Between vc-state and the following steal-lock (apparent
3467 ;; state E). This window may never close if the user fails to complete
3468 ;; the steal-lock message. Includes window X.
3471 ;; Between the unlock and the immediately following re-lock during a
3472 ;; steal-lock operation (apparent state E). This window may never close
3473 ;; if the user fails to complete the steal-lock message.
3477 ;; Apparent state A ---
3479 ;; 1. File looked unregistered but is actually registered and not locked.
3481 ;; Potential cause: someone else's admin during window P, with
3482 ;; caller's admin happening before their checkout.
3484 ;; RCS: Prior to version 5.6.4, ci fails with message
3485 ;; "no lock set by <user>". From 5.6.4 onwards, VC uses the new
3486 ;; ci -i option and the message is "<file>,v: already exists".
3487 ;; SCCS: admin will fail with error (ad19).
3489 ;; We can let these errors be passed up to the user.
3491 ;; 2. File looked unregistered but is actually locked by caller, unchanged.
3493 ;; Potential cause: self-race during window P.
3495 ;; RCS: Prior to version 5.6.4, reverts the file to the last saved
3496 ;; version and unlocks it. From 5.6.4 onwards, VC uses the new
3497 ;; ci -i option, failing with message "<file>,v: already exists".
3498 ;; SCCS: will fail with error (ad19).
3500 ;; Either of these consequences is acceptable.
3502 ;; 3. File looked unregistered but is actually locked by caller, changed.
3504 ;; Potential cause: self-race during window P.
3506 ;; RCS: Prior to version 5.6.4, VC registers the caller's workfile as
3507 ;; a delta with a null change comment (the -t- switch will be
3508 ;; ignored). From 5.6.4 onwards, VC uses the new ci -i option,
3509 ;; failing with message "<file>,v: already exists".
3510 ;; SCCS: will fail with error (ad19).
3512 ;; 4. File looked unregistered but is locked by someone else.
3514 ;; Potential cause: someone else's admin during window P, with
3515 ;; caller's admin happening *after* their checkout.
3517 ;; RCS: Prior to version 5.6.4, ci fails with a
3518 ;; "no lock set by <user>" message. From 5.6.4 onwards,
3519 ;; VC uses the new ci -i option, failing with message
3520 ;; "<file>,v: already exists".
3521 ;; SCCS: will fail with error (ad19).
3523 ;; We can let these errors be passed up to the user.
3525 ;; Apparent state B ---
3527 ;; 5. File looked registered and not locked, but is actually unregistered.
3529 ;; Potential cause: master file got nuked during window P.
3531 ;; RCS: will fail with "RCS/<file>: No such file or directory"
3532 ;; SCCS: will fail with error ut4.
3534 ;; We can let these errors be passed up to the user.
3536 ;; 6. File looked registered and not locked, but is actually locked by the
3537 ;; calling user and unchanged.
3539 ;; Potential cause: self-race during window T.
3541 ;; RCS: in the same directory as the previous workfile, co -l will fail
3542 ;; with "co error: writable foo exists; checkout aborted". In any other
3543 ;; directory, checkout will succeed.
3544 ;; SCCS: will fail with ge17.
3546 ;; Either of these consequences is acceptable.
3548 ;; 7. File looked registered and not locked, but is actually locked by the
3549 ;; calling user and changed.
3553 ;; 8. File looked registered and not locked, but is actually locked by another
3556 ;; Potential cause: someone else checks it out during window T.
3558 ;; RCS: co error: revision 1.3 already locked by <user>
3559 ;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
3561 ;; We can let these errors be passed up to the user.
3563 ;; Apparent state C ---
3565 ;; 9. File looks locked by calling user and unchanged, but is unregistered.
3569 ;; 10. File looks locked by calling user and unchanged, but is actually not
3572 ;; Potential cause: a self-race in window U, or by the revert's
3573 ;; landing during window X of some other user's steal-lock or window S
3574 ;; of another user's revert.
3576 ;; RCS: succeeds, refreshing the file from the identical version in
3578 ;; SCCS: fails with error ut4 (p file nonexistent).
3580 ;; Either of these consequences is acceptable.
3582 ;; 11. File is locked by calling user. It looks unchanged, but is actually
3585 ;; Potential cause: the file would have to be touched by a self-race
3588 ;; The revert will succeed, removing whatever changes came with
3589 ;; the touch. It is theoretically possible that work could be lost.
3591 ;; 12. File looks like it's locked by the calling user and unchanged, but
3592 ;; it's actually locked by someone else.
3594 ;; Potential cause: a steal-lock in window V.
3596 ;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
3597 ;; SCCS: fails with error un2
3599 ;; We can pass these errors up to the user.
3601 ;; Apparent state D ---
3603 ;; 13. File looks like it's locked by the calling user and changed, but it's
3604 ;; actually unregistered.
3606 ;; Potential cause: master file got nuked during window P.
3608 ;; RCS: Prior to version 5.6.4, checks in the user's version as an
3609 ;; initial delta. From 5.6.4 onwards, VC uses the new ci -j
3610 ;; option, failing with message "no such file or directory".
3611 ;; SCCS: will fail with error ut4.
3613 ;; This case is kind of nasty. Under RCS prior to version 5.6.4,
3614 ;; VC may fail to detect the loss of previous version information.
3616 ;; 14. File looks like it's locked by the calling user and changed, but it's
3617 ;; actually unlocked.
3619 ;; Potential cause: self-race in window V, or the checkin happening
3620 ;; during the window X of someone else's steal-lock or window S of
3621 ;; someone else's revert.
3623 ;; RCS: ci will fail with "no lock set by <user>".
3624 ;; SCCS: delta will fail with error ut4.
3626 ;; 15. File looks like it's locked by the calling user and changed, but it's
3627 ;; actually locked by the calling user and unchanged.
3629 ;; Potential cause: another self-race --- a whole checkin/checkout
3630 ;; sequence by the calling user would have to land in window R.
3632 ;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
3633 ;; RCS: reverts to the file state as of the second user's checkin, leaving
3634 ;; the file unlocked.
3636 ;; It is theoretically possible that work could be lost under RCS.
3638 ;; 16. File looks like it's locked by the calling user and changed, but it's
3639 ;; actually locked by a different user.
3641 ;; RCS: ci error: no lock set by <user>
3642 ;; SCCS: unget will fail with error un2
3644 ;; We can pass these errors up to the user.
3646 ;; Apparent state E ---
3648 ;; 17. File looks like it's locked by some other user, but it's actually
3653 ;; 18. File looks like it's locked by some other user, but it's actually
3656 ;; Potential cause: someone released a lock during window W.
3658 ;; RCS: The calling user will get the lock on the file.
3659 ;; SCCS: unget -n will fail with cm4.
3661 ;; Either of these consequences will be OK.
3663 ;; 19. File looks like it's locked by some other user, but it's actually
3664 ;; locked by the calling user and unchanged.
3666 ;; Potential cause: the other user relinquishing a lock followed by
3667 ;; a self-race, both in window W.
3669 ;; Under both RCS and SCCS, both unlock and lock will succeed, making
3670 ;; the sequence a no-op.
3672 ;; 20. File looks like it's locked by some other user, but it's actually
3673 ;; locked by the calling user and changed.
3679 ;; In order of decreasing severity:
3681 ;; Cases 11 and 15 are the only ones that potentially lose work.
3682 ;; They would require a self-race for this to happen.
3684 ;; Case 13 in RCS loses information about previous deltas, retaining
3685 ;; only the information in the current workfile. This can only happen
3686 ;; if the master file gets nuked in window P.
3688 ;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
3689 ;; no change comment in the master. This would require a self-race in
3690 ;; window P or R respectively.
3692 ;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
3694 ;; Unfortunately, it appears to me that no recovery is possible in these
3695 ;; cases. They don't yield error messages, so there's no way to tell that
3696 ;; a race condition has occurred.
3698 ;; All other cases don't change either the workfile or the master, and
3699 ;; trigger command errors which the user will see.
3701 ;; Thus, there is no explicit recovery code.