904
|
1 ;;; vc.el --- drive a version-control system from within Emacs
|
|
2
|
|
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
|
|
6 ;; Version: 4.0
|
|
7
|
|
8 ;; $Id: vc.el,v 1.58 1992/07/31 07:17:21 esr Exp $
|
|
9
|
|
10 ;; This file is part of GNU Emacs.
|
|
11
|
|
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
13 ;; it under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 ;; GNU General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with GNU Emacs; see the file COPYING. If not, write to
|
|
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
25
|
|
26 ;;; Commentary:
|
|
27
|
|
28 ;; This was designed and implemented by Eric Raymond <esr@snark.thyrsus.com>.
|
|
29 ;; Paul Eggert <eggert@twinsun.com>, Sebastian Kremer <sk@thp.uni-koeln.de>,
|
|
30 ;; and Richard Stallman contributed valuable criticism, support, and testing.
|
|
31 ;;
|
|
32 ;; Supported version-control systems presently include SCCS and RCS;
|
|
33 ;; your RCS version should be 5.6.2 or later for proper operation of
|
|
34 ;; the lock-breaking code.
|
|
35 ;;
|
|
36 ;; The RCS code assumes strict locking. You can support the RCS -x option
|
|
37 ;; by adding pairs to the vc-master-templates list.
|
|
38 ;;
|
|
39 ;; Proper function of the SCCS diff commands requires the shellscript vcdiff
|
|
40 ;; to be installed somewhere on Emacs's path for executables.
|
|
41 ;;
|
|
42 ;; This code depends on call-process passing back the subprocess exit
|
|
43 ;; status. Thus, you need Emacs 18.58 or later to run it.
|
|
44 ;;
|
|
45 ;; The vc code maintains some internal state in order to reduce expensive
|
|
46 ;; version-control operations to a minimum. Some names are only computed
|
|
47 ;; once. If you perform version control operations with RCS/SCCS/CVS while
|
|
48 ;; vc's back is turned, or move/rename master files while vc is running,
|
|
49 ;; vc may get seriously confused. Don't do these things!
|
|
50 ;;
|
|
51 ;; Developer's notes on some concurrency issues are included at the end of
|
|
52 ;; the file.
|
|
53
|
|
54 ;;; Code:
|
|
55
|
|
56 (require 'vc-hooks)
|
|
57
|
|
58 ;; General customization
|
|
59
|
|
60 (defvar vc-default-back-end nil
|
|
61 "*Back-end actually used by this interface; may be SCCS or RCS.
|
|
62 The value is only computed when needed to avoid an expensive search.")
|
|
63 (defvar vc-diff-options '("-a" "-c1")
|
|
64 "*The command/flags list to be used in constructing diff commands.")
|
|
65 (defvar vc-suppress-confirm nil
|
|
66 "*If non-nil, reat user as expert; suppress yes-no prompts on some things.")
|
|
67 (defvar vc-keep-workfiles t
|
|
68 "*If non-nil, don't delete working files after registering changes.")
|
|
69 (defvar vc-initial-comment nil
|
|
70 "*Prompt for initial comment when a file is registered.")
|
|
71 (defvar vc-command-messages nil
|
|
72 "*Display run messages from back-end commands.")
|
|
73 (defvar vc-mistrust-permissions 'file-symlink-p
|
|
74 "*Don't assume that permissions and ownership track version-control status.")
|
|
75
|
|
76 ;; Header-insertion hair
|
|
77
|
|
78 (defvar vc-header-alist
|
|
79 '((SCCS "\%W\%") (RCS "\$Id\$"))
|
|
80 "*Header keywords to be inserted when vc-insert-header is executed.")
|
|
81 (defconst vc-static-header-alist
|
|
82 '(("\\.c$" .
|
|
83 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n"))
|
|
84 "*Associate static header string templates with file types. A \%s in the
|
|
85 template is replaced with the first string associated with the file's
|
|
86 verson-control type in vc-header-strings.")
|
|
87 (defvar vc-comment-alist
|
|
88 '((nroff-mode ".\\\"" ""))
|
|
89 "*Special comment delimiters to be used in generating vc headers only.
|
|
90 Add an entry in this list if you need to override the normal comment-start
|
|
91 and comment-end variables. This will only be necessary if the mode language
|
|
92 is sensitive to blank lines.")
|
|
93
|
|
94 ;; Variables the user doesn't need to know about.
|
|
95 (defvar vc-log-entry-mode nil)
|
|
96 (defvar vc-log-operation nil)
|
|
97
|
|
98 (defconst vc-name-assoc-file "VC-names")
|
|
99
|
|
100 (defmacro vc-error-occurred (&rest body)
|
|
101 (list 'condition-case nil (cons 'progn (append body '(nil))) '(error t)))
|
|
102
|
|
103 ;; File property caching
|
|
104
|
|
105 (defun vc-file-clearprops (file)
|
|
106 ;; clear all properties of a given file
|
|
107 (setplist (intern file vc-file-prop-obarray) nil))
|
|
108
|
|
109 ;; Random helper functions
|
|
110
|
|
111 (defun vc-name (file)
|
|
112 "Return the master name of a file, nil if it is not registered"
|
|
113 (or (vc-file-getprop file 'vc-name)
|
|
114 (vc-file-setprop file 'vc-name
|
|
115 (let ((name-and-type (vc-registered file)))
|
|
116 (and name-and-type (car name-and-type))))))
|
|
117
|
|
118 (defvar vc-binary-assoc nil)
|
|
119
|
|
120 (defun vc-find-binary (name)
|
|
121 "Look for a command anywhere on the subprocess-command search path."
|
|
122 (or (cdr (assoc name vc-binary-assoc))
|
|
123 (let ((full nil))
|
|
124 (catch 'found
|
|
125 (mapcar
|
|
126 (function (lambda (s)
|
|
127 (if (and s (file-exists-p (setq full (concat s "/" name))))
|
|
128 (throw 'found nil))))
|
|
129 exec-path))
|
|
130 (if full
|
|
131 (setq vc-binary-assoc (cons (cons name full) vc-binary-assoc)))
|
|
132 full)))
|
|
133
|
|
134 (defun vc-do-command (okstatus command file &rest flags)
|
|
135 "Execute a version-control command, notifying user and checking for errors.
|
|
136 The command is successful if its exit status does not exceed OKSTATUS.
|
|
137 Output from COMMAND goes to buffer *vc*. The last argument of the command is
|
|
138 the master name of FILE; this is appended to an optional list of FLAGS."
|
|
139 (setq file (expand-file-name file))
|
|
140 (if vc-command-messages
|
|
141 (message (format "Running %s on %s..." command file)))
|
|
142 (let ((obuf (current-buffer))
|
|
143 (squeezed nil)
|
|
144 (vc-file (and file (vc-name file)))
|
|
145 status)
|
|
146 (set-buffer (get-buffer-create "*vc*"))
|
|
147 (erase-buffer)
|
|
148 (mapcar
|
|
149 (function (lambda (s) (and s (setq squeezed (append squeezed (list s))))))
|
|
150 flags)
|
|
151 (if vc-file
|
|
152 (setq squeezed (append squeezed (list vc-file))))
|
|
153 (let
|
|
154 ((default-directory (file-name-directory (or file "./"))))
|
|
155 (setq status (apply 'call-process command nil t nil squeezed))
|
|
156 )
|
|
157 (goto-char (point-max))
|
|
158 (previous-line 1)
|
|
159 (if (or (not (integerp status)) (< okstatus status))
|
|
160 (progn
|
|
161 (previous-line 1)
|
|
162 (print (cons command squeezed))
|
|
163 (next-line 1)
|
|
164 (pop-to-buffer "*vc*")
|
|
165 (vc-shrink-to-fit)
|
|
166 (goto-char (point-min))
|
|
167 (error (format "Running %s...FAILED (%s)" command
|
|
168 (if (integerp status)
|
|
169 (format "status %d" status)
|
|
170 status)))
|
|
171 )
|
|
172 (if vc-command-messages
|
|
173 (message (format "Running %s...OK" command)))
|
|
174 )
|
|
175 (set-buffer obuf)
|
|
176 status)
|
|
177 )
|
|
178
|
|
179 (defun vc-revert-buffer1 (&optional arg no-confirm)
|
|
180 ;; This code was shamelessly lifted from Sebastian Kremer's rcs.el mode.
|
|
181 ;; Revert buffer, try to keep point where user expects it in spite
|
|
182 ;; of changes because of expanded version-control key words.
|
|
183 ;; This is quite important since otherwise typeahead won't work as expected.
|
|
184 (interactive "P")
|
|
185 (widen)
|
|
186 (let* ((opoint (point))
|
|
187 (osize (buffer-size))
|
|
188 diff
|
|
189 (context 100)
|
|
190 (ostring (buffer-substring (point)
|
|
191 (min (point-max)
|
|
192 (+ (point) context))))
|
|
193 (l (length ostring)))
|
|
194 (revert-buffer arg no-confirm)
|
|
195 (setq diff (- osize (buffer-size)))
|
|
196 (if (< diff 0) (setq diff (- diff)))
|
|
197 (goto-char opoint)
|
|
198 (cond ((equal "" ostring)
|
|
199 (goto-char (point-max)))
|
|
200 ((or (search-forward ostring nil t)
|
|
201 ;; Can't use search-backward since the match may continue
|
|
202 ;; after point.
|
|
203 (progn (goto-char (- (point) diff l))
|
|
204 ;; goto-char doesn't signal an error at
|
|
205 ;; beginning of buffer like backward-char would
|
|
206 (search-forward ostring nil t)))
|
|
207 ;; to beginning of OSTRING
|
|
208 (backward-char l)))))
|
|
209
|
|
210 (defun vc-buffer-sync ()
|
|
211 ;; Make sure the current buffer and its working file are in sync
|
|
212 (if (and (buffer-modified-p)
|
|
213 (or
|
|
214 vc-suppress-confirm
|
|
215 (y-or-n-p (format "%s has been modified. Write it out? "
|
|
216 (buffer-name)))))
|
|
217 (save-buffer)))
|
|
218
|
|
219 (defun vc-workfile-unchanged-p (file)
|
|
220 ;; Has the given workfile changed since last checkout?
|
|
221 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time))
|
|
222 (lastmod (nth 5 (file-attributes file))))
|
|
223 (if checkout-time
|
|
224 (equal lastmod checkout-time)
|
|
225 (if (zerop (vc-backend-diff file nil))
|
|
226 (progn
|
|
227 (vc-file-setprop file 'vc-checkout-time lastmod)
|
|
228 t)
|
|
229 (progn
|
|
230 (vc-file-setprop file 'vc-checkout-time '(0 . 0))
|
|
231 nil
|
|
232 ))
|
|
233 )))
|
|
234
|
927
|
235 ;; Here's the major entry point.
|
904
|
236
|
927
|
237 ;;;###autoload
|
904
|
238 (defun vc-next-action (verbose)
|
|
239 "Do the next logical checkin or checkout operation on the current file.
|
|
240 If the file is not already registered, this registers it for version
|
|
241 control and then retrieves a writeable, locked copy for editing.
|
|
242 If the file is registered and not locked by anyone, this checks out
|
|
243 a writeable and locked file ready for editing.
|
|
244 If the file is checked out and locked by the calling user, this
|
|
245 first checks to see if the file has changed since checkout. If not,
|
|
246 it performs a revert.
|
|
247 If the file has been changed, this pops up a buffer for creation of
|
|
248 a log message; when the message has been entered, it checks in the
|
|
249 resulting changes along with the log message as change commentary. If
|
|
250 the variable vc-keep-workfiles is non-nil (which is its default), a
|
|
251 read-only copy of the changed file is left in place afterwards.
|
|
252 If the file is registered and locked by someone else, you are given
|
|
253 the option to steal the lock."
|
|
254 (interactive "P")
|
|
255 (if buffer-file-name
|
|
256 (let
|
|
257 (do-update owner version
|
|
258 (file buffer-file-name)
|
|
259 (vc-file (vc-name buffer-file-name))
|
|
260 (err-msg nil)
|
|
261 owner)
|
|
262
|
|
263 (cond
|
|
264
|
|
265 ;; if there is no master file corresponding, create one
|
|
266 ((not vc-file)
|
|
267 (vc-register verbose)
|
|
268 (vc-next-action verbose))
|
|
269
|
|
270 ;; if there is no lock on the file, assert one and get it
|
|
271 ((not (setq owner (vc-locking-user file)))
|
|
272 (vc-checkout file t))
|
|
273
|
|
274 ;; a checked-out version exists, but the user may not own the lock
|
|
275 ((not (string-equal owner (user-login-name)))
|
|
276 (vc-steal-lock
|
|
277 file
|
|
278 (and verbose (read-string "Version to steal: "))
|
|
279 owner))
|
|
280
|
|
281 ;; OK, user owns the lock on the file
|
|
282 (t (progn
|
|
283
|
|
284 ;; give luser a chance to save before checking in.
|
|
285 (vc-buffer-sync)
|
|
286
|
|
287 ;; revert if file is unchanged
|
|
288 (if (vc-workfile-unchanged-p file)
|
|
289 (progn
|
|
290 (vc-backend-revert file)
|
|
291 (vc-resynch-window file t))
|
|
292
|
|
293 ;; user may want to set nonstandard parameters
|
|
294 (if verbose
|
|
295 (setq version (read-string "New version level: ")))
|
|
296
|
|
297 ;; OK, let's do the checkin
|
|
298 (vc-checkin file version))))))
|
|
299 (error "There is no file associated with buffer %s" (buffer-name))))
|
|
300
|
|
301 ;;; These functions help the vc-next-action entry point
|
|
302
|
927
|
303 ;;;###autoload
|
904
|
304 (defun vc-register (&optional override)
|
|
305 "Register the current file into your version-control system."
|
|
306 (interactive "P")
|
|
307 (if (vc-name buffer-file-name)
|
|
308 (error "This file is already registered."))
|
|
309 (vc-buffer-sync)
|
|
310 (vc-admin
|
|
311 buffer-file-name
|
|
312 (and override (read-string "Initial version level: ")))
|
|
313 )
|
|
314
|
|
315 (defun vc-resynch-window (file &optional keep)
|
|
316 ;; If the given file is in the current buffer,
|
|
317 ;; either revert on it so we see expanded keyworks,
|
|
318 ;; or unvisit it (depending on vc-keep-workfiles)
|
|
319 (and (string= buffer-file-name file)
|
|
320 (if keep
|
|
321 (progn
|
|
322 (vc-revert-buffer1 nil t)
|
|
323 (vc-mode-line buffer-file-name))
|
|
324 (progn
|
|
325 (delete-window)
|
|
326 (kill-buffer (current-buffer))))))
|
|
327
|
|
328
|
|
329 (defun vc-admin (file rev)
|
|
330 "Checks a file into your version-control system.
|
|
331 FILE is the unmodified name of the file. REV should be the base version
|
|
332 level to check it in under."
|
|
333 (if vc-initial-comment
|
|
334 (progn
|
|
335 (pop-to-buffer (get-buffer-create "*VC-log*"))
|
|
336 (vc-log-mode)
|
|
337 (narrow-to-region (point-max) (point-max))
|
|
338 (vc-mode-line file (file-name-nondirectory file))
|
|
339 (setq vc-log-operation 'vc-backend-admin)
|
|
340 (setq vc-log-file file)
|
|
341 (setq vc-log-version rev)
|
|
342 (message "Enter initial comment. Type C-c C-c when done."))
|
|
343 (progn
|
|
344 (vc-backend-admin file rev)
|
|
345 (vc-resynch-window file vc-keep-workfiles))))
|
|
346
|
|
347 (defun vc-steal-lock (file rev &optional owner)
|
|
348 "Steal the lock on the current workfile."
|
|
349 (interactive)
|
|
350 (if (not owner)
|
|
351 (setq owner (vc-locking-user file)))
|
|
352 (if (not (y-or-n-p (format "Take the lock on %s:%s from %s?" file rev owner)))
|
|
353 (error "Steal cancelled."))
|
|
354 (pop-to-buffer (get-buffer-create "*VC-log*"))
|
|
355 (vc-log-mode)
|
|
356 (narrow-to-region (point-max) (point-max))
|
|
357 (insert
|
|
358 (format "To: %s\n\nI stole the lock on %s:%s, " owner file rev)
|
|
359 (current-time-string)
|
|
360 "\n")
|
|
361 (vc-mode-line file (file-name-nondirectory file))
|
|
362 (setq vc-log-operation 'vc-finish-steal)
|
|
363 (setq vc-log-file file)
|
|
364 (setq vc-log-version rev)
|
|
365 (message "Please explain why you stole the lock. Type C-c C-c when done.")
|
|
366 )
|
|
367
|
|
368 (defun vc-finish-steal (file version)
|
|
369 ;; Actually do the lock acquisition; send the former owner a notification
|
|
370 (vc-backend-steal file version)
|
|
371 (require 'sendmail) ;; (send-mail) isn't on the standard autoload list.
|
|
372 (mail-send)
|
|
373 (vc-resynch-window file t)
|
|
374 )
|
|
375
|
|
376 (defun vc-checkout (file &optional writeable)
|
|
377 "Retrieve a copy of the latest version of the given file."
|
|
378 (vc-backend-checkout file writeable)
|
|
379 (if (string-equal file buffer-file-name)
|
|
380 (vc-resynch-window file t))
|
|
381 )
|
|
382
|
|
383 (defun vc-checkin (file &optional rev comment)
|
|
384 "Check in the file specified by FILE.
|
|
385 The optional argument REV may be a string specifying the new version level
|
|
386 (if nil increment the current level). The file is either retained with write
|
|
387 permissions zeroed, or deleted (according to the value of vc-keep-workfiles).
|
|
388 COMMENT is a comment string; if omitted, a buffer is
|
|
389 popped up to accept a comment."
|
|
390 (pop-to-buffer (get-buffer-create "*VC-log*"))
|
|
391 (vc-log-mode)
|
|
392 (narrow-to-region (point-max) (point-max))
|
|
393 (vc-mode-line file (file-name-nondirectory file))
|
|
394 (setq vc-log-operation 'vc-backend-checkin)
|
|
395 (setq vc-log-file file)
|
|
396 (setq vc-log-version rev)
|
|
397 (message "Enter log message. Type C-c C-c when done.")
|
|
398 (if comment
|
|
399 (progn
|
|
400 (insert comment)
|
|
401 (vc-finish-logentry))))
|
|
402
|
|
403 (defun vc-finish-logentry ()
|
|
404 "Complete the operation implied by the current log entry."
|
|
405 (interactive)
|
|
406 (goto-char (point-max))
|
|
407 (if (not (bolp)) (newline))
|
|
408 ;; delimit current page
|
|
409 (save-excursion
|
|
410 (widen)
|
|
411 (goto-char (point-max))
|
|
412 (if (and (not (bobp)) (not (= (char-after (1- (point))) ?\f)))
|
|
413 (insert-char ?\f 1)))
|
|
414 (if (not (bobp))
|
|
415 (forward-char -1))
|
|
416 (mark-page)
|
|
417 ;; Check for errors
|
|
418 (vc-backend-logentry-check vc-log-file)
|
|
419 ;; OK, do it to it
|
|
420 (if vc-log-operation
|
|
421 (funcall vc-log-operation
|
|
422 vc-log-file
|
|
423 vc-log-version
|
|
424 (buffer-substring (region-beginning) (1- (region-end))))
|
|
425 (error "No log operation is pending."))
|
|
426 ;; Return to "parent" buffer of this checkin and remove checkin window
|
|
427 (pop-to-buffer (get-file-buffer vc-log-file))
|
|
428 (delete-window (get-buffer-window "*VC-log*"))
|
|
429 (bury-buffer "*VC-log*")
|
|
430 ;; Now make sure we see the expanded headers
|
|
431 (vc-resynch-window buffer-file-name vc-keep-workfiles)
|
|
432 )
|
|
433
|
|
434 ;; Code for access to the comment ring
|
|
435
|
|
436 (defun vc-next-comment ()
|
|
437 "Fill the log buffer with the next message in the msg ring."
|
|
438 (interactive)
|
|
439 (widen)
|
|
440 (forward-page)
|
|
441 (if (= (point) (point-max))
|
|
442 (goto-char (point-min)))
|
|
443 (mark-page)
|
|
444 (narrow-to-page))
|
|
445
|
|
446 (defun vc-previous-comment ()
|
|
447 "Fill the log buffer with the previous message in the msg ring."
|
|
448 (interactive)
|
|
449 (widen)
|
|
450 (if (= (point) (point-min))
|
|
451 (goto-char (point-max)))
|
|
452 (backward-page)
|
|
453 (mark-page)
|
|
454 (narrow-to-page))
|
|
455
|
|
456 (defun vc-comment-search-backward (regexp)
|
|
457 "Fill the log buffer with the last message in the msg ring matching REGEXP."
|
|
458 (interactive "sSearch backward for: ")
|
|
459 (widen)
|
|
460 (if (= (point) (point-min))
|
|
461 (goto-char (point-max)))
|
|
462 (re-search-backward regexp nil t)
|
|
463 (mark-page)
|
|
464 (narrow-to-page))
|
|
465
|
|
466 (defun vc-comment-search-forward (regexp)
|
|
467 "Fill the log buffer with the next message in the msg ring matching REGEXP."
|
|
468 (interactive "sSearch forward for: ")
|
|
469 (widen)
|
|
470 (if (= (point) (point-min))
|
|
471 (goto-char (point-max)))
|
|
472 (re-search-forward regexp nil t)
|
|
473 (mark-page)
|
|
474 (narrow-to-page))
|
|
475
|
|
476 ;; Additional entry points for examining version histories
|
|
477
|
927
|
478 ;;;###autoload
|
904
|
479 (defun vc-diff (historic)
|
|
480 "Display diffs between file versions."
|
|
481 (interactive "P")
|
|
482 (if historic
|
|
483 (call-interactively 'vc-version-diff)
|
|
484 (let ((old
|
|
485 (and
|
|
486 current-prefix-arg
|
|
487 (read-string "Version to compare against: ")))
|
|
488 (file buffer-file-name)
|
|
489 unchanged)
|
|
490 (vc-buffer-sync)
|
|
491 (setq unchanged (vc-workfile-unchanged-p buffer-file-name))
|
|
492 (if unchanged
|
|
493 (message (format "No changes to %s since latest version." file))
|
|
494 (pop-to-buffer "*vc*")
|
|
495 (vc-backend-diff file nil)
|
|
496 (goto-char (point-min))
|
|
497 )
|
|
498 (not unchanged)
|
|
499 )
|
|
500 )
|
|
501 )
|
|
502
|
|
503 (defun vc-version-diff (file rel1 rel2)
|
|
504 "For FILE, report diffs between two stored versions REL1 and REL2 of it.
|
|
505 If FILE is a directory, generate diffs between versions for all registered
|
|
506 files in or below it."
|
|
507 (interactive "FFile or directory: \nsOlder version: \nsNewer version: ")
|
|
508 (if (string-equal rel1 "") (setq rel1 nil))
|
|
509 (if (string-equal rel2 "") (setq rel2 nil))
|
|
510 (if (file-directory-p file)
|
|
511 (progn
|
|
512 (set-buffer (get-buffer-create "*vc-status*"))
|
|
513 (erase-buffer)
|
|
514 (insert "Diffs between " rel1 " and " rel2 ":\n\n")
|
|
515 (set-buffer (get-buffer-create "*vc*"))
|
|
516 (vc-file-tree-walk
|
|
517 (function (lambda (f)
|
|
518 (and
|
|
519 (not (file-directory-p f))
|
|
520 (vc-name f)
|
|
521 (vc-backend-diff f rel1 rel2))
|
|
522 (append-to-buffer "*vc-status*" (point-min) (point-max))
|
|
523 ))
|
|
524 default-directory)
|
|
525 (pop-to-buffer "*vc-status*")
|
|
526 (insert "\nEnd of diffs.\n")
|
|
527 (goto-char (point-min))
|
|
528 (set-buffer-modified-p nil)
|
|
529 )
|
|
530 (progn
|
|
531 (vc-backend-diff file rel1 rel2)
|
|
532 (goto-char (point-min))
|
|
533 (if (equal (point-min) (point-max))
|
|
534 (message (format "No changes to %s between %s and %s." file rel1 rel2))
|
|
535 (pop-to-buffer "*vc*")
|
|
536 (goto-char (point-min))
|
|
537 )
|
|
538 )
|
|
539 )
|
|
540 )
|
|
541
|
|
542 ;; Header-insertion code
|
|
543
|
927
|
544 ;;;###autoload
|
904
|
545 (defun vc-insert-headers ()
|
|
546 "Insert headers in a file for use with your version-control system.
|
|
547 Headers desired are inserted at the start of the buffer, and are pulled from
|
|
548 the variable vc-header-strings"
|
|
549 (interactive)
|
|
550 (save-excursion
|
|
551 (save-restriction
|
|
552 (widen)
|
|
553 (if (or (not (vc-check-headers))
|
|
554 (y-or-n-p "Version headers already exist. Insert another set?"))
|
|
555 (progn
|
|
556 (let* ((delims (cdr (assq major-mode vc-comment-alist)))
|
|
557 (comment-start-vc (or (car delims) comment-start "#"))
|
|
558 (comment-end-vc (or (car (cdr delims)) comment-end ""))
|
|
559 (hdstrings (cdr (assoc (vc-backend-deduce (buffer-file-name)) vc-header-alist))))
|
|
560 (mapcar (function (lambda (s)
|
|
561 (insert comment-start-vc "\t" s "\t"
|
|
562 comment-end-vc "\n")))
|
|
563 hdstrings)
|
|
564 (if vc-static-header-alist
|
|
565 (mapcar (function (lambda (f)
|
|
566 (if (string-match (car f) buffer-file-name)
|
|
567 (insert (format (cdr f) (car hdstrings))))))
|
|
568 vc-static-header-alist))
|
|
569 )
|
|
570 )))))
|
|
571
|
|
572 ;; Status-checking functions
|
|
573
|
927
|
574 ;;;###autoload
|
904
|
575 (defun vc-directory (verbose)
|
|
576 "Show version-control status of all files under the current directory."
|
|
577 (interactive "P")
|
|
578 (let ((dir (substring default-directory 0 (1- (length default-directory))))
|
|
579 nonempty)
|
|
580 (save-excursion
|
|
581 (set-buffer (get-buffer-create "*vc-status*"))
|
|
582 (erase-buffer)
|
|
583 (vc-file-tree-walk
|
|
584 (function (lambda (f)
|
|
585 (if (vc-registered f)
|
|
586 (let ((user (vc-locking-user f)))
|
|
587 (if (or user verbose)
|
|
588 (insert (format
|
|
589 "%s %s\n"
|
|
590 (concat user) f)))))))
|
|
591 dir)
|
|
592 (setq nonempty (not (zerop (buffer-size)))))
|
|
593 (if nonempty
|
|
594 (progn
|
|
595 (pop-to-buffer "*vc-status*" t)
|
|
596 (vc-shrink-to-fit)
|
|
597 (goto-char (point-min)))
|
|
598 (message "No files are currently registered under %s" dir))
|
|
599 ))
|
|
600
|
|
601 ;; Named-configuration support for SCCS
|
|
602
|
|
603 (defun vc-add-triple (name file rev)
|
|
604 (save-excursion
|
|
605 (find-file (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file))
|
|
606 (goto-char (point-max))
|
|
607 (insert name "\t:\t" file "\t" rev "\n")
|
|
608 (basic-save-buffer)
|
|
609 (kill-buffer (current-buffer))
|
|
610 ))
|
|
611
|
|
612 (defun vc-record-rename (file newname)
|
|
613 (save-excursion
|
|
614 (find-file (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file))
|
|
615 (goto-char (point-min))
|
|
616 (replace-regexp (concat ":" (regexp-quote file) "$") (concat ":" newname))
|
|
617 (basic-save-buffer)
|
|
618 (kill-buffer (current-buffer))
|
|
619 ))
|
|
620
|
|
621 (defun vc-lookup-triple (file name)
|
|
622 (or
|
|
623 name
|
|
624 (let ((firstchar (aref name 0)))
|
|
625 (and (>= firstchar ?0) (<= firstchar ?9) name))
|
|
626 (car (vc-master-info
|
|
627 (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file)
|
|
628 (list (concat name "\t:\t" file "\t\\(.+\\)"))))
|
|
629 ))
|
|
630
|
|
631 ;; Named-configuration entry points
|
|
632
|
|
633 (defun vc-quiescent-p ()
|
|
634 ;; Is the current directory ready to be snapshot?
|
|
635 (let ((dir (substring default-directory 0 (1- (length default-directory)))))
|
|
636 (catch 'quiet
|
|
637 (vc-file-tree-walk
|
|
638 (function (lambda (f)
|
|
639 (if (and (vc-registered f) (vc-locking-user f))
|
|
640 (throw 'quiet nil))))
|
|
641 dir)
|
|
642 t)))
|
|
643
|
927
|
644 ;;;###autoload
|
904
|
645 (defun vc-create-snapshot (name)
|
|
646 "Make a snapshot called NAME.
|
|
647 The snapshot is made from all registered files at or below the current
|
|
648 directory. For each file, the version level of its latest
|
|
649 version becomes part of the named configuration."
|
|
650 (interactive "sNew snapshot name: ")
|
|
651 (if (not (vc-quiescent-p))
|
|
652 (error "Can't make a snapshot, locked files are in the way.")
|
|
653 (vc-file-tree-walk
|
|
654 (function (lambda (f) (and
|
|
655 (not (file-directory-p f))
|
|
656 (vc-name f)
|
|
657 (vc-backend-assign-name f name))))
|
|
658 default-directory)
|
|
659 ))
|
|
660
|
927
|
661 ;;;###autoload
|
904
|
662 (defun vc-retrieve-snapshot (name)
|
|
663 "Retrieve the snapshot called NAME.
|
|
664 This function fails if any files are locked at or below the current directory
|
|
665 Otherwise, all registered files are checked out (unlocked) at their version
|
|
666 levels in the snapshot."
|
|
667 (interactive "sSnapshot name to retrieve: ")
|
|
668 (if (not (vc-quiescent-p))
|
|
669 (error "Can't retrieve a snapshot, locked files are in the way.")
|
|
670 (vc-file-tree-walk
|
|
671 (function (lambda (f) (and
|
|
672 (not (file-directory-p f))
|
|
673 (vc-name f)
|
|
674 (vc-error-occurred (vc-backend-checkout f nil name)))))
|
|
675 default-directory)
|
|
676 ))
|
|
677
|
|
678 ;; Miscellaneous other entry points
|
|
679
|
927
|
680 ;;;###autoload
|
904
|
681 (defun vc-print-log ()
|
|
682 "List the change log of the current buffer in a window."
|
|
683 (interactive)
|
|
684 (if (and buffer-file-name (vc-name buffer-file-name))
|
|
685 (progn
|
|
686 (vc-backend-print-log buffer-file-name)
|
|
687 (pop-to-buffer (get-buffer-create "*vc*"))
|
|
688 (goto-char (point-min))
|
|
689 )
|
|
690 (error "There is no version-control master associated with this buffer")
|
|
691 )
|
|
692 )
|
|
693
|
927
|
694 ;;;###autoload
|
904
|
695 (defun vc-revert-buffer ()
|
952
|
696 "Revert the current buffer's file back to the latest checked-in version.
|
|
697 This asks for confirmation if the buffer contents are not identical
|
|
698 to that version."
|
904
|
699 (interactive)
|
|
700 (let ((file buffer-file-name)
|
|
701 (obuf (current-buffer)) (changed (vc-diff nil)))
|
952
|
702 (if (and changed (or vc-suppress-confirm
|
|
703 (not (yes-or-no-p "Discard changes? "))))
|
904
|
704 (progn
|
|
705 (delete-window)
|
|
706 (error "Revert cancelled."))
|
|
707 (set-buffer obuf))
|
|
708 (if changed
|
|
709 (delete-window))
|
|
710 (vc-backend-revert file)
|
|
711 (vc-resynch-window file t)
|
|
712 )
|
|
713 )
|
|
714
|
927
|
715 ;;;###autoload
|
904
|
716 (defun vc-cancel-version (norevert)
|
|
717 "Undo your latest checkin."
|
|
718 (interactive "P")
|
|
719 (let ((target (vc-your-latest-version (buffer-file-name))))
|
|
720 (if (null target)
|
|
721 (error "You didn't check in the last change."))
|
|
722 (and (y-or-n-p (format "Remove version %s from master? " target))
|
|
723 (vc-backend-uncheck (buffer-file-name) target)))
|
|
724 (if norevert
|
|
725 (vc-mode-line (buffer-file-name))
|
|
726 (vc-checkout (buffer-file-name) nil))
|
|
727 )
|
|
728
|
|
729 (defun vc-rename-file (old new)
|
|
730 "Rename a file, taking its master files with it."
|
|
731 (interactive "fOld name: \nFNew name: ")
|
|
732 (let ((oldbuf (get-file-buffer old)))
|
|
733 (if (buffer-modified-p oldbuf)
|
|
734 (error "Please save files before moving them."))
|
|
735 (if (get-file-buffer new)
|
|
736 (error "Already editing new file name."))
|
|
737 (let ((oldmaster (vc-name old)))
|
|
738 (if oldmaster
|
|
739 (if (vc-locking-user old)
|
|
740 (error "Please check in files before moving them."))
|
|
741 (if (or (file-symlink-p oldmaster)
|
|
742 (file-symlink-p (vc-backend-subdirectory-name file)))
|
|
743 (error "This is not a safe thing to do in the presence of symbolic links."))
|
|
744 (rename-file oldmaster (vc-name new)))
|
|
745 (if (or (not oldmaster) (file-exists-p old))
|
|
746 (rename-file old new)))
|
|
747 ; ?? Renaming a file might change its contents due to keyword expansion.
|
|
748 ; We should really check out a new copy if the old copy was precisely equal
|
|
749 ; to some checked in version. However, testing for this is tricky....
|
|
750 (if oldbuf
|
|
751 (save-excursion
|
|
752 (set-buffer oldbuf)
|
|
753 (set-visited-file-name new)
|
|
754 (set-buffer-modified-p nil))))
|
|
755 (vc-backend-dispatch file
|
|
756 (vc-record-rename old new)
|
|
757 nil)
|
|
758 )
|
|
759
|
927
|
760 ;;;###autoload
|
904
|
761 (defun vc-update-change-log ()
|
|
762 "Find change log file and add entries from recent RCS logs."
|
|
763 (interactive)
|
|
764 (find-file-other-window "ChangeLog")
|
|
765 (vc-buffer-sync)
|
|
766 (or (eq major-mode 'indented-text-mode)
|
|
767 (progn
|
|
768 (indented-text-mode)
|
|
769 (setq left-margin 8)
|
|
770 (setq fill-column 74)))
|
|
771 (auto-fill-mode 1)
|
|
772 (undo-boundary)
|
|
773 (goto-char (point-min))
|
|
774 (message "Computing change log entries...")
|
|
775 (shell-command-on-region (point) (point) "rcs2log" t)
|
|
776 (message "Computing change log entries... done"))
|
|
777
|
|
778 ;; Functions for querying the master and lock files.
|
|
779
|
|
780 (defun match-substring (bn)
|
|
781 (buffer-substring (match-beginning bn) (match-end bn)))
|
|
782
|
|
783 (defun vc-parse-buffer (patterns &optional file properties)
|
|
784 ;; Use PATTERNS to parse information out of the current buffer
|
|
785 ;; by matching each regular expression in the list and returning \\1.
|
|
786 ;; If a regexp has two tag brackets, assume the second is a date
|
|
787 ;; field and we want the most recent entry matching the template.
|
|
788 ;; If FILE and PROPERTIES are given, the latter must be a list of
|
|
789 ;; properties of the same length as PATTERNS; each property is assigned
|
|
790 ;; the corresponding value.
|
|
791 (mapcar (function (lambda (p)
|
|
792 (goto-char (point-min))
|
|
793 (if (string-match "\\\\(.*\\\\(" p)
|
|
794 (let ((latest-date "") (latest-val))
|
|
795 (while (re-search-forward p nil t)
|
|
796 (let ((date (match-substring 2)))
|
|
797 (if (string< latest-date date)
|
|
798 (progn
|
|
799 (setq latest-date date)
|
|
800 (setq latest-val
|
|
801 (match-substring 1))))))
|
|
802 latest-val))
|
|
803 (prog1
|
|
804 (and (re-search-forward p nil t)
|
|
805 (let ((value (match-substring 1)))
|
|
806 (if file
|
|
807 (vc-file-setprop file (car properties) value))
|
|
808 value))
|
|
809 (setq properties (cdr properties)))))
|
|
810 patterns)
|
|
811 )
|
|
812
|
|
813 (defun vc-master-info (file fields &optional rfile properties)
|
|
814 ;; Search for information in a master file.
|
|
815 (if (and file (file-exists-p file))
|
|
816 (save-excursion
|
|
817 (let ((buf))
|
|
818 (setq buf (create-file-buffer file))
|
|
819 (set-buffer buf))
|
|
820 (erase-buffer)
|
|
821 (insert-file-contents file nil)
|
|
822 (set-buffer-modified-p nil)
|
|
823 (auto-save-mode nil)
|
|
824 (prog1
|
|
825 (vc-parse-buffer fields rfile properties)
|
|
826 (kill-buffer (current-buffer)))
|
|
827 )
|
|
828 (if rfile
|
|
829 (mapcar
|
|
830 (function (lambda (p) (vc-file-setprop rfile p nil)))
|
|
831 properties))
|
|
832 )
|
|
833 )
|
|
834
|
|
835 (defun vc-log-info (command file patterns &optional properties)
|
|
836 ;; Search for information in log program output
|
|
837 (if (and file (file-exists-p file))
|
|
838 (save-excursion
|
|
839 (let ((buf))
|
|
840 (setq buf (get-buffer-create "*vc*"))
|
|
841 (set-buffer buf))
|
|
842 (apply 'vc-do-command 0 command file nil)
|
|
843 (set-buffer-modified-p nil)
|
|
844 (prog1
|
|
845 (vc-parse-buffer patterns file properties)
|
|
846 (kill-buffer (current-buffer))
|
|
847 )
|
|
848 )
|
|
849 (if file
|
|
850 (mapcar
|
|
851 (function (lambda (p) (vc-file-setprop file p nil)))
|
|
852 properties))
|
|
853 )
|
|
854 )
|
|
855
|
|
856 (defun vc-locking-user (file)
|
|
857 "Return the name of the person currently holding a lock on FILE.
|
|
858 Return nil if there is no such person."
|
|
859 (if (or (not vc-keep-workfiles)
|
|
860 (eq vc-mistrust-permissions 't)
|
|
861 (and vc-mistrust-permissions
|
|
862 (funcall vc-mistrust-permissions (vc-backend-subdirectory-name file))))
|
|
863 (vc-true-locking-user file)
|
|
864 ;; This implementation assumes that any file which is under version
|
|
865 ;; control and has -rw-r--r-- is locked by its owner. This is true
|
|
866 ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--.
|
|
867 ;; We have to be careful not to exclude files with execute bits on;
|
|
868 ;; scripts can be under version control too. The advantage of this
|
|
869 ;; hack is that calls to the very expensive vc-fetch-properties
|
|
870 ;; function only have to be made if (a) the file is locked by someone
|
|
871 ;; other than the current user, or (b) some untoward manipulation
|
|
872 ;; behind vc's back has twiddled the `group' or `other' write bits.
|
|
873 (let ((attributes (file-attributes file)))
|
|
874 (cond ((string-match ".r-.r-.r-." (nth 8 attributes))
|
|
875 nil)
|
|
876 ((and (= (nth 2 attributes) (user-uid))
|
|
877 (string-match ".rw.r-.r-." (nth 8 attributes)))
|
|
878 (user-login-name))
|
|
879 (t
|
|
880 (vc-true-locking-user file))))))
|
|
881
|
|
882 (defun vc-true-locking-user (file)
|
|
883 ;; The slow but reliable version
|
|
884 (vc-fetch-properties file)
|
|
885 (vc-file-getprop file 'vc-locking-user))
|
|
886
|
|
887 (defun vc-latest-version (file)
|
|
888 ;; Return version level of the latest version of FILE
|
|
889 (vc-fetch-properties file)
|
|
890 (vc-file-getprop file 'vc-latest-version))
|
|
891
|
|
892 (defun vc-your-latest-version (file)
|
|
893 ;; Return version level of the latest version of FILE checked in by you
|
|
894 (vc-fetch-properties file)
|
|
895 (vc-file-getprop file 'vc-your-latest-version))
|
|
896
|
|
897 ;; Collect back-end-dependent stuff here
|
|
898 ;;
|
|
899 ;; Everything eventually funnels through these functions. To implement
|
|
900 ;; support for a new version-control system, add another branch to the
|
|
901 ;; vc-backend-dispatch macro (in vc-hooks.el) and fill it in in each call.
|
|
902
|
|
903 (defmacro vc-backend-dispatch (f s r)
|
|
904 "Execute FORM1 or FORM2 depending on whether we're using SCCS or RCS."
|
|
905 (list 'let (list (list 'type (list 'vc-backend-deduce f)))
|
|
906 (list 'cond
|
|
907 (list (list 'eq 'type (quote 'SCCS)) s) ;; SCCS
|
|
908 (list (list 'eq 'type (quote 'RCS)) r) ;; RCS
|
|
909 )))
|
|
910
|
|
911 (defun vc-lock-file (file)
|
|
912 ;; Generate lock file name corresponding to FILE
|
|
913 (let ((master (vc-name file)))
|
|
914 (and
|
|
915 master
|
|
916 (string-match "\\(.*/\\)s\\.\\(.*\\)" master)
|
|
917 (concat
|
|
918 (substring master (match-beginning 1) (match-end 1))
|
|
919 "p."
|
|
920 (substring master (match-beginning 2) (match-end 2))))))
|
|
921
|
|
922
|
|
923 (defun vc-fetch-properties (file)
|
|
924 ;; Re-fetch all properties associated with the given file.
|
|
925 ;; Currently these properties are:
|
|
926 ;; vc-locking-user
|
|
927 ;; vc-locked-version
|
|
928 ;; vc-latest-version
|
|
929 ;; vc-your-latest-version
|
|
930 (vc-backend-dispatch
|
|
931 file
|
|
932 ;; SCCS
|
|
933 (progn
|
|
934 (vc-master-info (vc-lock-file file)
|
|
935 (list
|
|
936 "^[^ ]+ [^ ]+ \\([^ ]+\\)"
|
|
937 "^\\([^ ]+\\)")
|
|
938 file
|
|
939 '(vc-locking-user vc-locked-version))
|
|
940 (vc-master-info (vc-name file)
|
|
941 (list
|
|
942 "^\001d D \\([^ ]+\\)"
|
|
943 (concat "^\001d D \\([^ ]+\\) .* "
|
|
944 (regexp-quote (user-login-name)) " ")
|
|
945 )
|
|
946 file
|
|
947 '(vc-latest-version vc-your-latest-version))
|
|
948 )
|
|
949 ;; RCS
|
|
950 (vc-log-info "rlog" file
|
|
951 (list
|
|
952 "^locks: strict\n\t\\([^:]+\\)"
|
|
953 "^locks: strict\n\t[^:]+: \\(.+\\)"
|
|
954 "^revision[\t ]+\\([0-9.]+\\).*\ndate: \\([ /0-9:]+\\);"
|
|
955 (concat
|
|
956 "^revision[\t ]+\\([0-9.]+\\).*locked by: "
|
|
957 (regexp-quote (user-login-name))
|
|
958 ";\ndate: \\([ /0-9:]+\\);"))
|
|
959 '(vc-locking-user vc-locked-version
|
|
960 vc-latest-version vc-your-latest-version))
|
|
961 ))
|
|
962
|
|
963 (defun vc-backend-subdirectory-name (&optional file)
|
|
964 ;; Where the master and lock files for the current directory are kept
|
|
965 (symbol-name
|
|
966 (or
|
|
967 (and file (vc-backend-deduce file))
|
|
968 vc-default-back-end
|
|
969 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))))
|
|
970
|
|
971 (defun vc-backend-admin (file &optional rev comment)
|
|
972 ;; Register a file into the version-control system
|
|
973 ;; Automatically retrieves a read-only version of the file with
|
|
974 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
|
|
975 ;; it deletes the workfile.
|
|
976 (vc-file-clearprops file)
|
|
977 (or vc-default-back-end
|
|
978 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))
|
|
979 (message "Registering %s..." file)
|
|
980 (let ((backend
|
|
981 (cond
|
|
982 ((file-exists-p (vc-backend-subdirectory-name)) vc-default-back-end)
|
|
983 ((file-exists-p "RCS") 'RCS)
|
|
984 ((file-exists-p "SCCS") 'SCCS)
|
|
985 (t vc-default-back-end))))
|
|
986 (cond ((eq backend 'SCCS)
|
|
987 (vc-do-command 0 "admin" file ;; SCCS
|
|
988 (and rev (concat "-r" rev))
|
|
989 "-fb"
|
|
990 (concat "-i" file)
|
|
991 (and comment (concat "-y" comment))
|
|
992 (format
|
|
993 (car (rassq 'SCCS vc-master-templates))
|
|
994 (or (file-name-directory file) "")
|
|
995 (file-name-nondirectory file)))
|
|
996 (delete-file file)
|
|
997 (if vc-keep-workfiles
|
|
998 (vc-do-command 0 "get" file)))
|
|
999 ((eq backend 'RCS)
|
|
1000 (vc-do-command 0 "ci" file ;; RCS
|
|
1001 (concat (if vc-keep-workfiles "-u" "-r") rev)
|
|
1002 (and comment (concat "-t-" comment))
|
|
1003 file)
|
|
1004 )))
|
|
1005 (message "Registering %s...done" file)
|
|
1006 )
|
|
1007
|
|
1008 (defun vc-backend-checkout (file &optional writeable rev)
|
|
1009 ;; Retrieve a copy of a saved version into a workfile
|
|
1010 (message "Checking out %s..." file)
|
|
1011 (vc-backend-dispatch file
|
|
1012 (progn
|
|
1013 (vc-do-command 0 "get" file ;; SCCS
|
|
1014 (if writeable "-e")
|
|
1015 (and rev (concat "-r" (vc-lookup-triple file rev))))
|
|
1016 )
|
|
1017 (vc-do-command 0 "co" file ;; RCS
|
|
1018 (if writeable "-l")
|
|
1019 (and rev (concat "-r" rev)))
|
|
1020 )
|
|
1021 (vc-file-setprop file 'vc-checkout-time (nth 5 (file-attributes file)))
|
|
1022 (message "Checking out %s...done" file)
|
|
1023 )
|
|
1024
|
|
1025 (defun vc-backend-logentry-check (file)
|
|
1026 (vc-backend-dispatch file
|
|
1027 (if (>= (- (region-end) (region-beginning)) 512) ;; SCCS
|
|
1028 (progn
|
|
1029 (goto-char 512)
|
|
1030 (error
|
|
1031 "Log must be less than 512 characters. Point is now at char 512.")))
|
|
1032 nil)
|
|
1033 )
|
|
1034
|
|
1035 (defun vc-backend-checkin (file &optional rev comment)
|
|
1036 ;; Register changes to FILE as level REV with explanatory COMMENT.
|
|
1037 ;; Automatically retrieves a read-only version of the file with
|
|
1038 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
|
|
1039 ;; it deletes the workfile.
|
|
1040 (message "Checking in %s..." file)
|
|
1041 (vc-backend-dispatch file
|
|
1042 (progn
|
|
1043 (vc-do-command 0 "delta" file
|
|
1044 (if rev (concat "-r" rev))
|
|
1045 (concat "-y" comment))
|
|
1046 (if vc-keep-workfiles
|
|
1047 (vc-do-command 0 "get" file))
|
|
1048 )
|
|
1049 (vc-do-command 0 "ci" file
|
|
1050 (concat (if vc-keep-workfiles "-u" "-r") rev)
|
|
1051 (concat "-m" comment))
|
|
1052 )
|
|
1053 (vc-file-setprop file 'vc-locking-user nil)
|
|
1054 (message "Checking in %s...done" file)
|
|
1055 )
|
|
1056
|
|
1057 (defun vc-backend-revert (file)
|
|
1058 ;; Revert file to latest checked-in version.
|
|
1059 (message "Reverting %s..." file)
|
|
1060 (vc-backend-dispatch
|
|
1061 file
|
|
1062 (progn ;; SCCS
|
|
1063 (vc-do-command 0 "unget" file nil)
|
|
1064 (vc-do-command 0 "get" file nil))
|
|
1065 (progn
|
|
1066 (delete-file file) ;; RCS
|
|
1067 (vc-do-command 0 "co" file "-u")))
|
|
1068 (vc-file-setprop file 'vc-locking-user nil)
|
|
1069 (message "Reverting %s...done" file)
|
|
1070 )
|
|
1071
|
|
1072 (defun vc-backend-steal (file &optional rev)
|
|
1073 ;; Steal the lock on the current workfile. Needs RCS 5.6.2 or later for -M.
|
|
1074 (message "Stealing lock on %s..." file)
|
|
1075 (progn
|
|
1076 (vc-do-command 0 "unget" file "-n" (if rev (concat "-r" rev)))
|
|
1077 (vc-do-command 0 "get" file "-g" (if rev (concat "-r" rev)))
|
|
1078 )
|
|
1079 (progn
|
|
1080 (vc-do-command 0 "rcs" file "-M" (concat "-u" rev))
|
|
1081 (vc-do-command 0 "rcs" file (concat "-l" rev))
|
|
1082 )
|
|
1083 (vc-file-setprop file 'vc-locking-user (user-login-name))
|
|
1084 (message "Stealing lock on %s...done" file)
|
|
1085 )
|
|
1086
|
|
1087 (defun vc-backend-uncheck (file target)
|
|
1088 ;; Undo the latest checkin. Note: this code will have to get a lot
|
|
1089 ;; smarter when we support multiple branches.
|
|
1090 (message "Removing last change from %s..." file)
|
|
1091 (vc-backend-dispatch file
|
|
1092 (vc-do-command 0 "rmdel" file (concat "-r" target))
|
|
1093 (vc-do-command 0 "rcs" file (concat "-o" target))
|
|
1094 )
|
|
1095 (message "Removing last change from %s...done" file)
|
|
1096 )
|
|
1097
|
|
1098 (defun vc-backend-print-log (file)
|
|
1099 ;; Print change log associated with FILE to buffer *vc*.
|
|
1100 (vc-do-command 0
|
|
1101 (vc-backend-dispatch file "prs" "rlog")
|
|
1102 file)
|
|
1103 )
|
|
1104
|
|
1105 (defun vc-backend-assign-name (file name)
|
|
1106 ;; Assign to a FILE's latest version a given NAME.
|
|
1107 (vc-backend-dispatch file
|
|
1108 (vc-add-triple name file (vc-latest-version file)) ;; SCCS
|
|
1109 (vc-do-command 0 "rcs" file (concat "-n" name ":")) ;; RCS
|
|
1110 ))
|
|
1111
|
|
1112 (defun vc-backend-diff (file oldvers &optional newvers)
|
|
1113 ;; Get a difference report between two versions
|
|
1114 (apply 'vc-do-command 1
|
|
1115 (or (vc-backend-dispatch file "vcdiff" "rcsdiff")
|
|
1116 (error (format "File %s is not under version control." file)))
|
|
1117 file
|
|
1118 (and oldvers (concat "-r" oldvers))
|
|
1119 (and newvers (concat "-r" newvers))
|
|
1120 vc-diff-options
|
|
1121 ))
|
|
1122
|
|
1123 (defun vc-check-headers ()
|
|
1124 "Check if the current file has any headers in it."
|
|
1125 (interactive)
|
|
1126 (save-excursion
|
|
1127 (goto-char (point-min))
|
|
1128 (vc-backend-dispatch buffer-file-name
|
|
1129 (re-search-forward "%[MIRLBSDHTEGUYFPQCZWA]%" nil t) ;; SCCS
|
|
1130 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t) ;; RCS
|
|
1131 )
|
|
1132 ))
|
|
1133
|
|
1134 ;; Back-end-dependent stuff ends here.
|
|
1135
|
|
1136 ;; Set up key bindings for use while editing log messages
|
|
1137
|
|
1138 (defun vc-log-mode ()
|
|
1139 "Minor mode for driving version-control tools.
|
|
1140 These bindings are added to the global keymap when you enter this mode:
|
|
1141 \\[vc-next-action] perform next logical version-control operation on current file
|
|
1142 \\[vc-register] register current file
|
|
1143 \\[vc-toggle-read-only] like next-action, but won't register files
|
|
1144 \\[vc-insert-headers] insert version-control headers in current file
|
|
1145 \\[vc-print-log] display change history of current file
|
|
1146 \\[vc-revert-buffer] revert buffer to latest version
|
|
1147 \\[vc-cancel-version] undo latest checkin
|
|
1148 \\[vc-diff] show diffs between file versions
|
|
1149 \\[vc-directory] show all files locked by any user in or below .
|
|
1150 \\[vc-update-change-log] add change log entry from recent checkins
|
|
1151
|
|
1152 While you are entering a change log message for a version, the following
|
|
1153 additional bindings will be in effect.
|
|
1154
|
|
1155 \\[vc-finish-logentry] proceed with check in, ending log message entry
|
|
1156
|
|
1157 Whenever you do a checkin, your log comment is added to a ring of
|
|
1158 saved comments. These can be recalled as follows:
|
|
1159
|
|
1160 \\[vc-next-comment] replace region with next message in comment ring
|
|
1161 \\[vc-previous-comment] replace region with previous message in comment ring
|
|
1162 \\[vc-search-comment-reverse] search backward for regexp in the comment ring
|
|
1163 \\[vc-search-comment-forward] search backward for regexp in the comment ring
|
|
1164
|
|
1165 Entry to the change-log submode calls the value of text-mode-hook, then
|
|
1166 the value of vc-log-mode-hook.
|
|
1167
|
|
1168 Global user options:
|
|
1169 vc-initial-comment If non-nil, require user to enter a change
|
|
1170 comment upon first checkin of the file.
|
|
1171
|
|
1172 vc-keep-workfiles Non-nil value prevents workfiles from being
|
|
1173 deleted when changes are checked in
|
|
1174
|
|
1175 vc-suppress-confirm Suppresses some confirmation prompts,
|
|
1176 notably for reversions.
|
|
1177
|
|
1178 vc-diff-options A list consisting of the flags
|
|
1179 to be used for generating context diffs.
|
|
1180
|
|
1181 vc-header-strings Which keywords to insert when adding headers
|
|
1182 with \\[vc-insert-headers]. Defaults to
|
|
1183 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under RCS.
|
|
1184
|
|
1185 vc-static-header-alist By default, version headers inserted in C files
|
|
1186 get stuffed in a static string area so that
|
|
1187 ident(RCS) or what(SCCS) can see them in the
|
|
1188 compiled object code. You can override this
|
|
1189 by setting this variable to nil, or change
|
|
1190 the header template by changing it.
|
|
1191
|
|
1192 vc-command-messages if non-nil, display run messages from the
|
|
1193 actual version-control utilities (this is
|
|
1194 intended primarily for people hacking vc
|
|
1195 itself).
|
|
1196 "
|
|
1197 (interactive)
|
|
1198 (set-syntax-table text-mode-syntax-table)
|
|
1199 (use-local-map vc-log-entry-mode)
|
|
1200 (setq local-abbrev-table text-mode-abbrev-table)
|
|
1201 (setq major-mode 'vc-log-mode)
|
|
1202 (setq mode-name "VC-Log")
|
|
1203 (make-local-variable 'vc-log-file)
|
|
1204 (make-local-variable 'vc-log-version)
|
|
1205 (set-buffer-modified-p nil)
|
|
1206 (setq buffer-file-name nil)
|
|
1207 (run-hooks 'text-mode-hook 'vc-log-mode-hook)
|
|
1208 )
|
|
1209
|
|
1210 ;; Initialization code, to be done just once at load-time
|
|
1211 (if vc-log-entry-mode
|
|
1212 nil
|
|
1213 (setq vc-log-entry-mode (make-sparse-keymap))
|
|
1214 (define-key vc-log-entry-mode "\M-n" 'vc-next-comment)
|
|
1215 (define-key vc-log-entry-mode "\M-p" 'vc-previous-comment)
|
|
1216 (define-key vc-log-entry-mode "\M-r" 'vc-comment-search-backward)
|
|
1217 (define-key vc-log-entry-mode "\M-s" 'vc-comment-search-forward)
|
|
1218 (define-key vc-log-entry-mode "\C-c\C-c" 'vc-finish-logentry)
|
|
1219 )
|
|
1220
|
|
1221 ;;; These things should probably be generally available
|
|
1222
|
|
1223 (defun vc-shrink-to-fit ()
|
|
1224 "Shrink a window vertically until it's just large enough to contain its text"
|
|
1225 (let ((minsize (1+ (count-lines (point-min) (point-max)))))
|
|
1226 (if (< minsize (window-height))
|
|
1227 (let ((window-min-height 2))
|
|
1228 (shrink-window (- (window-height) minsize))))))
|
|
1229
|
|
1230 (defun vc-file-tree-walk (func dir &rest args)
|
|
1231 "Apply a given function to dir and all files underneath it, recursively."
|
|
1232 (apply 'funcall func dir args)
|
|
1233 (and (file-directory-p dir)
|
|
1234 (mapcar
|
|
1235 (function (lambda (f) (or
|
|
1236 (string-equal f ".")
|
|
1237 (string-equal f "..")
|
|
1238 (file-symlink-p f) ;; Avoid possible loops
|
|
1239 (apply 'vc-file-tree-walk
|
|
1240 func
|
|
1241 (if (= (aref dir (1- (length dir))) ?/)
|
|
1242 (concat dir f)
|
|
1243 (concat dir "/" f))
|
|
1244 args))))
|
|
1245 (directory-files dir))))
|
|
1246
|
|
1247 (provide 'vc)
|
|
1248
|
|
1249 ;;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
|
|
1250 ;;;
|
|
1251 ;;; These may be useful to anyone who has to debug or extend the package.
|
|
1252 ;;;
|
|
1253 ;;; A fundamental problem in VC is that there are time windows between
|
|
1254 ;;; vc-next-action's computations of the file's version-control state and
|
|
1255 ;;; the actions that change it. This is a window open to lossage in a
|
|
1256 ;;; multi-user environment; someone else could nip in and change the state
|
|
1257 ;;; of the master during it.
|
|
1258 ;;;
|
|
1259 ;;; The performance problem is that rlog/prs calls are very expensive; we want
|
|
1260 ;;; to avoid them as much as possible.
|
|
1261 ;;;
|
|
1262 ;;; ANALYSIS:
|
|
1263 ;;;
|
|
1264 ;;; The performance problem, it turns out, simplifies in practice to the
|
|
1265 ;;; problem of making vc-locking-user fast. The two other functions that call
|
|
1266 ;;; prs/rlog will not be so commonly used that the slowdown is a problem; one
|
|
1267 ;;; makes snapshots, the other deletes the calling user's last change in the
|
|
1268 ;;; master.
|
|
1269 ;;;
|
|
1270 ;;; The race condition implies that we have to either (a) lock the master
|
|
1271 ;;; during the entire execution of vc-next-action, or (b) detect and
|
|
1272 ;;; recover from errors resulting from dispatch on an out-of-date state.
|
|
1273 ;;;
|
|
1274 ;;; Alternative (a) appears to be unfeasible. The problem is that we can't
|
|
1275 ;;; guarantee that the lock will ever be removed. Suppose a user starts a
|
|
1276 ;;; checkin, the change message buffer pops up, and the user, having wandered
|
|
1277 ;;; off to do something else, simply forgets about it?
|
|
1278 ;;;
|
|
1279 ;;; Alternative (b), on the other hand, works well with a cheap way to speed up
|
|
1280 ;;; vc-locking-user. Usually, if a file is registered, we can read its locked/
|
|
1281 ;;; unlocked state and its current owner from its permissions.
|
|
1282 ;;;
|
|
1283 ;;; This shortcut will fail if someone has manually changed the workfile's
|
|
1284 ;;; permissions; also if developers are munging the workfile in several
|
|
1285 ;;; directories, with symlinks to a master (in this latter case, the
|
|
1286 ;;; permissions shortcut will fail to detect a lock asserted from another
|
|
1287 ;;; directory).
|
|
1288 ;;;
|
|
1289 ;;; Note that these cases correspond exactly to the errors which could happen
|
|
1290 ;;; because of a competing checkin/checkout race in between two instances of
|
|
1291 ;;; vc-next-action.
|
|
1292 ;;;
|
|
1293 ;;; For VC's purposes, a workfile/master pair may have the following states:
|
|
1294 ;;;
|
|
1295 ;;; A. Unregistered. There is a workfile, there is no master.
|
|
1296 ;;;
|
|
1297 ;;; B. Registered and not locked by anyone.
|
|
1298 ;;;
|
|
1299 ;;; C. Locked by calling user and unchanged.
|
|
1300 ;;;
|
|
1301 ;;; D. Locked by the calling user and changed.
|
|
1302 ;;;
|
|
1303 ;;; E. Locked by someone other than the calling user.
|
|
1304 ;;;
|
|
1305 ;;; This makes for 25 states and 20 error conditions. Here's the matrix:
|
|
1306 ;;;
|
|
1307 ;;; VC's idea of state
|
|
1308 ;;; |
|
|
1309 ;;; V Actual state RCS action SCCS action Effect
|
|
1310 ;;; A B C D E
|
|
1311 ;;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
|
|
1312 ;;; B 5 . 6 7 8 co -l get -e checkout
|
|
1313 ;;; C 9 10 . 11 12 co -u unget; get revert
|
|
1314 ;;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
|
|
1315 ;;; E 17 18 19 20 . rcs -u -M ; rcs -l unget -n ; get -g steal lock
|
|
1316 ;;;
|
|
1317 ;;; All commands take the master file name as a last argument (not shown).
|
|
1318 ;;;
|
|
1319 ;;; In the discussion below, a "self-race" is a pathological situation in
|
|
1320 ;;; which VC operations are being attempted simultaneously by two or more
|
|
1321 ;;; Emacsen running under the same username.
|
|
1322 ;;;
|
|
1323 ;;; The vc-next-action code has the following windows:
|
|
1324 ;;;
|
|
1325 ;;; Window P:
|
|
1326 ;;; Between the check for existence of a master file and the call to
|
|
1327 ;;; admin/checkin in vc-buffer-admin (apparent state A). This window may
|
|
1328 ;;; never close if the initial-comment feature is on.
|
|
1329 ;;;
|
|
1330 ;;; Window Q:
|
|
1331 ;;; Between the call to vc-workfile-unchanged-p in and the immediately
|
|
1332 ;;; following revert (apparent state C).
|
|
1333 ;;;
|
|
1334 ;;; Window R:
|
|
1335 ;;; Between the call to vc-workfile-unchanged-p in and the following
|
|
1336 ;;; checkin (apparent state D). This window may never close.
|
|
1337 ;;;
|
|
1338 ;;; Window S:
|
|
1339 ;;; Between the unlock and the immediately following checkout during a
|
|
1340 ;;; revert operation (apparent state C). Included in window Q.
|
|
1341 ;;;
|
|
1342 ;;; Window T:
|
|
1343 ;;; Between vc-locking-user and the following checkout (apparent state B).
|
|
1344 ;;;
|
|
1345 ;;; Window U:
|
|
1346 ;;; Between vc-locking-user and the following revert (apparent state C).
|
|
1347 ;;; Includes windows Q and S.
|
|
1348 ;;;
|
|
1349 ;;; Window V:
|
|
1350 ;;; Between vc-locking-user and the following checkin (apparent state
|
|
1351 ;;; D). This window may never be closed if the user fails to complete the
|
|
1352 ;;; checkin message. Includes window R.
|
|
1353 ;;;
|
|
1354 ;;; Window W:
|
|
1355 ;;; Between vc-locking-user and the following steal-lock (apparent
|
|
1356 ;;; state E). This window may never cloce if the user fails to complete
|
|
1357 ;;; the steal-lock message. Includes window X.
|
|
1358 ;;;
|
|
1359 ;;; Window X:
|
|
1360 ;;; Between the unlock and the immediately following re-lock during a
|
|
1361 ;;; steal-lock operation (apparent state E). This window may never cloce
|
|
1362 ;;; if the user fails to complete the steal-lock message.
|
|
1363 ;;;
|
|
1364 ;;; Errors:
|
|
1365 ;;;
|
|
1366 ;;; Apparent state A ---
|
|
1367 ;;;
|
|
1368 ;;; 1. File looked unregistered but is actually registered and not locked.
|
|
1369 ;;;
|
|
1370 ;;; Potential cause: someone else's admin during window P, with
|
|
1371 ;;; caller's admin happening before their checkout.
|
|
1372 ;;;
|
|
1373 ;;; RCS: ci will fail with a "no lock set by <user>" message.
|
|
1374 ;;; SCCS: admin will fail with error (ad19).
|
|
1375 ;;;
|
|
1376 ;;; We can let these errors be passed up to the user.
|
|
1377 ;;;
|
|
1378 ;;; 2. File looked unregistered but is actually locked by caller, unchanged.
|
|
1379 ;;;
|
|
1380 ;;; Potential cause: self-race during window P.
|
|
1381 ;;;
|
|
1382 ;;; RCS: will revert the file to the last saved version and unlock it.
|
|
1383 ;;; SCCS: will fail with error (ad19).
|
|
1384 ;;;
|
|
1385 ;;; Either of these consequences is acceptable.
|
|
1386 ;;;
|
|
1387 ;;; 3. File looked unregistered but is actually locked by caller, changed.
|
|
1388 ;;;
|
|
1389 ;;; Potential cause: self-race during window P.
|
|
1390 ;;;
|
|
1391 ;;; RCS: will register the caller's workfile as a delta with a
|
|
1392 ;;; null change comment (the -t- switch will be ignored).
|
|
1393 ;;; SCCS: will fail with error (ad19).
|
|
1394 ;;;
|
|
1395 ;;; 4. File looked unregistered but is locked by someone else.
|
|
1396 ;;;
|
|
1397 ;;; Potential cause: someone else's admin during window P, with
|
|
1398 ;;; caller's admin happening *after* their checkout.
|
|
1399 ;;;
|
|
1400 ;;; RCS: will fail with a "no lock set by <user>" message.
|
|
1401 ;;; SCCS: will fail with error (ad19).
|
|
1402 ;;;
|
|
1403 ;;; We can let these errors be passed up to the user.
|
|
1404 ;;;
|
|
1405 ;;; Apparent state B ---
|
|
1406 ;;;
|
|
1407 ;;; 5. File looked registered and not locked, but is actually unregistered.
|
|
1408 ;;;
|
|
1409 ;;; Potential cause: master file got nuked during window P.
|
|
1410 ;;;
|
|
1411 ;;; RCS: will fail with "RCS/<file>: No such file or directory"
|
|
1412 ;;; SCCS: will fail with error ut4.
|
|
1413 ;;;
|
|
1414 ;;; We can let these errors be passed up to the user.
|
|
1415 ;;;
|
|
1416 ;;; 6. File looked registered and not locked, but is actually locked by the
|
|
1417 ;;; calling user and unchanged.
|
|
1418 ;;;
|
|
1419 ;;; Potential cause: self-race during window T.
|
|
1420 ;;;
|
|
1421 ;;; RCS: in the same directory as the previous workfile, co -l will fail
|
|
1422 ;;; with "co error: writable foo exists; checkout aborted". In any other
|
|
1423 ;;; directory, checkout will succeed.
|
|
1424 ;;; SCCS: will fail with ge17.
|
|
1425 ;;;
|
|
1426 ;;; Either of these consequences is acceptable.
|
|
1427 ;;;
|
|
1428 ;;; 7. File looked registered and not locked, but is actually locked by the
|
|
1429 ;;; calling user and changed.
|
|
1430 ;;;
|
|
1431 ;;; As case 6.
|
|
1432 ;;;
|
|
1433 ;;; 8. File looked registered and not locked, but is actually locked by another
|
|
1434 ;;; user.
|
|
1435 ;;;
|
|
1436 ;;; Potential cause: someone else checks it out during window T.
|
|
1437 ;;;
|
|
1438 ;;; RCS: co error: revision 1.3 already locked by <user>
|
|
1439 ;;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
|
|
1440 ;;;
|
|
1441 ;;; We can let these errors be passed up to the user.
|
|
1442 ;;;
|
|
1443 ;;; Apparent state C ---
|
|
1444 ;;;
|
|
1445 ;;; 9. File looks locked by calling user and unchanged, but is unregistered.
|
|
1446 ;;;
|
|
1447 ;;; As case 5.
|
|
1448 ;;;
|
|
1449 ;;; 10. File looks locked by calling user and unchanged, but is actually not
|
|
1450 ;;; locked.
|
|
1451 ;;;
|
|
1452 ;;; Potential cause: a self-race in window U, or by the revert's
|
|
1453 ;;; landing during window X of some other user's steal-lock or window S
|
|
1454 ;;; of another user's revert.
|
|
1455 ;;;
|
|
1456 ;;; RCS: succeeds, refreshing the file from the identical version in
|
|
1457 ;;; the master.
|
|
1458 ;;; SCCS: fails with error ut4 (p file nonexistent).
|
|
1459 ;;;
|
|
1460 ;;; Either of these consequences is acceptable.
|
|
1461 ;;;
|
|
1462 ;;; 11. File is locked by calling user. It looks unchanged, but is actually
|
|
1463 ;;; changed.
|
|
1464 ;;;
|
|
1465 ;;; Potential cause: the file would have to be touched by a self-race
|
|
1466 ;;; during window Q.
|
|
1467 ;;;
|
|
1468 ;;; The revert will succeed, removing whatever changes came with
|
|
1469 ;;; the touch. It is theoretically possible that work could be lost.
|
|
1470 ;;;
|
|
1471 ;;; 12. File looks like it's locked by the calling user and unchanged, but
|
|
1472 ;;; it's actually locked by someone else.
|
|
1473 ;;;
|
|
1474 ;;; Potential cause: a steal-lock in window V.
|
|
1475 ;;;
|
|
1476 ;;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
|
|
1477 ;;; SCCS: fails with error un2
|
|
1478 ;;;
|
|
1479 ;;; We can pass these errors up to the user.
|
|
1480 ;;;
|
|
1481 ;;; Apparent state D ---
|
|
1482 ;;;
|
|
1483 ;;; 13. File looks like it's locked by the calling user and changed, but it's
|
|
1484 ;;; actually unregistered.
|
|
1485 ;;;
|
|
1486 ;;; Potential cause: master file got nuked during window P.
|
|
1487 ;;;
|
|
1488 ;;; RCS: Checks in the user's version as an initial delta.
|
|
1489 ;;; SCCS: will fail with error ut4.
|
|
1490 ;;;
|
|
1491 ;;; This case is kind of nasty. It means VC may fail to detect the
|
|
1492 ;;; loss of previous version information.
|
|
1493 ;;;
|
|
1494 ;;; 14. File looks like it's locked by the calling user and changed, but it's
|
|
1495 ;;; actually unlocked.
|
|
1496 ;;;
|
|
1497 ;;; Potential cause: self-race in window V, or the checkin happening
|
|
1498 ;;; during the window X of someone else's steal-lock or window S of
|
|
1499 ;;; someone else's revert.
|
|
1500 ;;;
|
|
1501 ;;; RCS: ci will fail with "no lock set by <user>".
|
|
1502 ;;; SCCS: delta will fail with error ut4.
|
|
1503 ;;;
|
|
1504 ;;; 15. File looks like it's locked by the calling user and changed, but it's
|
|
1505 ;;; actually locked by the calling user and unchanged.
|
|
1506 ;;;
|
|
1507 ;;; Potential cause: another self-race --- a whole checkin/checkout
|
|
1508 ;;; sequence by the calling user would have to land in window R.
|
|
1509 ;;;
|
|
1510 ;;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
|
|
1511 ;;; RCS: reverts to the file state as of the second user's checkin, leaving
|
|
1512 ;;; the file unlocked.
|
|
1513 ;;;
|
|
1514 ;;; It is theoretically possible that work could be lost under RCS.
|
|
1515 ;;;
|
|
1516 ;;; 16. File looks like it's locked by the calling user and changed, but it's
|
|
1517 ;;; actually locked by a different user.
|
|
1518 ;;;
|
|
1519 ;;; RCS: ci error: no lock set by <user>
|
|
1520 ;;; SCCS: unget will fail with error un2
|
|
1521 ;;;
|
|
1522 ;;; We can pass these errors up to the user.
|
|
1523 ;;;
|
|
1524 ;;; Apparent state E ---
|
|
1525 ;;;
|
|
1526 ;;; 17. File looks like it's locked by some other user, but it's actually
|
|
1527 ;;; unregistered.
|
|
1528 ;;;
|
|
1529 ;;; As case 13.
|
|
1530 ;;;
|
|
1531 ;;; 18. File looks like it's locked by some other user, but it's actually
|
|
1532 ;;; unlocked.
|
|
1533 ;;;
|
|
1534 ;;; Potential cause: someone released a lock during window W.
|
|
1535 ;;;
|
|
1536 ;;; RCS: The calling user will get the lock on the file.
|
|
1537 ;;; SCCS: unget -n will fail with cm4.
|
|
1538 ;;;
|
|
1539 ;;; Either of these consequences will be OK.
|
|
1540 ;;;
|
|
1541 ;;; 19. File looks like it's locked by some other user, but it's actually
|
|
1542 ;;; locked by the calling user and unchanged.
|
|
1543 ;;;
|
|
1544 ;;; Potential cause: the other user relinquishing a lock followed by
|
|
1545 ;;; a self-race, both in window W.
|
|
1546 ;;;
|
|
1547 ;;; Under both RCS and SCCS, both unlock and lock will succeed, making
|
|
1548 ;;; the sequence a no-op.
|
|
1549 ;;;
|
|
1550 ;;; 20. File looks like it's locked by some other user, but it's actually
|
|
1551 ;;; locked by the calling user and changed.
|
|
1552 ;;;
|
|
1553 ;;; As case 19.
|
|
1554 ;;;
|
|
1555 ;;; PROBLEM CASES:
|
|
1556 ;;;
|
|
1557 ;;; In order of decreasing severity:
|
|
1558 ;;;
|
|
1559 ;;; Cases 11 and 15 under RCS are the only one that potentially lose work.
|
|
1560 ;;; They would require a self-race for this to happen.
|
|
1561 ;;;
|
|
1562 ;;; Case 13 in RCS loses information about previous deltas, retaining
|
|
1563 ;;; only the information in the current workfile. This can only happen
|
|
1564 ;;; if the master file gets nuked in window P.
|
|
1565 ;;;
|
|
1566 ;;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
|
|
1567 ;;; no change comment in the master. This would require a self-race in
|
|
1568 ;;; window P or R respectively.
|
|
1569 ;;;
|
|
1570 ;;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
|
|
1571 ;;;
|
|
1572 ;;; Unfortunately, it appears to me that no recovery is possible in these
|
|
1573 ;;; cases. They don't yield error messages, so there's no way to tell that
|
|
1574 ;;; a race condition has occurred.
|
|
1575 ;;;
|
|
1576 ;;; All other cases don't change either the workfile or the master, and
|
|
1577 ;;; trigger command errors which the user will see.
|
|
1578 ;;;
|
|
1579 ;;; Thus, there is no explicit recovery code.
|
|
1580
|
|
1581 ;;; vc.el ends here
|