1 ;;; vc-cc-hooks.el --- support for vc-cc.el, formerly resident
3 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
6 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
7 ;; Maintainer: ttn@netcom.com
8 ;; Version: 5.3 + CVS hacks by ceder@lysator.liu.se made in Jan-Feb 1994.
10 ;; XEmacs fixes, CVS fixes, and general improvements
11 ;; by Jonathan Stigelman <Stig@hackvan.com>
13 ;; This file is part of XEmacs.
15 ;; XEmacs is free software; you can redistribute it and/or modify it
16 ;; under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; XEmacs is distributed in the hope that it will be useful, but
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ;; General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with XEmacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
30 ;;; Synched up with: FSF 19.28.
34 ;; This is like vc-hooks.el, but for vc-cc. See the commentary of
35 ;; vc-hooks.el and vc-cc.el.
42 ;; Using defconst only because we may have already loaded another version of
44 (defconst vc-master-templates
45 '(("%sRCS/%s,v" . RCS) ("%s%s,v" . RCS) ("%sRCS/%s" . RCS)
46 ("%sSCCS/s.%s" . SCCS) ("%ss.%s". SCCS)
49 "*Where to look for version-control master files.
50 The first pair corresponding to a given back end is used as a template
51 when creating new masters.")
53 (defconst ClearCase "@@")
56 (if (file-exists-p "/usr/sccs")
58 "*List of extra directories to search for version control commands.")
60 (defvar vc-make-backup-files nil
61 "*If non-nil, backups of registered files are made as with other files.
62 If nil (the default), files covered by version control don't get backups.")
64 (defvar vc-follow-symlinks 'ask
65 "*Indicates what to do if you visit a symbolic link to a file
66 that is under version control. Editing such a file through the
67 link bypasses the version control system, which is dangerous and
68 probably not what you want.
69 If this variable is t, VC follows the link and visits the real file,
70 telling you about it in the echo area. If it is `ask', VC asks for
71 confirmation whether it should follow the link. If nil, the link is
72 visited and a warning displayed.")
74 (defvar vc-display-status t
75 "*If non-nil, display revision number and lock status in modeline.
76 Otherwise, not displayed.")
78 (defvar vc-cc-display-branch t
79 "*If non-nil, full branch name of ClearCase working file displayed in modeline.
80 Otherwise, just the version number or label is displayed.")
82 (defvar vc-auto-dired-mode t
83 "*If non-nil, automatically enter `vc-dired-mode' in dired-mode buffers where
84 version control is set-up.")
86 (defvar vc-cc-pwv nil ;; (getenv "CLEARCASE_ROOT")
87 "The ClearCase present working view for the current buffer.")
88 (make-variable-buffer-local 'vc-cc-pwv)
90 (defvar vc-consult-headers t
91 "*If non-nil, identify work files by searching for version headers.")
93 (defconst vc-elucidated (string-match "Lucid" emacs-version))
95 ;; Tell Emacs about this new kind of minor mode
96 (if (not (assoc 'vc-mode minor-mode-alist))
97 (setq minor-mode-alist (cons '(vc-mode vc-mode)
99 ;; We don't really need to have the toggling feature provided by this command,
100 ;; so in deference to FSF Emacs, I won't use it.
101 ;;(add-minor-mode 'vc-mode 'vc-mode)
103 (defvar vc-mode nil) ; used for modeline flag
104 (make-variable-buffer-local 'vc-mode)
105 (set-default 'vc-mode nil)
106 (put 'vc-mode 'permanent-local t)
108 (defvar vc-dired-mode nil)
109 (make-variable-buffer-local 'vc-dired-mode)
111 ;; We need a notion of per-file properties because the version
112 ;; control state of a file is expensive to derive --- we don't
113 ;; want to recompute it even on every find.
115 (defmacro vc-error-occurred (&rest body)
116 (list 'condition-case nil (cons 'progn (append body '(nil))) '(error t)))
118 (defvar vc-file-prop-obarray (make-vector 17 0)
119 "Obarray for per-file properties.")
121 (defun vc-file-setprop (file property value)
122 ;; set per-file property
123 (put (intern file vc-file-prop-obarray) property value))
125 (defun vc-file-getprop (file property)
126 ;; get per-file property
127 (get (intern file vc-file-prop-obarray) property))
129 (defun vc-file-clearprops (file)
130 ;; clear all properties of a given file
131 (setplist (intern file vc-file-prop-obarray) nil))
133 ;;; actual version-control code starts here
135 (defun vc-registered (file)
137 (if (boundp 'file-name-handler-alist)
138 (setq handler (find-file-name-handler file 'vc-registered)))
140 (funcall handler 'vc-registered file)
141 ;; Search for a master corresponding to the given file
142 (let ((dirname (or (file-name-directory file) ""))
143 (basename (file-name-nondirectory file)))
149 (funcall s dirname basename)
150 (let ((trial (format (car s) dirname basename)))
151 (if (and (file-exists-p trial)
152 ;; This ensures that directories are not considered
153 ;; to be registered files (this happens with the
154 ;; third RCS pattern in vc-master-templates).
155 (not (equal basename ""))
156 ;; Make sure the file we found with name
157 ;; TRIAL is not the source file itself.
158 ;; That can happen with RCS-style names
159 ;; if the file name is truncated
160 ;; (e.g. to 14 chars). See if either
161 ;; directory or attributes differ.
162 (or (not (string= dirname
163 (file-name-directory trial)))
165 (file-attributes file)
166 (file-attributes trial)))))
167 (throw 'found (cons trial (cdr s))))))))
171 (defun vc-cc-registered (dirname basename)
172 ;; Check if DIRNAME/BASENAME is a ClearCase element
173 ;; If it is, do a (throw 'found (cons MASTER '@@)).
174 ;; Use general purpose function for real check
175 ;; This should only be used in vc-master-template.
176 (let ((fullname (concat dirname basename)))
177 ;; If this is a symlink to a ClearCase file, it will think that it is
178 ;; under control, but won't be able to get all information with
179 ;; vc-fetch-properties. We should leave it up to the user to chase the
180 ;; link, or simply not edit the file through the link.
181 (if (and (not (file-symlink-p fullname))
182 (clearcase-element-p fullname))
183 (throw 'found (cons fullname '@@))))
186 (defun vc-find-cvs-master (dirname basename)
187 ;; Check if DIRNAME/BASENAME is handled by CVS.
188 ;; If it is, do a (throw 'found (cons MASTER 'CVS)).
189 ;; Note: If the file is ``cvs add''ed but not yet ``cvs commit''ed
190 ;; the MASTER will not actually exist yet. The other parts of VC
191 ;; checks for this condition. This function returns something random if
192 ;; DIRNAME/BASENAME is not handled by CVS.
193 ;; This should only be used in vc-master-template.
194 (and (string= "" dirname) (setq dirname default-directory))
195 (if (and (file-directory-p (concat dirname "CVS/"))
196 (file-readable-p (concat dirname "CVS/Entries")))
197 (let ((fname (concat dirname basename))
201 (set-buffer (generate-new-buffer " vc-scratch"))
202 (setq sbuf (current-buffer))
203 (insert-file-contents (concat dirname "CVS/Entries"))
206 (concat "^/" (regexp-quote basename) "/\\([0-9.]*\\)/.*/\\(T\\([^/\n]+\\)\\)?$")
208 ;; We found it. Store version number, and branch tag
209 (setq rev (buffer-substring (match-beginning 1)
211 (vc-file-setprop fname 'vc-your-latest-version rev)
212 ;; XEmacs - we put something useful in the modeline
213 (vc-file-setprop fname 'sticky-tag
214 (cond ((string= "0" rev) "newfile")
216 (buffer-substring (match-beginning 3)
220 (insert-file-contents (concat dirname "CVS/Repository"))
222 (concat (file-name-as-directory
223 (buffer-substring (point-min)
227 (throw 'found (cons master 'CVS))))))
228 (kill-buffer sbuf)))))
230 (defun vc-name (file)
231 "Return the master name of a file, nil if it is not registered."
232 (or (vc-file-getprop file 'vc-name)
233 (let ((name-and-type (vc-registered file)))
236 (vc-file-setprop file 'vc-backend (cdr name-and-type))
237 (vc-file-setprop file 'vc-name (car name-and-type)))))))
239 (defun vc-backend-deduce (file)
240 "Return the version-control type of a file, nil if it is not registered."
242 (or (vc-file-getprop file 'vc-backend)
243 (let ((name-and-type (vc-registered file)))
246 (vc-file-setprop file 'vc-name (car name-and-type))
247 (vc-file-setprop file 'vc-backend (cdr name-and-type))))))))
249 (defun vc-toggle-read-only (&optional verbose)
250 "Change read-only status of current buffer, perhaps via version control.
251 If the buffer is visiting a file registered with a form of version control
252 that locks files by making them read-only (i.e.: not CVS), then check the
253 file in or out. Otherwise, just change the read-only flag of the buffer.
255 If you provide a prefix argument, we pass it on to `vc-next-action'."
257 (let ((vc-type (vc-backend-deduce (buffer-file-name))))
260 (file-writable-p buffer-file-name)
262 ;; XEmacs - The buffer isn't read-only because it's locked, so
263 ;; keep vc out of this...
265 ((and vc-type (not (eq 'CVS vc-type)))
266 (vc-next-action verbose))
271 ;; Map the vc-toggle-read-only key whereever toggle-read-only was
272 (let ((where (where-is-internal 'toggle-read-only global-map)))
274 (mapcar (lambda (key)
275 (define-key global-map
276 key 'vc-toggle-read-only))
279 ;;(define-key global-map "\C-x\C-q" 'vc-toggle-read-only)
281 ;; For other cases, try advising...
282 (defadvice toggle-read-only (around vc activate)
283 "If file is under version control, perform `vc-next-action'."
285 (let ((vc-type (vc-backend-deduce (buffer-file-name))))
288 (file-writable-p buffer-file-name)
290 ;; XEmacs - The buffer isn't read-only because it's locked, so
291 ;; keep vc out of this...
293 ((and vc-type (not (eq 'CVS vc-type)))
294 (vc-next-action (ad-get-arg 0)))
300 (defun vc-file-owner (file)
301 ;; XEmacs - vc-locking-user is just WAY too slow.
302 (let* ((fa (file-attributes file)))
303 (cond ((eq ?w (aref (nth 8 fa) 2)) ; -rw-r--r--
304 ;; #### - if it's writable, we trust unix...dumb move?
305 (user-login-name (nth 2 fa)))
307 ;; big slowness here...
309 (vc-locking-user file)
312 (defun vc-mode-line (file &optional label)
313 "Set `vc-mode' to display type of version control for FILE.
314 The value is set in the current buffer, which should be the buffer
315 visiting FILE. Second optional arg LABEL is put in place of version
316 control system name."
317 (interactive (list buffer-file-name nil))
319 (let ((vc-type (vc-backend-deduce file)))
322 (concat " " (or label (symbol-name vc-type))
323 (if vc-display-status
324 (vc-status file vc-type)))))
325 ;; Even root shouldn't modify a registered file without
328 (not (string= (user-login-name) (vc-file-owner file)))
329 (setq buffer-read-only t))
331 (file-symlink-p file)
332 (let ((link-type (vc-backend-deduce (file-symlink-p file))))
335 "Warning: symbolic link to %s-controlled source file"
338 ;;(set-buffer-modified-p (buffer-modified-p)) ;;use this if Emacs 18
341 (defun vc-status (file vc-type)
342 ;; Return string for placement in modeline by `vc-mode-line'.
343 ;; If FILE is not registered, return nil.
344 ;; If FILE is registered but not locked, return " REV" if there is a head
345 ;; revision and " @@" otherwise.
346 ;; If FILE is locked then return all locks in a string of the
347 ;; form " LOCKER1:REV1 LOCKER2:REV2 ...", where "LOCKERi:" is empty if you
348 ;; are the locker, and otherwise is the name of the locker followed by ":".
352 ;; Check for master file corresponding to FILE being visited.
354 ;; RCS: Insert the first few characters of the master file into a
355 ;; work buffer. Search work buffer for "locks...;" phrase; if not
356 ;; found, then keep inserting more characters until the phrase is
357 ;; found. Extract the locks, and remove control characters
358 ;; separating them, like newlines; the string " user1:revision1
359 ;; user2:revision2 ..." is returned.
361 ;; SCCS: Check if the p-file exists. If it does, read it and
362 ;; extract the locks, giving them the right format. Else use prs to
363 ;; find the revision number.
365 ;; CVS: vc-find-cvs-master has already stored the current revision
366 ;; number and sticky-tag for the file. XEmacs displays the sticky-tag.
370 ;; The output doesn't show which version you are actually looking at.
371 ;; The modeline can get quite cluttered when there are multiple locks.
372 ;; The head revision is probably not what you want if you've used `rcs -b'.
374 (let ((master (vc-name file))
378 ;; If master file exists, then parse its contents, otherwise we
379 ;; return the nil value of this if form.
380 (if (and master vc-type)
383 ;; Create work buffer.
384 (set-buffer (get-buffer-create " *vc-status*"))
385 (setq buffer-read-only nil
386 default-directory (file-name-directory master))
389 ;; Set the `status' var to the return value.
394 ;; Check if we have enough of the header.
395 ;; If not, then keep including more.
398 (let ((s (buffer-size)))
400 (zerop (car (cdr (insert-file-contents
401 master nil s (+ s 8192))))))))
403 (setq found (re-search-forward "^locks\\([^;]*\\);" nil t)))
406 ;; Clean control characters and self-locks from text.
408 (concat "[ \b\t\n\v\f\r]+\\("
409 (regexp-quote (user-login-name))
413 (narrow-to-region (match-beginning 1) (match-end 1))
414 (goto-char (point-min))
415 (while (re-search-forward lock-pattern nil t)
416 (replace-match (if (eobp) "" ":") t t))
419 (if (not (string-equal locks ""))
421 (goto-char (point-min))
422 (if (looking-at "head[ \b\t\n\v\f\r]+\\([.0-9]+\\)")
424 (buffer-substring (match-beginning 1)
430 ;; Build the name of the p-file and put it in the work buffer.
432 (search-backward "/s.")
435 (if (not (file-exists-p (buffer-string)))
437 (let ((exec-path (if (boundp 'vc-path) (append exec-path vc-path)
441 (if (zerop (call-process "prs" nil t nil "-d:I:" master))
442 (setq status (buffer-substring 1 (1- (point-max))))))
444 (insert-file-contents (buffer-string) nil nil nil t)
445 (while (looking-at "[^ ]+ \\([^ ]+\\) \\([^ ]+\\).*\n")
446 (replace-match " \\2:\\1"))
447 (setq status (buffer-string))
451 ;; sticky-tag is initialized by vc-backend-deduce
452 (setq status (concat ":" (vc-file-getprop file 'sticky-tag) "-"
453 (vc-file-getprop file 'vc-your-latest-version)
459 ;; Display the explicitly specified version or the latest version
460 (let ((version (or (vc-cc-version-name file)
461 (vc-latest-version file)
462 ;; Make sure version is a string in case the
463 ;; file is not really a versioned object
465 ;; Check if the user wants to see the branch
466 (if vc-cc-display-branch
467 (setq status version)
468 (setq status (concat ":" (file-name-nondirectory version))))
472 ;; Clean work buffer.
474 (set-buffer-modified-p nil)
477 ;;;;; install a call to the above as a find-file hook
479 (defun vc-follow-link ()
480 ;; If the current buffer visits a symbolic link, this function makes it
481 ;; visit the real file instead. If the real file is already visited in
482 ;; another buffer, make that buffer current, and kill the buffer
483 ;; that visits the link.
484 (let* ((truename (abbreviate-file-name (file-chase-links buffer-file-name)))
485 (true-buffer (find-buffer-visiting truename))
486 (this-buffer (current-buffer)))
487 (if (eq true-buffer this-buffer)
489 (kill-buffer this-buffer)
490 ;; In principle, we could do something like set-visited-file-name.
491 ;; However, it can't be exactly the same as set-visited-file-name.
492 ;; I'm not going to work out the details right now. -- rms.
493 (set-buffer (find-file-noselect truename)))
494 (set-buffer true-buffer)
495 (kill-buffer this-buffer))))
497 (defun vc-set-auto-mode ()
498 "Check again for the mode of the current buffer when using ClearCase version extended paths."
500 (if (eq (vc-file-getprop buffer-file-name 'vc-backend) '@@)
501 (let* ((version (vc-cc-version-name buffer-file-name))
502 (buffer-file-name (vc-cc-element-name buffer-file-name)))
503 ;; Need to recheck the major mode only if a version was appended
504 (if version (set-auto-mode))
505 ;; Set a buffer-local variable for the working view
506 (setq vc-cc-pwv (vc-cc-pwv buffer-file-name))
510 (defun vc-find-file-hook ()
511 ;; Recompute whether file is version controlled,
512 ;; if user has killed the buffer and revisited.
515 (vc-file-clearprops buffer-file-name)
517 ((vc-backend-deduce buffer-file-name)
518 (vc-mode-line buffer-file-name)
519 (cond ((not vc-make-backup-files)
520 ;; Use this variable, not make-backup-files,
521 ;; because this is for things that depend on the file name.
522 (make-local-variable 'backup-inhibited)
523 (setq backup-inhibited t)))
525 ((let* ((link (file-symlink-p buffer-file-name))
526 (link-type (and link (vc-backend-deduce (file-chase-links link)))))
528 (cond ((null vc-follow-symlinks)
530 "Warning: symbolic link to %s-controlled source file" link-type))
531 ((or (not (eq vc-follow-symlinks 'ask))
532 ;; If we already visited this file by following
533 ;; the link, don't ask again if we try to visit
534 ;; it again. GUD does that, and repeated questions
536 (let ((find-file-compare-truenames nil))
537 ;; If compare-truenames is t, this will always be t
539 (abbreviate-file-name (file-chase-links buffer-file-name)))))
542 (message "Followed link to %s" buffer-file-name)
547 "Symbolic link to %s-controlled source file; follow link? "
549 (progn (vc-follow-link)
550 (message "Followed link to %s" buffer-file-name)
553 "Warning: editing through the link bypasses version control")
558 ;;; install a call to the above as a find-file hook
559 (add-hook 'find-file-hooks 'vc-find-file-hook)
561 ;; Handle ClearCase version files correctly.
563 ;; This little bit of magic causes the buffer name to be set to
564 ;; <filename>@@/<branch path>/<version>, if you find a specific version of
565 ;; a file. Without this the name of the buffer will just be the version
568 (defun vc-check-cc-name ()
569 (let ((match (string-match "@@" default-directory)))
572 (while (and (> match 0)
573 (not (equal (elt default-directory match)
574 (string-to-char "/"))))
575 (setq match (1- match)))
578 (let ((new-buffer-name
579 (concat (substring default-directory (1+ match))
582 (substring default-directory 0 (1+ match))))
583 (or (string= new-buffer-name (buffer-name))
584 ;; Uniquify the name, if necessary.
587 (uniquifier-string ""))
588 (while (get-buffer (concat new-buffer-name uniquifier-string))
589 (setq uniquifier-string (format "<%d>" n))
592 (concat new-buffer-name uniquifier-string))))
593 (setq default-directory new-dir)))
596 (add-hook 'find-file-hooks 'vc-check-cc-name)
598 (defun vc-find-dir-hook ()
599 ;; Recompute whether file is version controlled,
600 ;; if user has killed the buffer and revisited.
601 (vc-file-clearprops default-directory)
602 (if default-directory
603 (vc-file-setprop default-directory 'vc-backend nil))
605 ;; Let dired decide whether the file should be read-only
606 (let (buffer-read-only)
607 (vc-mode-line default-directory))
609 ;; If in vc-dired-mode, reformat the buffer
611 (vc-reformat-dired-buffer)
612 ;; Otherwise, check if we should automatically enter vc-dired-mode
613 (let ((default-directory (dired-current-directory)))
614 (if (and vc-auto-dired-mode
616 (file-directory-p "SCCS")
617 (file-directory-p "RCS")
618 (file-directory-p "CVS")))
622 (add-hook 'dired-after-readin-hook 'vc-find-dir-hook)
624 ;;; more hooks, this time for file-not-found
625 (defun vc-file-not-found-hook ()
626 "When file is not found, try to check it out from RCS or SCCS.
627 Returns t if checkout was successful, nil otherwise."
628 (if (vc-backend-deduce buffer-file-name)
631 (not (vc-error-occurred (vc-checkout buffer-file-name))))))
633 (add-hook 'find-file-not-found-hooks 'vc-file-not-found-hook)
635 ;;; Now arrange for bindings and autoloading of the main package.
636 ;;; Bindings for this have to go in the global map, as we'll often
637 ;;; want to call them from random buffers.
639 (add-to-list 'file-name-handler-alist '("^/view/[^/]+/" . vc-cc-file-handler))
640 (add-to-list 'file-name-handler-alist '("^/view[/]*$" . vc-cc-view-handler))
642 ; XEmacs - this is preloaded. let's not be obtuse!
643 (defconst vc-prefix-map
644 (let ((map (make-sparse-keymap)))
645 (set-keymap-name map 'vc-prefix-map)
646 (define-key map "a" 'vc-update-change-log)
647 (define-key map "c" 'vc-cancel-version)
648 (define-key map "d" 'vc-directory)
649 (define-key map "h" 'vc-insert-headers)
650 (define-key map "i" 'vc-register)
651 (define-key map "l" 'vc-print-log)
652 (define-key map "n" 'vc-assign-name)
653 (define-key map "r" 'vc-retrieve-snapshot)
654 (define-key map "s" 'vc-create-snapshot)
655 (define-key map "u" 'vc-revert-buffer)
656 (define-key map "v" 'vc-next-action)
657 (define-key map "=" 'vc-diff)
658 (define-key map "?" 'vc-file-status) ; XEmacs - this doesn't fit elsewhere
659 (define-key map "~" 'vc-version-other-window)
660 ;; ClearCase only stuff
661 (define-key map "e" 'vc-edit-config)
662 (define-key map "b" 'vc-cc-browse-versions)
663 (define-key map "m" 'vc-mkbrtype)
664 (define-key map "t" 'vc-graph-history)
665 (define-key map "w" 'vc-cc-what-rule)
666 (global-set-key "\C-xv" map)
671 (if (and (not vc-elucidated) (boundp 'menu-bar-final-items))
673 (defvar menu-bar-vc-menu
674 (make-sparse-keymap "VC"))
676 'vc menu-bar-final-items)
677 (setq menu-bar-final-items
679 'vc menu-bar-final-items)))
680 (define-key menu-bar-vc-menu [vc-report-bug]
681 '("Report Bug in Clearcase VC" . cc-vc-submit-bug-report))
682 (define-key menu-bar-vc-menu [vc-directory-registered]
683 '("List Registered Files" . vc-directory-registered))
684 (define-key menu-bar-vc-menu [vc-directory]
685 '("List Locked Files Any User" . vc-directory))
686 (define-key menu-bar-vc-menu [vc-directory-locked]
687 '("List Locked Files" . vc-directory-locked))
688 (put 'vc-print-log 'menu-enable 'vc-mode)
689 (define-key menu-bar-vc-menu [vc-print-log]
690 '("Show Edit History" . vc-print-log))
691 (put 'vc-version-other-window 'menu-enable 'vc-mode)
692 (define-key menu-bar-vc-menu [vc-version-other-window]
693 '("Visit Previous Revision..." . vc-version-other-window))
694 (put 'vc-diff-since-revision 'menu-enable 'vc-mode)
695 (define-key menu-bar-vc-menu [vc-diff-since-revision]
696 '("Show Changes Since Revision..." . vc-diff-since-revision))
697 (put 'vc-diff 'menu-enable 'vc-mode)
698 (define-key menu-bar-vc-menu [vc-diff]
699 '("Show Changes" . vc-diff))
700 (put 'vc-rename-this-file 'menu-enable 'vc-mode)
701 (define-key menu-bar-vc-menu [vc-rename-this-file]
702 '("Rename File" . vc-rename-this-file))
703 (put 'vc-revert-buffer 'menu-enable 'vc-mode)
704 (define-key menu-bar-vc-menu [vc-revert-buffer]
705 '("Revert File" . vc-revert-buffer))
706 (define-key menu-bar-vc-menu [vc-update-directory]
707 '("Update Current Directory" . vc-update-directory))
708 (define-key menu-bar-vc-menu [next-action]
709 '("Next Action" . vc-next-action))
710 (define-key global-map [menu-bar vc]
711 (cons "VC" menu-bar-vc-menu))))
713 ;;; Lucid Emacs menus..
714 (defconst vc-default-menu
715 '(:filter vc-menu-filter
716 ["NEXT-OPERATION" vc-next-action t nil]
717 ["Update Current Directory" vc-update-directory t]
719 ["Revert to Last Revision" vc-revert-buffer t nil]
720 ["Cancel Last Checkin" vc-cancel-version t nil]
721 ["Rename File" vc-rename-this-file t nil]
723 ["Diff Against Last Version" vc-diff t]
724 ["Diff Between Revisions..." vc-diff-since-revision t]
725 ["Visit Other Version..." vc-version-other-window t]
726 ["Show Edit History" vc-print-log t]
727 ["Assign Label..." vc-assign-name t]
729 ["List Locked Files" (progn
730 (setq current-prefix-arg '(16))
731 (call-interactively 'vc-directory)) t]
732 ["List Locked Files Any User" vc-directory t]
733 ["List Registered Files" (progn
734 (setq current-prefix-arg '(4))
735 (call-interactively 'vc-directory)) t])
736 "Menubar entry for using the revision control system.")
738 (defconst vc-cvs-menu
739 '(:filter vc-menu-filter
740 ["Update Current Directory" vc-cvs-update-directory t]
741 ["Revert File" vc-revert-file t nil]
743 ["Show Changes" vc-show-changes t]
744 ["Show Changes Since Revision..." vc-show-revision-changes t]
745 ["Visit Previous Revision..." vc-version-other-window t]
746 ["Show File Status" vc-cvs-file-status t]
747 ["Show Edit History" vc-show-history t])
748 "Menubar entry for using the revision control system with CVS.")
751 '(["Edit Config Spec..." vc-edit-config t]
752 ["Browse Versions" vc-cc-browse-versions t]
753 ["Make Branch Type..." vc-mkbrtype t]
754 ["View Graph History" vc-graph-history t]
755 ["Show Rule" vc-cc-what-rule t])
756 "Menubar entries to add to the VC menu when using ClearCase.")
758 ;; This function may be called as a menubar hook, or as a menu filter
759 ;; The filter is much more efficient, and doesn't slow down menubar selection
760 ;; for every single menu action, as does the hook method.
761 (defun vc-menu-filter (&optional menu)
764 (setq menu (find-menu-item current-menubar '("Tools" "Version Control")))
765 ;; Get just the menu portion
766 (if menu (setq menu (cdr (car menu))))
772 (filepath (cond ((and vc-dired-mode
773 (dired-get-filename nil 'no-error)))
776 (file (and filepath (file-name-nondirectory filepath)))
777 (vc-file (and filepath (vc-name filepath)))
782 (setq item (car rest))
784 (if (not (vectorp item))
786 (setq command (aref item 1))
788 ;; Display the correct action for vc-next-action command
789 ((eq 'vc-next-action command)
794 ;; Just check properties, it's too
795 ;; slow (and dangerous) to fetch
797 (vc-file-getprop filepath 'vc-locking-user)))
798 ;;(vc-locking-user filepath)))
800 ((not (string-equal owner (user-login-name)))
802 (t "Check in File")))
803 (aset item 2 (or buffer-file-name
804 (and vc-dired-mode "Marked")))
807 ;; Check for commands to disable
813 vc-diff-since-revision
814 vc-version-other-window
815 vc-visit-previous-revision
818 (aset item 2 vc-file))
822 ;; Add the file to the menu suffix if not disabled
823 (if (and (> (length item) 3) (aref item 2))
825 (if vc-dired-mode "Marked" file)))
828 (setq rest (cdr rest)))
830 ;; Return menu plus the ClearCase menu if needed
831 (if (and vc-file (clearcase-element-p filepath))
832 ;; Must use append here - nconc will create looped list
833 (append menu '("----") vc-cc-menu)
837 ;; vc-menu-filter was once called vc-sensitize-menu, so just in case another
838 ;; version of vc was loaded:
839 (defalias 'vc-sensitize-menu 'vc-menu-filter)
841 (if (and (fboundp 'add-submenu) (not (featurep 'infodock)) vc-elucidated)
843 (add-submenu '("Tools") (append (list "Version Control") vc-default-menu))
844 ;; Only add the hook if the :filter method is unavailable. I don't know which
845 ;; version of XEmacs introduced it, but it's been available at least since 19.13
846 ;; (add-hook 'activate-menubar-hook 'vc-sensitize-menu)))
849 ;; #### called by files.el. Define it like this until we're merged.
850 (defun vc-after-save ())
852 ;;---------------------------------------------------------------------------
853 ;; Utility functions for ClearCase
854 ;;---------------------------------------------------------------------------
856 (defun clearcase-element-p (path)
857 "Determine if PATH refers to a Clearcase element."
859 (let (extended-path versioned-path)
861 (if (string-match "@@" path)
862 (setq extended-path (substring path 0 (match-end 0))
864 (setq extended-path (concat path "@@")))
866 (and (file-exists-p path)
867 (file-directory-p extended-path)
869 ;; Non-checked-out elements have the same inode-number
870 ;; as the extended name ("foo@@").
871 ;; Not so for checked out, and therefore writeable elements.
873 (or (file-writable-p path)
875 (eq (file-inode path)
876 (file-inode extended-path)))
879 (if (not (fboundp 'file-inode))
880 (defun file-inode (file)
881 (nth 10 (file-attributes file))))
883 (defun vc-cc-element-name (path)
884 (if (string-match "@@" path)
885 (substring path 0 (match-beginning 0))
888 (defun vc-cc-version-name (path)
889 (if (string-match "@@" path)
890 (substring path (match-end 0))
893 (defsubst vc-cc-relpath (str)
896 (string-match "^/view/\\([^/]+\\)" str)
900 (defun vc-cc-build-version (file version &optional view-tag)
901 "Build a ClearCase version-extended pathname for ELEMENT's version VERSION.
902 If ELEMENT is actually a version-extended pathname, substitute VERSION for
903 the version included in ELEMENT. If VERSION is nil, remove the version-extended
906 If optional VIEW-TAG is specified, make a view-relative pathname, possibly
907 replacing the existing view prefix."
908 (let* ((element (vc-cc-element-name file))
909 (glue-fmt (if (and (> (length version) 0)
910 (= (aref version 0) ?/))
913 (relpath (vc-cc-relpath element)))
915 (setq element (concat "/view/" view-tag (or relpath element))))
917 (format glue-fmt element version)
921 ;; These stolen from vc. pcl-cvs wants to call these in
922 ;; cvs-mark-buffer-changed. (Basically only changed vc-backend to
923 ;; vc-backend-deduce.)
925 (defun vc-consult-rcs-headers (file)
926 ;; Search for RCS headers in FILE, and set properties
927 ;; accordingly. This function can be disabled by setting
928 ;; vc-consult-headers to nil.
929 ;; Returns: nil if no headers were found
930 ;; (or if the feature is disabled,
931 ;; or if there is currently no buffer
933 ;; 'rev if a workfile revision was found
934 ;; 'rev-and-lock if revision and lock info was found
936 ((or (not vc-consult-headers)
937 (not (get-file-buffer file))) nil)
938 ((let (status version locking-user)
940 (set-buffer (get-file-buffer file))
941 (goto-char (point-min))
943 ;; search for $Id or $Header
944 ;; -------------------------
945 ((or (and (search-forward "$Id: " nil t)
946 (looking-at "[^ ]+ \\([0-9.]+\\) "))
947 (and (progn (goto-char (point-min))
948 (search-forward "$Header: " nil t))
949 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
950 (goto-char (match-end 0))
951 ;; if found, store the revision number ...
952 (setq version (buffer-substring-no-properties (match-beginning 1)
954 ;; ... and check for the locking state
957 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
958 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
959 "[^ ]+ [^ ]+ ")) ; author & state
960 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
964 (setq locking-user 'none)
965 (setq status 'rev-and-lock))
966 ;; revision is locked by some user
967 ((looking-at "\\([^ ]+\\) \\$")
969 (buffer-substring-no-properties (match-beginning 1)
971 (setq status 'rev-and-lock))
972 ;; everything else: false
974 ;; unexpected information in
975 ;; keyword string --> quit
977 ;; search for $Revision
978 ;; --------------------
979 ((re-search-forward (concat "\\$"
980 "Revision: \\([0-9.]+\\) \\$")
982 ;; if found, store the revision number ...
983 (setq version (buffer-substring-no-properties (match-beginning 1)
985 ;; and see if there's any lock information
986 (goto-char (point-min))
987 (if (re-search-forward (concat "\\$" "Locker:") nil t)
988 (cond ((looking-at " \\([^ ]+\\) \\$")
989 (setq locking-user (buffer-substring-no-properties
992 (setq status 'rev-and-lock))
993 ((looking-at " *\\$")
994 (setq locking-user 'none)
995 (setq status 'rev-and-lock))
997 (setq locking-user 'none)
998 (setq status 'rev-and-lock)))
1000 ;; else: nothing found
1001 ;; -------------------
1003 (if status (vc-file-setprop file 'vc-workfile-version version))
1004 (and (eq status 'rev-and-lock)
1005 (eq (vc-backend-deduce file) 'RCS)
1006 (vc-file-setprop file 'vc-locking-user locking-user)
1007 ;; If the file has headers, we don't want to query the master file,
1008 ;; because that would eliminate all the performance gain the headers
1009 ;; brought us. We therefore use a heuristic for the checkout model
1010 ;; now: If we trust the file permissions, and the file is not
1011 ;; locked, then if the file is read-only the checkout model is
1012 ;; `manual', otherwise `implicit'.
1013 (not (vc-mistrust-permissions file))
1014 (not (vc-locking-user file))
1015 (if (string-match ".r-..-..-." (nth 8 (file-attributes file)))
1016 (vc-file-setprop file 'vc-checkout-model 'manual)
1017 (vc-file-setprop file 'vc-checkout-model 'implicit)))
1020 (defun vc-workfile-version (file)
1021 ;; Return version level of the current workfile FILE
1022 ;; This is attempted by first looking at the RCS keywords.
1023 ;; If there are no keywords in the working file,
1024 ;; vc-master-workfile-version is taken.
1025 ;; Note that this property is cached, that is, it is only
1026 ;; looked up if it is nil.
1027 ;; For SCCS, this property is equivalent to vc-latest-version.
1028 (cond ((vc-file-getprop file 'vc-workfile-version))
1029 ((eq (vc-backend-deduce file) 'SCCS) (vc-latest-version file))
1030 ((eq (vc-backend-deduce file) 'RCS)
1031 (if (vc-consult-rcs-headers file)
1032 (vc-file-getprop file 'vc-workfile-version)
1033 (let ((rev (cond ((vc-master-workfile-version file))
1034 ((vc-latest-version file)))))
1035 (vc-file-setprop file 'vc-workfile-version rev)
1037 ((eq (vc-backend-deduce file) 'CVS)
1038 (if (vc-consult-rcs-headers file) ;; CVS
1039 (vc-file-getprop file 'vc-workfile-version)
1041 (vc-find-cvs-master (file-name-directory file)
1042 (file-name-nondirectory file)))
1043 (vc-file-getprop file 'vc-workfile-version)))))
1045 (provide 'vc-cc-hooks)
1047 ;;; vc-cc-hooks.el ends here