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