comparison lisp/vc-hooks.el @ 9248:325cee61ab7f

(vc-status): Handle CVS. (vc-find-cvs-master): New function. (vc-master-templates): Add vc-find-cvs-master. (vc-registered): Allow vc-master-templates to contain atoms, and call them with dirname and basename as arguments. (vc-mode-line): Use equal, not string-equal, to compare the result of vc-locking-user.
author Richard M. Stallman <rms@gnu.org>
date Mon, 03 Oct 1994 21:56:50 +0000
parents 2a81d1c79162
children b6bed4a60f84
comparison
equal deleted inserted replaced
9247:729da1317557 9248:325cee61ab7f
1 ;;; vc-hooks.el --- resident support for version-control 1 ;;; vc-hooks.el --- resident support for version-control
2 2
3 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. 3 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
4 4
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> 5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
6 ;; Version: 5.3 6 ;; Version: 5.3 + CVS hacks by ceder@lysator.liu.se made in Jan-Feb 1994.
7 7
8 ;; This file is part of GNU Emacs. 8 ;; This file is part of GNU Emacs.
9 9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify 10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by 11 ;; it under the terms of the GNU General Public License as published by
27 27
28 ;;; Code: 28 ;;; Code:
29 29
30 (defvar vc-master-templates 30 (defvar vc-master-templates
31 '(("%sRCS/%s,v" . RCS) ("%s%s,v" . RCS) ("%sRCS/%s" . RCS) 31 '(("%sRCS/%s,v" . RCS) ("%s%s,v" . RCS) ("%sRCS/%s" . RCS)
32 ("%sSCCS/s.%s" . SCCS) ("%ss.%s". SCCS)) 32 ("%sSCCS/s.%s" . SCCS) ("%ss.%s". SCCS)
33 vc-find-cvs-master)
33 "*Where to look for version-control master files. 34 "*Where to look for version-control master files.
34 The first pair corresponding to a given back end is used as a template 35 The first pair corresponding to a given back end is used as a template
35 when creating new masters.") 36 when creating new masters.")
36 37
37 (defvar vc-make-backup-files nil 38 (defvar vc-make-backup-files nil
80 (let ((dirname (or (file-name-directory file) "")) 81 (let ((dirname (or (file-name-directory file) ""))
81 (basename (file-name-nondirectory file))) 82 (basename (file-name-nondirectory file)))
82 (catch 'found 83 (catch 'found
83 (mapcar 84 (mapcar
84 (function (lambda (s) 85 (function (lambda (s)
85 (let ((trial (format (car s) dirname basename))) 86 (if (atom s)
86 (if (and (file-exists-p trial) 87 (funcall s dirname basename)
87 ;; Make sure the file we found with name 88 (let ((trial (format (car s) dirname basename)))
88 ;; TRIAL is not the source file itself. 89 (if (and (file-exists-p trial)
89 ;; That can happen with RCS-style names 90 ;; Make sure the file we found with name
90 ;; if the file name is truncated 91 ;; TRIAL is not the source file itself.
91 ;; (e.g. to 14 chars). See if either 92 ;; That can happen with RCS-style names
92 ;; directory or attributes differ. 93 ;; if the file name is truncated
93 (or (not (string= dirname 94 ;; (e.g. to 14 chars). See if either
94 (file-name-directory trial))) 95 ;; directory or attributes differ.
95 (not (equal 96 (or (not (string= dirname
96 (file-attributes file) 97 (file-name-directory trial)))
97 (file-attributes trial))))) 98 (not (equal
98 (throw 'found (cons trial (cdr s))))))) 99 (file-attributes file)
100 (file-attributes trial)))))
101 (throw 'found (cons trial (cdr s))))))))
99 vc-master-templates) 102 vc-master-templates)
100 nil))))) 103 nil)))))
104
105 (defun vc-find-cvs-master (dirname basename)
106 ;; Check if DIRNAME/BASENAME is handled by CVS.
107 ;; If it is, do a (throw 'found (cons MASTER 'CVS)).
108 ;; Note: If the file is ``cvs add''ed but not yet ``cvs commit''ed
109 ;; the MASTER will not actually exist yet. The other parts of VC
110 ;; checks for this condition. This function returns something random if
111 ;; DIRNAME/BASENAME is not handled by CVS.
112 (if (and (file-directory-p (concat dirname "CVS/"))
113 (file-readable-p (concat dirname "CVS/Entries")))
114 (let ((bufs nil))
115 (unwind-protect
116 (save-excursion
117 (setq bufs (list
118 (find-file-noselect (concat dirname "CVS/Entries"))))
119 (set-buffer (car bufs))
120 (goto-char (point-min))
121 (cond
122 ((re-search-forward
123 (concat "^/" (regexp-quote basename) "/\\([^/]*\\)/")
124 nil t)
125 ;; We found it. Store away version number, now
126 ;; that we are anyhow so close to finding it.
127 (vc-file-setprop (concat dirname basename)
128 'vc-your-latest-version
129 (buffer-substring (match-beginning 1)
130 (match-end 1)))
131 (setq bufs (cons (find-file-noselect
132 (concat dirname "CVS/Repository"))
133 bufs))
134 (set-buffer (car bufs))
135 (let ((master
136 (concat (file-name-as-directory
137 (buffer-substring (point-min)
138 (1- (point-max))))
139 basename
140 ",v")))
141 (throw 'found (cons master 'CVS))))))
142 (mapcar (function kill-buffer) bufs)))))
101 143
102 (defun vc-name (file) 144 (defun vc-name (file)
103 "Return the master name of a file, nil if it is not registered." 145 "Return the master name of a file, nil if it is not registered."
104 (or (vc-file-getprop file 'vc-name) 146 (or (vc-file-getprop file 'vc-name)
105 (let ((name-and-type (vc-registered file))) 147 (let ((name-and-type (vc-registered file)))
146 ;; locking it first. 188 ;; locking it first.
147 (and vc-type 189 (and vc-type
148 (not buffer-read-only) 190 (not buffer-read-only)
149 (zerop (user-uid)) 191 (zerop (user-uid))
150 (require 'vc) 192 (require 'vc)
151 (not (string-equal (user-login-name) (vc-locking-user file))) 193 (not (equal (user-login-name) (vc-locking-user file)))
152 (setq buffer-read-only t)) 194 (setq buffer-read-only t))
153 (and (null vc-type) 195 (and (null vc-type)
154 (file-symlink-p file) 196 (file-symlink-p file)
155 (let ((link-type (vc-backend-deduce (file-symlink-p file)))) 197 (let ((link-type (vc-backend-deduce (file-symlink-p file))))
156 (if link-type 198 (if link-type
157 (message "Warning: symbolic link to %s-controlled source file" 199 (message
158 link-type)))) 200 "Warning: symbolic link to %s-controlled source file"
201 link-type))))
159 (force-mode-line-update) 202 (force-mode-line-update)
160 ;;(set-buffer-modified-p (buffer-modified-p)) ;;use this if Emacs 18 203 ;;(set-buffer-modified-p (buffer-modified-p)) ;;use this if Emacs 18
161 vc-type))) 204 vc-type)))
162 205
163 (defun vc-status (file vc-type) 206 (defun vc-status (file vc-type)
181 ;; user2:revision2 ..." is returned. 224 ;; user2:revision2 ..." is returned.
182 ;; 225 ;;
183 ;; SCCS: Check if the p-file exists. If it does, read it and 226 ;; SCCS: Check if the p-file exists. If it does, read it and
184 ;; extract the locks, giving them the right format. Else use prs to 227 ;; extract the locks, giving them the right format. Else use prs to
185 ;; find the revision number. 228 ;; find the revision number.
229 ;;
230 ;; CVS: vc-find-cvs-master has already stored the current revision
231 ;; number. Fetch it from the file property.
186 232
187 ;; Limitations: 233 ;; Limitations:
188 234
189 ;; The output doesn't show which version you are actually looking at. 235 ;; The output doesn't show which version you are actually looking at.
190 ;; The modeline can get quite cluttered when there are multiple locks. 236 ;; The modeline can get quite cluttered when there are multiple locks.
262 ;; Locks exist. 308 ;; Locks exist.
263 (insert-file-contents (buffer-string) nil nil nil t) 309 (insert-file-contents (buffer-string) nil nil nil t)
264 (while (looking-at "[^ ]+ \\([^ ]+\\) \\([^ ]+\\).*\n") 310 (while (looking-at "[^ ]+ \\([^ ]+\\) \\([^ ]+\\).*\n")
265 (replace-match " \\2:\\1")) 311 (replace-match " \\2:\\1"))
266 (setq status (buffer-string)) 312 (setq status (buffer-string))
267 (aset status 0 ?:)))) 313 (aset status 0 ?:)))
314 ;; CVS code.
315 ((eq vc-type 'CVS)
316 (let ((version (vc-file-getprop
317 file 'vc-your-latest-version)))
318 (setq status (concat ":" (if (string= "0" version)
319 " @@" ;added, not yet committed.
320 version))))))
268 321
269 ;; Clean work buffer. 322 ;; Clean work buffer.
270 (erase-buffer) 323 (erase-buffer)
271 (set-buffer-modified-p nil) 324 (set-buffer-modified-p nil)
272 status)))) 325 status))))