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