]> code.delx.au - gnu-emacs/blob - lisp/vc-hooks.el
(vc-menu-map): Replace entries for "Check In" and "Check Out" with
[gnu-emacs] / lisp / vc-hooks.el
1 ;;; vc-hooks.el --- resident support for version-control
2
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
4
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
6 ;; Maintainer: Andre Spiegel <spiegel@inf.fu-berlin.de>
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; This is the always-loaded portion of VC.
28 ;; It takes care VC-related activities that are done when you visit a file,
29 ;; so that vc.el itself is loaded only when you use a VC command.
30 ;; See the commentary of vc.el.
31
32 ;;; Code:
33
34 ;; Customization Variables (the rest is in vc.el)
35
36 (defvar vc-default-back-end nil
37 "*Back-end actually used by this interface; may be SCCS or RCS.
38 The value is only computed when needed to avoid an expensive search.")
39
40 (defvar vc-handle-cvs t
41 "*If non-nil, use VC for files managed with CVS.
42 If it is nil, don't use VC for those files.")
43
44 (defvar vc-rcsdiff-knows-brief nil
45 "*Indicates whether rcsdiff understands the --brief option.
46 The value is either `yes', `no', or nil. If it is nil, VC tries
47 to use --brief and sets this variable to remember whether it worked.")
48
49 (defvar vc-path
50 (if (file-directory-p "/usr/sccs")
51 '("/usr/sccs")
52 nil)
53 "*List of extra directories to search for version control commands.")
54
55 (defvar vc-master-templates
56 '(("%sRCS/%s,v" . RCS) ("%s%s,v" . RCS) ("%sRCS/%s" . RCS)
57 ("%sSCCS/s.%s" . SCCS) ("%ss.%s". SCCS)
58 vc-find-cvs-master)
59 "*Where to look for version-control master files.
60 The first pair corresponding to a given back end is used as a template
61 when creating new masters.
62 Setting this variable to nil turns off use of VC entirely.")
63
64 (defvar vc-make-backup-files nil
65 "*If non-nil, backups of registered files are made as with other files.
66 If nil (the default), files covered by version control don't get backups.")
67
68 (defvar vc-follow-symlinks 'ask
69 "*Indicates what to do if you visit a symbolic link to a file
70 that is under version control. Editing such a file through the
71 link bypasses the version control system, which is dangerous and
72 probably not what you want.
73 If this variable is t, VC follows the link and visits the real file,
74 telling you about it in the echo area. If it is `ask', VC asks for
75 confirmation whether it should follow the link. If nil, the link is
76 visited and a warning displayed.")
77
78 (defvar vc-display-status t
79 "*If non-nil, display revision number and lock status in modeline.
80 Otherwise, not displayed.")
81
82 (defvar vc-consult-headers t
83 "*If non-nil, identify work files by searching for version headers.")
84
85 (defvar vc-keep-workfiles t
86 "*If non-nil, don't delete working files after registering changes.
87 If the back-end is CVS, workfiles are always kept, regardless of the
88 value of this flag.")
89
90 (defvar vc-mistrust-permissions nil
91 "*If non-nil, don't assume that permissions and ownership track
92 version-control status. If nil, do rely on the permissions.
93 See also variable `vc-consult-headers'.")
94
95 (defun vc-mistrust-permissions (file)
96 ;; Access function to the above.
97 (or (eq vc-mistrust-permissions 't)
98 (and vc-mistrust-permissions
99 (funcall vc-mistrust-permissions
100 (vc-backend-subdirectory-name file)))))
101
102 ;; Tell Emacs about this new kind of minor mode
103 (if (not (assoc 'vc-mode minor-mode-alist))
104 (setq minor-mode-alist (cons '(vc-mode vc-mode)
105 minor-mode-alist)))
106
107 (make-variable-buffer-local 'vc-mode)
108 (put 'vc-mode 'permanent-local t)
109
110 ;; We need a notion of per-file properties because the version
111 ;; control state of a file is expensive to derive --- we compute
112 ;; them when the file is initially found, keep them up to date
113 ;; during any subsequent VC operations, and forget them when
114 ;; the buffer is killed.
115
116 (defmacro vc-error-occurred (&rest body)
117 (list 'condition-case nil (cons 'progn (append body '(nil))) '(error t)))
118
119 (defvar vc-file-prop-obarray [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
120 "Obarray for per-file properties.")
121
122 (defvar vc-buffer-backend t)
123 (make-variable-buffer-local 'vc-buffer-backend)
124
125 (defun vc-file-setprop (file property value)
126 ;; set per-file property
127 (put (intern file vc-file-prop-obarray) property value))
128
129 (defun vc-file-getprop (file property)
130 ;; get per-file property
131 (get (intern file vc-file-prop-obarray) property))
132
133 (defun vc-file-clearprops (file)
134 ;; clear all properties of a given file
135 (setplist (intern file vc-file-prop-obarray) nil))
136
137 ;;; Functions that determine property values, by examining the
138 ;;; working file, the master file, or log program output
139
140 (defun vc-match-substring (bn)
141 (buffer-substring (match-beginning bn) (match-end bn)))
142
143 (defun vc-lock-file (file)
144 ;; Generate lock file name corresponding to FILE
145 (let ((master (vc-name file)))
146 (and
147 master
148 (string-match "\\(.*/\\)s\\.\\(.*\\)" master)
149 (concat
150 (substring master (match-beginning 1) (match-end 1))
151 "p."
152 (substring master (match-beginning 2) (match-end 2))))))
153
154 (defun vc-parse-buffer (patterns &optional file properties)
155 ;; Use PATTERNS to parse information out of the current buffer.
156 ;; Each element of PATTERNS is a list of 2 to 3 elements. The first element
157 ;; is the pattern to be matched, and the second (an integer) is the
158 ;; number of the subexpression that should be returned. If there's
159 ;; a third element (also the number of a subexpression), that
160 ;; subexpression is assumed to be a date field and we want the most
161 ;; recent entry matching the template.
162 ;; If FILE and PROPERTIES are given, the latter must be a list of
163 ;; properties of the same length as PATTERNS; each property is assigned
164 ;; the corresponding value.
165 (mapcar (function (lambda (p)
166 (goto-char (point-min))
167 (cond
168 ((eq (length p) 2) ;; search for first entry
169 (let ((value nil))
170 (if (re-search-forward (car p) nil t)
171 (setq value (vc-match-substring (elt p 1))))
172 (if file
173 (progn (vc-file-setprop file (car properties) value)
174 (setq properties (cdr properties))))
175 value))
176 ((eq (length p) 3) ;; search for latest entry
177 (let ((latest-date "") (latest-val))
178 (while (re-search-forward (car p) nil t)
179 (let ((date (vc-match-substring (elt p 2))))
180 (if (string< latest-date date)
181 (progn
182 (setq latest-date date)
183 (setq latest-val
184 (vc-match-substring (elt p 1)))))))
185 (if file
186 (progn (vc-file-setprop file (car properties) latest-val)
187 (setq properties (cdr properties))))
188 latest-val)))))
189 patterns)
190 )
191
192 (defun vc-insert-file (file &optional limit blocksize)
193 ;; Insert the contents of FILE into the current buffer.
194 ;; Optional argument LIMIT is a regexp. If present,
195 ;; the file is inserted in chunks of size BLOCKSIZE
196 ;; (default 8 kByte), until the first occurrence of
197 ;; LIMIT is found. The function returns nil if FILE
198 ;; doesn't exist.
199 (erase-buffer)
200 (cond ((file-exists-p file)
201 (cond (limit
202 (if (not blocksize) (setq blocksize 8192))
203 (let (found s)
204 (while (not found)
205 (setq s (buffer-size))
206 (goto-char (1+ s))
207 (setq found
208 (or (zerop (car (cdr
209 (insert-file-contents file nil s
210 (+ s blocksize)))))
211 (progn (beginning-of-line)
212 (re-search-forward limit nil t)))))))
213 (t (insert-file-contents file)))
214 (set-buffer-modified-p nil)
215 (auto-save-mode nil)
216 t)
217 (t nil)))
218
219 (defun vc-parse-locks (file locks)
220 ;; Parse RCS or SCCS locks.
221 ;; The result is a list of the form ((VERSION USER) (VERSION USER) ...),
222 ;; which is returned and stored into the property `vc-master-locks'.
223 (if (not locks)
224 (vc-file-setprop file 'vc-master-locks 'none)
225 (let ((found t) (index 0) master-locks version user)
226 (cond ((eq (vc-backend file) 'SCCS)
227 (while (string-match "^\\([0-9.]+\\) [0-9.]+ \\([^ ]+\\) .*\n?"
228 locks index)
229 (setq version (substring locks
230 (match-beginning 1) (match-end 1)))
231 (setq user (substring locks
232 (match-beginning 2) (match-end 2)))
233 (setq master-locks (append master-locks
234 (list (cons version user))))
235 (setq index (match-end 0))))
236 ((eq (vc-backend file) 'RCS)
237 (while (string-match "[ \t\n]*\\([^:]+\\):\\([0-9.]+\\)"
238 locks index)
239 (setq version (substring locks
240 (match-beginning 2) (match-end 2)))
241 (setq user (substring locks
242 (match-beginning 1) (match-end 1)))
243 (setq master-locks (append master-locks
244 (list (cons version user))))
245 (setq index (match-end 0)))
246 (if (string-match ";[ \t\n]+strict;" locks index)
247 (vc-file-setprop file 'vc-checkout-model 'manual)
248 (vc-file-setprop file 'vc-checkout-model 'implicit))))
249 (vc-file-setprop file 'vc-master-locks (or master-locks 'none)))))
250
251 (defun vc-simple-command (okstatus command file &rest args)
252 ;; Simple version of vc-do-command, for use in vc-hooks only.
253 ;; Don't switch to the *vc-info* buffer before running the
254 ;; command, because that would change its default directory
255 (save-excursion (set-buffer (get-buffer-create "*vc-info*"))
256 (erase-buffer))
257 (let ((exec-path (append vc-path exec-path)) exec-status
258 ;; Add vc-path to PATH for the execution of this command.
259 (process-environment
260 (cons (concat "PATH=" (getenv "PATH")
261 path-separator
262 (mapconcat 'identity vc-path path-separator))
263 process-environment)))
264 (setq exec-status
265 (apply 'call-process command nil "*vc-info*" nil
266 (append args (list file))))
267 (cond ((> exec-status okstatus)
268 (switch-to-buffer (get-file-buffer file))
269 (shrink-window-if-larger-than-buffer
270 (display-buffer "*vc-info*"))
271 (error "Couldn't find version control information")))
272 exec-status))
273
274 (defun vc-fetch-master-properties (file)
275 ;; Fetch those properties of FILE that are stored in the master file.
276 ;; For an RCS file, we don't get vc-latest-version vc-your-latest-version
277 ;; here because that is slow.
278 ;; That gets done if/when the functions vc-latest-version
279 ;; and vc-your-latest-version get called.
280 (save-excursion
281 (cond
282 ((eq (vc-backend file) 'SCCS)
283 (set-buffer (get-buffer-create "*vc-info*"))
284 (if (vc-insert-file (vc-lock-file file))
285 (vc-parse-locks file (buffer-string))
286 (vc-file-setprop file 'vc-master-locks 'none))
287 (vc-insert-file (vc-name file) "^\001e")
288 (vc-parse-buffer
289 (list '("^\001d D \\([^ ]+\\)" 1)
290 (list (concat "^\001d D \\([^ ]+\\) .* "
291 (regexp-quote (vc-user-login-name)) " ") 1))
292 file
293 '(vc-latest-version vc-your-latest-version)))
294
295 ((eq (vc-backend file) 'RCS)
296 (set-buffer (get-buffer-create "*vc-info*"))
297 (vc-insert-file (vc-name file) "^[0-9]")
298 (vc-parse-buffer
299 (list '("^head[ \t\n]+\\([^;]+\\);" 1)
300 '("^branch[ \t\n]+\\([^;]+\\);" 1)
301 '("^locks[ \t\n]*\\([^;]*;\\([ \t\n]*strict;\\)?\\)" 1))
302 file
303 '(vc-head-version
304 vc-default-branch
305 vc-master-locks))
306 ;; determine vc-master-workfile-version: it is either the head
307 ;; of the trunk, the head of the default branch, or the
308 ;; "default branch" itself, if that is a full revision number.
309 (let ((default-branch (vc-file-getprop file 'vc-default-branch)))
310 (cond
311 ;; no default branch
312 ((or (not default-branch) (string= "" default-branch))
313 (vc-file-setprop file 'vc-master-workfile-version
314 (vc-file-getprop file 'vc-head-version)))
315 ;; default branch is actually a revision
316 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
317 default-branch)
318 (vc-file-setprop file 'vc-master-workfile-version default-branch))
319 ;; else, search for the head of the default branch
320 (t (vc-insert-file (vc-name file) "^desc")
321 (vc-parse-buffer (list (list
322 (concat "^\\("
323 (regexp-quote default-branch)
324 "\\.[0-9]+\\)\ndate[ \t]+\\([0-9.]+\\);") 1 2))
325 file '(vc-master-workfile-version)))))
326 ;; translate the locks
327 (vc-parse-locks file (vc-file-getprop file 'vc-master-locks)))
328
329 ((eq (vc-backend file) 'CVS)
330 (save-excursion
331 ;; Call "cvs status" in the right directory, passing only the
332 ;; nondirectory part of the file name -- otherwise CVS might
333 ;; silently give a wrong result.
334 (let ((default-directory (file-name-directory file)))
335 (vc-simple-command 0 "cvs" (file-name-nondirectory file) "status"))
336 (set-buffer (get-buffer "*vc-info*"))
337 (vc-parse-buffer
338 ;; CVS 1.3 says "RCS Version:", other releases "RCS Revision:",
339 ;; and CVS 1.4a1 says "Repository revision:".
340 '(("\\(RCS Version\\|RCS Revision\\|Repository revision\\):[\t ]+\\([0-9.]+\\)" 2)
341 ("^File: [^ \t]+[ \t]+Status: \\(.*\\)" 1))
342 file
343 '(vc-latest-version vc-cvs-status))
344 ;; Translate those status values that we understand into symbols.
345 ;; Any other value is converted to nil.
346 (let ((status (vc-file-getprop file 'vc-cvs-status)))
347 (cond
348 ((string-match "Up-to-date" status)
349 (vc-file-setprop file 'vc-cvs-status 'up-to-date)
350 (vc-file-setprop file 'vc-checkout-time
351 (nth 5 (file-attributes file))))
352 ((vc-file-setprop file 'vc-cvs-status
353 (cond
354 ((string-match "Locally Modified" status) 'locally-modified)
355 ((string-match "Needs Merge" status) 'needs-merge)
356 ((string-match "Needs \\(Checkout\\|Patch\\)" status)
357 'needs-checkout)
358 ((string-match "Unresolved Conflict" status) 'unresolved-conflict)
359 ((string-match "Locally Added" status) 'locally-added)
360 ((string-match "New file!" status) 'locally-added)
361 (t 'unknown)
362 ))))))))
363 (if (get-buffer "*vc-info*")
364 (kill-buffer (get-buffer "*vc-info*")))))
365
366 ;;; Functions that determine property values, by examining the
367 ;;; working file, the master file, or log program output
368
369 (defun vc-consult-rcs-headers (file)
370 ;; Search for RCS headers in FILE, and set properties
371 ;; accordingly. This function can be disabled by setting
372 ;; vc-consult-headers to nil.
373 ;; Returns: nil if no headers were found
374 ;; (or if the feature is disabled,
375 ;; or if there is currently no buffer
376 ;; visiting FILE)
377 ;; 'rev if a workfile revision was found
378 ;; 'rev-and-lock if revision and lock info was found
379 (cond
380 ((or (not vc-consult-headers)
381 (not (get-file-buffer file))) nil)
382 ((let (status version locking-user)
383 (save-excursion
384 (set-buffer (get-file-buffer file))
385 (goto-char (point-min))
386 (cond
387 ;; search for $Id or $Header
388 ;; -------------------------
389 ((or (and (search-forward "$Id: " nil t)
390 (looking-at "[^ ]+ \\([0-9.]+\\) "))
391 (and (progn (goto-char (point-min))
392 (search-forward "$Header: " nil t))
393 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
394 (goto-char (match-end 0))
395 ;; if found, store the revision number ...
396 (setq version (buffer-substring-no-properties (match-beginning 1)
397 (match-end 1)))
398 ;; ... and check for the locking state
399 (cond
400 ((looking-at
401 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
402 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
403 "[^ ]+ [^ ]+ ")) ; author & state
404 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
405 (cond
406 ;; unlocked revision
407 ((looking-at "\\$")
408 (setq locking-user 'none)
409 (setq status 'rev-and-lock))
410 ;; revision is locked by some user
411 ((looking-at "\\([^ ]+\\) \\$")
412 (setq locking-user
413 (buffer-substring-no-properties (match-beginning 1)
414 (match-end 1)))
415 (setq status 'rev-and-lock))
416 ;; everything else: false
417 (nil)))
418 ;; unexpected information in
419 ;; keyword string --> quit
420 (nil)))
421 ;; search for $Revision
422 ;; --------------------
423 ((re-search-forward (concat "\\$"
424 "Revision: \\([0-9.]+\\) \\$")
425 nil t)
426 ;; if found, store the revision number ...
427 (setq version (buffer-substring-no-properties (match-beginning 1)
428 (match-end 1)))
429 ;; and see if there's any lock information
430 (goto-char (point-min))
431 (if (re-search-forward (concat "\\$" "Locker:") nil t)
432 (cond ((looking-at " \\([^ ]+\\) \\$")
433 (setq locking-user (buffer-substring-no-properties
434 (match-beginning 1)
435 (match-end 1)))
436 (setq status 'rev-and-lock))
437 ((looking-at " *\\$")
438 (setq locking-user 'none)
439 (setq status 'rev-and-lock))
440 (t
441 (setq locking-user 'none)
442 (setq status 'rev-and-lock)))
443 (setq status 'rev)))
444 ;; else: nothing found
445 ;; -------------------
446 (t nil)))
447 (if status (vc-file-setprop file 'vc-workfile-version version))
448 (and (eq status 'rev-and-lock)
449 (eq (vc-backend file) 'RCS)
450 (vc-file-setprop file 'vc-locking-user locking-user)
451 ;; If the file has headers, we don't want to query the master file,
452 ;; because that would eliminate all the performance gain the headers
453 ;; brought us. We therefore use a heuristic for the checkout model
454 ;; now: If we trust the file permissions, and the file is not
455 ;; locked, then if the file is read-only the checkout model is
456 ;; `manual', otherwise `implicit'.
457 (not (vc-mistrust-permissions file))
458 (not (vc-locking-user file))
459 (if (string-match ".r-..-..-." (nth 8 (file-attributes file)))
460 (vc-file-setprop file 'vc-checkout-model 'manual)
461 (vc-file-setprop file 'vc-checkout-model 'implicit)))
462 status))))
463
464 ;;; Access functions to file properties
465 ;;; (Properties should be _set_ using vc-file-setprop, but
466 ;;; _retrieved_ only through these functions, which decide
467 ;;; if the property is already known or not. A property should
468 ;;; only be retrieved by vc-file-getprop if there is no
469 ;;; access function.)
470
471 ;;; properties indicating the backend
472 ;;; being used for FILE
473
474 (defun vc-backend-subdirectory-name (&optional file)
475 ;; Where the master and lock files for the current directory are kept
476 (symbol-name
477 (or
478 (and file (vc-backend file))
479 vc-default-back-end
480 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))))
481
482 (defun vc-name (file)
483 "Return the master name of a file, nil if it is not registered.
484 For CVS, the full name of CVS/Entries is returned."
485 (or (vc-file-getprop file 'vc-name)
486 (let ((name-and-type (vc-registered file)))
487 (if name-and-type
488 (progn
489 (vc-file-setprop file 'vc-backend (cdr name-and-type))
490 (vc-file-setprop file 'vc-name (car name-and-type)))))))
491
492 (defun vc-backend (file)
493 "Return the version-control type of a file, nil if it is not registered."
494 (and file
495 (or (vc-file-getprop file 'vc-backend)
496 (let ((name-and-type (vc-registered file)))
497 (if name-and-type
498 (progn
499 (vc-file-setprop file 'vc-name (car name-and-type))
500 (vc-file-setprop file 'vc-backend (cdr name-and-type))))))))
501
502 (defun vc-checkout-model (file)
503 ;; Return `manual' if the user has to type C-x C-q to check out FILE.
504 ;; Return `implicit' if the file can be modified without locking it first.
505 (or
506 (vc-file-getprop file 'vc-checkout-model)
507 (cond
508 ((eq (vc-backend file) 'SCCS)
509 (vc-file-setprop file 'vc-checkout-model 'manual))
510 ((eq (vc-backend file) 'RCS)
511 (vc-consult-rcs-headers file)
512 (or (vc-file-getprop file 'vc-checkout-model)
513 (progn (vc-fetch-master-properties file)
514 (vc-file-getprop file 'vc-checkout-model))))
515 ((eq (vc-backend file) 'CVS)
516 (vc-file-setprop file 'vc-checkout-model
517 (cond
518 ((getenv "CVSREAD") 'manual)
519 ;; If the file is not writeable, this is probably because the
520 ;; file is being "watched" by other developers. Use "manual"
521 ;; checkout in this case. (If vc-mistrust-permissions was t,
522 ;; we actually shouldn't trust this, but there is no other way
523 ;; to learn this from CVS at the moment (version 1.9).)
524 ((string-match "r-..-..-." (nth 8 (file-attributes file)))
525 'manual)
526 (t 'implicit)))))))
527
528 ;;; properties indicating the locking state
529
530 (defun vc-cvs-status (file)
531 ;; Return the cvs status of FILE
532 ;; (Status field in output of "cvs status")
533 (cond ((vc-file-getprop file 'vc-cvs-status))
534 (t (vc-fetch-master-properties file)
535 (vc-file-getprop file 'vc-cvs-status))))
536
537 (defun vc-master-locks (file)
538 ;; Return the lock entries in the master of FILE.
539 ;; Return 'none if there are no such entries, and a list
540 ;; of the form ((VERSION USER) (VERSION USER) ...) otherwise.
541 (cond ((vc-file-getprop file 'vc-master-locks))
542 (t (vc-fetch-master-properties file)
543 (vc-file-getprop file 'vc-master-locks))))
544
545 (defun vc-master-locking-user (file)
546 ;; Return the master file's idea of who is locking
547 ;; the current workfile version of FILE.
548 ;; Return 'none if it is not locked.
549 (let ((master-locks (vc-master-locks file)) lock)
550 (if (eq master-locks 'none) 'none
551 ;; search for a lock on the current workfile version
552 (setq lock (assoc (vc-workfile-version file) master-locks))
553 (cond (lock (cdr lock))
554 ('none)))))
555
556 (defun vc-lock-from-permissions (file)
557 ;; If the permissions can be trusted for this file, determine the
558 ;; locking state from them. Returns (user-login-name), `none', or nil.
559 ;; This implementation assumes that any file which is under version
560 ;; control and has -rw-r--r-- is locked by its owner. This is true
561 ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--.
562 ;; We have to be careful not to exclude files with execute bits on;
563 ;; scripts can be under version control too. Also, we must ignore the
564 ;; group-read and other-read bits, since paranoid users turn them off.
565 ;; This hack wins because calls to the somewhat expensive
566 ;; `vc-fetch-master-properties' function only have to be made if
567 ;; (a) the file is locked by someone other than the current user,
568 ;; or (b) some untoward manipulation behind vc's back has changed
569 ;; the owner or the `group' or `other' write bits.
570 (let ((attributes (file-attributes file)))
571 (if (not (vc-mistrust-permissions file))
572 (cond ((string-match ".r-..-..-." (nth 8 attributes))
573 (vc-file-setprop file 'vc-locking-user 'none))
574 ((and (= (nth 2 attributes) (user-uid))
575 (string-match ".rw..-..-." (nth 8 attributes)))
576 (vc-file-setprop file 'vc-locking-user (vc-user-login-name)))
577 (nil)))))
578
579 (defun vc-user-login-name (&optional uid)
580 ;; Return the name under which the user is logged in, as a string.
581 ;; (With optional argument UID, return the name of that user.)
582 ;; This function does the same as `user-login-name', but unlike
583 ;; that, it never returns nil. If a UID cannot be resolved, that
584 ;; UID is returned as a string.
585 (or (user-login-name uid)
586 (and uid (number-to-string uid))
587 (number-to-string (user-uid))))
588
589 (defun vc-file-owner (file)
590 ;; Return who owns FILE (user name, as a string).
591 (vc-user-login-name (nth 2 (file-attributes file))))
592
593 (defun vc-rcs-lock-from-diff (file)
594 ;; Diff the file against the master version. If differences are found,
595 ;; mark the file locked. This is only used for RCS with non-strict
596 ;; locking. (If "rcsdiff" doesn't understand --brief, we do a double-take
597 ;; and remember the fact for the future.)
598 (let* ((version (concat "-r" (vc-workfile-version file)))
599 (status (if (eq vc-rcsdiff-knows-brief 'no)
600 (vc-simple-command 1 "rcsdiff" file version)
601 (vc-simple-command 2 "rcsdiff" file "--brief" version))))
602 (if (eq status 2)
603 (if (not vc-rcsdiff-knows-brief)
604 (setq vc-rcsdiff-knows-brief 'no
605 status (vc-simple-command 1 "rcsdiff" file version))
606 (error "rcsdiff failed."))
607 (if (not vc-rcsdiff-knows-brief) (setq vc-rcsdiff-knows-brief 'yes)))
608 (if (zerop status)
609 (vc-file-setprop file 'vc-locking-user 'none)
610 (vc-file-setprop file 'vc-locking-user (vc-file-owner file)))))
611
612 (defun vc-locking-user (file)
613 ;; Return the name of the person currently holding a lock on FILE.
614 ;; Return nil if there is no such person.
615 ;; Under CVS, a file is considered locked if it has been modified since
616 ;; it was checked out.
617 ;; The property is cached. It is only looked up if it is currently nil.
618 ;; Note that, for a file that is not locked, the actual property value
619 ;; is `none', to distinguish it from an unknown locking state. That value
620 ;; is converted to nil by this function, and returned to the caller.
621 (let ((locking-user (vc-file-getprop file 'vc-locking-user)))
622 (if locking-user
623 ;; if we already know the property, return it
624 (if (eq locking-user 'none) nil locking-user)
625
626 ;; otherwise, infer the property...
627 (cond
628 ((eq (vc-backend file) 'CVS)
629 (or (and (eq (vc-checkout-model file) 'manual)
630 (vc-lock-from-permissions file))
631 (and (equal (vc-file-getprop file 'vc-checkout-time)
632 (nth 5 (file-attributes file)))
633 (vc-file-setprop file 'vc-locking-user 'none))
634 (vc-file-setprop file 'vc-locking-user (vc-file-owner file))))
635
636 ((eq (vc-backend file) 'RCS)
637 (let (p-lock)
638
639 ;; Check for RCS headers first
640 (or (eq (vc-consult-rcs-headers file) 'rev-and-lock)
641
642 ;; If there are no headers, try to learn it
643 ;; from the permissions.
644 (and (setq p-lock (vc-lock-from-permissions file))
645 (if (eq p-lock 'none)
646
647 ;; If the permissions say "not locked", we know
648 ;; that the checkout model must be `manual'.
649 (vc-file-setprop file 'vc-checkout-model 'manual)
650
651 ;; If the permissions say "locked", we can only trust
652 ;; this *if* the checkout model is `manual'.
653 (eq (vc-checkout-model file) 'manual)))
654
655 ;; Otherwise, use lock information from the master file.
656 (vc-file-setprop file 'vc-locking-user
657 (vc-master-locking-user file)))
658
659 ;; Finally, if the file is not explicitly locked
660 ;; it might still be locked implicitly.
661 (and (eq (vc-file-getprop file 'vc-locking-user) 'none)
662 (eq (vc-checkout-model file) 'implicit)
663 (vc-rcs-lock-from-diff file))))
664
665 ((eq (vc-backend file) 'SCCS)
666 (or (vc-lock-from-permissions file)
667 (vc-file-setprop file 'vc-locking-user
668 (vc-master-locking-user file)))))
669
670 ;; convert a possible 'none value
671 (setq locking-user (vc-file-getprop file 'vc-locking-user))
672 (if (eq locking-user 'none) nil locking-user))))
673
674 ;;; properties to store current and recent version numbers
675
676 (defun vc-latest-version (file)
677 ;; Return version level of the latest version of FILE
678 (cond ((vc-file-getprop file 'vc-latest-version))
679 (t (vc-fetch-properties file)
680 (vc-file-getprop file 'vc-latest-version))))
681
682 (defun vc-your-latest-version (file)
683 ;; Return version level of the latest version of FILE checked in by you
684 (cond ((vc-file-getprop file 'vc-your-latest-version))
685 (t (vc-fetch-properties file)
686 (vc-file-getprop file 'vc-your-latest-version))))
687
688 (defun vc-master-workfile-version (file)
689 ;; Return the master file's idea of what is the current workfile version.
690 ;; This property is defined for RCS only.
691 (cond ((vc-file-getprop file 'vc-master-workfile-version))
692 (t (vc-fetch-master-properties file)
693 (vc-file-getprop file 'vc-master-workfile-version))))
694
695 (defun vc-fetch-properties (file)
696 ;; Fetch vc-latest-version and vc-your-latest-version
697 ;; if that wasn't already done.
698 (cond
699 ((eq (vc-backend file) 'RCS)
700 (save-excursion
701 (set-buffer (get-buffer-create "*vc-info*"))
702 (vc-insert-file (vc-name file) "^desc")
703 (vc-parse-buffer
704 (list '("^\\([0-9]+\\.[0-9.]+\\)\ndate[ \t]+\\([0-9.]+\\);" 1 2)
705 (list (concat "^\\([0-9]+\\.[0-9.]+\\)\n"
706 "date[ \t]+\\([0-9.]+\\);[ \t]+"
707 "author[ \t]+"
708 (regexp-quote (vc-user-login-name)) ";") 1 2))
709 file
710 '(vc-latest-version vc-your-latest-version))
711 (if (get-buffer "*vc-info*")
712 (kill-buffer (get-buffer "*vc-info*")))))
713 (t (vc-fetch-master-properties file))
714 ))
715
716 (defun vc-workfile-version (file)
717 ;; Return version level of the current workfile FILE
718 ;; This is attempted by first looking at the RCS keywords.
719 ;; If there are no keywords in the working file,
720 ;; vc-master-workfile-version is taken.
721 ;; Note that this property is cached, that is, it is only
722 ;; looked up if it is nil.
723 ;; For SCCS, this property is equivalent to vc-latest-version.
724 (cond ((vc-file-getprop file 'vc-workfile-version))
725 ((eq (vc-backend file) 'SCCS) (vc-latest-version file))
726 ((eq (vc-backend file) 'RCS)
727 (if (vc-consult-rcs-headers file)
728 (vc-file-getprop file 'vc-workfile-version)
729 (let ((rev (cond ((vc-master-workfile-version file))
730 ((vc-latest-version file)))))
731 (vc-file-setprop file 'vc-workfile-version rev)
732 rev)))
733 ((eq (vc-backend file) 'CVS)
734 (if (vc-consult-rcs-headers file) ;; CVS
735 (vc-file-getprop file 'vc-workfile-version)
736 (catch 'found
737 (vc-find-cvs-master (file-name-directory file)
738 (file-name-nondirectory file)))
739 (vc-file-getprop file 'vc-workfile-version)))))
740
741 ;;; actual version-control code starts here
742
743 (defun vc-registered (file)
744 (let (handler handlers)
745 (if (boundp 'file-name-handler-alist)
746 (setq handler (find-file-name-handler file 'vc-registered)))
747 (if handler
748 (funcall handler 'vc-registered file)
749 ;; Search for a master corresponding to the given file
750 (let ((dirname (or (file-name-directory file) ""))
751 (basename (file-name-nondirectory file)))
752 (catch 'found
753 (mapcar
754 (function (lambda (s)
755 (if (atom s)
756 (funcall s dirname basename)
757 (let ((trial (format (car s) dirname basename)))
758 (if (and (file-exists-p trial)
759 ;; Make sure the file we found with name
760 ;; TRIAL is not the source file itself.
761 ;; That can happen with RCS-style names
762 ;; if the file name is truncated
763 ;; (e.g. to 14 chars). See if either
764 ;; directory or attributes differ.
765 (or (not (string= dirname
766 (file-name-directory trial)))
767 (not (equal
768 (file-attributes file)
769 (file-attributes trial)))))
770 (throw 'found (cons trial (cdr s))))))))
771 vc-master-templates)
772 nil)))))
773
774 (defun vc-find-cvs-master (dirname basename)
775 ;; Check if DIRNAME/BASENAME is handled by CVS.
776 ;; If it is, do a (throw 'found (cons MASTER 'CVS)).
777 ;; Note: This function throws the name of CVS/Entries
778 ;; NOT that of the RCS master file (because we wouldn't be able
779 ;; to access it under remote CVS).
780 ;; The function returns nil if DIRNAME/BASENAME is not handled by CVS.
781 (if (and vc-handle-cvs
782 (file-directory-p (concat dirname "CVS/"))
783 (file-readable-p (concat dirname "CVS/Entries")))
784 (let ((file (concat dirname basename))
785 ;; make sure that the file name is searched
786 ;; case-sensitively
787 (case-fold-search nil)
788 buffer)
789 (unwind-protect
790 (save-excursion
791 (setq buffer (set-buffer (get-buffer-create "*vc-info*")))
792 (vc-insert-file (concat dirname "CVS/Entries"))
793 (goto-char (point-min))
794 (cond
795 ;; entry for a "locally added" file (not yet committed)
796 ((re-search-forward
797 (concat "^/" (regexp-quote basename) "/0/") nil t)
798 (vc-file-setprop file 'vc-checkout-time 0)
799 (vc-file-setprop file 'vc-workfile-version "0")
800 (throw 'found (cons (concat dirname "CVS/Entries") 'CVS)))
801 ;; normal entry
802 ((re-search-forward
803 (concat "^/" (regexp-quote basename)
804 ;; revision
805 "/\\([^/]*\\)"
806 ;; timestamp
807 "/[A-Z][a-z][a-z]" ;; week day (irrelevant)
808 " \\([A-Z][a-z][a-z]\\)" ;; month name
809 " *\\([0-9]*\\)" ;; day of month
810 " \\([0-9]*\\):\\([0-9]*\\):\\([0-9]*\\)" ;; hms
811 " \\([0-9]*\\)" ;; year
812 ;; optional conflict field
813 "\\(+[^/]*\\)?/")
814 nil t)
815 ;; We found it. Store away version number now that we
816 ;; are anyhow so close to finding it.
817 (vc-file-setprop file
818 'vc-workfile-version
819 (match-string 1))
820 ;; If the file hasn't been modified since checkout,
821 ;; store the checkout-time.
822 (let ((mtime (nth 5 (file-attributes file)))
823 (second (string-to-number (match-string 6)))
824 (minute (string-to-number (match-string 5)))
825 (hour (string-to-number (match-string 4)))
826 (day (string-to-number (match-string 3)))
827 (year (string-to-number (match-string 7))))
828 (if (equal mtime
829 (encode-time
830 second minute hour day
831 (/ (string-match
832 (match-string 2)
833 "xxxJanFebMarAprMayJunJulAugSepOctNovDec")
834 3)
835 year 0))
836 (vc-file-setprop file 'vc-checkout-time mtime)
837 (vc-file-setprop file 'vc-checkout-time 0)))
838 (throw 'found (cons (concat dirname "CVS/Entries") 'CVS)))
839 ;; entry with arbitrary text as timestamp
840 ;; (this means we should consider it modified)
841 ((re-search-forward
842 (concat "^/" (regexp-quote basename)
843 ;; revision
844 "/\\([^/]*\\)"
845 ;; timestamp (arbitrary text)
846 "/[^/]*"
847 ;; optional conflict field
848 "\\(+[^/]*\\)?/")
849 nil t)
850 ;; We found it. Store away version number now that we
851 ;; are anyhow so close to finding it.
852 (vc-file-setprop file 'vc-workfile-version (match-string 1))
853 (vc-file-setprop file 'vc-checkout-time 0))
854 (t nil)))
855 (kill-buffer buffer)))))
856
857 (defun vc-buffer-backend ()
858 "Return the version-control type of the visited file, or nil if none."
859 (if (eq vc-buffer-backend t)
860 (setq vc-buffer-backend (vc-backend (buffer-file-name)))
861 vc-buffer-backend))
862
863 (defun vc-toggle-read-only (&optional verbose)
864 "Change read-only status of current buffer, perhaps via version control.
865 If the buffer is visiting a file registered with version control,
866 then check the file in or out. Otherwise, just change the read-only flag
867 of the buffer. With prefix argument, ask for version number."
868 (interactive "P")
869 (if (or (and (boundp 'vc-dired-mode) vc-dired-mode)
870 ;; use boundp because vc.el might not be loaded
871 (vc-backend (buffer-file-name)))
872 (vc-next-action verbose)
873 (toggle-read-only)))
874 (define-key global-map "\C-x\C-q" 'vc-toggle-read-only)
875
876 (defun vc-after-save ()
877 ;; Function to be called by basic-save-buffer (in files.el).
878 ;; If the file in the current buffer is under version control,
879 ;; not locked, and the checkout model for it is `implicit',
880 ;; mark it "locked" and redisplay the mode line.
881 (let ((file (buffer-file-name)))
882 (and (vc-file-getprop file 'vc-backend)
883 ;; ...check the property directly, not through the function of the
884 ;; same name. Otherwise Emacs would check for a master file
885 ;; each time a non-version-controlled buffer is saved.
886 ;; The property is computed when the file is visited, so if it
887 ;; is `nil' now, it is certain that the file is NOT
888 ;; version-controlled.
889 (or (and (equal (vc-file-getprop file 'vc-checkout-time)
890 (nth 5 (file-attributes file)))
891 ;; File has been saved in the same second in which
892 ;; it was checked out. Clear the checkout-time
893 ;; to avoid confusion.
894 (vc-file-setprop file 'vc-checkout-time nil))
895 t)
896 (not (vc-locking-user file))
897 (eq (vc-checkout-model file) 'implicit)
898 (vc-file-setprop file 'vc-locking-user (vc-user-login-name))
899 (or (and (eq (vc-backend file) 'CVS)
900 (vc-file-setprop file 'vc-cvs-status nil))
901 t)
902 (vc-mode-line file))))
903
904 (defun vc-mode-line (file &optional label)
905 "Set `vc-mode' to display type of version control for FILE.
906 The value is set in the current buffer, which should be the buffer
907 visiting FILE. Second optional arg LABEL is put in place of version
908 control system name."
909 (interactive (list buffer-file-name nil))
910 (let ((vc-type (vc-backend file)))
911 (setq vc-mode
912 (and vc-type
913 (concat " " (or label (symbol-name vc-type))
914 (and vc-display-status (vc-status file)))))
915 ;; If the file is locked by some other user, make
916 ;; the buffer read-only. Like this, even root
917 ;; cannot modify a file that someone else has locked.
918 (and vc-type
919 (equal file (buffer-file-name))
920 (vc-locking-user file)
921 (not (string= (vc-user-login-name) (vc-locking-user file)))
922 (setq buffer-read-only t))
923 ;; If the user is root, and the file is not owner-writable,
924 ;; then pretend that we can't write it
925 ;; even though we can (because root can write anything).
926 ;; This way, even root cannot modify a file that isn't locked.
927 (and vc-type
928 (equal file (buffer-file-name))
929 (not buffer-read-only)
930 (zerop (user-real-uid))
931 (zerop (logand (file-modes (buffer-file-name)) 128))
932 (setq buffer-read-only t))
933 (force-mode-line-update)
934 ;;(set-buffer-modified-p (buffer-modified-p)) ;;use this if Emacs 18
935 vc-type))
936
937 (defun vc-status (file)
938 ;; Return string for placement in modeline by `vc-mode-line'.
939 ;; Format:
940 ;;
941 ;; "-REV" if the revision is not locked
942 ;; ":REV" if the revision is locked by the user
943 ;; ":LOCKER:REV" if the revision is locked by somebody else
944 ;; " @@" for a CVS file that is added, but not yet committed
945 ;;
946 ;; In the CVS case, a "locked" working file is a
947 ;; working file that is modified with respect to the master.
948 ;; The file is "locked" from the moment when the user saves
949 ;; the modified buffer.
950 ;;
951 ;; This function assumes that the file is registered.
952
953 (let ((locker (vc-locking-user file))
954 (rev (vc-workfile-version file)))
955 (cond ((string= "0" rev)
956 " @@")
957 ((not locker)
958 (concat "-" rev))
959 ((string= locker (vc-user-login-name))
960 (concat ":" rev))
961 (t
962 (concat ":" locker ":" rev)))))
963
964 (defun vc-follow-link ()
965 ;; If the current buffer visits a symbolic link, this function makes it
966 ;; visit the real file instead. If the real file is already visited in
967 ;; another buffer, make that buffer current, and kill the buffer
968 ;; that visits the link.
969 (let* ((truename (abbreviate-file-name (file-chase-links buffer-file-name)))
970 (true-buffer (find-buffer-visiting truename))
971 (this-buffer (current-buffer)))
972 (if (eq true-buffer this-buffer)
973 (progn
974 (kill-buffer this-buffer)
975 ;; In principle, we could do something like set-visited-file-name.
976 ;; However, it can't be exactly the same as set-visited-file-name.
977 ;; I'm not going to work out the details right now. -- rms.
978 (set-buffer (find-file-noselect truename)))
979 (set-buffer true-buffer)
980 (kill-buffer this-buffer))))
981
982 ;;; install a call to the above as a find-file hook
983 (defun vc-find-file-hook ()
984 ;; Recompute whether file is version controlled,
985 ;; if user has killed the buffer and revisited.
986 (cond
987 (buffer-file-name
988 (vc-file-clearprops buffer-file-name)
989 (cond
990 ((vc-backend buffer-file-name)
991 (vc-mode-line buffer-file-name)
992 (cond ((not vc-make-backup-files)
993 ;; Use this variable, not make-backup-files,
994 ;; because this is for things that depend on the file name.
995 (make-local-variable 'backup-inhibited)
996 (setq backup-inhibited t))))
997 ((let* ((link (file-symlink-p buffer-file-name))
998 (link-type (and link (vc-backend (file-chase-links link)))))
999 (if link-type
1000 (cond ((eq vc-follow-symlinks nil)
1001 (message
1002 "Warning: symbolic link to %s-controlled source file" link-type))
1003 ((or (not (eq vc-follow-symlinks 'ask))
1004 ;; If we already visited this file by following
1005 ;; the link, don't ask again if we try to visit
1006 ;; it again. GUD does that, and repeated questions
1007 ;; are painful.
1008 (get-file-buffer
1009 (abbreviate-file-name (file-chase-links buffer-file-name))))
1010
1011 (vc-follow-link)
1012 (message "Followed link to %s" buffer-file-name)
1013 (vc-find-file-hook))
1014 (t
1015 (if (yes-or-no-p (format
1016 "Symbolic link to %s-controlled source file; follow link? " link-type))
1017 (progn (vc-follow-link)
1018 (message "Followed link to %s" buffer-file-name)
1019 (vc-find-file-hook))
1020 (message
1021 "Warning: editing through the link bypasses version control")
1022 ))))))))))
1023
1024 (add-hook 'find-file-hooks 'vc-find-file-hook)
1025
1026 ;;; more hooks, this time for file-not-found
1027 (defun vc-file-not-found-hook ()
1028 "When file is not found, try to check it out from RCS or SCCS.
1029 Returns t if checkout was successful, nil otherwise."
1030 (if (vc-backend buffer-file-name)
1031 (save-excursion
1032 (require 'vc)
1033 (setq default-directory (file-name-directory (buffer-file-name)))
1034 (not (vc-error-occurred (vc-checkout buffer-file-name))))))
1035
1036 (add-hook 'find-file-not-found-hooks 'vc-file-not-found-hook)
1037
1038 ;; Discard info about a file when we kill its buffer.
1039 (defun vc-kill-buffer-hook ()
1040 (if (stringp (buffer-file-name))
1041 (progn
1042 (vc-file-clearprops (buffer-file-name))
1043 (kill-local-variable 'vc-buffer-backend))))
1044
1045 ;;;(add-hook 'kill-buffer-hook 'vc-kill-buffer-hook)
1046
1047 ;;; Now arrange for bindings and autoloading of the main package.
1048 ;;; Bindings for this have to go in the global map, as we'll often
1049 ;;; want to call them from random buffers.
1050
1051 (setq vc-prefix-map (lookup-key global-map "\C-xv"))
1052 (if (not (keymapp vc-prefix-map))
1053 (progn
1054 (setq vc-prefix-map (make-sparse-keymap))
1055 (define-key global-map "\C-xv" vc-prefix-map)
1056 (define-key vc-prefix-map "a" 'vc-update-change-log)
1057 (define-key vc-prefix-map "c" 'vc-cancel-version)
1058 (define-key vc-prefix-map "d" 'vc-directory)
1059 (define-key vc-prefix-map "g" 'vc-annotate)
1060 (define-key vc-prefix-map "h" 'vc-insert-headers)
1061 (define-key vc-prefix-map "i" 'vc-register)
1062 (define-key vc-prefix-map "l" 'vc-print-log)
1063 (define-key vc-prefix-map "r" 'vc-retrieve-snapshot)
1064 (define-key vc-prefix-map "s" 'vc-create-snapshot)
1065 (define-key vc-prefix-map "u" 'vc-revert-buffer)
1066 (define-key vc-prefix-map "v" 'vc-next-action)
1067 (define-key vc-prefix-map "=" 'vc-diff)
1068 (define-key vc-prefix-map "~" 'vc-version-other-window)))
1069
1070 (if (not (boundp 'vc-menu-map))
1071 ;; Don't do the menu bindings if menu-bar.el wasn't loaded to defvar
1072 ;; vc-menu-map.
1073 ()
1074 ;;(define-key vc-menu-map [show-files]
1075 ;; '("Show Files under VC" . (vc-directory t)))
1076 (define-key vc-menu-map [vc-retrieve-snapshot]
1077 '("Retrieve Snapshot" . vc-retrieve-snapshot))
1078 (define-key vc-menu-map [vc-create-snapshot]
1079 '("Create Snapshot" . vc-create-snapshot))
1080 (define-key vc-menu-map [vc-directory] '("Show Locked Files" . vc-directory))
1081 (define-key vc-menu-map [separator1] '("----"))
1082 (define-key vc-menu-map [vc-annotate] '("Annotate" . vc-annotate))
1083 (define-key vc-menu-map [vc-rename-file] '("Rename File" . vc-rename-file))
1084 (define-key vc-menu-map [vc-version-other-window]
1085 '("Show Other Version" . vc-version-other-window))
1086 (define-key vc-menu-map [vc-diff] '("Compare with Last Version" . vc-diff))
1087 (define-key vc-menu-map [vc-update-change-log]
1088 '("Update ChangeLog" . vc-update-change-log))
1089 (define-key vc-menu-map [vc-print-log] '("Show History" . vc-print-log))
1090 (define-key vc-menu-map [separator2] '("----"))
1091 (define-key vc-menu-map [undo] '("Undo Last Check-In" . vc-cancel-version))
1092 (define-key vc-menu-map [vc-revert-buffer]
1093 '("Revert to Last Version" . vc-revert-buffer))
1094 (define-key vc-menu-map [vc-insert-header]
1095 '("Insert Header" . vc-insert-headers))
1096 (define-key vc-menu-map [vc-next-action] '("Check In/Out" . vc-next-action))
1097 (define-key vc-menu-map [vc-register] '("Register" . vc-register)))
1098
1099 (put 'vc-rename-file 'menu-enable 'vc-mode)
1100 (put 'vc-annotate 'menu-enable '(eq (vc-buffer-backend) 'CVS))
1101 (put 'vc-version-other-window 'menu-enable 'vc-mode)
1102 (put 'vc-diff 'menu-enable 'vc-mode)
1103 (put 'vc-update-change-log 'menu-enable
1104 '(eq (vc-buffer-backend) 'RCS))
1105 (put 'vc-print-log 'menu-enable 'vc-mode)
1106 (put 'vc-cancel-version 'menu-enable 'vc-mode)
1107 (put 'vc-revert-buffer 'menu-enable 'vc-mode)
1108 (put 'vc-insert-headers 'menu-enable 'vc-mode)
1109 (put 'vc-next-action 'menu-enable 'vc-mode)
1110 (put 'vc-register 'menu-enable '(and buffer-file-name (not vc-mode)))
1111
1112 (provide 'vc-hooks)
1113
1114 ;;; vc-hooks.el ends here