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