0
|
1 ;;; vc.el --- drive a version-control system from within Emacs
|
|
2
|
|
3 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
|
|
5
|
|
6 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
|
|
7 ;; Maintainer: ttn@netcom.com
|
|
8 ;; Version: 5.6
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
16
|
23 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
25 ;; Boston, MA 02111-1307, USA.
|
0
|
26
|
|
27 ;;; Synched up with: It's not clear at this point.
|
|
28 ;;; mly synched this with FSF at version 5.4. Stig did a whole lot
|
|
29 ;;; of stuff to it since then, and so has the FSF.
|
|
30
|
|
31 ;;; Commentary:
|
|
32
|
|
33 ;; This mode is fully documented in the Emacs user's manual.
|
|
34 ;;
|
|
35 ;; This was designed and implemented by Eric Raymond <esr@snark.thyrsus.com>.
|
|
36 ;; Paul Eggert <eggert@twinsun.com>, Sebastian Kremer <sk@thp.uni-koeln.de>,
|
|
37 ;; and Richard Stallman contributed valuable criticism, support, and testing.
|
|
38 ;; CVS support was added by Per Cederqvist <ceder@lysator.liu.se>
|
|
39 ;; in Jan-Feb 1994.
|
|
40 ;;
|
|
41 ;; XEmacs fixes, CVS fixes, and general improvements
|
|
42 ;; by Jonathan Stigelman <Stig@hackvan.com>
|
|
43 ;;
|
|
44 ;; Supported version-control systems presently include SCCS, RCS, and CVS.
|
|
45 ;; The RCS lock-stealing code doesn't work right unless you use RCS 5.6.2
|
|
46 ;; or newer. Currently (January 1994) that is only a beta test release.
|
|
47 ;; Even initial checkins will fail if your RCS version is so old that ci
|
|
48 ;; doesn't understand -t-; this has been known to happen to people running
|
|
49 ;; NExTSTEP 3.0.
|
|
50 ;;
|
|
51 ;; The RCS code assumes strict locking. You can support the RCS -x option
|
|
52 ;; by adding pairs to the vc-master-templates list.
|
|
53 ;;
|
|
54 ;; Proper function of the SCCS diff commands requires the shellscript vcdiff
|
|
55 ;; to be installed somewhere on Emacs's path for executables.
|
|
56 ;;
|
|
57 ;; If your site uses the ChangeLog convention supported by Emacs, the
|
|
58 ;; function vc-comment-to-change-log should prove a useful checkin hook.
|
|
59 ;;
|
|
60 ;; This code depends on call-process passing back the subprocess exit
|
|
61 ;; status. Thus, you need Emacs 18.58 or later to run it. For the
|
|
62 ;; vc-directory command to work properly as documented, you need 19.
|
|
63 ;; You also need Emacs 19's ring.el.
|
|
64 ;;
|
|
65 ;; The vc code maintains some internal state in order to reduce expensive
|
|
66 ;; version-control operations to a minimum. Some names are only computed
|
|
67 ;; once. If you perform version control operations with RCS/SCCS/CVS while
|
|
68 ;; vc's back is turned, or move/rename master files while vc is running,
|
|
69 ;; vc may get seriously confused. Don't do these things!
|
|
70 ;;
|
|
71 ;; Developer's notes on some concurrency issues are included at the end of
|
|
72 ;; the file.
|
|
73
|
|
74 ;;; Code:
|
|
75
|
|
76 (require 'vc-hooks)
|
|
77 (require 'ring)
|
|
78 (eval-when-compile (require 'dired)) ; for dired-map-over-marks macro
|
|
79
|
|
80 (if (not (assoc 'vc-parent-buffer minor-mode-alist))
|
|
81 (setq minor-mode-alist
|
|
82 (cons '(vc-parent-buffer vc-parent-buffer-name)
|
|
83 minor-mode-alist)))
|
|
84
|
|
85 ;; General customization
|
|
86
|
|
87 (defvar vc-default-back-end nil
|
|
88 "*Back-end actually used by this interface; may be SCCS or RCS.
|
|
89 The value is only computed when needed to avoid an expensive search.")
|
|
90 (defvar vc-suppress-confirm nil
|
|
91 "*If non-nil, treat user as expert; suppress yes-no prompts on some things.")
|
|
92 (defvar vc-keep-workfiles t
|
|
93 "*If non-nil, don't delete working files after registering changes.
|
|
94 If the back-end is CVS, workfiles are always kept, regardless of the
|
|
95 value of this flag.")
|
|
96 (defvar vc-initial-comment nil
|
|
97 "*Prompt for initial comment when a file is registered.")
|
|
98 (defvar vc-command-messages nil
|
|
99 "*Display run messages from back-end commands.")
|
|
100 (defvar vc-mistrust-permissions 'file-symlink-p
|
|
101 "*Don't assume that permissions and ownership track version-control status.")
|
|
102 (defvar vc-checkin-switches nil
|
|
103 "*Extra switches passed to the checkin program by \\[vc-checkin].")
|
|
104 (defvar vc-checkout-switches nil
|
|
105 "*Extra switches passed to the checkout program by \\[vc-checkout].")
|
|
106 (defvar vc-path
|
|
107 (if (file-exists-p "/usr/sccs")
|
|
108 '("/usr/sccs") nil)
|
|
109 "*List of extra directories to search for version control commands.")
|
|
110 (defvar vc-directory-exclusion-list '("SCCS" "RCS")
|
|
111 "*Directory names ignored by functions that recursively walk file trees.")
|
|
112
|
|
113 (defconst vc-maximum-comment-ring-size 32
|
|
114 "Maximum number of saved comments in the comment ring.")
|
|
115
|
|
116 ;;; XEmacs - This is dumped into loaddefs.el already.
|
100
|
117 ;; Not any more! -sb
|
|
118 (defvar diff-switches "-c"
|
|
119 "*A string or list of strings specifying switches to be passed to diff.")
|
0
|
120
|
|
121 ;;;###autoload
|
|
122 (defvar vc-checkin-hook nil
|
|
123 "*List of functions called after a checkin is done. See `run-hooks'.")
|
|
124
|
|
125 (defvar vc-make-buffer-writable-hook nil
|
|
126 "*List of functions called when a buffer is made writable. See `run-hooks.'
|
|
127 This hook is only used when the version control system is CVS. It
|
|
128 might be useful for sites who uses locking with CVS, or who uses link
|
|
129 farms to gold trees.")
|
|
130
|
|
131 ;; Header-insertion hair
|
|
132
|
|
133 (defvar vc-header-alist
|
|
134 '((SCCS "\%W\%") (RCS "\$Id\$") (CVS "\$Id\$"))
|
|
135 "*Header keywords to be inserted when `vc-insert-headers' is executed.")
|
|
136 (defvar vc-static-header-alist
|
|
137 '(("\\.c$" .
|
|
138 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
|
|
139 "*Associate static header string templates with file types. A \%s in the
|
|
140 template is replaced with the first string associated with the file's
|
|
141 version-control type in `vc-header-alist'.")
|
|
142
|
|
143 (defvar vc-comment-alist
|
|
144 '((nroff-mode ".\\\"" ""))
|
|
145 "*Special comment delimiters to be used in generating vc headers only.
|
|
146 Add an entry in this list if you need to override the normal comment-start
|
|
147 and comment-end variables. This will only be necessary if the mode language
|
|
148 is sensitive to blank lines.")
|
|
149
|
|
150 ;; Default is to be extra careful for super-user.
|
|
151 (defvar vc-checkout-carefully (= (user-uid) 0) ; #### - this prevents preloading!
|
|
152 "*Non-nil means be extra-careful in checkout.
|
|
153 Verify that the file really is not locked
|
|
154 and that its contents match what the master file says.")
|
|
155
|
|
156 ;; Variables the user doesn't need to know about.
|
|
157 (defvar vc-log-entry-mode nil)
|
|
158 (defvar vc-log-operation nil)
|
|
159 (defvar vc-log-after-operation-hook nil)
|
|
160 (defvar vc-checkout-writable-buffer-hook 'vc-checkout-writable-buffer)
|
|
161 ;; In a log entry buffer, this is a local variable
|
|
162 ;; that points to the buffer for which it was made
|
|
163 ;; (either a file, or a VC dired buffer).
|
|
164 (defvar vc-parent-buffer nil)
|
|
165 (defvar vc-parent-buffer-name nil)
|
|
166
|
|
167 (defvar vc-log-file)
|
|
168 (defvar vc-log-version)
|
|
169
|
|
170 (defconst vc-name-assoc-file "VC-names")
|
|
171
|
|
172 (defvar vc-dired-mode nil)
|
|
173 (make-variable-buffer-local 'vc-dired-mode)
|
|
174
|
|
175 (defvar vc-comment-ring nil)
|
|
176 (defvar vc-comment-ring-index nil)
|
|
177 (defvar vc-last-comment-match nil)
|
|
178
|
|
179 ;; File property caching
|
|
180
|
|
181 (defun vc-file-clearprops (file)
|
|
182 ;; clear all properties of a given file
|
|
183 (setplist (intern file vc-file-prop-obarray) nil))
|
|
184
|
|
185 (defun vc-clear-context ()
|
|
186 "Clear all cached file properties and the comment ring."
|
|
187 (interactive)
|
|
188 (fillarray vc-file-prop-obarray nil)
|
|
189 ;; Note: there is potential for minor lossage here if there is an open
|
|
190 ;; log buffer with a nonzero local value of vc-comment-ring-index.
|
|
191 (setq vc-comment-ring nil))
|
|
192
|
|
193 ;; Random helper functions
|
|
194
|
|
195 (defun vc-registration-error (file)
|
|
196 (if file
|
|
197 (error "File %s is not under version control" file)
|
|
198 (error "Buffer %s is not associated with a file" (buffer-name))))
|
|
199
|
|
200 (defvar vc-binary-assoc nil)
|
|
201
|
|
202 (defun vc-find-binary (name)
|
|
203 "Look for a command anywhere on the subprocess-command search path."
|
|
204 (or (cdr (assoc name vc-binary-assoc))
|
|
205 ;; XEmacs - use locate-file
|
|
206 (let ((full (locate-file name exec-path nil 1)))
|
|
207 (if full
|
|
208 (setq vc-binary-assoc (cons (cons name full) vc-binary-assoc)))
|
|
209 full)))
|
|
210
|
|
211 (defun vc-do-command (okstatus command file last &rest flags)
|
|
212 "Execute a version-control command, notifying user and checking for errors.
|
|
213 The command is successful if its exit status does not exceed OKSTATUS.
|
|
214 Output from COMMAND goes to buffer *vc*. The last argument of the command is
|
|
215 the master name of FILE if LAST is 'MASTER, or the workfile of FILE if LAST is
|
|
216 'WORKFILE; this is appended to an optional list of FLAGS."
|
|
217 (setq file (expand-file-name file))
|
|
218 (let ((camefrom (current-buffer))
|
|
219 (pwd (file-name-directory (expand-file-name file)))
|
|
220 (squeezed nil)
|
|
221 (vc-file (and file (vc-name file)))
|
|
222 status)
|
|
223 ;;; #### - don't know why this code was here...to beautify the echo message?
|
|
224 ;;; the version of code below doesn't break default-directory, but it
|
|
225 ;;; still might mess up CVS and RCS because they like to operate on
|
|
226 ;;; files in the current directory. --Stig
|
|
227 ;;;
|
|
228 ;;; (if (string-match (concat "^" (regexp-quote pwd)) file)
|
|
229 ;;; (setq file (substring file (match-end 0)))
|
|
230 ;;; (setq pwd (file-name-directory file)))
|
|
231 (if vc-command-messages
|
|
232 (message "Running %s on %s..." command file))
|
|
233 (set-buffer (get-buffer-create "*vc*"))
|
|
234 (setq default-directory pwd
|
|
235 file (file-name-nondirectory file))
|
|
236
|
|
237 (set (make-local-variable 'vc-parent-buffer) camefrom)
|
|
238 (set (make-local-variable 'vc-parent-buffer-name)
|
|
239 (concat " from " (buffer-name camefrom)))
|
|
240
|
|
241 (erase-buffer)
|
|
242
|
|
243 (mapcar
|
|
244 (function (lambda (s) (and s (setq squeezed (append squeezed (list s))))))
|
|
245 flags)
|
|
246 (if (and vc-file (eq last 'MASTER))
|
|
247 (setq squeezed (append squeezed (list vc-file))))
|
|
248 (if (eq last 'WORKFILE)
|
|
249 (setq squeezed (append squeezed (list file))))
|
|
250 (let ((exec-path (if vc-path (append vc-path exec-path) exec-path))
|
|
251 ;; Add vc-path to PATH for the execution of this command.
|
|
252 (process-environment (copy-sequence process-environment)))
|
|
253 (setenv "PATH" (mapconcat 'identity exec-path ":"))
|
|
254 (setq status (apply 'call-process command nil t nil squeezed)))
|
|
255 (goto-char (point-max))
|
|
256 (set-buffer-modified-p nil) ; XEmacs - fsf uses `not-modified'
|
|
257 (forward-line -1)
|
|
258 (if (or (not (integerp status)) (< okstatus status))
|
|
259 (progn
|
|
260 (pop-to-buffer "*vc*")
|
|
261 (goto-char (point-min))
|
|
262 (shrink-window-if-larger-than-buffer)
|
|
263 (error "Running %s...FAILED (%s)" command
|
|
264 (if (integerp status)
|
|
265 (format "status %d" status)
|
|
266 status))
|
|
267 )
|
|
268 (if vc-command-messages
|
|
269 (message "Running %s...OK" command))
|
|
270 )
|
|
271 (set-buffer camefrom)
|
|
272 status)
|
|
273 )
|
|
274
|
|
275 ;;; Save a bit of the text around POSN in the current buffer, to help
|
|
276 ;;; us find the corresponding position again later. This works even
|
|
277 ;;; if all markers are destroyed or corrupted.
|
|
278 (defun vc-position-context (posn)
|
|
279 (list posn
|
|
280 (buffer-size)
|
|
281 (buffer-substring posn
|
|
282 (min (point-max) (+ posn 100)))))
|
|
283
|
|
284 ;;; Return the position of CONTEXT in the current buffer, or nil if we
|
|
285 ;;; couldn't find it.
|
|
286 (defun vc-find-position-by-context (context)
|
|
287 (let ((context-string (nth 2 context)))
|
|
288 (if (equal "" context-string)
|
|
289 (point-max)
|
|
290 (save-excursion
|
|
291 (let ((diff (- (nth 1 context) (buffer-size))))
|
|
292 (if (< diff 0) (setq diff (- diff)))
|
|
293 (goto-char (nth 0 context))
|
|
294 (if (or (search-forward context-string nil t)
|
|
295 ;; Can't use search-backward since the match may continue
|
|
296 ;; after point.
|
|
297 (progn (goto-char (- (point) diff (length context-string)))
|
|
298 ;; goto-char doesn't signal an error at
|
|
299 ;; beginning of buffer like backward-char would
|
|
300 (search-forward context-string nil t)))
|
|
301 ;; to beginning of OSTRING
|
|
302 (- (point) (length context-string))))))))
|
|
303
|
|
304 (defun vc-revert-buffer1 (&optional arg no-confirm)
|
|
305 ;; Most of this was shamelessly lifted from Sebastian Kremer's rcs.el mode.
|
|
306 ;; Revert buffer, try to keep point and mark where user expects them in spite
|
|
307 ;; of changes because of expanded version-control key words.
|
|
308 ;; This is quite important since otherwise typeahead won't work as expected.
|
|
309 (interactive "P")
|
|
310 (widen)
|
|
311 (let ((point-context (vc-position-context (point)))
|
|
312 ;; Use mark-marker to avoid confusion in transient-mark-mode.
|
|
313 ;; XEmacs - mark-marker t
|
|
314 (mark-context (if (eq (marker-buffer (mark-marker t)) (current-buffer))
|
|
315 (vc-position-context (mark-marker t))))
|
|
316 ;; We may want to reparse the compilation buffer after revert
|
|
317 (reparse (and (boundp 'compilation-error-list) ;compile loaded
|
|
318 ;; Construct a list; each elt is nil or a buffer
|
|
319 ;; iff that buffer is a compilation output buffer
|
|
320 ;; that contains markers into the current buffer.
|
|
321 (save-excursion
|
|
322 (mapcar (function
|
|
323 (lambda (buffer)
|
|
324 (set-buffer buffer)
|
|
325 (let ((errors (or
|
|
326 compilation-old-error-list
|
|
327 compilation-error-list))
|
|
328 (buffer-error-marked-p nil))
|
|
329 (while (and (consp errors)
|
|
330 (not buffer-error-marked-p))
|
|
331 (and (markerp (cdr (car errors)))
|
|
332 (eq buffer
|
|
333 (marker-buffer
|
|
334 (cdr (car errors))))
|
|
335 (setq buffer-error-marked-p t))
|
|
336 (setq errors (cdr errors)))
|
|
337 (if buffer-error-marked-p buffer))))
|
|
338 (buffer-list))))))
|
|
339
|
|
340 ;; The FSF version intentionally runs font-lock here. That
|
|
341 ;; usually just leads to a correctly font-locked buffer being
|
|
342 ;; redone. #### We should detect the cases where the font-locking
|
|
343 ;; may be incorrect (such as on reverts). We know that it is fine
|
|
344 ;; during regular checkin and checkouts.
|
|
345
|
|
346 ;; the actual revisit
|
|
347 (revert-buffer arg no-confirm)
|
|
348
|
|
349 ;; Reparse affected compilation buffers.
|
|
350 (while reparse
|
|
351 (if (car reparse)
|
|
352 (save-excursion
|
|
353 (set-buffer (car reparse))
|
|
354 (let ((compilation-last-buffer (current-buffer)) ;select buffer
|
|
355 ;; Record the position in the compilation buffer of
|
|
356 ;; the last error next-error went to.
|
|
357 (error-pos (marker-position
|
|
358 (car (car-safe compilation-error-list)))))
|
|
359 ;; Reparse the error messages as far as they were parsed before.
|
|
360 (compile-reinitialize-errors '(4) compilation-parsing-end)
|
|
361 ;; Move the pointer up to find the error we were at before
|
|
362 ;; reparsing. Now next-error should properly go to the next one.
|
|
363 (while (and compilation-error-list
|
|
364 (/= error-pos (car (car compilation-error-list))))
|
|
365 (setq compilation-error-list (cdr compilation-error-list))))))
|
|
366 (setq reparse (cdr reparse)))
|
|
367
|
|
368 ;; Restore point and mark
|
|
369 (let ((new-point (vc-find-position-by-context point-context)))
|
|
370 (if new-point (goto-char new-point)))
|
|
371 (if mark-context
|
|
372 (let ((new-mark (vc-find-position-by-context mark-context)))
|
|
373 (if new-mark (set-mark new-mark))))))
|
|
374
|
|
375
|
|
376 (defun vc-buffer-sync (&optional not-urgent)
|
|
377 ;; Make sure the current buffer and its working file are in sync
|
|
378 ;; NOT-URGENT means it is ok to continue if the user says not to save.
|
|
379 (if (buffer-modified-p)
|
|
380 (if (or vc-suppress-confirm
|
|
381 (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name))))
|
|
382 (save-buffer)
|
|
383 (if not-urgent
|
|
384 nil
|
|
385 (error "Aborted")))))
|
|
386
|
|
387 ;;;###autoload
|
|
388 (defun vc-file-status ()
|
|
389 "Display the current status of the file being visited.
|
|
390 Currently, this is only defined for CVS. The information provided in the
|
|
391 modeline is generally sufficient for RCS and SCCS."
|
|
392 ;; by Stig@hackvan.com
|
|
393 (interactive)
|
|
394 (vc-buffer-sync t)
|
|
395 (let ((type (vc-backend-deduce buffer-file-name))
|
|
396 (file buffer-file-name))
|
|
397 (cond ((null type)
|
|
398 (if buffer-file-name
|
|
399 (message "`%s' is not registered with a version control system."
|
|
400 buffer-file-name)
|
|
401 (ding)
|
|
402 (message "Buffer `%s' has no associated file."
|
|
403 (buffer-name (current-buffer)))))
|
|
404 ((eq 'CVS type)
|
|
405 (vc-do-command 0 "cvs" file 'WORKFILE "status" "-v")
|
|
406 (set-buffer "*vc*")
|
|
407 (set-buffer-modified-p nil)
|
|
408 ;; reparse the status information, since we have it handy...
|
|
409 (vc-parse-buffer '("Status: \\(.*\\)") file '(vc-cvs-status))
|
|
410 (goto-char (point-min))
|
|
411 (shrink-window-if-larger-than-buffer
|
|
412 (display-buffer (current-buffer))))
|
|
413 ((eq 'CC type)
|
|
414 (vc-do-command 0 "cleartool" file 'WORKFILE "describe")
|
|
415 (set-buffer "*vc*")
|
|
416 (set-buffer-modified-p nil)
|
|
417 (goto-char (point-min))
|
|
418 (shrink-window-if-larger-than-buffer
|
|
419 (display-buffer (current-buffer))))
|
|
420 (t
|
|
421 (ding)
|
|
422 (message "Operation not yet defined for RCS or SCCS.")))
|
|
423 ))
|
|
424
|
|
425 (defun vc-workfile-unchanged-p (file &optional want-differences-if-changed)
|
|
426 ;; Has the given workfile changed since last checkout?
|
|
427 (cond ((and (eq 'CVS (vc-backend-deduce file))
|
|
428 (not want-differences-if-changed))
|
|
429
|
|
430 (let ((status (vc-file-getprop file 'vc-cvs-status)))
|
|
431 ;; #### - should this have some kind of timeout? how often does
|
|
432 ;; this get called? possibly the cached information should be
|
|
433 ;; flushed out of hand. The only concern is the VC menu, which
|
|
434 ;; may indirectly call this function.
|
|
435 (or status ; #### - caching is error-prone
|
|
436 (setq status (car (vc-log-info "cvs" file 'WORKFILE '("status")
|
|
437 '("Status: \\(.*\\)")
|
|
438 '(vc-cvs-status)))))
|
|
439 (string= status "Up-to-date")))
|
|
440 (t
|
|
441 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time))
|
|
442 (lastmod (nth 5 (file-attributes file)))
|
|
443 unchanged)
|
|
444 (or (equal checkout-time lastmod)
|
|
445 (and (or (not checkout-time) want-differences-if-changed)
|
|
446 (setq unchanged
|
|
447 (zerop (vc-backend-diff file nil nil
|
|
448 (not want-differences-if-changed))))
|
|
449 ;; 0 stands for an unknown time; it can't match any mod time.
|
|
450 (vc-file-setprop file 'vc-checkout-time (if unchanged lastmod 0))
|
|
451 unchanged))))))
|
|
452
|
|
453 (defun vc-next-action-on-file (file verbose &optional comment)
|
|
454 ;;; If comment is specified, it will be used as an admin or checkin comment.
|
|
455 (let ((vc-file (vc-name file))
|
|
456 (vc-type (vc-backend-deduce file))
|
|
457 owner version)
|
|
458 (cond
|
|
459
|
|
460 ;; if there is no master file corresponding, create one
|
|
461 ((not vc-file)
|
|
462 (vc-register verbose comment))
|
|
463
|
|
464 ;; if there is no lock on the file, assert one and get it
|
|
465 ((and (not (eq vc-type 'CVS)) ;There are no locks in CVS.
|
|
466 (not (setq owner (vc-locking-user file))))
|
|
467 (if (and vc-checkout-carefully
|
|
468 (not (vc-workfile-unchanged-p file t)))
|
|
469 (if (save-window-excursion
|
|
470 (pop-to-buffer "*vc*")
|
|
471 (goto-char (point-min))
|
|
472 (insert (format "Changes to %s since last lock:\n\n" file))
|
|
473 (not (beep))
|
|
474 (yes-or-no-p
|
|
475 "File has unlocked changes, claim lock retaining changes? "))
|
|
476 (progn (vc-backend-steal file)
|
|
477 (vc-mode-line file))
|
|
478 (if (not (yes-or-no-p "Revert to checked-in version, instead? "))
|
|
479 (error "Checkout aborted.")
|
|
480 (vc-revert-buffer1 t t)
|
|
481 (vc-checkout-writable-buffer file))
|
|
482 )
|
|
483 (vc-checkout-writable-buffer file)))
|
|
484
|
|
485 ;; a checked-out version exists, but the user may not own the lock
|
|
486 ((and (not (eq vc-type 'CVS)) ;There are no locks in CVS.
|
|
487 (not (string-equal owner (user-login-name))))
|
|
488 (if comment
|
|
489 (error "Sorry, you can't steal the lock on %s this way" file))
|
|
490 (vc-steal-lock
|
|
491 file
|
|
492 (and verbose (read-string "Version to steal: "))
|
|
493 owner))
|
|
494
|
|
495 ;; changes to the master file needs to be merged back into the
|
|
496 ;; working file
|
|
497 ((and (eq vc-type 'CVS)
|
|
498 ;; "0" means "added, but not yet committed"
|
|
499 (not (string= (vc-file-getprop file 'vc-your-latest-version) "0"))
|
|
500 (progn
|
|
501 (vc-fetch-properties file)
|
|
502 (not (string= (vc-file-getprop file 'vc-your-latest-version)
|
|
503 (vc-file-getprop file 'vc-latest-version)))))
|
|
504 (vc-buffer-sync)
|
|
505 (if (yes-or-no-p (format "%s is not up-to-date. Merge in changes now? "
|
|
506 (buffer-name)))
|
|
507 (progn
|
|
508 (if (and (buffer-modified-p)
|
|
509 (not (yes-or-no-p
|
|
510 (format
|
|
511 "Buffer %s modified; merge file on disc anyhow? "
|
|
512 (buffer-name)))))
|
|
513 (error "Merge aborted"))
|
|
514 (if (not (zerop (vc-backend-merge-news file)))
|
|
515 ;; Overlaps detected - what now? Should use some
|
|
516 ;; fancy RCS conflict resolving package, or maybe
|
|
517 ;; emerge, but for now, simply warn the user with a
|
|
518 ;; message.
|
|
519 (message "Conflicts detected!"))
|
|
520 (vc-resynch-window file t (not (buffer-modified-p))))
|
|
521
|
|
522 (error "%s needs update" (buffer-name))))
|
|
523
|
|
524 ((and buffer-read-only (eq vc-type 'CVS))
|
|
525 (toggle-read-only)
|
|
526 ;; Sites who make link farms to a read-only gold tree (or
|
|
527 ;; something similar) can use the hook below to break the
|
|
528 ;; sym-link.
|
|
529 (run-hooks 'vc-make-buffer-writable-hook))
|
|
530
|
|
531 ;; OK, user owns the lock on the file (or we are running CVS)
|
|
532 (t
|
|
533 (find-file file)
|
|
534
|
|
535 ;; give luser a chance to save before checking in.
|
|
536 (vc-buffer-sync)
|
|
537
|
|
538 ;; Revert if file is unchanged and buffer is too.
|
|
539 ;; If buffer is modified, that means the user just said no
|
|
540 ;; to saving it; in that case, don't revert,
|
|
541 ;; because the user might intend to save
|
|
542 ;; after finishing the log entry.
|
|
543 (if (and (vc-workfile-unchanged-p file)
|
|
544 (not (buffer-modified-p)))
|
|
545 (progn
|
|
546 (if (eq vc-type 'CVS)
|
|
547 (message "No changes to %s" file)
|
|
548
|
|
549 (vc-backend-revert file)
|
|
550 ;; DO NOT revert the file without asking the user!
|
|
551 (vc-resynch-window file t nil)))
|
|
552
|
|
553 ;; user may want to set nonstandard parameters
|
|
554 (if verbose
|
|
555 (setq version (read-string "New version level: ")))
|
|
556
|
|
557 ;; OK, let's do the checkin
|
|
558 (vc-checkin file version comment)
|
|
559 )))))
|
|
560
|
|
561 (defun vc-next-action-dired (file rev comment)
|
|
562 ;; We've accepted a log comment, now do a vc-next-action using it on all
|
|
563 ;; marked files.
|
|
564 (set-buffer vc-parent-buffer)
|
|
565 (dired-map-over-marks
|
|
566 (save-window-excursion
|
|
567 (let ((file (dired-get-filename)))
|
|
568 (message "Processing %s..." file)
|
|
569 (vc-next-action-on-file file nil comment)
|
|
570 (message "Processing %s...done" file)))
|
|
571 nil t)
|
|
572 )
|
|
573
|
|
574 ;; Here's the major entry point.
|
|
575
|
|
576 ;;;###autoload
|
|
577 (defun vc-next-action (verbose)
|
|
578 "Do the next logical checkin or checkout operation on the current file.
|
|
579
|
|
580 For RCS and SCCS files:
|
|
581 If the file is not already registered, this registers it for version
|
|
582 control and then retrieves a writable, locked copy for editing.
|
|
583 If the file is registered and not locked by anyone, this checks out
|
|
584 a writable and locked file ready for editing.
|
|
585 If the file is checked out and locked by the calling user, this
|
|
586 first checks to see if the file has changed since checkout. If not,
|
|
587 it performs a revert.
|
|
588 If the file has been changed, this pops up a buffer for entry
|
|
589 of a log message; when the message has been entered, it checks in the
|
|
590 resulting changes along with the log message as change commentary. If
|
|
591 the variable `vc-keep-workfiles' is non-nil (which is its default), a
|
|
592 read-only copy of the changed file is left in place afterwards.
|
|
593 If the file is registered and locked by someone else, you are given
|
|
594 the option to steal the lock.
|
|
595
|
|
596 For CVS files:
|
|
597 If the file is not already registered, this registers it for version
|
|
598 control. This does a \"cvs add\", but no \"cvs commit\".
|
|
599 If the file is added but not committed, it is committed.
|
|
600 If the file has not been changed, neither in your working area or
|
|
601 in the repository, a message is printed and nothing is done.
|
|
602 If your working file is changed, but the repository file is
|
|
603 unchanged, this pops up a buffer for entry of a log message; when the
|
|
604 message has been entered, it checks in the resulting changes along
|
|
605 with the logmessage as change commentary. A writable file is retained.
|
|
606 If the repository file is changed, you are asked if you want to
|
|
607 merge in the changes into your working copy.
|
|
608
|
|
609 The following is true regardless of which version control system you
|
|
610 are using:
|
|
611
|
|
612 If you call this from within a VC dired buffer with no files marked,
|
|
613 it will operate on the file in the current line.
|
|
614 If you call this from within a VC dired buffer, and one or more
|
|
615 files are marked, it will accept a log message and then operate on
|
|
616 each one. The log message will be used as a comment for any register
|
|
617 or checkin operations, but ignored when doing checkouts. Attempted
|
|
618 lock steals will raise an error.
|
|
619
|
|
620 For checkin, a prefix argument lets you specify the version number to use."
|
|
621 (interactive "P")
|
|
622 (catch 'nogo
|
|
623 (if vc-dired-mode
|
|
624 (let ((files (dired-get-marked-files)))
|
|
625 (if (= (length files) 1)
|
|
626 (find-file-other-window (car files))
|
|
627 (vc-start-entry nil nil nil
|
|
628 "Enter a change comment for the marked files."
|
|
629 'vc-next-action-dired)
|
|
630 (throw 'nogo nil))))
|
|
631 (while vc-parent-buffer
|
|
632 (pop-to-buffer vc-parent-buffer))
|
|
633 (if buffer-file-name
|
|
634 (vc-next-action-on-file buffer-file-name verbose)
|
|
635 (vc-registration-error nil))))
|
|
636
|
|
637 ;;; These functions help the vc-next-action entry point
|
|
638
|
|
639 (defun vc-checkout-writable-buffer (&optional file)
|
|
640 "Retrieve a writable copy of the latest version of the current buffer's file."
|
|
641 (vc-checkout (or file (buffer-file-name)) t)
|
|
642 )
|
|
643
|
|
644 ;;;###autoload
|
|
645 (defun vc-register (&optional override comment)
|
|
646 "Register the current file into your version-control system."
|
|
647 (interactive "P")
|
|
648 (let ((master (vc-name buffer-file-name)))
|
|
649 (and master (file-exists-p master)
|
|
650 (error "This file is already registered"))
|
|
651 (and master
|
|
652 (not (y-or-n-p "Previous master file has vanished. Make a new one? "))
|
|
653 (error "This file is already registered")))
|
|
654 ;; Watch out for new buffers of size 0: the corresponding file
|
|
655 ;; does not exist yet, even though buffer-modified-p is nil.
|
|
656 (if (and (not (buffer-modified-p))
|
|
657 (zerop (buffer-size))
|
|
658 (not (file-exists-p buffer-file-name)))
|
|
659 (set-buffer-modified-p t))
|
|
660 (vc-buffer-sync)
|
|
661 (vc-admin
|
|
662 buffer-file-name
|
|
663 (and override
|
|
664 (read-string
|
|
665 (format "Initial version level for %s: " buffer-file-name))))
|
|
666 )
|
|
667
|
|
668 (defun vc-resynch-window (file &optional keep noquery)
|
|
669 ;; If the given file is in the current buffer,
|
|
670 ;; either revert on it so we see expanded keyworks,
|
|
671 ;; or unvisit it (depending on vc-keep-workfiles)
|
|
672 ;; NOQUERY if non-nil inhibits confirmation for reverting.
|
|
673 ;; NOQUERY should be t *only* if it is known the only difference
|
|
674 ;; between the buffer and the file is due to RCS rather than user editing!
|
|
675 (and (string= buffer-file-name file)
|
|
676 (if keep
|
|
677 (progn
|
|
678 (vc-revert-buffer1 t noquery)
|
|
679 (vc-mode-line buffer-file-name))
|
|
680 (progn
|
|
681 (delete-window)
|
|
682 (kill-buffer (current-buffer))))))
|
|
683
|
70
|
684 (defun vc-start-entry (file rev comment msg action &optional after-hook)
|
0
|
685 ;; Accept a comment for an operation on FILE revision REV. If COMMENT
|
|
686 ;; is nil, pop up a VC-log buffer, emit MSG, and set the
|
|
687 ;; action on close to ACTION; otherwise, do action immediately.
|
|
688 ;; Remember the file's buffer in vc-parent-buffer (current one if no file).
|
|
689 ;; AFTER-HOOK specifies the local value for vc-log-operation-hook.
|
|
690 (let ((parent (if file (find-file-noselect file) (current-buffer))))
|
|
691 (if comment
|
|
692 (set-buffer (get-buffer-create "*VC-log*"))
|
|
693 (pop-to-buffer (get-buffer-create "*VC-log*")))
|
|
694 (set (make-local-variable 'vc-parent-buffer) parent)
|
|
695 (set (make-local-variable 'vc-parent-buffer-name)
|
|
696 (concat " from " (buffer-name vc-parent-buffer)))
|
|
697 (vc-mode-line (or file " (no file)"))
|
|
698 (vc-log-mode)
|
|
699 (make-local-variable 'vc-log-after-operation-hook)
|
|
700 (if after-hook
|
|
701 (setq vc-log-after-operation-hook after-hook))
|
|
702 (setq vc-log-operation action)
|
|
703 (setq vc-log-file file)
|
|
704 (setq vc-log-version rev)
|
|
705 (if comment
|
|
706 (progn
|
|
707 (erase-buffer)
|
|
708 (if (eq comment t)
|
|
709 (vc-finish-logentry t)
|
|
710 (insert comment)
|
|
711 (vc-finish-logentry nil)))
|
|
712 (message "%s Type C-c C-c when done." msg))))
|
|
713
|
|
714 (defun vc-admin (file rev &optional comment)
|
|
715 "Check a file into your version-control system.
|
|
716 FILE is the unmodified name of the file. REV should be the base version
|
|
717 level to check it in under. COMMENT, if specified, is the checkin comment."
|
|
718 (vc-start-entry file rev
|
|
719 (or comment (not vc-initial-comment))
|
|
720 "Enter initial comment." 'vc-backend-admin
|
70
|
721 nil))
|
0
|
722
|
|
723 (defun vc-checkout (file &optional writable)
|
|
724 "Retrieve a copy of the latest version of the given file."
|
|
725 ;; XEmacs - ftp is suppressed by the check for a filename handler in
|
|
726 ;; vc-registered, so this is needless surplussage
|
|
727 ;; If ftp is on this system and the name matches the ange-ftp format
|
|
728 ;; for a remote file, the user is trying something that won't work.
|
|
729 ;; (if (and (string-match "^/[^/:]+:" file) (vc-find-binary "ftp"))
|
|
730 ;; (error "Sorry, you can't check out files over FTP"))
|
|
731 (vc-backend-checkout file writable)
|
|
732 (if (string-equal file buffer-file-name)
|
|
733 (vc-resynch-window file t t))
|
|
734 )
|
|
735
|
|
736 (defun vc-steal-lock (file rev &optional owner)
|
|
737 "Steal the lock on the current workfile."
|
|
738 (let (file-description)
|
|
739 (if (not owner)
|
|
740 (setq owner (vc-locking-user file)))
|
|
741 (if rev
|
|
742 (setq file-description (format "%s:%s" file rev))
|
|
743 (setq file-description file))
|
|
744 (if (not (y-or-n-p (format "Take the lock on %s from %s? "
|
|
745 file-description owner)))
|
|
746 (error "Steal cancelled"))
|
|
747 (pop-to-buffer (get-buffer-create "*VC-mail*"))
|
|
748 (setq default-directory (expand-file-name "~/"))
|
|
749 (auto-save-mode auto-save-default)
|
|
750 (mail-mode)
|
|
751 (erase-buffer)
|
|
752 (mail-setup owner (format "Stolen lock on %s" file-description) nil nil nil
|
|
753 (list (list 'vc-finish-steal file rev)))
|
|
754 (goto-char (point-max))
|
|
755 (insert
|
|
756 (format "I stole the lock on %s, " file-description)
|
|
757 (current-time-string)
|
|
758 ".\n")
|
|
759 (message "Please explain why you stole the lock. Type C-c C-c when done.")))
|
|
760
|
|
761 ;; This is called when the notification has been sent.
|
|
762 (defun vc-finish-steal (file version)
|
|
763 (vc-backend-steal file version)
|
|
764 (if (get-file-buffer file)
|
|
765 (save-excursion
|
|
766 (set-buffer (get-file-buffer file))
|
|
767 (vc-resynch-window file t t))))
|
|
768
|
|
769 (defun vc-checkin (file &optional rev comment)
|
|
770 "Check in the file specified by FILE.
|
|
771 The optional argument REV may be a string specifying the new version level
|
|
772 \(if nil increment the current level). The file is either retained with write
|
|
773 permissions zeroed, or deleted (according to the value of `vc-keep-workfiles').
|
|
774 If the back-end is CVS, a writable workfile is always kept.
|
|
775 COMMENT is a comment string; if omitted, a buffer is
|
|
776 popped up to accept a comment."
|
|
777 (vc-start-entry file rev comment
|
|
778 "Enter a change comment." 'vc-backend-checkin
|
70
|
779 'vc-checkin-hook))
|
0
|
780
|
|
781 ;;; Here is a checkin hook that may prove useful to sites using the
|
|
782 ;;; ChangeLog facility supported by Emacs.
|
|
783 (defun vc-comment-to-change-log (&optional whoami file-name)
|
|
784 "Enter last VC comment into change log file for current buffer's file.
|
|
785 Optional arg (interactive prefix) non-nil means prompt for user name and site.
|
|
786 Second arg is file name of change log. \
|
|
787 If nil, uses `change-log-default-name'."
|
|
788 (interactive (if current-prefix-arg
|
|
789 (list current-prefix-arg
|
|
790 (prompt-for-change-log-name))))
|
|
791 ;; Make sure the defvar for add-log-current-defun-function has been executed
|
|
792 ;; before binding it.
|
|
793 (require 'add-log)
|
|
794 (let ( ; Extract the comment first so we get any error before doing anything.
|
|
795 (comment (ring-ref vc-comment-ring 0))
|
|
796 ;; Don't let add-change-log-entry insert a defun name.
|
|
797 (add-log-current-defun-function 'ignore)
|
|
798 end)
|
|
799 ;; Call add-log to do half the work.
|
|
800 (add-change-log-entry whoami file-name t t)
|
|
801 ;; Insert the VC comment, leaving point before it.
|
|
802 (setq end (save-excursion (insert comment) (point-marker)))
|
|
803 (if (looking-at "\\s *\\s(")
|
|
804 ;; It starts with an open-paren, as in "(foo): Frobbed."
|
|
805 ;; So remove the ": " add-log inserted.
|
|
806 (delete-char -2))
|
|
807 ;; Canonicalize the white space between the file name and comment.
|
|
808 (just-one-space)
|
|
809 ;; Indent rest of the text the same way add-log indented the first line.
|
|
810 (let ((indentation (current-indentation)))
|
|
811 (save-excursion
|
|
812 (while (< (point) end)
|
|
813 (forward-line 1)
|
|
814 (indent-to indentation))
|
|
815 (setq end (point))))
|
|
816 ;; Fill the inserted text, preserving open-parens at bol.
|
|
817 (let ((paragraph-separate (concat paragraph-separate "\\|^\\s *\\s("))
|
|
818 (paragraph-start (concat paragraph-start "\\|^\\s *\\s(")))
|
|
819 (beginning-of-line)
|
|
820 (fill-region (point) end))
|
|
821 ;; Canonicalize the white space at the end of the entry so it is
|
|
822 ;; separated from the next entry by a single blank line.
|
|
823 (skip-syntax-forward " " end)
|
|
824 (delete-char (- (skip-syntax-backward " ")))
|
|
825 (or (eobp) (looking-at "\n\n")
|
|
826 (insert "\n"))))
|
|
827
|
|
828
|
|
829 (defun vc-finish-logentry (&optional nocomment)
|
|
830 "Complete the operation implied by the current log entry."
|
|
831 (interactive)
|
|
832 ;; Check and record the comment, if any.
|
|
833 (if (not nocomment)
|
|
834 (progn
|
|
835 (goto-char (point-max))
|
|
836 (if (not (bolp))
|
|
837 (newline))
|
|
838 ;; Comment too long?
|
|
839 (vc-backend-logentry-check vc-log-file)
|
|
840 ;; Record the comment in the comment ring
|
|
841 (if (null vc-comment-ring)
|
|
842 (setq vc-comment-ring (make-ring vc-maximum-comment-ring-size)))
|
|
843 (ring-insert vc-comment-ring (buffer-string))
|
|
844 ))
|
|
845 ;; Sync parent buffer in case the user modified it while editing the comment.
|
|
846 ;; But not if it is a vc-dired buffer.
|
|
847 (save-excursion
|
|
848 (set-buffer vc-parent-buffer)
|
|
849 (or vc-dired-mode
|
|
850 (vc-buffer-sync)))
|
|
851 ;; OK, do it to it
|
|
852 (if vc-log-operation
|
|
853 (save-excursion
|
|
854 (funcall vc-log-operation
|
|
855 vc-log-file
|
|
856 vc-log-version
|
|
857 (buffer-string)))
|
|
858 (error "No log operation is pending"))
|
|
859 ;; save the vc-log-after-operation-hook of log buffer
|
|
860 (let ((after-hook vc-log-after-operation-hook))
|
|
861 ;; Return to "parent" buffer of this checkin and remove checkin window
|
|
862 (pop-to-buffer vc-parent-buffer)
|
|
863 (let ((logbuf (get-buffer "*VC-log*")))
|
|
864 (delete-windows-on logbuf)
|
|
865 (kill-buffer logbuf))
|
|
866 ;; Now make sure we see the expanded headers
|
|
867 (if buffer-file-name
|
|
868 (vc-resynch-window buffer-file-name vc-keep-workfiles t))
|
|
869 (run-hooks after-hook)))
|
|
870
|
|
871 ;; Code for access to the comment ring
|
|
872
|
|
873 (defun vc-previous-comment (arg)
|
|
874 "Cycle backwards through comment history."
|
|
875 (interactive "*p")
|
|
876 (let ((len (ring-length vc-comment-ring)))
|
|
877 (cond ((or (not len) (<= len 0)) ; XEmacs change from Barry Warsaw
|
|
878 (message "Empty comment ring")
|
|
879 (ding))
|
|
880 (t
|
|
881 (erase-buffer)
|
|
882 ;; Initialize the index on the first use of this command
|
|
883 ;; so that the first M-p gets index 0, and the first M-n gets
|
|
884 ;; index -1.
|
|
885 (if (null vc-comment-ring-index)
|
|
886 (setq vc-comment-ring-index
|
|
887 (if (> arg 0) -1
|
|
888 (if (< arg 0) 1 0))))
|
|
889 (setq vc-comment-ring-index
|
|
890 (mod (+ vc-comment-ring-index arg) len))
|
|
891 (message "%d" (1+ vc-comment-ring-index))
|
|
892 (insert (ring-ref vc-comment-ring vc-comment-ring-index))))))
|
|
893
|
|
894 (defun vc-next-comment (arg)
|
|
895 "Cycle forwards through comment history."
|
|
896 (interactive "*p")
|
|
897 (vc-previous-comment (- arg)))
|
|
898
|
|
899 (defun vc-comment-search-reverse (str)
|
|
900 "Searches backwards through comment history for substring match."
|
|
901 (interactive "sComment substring: ")
|
|
902 (if (string= str "")
|
|
903 (setq str vc-last-comment-match)
|
|
904 (setq vc-last-comment-match str))
|
|
905 (if (null vc-comment-ring-index)
|
|
906 (setq vc-comment-ring-index -1))
|
|
907 (let ((str (regexp-quote str))
|
|
908 (len (ring-length vc-comment-ring))
|
|
909 (n (1+ vc-comment-ring-index)))
|
|
910 (while (and (< n len) (not (string-match str (ring-ref vc-comment-ring n))))
|
|
911 (setq n (+ n 1)))
|
|
912 (cond ((< n len)
|
|
913 (vc-previous-comment (- n vc-comment-ring-index)))
|
|
914 (t (error "Not found")))))
|
|
915
|
|
916 (defun vc-comment-search-forward (str)
|
|
917 "Searches forwards through comment history for substring match."
|
|
918 (interactive "sComment substring: ")
|
|
919 (if (string= str "")
|
|
920 (setq str vc-last-comment-match)
|
|
921 (setq vc-last-comment-match str))
|
|
922 (if (null vc-comment-ring-index)
|
|
923 (setq vc-comment-ring-index 0))
|
|
924 (let ((str (regexp-quote str))
|
|
925 (n vc-comment-ring-index))
|
|
926 (while (and (>= n 0) (not (string-match str (ring-ref vc-comment-ring n))))
|
|
927 (setq n (- n 1)))
|
|
928 (cond ((>= n 0)
|
|
929 (vc-next-comment (- n vc-comment-ring-index)))
|
|
930 (t (error "Not found")))))
|
|
931
|
|
932 ;; Additional entry points for examining version histories
|
|
933
|
|
934 ;;;###autoload
|
|
935 (defun vc-diff (historic &optional not-urgent)
|
|
936 "Display diffs between file versions.
|
|
937 Normally this compares the current file and buffer with the most recent
|
|
938 checked in version of that file. This uses no arguments.
|
|
939 With a prefix argument, it reads the file name to use
|
|
940 and two version designators specifying which versions to compare."
|
|
941 (interactive "P")
|
|
942 (if vc-dired-mode
|
|
943 (set-buffer (find-file-noselect (dired-get-filename))))
|
|
944 (while vc-parent-buffer
|
|
945 (pop-to-buffer vc-parent-buffer))
|
|
946 (if historic
|
|
947 (call-interactively 'vc-version-diff)
|
|
948 (if (or (null buffer-file-name) (null (vc-name buffer-file-name)))
|
|
949 (error
|
|
950 "There is no version-control master associated with this buffer"))
|
|
951 (let ((file buffer-file-name)
|
|
952 unchanged)
|
|
953 (or (and file (vc-name file))
|
|
954 (vc-registration-error file))
|
|
955 (vc-buffer-sync not-urgent)
|
|
956 (setq unchanged (vc-workfile-unchanged-p buffer-file-name))
|
|
957 (if unchanged
|
|
958 (message "No changes to %s since latest version." file)
|
|
959 (vc-backend-diff file)
|
|
960 ;; Ideally, we'd like at this point to parse the diff so that
|
|
961 ;; the buffer effectively goes into compilation mode and we
|
|
962 ;; can visit the old and new change locations via next-error.
|
|
963 ;; Unfortunately, this is just too painful to do. The basic
|
|
964 ;; problem is that the `old' file doesn't exist to be
|
|
965 ;; visited. This plays hell with numerous assumptions in
|
|
966 ;; the diff.el and compile.el machinery.
|
|
967 (pop-to-buffer "*vc*")
|
|
968 (setq default-directory (file-name-directory file))
|
|
969 (if (= 0 (buffer-size))
|
|
970 (progn
|
|
971 (setq unchanged t)
|
|
972 (message "No changes to %s since latest version." file))
|
|
973 (goto-char (point-min))
|
|
974 (shrink-window-if-larger-than-buffer)))
|
|
975 (not unchanged))))
|
|
976
|
|
977 ;;;###autoload
|
|
978 (defun vc-version-diff (file rel1 rel2)
|
|
979 "For FILE, report diffs between two stored versions REL1 and REL2 of it.
|
|
980 If FILE is a directory, generate diffs between versions for all registered
|
|
981 files in or below it."
|
|
982 ;; XEmacs - better prompt
|
|
983 (interactive "FFile or directory to diff: \nsOlder version (default is repository): \nsNewer version (default is workfile): ")
|
|
984 (if (string-equal rel1 "") (setq rel1 nil))
|
|
985 (if (string-equal rel2 "") (setq rel2 nil))
|
|
986 (if (file-directory-p file)
|
|
987 (let ((camefrom (current-buffer)))
|
|
988 (set-buffer (get-buffer-create "*vc-status*"))
|
|
989 (set (make-local-variable 'vc-parent-buffer) camefrom)
|
|
990 (set (make-local-variable 'vc-parent-buffer-name)
|
|
991 (concat " from " (buffer-name camefrom)))
|
|
992 (erase-buffer)
|
|
993 (insert "Diffs between "
|
|
994 (or rel1 "last version checked in")
|
|
995 " and "
|
|
996 (or rel2 "current workfile(s)")
|
|
997 ":\n\n")
|
|
998 (set-buffer (get-buffer-create "*vc*"))
|
|
999 (cd file)
|
|
1000 (vc-file-tree-walk
|
|
1001 (function (lambda (f)
|
|
1002 (message "Looking at %s" f)
|
|
1003 (and
|
|
1004 (not (file-directory-p f))
|
|
1005 (vc-registered f)
|
|
1006 (vc-backend-diff f rel1 rel2)
|
|
1007 (append-to-buffer "*vc-status*" (point-min) (point-max)))
|
|
1008 )))
|
|
1009 (pop-to-buffer "*vc-status*")
|
|
1010 (insert "\nEnd of diffs.\n")
|
|
1011 (goto-char (point-min))
|
|
1012 (set-buffer-modified-p nil)
|
|
1013 )
|
|
1014 (if (zerop (vc-backend-diff file rel1 rel2))
|
|
1015 (message "No changes to %s between %s and %s." file rel1 rel2)
|
|
1016 (pop-to-buffer "*vc*"))))
|
|
1017
|
|
1018 ;;;###autoload
|
|
1019 (defun vc-version-other-window (rev)
|
|
1020 "Visit version REV of the current buffer in another window.
|
|
1021 If the current buffer is named `F', the version is named `F.~REV~'.
|
|
1022 If `F.~REV~' already exists, it is used instead of being re-created."
|
|
1023 (interactive "sVersion to visit (default is latest version): ")
|
|
1024 (if vc-dired-mode
|
|
1025 (set-buffer (find-file-noselect (dired-get-filename))))
|
|
1026 (while vc-parent-buffer
|
|
1027 (pop-to-buffer vc-parent-buffer))
|
|
1028 (if (and buffer-file-name (vc-name buffer-file-name))
|
|
1029 (let* ((version (if (string-equal rev "")
|
|
1030 (vc-latest-version buffer-file-name)
|
|
1031 rev))
|
|
1032 (filename (concat buffer-file-name ".~" version "~")))
|
|
1033 (or (file-exists-p filename)
|
|
1034 (vc-backend-checkout buffer-file-name nil version filename))
|
|
1035 (find-file-other-window filename))
|
|
1036 (vc-registration-error buffer-file-name)))
|
|
1037
|
|
1038 ;; Header-insertion code
|
|
1039
|
|
1040 ;;;###autoload
|
|
1041 (defun vc-insert-headers ()
|
|
1042 "Insert headers in a file for use with your version-control system.
|
|
1043 Headers desired are inserted at the start of the buffer, and are pulled from
|
|
1044 the variable `vc-header-alist'."
|
|
1045 (interactive)
|
|
1046 (if vc-dired-mode
|
|
1047 (find-file-other-window (dired-get-filename)))
|
|
1048 (while vc-parent-buffer
|
|
1049 (pop-to-buffer vc-parent-buffer))
|
|
1050 (save-excursion
|
|
1051 (save-restriction
|
|
1052 (widen)
|
|
1053 (if (or (not (vc-check-headers))
|
|
1054 (y-or-n-p "Version headers already exist. Insert another set? "))
|
|
1055 (progn
|
|
1056 (let* ((delims (cdr (assq major-mode vc-comment-alist)))
|
|
1057 (comment-start-vc (or (car delims) comment-start "#"))
|
|
1058 (comment-end-vc (or (car (cdr delims)) comment-end ""))
|
|
1059 (hdstrings (cdr (assoc (vc-backend-deduce buffer-file-name)
|
|
1060 vc-header-alist))))
|
|
1061 (mapcar #'(lambda (s)
|
|
1062 (insert comment-start-vc "\t" s "\t"
|
|
1063 comment-end-vc "\n"))
|
|
1064 hdstrings)
|
|
1065 (if vc-static-header-alist
|
|
1066 (mapcar #'(lambda (f)
|
|
1067 (if (and buffer-file-name
|
|
1068 (string-match (car f) buffer-file-name))
|
|
1069 (insert (format (cdr f) (car hdstrings)))))
|
|
1070 vc-static-header-alist))
|
|
1071 )
|
|
1072 )))))
|
|
1073
|
|
1074 ;; The VC directory submode. Coopt Dired for this.
|
|
1075 ;; All VC commands get mapped into logical equivalents.
|
|
1076
|
|
1077 ;; XEmacs
|
|
1078 (defvar vc-dired-prefix-map (let ((map (make-sparse-keymap)))
|
|
1079 (set-keymap-name map 'vc-dired-prefix-map)
|
|
1080 (define-key map "\C-xv" vc-prefix-map)
|
|
1081 map))
|
|
1082
|
|
1083 (or (not (boundp 'minor-mode-map-alist))
|
|
1084 (assq 'vc-dired-mode minor-mode-map-alist)
|
|
1085 (setq minor-mode-map-alist
|
|
1086 (cons (cons 'vc-dired-mode vc-dired-prefix-map)
|
|
1087 minor-mode-map-alist)))
|
|
1088
|
|
1089 (defun vc-dired-mode ()
|
|
1090 "The augmented Dired minor mode used in VC directory buffers.
|
|
1091 All Dired commands operate normally. Users currently locking listed files
|
|
1092 are listed in place of the file's owner and group.
|
|
1093 Keystrokes bound to VC commands will execute as though they had been called
|
|
1094 on a buffer attached to the file named in the current Dired buffer line."
|
|
1095 (setq vc-dired-mode t)
|
|
1096 (setq vc-mode " under VC"))
|
|
1097
|
|
1098 (defun vc-dired-reformat-line (x)
|
|
1099 ;; Hack a directory-listing line, plugging in locking-user info in
|
|
1100 ;; place of the user and group info. Should have the beneficial
|
|
1101 ;; side-effect of shortening the listing line. Each call starts with
|
|
1102 ;; point immediately following the dired mark area on the line to be
|
|
1103 ;; hacked.
|
|
1104 ;;
|
|
1105 ;; Simplest possible one:
|
|
1106 ;; (insert (concat x "\t")))
|
|
1107 ;;
|
|
1108 ;; This code, like dired, assumes UNIX -l format.
|
|
1109 (forward-word 1) ; skip over any extra field due to -ibs options
|
|
1110 (cond ((numberp x) ; This hack is used by the CVS code. See vc-locking-user.
|
|
1111 (cond
|
|
1112 ((re-search-forward "\\([0-9]+ \\)\\([^ ]+\\)\\( .*\\)" nil 0)
|
|
1113 (save-excursion
|
|
1114 (goto-char (match-beginning 2))
|
|
1115 (insert "(")
|
|
1116 (goto-char (1+ (match-end 2)))
|
|
1117 (insert ")")
|
|
1118 (delete-char (- 17 (- (match-end 2) (match-beginning 2))))
|
|
1119 (insert (substring " " 0
|
|
1120 (- 7 (- (match-end 2) (match-beginning 2)))))))))
|
|
1121 (t
|
|
1122 (if x (setq x (concat "(" x ")")))
|
|
1123 (if (re-search-forward "\\([0-9]+ \\).................\\( .*\\)" nil 0)
|
|
1124 (let ((rep (substring (concat x " ") 0 9)))
|
|
1125 (replace-match (concat "\\1" rep "\\2") t)))
|
|
1126 )))
|
|
1127
|
|
1128 ;;;###autoload
|
|
1129 (defun vc-directory (dir verbose &optional nested)
|
|
1130 "Show version-control status of all files in the directory DIR.
|
|
1131 If the second argument VERBOSE is non-nil, show all files;
|
|
1132 otherwise show only files that current locked in the version control system.
|
|
1133 Interactively, supply a prefix arg to make VERBOSE non-nil.
|
|
1134
|
|
1135 If the optional third argument NESTED is non-nil,
|
|
1136 scan the entire tree of subdirectories of the current directory."
|
|
1137 (interactive "DVC status of directory: \nP")
|
|
1138 (let* (nonempty
|
|
1139 (dl (length dir))
|
|
1140 (filelist nil) (userlist nil)
|
|
1141 dired-buf
|
|
1142 (subfunction
|
|
1143 (function (lambda (f)
|
|
1144 (if (vc-registered f)
|
|
1145 (let ((user (vc-locking-user f)))
|
|
1146 (and (or verbose user)
|
|
1147 (setq filelist (cons (substring f dl) filelist))
|
|
1148 (setq userlist (cons user userlist)))))))))
|
|
1149 (let ((default-directory dir))
|
|
1150 (if nested
|
|
1151 (vc-file-tree-walk subfunction)
|
|
1152 (vc-dir-all-files subfunction)))
|
|
1153 (save-excursion
|
70
|
1154 (dired (make-string-stringlist (cons dir (nreverse filelist)))
|
|
1155 dired-listing-switches)
|
0
|
1156 (rename-buffer (generate-new-buffer-name "VC-DIRED"))
|
|
1157 (setq dired-buf (current-buffer))
|
|
1158 (setq nonempty (not (zerop (buffer-size)))))
|
|
1159 (if nonempty
|
|
1160 (progn
|
|
1161 (pop-to-buffer dired-buf)
|
|
1162 (vc-dired-mode)
|
|
1163 (goto-char (point-min))
|
|
1164 (setq buffer-read-only nil)
|
|
1165 (forward-line 1) ; Skip header line
|
|
1166 (mapcar
|
|
1167 (function
|
|
1168 (lambda (x)
|
|
1169 (forward-char 2) ; skip dired's mark area
|
|
1170 (vc-dired-reformat-line x)
|
|
1171 (forward-line 1))) ; go to next line
|
|
1172 (nreverse userlist))
|
|
1173 (setq buffer-read-only t)
|
|
1174 (goto-char (point-min))
|
|
1175 )
|
|
1176 (message "No files are currently %s under %s"
|
|
1177 (if verbose "registered" "locked") default-directory))
|
|
1178 ))
|
|
1179
|
|
1180 (defun make-string-stringlist (stringlist)
|
|
1181 "Turn a list of strings into a string of space-delimited elements."
|
|
1182 (save-excursion
|
|
1183 (let ((tlist stringlist)
|
|
1184 (buf (generate-new-buffer "*stringlist*")))
|
|
1185 (set-buffer buf)
|
|
1186 (insert (car tlist))
|
|
1187 (setq tlist (cdr tlist))
|
|
1188 (while (not (null tlist))
|
|
1189 (setq s (car tlist))
|
|
1190 (insert s " ")
|
|
1191 (setq tlist (cdr tlist)))
|
|
1192 (setq string (buffer-string))
|
|
1193 (kill-this-buffer)
|
|
1194 string
|
|
1195 )))
|
|
1196
|
|
1197 ;; Named-configuration support for SCCS
|
|
1198
|
|
1199 (defun vc-add-triple (name file rev)
|
|
1200 (save-excursion
|
|
1201 (find-file (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file))
|
|
1202 (goto-char (point-max))
|
|
1203 (insert name "\t:\t" file "\t" rev "\n")
|
|
1204 (basic-save-buffer)
|
|
1205 (kill-buffer (current-buffer))
|
|
1206 ))
|
|
1207
|
|
1208 (defun vc-record-rename (file newname)
|
|
1209 (save-excursion
|
|
1210 (find-file (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file))
|
|
1211 (goto-char (point-min))
|
|
1212 ;; (replace-regexp (concat ":" (regexp-quote file) "$") (concat ":" newname))
|
|
1213 (while (re-search-forward (concat ":" (regexp-quote file) "$") nil t)
|
|
1214 (replace-match (concat ":" newname) nil nil))
|
|
1215 (basic-save-buffer)
|
|
1216 (kill-buffer (current-buffer))
|
|
1217 ))
|
|
1218
|
|
1219 (defun vc-lookup-triple (file name)
|
|
1220 ;; Return the numeric version corresponding to a named snapshot of file
|
|
1221 ;; If name is nil or a version number string it's just passed through
|
|
1222 (cond ((null name) name)
|
|
1223 ((let ((firstchar (aref name 0)))
|
|
1224 (and (>= firstchar ?0) (<= firstchar ?9)))
|
|
1225 name)
|
|
1226 (t
|
|
1227 (car (vc-master-info
|
|
1228 (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file)
|
|
1229 (list (concat name "\t:\t" file "\t\\(.+\\)"))))
|
|
1230 )))
|
|
1231
|
|
1232 ;; Named-configuration entry points
|
|
1233
|
|
1234 (defun vc-locked-example ()
|
|
1235 ;; Return an example of why the current directory is not ready to be snapshot
|
|
1236 ;; or nil if no such example exists.
|
|
1237 (catch 'vc-locked-example
|
|
1238 (vc-file-tree-walk
|
|
1239 (function (lambda (f)
|
|
1240 (if (and (vc-registered f) (vc-locking-user f))
|
|
1241 (throw 'vc-locked-example f)))))
|
|
1242 nil))
|
|
1243
|
|
1244 ;;;###autoload
|
|
1245 (defun vc-create-snapshot (name)
|
|
1246 "Make a snapshot called NAME.
|
|
1247 The snapshot is made from all registered files at or below the current
|
|
1248 directory. For each file, the version level of its latest
|
|
1249 version becomes part of the named configuration."
|
|
1250 (interactive "sNew snapshot name: ")
|
|
1251 (let ((locked (vc-locked-example)))
|
|
1252 (if locked
|
|
1253 (error "File %s is locked" locked)
|
|
1254 (vc-file-tree-walk
|
|
1255 (function (lambda (f) (and
|
|
1256 (vc-name f)
|
|
1257 (vc-backend-assign-name f name)))))
|
|
1258 )))
|
|
1259
|
|
1260 ;;;###autoload
|
|
1261 (defun vc-retrieve-snapshot (name)
|
|
1262 "Retrieve the snapshot called NAME.
|
|
1263 This function fails if any files are locked at or below the current directory
|
|
1264 Otherwise, all registered files are checked out (unlocked) at their version
|
|
1265 levels in the snapshot."
|
|
1266 (interactive "sSnapshot name to retrieve: ")
|
|
1267 (let ((locked (vc-locked-example)))
|
|
1268 (if locked
|
|
1269 (error "File %s is locked" locked)
|
|
1270 (vc-file-tree-walk
|
|
1271 (function (lambda (f) (and
|
|
1272 (vc-name f)
|
|
1273 (vc-error-occurred
|
|
1274 (vc-backend-checkout f nil name))))))
|
|
1275 )))
|
|
1276
|
|
1277 ;; Miscellaneous other entry points
|
|
1278
|
|
1279 ;;;###autoload
|
|
1280 (defun vc-print-log ()
|
|
1281 "List the change log of the current buffer in a window."
|
|
1282 (interactive)
|
|
1283 (if vc-dired-mode
|
|
1284 (set-buffer (find-file-noselect (dired-get-filename))))
|
|
1285 (while vc-parent-buffer
|
|
1286 (pop-to-buffer vc-parent-buffer))
|
|
1287 (if (and buffer-file-name (vc-name buffer-file-name))
|
|
1288 (let ((file buffer-file-name))
|
|
1289 (vc-backend-print-log file)
|
|
1290 (pop-to-buffer (get-buffer-create "*vc*"))
|
|
1291 (setq default-directory (file-name-directory file))
|
|
1292 (while (looking-at "=*\n")
|
|
1293 (delete-char (- (match-end 0) (match-beginning 0)))
|
|
1294 (forward-line -1))
|
|
1295 (goto-char (point-min))
|
|
1296 (if (looking-at "[\b\t\n\v\f\r ]+")
|
|
1297 (delete-char (- (match-end 0) (match-beginning 0))))
|
|
1298 (shrink-window-if-larger-than-buffer)
|
|
1299 )
|
|
1300 (vc-registration-error buffer-file-name)))
|
|
1301
|
|
1302 ;;;###autoload
|
|
1303 (defun vc-revert-buffer ()
|
|
1304 "Revert the current buffer's file back to the latest checked-in version.
|
|
1305 This asks for confirmation if the buffer contents are not identical
|
|
1306 to that version.
|
|
1307 If the back-end is CVS, this will give you the most recent revision of
|
|
1308 the file on the branch you are editing."
|
|
1309 (interactive)
|
|
1310 (if vc-dired-mode
|
|
1311 (find-file-other-window (dired-get-filename)))
|
|
1312 (while vc-parent-buffer
|
|
1313 (pop-to-buffer vc-parent-buffer))
|
|
1314 (let ((file buffer-file-name)
|
|
1315 (obuf (current-buffer)) (changed (vc-diff nil t)))
|
|
1316 (if (and changed (or vc-suppress-confirm
|
|
1317 (not (yes-or-no-p "Discard changes? "))))
|
|
1318 (progn
|
|
1319 (delete-window)
|
|
1320 (error "Revert cancelled"))
|
|
1321 (set-buffer obuf))
|
|
1322 (if changed
|
|
1323 (delete-window))
|
|
1324 (vc-backend-revert file)
|
|
1325 (vc-resynch-window file t t)
|
|
1326 ))
|
|
1327
|
|
1328 ;;;###autoload
|
|
1329 (defun vc-cancel-version (norevert)
|
|
1330 "Get rid of most recently checked in version of this file.
|
|
1331 A prefix argument means do not revert the buffer afterwards."
|
|
1332 (interactive "P")
|
|
1333 (if vc-dired-mode
|
|
1334 (find-file-other-window (dired-get-filename)))
|
|
1335 (while vc-parent-buffer
|
|
1336 (pop-to-buffer vc-parent-buffer))
|
|
1337 (let* ((target (concat (vc-latest-version (buffer-file-name))))
|
|
1338 (yours (concat (vc-your-latest-version (buffer-file-name))))
|
|
1339 (prompt (if (string-equal yours target)
|
|
1340 "Remove your version %s from master? "
|
|
1341 "Version %s was not your change. Remove it anyway? ")))
|
|
1342 (if (null (yes-or-no-p (format prompt target)))
|
|
1343 nil
|
|
1344 (vc-backend-uncheck (buffer-file-name) target)
|
|
1345 (if (or norevert
|
|
1346 (not (yes-or-no-p "Revert buffer to most recent remaining version? ")))
|
|
1347 (vc-mode-line (buffer-file-name))
|
|
1348 (vc-checkout (buffer-file-name) nil)))
|
|
1349 ))
|
|
1350
|
|
1351 ;;;###autoload
|
|
1352 (defun vc-rename-file (old new)
|
|
1353 "Rename file OLD to NEW, and rename its master file likewise."
|
|
1354 (interactive "fVC rename file: \nFRename to: ")
|
|
1355 ;; There are several ways of renaming files under CVS 1.3, but they all
|
|
1356 ;; have serious disadvantages. See the FAQ (available from think.com in
|
|
1357 ;; pub/cvs/). I'd rather send the user an error, than do something he might
|
|
1358 ;; consider to be wrong. When the famous, long-awaited rename database is
|
|
1359 ;; implemented things might change for the better. This is unlikely to occur
|
|
1360 ;; until CVS 2.0 is released. --ceder 1994-01-23 21:27:51
|
|
1361 (if (eq (vc-backend-deduce old) 'CVS)
|
|
1362 (error "Renaming files under CVS is dangerous and not supported in VC."))
|
|
1363 (if (eq (vc-backend-deduce old) 'CC)
|
|
1364 (error "VC's ClearCase support cannot rename files."))
|
|
1365 (let ((oldbuf (get-file-buffer old)))
|
|
1366 (if (and oldbuf (buffer-modified-p oldbuf))
|
|
1367 (error "Please save files before moving them"))
|
|
1368 (if (get-file-buffer new)
|
|
1369 (error "Already editing new file name"))
|
|
1370 (if (file-exists-p new)
|
|
1371 (error "New file already exists"))
|
|
1372 (let ((oldmaster (vc-name old)))
|
|
1373 (if oldmaster
|
|
1374 (progn
|
|
1375 (if (vc-locking-user old)
|
|
1376 (error "Please check in files before moving them"))
|
|
1377 (if (or (file-symlink-p oldmaster)
|
|
1378 ;; This had FILE, I changed it to OLD. -- rms.
|
|
1379 (file-symlink-p (vc-backend-subdirectory-name old)))
|
|
1380 (error "This is not a safe thing to do in the presence of symbolic links"))
|
|
1381 (rename-file
|
|
1382 oldmaster
|
|
1383 (let ((backend (vc-backend-deduce old))
|
|
1384 (newdir (or (file-name-directory new) ""))
|
|
1385 (newbase (file-name-nondirectory new)))
|
|
1386 (catch 'found
|
|
1387 (mapcar
|
|
1388 (function
|
|
1389 (lambda (s)
|
|
1390 (if (eq backend (cdr s))
|
|
1391 (let* ((newmaster (format (car s) newdir newbase))
|
|
1392 (newmasterdir (file-name-directory newmaster)))
|
|
1393 (if (or (not newmasterdir)
|
|
1394 (file-directory-p newmasterdir))
|
|
1395 (throw 'found newmaster))))))
|
|
1396 vc-master-templates)
|
|
1397 (error "New file lacks a version control directory"))))))
|
|
1398 (if (or (not oldmaster) (file-exists-p old))
|
|
1399 (rename-file old new)))
|
|
1400 ;; ?? Renaming a file might change its contents due to keyword expansion.
|
|
1401 ;; We should really check out a new copy if the old copy was precisely equal
|
|
1402 ;; to some checked in version. However, testing for this is tricky....
|
|
1403 (if oldbuf
|
|
1404 (save-excursion
|
|
1405 (set-buffer oldbuf)
|
|
1406 (set-visited-file-name new)
|
|
1407 (set-buffer-modified-p nil))))
|
|
1408 ;; This had FILE, I changed it to OLD. -- rms.
|
|
1409 (vc-backend-dispatch old
|
|
1410 (vc-record-rename old new) ;SCCS
|
|
1411 ;; #### - This CAN kinda be done for both rcs and
|
|
1412 ;; cvs. It needs to be implemented. -- Stig
|
|
1413 nil ;RCS
|
|
1414 nil ;CVS
|
|
1415 nil ;CC
|
|
1416 )
|
|
1417 )
|
|
1418
|
|
1419 ;;;###autoload
|
74
|
1420 (defun vc-rename-this-file (new)
|
|
1421 (interactive "FVC rename file to: ")
|
|
1422 (vc-rename-file buffer-file-name new))
|
|
1423
|
|
1424 ;;;###autoload
|
0
|
1425 (defun vc-update-change-log (&rest args)
|
|
1426 "Find change log file and add entries from recent RCS logs.
|
|
1427 The mark is left at the end of the text prepended to the change log.
|
|
1428 With prefix arg of C-u, only find log entries for the current buffer's file.
|
|
1429 With any numeric prefix arg, find log entries for all files currently visited.
|
|
1430 Otherwise, find log entries for all registered files in the default directory.
|
|
1431 From a program, any arguments are passed to the `rcs2log' script."
|
|
1432 (interactive
|
|
1433 (cond ((consp current-prefix-arg) ;C-u
|
|
1434 (list buffer-file-name))
|
|
1435 (current-prefix-arg ;Numeric argument.
|
|
1436 (let ((files nil)
|
|
1437 (buffers (buffer-list))
|
|
1438 file)
|
|
1439 (while buffers
|
|
1440 (setq file (buffer-file-name (car buffers)))
|
|
1441 (and file (vc-backend-deduce file)
|
|
1442 (setq files (cons file files)))
|
|
1443 (setq buffers (cdr buffers)))
|
|
1444 files))
|
|
1445 (t
|
|
1446 (let ((RCS (concat default-directory "RCS")))
|
|
1447 (and (file-directory-p RCS)
|
|
1448 (mapcar (function
|
|
1449 (lambda (f)
|
|
1450 (if (string-match "\\(.*\\),v$" f)
|
|
1451 (substring f 0 (match-end 1))
|
|
1452 f)))
|
|
1453 (directory-files RCS nil "...\\|^[^.]\\|^.[^.]")))))))
|
|
1454 (let ((odefault default-directory))
|
|
1455 (find-file-other-window (find-change-log))
|
|
1456 (barf-if-buffer-read-only)
|
|
1457 (vc-buffer-sync)
|
|
1458 (undo-boundary)
|
|
1459 (goto-char (point-min))
|
|
1460 (push-mark)
|
|
1461 (message "Computing change log entries...")
|
|
1462 (message "Computing change log entries... %s"
|
|
1463 (if (or (null args)
|
|
1464 (eq 0 (apply 'call-process "rcs2log" nil t nil
|
|
1465 "-n"
|
|
1466 (user-login-name)
|
|
1467 (user-full-name)
|
|
1468 user-mail-address
|
|
1469 (mapcar (function
|
|
1470 (lambda (f)
|
|
1471 (file-relative-name
|
|
1472 (if (file-name-absolute-p f)
|
|
1473 f
|
|
1474 (concat odefault f)))))
|
|
1475 args))))
|
|
1476 "done" "failed"))))
|
|
1477
|
|
1478 ;; Functions for querying the master and lock files.
|
|
1479
|
|
1480 ;; XEmacs - use match-string instead...
|
|
1481 ;; (defun vc-match-substring (bn)
|
|
1482 ;; (buffer-substring (match-beginning bn) (match-end bn)))
|
|
1483
|
|
1484 (defun vc-parse-buffer (patterns &optional file properties)
|
|
1485 ;; Each pattern is of the form:
|
|
1486 ;; regex ; subex is 1, and date-subex is 2 (or nil)
|
|
1487 ;; (regex subex date-subex)
|
|
1488 ;;
|
|
1489 ;; Use PATTERNS to parse information out of the current buffer by matching
|
|
1490 ;; each REGEX in the list and the returning the string matched by SUBEX.
|
|
1491 ;; If a DATE-SUBEX is present, then the SUBEX from the match with the
|
|
1492 ;; highest value for DATE-SUBEX (string comparison is used) will be
|
|
1493 ;; returned.
|
|
1494 ;;
|
|
1495 ;; If FILE and PROPERTIES are given, the latter must be a list of
|
|
1496 ;; properties of the same length as PATTERNS; each property is assigned
|
|
1497 ;; the corresponding value.
|
|
1498 ;;
|
|
1499 (let (pattern regex subex date-subex latest-date val values date)
|
|
1500 (while (setq pattern (car patterns))
|
|
1501 (if (stringp pattern)
|
|
1502 (setq regex pattern
|
|
1503 subex 1
|
|
1504 date-subex (and (string-match "\\\\(.*\\\\(" regex) 2))
|
|
1505 (setq regex (car pattern)
|
|
1506 subex (nth 1 pattern)
|
|
1507 date-subex (nth 2 pattern)))
|
|
1508 (goto-char (point-min))
|
|
1509 (if date-subex
|
|
1510 (progn
|
|
1511 (setq latest-date "" val nil)
|
|
1512 (while (re-search-forward regex nil t)
|
|
1513 (setq date (match-string date-subex))
|
|
1514 (if (string< latest-date date)
|
|
1515 (setq latest-date date
|
|
1516 val (match-string subex))))
|
|
1517 val)
|
|
1518 ;; no date subex, so just take the first match...
|
|
1519 (setq val (and (re-search-forward regex nil t) (match-string subex))))
|
|
1520 (if file (vc-file-setprop file (car properties) val))
|
|
1521 (setq values (cons val values)
|
|
1522 patterns (cdr patterns)
|
|
1523 properties (cdr properties)))
|
|
1524 values
|
|
1525 ))
|
|
1526
|
|
1527 (defun vc-master-info (file fields &optional rfile properties)
|
|
1528 ;; Search for information in a master file.
|
|
1529 (if (and file (file-exists-p file))
|
|
1530 (save-excursion
|
|
1531 (let ((buf))
|
|
1532 (setq buf (create-file-buffer file))
|
|
1533 (set-buffer buf))
|
|
1534 (erase-buffer)
|
|
1535 (insert-file-contents file)
|
|
1536 (set-buffer-modified-p nil)
|
|
1537 (auto-save-mode nil)
|
|
1538 (prog1
|
|
1539 (vc-parse-buffer fields rfile properties)
|
|
1540 (kill-buffer (current-buffer)))
|
|
1541 )
|
|
1542 (if rfile
|
|
1543 (mapcar
|
|
1544 (function (lambda (p) (vc-file-setprop rfile p nil)))
|
|
1545 properties))
|
|
1546 )
|
|
1547 )
|
|
1548
|
|
1549 (defun vc-log-info (command file last flags patterns &optional properties)
|
|
1550 ;; Search for information in log program output
|
|
1551 (if (and file (file-exists-p file))
|
|
1552 (save-excursion
|
|
1553 (set-buffer (get-buffer-create "*vc*"))
|
|
1554 (apply 'vc-do-command 0 command file last flags)
|
|
1555 (set-buffer-modified-p nil)
|
|
1556 (prog1
|
|
1557 (vc-parse-buffer patterns file properties)
|
|
1558 (kill-buffer (current-buffer))
|
|
1559 )
|
|
1560 )
|
|
1561 (if file
|
|
1562 (mapcar
|
|
1563 (function (lambda (p) (vc-file-setprop file p nil)))
|
|
1564 properties))
|
|
1565 )
|
|
1566 )
|
|
1567
|
|
1568 (defun vc-locking-user (file)
|
|
1569 "Return the name of the person currently holding a lock on FILE.
|
|
1570 Return nil if there is no such person.
|
|
1571 Under CVS, a file is considered locked if it has been modified since it
|
|
1572 was checked out...even though it may well be writable by you."
|
|
1573 (setq file (expand-file-name file)) ; use full pathname
|
|
1574 (cond ((eq (vc-backend-deduce file) 'CVS)
|
|
1575 (if (vc-workfile-unchanged-p file t)
|
|
1576 nil
|
|
1577 ;; XEmacs - ahead of the pack...
|
|
1578 (user-login-name (nth 2 (file-attributes file)))))
|
|
1579 (t
|
|
1580 ;; #### - this can probably be cleaned up as a result of the changes to
|
|
1581 ;; user-login-name...
|
|
1582 (if (or (not vc-keep-workfiles)
|
|
1583 (eq vc-mistrust-permissions 't)
|
|
1584 (and vc-mistrust-permissions
|
|
1585 (funcall vc-mistrust-permissions (vc-backend-subdirectory-name
|
|
1586 file))))
|
|
1587 (vc-true-locking-user file)
|
|
1588 ;; This implementation assumes that any file which is under version
|
|
1589 ;; control and has -rw-r--r-- is locked by its owner. This is true
|
|
1590 ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--.
|
|
1591 ;; We have to be careful not to exclude files with execute bits on;
|
|
1592 ;; scripts can be under version control too. Also, we must ignore
|
|
1593 ;; the group-read and other-read bits, since paranoid users turn them off.
|
|
1594 ;; This hack wins because calls to the very expensive vc-fetch-properties
|
|
1595 ;; function only have to be made if (a) the file is locked by someone
|
|
1596 ;; other than the current user, or (b) some untoward manipulation
|
|
1597 ;; behind vc's back has changed the owner or the `group' or `other'
|
|
1598 ;; write bits.
|
|
1599 (let ((attributes (file-attributes file)))
|
|
1600 (cond ((string-match ".r-..-..-." (nth 8 attributes))
|
|
1601 nil)
|
|
1602 ((and (= (nth 2 attributes) (user-uid))
|
|
1603 (string-match ".rw..-..-." (nth 8 attributes)))
|
|
1604 (user-login-name))
|
|
1605 (t
|
|
1606 (vc-true-locking-user file)))) ; #### - this looks recursive!!!
|
|
1607 ))))
|
|
1608
|
|
1609 (defun vc-true-locking-user (file)
|
|
1610 ;; The slow but reliable version
|
|
1611 (vc-fetch-properties file)
|
|
1612 (vc-file-getprop file 'vc-locking-user))
|
|
1613
|
|
1614 (defun vc-latest-version (file)
|
|
1615 ;; Return version level of the latest version of FILE
|
|
1616 (vc-fetch-properties file)
|
|
1617 (vc-file-getprop file 'vc-latest-version))
|
|
1618
|
|
1619 (defun vc-your-latest-version (file)
|
|
1620 ;; Return version level of the latest version of FILE checked in by you
|
|
1621 (vc-fetch-properties file)
|
|
1622 (vc-file-getprop file 'vc-your-latest-version))
|
|
1623
|
|
1624 ;; Collect back-end-dependent stuff here
|
|
1625 ;;
|
|
1626 ;; Everything eventually funnels through these functions. To implement
|
|
1627 ;; support for a new version-control system, add another branch to the
|
|
1628 ;; vc-backend-dispatch macro and fill it in in each call. The variable
|
|
1629 ;; vc-master-templates in vc-hooks.el will also have to change.
|
|
1630
|
|
1631 (put 'vc-backend-dispatch 'lisp-indent-function 'defun)
|
|
1632
|
|
1633 (defmacro vc-backend-dispatch (f s r c a)
|
|
1634 "Execute FORM1, FORM2 or FORM3 depending whether we're using SCCS, RCS, CVS
|
|
1635 or ClearCase.
|
|
1636 If FORM3 is RCS, use FORM2 even if we are using CVS. (CVS shares some code
|
|
1637 with RCS)."
|
|
1638 (list 'let (list (list 'type (list 'vc-backend-deduce f)))
|
|
1639 (list 'cond
|
|
1640 (list (list 'eq 'type (quote 'SCCS)) s) ; SCCS
|
|
1641 (list (list 'eq 'type (quote 'RCS)) r) ; RCS
|
|
1642 (list (list 'eq 'type (quote 'CVS)) ; CVS
|
|
1643 (if (eq c 'RCS) r c))
|
|
1644 (list (list 'eq 'type (quote 'CC)) a) ; CC
|
|
1645 )))
|
|
1646
|
|
1647 (defun vc-lock-file (file)
|
|
1648 ;; Generate lock file name corresponding to FILE
|
|
1649 (let ((master (vc-name file)))
|
|
1650 (and
|
|
1651 master
|
|
1652 (string-match "\\(.*/\\)s\\.\\(.*\\)" master)
|
|
1653 (concat
|
|
1654 (substring master (match-beginning 1) (match-end 1))
|
|
1655 "p."
|
|
1656 (substring master (match-beginning 2) (match-end 2))))))
|
|
1657
|
|
1658
|
|
1659 (defun vc-fetch-properties (file)
|
|
1660 ;; Re-fetch all properties associated with the given file.
|
|
1661 ;; Currently these properties are:
|
|
1662 ;; vc-locking-user
|
|
1663 ;; vc-locked-version
|
|
1664 ;; vc-latest-version
|
|
1665 ;; vc-your-latest-version
|
|
1666 ;; vc-cvs-status (cvs only)
|
|
1667 ;; vc-cc-predecessor (ClearCase only)
|
|
1668 (vc-backend-dispatch
|
|
1669 file
|
|
1670 ;; SCCS
|
|
1671 (progn
|
|
1672 (vc-master-info (vc-lock-file file)
|
|
1673 (list
|
|
1674 "^[^ ]+ [^ ]+ \\([^ ]+\\)"
|
|
1675 "^\\([^ ]+\\)")
|
|
1676 file
|
|
1677 '(vc-locking-user vc-locked-version))
|
|
1678 (vc-master-info (vc-name file)
|
|
1679 (list
|
|
1680 "^\001d D \\([^ ]+\\)"
|
|
1681 (concat "^\001d D \\([^ ]+\\) .* "
|
|
1682 (regexp-quote (user-login-name)) " ")
|
|
1683 )
|
|
1684 file
|
|
1685 '(vc-latest-version vc-your-latest-version))
|
|
1686 )
|
|
1687 ;; RCS
|
|
1688 (vc-log-info "rlog" file 'MASTER nil
|
|
1689 (list
|
|
1690 "^locks: strict\n\t\\([^:]+\\)"
|
|
1691 "^locks: strict\n\t[^:]+: \\(.+\\)"
|
|
1692 "^revision[\t ]+\\([0-9.]+\\).*\ndate: \\([ /0-9:]+\\);"
|
|
1693 (concat
|
|
1694 "^revision[\t ]+\\([0-9.]+\\)\n.*author: "
|
|
1695 (regexp-quote (user-login-name))
|
|
1696 ";"))
|
|
1697 '(vc-locking-user vc-locked-version
|
|
1698 vc-latest-version vc-your-latest-version))
|
|
1699 ;; CVS
|
|
1700 ;; Don't fetch vc-locking-user and vc-locked-version here, since they
|
|
1701 ;; should always be nil anyhow. Don't fetch vc-your-latest-version, since
|
|
1702 ;; that is done in vc-find-cvs-master.
|
|
1703 (vc-log-info
|
|
1704 "cvs" file 'WORKFILE '("status")
|
|
1705 ;; CVS 1.3 says "RCS Version:", other releases "RCS Revision:",
|
|
1706 ;; and CVS 1.4a1 says "Repository revision:". The regexp below
|
|
1707 ;; matches much more, but because of the way vc-log-info is
|
|
1708 ;; implemented it is impossible to use additional groups.
|
|
1709 '(("\\(RCS Version\\|RCS Revision\\|Repository revision\\):[\t ]+\\([0-9.]+\\)" 2)
|
|
1710 "Status: \\(.*\\)")
|
|
1711 '(vc-latest-version
|
|
1712 vc-cvs-status))
|
|
1713 ;; CC
|
|
1714 (vc-log-info "cleartool" file 'WORKFILE '("describe")
|
|
1715 (list
|
|
1716 "checked out .* by .* (\\([^ .]+\\)..*@.*)"
|
|
1717 "from \\([^ ]+\\) (reserved)"
|
|
1718 "version [^\"]*\".*@@\\([^ ]+\\)\""
|
|
1719 "version [^\"]*\".*@@\\([^ ]+\\)\""
|
|
1720 "predecessor version: \\([^ ]+\\)\n")
|
|
1721 '(vc-locking-user vc-locked-version
|
|
1722 vc-latest-version vc-your-latest-version
|
|
1723 vc-cc-predecessor))
|
|
1724 ))
|
|
1725
|
|
1726 (defun vc-backend-subdirectory-name (&optional file)
|
|
1727 ;; Where the master and lock files for the current directory are kept
|
|
1728 (let ((backend
|
|
1729 (or
|
|
1730 (and file (vc-backend-deduce file))
|
|
1731 vc-default-back-end
|
|
1732 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))))
|
|
1733 (cond
|
|
1734 ((eq backend 'SCCS) "SCCS")
|
|
1735 ((eq backend 'RCS) "RCS")
|
|
1736 ((eq backend 'CVS) "CVS")
|
|
1737 ((eq backend 'CC) "@@"))
|
|
1738 ))
|
|
1739
|
|
1740 (defun vc-backend-admin (file &optional rev comment)
|
|
1741 ;; Register a file into the version-control system
|
|
1742 ;; Automatically retrieves a read-only version of the file with
|
|
1743 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
|
|
1744 ;; it deletes the workfile.
|
|
1745 (vc-file-clearprops file)
|
|
1746 (or vc-default-back-end
|
|
1747 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))
|
|
1748 (message "Registering %s..." file)
|
|
1749 (let ((backend
|
|
1750 (cond
|
|
1751 ((file-exists-p (vc-backend-subdirectory-name)) vc-default-back-end)
|
|
1752 ((file-exists-p "RCS") 'RCS)
|
|
1753 ((file-exists-p "SCCS") 'SCCS)
|
|
1754 ((file-exists-p "CVS") 'CVS)
|
|
1755 ((file-exists-p "@@") 'CC)
|
|
1756 (t vc-default-back-end))))
|
|
1757 (cond ((eq backend 'SCCS)
|
|
1758 (vc-do-command 0 "admin" file 'MASTER ; SCCS
|
|
1759 (and rev (concat "-r" rev))
|
|
1760 "-fb"
|
|
1761 (concat "-i" file)
|
|
1762 (and comment (concat "-y" comment))
|
|
1763 (format
|
|
1764 (car (rassq 'SCCS vc-master-templates))
|
|
1765 (or (file-name-directory file) "")
|
|
1766 (file-name-nondirectory file)))
|
|
1767 (delete-file file)
|
|
1768 (if vc-keep-workfiles
|
|
1769 (vc-do-command 0 "get" file 'MASTER)))
|
|
1770 ((eq backend 'RCS)
|
|
1771 (vc-do-command 0 "ci" file 'MASTER ; RCS
|
|
1772 (concat (if vc-keep-workfiles "-u" "-r") rev)
|
|
1773 (and comment (concat "-t-" comment))
|
|
1774 file))
|
|
1775 ((eq backend 'CVS)
|
|
1776 ;; #### - should maybe check to see if the master file is
|
|
1777 ;; already in the repository...in which case we need to add the
|
|
1778 ;; appropriate branch tag and do an update.
|
|
1779 ;; #### - note that adding a file is a 2 step process in CVS...
|
|
1780 (vc-do-command 0 "cvs" file 'WORKFILE "add")
|
|
1781 (vc-do-command 0 "cvs" file 'WORKFILE "commit"
|
|
1782 (and comment (not (string= comment ""))
|
|
1783 (concat "-m" comment)))
|
|
1784 )
|
|
1785 ((eq backend 'CC)
|
|
1786 (vc-do-command 0 "cleartool" file 'WORKFILE ; CC
|
|
1787 "mkelem"
|
|
1788 (if (string-equal "" comment)
|
|
1789 "-nc")
|
|
1790 (if (not (string-equal "" comment))
|
|
1791 "-c")
|
|
1792 (if (not (string-equal "" comment))
|
|
1793 comment)
|
|
1794 )
|
|
1795 (vc-do-command 0 "cleartool" file 'WORKFILE
|
|
1796 "checkin" "-identical" "-nc"
|
|
1797 )
|
|
1798 )))
|
|
1799 (message "Registering %s...done" file)
|
|
1800 )
|
|
1801
|
|
1802 (defun vc-backend-checkout (file &optional writable rev workfile)
|
|
1803 ;; Retrieve a copy of a saved version into a workfile
|
|
1804 (let ((filename (or workfile file)))
|
|
1805 (message "Checking out %s..." filename)
|
|
1806 (save-excursion
|
|
1807 ;; Change buffers to get local value of vc-checkin-switches.
|
|
1808 (set-buffer (or (get-file-buffer file) (current-buffer)))
|
|
1809 (vc-backend-dispatch
|
|
1810 file
|
|
1811 ;; SCCS
|
|
1812 (if workfile
|
|
1813 ;; Some SCCS implementations allow checking out directly to a
|
|
1814 ;; file using the -G option, but then some don't so use the
|
|
1815 ;; least common denominator approach and use the -p option
|
|
1816 ;; ala RCS.
|
|
1817 (let ((vc-modes (logior (file-modes (vc-name file))
|
|
1818 (if writable 128 0)))
|
|
1819 (failed t))
|
|
1820 (unwind-protect
|
|
1821 (progn
|
|
1822 (apply 'vc-do-command
|
|
1823 0 "/bin/sh" file 'MASTER "-c"
|
|
1824 ;; Some shells make the "" dummy argument into $0
|
|
1825 ;; while others use the shell's name as $0 and
|
|
1826 ;; use the "" as $1. The if-statement
|
|
1827 ;; converts the latter case to the former.
|
|
1828 (format "if [ x\"$1\" = x ]; then shift; fi; \
|
|
1829 umask %o; exec >\"$1\" || exit; \
|
|
1830 shift; umask %o; exec get \"$@\""
|
|
1831 (logand 511 (lognot vc-modes))
|
|
1832 (logand 511 (lognot (default-file-modes))))
|
|
1833 "" ; dummy argument for shell's $0
|
|
1834 filename
|
|
1835 (if writable "-e")
|
|
1836 "-p" (and rev
|
|
1837 (concat "-r" (vc-lookup-triple file rev)))
|
|
1838 vc-checkout-switches)
|
|
1839 (setq failed nil))
|
|
1840 (and failed (file-exists-p filename) (delete-file filename))))
|
|
1841 (apply 'vc-do-command 0 "get" file 'MASTER ; SCCS
|
|
1842 (if writable "-e")
|
|
1843 (and rev (concat "-r" (vc-lookup-triple file rev)))
|
|
1844 vc-checkout-switches))
|
|
1845 ;; RCS
|
|
1846 (if workfile
|
|
1847 ;; RCS doesn't let us check out into arbitrary file names directly.
|
|
1848 ;; Use `co -p' and make stdout point to the correct file.
|
|
1849 (let ((vc-modes (logior (file-modes (vc-name file))
|
|
1850 (if writable 128 0)))
|
|
1851 (failed t))
|
|
1852 (unwind-protect
|
|
1853 (progn
|
|
1854 (apply 'vc-do-command
|
|
1855 0 "/bin/sh" file 'MASTER "-c"
|
|
1856 ;; See the SCCS case, above, regarding the
|
|
1857 ;; if-statement.
|
|
1858 (format "if [ x\"$1\" = x ]; then shift; fi; \
|
|
1859 umask %o; exec >\"$1\" || exit; \
|
|
1860 shift; umask %o; exec co \"$@\""
|
|
1861 (logand 511 (lognot vc-modes))
|
|
1862 (logand 511 (lognot (default-file-modes))))
|
|
1863 "" ; dummy argument for shell's $0
|
|
1864 filename
|
|
1865 (if writable "-l")
|
|
1866 (concat "-p" rev)
|
|
1867 vc-checkout-switches)
|
|
1868 (setq failed nil))
|
|
1869 (and failed (file-exists-p filename) (delete-file filename))))
|
|
1870 (apply 'vc-do-command 0 "co" file 'MASTER
|
|
1871 (if writable "-l")
|
|
1872 (and rev (concat "-r" rev))
|
|
1873 vc-checkout-switches))
|
|
1874 ;; CVS
|
|
1875 (if workfile
|
|
1876 ;; CVS is much like RCS
|
|
1877 (let ((failed t))
|
|
1878 (unwind-protect
|
|
1879 (progn
|
|
1880 (apply 'vc-do-command
|
|
1881 0 "/bin/sh" file 'WORKFILE "-c"
|
|
1882 "exec >\"$1\" || exit; shift; exec cvs update \"$@\""
|
|
1883 "" ; dummy argument for shell's $0
|
|
1884 workfile
|
|
1885 (concat "-r" rev)
|
|
1886 "-p"
|
|
1887 vc-checkout-switches)
|
|
1888 (setq failed nil))
|
|
1889 (and failed (file-exists-p filename) (delete-file filename))))
|
|
1890 (apply 'vc-do-command 0 "cvs" file 'WORKFILE
|
|
1891 "update"
|
|
1892 (and rev (concat "-r" rev))
|
|
1893 file
|
|
1894 vc-checkout-switches))
|
|
1895 ;; CC
|
|
1896 (if (or rev workfile)
|
|
1897 (error "VC's ClearCase support currently checks out /main/LATEST.")
|
|
1898 (apply 'vc-do-command 0 "cleartool" file 'WORKFILE
|
|
1899 "checkout" "-nc"
|
|
1900 vc-checkout-switches))
|
|
1901 ))
|
|
1902 (or workfile
|
|
1903 (vc-file-setprop file
|
|
1904 'vc-checkout-time (nth 5 (file-attributes file))))
|
|
1905 (message "Checking out %s...done" filename))
|
|
1906 )
|
|
1907
|
|
1908 (defun vc-backend-logentry-check (file)
|
|
1909 (vc-backend-dispatch file
|
|
1910 (if (>= (buffer-size) 512) ; SCCS
|
|
1911 (progn
|
|
1912 (goto-char 512)
|
|
1913 (error
|
|
1914 "Log must be less than 512 characters; point is now at pos 512")))
|
|
1915 nil ; RCS
|
|
1916 nil ; CVS
|
|
1917 nil) ; CC
|
|
1918 )
|
|
1919
|
|
1920 (defun vc-backend-checkin (file rev comment)
|
|
1921 ;; Register changes to FILE as level REV with explanatory COMMENT.
|
|
1922 ;; Automatically retrieves a read-only version of the file with
|
|
1923 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
|
|
1924 ;; it deletes the workfile.
|
|
1925 (message "Checking in %s..." file)
|
|
1926 (save-excursion
|
|
1927 ;; Change buffers to get local value of vc-checkin-switches.
|
|
1928 (set-buffer (or (get-file-buffer file) (current-buffer)))
|
|
1929 (vc-backend-dispatch file
|
|
1930 (progn
|
|
1931 (apply 'vc-do-command 0 "delta" file 'MASTER
|
|
1932 (if rev (concat "-r" rev))
|
|
1933 (concat "-y" comment)
|
|
1934 vc-checkin-switches)
|
|
1935 (if vc-keep-workfiles
|
|
1936 (vc-do-command 0 "get" file 'MASTER))
|
|
1937 )
|
|
1938 (apply 'vc-do-command 0 "ci" file 'MASTER
|
|
1939 (concat (if vc-keep-workfiles "-u" "-r") rev)
|
|
1940 (if (not (string-equal "" comment))
|
|
1941 (concat "-m" comment))
|
|
1942 vc-checkin-switches)
|
|
1943 (progn
|
|
1944 (apply 'vc-do-command 0 "cvs" file 'WORKFILE
|
|
1945 "ci"
|
|
1946 (if (not (string-equal "" comment))
|
|
1947 (concat "-m" comment))
|
|
1948 vc-checkin-switches)
|
|
1949 (vc-file-setprop file 'vc-checkout-time
|
|
1950 (nth 5 (file-attributes file))))
|
|
1951 (progn
|
|
1952 (apply 'vc-do-command 0 "cleartool" file 'WORKFILE
|
|
1953 "checkin" "-identical"
|
|
1954 (if (string-equal "" comment)
|
|
1955 "-nc")
|
|
1956 (if (not (string-equal "" comment))
|
|
1957 "-c")
|
|
1958 (if (not (string-equal "" comment))
|
|
1959 comment)
|
|
1960 vc-checkin-switches)
|
|
1961 (vc-file-setprop file 'vc-checkout-time
|
|
1962 (nth 5 (file-attributes file))))
|
|
1963 ))
|
|
1964 (vc-file-setprop file 'vc-locking-user nil)
|
|
1965 (message "Checking in %s...done" file)
|
|
1966 )
|
|
1967
|
|
1968 (defun vc-backend-revert (file)
|
|
1969 ;; Revert file to latest checked-in version.
|
|
1970 (message "Reverting %s..." file)
|
|
1971 (vc-backend-dispatch
|
|
1972 file
|
|
1973 (progn ; SCCS
|
|
1974 (vc-do-command 0 "unget" file 'MASTER nil)
|
|
1975 (vc-do-command 0 "get" file 'MASTER nil))
|
|
1976 (vc-do-command 0 "co" file 'MASTER ; RCS. This deletes the work file.
|
|
1977 "-f" "-u")
|
|
1978 (progn ; CVS
|
|
1979 (delete-file file)
|
|
1980 (vc-do-command 0 "cvs" file 'WORKFILE "update"))
|
|
1981 (vc-do-command 0 "cleartool" file 'WORKFILE ; CC
|
|
1982 "unco" "-rm")
|
|
1983 )
|
|
1984 (vc-file-setprop file 'vc-locking-user nil)
|
|
1985 (message "Reverting %s...done" file)
|
|
1986 )
|
|
1987
|
|
1988 (defun vc-backend-steal (file &optional rev)
|
|
1989 ;; Steal the lock on the current workfile. Needs RCS 5.6.2 or later for -M.
|
|
1990 (message "Stealing lock on %s..." file)
|
|
1991 (vc-backend-dispatch file
|
|
1992 (progn ; SCCS
|
|
1993 (vc-do-command 0 "unget" file 'MASTER "-n" (if rev (concat "-r" rev)))
|
|
1994 (vc-do-command 0 "get" file 'MASTER "-g" (if rev (concat "-r" rev)))
|
|
1995 )
|
|
1996 (vc-do-command 0 "rcs" file 'MASTER ; RCS
|
|
1997 "-M" (concat "-u" rev) (concat "-l" rev))
|
|
1998 (error "You cannot steal a CVS lock; there are no CVS locks to steal.") ; CVS
|
|
1999 (error "VC's ClearCase support cannot steal locks.") ; CC
|
|
2000 )
|
|
2001 (vc-file-setprop file 'vc-locking-user (user-login-name))
|
|
2002 (message "Stealing lock on %s...done" file)
|
|
2003 )
|
|
2004
|
|
2005 (defun vc-backend-uncheck (file target)
|
|
2006 ;; Undo the latest checkin. Note: this code will have to get a lot
|
|
2007 ;; smarter when we support multiple branches.
|
|
2008 (message "Removing last change from %s..." file)
|
|
2009 (vc-backend-dispatch file
|
|
2010 (vc-do-command 0 "rmdel" file 'MASTER (concat "-r" target))
|
|
2011 (vc-do-command 0 "rcs" file 'MASTER (concat "-o" target))
|
|
2012 (error "Unchecking files under CVS is dangerous and not supported in VC.")
|
|
2013 (error "VC's ClearCase support cannot cancel checkins.")
|
|
2014 )
|
|
2015 (message "Removing last change from %s...done" file)
|
|
2016 )
|
|
2017
|
|
2018 (defun vc-backend-print-log (file)
|
|
2019 ;; Print change log associated with FILE to buffer *vc*.
|
|
2020 (vc-backend-dispatch
|
|
2021 file
|
|
2022 (vc-do-command 0 "prs" file 'MASTER)
|
|
2023 (vc-do-command 0 "rlog" file 'MASTER)
|
100
|
2024 (vc-do-command 0 "cvs" file 'WORKFILE "log")
|
0
|
2025 (vc-do-command 0 "cleartool" file 'WORKFILE "lshistory")))
|
|
2026
|
|
2027 (defun vc-backend-assign-name (file name)
|
|
2028 ;; Assign to a FILE's latest version a given NAME.
|
|
2029 (vc-backend-dispatch file
|
|
2030 (vc-add-triple name file (vc-latest-version file)) ; SCCS
|
|
2031 (vc-do-command 0 "rcs" file 'MASTER (concat "-n" name ":")) ; RCS
|
|
2032 (vc-do-command 0 "cvs" file 'WORKFILE "tag" name) ; CVS
|
|
2033 (vc-do-command 0 "cleartool" file 'WORKFILE ; CC
|
|
2034 "mklabel" "-replace" "-nc" name)
|
|
2035 )
|
|
2036 )
|
|
2037
|
|
2038 (defun vc-backend-diff (file &optional oldvers newvers cmp)
|
|
2039 ;; Get a difference report between two versions of FILE.
|
|
2040 ;; Get only a brief comparison report if CMP, a difference report otherwise.
|
|
2041 (let ((backend (vc-backend-deduce file)))
|
|
2042 (cond
|
|
2043 ((eq backend 'SCCS)
|
|
2044 (setq oldvers (vc-lookup-triple file oldvers))
|
|
2045 (setq newvers (vc-lookup-triple file newvers))))
|
|
2046 (cond
|
|
2047 ;; SCCS and RCS shares a lot of code.
|
|
2048 ((or (eq backend 'SCCS) (eq backend 'RCS))
|
|
2049 (let* ((command (if (eq backend 'SCCS)
|
|
2050 "vcdiff"
|
|
2051 "rcsdiff"))
|
|
2052 (mode (if (eq backend 'RCS) 'WORKFILE 'MASTER))
|
|
2053 (options (append (list (and cmp "--brief")
|
|
2054 "-q"
|
|
2055 (and oldvers (concat "-r" oldvers))
|
|
2056 (and newvers (concat "-r" newvers)))
|
|
2057 (and (not cmp)
|
|
2058 (if (listp diff-switches)
|
|
2059 diff-switches
|
|
2060 (list diff-switches)))))
|
|
2061 (status (apply 'vc-do-command 2 command file mode options)))
|
|
2062 ;; Some RCS versions don't understand "--brief"; work around this.
|
|
2063 (if (eq status 2)
|
|
2064 (apply 'vc-do-command 1 command file 'WORKFILE
|
|
2065 (if cmp (cdr options) options))
|
|
2066 status)))
|
|
2067 ;; CVS is different.
|
|
2068 ;; cmp is not yet implemented -- we always do a full diff.
|
|
2069 ((eq backend 'CVS)
|
|
2070 (if (string= (vc-file-getprop file 'vc-your-latest-version) "0") ; CVS
|
|
2071 ;; This file is added but not yet committed; there is no master file.
|
|
2072 ;; diff it against /dev/null.
|
|
2073 (if (or oldvers newvers)
|
|
2074 (error "No revisions of %s exists" file)
|
|
2075 (apply 'vc-do-command
|
|
2076 1 "diff" file 'WORKFILE "/dev/null"
|
|
2077 (if (listp diff-switches)
|
|
2078 diff-switches
|
|
2079 (list diff-switches))))
|
|
2080 (apply 'vc-do-command
|
|
2081 1 "cvs" file 'WORKFILE "diff"
|
|
2082 (and oldvers (concat "-r" oldvers))
|
|
2083 (and newvers (concat "-r" newvers))
|
|
2084 (if (listp diff-switches)
|
|
2085 diff-switches
|
|
2086 (list diff-switches)))))
|
|
2087 ;; ClearCase is completely different.
|
|
2088 ((eq backend 'CC)
|
|
2089 (apply 'vc-do-command 2 "cleardiff" file nil
|
|
2090 (if cmp "-status_only")
|
|
2091 (concat file "@@"
|
|
2092 (or oldvers
|
|
2093 (vc-file-getprop file 'vc-cc-predecessor)))
|
|
2094 (if newvers
|
|
2095 (concat file "@@" newvers)
|
|
2096 file)
|
|
2097 nil))
|
|
2098 (t
|
|
2099 (vc-registration-error file)))))
|
|
2100
|
|
2101 (defun vc-backend-merge-news (file)
|
|
2102 ;; Merge in any new changes made to FILE.
|
|
2103 (vc-backend-dispatch
|
|
2104 file
|
|
2105 (error "vc-backend-merge-news not meaningful for SCCS files") ; SCCS
|
|
2106 (error "vc-backend-merge-news not meaningful for RCS files") ; RCS
|
|
2107 (vc-do-command 1 "cvs" file 'WORKFILE "update") ; CVS
|
|
2108 (error "vc-backend-merge-news not meaningful for ClearCase files") ; CC
|
|
2109 ))
|
|
2110
|
|
2111 (defun vc-check-headers ()
|
|
2112 "Check if the current file has any headers in it."
|
|
2113 (interactive)
|
|
2114 (save-excursion
|
|
2115 (goto-char (point-min))
|
|
2116 (vc-backend-dispatch buffer-file-name
|
|
2117 (re-search-forward "%[MIRLBSDHTEGUYFPQCZWA]%" nil t) ; SCCS
|
|
2118 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t) ; RCS
|
|
2119 'RCS ; CVS works like RCS in this regard.
|
|
2120 nil ; ClearCase does not recognise headers.
|
|
2121 )
|
|
2122 ))
|
|
2123
|
|
2124 ;; Back-end-dependent stuff ends here.
|
|
2125
|
|
2126 ;; Set up key bindings for use while editing log messages
|
|
2127
|
|
2128 (defun vc-log-mode ()
|
|
2129 "Minor mode for driving version-control tools.
|
|
2130 These bindings are added to the global keymap when you enter this mode:
|
|
2131 \\[vc-next-action] perform next logical version-control operation on current file
|
|
2132 \\[vc-register] register current file
|
|
2133 \\[vc-toggle-read-only] like next-action, but won't register files
|
|
2134 \\[vc-insert-headers] insert version-control headers in current file
|
|
2135 \\[vc-print-log] display change history of current file
|
|
2136 \\[vc-revert-buffer] revert buffer to latest version
|
|
2137 \\[vc-cancel-version] undo latest checkin
|
|
2138 \\[vc-diff] show diffs between file versions
|
|
2139 \\[vc-version-other-window] visit old version in another window
|
|
2140 \\[vc-directory] show all files locked by any user in or below .
|
|
2141 \\[vc-update-change-log] add change log entry from recent checkins
|
|
2142
|
|
2143 While you are entering a change log message for a version, the following
|
|
2144 additional bindings will be in effect.
|
|
2145
|
|
2146 \\[vc-finish-logentry] proceed with check in, ending log message entry
|
|
2147
|
|
2148 Whenever you do a checkin, your log comment is added to a ring of
|
|
2149 saved comments. These can be recalled as follows:
|
|
2150
|
|
2151 \\[vc-next-comment] replace region with next message in comment ring
|
|
2152 \\[vc-previous-comment] replace region with previous message in comment ring
|
|
2153 \\[vc-comment-search-reverse] search backward for regexp in the comment ring
|
|
2154 \\[vc-comment-search-forward] search backward for regexp in the comment ring
|
|
2155
|
|
2156 Entry to the change-log submode calls the value of text-mode-hook, then
|
|
2157 the value of vc-log-mode-hook.
|
|
2158
|
|
2159 Global user options:
|
|
2160 vc-initial-comment If non-nil, require user to enter a change
|
|
2161 comment upon first checkin of the file.
|
|
2162
|
|
2163 vc-keep-workfiles Non-nil value prevents workfiles from being
|
|
2164 deleted when changes are checked in
|
|
2165
|
|
2166 vc-suppress-confirm Suppresses some confirmation prompts,
|
|
2167 notably for reversions.
|
|
2168
|
|
2169 vc-header-alist Which keywords to insert when adding headers
|
|
2170 with \\[vc-insert-headers]. Defaults to
|
|
2171 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under
|
|
2172 RCS and CVS.
|
|
2173
|
|
2174 vc-static-header-alist By default, version headers inserted in C files
|
|
2175 get stuffed in a static string area so that
|
|
2176 ident(RCS/CVS) or what(SCCS) can see them in
|
|
2177 the compiled object code. You can override
|
|
2178 this by setting this variable to nil, or change
|
|
2179 the header template by changing it.
|
|
2180
|
|
2181 vc-command-messages if non-nil, display run messages from the
|
|
2182 actual version-control utilities (this is
|
|
2183 intended primarily for people hacking vc
|
|
2184 itself).
|
|
2185 "
|
|
2186 (interactive)
|
|
2187 (set-syntax-table text-mode-syntax-table)
|
|
2188 (use-local-map vc-log-entry-mode)
|
|
2189 (setq local-abbrev-table text-mode-abbrev-table)
|
|
2190 (setq major-mode 'vc-log-mode)
|
|
2191 (setq mode-name "VC-Log")
|
|
2192 (make-local-variable 'vc-log-file)
|
|
2193 (make-local-variable 'vc-log-version)
|
|
2194 (make-local-variable 'vc-comment-ring-index)
|
|
2195 (set-buffer-modified-p nil)
|
|
2196 (setq buffer-file-name nil)
|
|
2197 (run-hooks 'text-mode-hook 'vc-log-mode-hook)
|
|
2198 )
|
|
2199
|
|
2200 ;; Initialization code, to be done just once at load-time
|
|
2201 (if vc-log-entry-mode
|
|
2202 nil
|
|
2203 (setq vc-log-entry-mode (make-sparse-keymap))
|
|
2204 (set-keymap-name vc-log-entry-mode 'vc-log-entry-mode) ; XEmacs
|
|
2205 (define-key vc-log-entry-mode "\M-n" 'vc-next-comment)
|
|
2206 (define-key vc-log-entry-mode "\M-p" 'vc-previous-comment)
|
|
2207 (define-key vc-log-entry-mode "\M-r" 'vc-comment-search-reverse)
|
|
2208 (define-key vc-log-entry-mode "\M-s" 'vc-comment-search-forward)
|
|
2209 (define-key vc-log-entry-mode "\C-c\C-c" 'vc-finish-logentry)
|
|
2210 )
|
|
2211
|
|
2212 ;;; These things should probably be generally available
|
|
2213
|
|
2214 (defun vc-file-tree-walk (func &rest args)
|
|
2215 "Walk recursively through default directory.
|
|
2216 Invoke FUNC f ARGS on each non-directory file f underneath it."
|
|
2217 (vc-file-tree-walk-internal default-directory func args)
|
|
2218 (message "Traversing directory %s...done" default-directory))
|
|
2219
|
|
2220 (defun vc-file-tree-walk-internal (file func args)
|
|
2221 (if (not (file-directory-p file))
|
|
2222 (apply func file args)
|
|
2223 (message "Traversing directory %s..." file)
|
|
2224 (let ((dir (file-name-as-directory file)))
|
|
2225 (mapcar
|
|
2226 (function
|
|
2227 (lambda (f) (or
|
|
2228 (string-equal f ".")
|
|
2229 (string-equal f "..")
|
|
2230 (member f vc-directory-exclusion-list)
|
|
2231 (let ((dirf (concat dir f)))
|
|
2232 (or
|
|
2233 (file-symlink-p dirf) ; Avoid possible loops
|
|
2234 (vc-file-tree-walk-internal dirf func args))))))
|
|
2235 (directory-files dir)))))
|
|
2236
|
|
2237 (defun vc-dir-all-files (func &rest args)
|
|
2238 "Invoke FUNC f ARGS on each regular file f in default directory."
|
|
2239 (let ((dir default-directory))
|
|
2240 (message "Scanning directory %s..." dir)
|
|
2241 (mapcar (function (lambda (f)
|
|
2242 (let ((dirf (expand-file-name f dir)))
|
|
2243 (if (not (file-directory-p dirf))
|
|
2244 (apply func dirf args)))))
|
|
2245 (directory-files dir))
|
|
2246 (message "Scanning directory %s...done" dir)))
|
|
2247
|
|
2248 (provide 'vc)
|
|
2249
|
|
2250 ;;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
|
|
2251 ;;;
|
|
2252 ;;; These may be useful to anyone who has to debug or extend the package.
|
|
2253 ;;;
|
|
2254 ;;; A fundamental problem in VC is that there are time windows between
|
|
2255 ;;; vc-next-action's computations of the file's version-control state and
|
|
2256 ;;; the actions that change it. This is a window open to lossage in a
|
|
2257 ;;; multi-user environment; someone else could nip in and change the state
|
|
2258 ;;; of the master during it.
|
|
2259 ;;;
|
|
2260 ;;; The performance problem is that rlog/prs calls are very expensive; we want
|
|
2261 ;;; to avoid them as much as possible.
|
|
2262 ;;;
|
|
2263 ;;; ANALYSIS:
|
|
2264 ;;;
|
|
2265 ;;; The performance problem, it turns out, simplifies in practice to the
|
|
2266 ;;; problem of making vc-locking-user fast. The two other functions that call
|
|
2267 ;;; prs/rlog will not be so commonly used that the slowdown is a problem; one
|
|
2268 ;;; makes snapshots, the other deletes the calling user's last change in the
|
|
2269 ;;; master.
|
|
2270 ;;;
|
|
2271 ;;; The race condition implies that we have to either (a) lock the master
|
|
2272 ;;; during the entire execution of vc-next-action, or (b) detect and
|
|
2273 ;;; recover from errors resulting from dispatch on an out-of-date state.
|
|
2274 ;;;
|
|
2275 ;;; Alternative (a) appears to be unfeasible. The problem is that we can't
|
|
2276 ;;; guarantee that the lock will ever be removed. Suppose a user starts a
|
|
2277 ;;; checkin, the change message buffer pops up, and the user, having wandered
|
|
2278 ;;; off to do something else, simply forgets about it?
|
|
2279 ;;;
|
|
2280 ;;; Alternative (b), on the other hand, works well with a cheap way to speed up
|
|
2281 ;;; vc-locking-user. Usually, if a file is registered, we can read its locked/
|
|
2282 ;;; unlocked state and its current owner from its permissions.
|
|
2283 ;;;
|
|
2284 ;;; This shortcut will fail if someone has manually changed the workfile's
|
|
2285 ;;; permissions; also if developers are munging the workfile in several
|
|
2286 ;;; directories, with symlinks to a master (in this latter case, the
|
|
2287 ;;; permissions shortcut will fail to detect a lock asserted from another
|
|
2288 ;;; directory).
|
|
2289 ;;;
|
|
2290 ;;; Note that these cases correspond exactly to the errors which could happen
|
|
2291 ;;; because of a competing checkin/checkout race in between two instances of
|
|
2292 ;;; vc-next-action.
|
|
2293 ;;;
|
|
2294 ;;; For VC's purposes, a workfile/master pair may have the following states:
|
|
2295 ;;;
|
|
2296 ;;; A. Unregistered. There is a workfile, there is no master.
|
|
2297 ;;;
|
|
2298 ;;; B. Registered and not locked by anyone.
|
|
2299 ;;;
|
|
2300 ;;; C. Locked by calling user and unchanged.
|
|
2301 ;;;
|
|
2302 ;;; D. Locked by the calling user and changed.
|
|
2303 ;;;
|
|
2304 ;;; E. Locked by someone other than the calling user.
|
|
2305 ;;;
|
|
2306 ;;; This makes for 25 states and 20 error conditions. Here's the matrix:
|
|
2307 ;;;
|
|
2308 ;;; VC's idea of state
|
|
2309 ;;; |
|
|
2310 ;;; V Actual state RCS action SCCS action Effect
|
|
2311 ;;; A B C D E
|
|
2312 ;;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
|
|
2313 ;;; B 5 . 6 7 8 co -l get -e checkout
|
|
2314 ;;; C 9 10 . 11 12 co -u unget; get revert
|
|
2315 ;;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
|
|
2316 ;;; E 17 18 19 20 . rcs -u -M ; rcs -l unget -n ; get -g steal lock
|
|
2317 ;;;
|
|
2318 ;;; All commands take the master file name as a last argument (not shown).
|
|
2319 ;;;
|
|
2320 ;;; In the discussion below, a "self-race" is a pathological situation in
|
|
2321 ;;; which VC operations are being attempted simultaneously by two or more
|
|
2322 ;;; Emacsen running under the same username.
|
|
2323 ;;;
|
|
2324 ;;; The vc-next-action code has the following windows:
|
|
2325 ;;;
|
|
2326 ;;; Window P:
|
|
2327 ;;; Between the check for existence of a master file and the call to
|
|
2328 ;;; admin/checkin in vc-buffer-admin (apparent state A). This window may
|
|
2329 ;;; never close if the initial-comment feature is on.
|
|
2330 ;;;
|
|
2331 ;;; Window Q:
|
|
2332 ;;; Between the call to vc-workfile-unchanged-p in and the immediately
|
|
2333 ;;; following revert (apparent state C).
|
|
2334 ;;;
|
|
2335 ;;; Window R:
|
|
2336 ;;; Between the call to vc-workfile-unchanged-p in and the following
|
|
2337 ;;; checkin (apparent state D). This window may never close.
|
|
2338 ;;;
|
|
2339 ;;; Window S:
|
|
2340 ;;; Between the unlock and the immediately following checkout during a
|
|
2341 ;;; revert operation (apparent state C). Included in window Q.
|
|
2342 ;;;
|
|
2343 ;;; Window T:
|
|
2344 ;;; Between vc-locking-user and the following checkout (apparent state B).
|
|
2345 ;;;
|
|
2346 ;;; Window U:
|
|
2347 ;;; Between vc-locking-user and the following revert (apparent state C).
|
|
2348 ;;; Includes windows Q and S.
|
|
2349 ;;;
|
|
2350 ;;; Window V:
|
|
2351 ;;; Between vc-locking-user and the following checkin (apparent state
|
|
2352 ;;; D). This window may never be closed if the user fails to complete the
|
|
2353 ;;; checkin message. Includes window R.
|
|
2354 ;;;
|
|
2355 ;;; Window W:
|
|
2356 ;;; Between vc-locking-user and the following steal-lock (apparent
|
|
2357 ;;; state E). This window may never close if the user fails to complete
|
|
2358 ;;; the steal-lock message. Includes window X.
|
|
2359 ;;;
|
|
2360 ;;; Window X:
|
|
2361 ;;; Between the unlock and the immediately following re-lock during a
|
|
2362 ;;; steal-lock operation (apparent state E). This window may never cloce
|
|
2363 ;;; if the user fails to complete the steal-lock message.
|
|
2364 ;;;
|
|
2365 ;;; Errors:
|
|
2366 ;;;
|
|
2367 ;;; Apparent state A ---
|
|
2368 ;;;
|
|
2369 ;;; 1. File looked unregistered but is actually registered and not locked.
|
|
2370 ;;;
|
|
2371 ;;; Potential cause: someone else's admin during window P, with
|
|
2372 ;;; caller's admin happening before their checkout.
|
|
2373 ;;;
|
|
2374 ;;; RCS: ci will fail with a "no lock set by <user>" message.
|
|
2375 ;;; SCCS: admin will fail with error (ad19).
|
|
2376 ;;;
|
|
2377 ;;; We can let these errors be passed up to the user.
|
|
2378 ;;;
|
|
2379 ;;; 2. File looked unregistered but is actually locked by caller, unchanged.
|
|
2380 ;;;
|
|
2381 ;;; Potential cause: self-race during window P.
|
|
2382 ;;;
|
|
2383 ;;; RCS: will revert the file to the last saved version and unlock it.
|
|
2384 ;;; SCCS: will fail with error (ad19).
|
|
2385 ;;;
|
|
2386 ;;; Either of these consequences is acceptable.
|
|
2387 ;;;
|
|
2388 ;;; 3. File looked unregistered but is actually locked by caller, changed.
|
|
2389 ;;;
|
|
2390 ;;; Potential cause: self-race during window P.
|
|
2391 ;;;
|
|
2392 ;;; RCS: will register the caller's workfile as a delta with a
|
|
2393 ;;; null change comment (the -t- switch will be ignored).
|
|
2394 ;;; SCCS: will fail with error (ad19).
|
|
2395 ;;;
|
|
2396 ;;; 4. File looked unregistered but is locked by someone else.
|
|
2397 ;;;
|
|
2398 ;;; Potential cause: someone else's admin during window P, with
|
|
2399 ;;; caller's admin happening *after* their checkout.
|
|
2400 ;;;
|
|
2401 ;;; RCS: will fail with a "no lock set by <user>" message.
|
|
2402 ;;; SCCS: will fail with error (ad19).
|
|
2403 ;;;
|
|
2404 ;;; We can let these errors be passed up to the user.
|
|
2405 ;;;
|
|
2406 ;;; Apparent state B ---
|
|
2407 ;;;
|
|
2408 ;;; 5. File looked registered and not locked, but is actually unregistered.
|
|
2409 ;;;
|
|
2410 ;;; Potential cause: master file got nuked during window P.
|
|
2411 ;;;
|
|
2412 ;;; RCS: will fail with "RCS/<file>: No such file or directory"
|
|
2413 ;;; SCCS: will fail with error ut4.
|
|
2414 ;;;
|
|
2415 ;;; We can let these errors be passed up to the user.
|
|
2416 ;;;
|
|
2417 ;;; 6. File looked registered and not locked, but is actually locked by the
|
|
2418 ;;; calling user and unchanged.
|
|
2419 ;;;
|
|
2420 ;;; Potential cause: self-race during window T.
|
|
2421 ;;;
|
|
2422 ;;; RCS: in the same directory as the previous workfile, co -l will fail
|
|
2423 ;;; with "co error: writable foo exists; checkout aborted". In any other
|
|
2424 ;;; directory, checkout will succeed.
|
|
2425 ;;; SCCS: will fail with ge17.
|
|
2426 ;;;
|
|
2427 ;;; Either of these consequences is acceptable.
|
|
2428 ;;;
|
|
2429 ;;; 7. File looked registered and not locked, but is actually locked by the
|
|
2430 ;;; calling user and changed.
|
|
2431 ;;;
|
|
2432 ;;; As case 6.
|
|
2433 ;;;
|
|
2434 ;;; 8. File looked registered and not locked, but is actually locked by another
|
|
2435 ;;; user.
|
|
2436 ;;;
|
|
2437 ;;; Potential cause: someone else checks it out during window T.
|
|
2438 ;;;
|
|
2439 ;;; RCS: co error: revision 1.3 already locked by <user>
|
|
2440 ;;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
|
|
2441 ;;;
|
|
2442 ;;; We can let these errors be passed up to the user.
|
|
2443 ;;;
|
|
2444 ;;; Apparent state C ---
|
|
2445 ;;;
|
|
2446 ;;; 9. File looks locked by calling user and unchanged, but is unregistered.
|
|
2447 ;;;
|
|
2448 ;;; As case 5.
|
|
2449 ;;;
|
|
2450 ;;; 10. File looks locked by calling user and unchanged, but is actually not
|
|
2451 ;;; locked.
|
|
2452 ;;;
|
|
2453 ;;; Potential cause: a self-race in window U, or by the revert's
|
|
2454 ;;; landing during window X of some other user's steal-lock or window S
|
|
2455 ;;; of another user's revert.
|
|
2456 ;;;
|
|
2457 ;;; RCS: succeeds, refreshing the file from the identical version in
|
|
2458 ;;; the master.
|
|
2459 ;;; SCCS: fails with error ut4 (p file nonexistent).
|
|
2460 ;;;
|
|
2461 ;;; Either of these consequences is acceptable.
|
|
2462 ;;;
|
|
2463 ;;; 11. File is locked by calling user. It looks unchanged, but is actually
|
|
2464 ;;; changed.
|
|
2465 ;;;
|
|
2466 ;;; Potential cause: the file would have to be touched by a self-race
|
|
2467 ;;; during window Q.
|
|
2468 ;;;
|
|
2469 ;;; The revert will succeed, removing whatever changes came with
|
|
2470 ;;; the touch. It is theoretically possible that work could be lost.
|
|
2471 ;;;
|
|
2472 ;;; 12. File looks like it's locked by the calling user and unchanged, but
|
|
2473 ;;; it's actually locked by someone else.
|
|
2474 ;;;
|
|
2475 ;;; Potential cause: a steal-lock in window V.
|
|
2476 ;;;
|
|
2477 ;;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
|
|
2478 ;;; SCCS: fails with error un2
|
|
2479 ;;;
|
|
2480 ;;; We can pass these errors up to the user.
|
|
2481 ;;;
|
|
2482 ;;; Apparent state D ---
|
|
2483 ;;;
|
|
2484 ;;; 13. File looks like it's locked by the calling user and changed, but it's
|
|
2485 ;;; actually unregistered.
|
|
2486 ;;;
|
|
2487 ;;; Potential cause: master file got nuked during window P.
|
|
2488 ;;;
|
|
2489 ;;; RCS: Checks in the user's version as an initial delta.
|
|
2490 ;;; SCCS: will fail with error ut4.
|
|
2491 ;;;
|
|
2492 ;;; This case is kind of nasty. It means VC may fail to detect the
|
|
2493 ;;; loss of previous version information.
|
|
2494 ;;;
|
|
2495 ;;; 14. File looks like it's locked by the calling user and changed, but it's
|
|
2496 ;;; actually unlocked.
|
|
2497 ;;;
|
|
2498 ;;; Potential cause: self-race in window V, or the checkin happening
|
|
2499 ;;; during the window X of someone else's steal-lock or window S of
|
|
2500 ;;; someone else's revert.
|
|
2501 ;;;
|
|
2502 ;;; RCS: ci will fail with "no lock set by <user>".
|
|
2503 ;;; SCCS: delta will fail with error ut4.
|
|
2504 ;;;
|
|
2505 ;;; 15. File looks like it's locked by the calling user and changed, but it's
|
|
2506 ;;; actually locked by the calling user and unchanged.
|
|
2507 ;;;
|
|
2508 ;;; Potential cause: another self-race --- a whole checkin/checkout
|
|
2509 ;;; sequence by the calling user would have to land in window R.
|
|
2510 ;;;
|
|
2511 ;;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
|
|
2512 ;;; RCS: reverts to the file state as of the second user's checkin, leaving
|
|
2513 ;;; the file unlocked.
|
|
2514 ;;;
|
|
2515 ;;; It is theoretically possible that work could be lost under RCS.
|
|
2516 ;;;
|
|
2517 ;;; 16. File looks like it's locked by the calling user and changed, but it's
|
|
2518 ;;; actually locked by a different user.
|
|
2519 ;;;
|
|
2520 ;;; RCS: ci error: no lock set by <user>
|
|
2521 ;;; SCCS: unget will fail with error un2
|
|
2522 ;;;
|
|
2523 ;;; We can pass these errors up to the user.
|
|
2524 ;;;
|
|
2525 ;;; Apparent state E ---
|
|
2526 ;;;
|
|
2527 ;;; 17. File looks like it's locked by some other user, but it's actually
|
|
2528 ;;; unregistered.
|
|
2529 ;;;
|
|
2530 ;;; As case 13.
|
|
2531 ;;;
|
|
2532 ;;; 18. File looks like it's locked by some other user, but it's actually
|
|
2533 ;;; unlocked.
|
|
2534 ;;;
|
|
2535 ;;; Potential cause: someone released a lock during window W.
|
|
2536 ;;;
|
|
2537 ;;; RCS: The calling user will get the lock on the file.
|
|
2538 ;;; SCCS: unget -n will fail with cm4.
|
|
2539 ;;;
|
|
2540 ;;; Either of these consequences will be OK.
|
|
2541 ;;;
|
|
2542 ;;; 19. File looks like it's locked by some other user, but it's actually
|
|
2543 ;;; locked by the calling user and unchanged.
|
|
2544 ;;;
|
|
2545 ;;; Potential cause: the other user relinquishing a lock followed by
|
|
2546 ;;; a self-race, both in window W.
|
|
2547 ;;;
|
|
2548 ;;; Under both RCS and SCCS, both unlock and lock will succeed, making
|
|
2549 ;;; the sequence a no-op.
|
|
2550 ;;;
|
|
2551 ;;; 20. File looks like it's locked by some other user, but it's actually
|
|
2552 ;;; locked by the calling user and changed.
|
|
2553 ;;;
|
|
2554 ;;; As case 19.
|
|
2555 ;;;
|
|
2556 ;;; PROBLEM CASES:
|
|
2557 ;;;
|
|
2558 ;;; In order of decreasing severity:
|
|
2559 ;;;
|
|
2560 ;;; Cases 11 and 15 under RCS are the only one that potentially lose work.
|
|
2561 ;;; They would require a self-race for this to happen.
|
|
2562 ;;;
|
|
2563 ;;; Case 13 in RCS loses information about previous deltas, retaining
|
|
2564 ;;; only the information in the current workfile. This can only happen
|
|
2565 ;;; if the master file gets nuked in window P.
|
|
2566 ;;;
|
|
2567 ;;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
|
|
2568 ;;; no change comment in the master. This would require a self-race in
|
|
2569 ;;; window P or R respectively.
|
|
2570 ;;;
|
|
2571 ;;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
|
|
2572 ;;;
|
|
2573 ;;; Unfortunately, it appears to me that no recovery is possible in these
|
|
2574 ;;; cases. They don't yield error messages, so there's no way to tell that
|
|
2575 ;;; a race condition has occurred.
|
|
2576 ;;;
|
|
2577 ;;; All other cases don't change either the workfile or the master, and
|
|
2578 ;;; trigger command errors which the user will see.
|
|
2579 ;;;
|
|
2580 ;;; Thus, there is no explicit recovery code.
|
|
2581
|
|
2582 ;;; vc.el ends here
|