Removed auto-mode-alist hacking for html-mode to files.el.
[bpt/emacs.git] / lisp / vc-hooks.el
CommitLineData
aae56ea7 1;;; vc-hooks.el --- resident support for version-control
594722a8 2
38179d42 3;; Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
594722a8
ER
4
5;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
f2ee4191
RS
6;; Modified by:
7;; Per Cederqvist <ceder@lysator.liu.se>
8;; Andre Spiegel <spiegel@berlin.informatik.uni-stuttgart.de>
594722a8
ER
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software; you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
14;; the Free Software Foundation; either version 2, or (at your option)
15;; any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
23;; along with GNU Emacs; see the file COPYING. If not, write to
24;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25
26;;; Commentary:
27
f2ee4191
RS
28;; This is the always-loaded portion of VC.
29;; It takes care VC-related activities that are done when you visit a file,
30;; so that vc.el itself is loaded only when you use a VC command.
594722a8
ER
31;; See the commentary of vc.el.
32
33;;; Code:
34
e1c0c2d1
KH
35;; Customization Variables (the rest is in vc.el)
36
37(defvar vc-default-back-end nil
38 "*Back-end actually used by this interface; may be SCCS or RCS.
39The value is only computed when needed to avoid an expensive search.")
40
0b086efb
RS
41(defvar vc-handle-cvs t
42 "*If non-nil, use VC for files managed with CVS.
43If it is nil, don't use VC for those files.")
44
31888047
AS
45(defvar vc-rcsdiff-knows-brief nil
46 "*Indicates whether rcsdiff understands the --brief option.
47The value is either `yes', `no', or nil. If it is nil, VC tries
48to use --brief and sets this variable to remember whether it worked.")
49
e1c0c2d1
KH
50(defvar vc-path
51 (if (file-directory-p "/usr/sccs")
52 '("/usr/sccs")
53 nil)
54 "*List of extra directories to search for version control commands.")
55
594722a8
ER
56(defvar vc-master-templates
57 '(("%sRCS/%s,v" . RCS) ("%s%s,v" . RCS) ("%sRCS/%s" . RCS)
174edc13
RS
58 ("%sSCCS/s.%s" . SCCS) ("%ss.%s". SCCS)
59 vc-find-cvs-master)
594722a8
ER
60 "*Where to look for version-control master files.
61The first pair corresponding to a given back end is used as a template
62when creating new masters.")
63
64(defvar vc-make-backup-files nil
5032bd23 65 "*If non-nil, backups of registered files are made as with other files.
9228cfac 66If nil (the default), files covered by version control don't get backups.")
594722a8 67
b8063212
AS
68(defvar vc-follow-symlinks 'ask
69 "*Indicates what to do if you visit a symbolic link to a file
70that is under version control. Editing such a file through the
71link bypasses the version control system, which is dangerous and
72probably not what you want.
73 If this variable is t, VC follows the link and visits the real file,
74telling you about it in the echo area. If it is `ask', VC asks for
75confirmation whether it should follow the link. If nil, the link is
76visited and a warning displayed.")
77
624c0e9d
RS
78(defvar vc-display-status t
79 "*If non-nil, display revision number and lock status in modeline.
198d5c00
RS
80Otherwise, not displayed.")
81
e1c0c2d1 82(defvar vc-consult-headers t
95420811 83 "*If non-nil, identify work files by searching for version headers.")
e1c0c2d1 84
e1c0c2d1
KH
85(defvar vc-keep-workfiles t
86 "*If non-nil, don't delete working files after registering changes.
87If the back-end is CVS, workfiles are always kept, regardless of the
88value of this flag.")
89
e66eac08 90(defvar vc-mistrust-permissions nil
95420811
AS
91 "*If non-nil, don't assume that permissions and ownership track
92version-control status. If nil, do rely on the permissions.
93See also variable `vc-consult-headers'.")
e66eac08
AS
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
594722a8 102;; Tell Emacs about this new kind of minor mode
7bc2b98b
ER
103(if (not (assoc 'vc-mode minor-mode-alist))
104 (setq minor-mode-alist (cons '(vc-mode vc-mode)
594722a8
ER
105 minor-mode-alist)))
106
7bc2b98b 107(make-variable-buffer-local 'vc-mode)
c43e436c 108(put 'vc-mode 'permanent-local t)
594722a8
ER
109
110;; We need a notion of per-file properties because the version
f2ee4191
RS
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.
594722a8 115
80169ab5
ER
116(defmacro vc-error-occurred (&rest body)
117 (list 'condition-case nil (cons 'progn (append body '(nil))) '(error t)))
118
594722a8
ER
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
f2ee4191
RS
122(defvar vc-buffer-backend t)
123(make-variable-buffer-local 'vc-buffer-backend)
124
594722a8
ER
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
e1c0c2d1
KH
133(defun vc-file-clearprops (file)
134 ;; clear all properties of a given file
135 (setplist (intern file vc-file-prop-obarray) nil))
f2ee4191 136
02d383eb
RS
137;;; Functions that determine property values, by examining the
138;;; working file, the master file, or log program output
e1c0c2d1
KH
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
02d383eb
RS
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
a7acbbe4 196 ;; (default 8 kByte), until the first occurrence of
02d383eb
RS
197 ;; LIMIT is found. The function returns nil if FILE
198 ;; doesn't exist.
07de4c3d 199 (erase-buffer)
02d383eb
RS
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))))
e66eac08
AS
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))))
02d383eb
RS
249 (vc-file-setprop file 'vc-master-locks (or master-locks 'none)))))
250
7064821c
AS
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
02d383eb
RS
274(defun vc-fetch-master-properties (file)
275 ;; Fetch those properties of FILE that are stored in the master file.
1efcbf46
RS
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.
02d383eb
RS
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))
07de4c3d 285 (vc-parse-locks file (buffer-string))
02d383eb
RS
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 (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*"))
e66eac08 297 (vc-insert-file (vc-name file) "^[0-9]")
02d383eb
RS
298 (vc-parse-buffer
299 (list '("^head[ \t\n]+\\([^;]+\\);" 1)
300 '("^branch[ \t\n]+\\([^;]+\\);" 1)
e66eac08 301 '("^locks[ \t\n]*\\([^;]*;\\([ \t\n]*strict;\\)?\\)" 1))
02d383eb
RS
302 file
303 '(vc-head-version
304 vc-default-branch
1efcbf46 305 vc-master-locks))
af5e65b9
AS
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.
02d383eb
RS
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))
af5e65b9 313 (vc-file-setprop file 'vc-master-workfile-version
02d383eb
RS
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)
af5e65b9
AS
318 (vc-file-setprop file 'vc-master-workfile-version default-branch))
319 ;; else, search for the head of the default branch
07de4c3d 320 (t (vc-insert-file (vc-name file) "^desc")
1efcbf46 321 (vc-parse-buffer (list (list
02d383eb
RS
322 (concat "^\\("
323 (regexp-quote default-branch)
324 "\\.[0-9]+\\)\ndate[ \t]+\\([0-9.]+\\);") 1 2))
af5e65b9 325 file '(vc-master-workfile-version)))))
02d383eb
RS
326 ;; translate the locks
327 (vc-parse-locks file (vc-file-getprop file 'vc-master-locks)))
328
329 ((eq (vc-backend file) 'CVS)
7064821c 330 (save-excursion
719dcee9
AS
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"))
7064821c
AS
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
e66eac08
AS
353 (cond
354 ((string-match "Locally Modified" status) 'locally-modified)
355 ((string-match "Needs Merge" status) 'needs-merge)
d270fe6e
AS
356 ((string-match "Needs \\(Checkout\\|Patch\\)" status)
357 'needs-checkout)
e66eac08
AS
358 ((string-match "Unresolved Conflict" status) 'unresolved-conflict)
359 ((string-match "Locally Added" status) 'locally-added)
d270fe6e 360 (t 'unknown)
7064821c 361 ))))))))
3be2a362
RS
362 (if (get-buffer "*vc-info*")
363 (kill-buffer (get-buffer "*vc-info*")))))
e1c0c2d1
KH
364
365;;; Functions that determine property values, by examining the
366;;; working file, the master file, or log program output
367
368(defun vc-consult-rcs-headers (file)
369 ;; Search for RCS headers in FILE, and set properties
370 ;; accordingly. This function can be disabled by setting
371 ;; vc-consult-headers to nil.
372 ;; Returns: nil if no headers were found
373 ;; (or if the feature is disabled,
374 ;; or if there is currently no buffer
375 ;; visiting FILE)
376 ;; 'rev if a workfile revision was found
377 ;; 'rev-and-lock if revision and lock info was found
e66eac08 378 (cond
e1c0c2d1 379 ((or (not vc-consult-headers)
02d383eb 380 (not (get-file-buffer file))) nil)
e66eac08
AS
381 ((let (status version locking-user)
382 (save-excursion
e1c0c2d1
KH
383 (set-buffer (get-file-buffer file))
384 (goto-char (point-min))
385 (cond
386 ;; search for $Id or $Header
387 ;; -------------------------
1efcbf46
RS
388 ((or (and (search-forward "$Id: " nil t)
389 (looking-at "[^ ]+ \\([0-9.]+\\) "))
390 (and (progn (goto-char (point-min))
fceee007 391 (search-forward "$Header: " nil t))
1efcbf46 392 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
04094290 393 (goto-char (match-end 0))
e1c0c2d1 394 ;; if found, store the revision number ...
e66eac08
AS
395 (setq version (buffer-substring (match-beginning 1) (match-end 1)))
396 ;; ... and check for the locking state
397 (cond
398 ((looking-at
399 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
400 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
401 "[^ ]+ [^ ]+ ")) ; author & state
402 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
ce27f264 403 (cond
e66eac08
AS
404 ;; unlocked revision
405 ((looking-at "\\$")
406 (setq locking-user 'none)
407 (setq status 'rev-and-lock))
408 ;; revision is locked by some user
409 ((looking-at "\\([^ ]+\\) \\$")
410 (setq locking-user
411 (buffer-substring (match-beginning 1) (match-end 1)))
412 (setq status 'rev-and-lock))
413 ;; everything else: false
414 (nil)))
415 ;; unexpected information in
416 ;; keyword string --> quit
417 (nil)))
e1c0c2d1
KH
418 ;; search for $Revision
419 ;; --------------------
420 ((re-search-forward (concat "\\$"
421 "Revision: \\([0-9.]+\\) \\$")
422 nil t)
423 ;; if found, store the revision number ...
e66eac08
AS
424 (setq version (buffer-substring (match-beginning 1) (match-end 1)))
425 ;; and see if there's any lock information
426 (goto-char (point-min))
427 (if (re-search-forward (concat "\\$" "Locker:") nil t)
428 (cond ((looking-at " \\([^ ]+\\) \\$")
429 (setq locking-user (buffer-substring (match-beginning 1)
e1c0c2d1 430 (match-end 1)))
e66eac08
AS
431 (setq status 'rev-and-lock))
432 ((looking-at " *\\$")
433 (setq locking-user 'none)
434 (setq status 'rev-and-lock))
435 (t
436 (setq locking-user 'none)
437 (setq status 'rev-and-lock)))
438 (setq status 'rev)))
e1c0c2d1
KH
439 ;; else: nothing found
440 ;; -------------------
e66eac08
AS
441 (t nil)))
442 (if status (vc-file-setprop file 'vc-workfile-version version))
443 (and (eq status 'rev-and-lock)
444 (eq (vc-backend file) 'RCS)
445 (vc-file-setprop file 'vc-locking-user locking-user)
446 ;; If the file has headers, we don't want to query the master file,
447 ;; because that would eliminate all the performance gain the headers
448 ;; brought us. We therefore use a heuristic for the checkout model
449 ;; now: If we trust the file permissions, and the file is not
450 ;; locked, then if the file is read-only the checkout model is
451 ;; `manual', otherwise `implicit'.
452 (not (vc-mistrust-permissions file))
453 (not (vc-locking-user file))
454 (if (string-match ".r-..-..-." (nth 8 (file-attributes file)))
455 (vc-file-setprop file 'vc-checkout-model 'manual)
7064821c
AS
456 (vc-file-setprop file 'vc-checkout-model 'implicit)))
457 status))))
e1c0c2d1 458
02d383eb
RS
459;;; Access functions to file properties
460;;; (Properties should be _set_ using vc-file-setprop, but
461;;; _retrieved_ only through these functions, which decide
462;;; if the property is already known or not. A property should
463;;; only be retrieved by vc-file-getprop if there is no
464;;; access function.)
465
466;;; properties indicating the backend
467;;; being used for FILE
e1c0c2d1
KH
468
469(defun vc-backend-subdirectory-name (&optional file)
470 ;; Where the master and lock files for the current directory are kept
471 (symbol-name
472 (or
473 (and file (vc-backend file))
474 vc-default-back-end
475 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))))
476
02d383eb 477(defun vc-name (file)
b23a2306
AS
478 "Return the master name of a file, nil if it is not registered.
479For CVS, the full name of CVS/Entries is returned."
02d383eb
RS
480 (or (vc-file-getprop file 'vc-name)
481 (let ((name-and-type (vc-registered file)))
482 (if name-and-type
483 (progn
484 (vc-file-setprop file 'vc-backend (cdr name-and-type))
485 (vc-file-setprop file 'vc-name (car name-and-type)))))))
e1c0c2d1 486
02d383eb
RS
487(defun vc-backend (file)
488 "Return the version-control type of a file, nil if it is not registered."
489 (and file
490 (or (vc-file-getprop file 'vc-backend)
491 (let ((name-and-type (vc-registered file)))
492 (if name-and-type
493 (progn
494 (vc-file-setprop file 'vc-name (car name-and-type))
495 (vc-file-setprop file 'vc-backend (cdr name-and-type))))))))
e1c0c2d1 496
04446ed0
AS
497(defun vc-checkout-model (file)
498 ;; Return `manual' if the user has to type C-x C-q to check out FILE.
e66eac08
AS
499 ;; Return `implicit' if the file can be modified without locking it first.
500 (or
501 (vc-file-getprop file 'vc-checkout-model)
502 (cond
503 ((eq (vc-backend file) 'SCCS)
504 (vc-file-setprop file 'vc-checkout-model 'manual))
505 ((eq (vc-backend file) 'RCS)
506 (vc-consult-rcs-headers file)
507 (or (vc-file-getprop file 'vc-checkout-model)
508 (progn (vc-fetch-master-properties file)
509 (vc-file-getprop file 'vc-checkout-model))))
510 ((eq (vc-backend file) 'CVS)
511 (vc-file-setprop file 'vc-checkout-model
512 (if (getenv "CVSREAD") 'manual 'implicit))))))
04446ed0 513
02d383eb 514;;; properties indicating the locking state
e1c0c2d1
KH
515
516(defun vc-cvs-status (file)
517 ;; Return the cvs status of FILE
518 ;; (Status field in output of "cvs status")
519 (cond ((vc-file-getprop file 'vc-cvs-status))
02d383eb 520 (t (vc-fetch-master-properties file)
e1c0c2d1
KH
521 (vc-file-getprop file 'vc-cvs-status))))
522
02d383eb
RS
523(defun vc-master-locks (file)
524 ;; Return the lock entries in the master of FILE.
525 ;; Return 'none if there are no such entries, and a list
526 ;; of the form ((VERSION USER) (VERSION USER) ...) otherwise.
527 (cond ((vc-file-getprop file 'vc-master-locks))
528 (t (vc-fetch-master-properties file)
529 (vc-file-getprop file 'vc-master-locks))))
530
531(defun vc-master-locking-user (file)
532 ;; Return the master file's idea of who is locking
533 ;; the current workfile version of FILE.
534 ;; Return 'none if it is not locked.
535 (let ((master-locks (vc-master-locks file)) lock)
536 (if (eq master-locks 'none) 'none
537 ;; search for a lock on the current workfile version
538 (setq lock (assoc (vc-workfile-version file) master-locks))
539 (cond (lock (cdr lock))
540 ('none)))))
541
7064821c
AS
542(defun vc-lock-from-permissions (file)
543 ;; If the permissions can be trusted for this file, determine the
544 ;; locking state from them. Returns (user-login-name), `none', or nil.
545 ;; This implementation assumes that any file which is under version
546 ;; control and has -rw-r--r-- is locked by its owner. This is true
547 ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--.
548 ;; We have to be careful not to exclude files with execute bits on;
549 ;; scripts can be under version control too. Also, we must ignore the
550 ;; group-read and other-read bits, since paranoid users turn them off.
551 ;; This hack wins because calls to the somewhat expensive
552 ;; `vc-fetch-master-properties' function only have to be made if
553 ;; (a) the file is locked by someone other than the current user,
554 ;; or (b) some untoward manipulation behind vc's back has changed
555 ;; the owner or the `group' or `other' write bits.
556 (let ((attributes (file-attributes file)))
557 (if (not (vc-mistrust-permissions file))
558 (cond ((string-match ".r-..-..-." (nth 8 attributes))
559 (vc-file-setprop file 'vc-locking-user 'none))
560 ((and (= (nth 2 attributes) (user-uid))
561 (string-match ".rw..-..-." (nth 8 attributes)))
562 (vc-file-setprop file 'vc-locking-user (user-login-name)))
563 (nil)))))
564
565(defun vc-file-owner (file)
566 ;; The expression below should return the username of the owner
567 ;; of the file. It doesn't. It returns the username if it is
568 ;; you, or otherwise the UID of the owner of the file. The
569 ;; return value from this function is only used by
570 ;; vc-dired-reformat-line, and it does the proper thing if a UID
571 ;; is returned.
572 ;; The *proper* way to fix this would be to implement a built-in
573 ;; function in Emacs, say, (username UID), that returns the
574 ;; username of a given UID.
575 ;; The result of this hack is that vc-directory will print the
576 ;; name of the owner of the file for any files that are
577 ;; modified.
578 (let ((uid (nth 2 (file-attributes file))))
579 (if (= uid (user-uid)) (user-login-name) uid)))
580
581(defun vc-rcs-lock-from-diff (file)
582 ;; Diff the file against the master version. If differences are found,
31888047
AS
583 ;; mark the file locked. This is only used for RCS with non-strict
584 ;; locking. (If "rcsdiff" doesn't understand --brief, we do a double-take
585 ;; and remember the fact for the future.)
586 (let* ((version (concat "-r" (vc-workfile-version file)))
587 (status (if (eq vc-rcsdiff-knows-brief 'no)
588 (vc-simple-command 1 "rcsdiff" file version)
589 (vc-simple-command 2 "rcsdiff" file "--brief" version))))
590 (if (eq status 2)
591 (if (not vc-rcsdiff-knows-brief)
592 (setq vc-rcsdiff-knows-brief 'no
593 status (vc-simple-command 1 "rcsdiff" file version))
594 (error "rcsdiff failed."))
595 (if (not vc-rcsdiff-knows-brief) (setq vc-rcsdiff-knows-brief 'yes)))
596 (if (zerop status)
597 (vc-file-setprop file 'vc-locking-user 'none)
598 (vc-file-setprop file 'vc-locking-user (vc-file-owner file)))))
7064821c 599
e1c0c2d1 600(defun vc-locking-user (file)
02d383eb 601 ;; Return the name of the person currently holding a lock on FILE.
7064821c
AS
602 ;; Return nil if there is no such person. (Sometimes, not the name
603 ;; of the locking user but his uid will be returned.)
02d383eb 604 ;; Under CVS, a file is considered locked if it has been modified since
7064821c 605 ;; it was checked out.
02d383eb
RS
606 ;; The property is cached. It is only looked up if it is currently nil.
607 ;; Note that, for a file that is not locked, the actual property value
7064821c 608 ;; is `none', to distinguish it from an unknown locking state. That value
02d383eb
RS
609 ;; is converted to nil by this function, and returned to the caller.
610 (let ((locking-user (vc-file-getprop file 'vc-locking-user)))
611 (if locking-user
612 ;; if we already know the property, return it
613 (if (eq locking-user 'none) nil locking-user)
614
615 ;; otherwise, infer the property...
616 (cond
02d383eb 617 ((eq (vc-backend file) 'CVS)
7064821c
AS
618 (or (and (eq (vc-checkout-model file) 'manual)
619 (vc-lock-from-permissions file))
b23a2306
AS
620 (and (equal (vc-file-getprop file 'vc-checkout-time)
621 (nth 5 (file-attributes file)))
622 (vc-file-setprop file 'vc-locking-user 'none))
10aa933d
RS
623 (let ((locker (vc-file-owner file)))
624 (vc-file-setprop file 'vc-locking-user
625 (if (stringp locker) locker
626 (format "%d" locker))))))
7064821c
AS
627
628 ((eq (vc-backend file) 'RCS)
629 (let (p-lock)
630
631 ;; Check for RCS headers first
632 (or (eq (vc-consult-rcs-headers file) 'rev-and-lock)
633
634 ;; If there are no headers, try to learn it
635 ;; from the permissions.
636 (and (setq p-lock (vc-lock-from-permissions file))
637 (if (eq p-lock 'none)
638
639 ;; If the permissions say "not locked", we know
640 ;; that the checkout model must be `manual'.
641 (vc-file-setprop file 'vc-checkout-model 'manual)
642
643 ;; If the permissions say "locked", we can only trust
644 ;; this *if* the checkout model is `manual'.
645 (eq (vc-checkout-model file) 'manual)))
646
647 ;; Otherwise, use lock information from the master file.
648 (vc-file-setprop file 'vc-locking-user
649 (vc-master-locking-user file)))
650
651 ;; Finally, if the file is not explicitly locked
652 ;; it might still be locked implicitly.
653 (and (eq (vc-file-getprop file 'vc-locking-user) 'none)
654 (eq (vc-checkout-model file) 'implicit)
655 (vc-rcs-lock-from-diff file))))
656
657 ((eq (vc-backend file) 'SCCS)
658 (or (vc-lock-from-permissions file)
659 (vc-file-setprop file 'vc-locking-user
aadce164 660 (vc-master-locking-user file)))))
7064821c
AS
661
662 ;; convert a possible 'none value
663 (setq locking-user (vc-file-getprop file 'vc-locking-user))
aadce164 664 (if (eq locking-user 'none) nil locking-user))))
02d383eb
RS
665
666;;; properties to store current and recent version numbers
e1c0c2d1
KH
667
668(defun vc-latest-version (file)
669 ;; Return version level of the latest version of FILE
02d383eb 670 (cond ((vc-file-getprop file 'vc-latest-version))
1efcbf46 671 (t (vc-fetch-properties file)
02d383eb 672 (vc-file-getprop file 'vc-latest-version))))
e1c0c2d1
KH
673
674(defun vc-your-latest-version (file)
675 ;; Return version level of the latest version of FILE checked in by you
02d383eb 676 (cond ((vc-file-getprop file 'vc-your-latest-version))
1efcbf46 677 (t (vc-fetch-properties file)
02d383eb 678 (vc-file-getprop file 'vc-your-latest-version))))
e1c0c2d1 679
af5e65b9
AS
680(defun vc-master-workfile-version (file)
681 ;; Return the master file's idea of what is the current workfile version.
e1c0c2d1 682 ;; This property is defined for RCS only.
af5e65b9 683 (cond ((vc-file-getprop file 'vc-master-workfile-version))
02d383eb 684 (t (vc-fetch-master-properties file)
af5e65b9 685 (vc-file-getprop file 'vc-master-workfile-version))))
e1c0c2d1 686
1efcbf46
RS
687(defun vc-fetch-properties (file)
688 ;; Fetch vc-latest-version and vc-your-latest-version
689 ;; if that wasn't already done.
04094290
RS
690 (cond
691 ((eq (vc-backend file) 'RCS)
ee526b55
RS
692 (save-excursion
693 (set-buffer (get-buffer-create "*vc-info*"))
694 (vc-insert-file (vc-name file) "^desc")
695 (vc-parse-buffer
696 (list '("^\\([0-9]+\\.[0-9.]+\\)\ndate[ \t]+\\([0-9.]+\\);" 1 2)
697 (list (concat "^\\([0-9]+\\.[0-9.]+\\)\n"
698 "date[ \t]+\\([0-9.]+\\);[ \t]+"
699 "author[ \t]+"
700 (regexp-quote (user-login-name)) ";") 1 2))
701 file
07de4c3d
RS
702 '(vc-latest-version vc-your-latest-version))
703 (if (get-buffer "*vc-info*")
704 (kill-buffer (get-buffer "*vc-info*")))))
04094290 705 (t (vc-fetch-master-properties file))
1efcbf46
RS
706 ))
707
e1c0c2d1
KH
708(defun vc-workfile-version (file)
709 ;; Return version level of the current workfile FILE
710 ;; This is attempted by first looking at the RCS keywords.
711 ;; If there are no keywords in the working file,
af5e65b9 712 ;; vc-master-workfile-version is taken.
e1c0c2d1
KH
713 ;; Note that this property is cached, that is, it is only
714 ;; looked up if it is nil.
715 ;; For SCCS, this property is equivalent to vc-latest-version.
716 (cond ((vc-file-getprop file 'vc-workfile-version))
717 ((eq (vc-backend file) 'SCCS) (vc-latest-version file))
718 ((eq (vc-backend file) 'RCS)
719 (if (vc-consult-rcs-headers file)
720 (vc-file-getprop file 'vc-workfile-version)
af5e65b9 721 (let ((rev (cond ((vc-master-workfile-version file))
e1c0c2d1
KH
722 ((vc-latest-version file)))))
723 (vc-file-setprop file 'vc-workfile-version rev)
724 rev)))
725 ((eq (vc-backend file) 'CVS)
726 (if (vc-consult-rcs-headers file) ;; CVS
727 (vc-file-getprop file 'vc-workfile-version)
7b0e1b8f
KH
728 (catch 'found
729 (vc-find-cvs-master (file-name-directory file)
730 (file-name-nondirectory file)))
e1c0c2d1 731 (vc-file-getprop file 'vc-workfile-version)))))
f2ee4191 732
594722a8
ER
733;;; actual version-control code starts here
734
735(defun vc-registered (file)
18c8a18e
PE
736 (let (handler handlers)
737 (if (boundp 'file-name-handler-alist)
b993101e 738 (setq handler (find-file-name-handler file 'vc-registered)))
18c8a18e
PE
739 (if handler
740 (funcall handler 'vc-registered file)
741 ;; Search for a master corresponding to the given file
742 (let ((dirname (or (file-name-directory file) ""))
743 (basename (file-name-nondirectory file)))
744 (catch 'found
745 (mapcar
746 (function (lambda (s)
174edc13
RS
747 (if (atom s)
748 (funcall s dirname basename)
749 (let ((trial (format (car s) dirname basename)))
750 (if (and (file-exists-p trial)
751 ;; Make sure the file we found with name
752 ;; TRIAL is not the source file itself.
753 ;; That can happen with RCS-style names
754 ;; if the file name is truncated
755 ;; (e.g. to 14 chars). See if either
756 ;; directory or attributes differ.
757 (or (not (string= dirname
758 (file-name-directory trial)))
759 (not (equal
760 (file-attributes file)
761 (file-attributes trial)))))
762 (throw 'found (cons trial (cdr s))))))))
18c8a18e
PE
763 vc-master-templates)
764 nil)))))
594722a8 765
b23a2306
AS
766(defun vc-utc-string (timeval)
767 ;; Convert a time value into universal time, and return it as a
31888047 768 ;; human-readable string. This is for comparing CVS checkout times
b23a2306
AS
769 ;; with file modification times.
770 (let (utc (high (car timeval)) (low (nth 1 timeval))
31888047 771 (offset (car (current-time-zone timeval))))
b23a2306
AS
772 (setq low (- low offset))
773 (setq utc (if (> low 65535)
774 (list (1+ high) (- low 65536))
775 (if (< low 0)
776 (list (1- high) (+ 65536 low))
777 (list high low))))
778 (current-time-string utc)))
779
174edc13
RS
780(defun vc-find-cvs-master (dirname basename)
781 ;; Check if DIRNAME/BASENAME is handled by CVS.
782 ;; If it is, do a (throw 'found (cons MASTER 'CVS)).
b23a2306
AS
783 ;; Note: This function throws the name of CVS/Entries
784 ;; NOT that of the RCS master file (because we wouldn't be able
785 ;; to access it under remote CVS).
786 ;; The function returns nil if DIRNAME/BASENAME is not handled by CVS.
0b086efb
RS
787 (if (and vc-handle-cvs
788 (file-directory-p (concat dirname "CVS/"))
b23a2306
AS
789 (file-readable-p (concat dirname "CVS/Entries")))
790 (let (buffer time (fold case-fold-search)
791 (file (concat dirname basename)))
174edc13
RS
792 (unwind-protect
793 (save-excursion
7064821c
AS
794 (setq buffer (set-buffer (get-buffer-create "*vc-info*")))
795 (vc-insert-file (concat dirname "CVS/Entries"))
174edc13 796 (goto-char (point-min))
f2ee4191
RS
797 ;; make sure the file name is searched
798 ;; case-sensitively
799 (setq case-fold-search nil)
174edc13
RS
800 (cond
801 ((re-search-forward
b23a2306
AS
802 (concat "^/" (regexp-quote basename)
803 "/\\([^/]*\\)/\\([^/]*\\)/")
174edc13 804 nil t)
f2ee4191 805 (setq case-fold-search fold) ;; restore the old value
b23a2306
AS
806 ;; We found it. Store away version number now that we
807 ;; are anyhow so close to finding it.
808 (vc-file-setprop file
f2ee4191 809 'vc-workfile-version
b23a2306
AS
810 (match-string 1))
811 ;; If the file hasn't been modified since checkout,
812 ;; store the checkout-time.
719dcee9
AS
813 (let ((mtime (nth 5 (file-attributes file))))
814 (if (string= (match-string 2) (vc-utc-string mtime))
815 (vc-file-setprop file 'vc-checkout-time mtime)
816 (vc-file-setprop file 'vc-checkout-time 0)))
b23a2306 817 (throw 'found (cons (concat dirname "CVS/Entries") 'CVS)))
f2ee4191
RS
818 (t (setq case-fold-search fold) ;; restore the old value
819 nil)))
7064821c 820 (kill-buffer buffer)))))
174edc13 821
f2ee4191
RS
822(defun vc-buffer-backend ()
823 "Return the version-control type of the visited file, or nil if none."
824 (if (eq vc-buffer-backend t)
e1c0c2d1 825 (setq vc-buffer-backend (vc-backend (buffer-file-name)))
f2ee4191
RS
826 vc-buffer-backend))
827
c844616c 828(defun vc-toggle-read-only (&optional verbose)
c43e436c
RS
829 "Change read-only status of current buffer, perhaps via version control.
830If the buffer is visiting a file registered with version control,
831then check the file in or out. Otherwise, just change the read-only flag
f2ee4191 832of the buffer. With prefix argument, ask for version number."
c844616c 833 (interactive "P")
e1c0c2d1 834 (if (vc-backend (buffer-file-name))
c844616c 835 (vc-next-action verbose)
594722a8 836 (toggle-read-only)))
c43e436c 837(define-key global-map "\C-x\C-q" 'vc-toggle-read-only)
594722a8 838
e66eac08
AS
839(defun vc-after-save ()
840 ;; Function to be called by basic-save-buffer (in files.el).
841 ;; If the file in the current buffer is under version control,
842 ;; not locked, and the checkout model for it is `implicit',
843 ;; mark it "locked" and redisplay the mode line.
844 (let ((file (buffer-file-name)))
845 (and (vc-file-getprop file 'vc-backend)
846 ;; ...check the property directly, not through the function of the
847 ;; same name. Otherwise Emacs would check for a master file
848 ;; each time a non-version-controlled buffer is saved.
849 ;; The property is computed when the file is visited, so if it
850 ;; is `nil' now, it is certain that the file is NOT
851 ;; version-controlled.
b23a2306
AS
852 (or (and (equal (vc-file-getprop file 'vc-checkout-time)
853 (nth 5 (file-attributes file)))
854 ;; File has been saved in the same second in which
855 ;; it was checked out. Clear the checkout-time
856 ;; to avoid confusion.
857 (vc-file-setprop file 'vc-checkout-time nil))
858 t)
e66eac08
AS
859 (not (vc-locking-user file))
860 (eq (vc-checkout-model file) 'implicit)
861 (vc-file-setprop file 'vc-locking-user (user-login-name))
b23a2306
AS
862 (or (and (eq (vc-backend file) 'CVS)
863 (vc-file-setprop file 'vc-cvs-status nil))
864 t)
865 (vc-mode-line file))))
04446ed0 866
594722a8 867(defun vc-mode-line (file &optional label)
7bc2b98b 868 "Set `vc-mode' to display type of version control for FILE.
594722a8 869The value is set in the current buffer, which should be the buffer
624c0e9d
RS
870visiting FILE. Second optional arg LABEL is put in place of version
871control system name."
18c8a18e 872 (interactive (list buffer-file-name nil))
7b0e1b8f 873 (let ((vc-type (vc-backend file)))
f2ee4191 874 (setq vc-mode
7b0e1b8f
KH
875 (and vc-type
876 (concat " " (or label (symbol-name vc-type))
877 (and vc-display-status (vc-status file)))))
878 (and vc-type
879 (equal file (buffer-file-name))
e66eac08
AS
880 (vc-locking-user file)
881 ;; If the file is locked by some other user, make
882 ;; the buffer read-only. Like this, even root
883 ;; cannot modify a file without locking it first.
884 (not (string= (user-login-name) (vc-locking-user file)))
885 (setq buffer-read-only t))
f2ee4191
RS
886 (force-mode-line-update)
887 ;;(set-buffer-modified-p (buffer-modified-p)) ;;use this if Emacs 18
888 vc-type))
594722a8 889
e1c0c2d1 890(defun vc-status (file)
45c92c0c 891 ;; Return string for placement in modeline by `vc-mode-line'.
e1c0c2d1 892 ;; Format:
624c0e9d 893 ;;
e1c0c2d1
KH
894 ;; "-REV" if the revision is not locked
895 ;; ":REV" if the revision is locked by the user
896 ;; ":LOCKER:REV" if the revision is locked by somebody else
897 ;; " @@" for a CVS file that is added, but not yet committed
174edc13 898 ;;
e1c0c2d1
KH
899 ;; In the CVS case, a "locked" working file is a
900 ;; working file that is modified with respect to the master.
e66eac08
AS
901 ;; The file is "locked" from the moment when the user saves
902 ;; the modified buffer.
e1c0c2d1
KH
903 ;;
904 ;; This function assumes that the file is registered.
905
906 (let ((locker (vc-locking-user file))
907 (rev (vc-workfile-version file)))
908 (cond ((string= "0" rev)
909 " @@")
38179d42
RM
910 ((not locker)
911 (concat "-" rev))
912 ((if (stringp locker)
913 (string= locker (user-login-name))
914 (= locker (user-uid)))
e1c0c2d1
KH
915 (concat ":" rev))
916 (t
917 (concat ":" locker ":" rev)))))
f2ee4191 918
594722a8
ER
919;;; install a call to the above as a find-file hook
920(defun vc-find-file-hook ()
18c8a18e
PE
921 ;; Recompute whether file is version controlled,
922 ;; if user has killed the buffer and revisited.
f2ee4191
RS
923 (cond
924 (buffer-file-name
925 (vc-file-clearprops buffer-file-name)
926 (cond
e1c0c2d1 927 ((vc-backend buffer-file-name)
f2ee4191
RS
928 (vc-mode-line buffer-file-name)
929 (cond ((not vc-make-backup-files)
930 ;; Use this variable, not make-backup-files,
931 ;; because this is for things that depend on the file name.
932 (make-local-variable 'backup-inhibited)
45fc7cc3
RS
933 (setq backup-inhibited t))))
934 ((let* ((link (file-symlink-p buffer-file-name))
935 (link-type (and link (vc-backend link))))
936 (if link-type
b8063212
AS
937 (cond ((eq vc-follow-symlinks nil)
938 (message
939 "Warning: symbolic link to %s-controlled source file" link-type))
940 ((eq vc-follow-symlinks 'ask)
941 (if (yes-or-no-p (format
942 "Symbolic link to %s-controlled source file; follow link? " link-type))
943 (progn (setq buffer-file-name
944 (file-truename buffer-file-name))
945 (message "Followed link to %s" buffer-file-name)
946 (vc-find-file-hook))
947 (message
948 "Warning: editing through the link bypasses version control")
949 ))
950 (t (setq buffer-file-name (file-truename buffer-file-name))
951 (message "Followed link to %s" buffer-file-name)
952 (vc-find-file-hook))))))))))
594722a8 953
6379911c 954(add-hook 'find-file-hooks 'vc-find-file-hook)
594722a8
ER
955
956;;; more hooks, this time for file-not-found
957(defun vc-file-not-found-hook ()
958 "When file is not found, try to check it out from RCS or SCCS.
959Returns t if checkout was successful, nil otherwise."
e1c0c2d1 960 (if (vc-backend buffer-file-name)
624c0e9d 961 (save-excursion
594722a8 962 (require 'vc)
02d383eb 963 (setq default-directory (file-name-directory (buffer-file-name)))
594722a8
ER
964 (not (vc-error-occurred (vc-checkout buffer-file-name))))))
965
6379911c 966(add-hook 'find-file-not-found-hooks 'vc-file-not-found-hook)
594722a8 967
f2ee4191
RS
968;; Discard info about a file when we kill its buffer.
969(defun vc-kill-buffer-hook ()
970 (if (stringp (buffer-file-name))
971 (progn
972 (vc-file-clearprops (buffer-file-name))
973 (kill-local-variable 'vc-buffer-backend))))
974
975;;;(add-hook 'kill-buffer-hook 'vc-kill-buffer-hook)
976
594722a8 977;;; Now arrange for bindings and autoloading of the main package.
7bc2b98b
ER
978;;; Bindings for this have to go in the global map, as we'll often
979;;; want to call them from random buffers.
594722a8
ER
980
981(setq vc-prefix-map (lookup-key global-map "\C-xv"))
982(if (not (keymapp vc-prefix-map))
983 (progn
984 (setq vc-prefix-map (make-sparse-keymap))
985 (define-key global-map "\C-xv" vc-prefix-map)
986 (define-key vc-prefix-map "a" 'vc-update-change-log)
987 (define-key vc-prefix-map "c" 'vc-cancel-version)
18c8a18e 988 (define-key vc-prefix-map "d" 'vc-directory)
594722a8
ER
989 (define-key vc-prefix-map "h" 'vc-insert-headers)
990 (define-key vc-prefix-map "i" 'vc-register)
991 (define-key vc-prefix-map "l" 'vc-print-log)
992 (define-key vc-prefix-map "r" 'vc-retrieve-snapshot)
993 (define-key vc-prefix-map "s" 'vc-create-snapshot)
994 (define-key vc-prefix-map "u" 'vc-revert-buffer)
995 (define-key vc-prefix-map "v" 'vc-next-action)
18c8a18e 996 (define-key vc-prefix-map "=" 'vc-diff)
624c0e9d
RS
997 (define-key vc-prefix-map "~" 'vc-version-other-window)))
998
b662fbb8
RM
999(if (not (boundp 'vc-menu-map))
1000 ;; Don't do the menu bindings if menu-bar.el wasn't loaded to defvar
1001 ;; vc-menu-map.
1002 ()
1003 ;;(define-key vc-menu-map [show-files]
1004 ;; '("Show Files under VC" . (vc-directory t)))
1005 (define-key vc-menu-map [vc-directory] '("Show Locked Files" . vc-directory))
1006 (define-key vc-menu-map [separator1] '("----"))
1007 (define-key vc-menu-map [vc-rename-file] '("Rename File" . vc-rename-file))
1008 (define-key vc-menu-map [vc-version-other-window]
1009 '("Show Other Version" . vc-version-other-window))
1010 (define-key vc-menu-map [vc-diff] '("Compare with Last Version" . vc-diff))
1011 (define-key vc-menu-map [vc-update-change-log]
1012 '("Update ChangeLog" . vc-update-change-log))
1013 (define-key vc-menu-map [vc-print-log] '("Show History" . vc-print-log))
1014 (define-key vc-menu-map [separator2] '("----"))
1015 (define-key vc-menu-map [undo] '("Undo Last Check-In" . vc-cancel-version))
1016 (define-key vc-menu-map [vc-revert-buffer]
1017 '("Revert to Last Version" . vc-revert-buffer))
1018 (define-key vc-menu-map [vc-insert-header]
1019 '("Insert Header" . vc-insert-headers))
1020 (define-key vc-menu-map [vc-menu-check-in] '("Check In" . vc-next-action))
1021 (define-key vc-menu-map [vc-check-out] '("Check Out" . vc-toggle-read-only))
1022 (define-key vc-menu-map [vc-register] '("Register" . vc-register))
1023 (put 'vc-rename-file 'menu-enable 'vc-mode)
1024 (put 'vc-version-other-window 'menu-enable 'vc-mode)
1025 (put 'vc-diff 'menu-enable 'vc-mode)
1026 (put 'vc-update-change-log 'menu-enable
f2ee4191 1027 '(eq (vc-buffer-backend) 'RCS))
b662fbb8
RM
1028 (put 'vc-print-log 'menu-enable 'vc-mode)
1029 (put 'vc-cancel-version 'menu-enable 'vc-mode)
1030 (put 'vc-revert-buffer 'menu-enable 'vc-mode)
1031 (put 'vc-insert-headers 'menu-enable 'vc-mode)
1032 (put 'vc-next-action 'menu-enable '(and vc-mode (not buffer-read-only)))
1033 (put 'vc-toggle-read-only 'menu-enable '(and vc-mode buffer-read-only))
76a8bf4c 1034 (put 'vc-register 'menu-enable '(and buffer-file-name (not vc-mode)))
b662fbb8 1035 )
594722a8 1036
594722a8
ER
1037(provide 'vc-hooks)
1038
1039;;; vc-hooks.el ends here