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