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