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