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