Merge from emacs-23
[bpt/emacs.git] / lisp / vc / vc-hooks.el
CommitLineData
aae56ea7 1;;; vc-hooks.el --- resident support for version-control
594722a8 2
c90f2757 3;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
5df4f04c 4;; 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
6dc3311d 5;; Free Software Foundation, Inc.
594722a8 6
0e0d9831
GM
7;; Author: FSF (see vc.el for full credits)
8;; Maintainer: Andre Spiegel <spiegel@gnu.org>
bd78fa1d 9;; Package: vc
594722a8
ER
10
11;; This file is part of GNU Emacs.
12
eb3fa2cf 13;; GNU Emacs is free software: you can redistribute it and/or modify
594722a8 14;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
15;; the Free Software Foundation, either version 3 of the License, or
16;; (at your option) any later version.
594722a8
ER
17
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
7d56ad0d 21;; GNU General Public License for more details.
594722a8
ER
22
23;; You should have received a copy of the GNU General Public License
eb3fa2cf 24;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
594722a8
ER
25
26;;; Commentary:
27
0e0d9831
GM
28;; This is the always-loaded portion of VC. It takes care of
29;; VC-related activities that are done when you visit a file, so that
30;; vc.el itself is loaded only when you use a VC command. See the
31;; commentary of vc.el.
594722a8
ER
32
33;;; Code:
34
c3ce5e29
AS
35(eval-when-compile
36 (require 'cl))
099bd78a 37
e1c0c2d1
KH
38;; Customization Variables (the rest is in vc.el)
39
e18cf2ee 40(defvar vc-ignore-vc-files nil)
5499f9dc 41(make-obsolete-variable 'vc-ignore-vc-files
329a656e
JB
42 "set `vc-handled-backends' to nil to disable VC."
43 "21.1")
5499f9dc 44
e18cf2ee 45(defvar vc-master-templates ())
0d2ce4ef
JB
46(make-obsolete-variable 'vc-master-templates
47 "to define master templates for a given BACKEND, use
5499f9dc 48vc-BACKEND-master-templates. To enable or disable VC for a given
329a656e
JB
49BACKEND, use `vc-handled-backends'."
50 "21.1")
5499f9dc 51
456e749f
SM
52(defcustom vc-ignore-dir-regexp
53 ;; Stop SMB, automounter, AFS, and DFS host lookups.
8cd56959 54 locate-dominating-stop-dir-regexp
43621386 55 "Regexp matching directory names that are not under VC's control.
ce9f8ffb
SM
56The default regexp prevents fruitless and time-consuming attempts
57to determine the VC status in directories in which filenames are
43621386
SM
58interpreted as hostnames."
59 :type 'regexp
60 :group 'vc)
ce9f8ffb 61
db86064f 62(defcustom vc-handled-backends '(RCS CVS SVN SCCS Bzr Git Hg Mtn Arch)
b1dc6d44
SM
63 ;; RCS, CVS, SVN and SCCS come first because they are per-dir
64 ;; rather than per-tree. RCS comes first because of the multibackend
65 ;; support intended to use RCS for local commits (with a remote CVS server).
e5162bc1 66 "List of version control backends for which VC will be used.
0e0d9831
GM
67Entries in this list will be tried in order to determine whether a
68file is under that sort of version control.
69Removing an entry from the list prevents VC from being activated
70when visiting a file managed by that backend.
71An empty list disables VC altogether."
72 :type '(repeat symbol)
dbd3d787 73 :version "23.1"
50bec091 74 :group 'vc)
31888047 75
1f0bee0a 76;; Note: we don't actually have a darcs back end yet.
db86064f 77;; Also, Meta-CVS (corresponsding to MCVS) is unsupported.
0b7f397c 78(defcustom vc-directory-exclusion-list (purecopy '("SCCS" "RCS" "CVS" "MCVS"
527b313d 79 ".svn" ".git" ".hg" ".bzr"
0b7f397c 80 "_MTN" "_darcs" "{arch}"))
9c4b89d5
ER
81 "List of directory names to be ignored when walking directory trees."
82 :type '(repeat string)
83 :group 'vc)
84
50bec091 85(defcustom vc-make-backup-files nil
e5162bc1 86 "If non-nil, backups of registered files are made as with other files.
50bec091
KH
87If nil (the default), files covered by version control don't get backups."
88 :type 'boolean
8f383484
DL
89 :group 'vc
90 :group 'backup)
594722a8 91
50bec091 92(defcustom vc-follow-symlinks 'ask
e5162bc1 93 "What to do if visiting a symbolic link to a file under version control.
0e0d9831
GM
94Editing such a file through the link bypasses the version control system,
95which is dangerous and probably not what you want.
96
97If this variable is t, VC follows the link and visits the real file,
b8063212
AS
98telling you about it in the echo area. If it is `ask', VC asks for
99confirmation whether it should follow the link. If nil, the link is
50bec091 100visited and a warning displayed."
0e0d9831
GM
101 :type '(choice (const :tag "Ask for confirmation" ask)
102 (const :tag "Visit link and warn" nil)
103 (const :tag "Follow link" t))
50bec091 104 :group 'vc)
b8063212 105
50bec091 106(defcustom vc-display-status t
e5162bc1 107 "If non-nil, display revision number and lock status in modeline.
50bec091
KH
108Otherwise, not displayed."
109 :type 'boolean
110 :group 'vc)
111
198d5c00 112
50bec091 113(defcustom vc-consult-headers t
e5162bc1 114 "If non-nil, identify work files by searching for version headers."
50bec091
KH
115 :type 'boolean
116 :group 'vc)
e1c0c2d1 117
50bec091 118(defcustom vc-keep-workfiles t
e5162bc1 119 "If non-nil, don't delete working files after registering changes.
e1c0c2d1 120If the back-end is CVS, workfiles are always kept, regardless of the
50bec091
KH
121value of this flag."
122 :type 'boolean
123 :group 'vc)
e1c0c2d1 124
50bec091 125(defcustom vc-mistrust-permissions nil
e5162bc1 126 "If non-nil, don't assume permissions/ownership track version-control status.
0e0d9831 127If nil, do rely on the permissions.
50bec091
KH
128See also variable `vc-consult-headers'."
129 :type 'boolean
130 :group 'vc)
e66eac08
AS
131
132(defun vc-mistrust-permissions (file)
0e0d9831 133 "Internal access function to variable `vc-mistrust-permissions' for FILE."
e66eac08
AS
134 (or (eq vc-mistrust-permissions 't)
135 (and vc-mistrust-permissions
0e0d9831 136 (funcall vc-mistrust-permissions
e66eac08
AS
137 (vc-backend-subdirectory-name file)))))
138
5870cb76 139(defcustom vc-stay-local 'only-file
e5162bc1 140 "Non-nil means use local operations when possible for remote repositories.
113414a9
SM
141This avoids slow queries over the network and instead uses heuristics
142and past information to determine the current status of a file.
143
5870cb76
DN
144If value is the symbol `only-file' `vc-dir' will connect to the
145server, but heuristics will be used to determine the status for
146all other VC operations.
147
113414a9
SM
148The value can also be a regular expression or list of regular
149expressions to match against the host name of a repository; then VC
150only stays local for hosts that match it. Alternatively, the value
151can be a list of regular expressions where the first element is the
152symbol `except'; then VC always stays local except for hosts matched
153by these regular expressions."
5870cb76
DN
154 :type '(choice
155 (const :tag "Always stay local" t)
37e14a62 156 (const :tag "Only for file operations" only-file)
113414a9
SM
157 (const :tag "Don't stay local" nil)
158 (list :format "\nExamine hostname and %v" :tag "Examine hostname ..."
159 (set :format "%v" :inline t (const :format "%t" :tag "don't" except))
160 (regexp :format " stay local,\n%t: %v" :tag "if it matches")
161 (repeat :format "%v%i\n" :inline t (regexp :tag "or"))))
5870cb76 162 :version "23.1"
113414a9
SM
163 :group 'vc)
164
77bf3f54 165(defun vc-stay-local-p (file &optional backend)
113414a9 166 "Return non-nil if VC should stay local when handling FILE.
33e0847d
TTN
167This uses the `repository-hostname' backend operation.
168If FILE is a list of files, return non-nil if any of them
169individually should stay local."
e4d26892 170 (if (listp file)
77bf3f54
DN
171 (delq nil (mapcar (lambda (arg) (vc-stay-local-p arg backend)) file))
172 (setq backend (or backend (vc-backend file)))
173 (let* ((sym (vc-make-backend-sym backend 'stay-local))
95541017 174 (stay-local (if (boundp sym) (symbol-value sym) vc-stay-local)))
e4d26892
ER
175 (if (symbolp stay-local) stay-local
176 (let ((dirname (if (file-directory-p file)
177 (directory-file-name file)
178 (file-name-directory file))))
179 (eq 'yes
180 (or (vc-file-getprop dirname 'vc-stay-local-p)
181 (vc-file-setprop
182 dirname 'vc-stay-local-p
183 (let ((hostname (vc-call-backend
184 backend 'repository-hostname dirname)))
185 (if (not hostname)
186 'no
187 (let ((default t))
188 (if (eq (car-safe stay-local) 'except)
189 (setq default nil stay-local (cdr stay-local)))
190 (when (consp stay-local)
191 (setq stay-local
192 (mapconcat 'identity stay-local "\\|")))
193 (if (if (string-match stay-local hostname)
194 default (not default))
195 'yes 'no))))))))))))
113414a9 196
9bd06e95 197;;; This is handled specially now.
594722a8 198;; Tell Emacs about this new kind of minor mode
9bd06e95 199;; (add-to-list 'minor-mode-alist '(vc-mode vc-mode))
594722a8 200
d270305a 201;;;###autoload
6dc3311d 202(put 'vc-mode 'risky-local-variable t)
7bc2b98b 203(make-variable-buffer-local 'vc-mode)
c43e436c 204(put 'vc-mode 'permanent-local t)
594722a8 205
14fef9de
SM
206(defun vc-mode (&optional arg)
207 ;; Dummy function for C-h m
208 "Version Control minor mode.
209This minor mode is automatically activated whenever you visit a file under
210control of one of the revision control systems in `vc-handled-backends'.
211VC commands are globally reachable under the prefix `\\[vc-prefix-map]':
212\\{vc-prefix-map}")
213
099bd78a 214(defmacro vc-error-occurred (&rest body)
becd6193 215 `(condition-case nil (progn ,@body nil) (error t)))
099bd78a 216
594722a8 217;; We need a notion of per-file properties because the version
f2ee4191 218;; control state of a file is expensive to derive --- we compute
0e0d9831 219;; them when the file is initially found, keep them up to date
f2ee4191
RS
220;; during any subsequent VC operations, and forget them when
221;; the buffer is killed.
594722a8 222
becd6193 223(defvar vc-file-prop-obarray (make-vector 17 0)
594722a8
ER
224 "Obarray for per-file properties.")
225
099bd78a
SM
226(defvar vc-touched-properties nil)
227
594722a8 228(defun vc-file-setprop (file property value)
0e0d9831 229 "Set per-file VC PROPERTY for FILE to VALUE."
099bd78a
SM
230 (if (and vc-touched-properties
231 (not (memq property vc-touched-properties)))
232 (setq vc-touched-properties (append (list property)
233 vc-touched-properties)))
594722a8
ER
234 (put (intern file vc-file-prop-obarray) property value))
235
236(defun vc-file-getprop (file property)
099bd78a 237 "Get per-file VC PROPERTY for FILE."
594722a8
ER
238 (get (intern file vc-file-prop-obarray) property))
239
e1c0c2d1 240(defun vc-file-clearprops (file)
0e0d9831 241 "Clear all VC properties of FILE."
f98c9a23 242 (setplist (intern file vc-file-prop-obarray) nil))
f2ee4191 243
0e0d9831
GM
244\f
245;; We keep properties on each symbol naming a backend as follows:
246;; * `vc-functions': an alist mapping vc-FUNCTION to vc-BACKEND-FUNCTION.
247
248(defun vc-make-backend-sym (backend sym)
249 "Return BACKEND-specific version of VC symbol SYM."
250 (intern (concat "vc-" (downcase (symbol-name backend))
251 "-" (symbol-name sym))))
252
253(defun vc-find-backend-function (backend fun)
254 "Return BACKEND-specific implementation of FUN.
f8b72742 255If there is no such implementation, return the default implementation;
0e0d9831
GM
256if that doesn't exist either, return nil."
257 (let ((f (vc-make-backend-sym backend fun)))
258 (if (fboundp f) f
259 ;; Load vc-BACKEND.el if needed.
260 (require (intern (concat "vc-" (downcase (symbol-name backend)))))
261 (if (fboundp f) f
262 (let ((def (vc-make-backend-sym 'default fun)))
263 (if (fboundp def) (cons def backend) nil))))))
264
265(defun vc-call-backend (backend function-name &rest args)
266 "Call for BACKEND the implementation of FUNCTION-NAME with the given ARGS.
267Calls
268
269 (apply 'vc-BACKEND-FUN ARGS)
270
271if vc-BACKEND-FUN exists (after trying to find it in vc-BACKEND.el)
272and else calls
273
274 (apply 'vc-default-FUN BACKEND ARGS)
275
276It is usually called via the `vc-call' macro."
0bfb74a9
SM
277 (let ((f (assoc function-name (get backend 'vc-functions))))
278 (if f (setq f (cdr f))
0e0d9831 279 (setq f (vc-find-backend-function backend function-name))
0bfb74a9
SM
280 (push (cons function-name f) (get backend 'vc-functions)))
281 (cond
282 ((null f)
283 (error "Sorry, %s is not implemented for %s" function-name backend))
284 ((consp f) (apply (car f) (cdr f) args))
285 (t (apply f args)))))
0e0d9831
GM
286
287(defmacro vc-call (fun file &rest args)
daffc81a
JR
288 "A convenience macro for calling VC backend functions.
289Functions called by this macro must accept FILE as the first argument.
d4e772c4
JB
290ARGS specifies any additional arguments. FUN should be unquoted.
291BEWARE!! FILE is evaluated twice!!"
0e0d9831 292 `(vc-call-backend (vc-backend ,file) ',fun ,file ,@args))
0e0d9831
GM
293\f
294(defsubst vc-parse-buffer (pattern i)
295 "Find PATTERN in the current buffer and return its Ith submatch."
296 (goto-char (point-min))
297 (if (re-search-forward pattern nil t)
298 (match-string i)))
e1c0c2d1 299
02d383eb 300(defun vc-insert-file (file &optional limit blocksize)
0e0d9831
GM
301 "Insert the contents of FILE into the current buffer.
302
303Optional argument LIMIT is a regexp. If present, the file is inserted
304in chunks of size BLOCKSIZE (default 8 kByte), until the first
f8b72742 305occurrence of LIMIT is found. Anything from the start of that occurrence
e30140ce
AS
306to the end of the buffer is then deleted. The function returns
307non-nil if FILE exists and its contents were successfully inserted."
07de4c3d 308 (erase-buffer)
ff40374a
AS
309 (when (file-exists-p file)
310 (if (not limit)
311 (insert-file-contents file)
b5446276 312 (unless blocksize (setq blocksize 8192))
4d2806e2
SM
313 (let ((filepos 0))
314 (while
315 (and (< 0 (cadr (insert-file-contents
316 file nil filepos (incf filepos blocksize))))
317 (progn (beginning-of-line)
e30140ce 318 (let ((pos (re-search-forward limit nil 'move)))
b5446276
DN
319 (when pos (delete-region (match-beginning 0)
320 (point-max)))
e30140ce 321 (not pos)))))))
ff40374a
AS
322 (set-buffer-modified-p nil)
323 t))
02d383eb 324
3dd2acc9 325(defun vc-find-root (file witness)
ce9f8ffb
SM
326 "Find the root of a checked out project.
327The function walks up the directory tree from FILE looking for WITNESS.
3dd2acc9 328If WITNESS if not found, return nil, otherwise return the root."
8cd56959
SM
329 (let ((locate-dominating-stop-dir-regexp
330 (or vc-ignore-dir-regexp locate-dominating-stop-dir-regexp)))
331 (locate-dominating-file file witness)))
37e14a62 332
14fef9de
SM
333;; Access functions to file properties
334;; (Properties should be _set_ using vc-file-setprop, but
335;; _retrieved_ only through these functions, which decide
d4e772c4 336;; if the property is already known or not. A property should
14fef9de
SM
337;; only be retrieved by vc-file-getprop if there is no
338;; access function.)
02d383eb 339
14fef9de 340;; properties indicating the backend being used for FILE
e1c0c2d1 341
0e0d9831
GM
342(defun vc-registered (file)
343 "Return non-nil if FILE is registered in a version control system.
344
1f22ad24
AS
345This function performs the check each time it is called. To rely
346on the result of a previous call, use `vc-backend' instead. If the
347file was previously registered under a certain backend, then that
348backend is tried first."
0e0d9831 349 (let (handler)
ce9f8ffb 350 (cond
8cd56959
SM
351 ((and (file-name-directory file)
352 (string-match vc-ignore-dir-regexp (file-name-directory file)))
44cd688b 353 nil)
ce9f8ffb
SM
354 ((and (boundp 'file-name-handler-alist)
355 (setq handler (find-file-name-handler file 'vc-registered)))
356 ;; handler should set vc-backend and return t if registered
357 (funcall handler 'vc-registered file))
358 (t
0e0d9831
GM
359 ;; There is no file name handler.
360 ;; Try vc-BACKEND-registered for each handled BACKEND.
361 (catch 'found
1f22ad24 362 (let ((backend (vc-file-getprop file 'vc-backend)))
a549ce70 363 (mapc
1f22ad24
AS
364 (lambda (b)
365 (and (vc-call-backend b 'registered file)
366 (vc-file-setprop file 'vc-backend b)
367 (throw 'found t)))
f8b72742 368 (if (or (not backend) (eq backend 'none))
1f22ad24
AS
369 vc-handled-backends
370 (cons backend vc-handled-backends))))
0e0d9831
GM
371 ;; File is not registered.
372 (vc-file-setprop file 'vc-backend 'none)
ce9f8ffb 373 nil)))))
0e0d9831 374
e4d26892
ER
375(defun vc-backend (file-or-list)
376 "Return the version control type of FILE-OR-LIST, nil if it's not registered.
377If the argument is a list, the files must all have the same back end."
0e0d9831 378 ;; `file' can be nil in several places (typically due to the use of
5232a436 379 ;; code like (vc-backend buffer-file-name)).
e4d26892
ER
380 (cond ((stringp file-or-list)
381 (let ((property (vc-file-getprop file-or-list 'vc-backend)))
382 ;; Note that internally, Emacs remembers unregistered
383 ;; files by setting the property to `none'.
384 (cond ((eq property 'none) nil)
385 (property)
386 ;; vc-registered sets the vc-backend property
387 (t (if (vc-registered file-or-list)
388 (vc-file-getprop file-or-list 'vc-backend)
389 nil)))))
390 ((and file-or-list (listp file-or-list))
391 (vc-backend (car file-or-list)))
392 (t
393 nil)))
394
0e0d9831
GM
395
396(defun vc-backend-subdirectory-name (file)
004f9b3f 397 "Return where the repository for the current directory is kept."
0e0d9831 398 (symbol-name (vc-backend file)))
e1c0c2d1 399
02d383eb 400(defun vc-name (file)
5eb2b516
DL
401 "Return the master name of FILE.
402If the file is not registered, or the master name is not known, return nil."
403 ;; TODO: This should ultimately become obsolete, at least up here
0e0d9831 404 ;; in vc-hooks.
02d383eb 405 (or (vc-file-getprop file 'vc-name)
64341022
AS
406 ;; force computation of the property by calling
407 ;; vc-BACKEND-registered explicitly
32ca5ee4
DN
408 (let ((backend (vc-backend file)))
409 (if (and backend
410 (vc-call-backend backend 'registered file))
411 (vc-file-getprop file 'vc-name)))))
e1c0c2d1 412
e0607aaa
SM
413(defun vc-checkout-model (backend files)
414 "Indicate how FILES are checked out.
0e0d9831 415
e0607aaa 416If FILES are not registered, this function always returns nil.
cb5af02a 417For registered files, the possible values are:
0e0d9831 418
fe3e2715 419 'implicit FILES are always writable, and checked out `implicitly'
0e0d9831
GM
420 when the user saves the first changes to the file.
421
e0607aaa 422 'locking FILES are read-only if up-to-date; user must type
db8afaee 423 \\[vc-next-action] before editing. Strict locking
0e0d9831
GM
424 is assumed.
425
e0607aaa 426 'announce FILES are read-only if up-to-date; user must type
db8afaee 427 \\[vc-next-action] before editing. But other users
0e0d9831 428 may be editing at the same time."
e0607aaa 429 (vc-call-backend backend 'checkout-model files))
7064821c 430
8d2b9c1a
AS
431(defun vc-user-login-name (file)
432 "Return the name under which the user accesses the given FILE."
433 (or (and (eq (string-match tramp-file-name-regexp file) 0)
434 ;; tramp case: execute "whoami" via tramp
ba2318b7
MA
435 (let ((default-directory (file-name-directory file))
436 process-file-side-effects)
8d2b9c1a
AS
437 (with-temp-buffer
438 (if (not (zerop (process-file "whoami" nil t)))
439 ;; fall through if "whoami" didn't work
440 nil
441 ;; remove trailing newline
442 (delete-region (1- (point-max)) (point-max))
443 (buffer-string)))))
444 ;; normal case
445 (user-login-name)
446 ;; if user-login-name is nil, return the UID as a string
447 (number-to-string (user-uid))))
0e0d9831 448
77bf3f54 449(defun vc-state (file &optional backend)
0e0d9831
GM
450 "Return the version control state of FILE.
451
cb5af02a
AS
452If FILE is not registered, this function always returns nil.
453For registered files, the value returned is one of:
0e0d9831
GM
454
455 'up-to-date The working file is unmodified with respect to the
456 latest version on the current branch, and not locked.
457
458 'edited The working file has been edited by the user. If
459 locking is used for the file, this state means that
460 the current version is locked by the calling user.
f6d90772
ER
461 This status should *not* be reported for files
462 which have a changed mtime but the same content
463 as the repo copy.
0e0d9831
GM
464
465 USER The current version of the working file is locked by
466 some other USER (a string).
f8b72742 467
004f9b3f 468 'needs-update The file has not been edited by the user, but there is
0e0d9831 469 a more recent version on the current branch stored
004f9b3f 470 in the repository.
0e0d9831
GM
471
472 'needs-merge The file has been edited by the user, and there is also
473 a more recent version on the current branch stored in
004f9b3f 474 the repository. This state can only occur if locking
0e0d9831
GM
475 is not used for the file.
476
fae00181 477 'unlocked-changes The working version of the file is not locked,
0e0d9831
GM
478 but the working file has been changed with respect
479 to that version. This state can only occur for files
480 with locking; it represents an erroneous condition that
481 should be resolved by the user (vc-next-action will
fae00181
ER
482 prompt the user to do it).
483
484 'added Scheduled to go into the repository on the next commit.
14f26054 485 Often represented by vc-working-revision = \"0\" in VCSes
722f037f
ER
486 with monotonic IDs like Subversion and Mercurial.
487
484c1b1f 488 'removed Scheduled to be deleted from the repository on next commit.
527b313d 489
7fbb4797 490 'conflict The file contains conflicts as the result of a merge.
329a656e
JB
491 For now the conflicts are text conflicts. In the
492 future this might be extended to deal with metadata
7fbb4797
DN
493 conflicts too.
494
329a656e 495 'missing The file is not present in the file system, but the VC
dd0d723c
DN
496 system still tracks it.
497
4903369a 498 'ignored The file showed up in a dir-status listing with a flag
722f037f 499 indicating the version-control system is ignoring it,
527b313d
SS
500 Note: This property is not set reliably (some VCSes
501 don't have useful directory-status commands) so assume
722f037f 502 that any file with vc-state nil might be ignorable
527b313d 503 without VC knowing it.
722f037f 504
3702367b 505 'unregistered The file is not under version control.
722f037f 506
527b313d 507A return of nil from this function means we have no information on the
d4e772c4 508status of this file."
a970a27e
ER
509 ;; Note: in Emacs 22 and older, return of nil meant the file was
510 ;; unregistered. This is potentially a source of
511 ;; backward-compatibility bugs.
fae00181 512
2a3897f5 513 ;; FIXME: New (sub)states needed (?):
2a3897f5 514 ;; - `copied' and `moved' (might be handled by `removed' and `added')
0e0d9831 515 (or (vc-file-getprop file 'vc-state)
dcbbecd4 516 (when (> (length file) 0) ;Why?? --Stef
77bf3f54
DN
517 (setq backend (or backend (vc-backend file)))
518 (when backend
dcbbecd4
SM
519 (vc-state-refresh file backend)))))
520
521(defun vc-state-refresh (file backend)
522 "Quickly recompute the `state' of FILE."
523 (vc-file-setprop
524 file 'vc-state
525 (vc-call-backend backend 'state-heuristic file)))
0e0d9831
GM
526
527(defsubst vc-up-to-date-p (file)
528 "Convenience function that checks whether `vc-state' of FILE is `up-to-date'."
529 (eq (vc-state file) 'up-to-date))
530
531(defun vc-default-state-heuristic (backend file)
d4e772c4 532 "Default implementation of vc-BACKEND-state-heuristic.
5eb2b516
DL
533It simply calls the real state computation function `vc-BACKEND-state'
534and does not employ any heuristic at all."
0e0d9831 535 (vc-call-backend backend 'state file))
1efcbf46 536
e767004f
AS
537(defun vc-workfile-unchanged-p (file)
538 "Return non-nil if FILE has not changed since the last checkout."
539 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time))
540 (lastmod (nth 5 (file-attributes file))))
70c8a390
CY
541 ;; This is a shortcut for determining when the workfile is
542 ;; unchanged. It can fail under some circumstances; see the
543 ;; discussion in bug#694.
544 (if (and checkout-time
545 ;; Tramp and Ange-FTP return this when they don't know the time.
546 (not (equal lastmod '(0 0))))
547 (equal checkout-time lastmod)
548 (let ((unchanged (vc-call workfile-unchanged-p file)))
549 (vc-file-setprop file 'vc-checkout-time (if unchanged lastmod 0))
550 unchanged))))
e767004f
AS
551
552(defun vc-default-workfile-unchanged-p (backend file)
004f9b3f 553 "Check if FILE is unchanged by diffing against the repository version.
e767004f 554Return non-nil if FILE is unchanged."
f8836381 555 (zerop (condition-case err
4392edab
AS
556 ;; If the implementation supports it, let the output
557 ;; go to *vc*, not *vc-diff*, since this is an internal call.
a749e19d 558 (vc-call-backend backend 'diff (list file) nil nil "*vc*")
f8836381
AS
559 (wrong-number-of-arguments
560 ;; If this error came from the above call to vc-BACKEND-diff,
561 ;; try again without the optional buffer argument (for
562 ;; backward compatibility). Otherwise, resignal.
563 (if (or (not (eq (cadr err)
564 (indirect-function
a749e19d 565 (vc-find-backend-function backend 'diff))))
0d2ce4ef
JB
566 (not (eq (caddr err) 4)))
567 (signal (car err) (cdr err))
a749e19d 568 (vc-call-backend backend 'diff (list file)))))))
e767004f 569
77bf3f54 570(defun vc-working-revision (file &optional backend)
e4d26892 571 "Return the repository version from which FILE was checked out.
cb5af02a 572If FILE is not registered, this function always returns nil."
ac3f4c6f 573 (or (vc-file-getprop file 'vc-working-revision)
77bf3f54
DN
574 (progn
575 (setq backend (or backend (vc-backend file)))
576 (when backend
577 (vc-file-setprop file 'vc-working-revision
578 (vc-call-backend backend 'working-revision file))))))
b5446276 579
6e5d0e9e
SM
580;; Backward compatibility.
581(define-obsolete-function-alias
582 'vc-workfile-version 'vc-working-revision "23.1")
583(defun vc-default-working-revision (backend file)
584 (message
585 "`working-revision' not found: using the old `workfile-version' instead")
586 (vc-call-backend backend 'workfile-version file))
f2ee4191 587
0e0d9831
GM
588(defun vc-default-registered (backend file)
589 "Check if FILE is registered in BACKEND using vc-BACKEND-master-templates."
590 (let ((sym (vc-make-backend-sym backend 'master-templates)))
591 (unless (get backend 'vc-templates-grabbed)
592 (put backend 'vc-templates-grabbed t)
593 (set sym (append (delq nil
594 (mapcar
595 (lambda (template)
596 (and (consp template)
597 (eq (cdr template) backend)
598 (car template)))
3756d481
AS
599 (with-no-warnings
600 vc-master-templates)))
0e0d9831
GM
601 (symbol-value sym))))
602 (let ((result (vc-check-master-templates file (symbol-value sym))))
603 (if (stringp result)
604 (vc-file-setprop file 'vc-name result)
605 nil)))) ; Not registered
606
607(defun vc-possible-master (s dirname basename)
608 (cond
609 ((stringp s) (format s dirname basename))
610 ((functionp s)
611 ;; The template is a function to invoke. If the
612 ;; function returns non-nil, that means it has found a
613 ;; master. For backward compatibility, we also handle
614 ;; the case that the function throws a 'found atom
615 ;; and a pair (cons MASTER-FILE BACKEND).
616 (let ((result (catch 'found (funcall s dirname basename))))
617 (if (consp result) (car result) result)))))
618
619(defun vc-check-master-templates (file templates)
cb5af02a 620 "Return non-nil if there is a master corresponding to FILE.
0e0d9831
GM
621
622TEMPLATES is a list of strings or functions. If an element is a
623string, it must be a control string as required by `format', with two
624string placeholders, such as \"%sRCS/%s,v\". The directory part of
625FILE is substituted for the first placeholder, the basename of FILE
626for the second. If a file with the resulting name exists, it is taken
627as the master of FILE, and returned.
628
629If an element of TEMPLATES is a function, it is called with the
630directory part and the basename of FILE as arguments. It should
631return non-nil if it finds a master; that value is then returned by
632this function."
633 (let ((dirname (or (file-name-directory file) ""))
634 (basename (file-name-nondirectory file)))
635 (catch 'found
5eb2b516 636 (mapcar
0e0d9831
GM
637 (lambda (s)
638 (let ((trial (vc-possible-master s dirname basename)))
b5446276
DN
639 (when (and trial (file-exists-p trial)
640 ;; Make sure the file we found with name
641 ;; TRIAL is not the source file itself.
642 ;; That can happen with RCS-style names if
643 ;; the file name is truncated (e.g. to 14
644 ;; chars). See if either directory or
645 ;; attributes differ.
646 (or (not (string= dirname
647 (file-name-directory trial)))
648 (not (equal (file-attributes file)
649 (file-attributes trial)))))
0e0d9831
GM
650 (throw 'found trial))))
651 templates))))
f2ee4191 652
c844616c 653(defun vc-toggle-read-only (&optional verbose)
c43e436c 654 "Change read-only status of current buffer, perhaps via version control.
db8afaee 655
c43e436c 656If the buffer is visiting a file registered with version control,
d4e772c4
JB
657throw an error, because this is not a safe or really meaningful operation
658on any version-control system newer than RCS.
25e94278
ER
659
660Otherwise, just change the read-only flag of the buffer.
661
662If you bind this function to \\[toggle-read-only], then Emacs
663will properly intercept all attempts to toggle the read-only flag
664on version-controlled buffer."
c844616c 665 (interactive "P")
25e94278 666 (if (vc-backend buffer-file-name)
5a0c3f56 667 (error "Toggling the readability of a version controlled file is likely to wreak havoc")
594722a8
ER
668 (toggle-read-only)))
669
e896a9e1 670(defun vc-default-make-version-backups-p (backend file)
cb5af02a 671 "Return non-nil if unmodified versions should be backed up locally.
9aa10a43 672The default is to switch off this feature."
d445a975
AS
673 nil)
674
e896a9e1
AS
675(defun vc-version-backup-file-name (file &optional rev manual regexp)
676 "Return a backup file name for REV or the current version of FILE.
677If MANUAL is non-nil it means that a name for backups created by
678the user should be returned; if REGEXP is non-nil that means to return
679a regexp for matching all such backup files, regardless of the version."
e3f955b6
AS
680 (if regexp
681 (concat (regexp-quote (file-name-nondirectory file))
d4c813e9 682 "\\.~.+" (unless manual "\\.") "~")
f8b72742 683 (expand-file-name (concat (file-name-nondirectory file)
d4c813e9 684 ".~" (subst-char-in-string
ac3f4c6f 685 ?/ ?_ (or rev (vc-working-revision file)))
e3f955b6
AS
686 (unless manual ".") "~")
687 (file-name-directory file))))
e896a9e1
AS
688
689(defun vc-delete-automatic-version-backups (file)
690 "Delete all existing automatic version backups for FILE."
d455f4f7 691 (condition-case nil
a549ce70 692 (mapc
d455f4f7 693 'delete-file
79e954d0 694 (directory-files (or (file-name-directory file) default-directory) t
d455f4f7
SM
695 (vc-version-backup-file-name file nil nil t)))
696 ;; Don't fail when the directory doesn't exist.
697 (file-error nil)))
e896a9e1
AS
698
699(defun vc-make-version-backup (file)
700 "Make a backup copy of FILE, which is assumed in sync with the repository.
701Before doing that, check if there are any old backups and get rid of them."
48b15d3f 702 (unless (and (fboundp 'msdos-long-file-names)
ee9be3de 703 (not (with-no-warnings (msdos-long-file-names))))
48b15d3f 704 (vc-delete-automatic-version-backups file)
27707243
AS
705 (condition-case nil
706 (copy-file file (vc-version-backup-file-name file)
707 nil 'keep-date)
708 ;; It's ok if it doesn't work (e.g. directory not writable),
709 ;; since this is just for efficiency.
bf247b6e 710 (file-error
27707243
AS
711 (message
712 (concat "Warning: Cannot make version backup; "
713 "diff/revert therefore not local"))))))
d445a975
AS
714
715(defun vc-before-save ()
716 "Function to be called by `basic-save-buffer' (in files.el)."
717 ;; If the file on disk is still in sync with the repository,
718 ;; and version backups should be made, copy the file to
719 ;; another name. This enables local diffs and local reverting.
e0607aaa
SM
720 (let ((file buffer-file-name)
721 backend)
f42af255 722 (ignore-errors ;Be careful not to prevent saving the file.
e0607aaa 723 (and (setq backend (vc-backend file))
f42af255 724 (vc-up-to-date-p file)
70e2f6c7 725 (eq (vc-checkout-model backend (list file)) 'implicit)
a749e19d 726 (vc-call-backend backend 'make-version-backups-p file)
f42af255 727 (vc-make-version-backup file)))))
d445a975 728
74d0991f 729(declare-function vc-dir-resynch-file "vc-dir" (&optional fname))
004a00f4 730
dcbbecd4
SM
731(defvar vc-dir-buffers nil "List of vc-dir buffers.")
732
e66eac08 733(defun vc-after-save ()
0e0d9831 734 "Function to be called by `basic-save-buffer' (in files.el)."
5eb2b516 735 ;; If the file in the current buffer is under version control,
0e0d9831
GM
736 ;; up-to-date, and locking is not used for the file, set
737 ;; the state to 'edited and redisplay the mode line.
e0607aaa
SM
738 (let* ((file buffer-file-name)
739 (backend (vc-backend file)))
740 (and backend
b23a2306
AS
741 (or (and (equal (vc-file-getprop file 'vc-checkout-time)
742 (nth 5 (file-attributes file)))
743 ;; File has been saved in the same second in which
744 ;; it was checked out. Clear the checkout-time
745 ;; to avoid confusion.
746 (vc-file-setprop file 'vc-checkout-time nil))
747 t)
70e2f6c7 748 (eq (vc-checkout-model backend (list file)) 'implicit)
dcbbecd4
SM
749 (vc-state-refresh file backend)
750 (vc-mode-line file backend))
751 ;; Try to avoid unnecessary work, a *vc-dir* buffer is
752 ;; present if this is true.
753 (when vc-dir-buffers
754 (vc-dir-resynch-file file))))
04446ed0 755
e2247dc8 756(defvar vc-menu-entry
8f43cbf3 757 `(menu-item ,(purecopy "Version Control") vc-menu-map
e2247dc8
SM
758 :filter vc-menu-map-filter))
759
760(when (boundp 'menu-bar-tools-menu)
761 ;; We do not need to worry here about the placement of this entry
762 ;; because menu-bar.el has already created the proper spot for us
763 ;; and this will simply use it.
764 (define-key menu-bar-tools-menu [vc] vc-menu-entry))
765
5719a098
SM
766(defconst vc-mode-line-map
767 (let ((map (make-sparse-keymap)))
e2247dc8 768 (define-key map [mode-line down-mouse-1] vc-menu-entry)
5719a098
SM
769 map))
770
32ca5ee4 771(defun vc-mode-line (file &optional backend)
7bc2b98b 772 "Set `vc-mode' to display type of version control for FILE.
594722a8 773The value is set in the current buffer, which should be the buffer
32ca5ee4
DN
774visiting FILE.
775If BACKEND is passed use it as the VC backend when computing the result."
67c6f446 776 (interactive (list buffer-file-name))
32ca5ee4
DN
777 (setq backend (or backend (vc-backend file)))
778 (if (not backend)
779 (setq vc-mode nil)
780 (let* ((ml-string (vc-call-backend backend 'mode-line-string file))
781 (ml-echo (get-text-property 0 'help-echo ml-string)))
782 (setq vc-mode
783 (concat
784 " "
785 (if (null vc-display-status)
786 (symbol-name backend)
787 (propertize
788 ml-string
789 'mouse-face 'mode-line-highlight
790 'help-echo
791 (concat (or ml-echo
792 (format "File under the %s version control system"
793 backend))
794 "\nmouse-1: Version Control menu")
795 'local-map vc-mode-line-map)))))
32ca5ee4
DN
796 ;; If the user is root, and the file is not owner-writable,
797 ;; then pretend that we can't write it
798 ;; even though we can (because root can write anything).
799 ;; This way, even root cannot modify a file that isn't locked.
800 (and (equal file buffer-file-name)
801 (not buffer-read-only)
802 (zerop (user-real-uid))
803 (zerop (logand (file-modes buffer-file-name) 128))
804 (setq buffer-read-only t)))
805 (force-mode-line-update)
806 backend)
0e0d9831
GM
807
808(defun vc-default-mode-line-string (backend file)
809 "Return string for placement in modeline by `vc-mode-line' for FILE.
810Format:
811
812 \"BACKEND-REV\" if the file is up-to-date
813 \"BACKEND:REV\" if the file is edited (or locked by the calling user)
814 \"BACKEND:LOCKER:REV\" if the file is locked by somebody else
cad90f3b
EZ
815 \"BACKEND@REV\" if the file was locally added
816 \"BACKEND!REV\" if the file contains conflicts or was removed
817 \"BACKEND?REV\" if the file is under VC, but is missing
0e0d9831
GM
818
819This function assumes that the file is registered."
77bf3f54
DN
820 (let* ((backend-name (symbol-name backend))
821 (state (vc-state file backend))
822 (state-echo nil)
823 (rev (vc-working-revision file backend)))
82c4728d
DN
824 (propertize
825 (cond ((or (eq state 'up-to-date)
3702367b 826 (eq state 'needs-update))
82c4728d 827 (setq state-echo "Up to date file")
77bf3f54 828 (concat backend-name "-" rev))
82c4728d
DN
829 ((stringp state)
830 (setq state-echo (concat "File locked by" state))
77bf3f54 831 (concat backend-name ":" state ":" rev))
45b24b4d
SM
832 ((eq state 'added)
833 (setq state-echo "Locally added file")
77bf3f54 834 (concat backend-name "@" rev))
7fbb4797
DN
835 ((eq state 'conflict)
836 (setq state-echo "File contains conflicts after the last merge")
77bf3f54 837 (concat backend-name "!" rev))
a58b57e2
DN
838 ((eq state 'removed)
839 (setq state-echo "File removed from the VC system")
77bf3f54 840 (concat backend-name "!" rev))
a58b57e2
DN
841 ((eq state 'missing)
842 (setq state-echo "File tracked by the VC system, but missing from the file system")
77bf3f54 843 (concat backend-name "?" rev))
82c4728d
DN
844 (t
845 ;; Not just for the 'edited state, but also a fallback
846 ;; for all other states. Think about different symbols
3702367b 847 ;; for 'needs-update and 'needs-merge.
3a12f9f8 848 (setq state-echo "Locally modified file")
77bf3f54
DN
849 (concat backend-name ":" rev)))
850 'help-echo (concat state-echo " under the " backend-name
3a12f9f8 851 " version control system"))))
f2ee4191 852
a3a39848 853(defun vc-follow-link ()
0e0d9831
GM
854 "If current buffer visits a symbolic link, visit the real file.
855If the real file is already visited in another buffer, make that buffer
856current, and kill the buffer that visits the link."
33f95a82 857 (let* ((true-buffer (find-buffer-visiting buffer-file-truename))
e7f5ddc2
RS
858 (this-buffer (current-buffer)))
859 (if (eq true-buffer this-buffer)
066b7259 860 (let ((truename buffer-file-truename))
d8221951 861 (kill-buffer this-buffer)
e7f5ddc2
RS
862 ;; In principle, we could do something like set-visited-file-name.
863 ;; However, it can't be exactly the same as set-visited-file-name.
864 ;; I'm not going to work out the details right now. -- rms.
d8221951 865 (set-buffer (find-file-noselect truename)))
e7f5ddc2
RS
866 (set-buffer true-buffer)
867 (kill-buffer this-buffer))))
a3a39848 868
b8d1db77
SM
869(defun vc-default-find-file-hook (backend)
870 nil)
871
594722a8 872(defun vc-find-file-hook ()
be4d6a6f 873 "Function for `find-file-hook' activating VC mode if appropriate."
18c8a18e
PE
874 ;; Recompute whether file is version controlled,
875 ;; if user has killed the buffer and revisited.
32ca5ee4
DN
876 (when vc-mode
877 (setq vc-mode nil))
0e0d9831 878 (when buffer-file-name
f2ee4191 879 (vc-file-clearprops buffer-file-name)
8c6eab5a
SM
880 ;; FIXME: Why use a hook? Why pass it buffer-file-name?
881 (add-hook 'vc-mode-line-hook 'vc-mode-line nil t)
32ca5ee4
DN
882 (let (backend)
883 (cond
884 ((setq backend (with-demoted-errors (vc-backend buffer-file-name)))
885 ;; Compute the state and put it in the modeline.
886 (vc-mode-line buffer-file-name backend)
887 (unless vc-make-backup-files
888 ;; Use this variable, not make-backup-files,
889 ;; because this is for things that depend on the file name.
890 (set (make-local-variable 'backup-inhibited) t))
891 ;; Let the backend setup any buffer-local things he needs.
892 (vc-call-backend backend 'find-file-hook))
893 ((let ((link-type (and (not (equal buffer-file-name buffer-file-truename))
894 (vc-backend buffer-file-truename))))
895 (cond ((not link-type) nil) ;Nothing to do.
896 ((eq vc-follow-symlinks nil)
0bfb74a9 897 (message
32ca5ee4
DN
898 "Warning: symbolic link to %s-controlled source file" link-type))
899 ((or (not (eq vc-follow-symlinks 'ask))
900 ;; If we already visited this file by following
901 ;; the link, don't ask again if we try to visit
902 ;; it again. GUD does that, and repeated questions
903 ;; are painful.
904 (get-file-buffer
905 (abbreviate-file-name
906 (file-chase-links buffer-file-name))))
907
908 (vc-follow-link)
909 (message "Followed link to %s" buffer-file-name)
910 (vc-find-file-hook))
911 (t
912 (if (yes-or-no-p (format
913 "Symbolic link to %s-controlled source file; follow link? " link-type))
914 (progn (vc-follow-link)
915 (message "Followed link to %s" buffer-file-name)
916 (vc-find-file-hook))
917 (message
918 "Warning: editing through the link bypasses version control")
919 )))))))))
594722a8 920
be4d6a6f 921(add-hook 'find-file-hook 'vc-find-file-hook)
594722a8 922
f2ee4191 923(defun vc-kill-buffer-hook ()
0e0d9831 924 "Discard VC info about a file when we kill its buffer."
b5446276 925 (when buffer-file-name (vc-file-clearprops buffer-file-name)))
f2ee4191 926
cd32d5d1 927(add-hook 'kill-buffer-hook 'vc-kill-buffer-hook)
f2ee4191 928
14fef9de
SM
929;; Now arrange for (autoloaded) bindings of the main package.
930;; Bindings for this have to go in the global map, as we'll often
931;; want to call them from random buffers.
932
933;; Autoloading works fine, but it prevents shortcuts from appearing
934;; in the menu because they don't exist yet when the menu is built.
935;; (autoload 'vc-prefix-map "vc" nil nil 'keymap)
936(defvar vc-prefix-map
937 (let ((map (make-sparse-keymap)))
938 (define-key map "a" 'vc-update-change-log)
939 (define-key map "b" 'vc-switch-backend)
e4d26892 940 (define-key map "c" 'vc-rollback)
e1aec6fb 941 (define-key map "d" 'vc-dir)
14fef9de
SM
942 (define-key map "g" 'vc-annotate)
943 (define-key map "h" 'vc-insert-headers)
944 (define-key map "i" 'vc-register)
945 (define-key map "l" 'vc-print-log)
32ba3abc 946 (define-key map "L" 'vc-print-root-log)
54d3626e
DN
947 (define-key map "I" 'vc-log-incoming)
948 (define-key map "O" 'vc-log-outgoing)
14fef9de 949 (define-key map "m" 'vc-merge)
370fded4
ER
950 (define-key map "r" 'vc-retrieve-tag)
951 (define-key map "s" 'vc-create-tag)
e4d26892 952 (define-key map "u" 'vc-revert)
14fef9de 953 (define-key map "v" 'vc-next-action)
e4d26892 954 (define-key map "+" 'vc-update)
14fef9de 955 (define-key map "=" 'vc-diff)
32ba3abc 956 (define-key map "D" 'vc-root-diff)
0a0ca7f1 957 (define-key map "~" 'vc-revision-other-window)
14fef9de
SM
958 map))
959(fset 'vc-prefix-map vc-prefix-map)
c1fdf758 960(define-key global-map "\C-xv" 'vc-prefix-map)
624c0e9d 961
e2247dc8
SM
962(defvar vc-menu-map
963 (let ((map (make-sparse-keymap "Version Control")))
964 ;;(define-key map [show-files]
965 ;; '("Show Files under VC" . (vc-directory t)))
370fded4 966 (define-key map [vc-retrieve-tag]
8f43cbf3
DN
967 `(menu-item ,(purecopy "Retrieve Tag") vc-retrieve-tag
968 :help ,(purecopy "Retrieve tagged version or branch")))
370fded4 969 (define-key map [vc-create-tag]
8f43cbf3
DN
970 `(menu-item ,(purecopy "Create Tag") vc-create-tag
971 :help ,(purecopy "Create version tag")))
04991a1c 972 (define-key map [separator1] menu-bar-separator)
6dbb5c76 973 (define-key map [vc-annotate]
8f43cbf3
DN
974 `(menu-item ,(purecopy "Annotate") vc-annotate
975 :help ,(purecopy "Display the edit history of the current file using colors")))
6dbb5c76 976 (define-key map [vc-rename-file]
8f43cbf3
DN
977 `(menu-item ,(purecopy "Rename File") vc-rename-file
978 :help ,(purecopy "Rename file")))
0a0ca7f1 979 (define-key map [vc-revision-other-window]
8f43cbf3
DN
980 `(menu-item ,(purecopy "Show Other Version") vc-revision-other-window
981 :help ,(purecopy "Visit another version of the current file in another window")))
6dbb5c76 982 (define-key map [vc-diff]
8f43cbf3
DN
983 `(menu-item ,(purecopy "Compare with Base Version") vc-diff
984 :help ,(purecopy "Compare file set with the base version")))
32ba3abc 985 (define-key map [vc-root-diff]
8f43cbf3
DN
986 `(menu-item ,(purecopy "Compare Tree with Base Version") vc-root-diff
987 :help ,(purecopy "Compare current tree with the base version")))
e2247dc8 988 (define-key map [vc-update-change-log]
8f43cbf3
DN
989 `(menu-item ,(purecopy "Update ChangeLog") vc-update-change-log
990 :help ,(purecopy "Find change log file and add entries from recent version control logs")))
31527c56
DN
991 (define-key map [vc-log-out]
992 `(menu-item ,(purecopy "Show Outgoing Log") vc-log-outgoing
993 :help ,(purecopy "Show a log of changes that will be sent with a push operation")))
994 (define-key map [vc-log-in]
995 `(menu-item ,(purecopy "Show Incoming Log") vc-log-incoming
996 :help ,(purecopy "Show a log of changes that will be received with a pull operation")))
6dbb5c76 997 (define-key map [vc-print-log]
8f43cbf3
DN
998 `(menu-item ,(purecopy "Show History") vc-print-log
999 :help ,(purecopy "List the change log of the current file set in a window")))
32ba3abc 1000 (define-key map [vc-print-root-log]
8f43cbf3
DN
1001 `(menu-item ,(purecopy "Show Top of the Tree History ") vc-print-root-log
1002 :help ,(purecopy "List the change log for the current tree in a window")))
04991a1c 1003 (define-key map [separator2] menu-bar-separator)
e2247dc8 1004 (define-key map [vc-insert-header]
8f43cbf3
DN
1005 `(menu-item ,(purecopy "Insert Header") vc-insert-headers
1006 :help ,(purecopy "Insert headers into a file for use with a version control system.
1007")))
6dbb5c76 1008 (define-key map [undo]
8f43cbf3
DN
1009 `(menu-item ,(purecopy "Undo Last Check-In") vc-rollback
1010 :help ,(purecopy "Remove the most recent changeset committed to the repository")))
e2247dc8 1011 (define-key map [vc-revert]
8f43cbf3
DN
1012 `(menu-item ,(purecopy "Revert to Base Version") vc-revert
1013 :help ,(purecopy "Revert working copies of the selected file set to their repository contents")))
e2247dc8 1014 (define-key map [vc-update]
8f43cbf3
DN
1015 `(menu-item ,(purecopy "Update to Latest Version") vc-update
1016 :help ,(purecopy "Update the current fileset's files to their tip revisions")))
6dbb5c76 1017 (define-key map [vc-next-action]
8f43cbf3
DN
1018 `(menu-item ,(purecopy "Check In/Out") vc-next-action
1019 :help ,(purecopy "Do the next logical version control operation on the current fileset")))
6dbb5c76 1020 (define-key map [vc-register]
8f43cbf3
DN
1021 `(menu-item ,(purecopy "Register") vc-register
1022 :help ,(purecopy "Register file set into a version control system")))
e1aec6fb 1023 (define-key map [vc-dir]
8f43cbf3
DN
1024 `(menu-item ,(purecopy "VC Dir") vc-dir
1025 :help ,(purecopy "Show the VC status of files in a directory")))
e2247dc8
SM
1026 map))
1027
1028(defalias 'vc-menu-map vc-menu-map)
1029
d270305a 1030(declare-function vc-responsible-backend "vc" (file))
aafb0703 1031
e2247dc8
SM
1032(defun vc-menu-map-filter (orig-binding)
1033 (if (and (symbolp orig-binding) (fboundp orig-binding))
1034 (setq orig-binding (indirect-function orig-binding)))
1035 (let ((ext-binding
f3d57a2c 1036 (when vc-mode
aafb0703 1037 (vc-call-backend
f3d57a2c
DN
1038 (if buffer-file-name
1039 (vc-backend buffer-file-name)
1040 (vc-responsible-backend default-directory))
1041 'extra-menu))))
e2247dc8
SM
1042 ;; Give the VC backend a chance to add menu entries
1043 ;; specific for that backend.
1044 (if (null ext-binding)
98481bad 1045 orig-binding
e2247dc8 1046 (append orig-binding
04991a1c 1047 '((ext-menu-separator "--"))
98481bad 1048 ext-binding))))
738efc8e 1049
cb223bba
DN
1050(defun vc-default-extra-menu (backend)
1051 nil)
1052
594722a8
ER
1053(provide 'vc-hooks)
1054
ce9f8ffb 1055;; arch-tag: 2e5a6fa7-1d30-48e2-8bd0-e3d335f04f32
594722a8 1056;;; vc-hooks.el ends here