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