diary-mail-entries calls exit-calendar when finished.
[bpt/emacs.git] / lisp / vc.el
1 ;;; vc.el --- drive a version-control system from within Emacs
2
3 ;; Copyright (C) 1992, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
4
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
6 ;; Maintainer: Andre Spiegel <spiegel@inf.fu-berlin.de>
7
8 ;; $Id: vc.el,v 1.232 1998/06/16 16:38:47 rms Exp eliz $
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;; This mode is fully documented in the Emacs user's manual.
30 ;;
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.
34 ;; CVS support was added by Per Cederqvist <ceder@lysator.liu.se>
35 ;; in Jan-Feb 1994. Further enhancements came from ttn@netcom.com and
36 ;; Andre Spiegel <spiegel@inf.fu-berlin.de>.
37 ;;
38 ;; Supported version-control systems presently include SCCS, RCS, and CVS.
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).
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.
47 ;;
48 ;; You can support the RCS -x option by adding pairs to the
49 ;; vc-master-templates list.
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 ;;
54 ;; If your site uses the ChangeLog convention supported by Emacs, the
55 ;; function vc-comment-to-change-log should prove a useful checkin hook.
56 ;;
57 ;; This code depends on call-process passing back the subprocess exit
58 ;; status. Thus, you need Emacs 18.58 or later to run it. For the
59 ;; vc-directory command to work properly as documented, you need 19.
60 ;; You also need Emacs 19's ring.el.
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
64 ;; once. If you perform version control operations with RCS/SCCS/CVS while
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)
74 (require 'ring)
75 (eval-when-compile (require 'dired)) ; for dired-map-over-marks macro
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)))
81
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
99 ;; General customization
100
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
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
119 :group 'vc
120 :version "20.3")
121
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
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
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)
173
174 (defconst vc-maximum-comment-ring-size 32
175 "Maximum number of saved comments in the comment ring.")
176
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
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
222 ;;;###autoload
223 (defcustom vc-checkin-hook nil
224 "*Normal hook (list of functions) run after a checkin is done.
225 See `run-hooks'."
226 :type 'hook
227 :options '(vc-comment-to-change-log)
228 :group 'vc)
229
230 ;;;###autoload
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)
236
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
243 ;; Header-insertion hair
244
245 (defcustom vc-header-alist
246 '((SCCS "\%W\%") (RCS "\$Id\$") (CVS "\$Id\$"))
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
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
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
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)
269
270 (defcustom vc-comment-alist
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
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)
281
282 ;; Default is to be extra careful for super-user.
283 (defcustom vc-checkout-carefully (= (user-uid) 0)
284 "*Non-nil means be extra-careful in checkout.
285 Verify that the file really is not locked
286 and that its contents match what the master file says."
287 :type 'boolean
288 :group 'vc)
289
290 (defcustom vc-rcs-release nil
291 "*The release number of your RCS installation, as a string.
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)
296
297 (defcustom vc-sccs-release nil
298 "*The release number of your SCCS installation, as a string.
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)
303
304 (defcustom vc-cvs-release nil
305 "*The release number of your CVS installation, as a string.
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)
310
311 ;; Variables the user doesn't need to know about.
312 (defvar vc-log-entry-mode nil)
313 (defvar vc-log-operation nil)
314 (defvar vc-log-after-operation-hook nil)
315 (defvar vc-checkout-writable-buffer-hook 'vc-checkout-writable-buffer)
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).
319 (defvar vc-parent-buffer nil)
320 (defvar vc-parent-buffer-name nil)
321
322 (defvar vc-log-file)
323 (defvar vc-log-version)
324
325 (defconst vc-name-assoc-file "VC-names")
326
327 (defvar vc-dired-mode nil)
328 (make-variable-buffer-local 'vc-dired-mode)
329
330 (defvar vc-comment-ring (make-ring vc-maximum-comment-ring-size))
331 (defvar vc-comment-ring-index nil)
332 (defvar vc-last-comment-match nil)
333
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
341 (and (zerop (vc-do-command nil nil "rcs" nil nil "-V"))
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
398 ;;; functions that operate on RCS revision numbers
399
400 (defun vc-trunk-p (rev)
401 ;; return t if REV is a revision on the trunk
402 (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev))))
403
404 (defun vc-branch-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
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
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
432 ;; File property caching
433
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.
440 (setq vc-comment-ring (make-ring vc-maximum-comment-ring-size)))
441
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)
453 (vc-file-setprop file 'vc-master-workfile-version nil)
454 (vc-file-setprop file 'vc-master-locks nil))
455 (progn
456 (vc-file-setprop file 'vc-cvs-status nil))))
457
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))))
463
464 ;; Random helper functions
465
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
483 ;; whole current branch. (vc-master-workfile-version
484 ;; is not what we need.)
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
495 t))
496
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))))))
507
508 (defvar vc-binary-assoc nil)
509 (defvar vc-binary-suffixes
510 (if (memq system-type '(ms-dos windows-nt))
511 '(".exe" ".com" ".bat" ".cmd" ".btm" "")
512 '("")))
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))
516 (catch 'found
517 (mapcar
518 (function
519 (lambda (s)
520 (if s
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))))))))
533 exec-path)
534 nil)))
535
536 (defun vc-do-command (buffer okstatus command file last &rest flags)
537 "Execute a version-control command, notifying user and checking for errors.
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."
548 (and file (setq file (expand-file-name file)))
549 (if (not buffer) (setq buffer "*vc*"))
550 (if vc-command-messages
551 (message "Running %s on %s..." command file))
552 (let ((obuf (current-buffer)) (camefrom (current-buffer))
553 (squeezed nil)
554 (olddir default-directory)
555 vc-file status)
556 (set-buffer (get-buffer-create buffer))
557 (set (make-local-variable 'vc-parent-buffer) camefrom)
558 (set (make-local-variable 'vc-parent-buffer-name)
559 (concat " from " (buffer-name camefrom)))
560 (setq default-directory olddir)
561
562 (erase-buffer)
563
564 (mapcar
565 (function (lambda (s) (and s (setq squeezed (append squeezed (list s))))))
566 flags)
567 (if (and (eq last 'MASTER) file (setq vc-file (vc-name file)))
568 (setq squeezed (append squeezed (list vc-file))))
569 (if (and file (eq last 'WORKFILE))
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)))))
576 (let ((exec-path (append vc-path exec-path))
577 ;; Add vc-path to PATH for the execution of this command.
578 (process-environment
579 (cons (concat "PATH=" (getenv "PATH")
580 path-separator
581 (mapconcat 'identity vc-path path-separator))
582 process-environment))
583 (w32-quote-process-args t))
584 (setq status (apply 'call-process command nil t nil squeezed)))
585 (goto-char (point-max))
586 (set-buffer-modified-p nil)
587 (forward-line -1)
588 (if (or (not (integerp status)) (and okstatus (< okstatus status)))
589 (progn
590 (pop-to-buffer buffer)
591 (goto-char (point-min))
592 (shrink-window-if-larger-than-buffer)
593 (error "Running %s...FAILED (%s)" command
594 (if (integerp status)
595 (format "status %d" status)
596 status))
597 )
598 (if vc-command-messages
599 (message "Running %s...OK" command))
600 )
601 (set-buffer obuf)
602 status)
603 )
604
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.
608 ;;; A lot of this was shamelessly lifted from Sebastian Kremer's rcs.el mode.
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
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
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.
647 (let ((point-context (vc-position-context (point)))
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.
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
660 (mapcar (function
661 (lambda (buffer)
662 (set-buffer buffer)
663 (let ((errors (or
664 compilation-old-error-list
665 compilation-error-list))
666 (buffer-error-marked-p nil))
667 (while (and (consp errors)
668 (not buffer-error-marked-p))
669 (and (markerp (cdr (car errors)))
670 (eq buffer
671 (marker-buffer
672 (cdr (car errors))))
673 (setq buffer-error-marked-p t))
674 (setq errors (cdr errors)))
675 (if buffer-error-marked-p buffer))))
676 (buffer-list)))))))
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)))
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
700 (/= error-pos (car (car compilation-error-list))))
701 (setq compilation-error-list (cdr compilation-error-list))))))
702 (setq reparse (cdr reparse)))
703
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))))
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))))))
713
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)))
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))
729 (vc-restore-buffer-context context)))
730
731
732 (defun vc-buffer-sync (&optional not-urgent)
733 ;; Make sure the current buffer and its working file are in sync
734 ;; NOT-URGENT means it is ok to continue if the user says not to save.
735 (if (buffer-modified-p)
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
743
744 (defun vc-workfile-unchanged-p (file &optional want-differences-if-changed)
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))))
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
751 (not want-differences-if-changed)))))
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)))))
755
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.
758 (let ((vc-type (vc-backend file))
759 owner version buffer)
760 (cond
761
762 ;; If the file is not under version control, register it
763 ((not vc-type)
764 (vc-register verbose comment))
765
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)))
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))))
775 (progn
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)
784 (not (yes-or-no-p
785 (format
786 "Buffer %s modified; merge file on disc anyhow? "
787 (buffer-name buffer)))))
788 (error "Merge aborted"))
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)))))
796 (error "%s needs update" (buffer-name))))
797
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
805 ;; If there is no lock on the file, assert one and get it.
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))
811 (if (and vc-checkout-carefully
812 (not (vc-workfile-unchanged-p file t)))
813 (if (save-window-excursion
814 (pop-to-buffer "*vc-diff*")
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? "))
825 (error "Checkout aborted")
826 (vc-revert-buffer1 t t)
827 (vc-checkout-writable-buffer file))
828 )
829 (if verbose
830 (if (not (eq vc-type 'SCCS))
831 (vc-checkout file nil
832 (read-string "Branch or version to move to: "))
833 (error "Sorry, this is not implemented for SCCS"))
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
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)))))))
844 )))
845
846 ;; a checked-out version exists, but the user may not own the lock
847 ((and (not (eq vc-type 'CVS))
848 (not (string-equal owner (vc-user-login-name))))
849 (if comment
850 (error "Sorry, you can't steal the lock on %s this way" file))
851 (and (eq vc-type 'RCS)
852 (not (vc-backend-release-p 'RCS "5.6.2"))
853 (error "File is locked by %s" owner))
854 (vc-steal-lock
855 file
856 (if verbose (read-string "Version to steal: ")
857 (vc-workfile-version file))
858 owner))
859
860 ;; OK, user owns the lock on the file
861 (t
862 (if vc-dired-mode
863 (find-file-other-window file)
864 (find-file file))
865
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"))
874 ;; if buffer is not saved, give user a chance to do it
875 (vc-buffer-sync))
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.
882 (if (and (vc-workfile-unchanged-p file)
883 (not (buffer-modified-p)))
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)))
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)
896 )))))
897
898 (defun vc-next-action-dired (file rev comment)
899 ;; Do a vc-next-action-on-file on all the marked files, possibly
900 ;; passing on the log comment we've just entered.
901 (let ((dired-buffer (current-buffer))
902 (dired-dir default-directory))
903 (dired-map-over-marks
904 (let ((file (dired-get-filename)))
905 (message "Processing %s..." file)
906 ;; Adjust the default directory so that checkouts
907 ;; go to the right place.
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))
915 (set-window-configuration vc-dired-window-configuration)
916 (message "Processing %s...done" file))
917 nil t))
918 (dired-move-to-filename))
919
920 ;; Here's the major entry point.
921
922 ;;;###autoload
923 (defun vc-next-action (verbose)
924 "Do the next logical checkin or checkout operation on the current file.
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.
933
934 For RCS and SCCS files:
935 If the file is not already registered, this registers it for version
936 control.
937 If the file is registered and not locked by anyone, this checks out
938 a writable and locked file ready for editing.
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.
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
944 resulting changes along with the log message as change commentary. If
945 the variable `vc-keep-workfiles' is non-nil (which is its default), a
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
948 the option to steal the lock.
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.
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
959 merge in the changes into your working copy."
960
961 (interactive "P")
962 (catch 'nogo
963 (if vc-dired-mode
964 (let ((files (dired-get-marked-files)))
965 (set (make-local-variable 'vc-dired-window-configuration)
966 (current-window-configuration))
967 (if (string= ""
968 (mapconcat
969 (function (lambda (f)
970 (if (eq (vc-backend f) 'CVS)
971 (if (or (eq (vc-cvs-status f) 'locally-modified)
972 (eq (vc-cvs-status f) 'locally-added))
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))
980 (throw 'nogo nil)))
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)))))
986
987 ;;; These functions help the vc-next-action entry point
988
989 (defun vc-checkout-writable-buffer (&optional file rev)
990 "Retrieve a writable copy of the latest version of the current buffer's file."
991 (vc-checkout (or file (buffer-file-name)) t rev)
992 )
993
994 ;;;###autoload
995 (defun vc-register (&optional override comment)
996 "Register the current file into your version-control system."
997 (interactive "P")
998 (or buffer-file-name
999 (error "No visited file"))
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")))
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))
1012 (vc-buffer-sync)
1013 (cond ((not vc-make-backup-files)
1014 ;; inhibit backup for this buffer
1015 (make-local-variable 'backup-inhibited)
1016 (setq backup-inhibited t)))
1017 (vc-admin
1018 buffer-file-name
1019 (or (and override
1020 (read-string
1021 (format "Initial version level for %s: " buffer-file-name)))
1022 vc-default-init-version)
1023 comment)
1024 ;; Recompute backend property (it may have been set to nil before).
1025 (setq vc-buffer-backend (vc-backend (buffer-file-name)))
1026 )
1027
1028 (defun vc-resynch-window (file &optional keep noquery)
1029 ;; If the given file is in the current buffer,
1030 ;; either revert on it so we see expanded keywords,
1031 ;; or unvisit it (depending on vc-keep-workfiles)
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!
1035 (and (string= buffer-file-name file)
1036 (if keep
1037 (progn
1038 (vc-revert-buffer1 t noquery)
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))))
1047 (vc-mode-line buffer-file-name))
1048 (kill-buffer (current-buffer)))))
1049
1050 (defun vc-resynch-buffer (file &optional keep noquery)
1051 ;; if FILE is currently visited, resynch its buffer
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))))))
1059
1060 (defun vc-start-entry (file rev comment msg action &optional after-hook)
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.
1064 ;; Remember the file's buffer in vc-parent-buffer (current one if no file).
1065 ;; AFTER-HOOK specifies the local value for vc-log-operation-hook.
1066 (let ((parent (if file (find-file-noselect file) (current-buffer))))
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)))
1073 (if comment
1074 (set-buffer (get-buffer-create "*VC-log*"))
1075 (pop-to-buffer (get-buffer-create "*VC-log*")))
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)))
1079 (if file (vc-mode-line file))
1080 (vc-log-mode file)
1081 (make-local-variable 'vc-log-after-operation-hook)
1082 (if after-hook
1083 (setq vc-log-after-operation-hook after-hook))
1084 (setq vc-log-operation action)
1085 (setq vc-log-version rev)
1086 (if comment
1087 (progn
1088 (erase-buffer)
1089 (if (eq comment t)
1090 (vc-finish-logentry t)
1091 (insert comment)
1092 (vc-finish-logentry nil)))
1093 (message "%s Type C-c C-c when done." msg))))
1094
1095 (defun vc-admin (file rev &optional comment)
1096 "Check a file into your version-control system.
1097 FILE is the unmodified name of the file. REV should be the base version
1098 level to check it in under. COMMENT, if specified, is the checkin comment."
1099 (vc-start-entry file rev
1100 (or comment (not vc-initial-comment))
1101 "Enter initial comment." 'vc-backend-admin
1102 nil))
1103
1104 (defun vc-checkout (file &optional writable rev)
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"))
1110 (vc-backend-checkout file writable rev)
1111 (vc-resynch-buffer file t t))
1112
1113 (defun vc-steal-lock (file rev &optional owner)
1114 "Steal the lock on the current workfile."
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))
1121 (if (not (yes-or-no-p (format "Steal the lock on %s from %s? "
1122 file-description owner)))
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
1130 (list (list 'vc-finish-steal file rev)))
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.")))
1137
1138 ;; This is called when the notification has been sent.
1139 (defun vc-finish-steal (file version)
1140 (vc-backend-steal file version)
1141 (if (get-file-buffer file)
1142 (save-excursion
1143 (set-buffer (get-file-buffer file))
1144 (vc-resynch-window file t t))))
1145
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
1149 \(if nil increment the current level). The file is either retained with write
1150 permissions zeroed, or deleted (according to the value of `vc-keep-workfiles').
1151 If the back-end is CVS, a writable workfile is always kept.
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'."
1156 (vc-start-entry file rev comment
1157 "Enter a change comment." 'vc-backend-checkin
1158 'vc-checkin-hook))
1159
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. \
1164 If nil, uses `change-log-default-name'.
1165
1166 May be useful as a `vc-checkin-hook' to update change logs automatically."
1167 (interactive (if current-prefix-arg
1168 (list current-prefix-arg
1169 (prompt-for-change-log-name))))
1170 ;; Make sure the defvar for add-log-current-defun-function has been executed
1171 ;; before binding it.
1172 (require 'add-log)
1173 (let (;; Extract the comment first so we get any error before doing anything.
1174 (comment (ring-ref vc-comment-ring 0))
1175 ;; Don't let add-change-log-entry insert a defun name.
1176 (add-log-current-defun-function 'ignore)
1177 end)
1178 ;; Call add-log to do half the work.
1179 (add-change-log-entry whoami file-name t t)
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."
1184 ;; So remove the ": " add-log inserted.
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))
1194 (setq end (point))))
1195 ;; Fill the inserted text, preserving open-parens at bol.
1196 (let ((paragraph-separate (concat paragraph-separate "\\|\\s *\\s("))
1197 (paragraph-start (concat paragraph-start "\\|\\s *\\s(")))
1198 (beginning-of-line)
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"))))
1206
1207
1208 (defun vc-finish-logentry (&optional nocomment)
1209 "Complete the operation implied by the current log entry."
1210 (interactive)
1211 ;; Check and record the comment, if any.
1212 (if (not nocomment)
1213 (progn
1214 ;; Comment too long?
1215 (vc-backend-logentry-check vc-log-file)
1216 ;; Record the comment in the comment ring
1217 (ring-insert vc-comment-ring (buffer-string))
1218 ))
1219 ;; Sync parent buffer in case the user modified it while editing the comment.
1220 ;; But not if it is a vc-dired buffer.
1221 (save-excursion
1222 (set-buffer vc-parent-buffer)
1223 (or vc-dired-mode
1224 (vc-buffer-sync)))
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))
1232 (pop-to-buffer vc-parent-buffer)
1233 ;; OK, do it to it
1234 (save-excursion
1235 (funcall log-operation
1236 log-file
1237 log-version
1238 log-entry))
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*")))
1242 (cond (logbuf
1243 (delete-windows-on logbuf)
1244 (kill-buffer logbuf))))
1245 ;; Now make sure we see the expanded headers
1246 (if buffer-file-name
1247 (vc-resynch-window buffer-file-name vc-keep-workfiles t))
1248 (if vc-dired-mode
1249 (dired-move-to-filename))
1250 (run-hooks after-hook 'vc-finish-logentry-hook)))
1251
1252 ;; Code for access to the comment ring
1253
1254 (defun vc-previous-comment (arg)
1255 "Cycle backwards through comment history."
1256 (interactive "*p")
1257 (let ((len (ring-length vc-comment-ring)))
1258 (cond ((<= len 0)
1259 (message "Empty comment ring")
1260 (ding))
1261 (t
1262 (erase-buffer)
1263 ;; Initialize the index on the first use of this command
1264 ;; so that the first M-p gets index 0, and the first M-n gets
1265 ;; index -1.
1266 (if (null vc-comment-ring-index)
1267 (setq vc-comment-ring-index
1268 (if (> arg 0) -1
1269 (if (< arg 0) 1 0))))
1270 (setq vc-comment-ring-index
1271 (mod (+ vc-comment-ring-index arg) len))
1272 (message "%d" (1+ vc-comment-ring-index))
1273 (insert (ring-ref vc-comment-ring vc-comment-ring-index))))))
1274
1275 (defun vc-next-comment (arg)
1276 "Cycle forwards through comment history."
1277 (interactive "*p")
1278 (vc-previous-comment (- arg)))
1279
1280 (defun vc-comment-search-reverse (str)
1281 "Searches backwards through comment history for substring match."
1282 (interactive "sComment substring: ")
1283 (if (string= str "")
1284 (setq str vc-last-comment-match)
1285 (setq vc-last-comment-match str))
1286 (if (null vc-comment-ring-index)
1287 (setq vc-comment-ring-index -1))
1288 (let ((str (regexp-quote str))
1289 (len (ring-length vc-comment-ring))
1290 (n (1+ vc-comment-ring-index)))
1291 (while (and (< n len) (not (string-match str (ring-ref vc-comment-ring n))))
1292 (setq n (+ n 1)))
1293 (cond ((< n len)
1294 (vc-previous-comment (- n vc-comment-ring-index)))
1295 (t (error "Not found")))))
1296
1297 (defun vc-comment-search-forward (str)
1298 "Searches forwards through comment history for substring match."
1299 (interactive "sComment substring: ")
1300 (if (string= str "")
1301 (setq str vc-last-comment-match)
1302 (setq vc-last-comment-match str))
1303 (if (null vc-comment-ring-index)
1304 (setq vc-comment-ring-index 0))
1305 (let ((str (regexp-quote str))
1306 (len (ring-length vc-comment-ring))
1307 (n vc-comment-ring-index))
1308 (while (and (>= n 0) (not (string-match str (ring-ref vc-comment-ring n))))
1309 (setq n (- n 1)))
1310 (cond ((>= n 0)
1311 (vc-next-comment (- n vc-comment-ring-index)))
1312 (t (error "Not found")))))
1313
1314 ;; Additional entry points for examining version histories
1315
1316 ;;;###autoload
1317 (defun vc-diff (historic &optional not-urgent)
1318 "Display diffs between file versions.
1319 Normally this compares the current file and buffer with the most recent
1320 checked in version of that file. This uses no arguments.
1321 With a prefix argument, it reads the file name to use
1322 and two version designators specifying which versions to compare."
1323 (interactive (list current-prefix-arg t))
1324 (vc-ensure-vc-buffer)
1325 (if historic
1326 (call-interactively 'vc-version-diff)
1327 (let ((file buffer-file-name)
1328 unchanged)
1329 (vc-buffer-sync not-urgent)
1330 (setq unchanged (vc-workfile-unchanged-p buffer-file-name))
1331 (if unchanged
1332 (message "No changes to %s since latest version" file)
1333 (vc-backend-diff file)
1334 ;; Ideally, we'd like at this point to parse the diff so that
1335 ;; the buffer effectively goes into compilation mode and we
1336 ;; can visit the old and new change locations via next-error.
1337 ;; Unfortunately, this is just too painful to do. The basic
1338 ;; problem is that the `old' file doesn't exist to be
1339 ;; visited. This plays hell with numerous assumptions in
1340 ;; the diff.el and compile.el machinery.
1341 (set-buffer "*vc-diff*")
1342 (setq default-directory (file-name-directory file))
1343 (if (= 0 (buffer-size))
1344 (progn
1345 (setq unchanged t)
1346 (message "No changes to %s since latest version" file))
1347 (pop-to-buffer "*vc-diff*")
1348 (goto-char (point-min))
1349 (shrink-window-if-larger-than-buffer)))
1350 (not unchanged))))
1351
1352 (defun vc-version-diff (file rel1 rel2)
1353 "For FILE, report diffs between two stored versions REL1 and REL2 of it.
1354 If FILE is a directory, generate diffs between versions for all registered
1355 files in or below it."
1356 (interactive
1357 (let ((file (read-file-name (if buffer-file-name
1358 "File or dir to diff: (default visited file) "
1359 "File or dir to diff: ")
1360 default-directory buffer-file-name t))
1361 (rel1-default nil) (rel2-default nil))
1362 ;; compute default versions based on the file state
1363 (cond
1364 ;; if it's a directory, don't supply any version defauolt
1365 ((file-directory-p file)
1366 nil)
1367 ;; if the file is locked, use current version as older version
1368 ((vc-locking-user file)
1369 (setq rel1-default (vc-workfile-version file)))
1370 ;; if the file is not locked, use last and previous version as default
1371 (t
1372 (setq rel1-default (vc-previous-version (vc-workfile-version file)))
1373 (setq rel2-default (vc-workfile-version file))))
1374 ;; construct argument list
1375 (list file
1376 (read-string (if rel1-default
1377 (concat "Older version: (default "
1378 rel1-default ") ")
1379 "Older version: ")
1380 nil nil rel1-default)
1381 (read-string (if rel2-default
1382 (concat "Newer version: (default "
1383 rel2-default ") ")
1384 "Newer version (default: current source): ")
1385 nil nil rel2-default))))
1386 (if (string-equal rel1 "") (setq rel1 nil))
1387 (if (string-equal rel2 "") (setq rel2 nil))
1388 (if (file-directory-p file)
1389 (let ((camefrom (current-buffer)))
1390 (set-buffer (get-buffer-create "*vc-status*"))
1391 (set (make-local-variable 'vc-parent-buffer) camefrom)
1392 (set (make-local-variable 'vc-parent-buffer-name)
1393 (concat " from " (buffer-name camefrom)))
1394 (erase-buffer)
1395 (insert "Diffs between "
1396 (or rel1 "last version checked in")
1397 " and "
1398 (or rel2 "current workfile(s)")
1399 ":\n\n")
1400 (set-buffer (get-buffer-create "*vc-diff*"))
1401 (cd file)
1402 (vc-file-tree-walk
1403 default-directory
1404 (function (lambda (f)
1405 (message "Looking at %s" f)
1406 (and
1407 (not (file-directory-p f))
1408 (vc-registered f)
1409 (vc-backend-diff f rel1 rel2)
1410 (append-to-buffer "*vc-status*" (point-min) (point-max)))
1411 )))
1412 (pop-to-buffer "*vc-status*")
1413 (insert "\nEnd of diffs.\n")
1414 (goto-char (point-min))
1415 (set-buffer-modified-p nil)
1416 )
1417 (if (zerop (vc-backend-diff file rel1 rel2))
1418 (message "No changes to %s between %s and %s." file rel1 rel2)
1419 (pop-to-buffer "*vc-diff*"))))
1420
1421 ;;;###autoload
1422 (defun vc-version-other-window (rev)
1423 "Visit version REV of the current buffer in another window.
1424 If the current buffer is named `F', the version is named `F.~REV~'.
1425 If `F.~REV~' already exists, it is used instead of being re-created."
1426 (interactive "sVersion to visit (default is latest version): ")
1427 (vc-ensure-vc-buffer)
1428 (let* ((version (if (string-equal rev "")
1429 (vc-latest-version buffer-file-name)
1430 rev))
1431 (filename (concat buffer-file-name ".~" version "~")))
1432 (or (file-exists-p filename)
1433 (vc-backend-checkout buffer-file-name nil version filename))
1434 (find-file-other-window filename)))
1435
1436 ;; Header-insertion code
1437
1438 ;;;###autoload
1439 (defun vc-insert-headers ()
1440 "Insert headers in a file for use with your version-control system.
1441 Headers desired are inserted at the start of the buffer, and are pulled from
1442 the variable `vc-header-alist'."
1443 (interactive)
1444 (vc-ensure-vc-buffer)
1445 (save-excursion
1446 (save-restriction
1447 (widen)
1448 (if (or (not (vc-check-headers))
1449 (y-or-n-p "Version headers already exist. Insert another set? "))
1450 (progn
1451 (let* ((delims (cdr (assq major-mode vc-comment-alist)))
1452 (comment-start-vc (or (car delims) comment-start "#"))
1453 (comment-end-vc (or (car (cdr delims)) comment-end ""))
1454 (hdstrings (cdr (assoc (vc-backend (buffer-file-name)) vc-header-alist))))
1455 (mapcar (function (lambda (s)
1456 (insert comment-start-vc "\t" s "\t"
1457 comment-end-vc "\n")))
1458 hdstrings)
1459 (if vc-static-header-alist
1460 (mapcar (function (lambda (f)
1461 (if (string-match (car f) buffer-file-name)
1462 (insert (format (cdr f) (car hdstrings))))))
1463 vc-static-header-alist))
1464 )
1465 )))))
1466
1467 (defun vc-clear-headers ()
1468 ;; Clear all version headers in the current buffer, i.e. reset them
1469 ;; to the nonexpanded form. Only implemented for RCS, yet.
1470 ;; Don't lose point and mark during this.
1471 (let ((context (vc-buffer-context))
1472 (case-fold-search nil))
1473 ;; save-excursion may be able to relocate point and mark properly.
1474 ;; If it fails, vc-restore-buffer-context will give it a second try.
1475 (save-excursion
1476 (goto-char (point-min))
1477 (while (re-search-forward
1478 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
1479 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
1480 nil t)
1481 (replace-match "$\\1$")))
1482 (vc-restore-buffer-context context)))
1483
1484 ;;;###autoload
1485 (defun vc-merge ()
1486 (interactive)
1487 (vc-ensure-vc-buffer)
1488 (vc-buffer-sync)
1489 (let* ((file buffer-file-name)
1490 (backend (vc-backend file))
1491 first-version second-version locking-user)
1492 (if (eq backend 'SCCS)
1493 (error "Sorry, merging is not implemented for SCCS")
1494 (setq locking-user (vc-locking-user file))
1495 (if (eq (vc-checkout-model file) 'manual)
1496 (if (not locking-user)
1497 (if (not (y-or-n-p
1498 (format "File must be %s for merging. %s now? "
1499 (if (eq backend 'RCS) "locked" "writable")
1500 (if (eq backend 'RCS) "Lock" "Check out"))))
1501 (error "Merge aborted")
1502 (vc-checkout file t))
1503 (if (not (string= locking-user (vc-user-login-name)))
1504 (error "File is locked by %s" locking-user))))
1505 (setq first-version (read-string "Branch or version to merge from: "))
1506 (if (and (>= (elt first-version 0) ?0)
1507 (<= (elt first-version 0) ?9))
1508 (if (not (vc-branch-p first-version))
1509 (setq second-version
1510 (read-string "Second version: "
1511 (concat (vc-branch-part first-version) ".")))
1512 ;; We want to merge an entire branch. Set versions
1513 ;; accordingly, so that vc-backend-merge understands us.
1514 (setq second-version first-version)
1515 ;; first-version must be the starting point of the branch
1516 (setq first-version (vc-branch-part first-version))))
1517 (let ((status (vc-backend-merge file first-version second-version)))
1518 (if (and (eq (vc-checkout-model file) 'implicit)
1519 (not (vc-locking-user file)))
1520 (vc-file-setprop file 'vc-locking-user nil))
1521 (vc-resynch-buffer file t t)
1522 (if (not (zerop status))
1523 (if (y-or-n-p "Conflicts detected. Resolve them now? ")
1524 (vc-resolve-conflicts "WORKFILE" "MERGE SOURCE")
1525 (message "File contains conflict markers"))
1526 (message "Merge successful"))))))
1527
1528 ;;;###autoload
1529 (defun vc-resolve-conflicts (&optional name-A name-B)
1530 "Invoke ediff to resolve conflicts in the current buffer.
1531 The conflicts must be marked with rcsmerge conflict markers."
1532 (interactive)
1533 (vc-ensure-vc-buffer)
1534 (let* ((found nil)
1535 (file-name (file-name-nondirectory buffer-file-name))
1536 (your-buffer (generate-new-buffer
1537 (concat "*" file-name
1538 " " (or name-A "WORKFILE") "*")))
1539 (other-buffer (generate-new-buffer
1540 (concat "*" file-name
1541 " " (or name-B "CHECKED-IN") "*")))
1542 (result-buffer (current-buffer)))
1543 (save-excursion
1544 (set-buffer your-buffer)
1545 (erase-buffer)
1546 (insert-buffer result-buffer)
1547 (goto-char (point-min))
1548 (while (re-search-forward (concat "^<<<<<<< "
1549 (regexp-quote file-name) "\n") nil t)
1550 (setq found t)
1551 (replace-match "")
1552 (if (not (re-search-forward "^=======\n" nil t))
1553 (error "Malformed conflict marker"))
1554 (replace-match "")
1555 (let ((start (point)))
1556 (if (not (re-search-forward "^>>>>>>> [0-9.]+\n" nil t))
1557 (error "Malformed conflict marker"))
1558 (delete-region start (point))))
1559 (if (not found)
1560 (progn
1561 (kill-buffer your-buffer)
1562 (kill-buffer other-buffer)
1563 (error "No conflict markers found")))
1564 (set-buffer other-buffer)
1565 (erase-buffer)
1566 (insert-buffer result-buffer)
1567 (goto-char (point-min))
1568 (while (re-search-forward (concat "^<<<<<<< "
1569 (regexp-quote file-name) "\n") nil t)
1570 (let ((start (match-beginning 0)))
1571 (if (not (re-search-forward "^=======\n" nil t))
1572 (error "Malformed conflict marker"))
1573 (delete-region start (point))
1574 (if (not (re-search-forward "^>>>>>>> [0-9.]+\n" nil t))
1575 (error "Malformed conflict marker"))
1576 (replace-match "")))
1577 (let ((config (current-window-configuration))
1578 (ediff-default-variant 'default-B))
1579
1580 ;; Fire up ediff.
1581
1582 (set-buffer (ediff-merge-buffers your-buffer other-buffer))
1583
1584 ;; Ediff is now set up, and we are in the control buffer.
1585 ;; Do a few further adjustments and take precautions for exit.
1586
1587 (make-local-variable 'vc-ediff-windows)
1588 (setq vc-ediff-windows config)
1589 (make-local-variable 'vc-ediff-result)
1590 (setq vc-ediff-result result-buffer)
1591 (make-local-variable 'ediff-quit-hook)
1592 (setq ediff-quit-hook
1593 (function
1594 (lambda ()
1595 (let ((buffer-A ediff-buffer-A)
1596 (buffer-B ediff-buffer-B)
1597 (buffer-C ediff-buffer-C)
1598 (result vc-ediff-result)
1599 (windows vc-ediff-windows))
1600 (ediff-cleanup-mess)
1601 (set-buffer result)
1602 (erase-buffer)
1603 (insert-buffer buffer-C)
1604 (kill-buffer buffer-A)
1605 (kill-buffer buffer-B)
1606 (kill-buffer buffer-C)
1607 (set-window-configuration windows)
1608 (message "Conflict resolution finished; you may save the buffer")))))
1609 (message "Please resolve conflicts now; exit ediff when done")
1610 nil))))
1611
1612 ;; The VC directory major mode. Coopt Dired for this.
1613 ;; All VC commands get mapped into logical equivalents.
1614
1615 (define-derived-mode vc-dired-mode dired-mode "Dired under VC"
1616 "The major mode used in VC directory buffers. It works like Dired,
1617 but lists only files under version control, with the current VC state of
1618 each file being indicated in the place of the file's link count, owner,
1619 group and size. Subdirectories are also listed, and you may insert them
1620 into the buffer as desired, like in Dired.
1621 All Dired commands operate normally, with the exception of `v', which
1622 is redefined as the version control prefix, so that you can type
1623 `vl', `v=' etc. to invoke `vc-print-log', `vc-diff', and the like on
1624 the file named in the current Dired buffer line. `vv' invokes
1625 `vc-next-action' on this file, or on all files currently marked.
1626 There is a special command, `*l', to mark all files currently locked."
1627 (make-local-hook 'dired-after-readin-hook)
1628 (add-hook 'dired-after-readin-hook 'vc-dired-hook nil t)
1629 ;; The following is slightly modified from dired.el,
1630 ;; because file lines look a bit different in vc-dired-mode.
1631 (set (make-local-variable 'dired-move-to-filename-regexp)
1632 (let*
1633 ((l "\\([A-Za-z]\\|[^\0-\177]\\)")
1634 ;; In some locales, month abbreviations are as short as 2 letters,
1635 ;; and they can be padded on the right with spaces.
1636 (month (concat l l "+ *"))
1637 ;; Recognize any non-ASCII character.
1638 ;; The purpose is to match a Kanji character.
1639 (k "[^\0-\177]")
1640 ;; (k "[^\x00-\x7f\x80-\xff]")
1641 (s " ")
1642 (yyyy "[0-9][0-9][0-9][0-9]")
1643 (mm "[ 0-1][0-9]")
1644 (dd "[ 0-3][0-9]")
1645 (HH:MM "[ 0-2][0-9]:[0-5][0-9]")
1646 (western (concat "\\(" month s dd "\\|" dd s month "\\)"
1647 s "\\(" HH:MM "\\|" s yyyy "\\)"))
1648 (japanese (concat mm k s dd k s "\\(" s HH:MM "\\|" yyyy k "\\)")))
1649 (concat s "\\(" western "\\|" japanese "\\)" s)))
1650 (and (boundp 'vc-dired-switches)
1651 vc-dired-switches
1652 (set (make-local-variable 'dired-actual-switches)
1653 vc-dired-switches))
1654 (set (make-local-variable 'vc-dired-terse-mode) vc-dired-terse-display)
1655 (setq vc-dired-mode t))
1656
1657 (define-key vc-dired-mode-map "\C-xv" vc-prefix-map)
1658 (define-key vc-dired-mode-map "v" vc-prefix-map)
1659
1660 (defun vc-dired-toggle-terse-mode ()
1661 "Toggle terse display in VC Dired."
1662 (interactive)
1663 (if (not vc-dired-mode)
1664 nil
1665 (setq vc-dired-terse-mode (not vc-dired-terse-mode))
1666 (if vc-dired-terse-mode
1667 (vc-dired-hook)
1668 (revert-buffer))))
1669
1670 (define-key vc-dired-mode-map "vt" 'vc-dired-toggle-terse-mode)
1671
1672 (defun vc-dired-mark-locked ()
1673 "Mark all files currently locked."
1674 (interactive)
1675 (dired-mark-if (let ((f (dired-get-filename nil t)))
1676 (and f
1677 (not (file-directory-p f))
1678 (vc-locking-user f)))
1679 "locked file"))
1680
1681 (define-key vc-dired-mode-map "*l" 'vc-dired-mark-locked)
1682
1683 (defun vc-fetch-cvs-status (dir)
1684 (let ((default-directory dir))
1685 ;; Don't specify DIR in this command, the default-directory is
1686 ;; enough. Otherwise it might fail with remote repositories.
1687 (vc-do-command "*vc-info*" 0 "cvs" nil nil "status")
1688 (save-excursion
1689 (set-buffer (get-buffer "*vc-info*"))
1690 (goto-char (point-min))
1691 (while (re-search-forward "^=+\n\\([^=\n].*\n\\|\n\\)+" nil t)
1692 (narrow-to-region (match-beginning 0) (match-end 0))
1693 (vc-parse-cvs-status)
1694 (goto-char (point-max))
1695 (widen)))))
1696
1697 (defun vc-dired-state-info (file)
1698 ;; Return the string that indicates the version control status
1699 ;; on a VC dired line.
1700 (let* ((cvs-state (and (eq (vc-backend file) 'CVS)
1701 (vc-cvs-status file)))
1702 (state
1703 (if cvs-state
1704 (cond ((eq cvs-state 'up-to-date) nil)
1705 ((eq cvs-state 'needs-checkout) "patch")
1706 ((eq cvs-state 'locally-modified) "modified")
1707 ((eq cvs-state 'needs-merge) "merge")
1708 ((eq cvs-state 'unresolved-conflict) "conflict")
1709 ((eq cvs-state 'locally-added) "added"))
1710 (vc-locking-user file))))
1711 (if state (concat "(" state ")"))))
1712
1713 (defun vc-dired-reformat-line (x)
1714 ;; Reformat a directory-listing line, replacing various columns with
1715 ;; version control information.
1716 ;; This code, like dired, assumes UNIX -l format.
1717 (beginning-of-line)
1718 (let ((pos (point)) limit perm date-and-file)
1719 (end-of-line)
1720 (setq limit (point))
1721 (goto-char pos)
1722 (when
1723 (or
1724 (re-search-forward ;; owner and group
1725 "^\\(..[drwxlts-]+ \\) *[0-9]+ [^ ]+ +[^ ]+ +[0-9]+\\( .*\\)"
1726 limit t)
1727 (re-search-forward ;; only owner displayed
1728 "^\\(..[drwxlts-]+ \\) *[0-9]+ [^ ]+ +[0-9]+\\( .*\\)"
1729 limit t)
1730 (re-search-forward ;; OS/2 -l format, no links, owner, group
1731 "^\\(..[drwxlts-]+ \\) *[0-9]+\\( .*\\)"
1732 limit t))
1733 (setq perm (match-string 1)
1734 date-and-file (match-string 2))
1735 (setq x (substring (concat x " ") 0 10))
1736 (replace-match (concat perm x date-and-file)))))
1737
1738 (defun vc-dired-hook ()
1739 ;; Called by dired after any portion of a vc-dired buffer has been read in.
1740 ;; Reformat the listing according to version control.
1741 (message "Getting version information... ")
1742 (let (subdir filename (buffer-read-only nil) cvs-dir)
1743 (goto-char (point-min))
1744 (while (not (eq (point) (point-max)))
1745 (cond
1746 ;; subdir header line
1747 ((setq subdir (dired-get-subdir))
1748 (if (file-directory-p (concat subdir "/CVS"))
1749 (progn
1750 (vc-fetch-cvs-status (file-name-as-directory subdir))
1751 (setq cvs-dir t))
1752 (setq cvs-dir nil))
1753 (forward-line 1)
1754 ;; erase (but don't remove) the "total" line
1755 (let ((start (point)))
1756 (end-of-line)
1757 (delete-region start (point))
1758 (beginning-of-line)
1759 (forward-line 1)))
1760 ;; directory entry
1761 ((setq filename (dired-get-filename nil t))
1762 (cond
1763 ;; subdir
1764 ((file-directory-p filename)
1765 (cond
1766 ((member (file-name-nondirectory filename)
1767 vc-directory-exclusion-list)
1768 (let ((pos (point)))
1769 (dired-kill-tree filename)
1770 (goto-char pos)
1771 (dired-kill-line)))
1772 (vc-dired-terse-mode
1773 ;; Don't show directories in terse mode. Don't use
1774 ;; dired-kill-line to remove it, because in recursive listings,
1775 ;; that would remove the directory contents as well.
1776 (delete-region (progn (beginning-of-line) (point))
1777 (progn (forward-line 1) (point))))
1778 ((string-match "\\`\\.\\.?\\'" (file-name-nondirectory filename))
1779 (dired-kill-line))
1780 (t
1781 (vc-dired-reformat-line nil)
1782 (forward-line 1))))
1783 ;; ordinary file
1784 ((if cvs-dir
1785 (and (eq (vc-file-getprop filename 'vc-backend) 'CVS)
1786 (or (not vc-dired-terse-mode)
1787 (not (eq (vc-cvs-status filename) 'up-to-date))))
1788 (and (vc-backend filename)
1789 (or (not vc-dired-terse-mode)
1790 (vc-locking-user filename))))
1791 (vc-dired-reformat-line (vc-dired-state-info filename))
1792 (forward-line 1))
1793 (t
1794 (dired-kill-line))))
1795 ;; any other line
1796 (t (forward-line 1))))
1797 (vc-dired-purge))
1798 (message "Getting version information... done")
1799 (save-restriction
1800 (widen)
1801 (cond ((eq (count-lines (point-min) (point-max)) 1)
1802 (goto-char (point-min))
1803 (message "No files locked under %s" default-directory)))))
1804
1805 (defun vc-dired-purge ()
1806 ;; Remove empty subdirs
1807 (let (subdir)
1808 (goto-char (point-min))
1809 (while (setq subdir (dired-get-subdir))
1810 (forward-line 2)
1811 (if (dired-get-filename nil t)
1812 (if (not (dired-next-subdir 1 t))
1813 (goto-char (point-max)))
1814 (forward-line -2)
1815 (if (not (string= (dired-current-directory) default-directory))
1816 (dired-do-kill-lines t "")
1817 ;; We cannot remove the top level directory.
1818 ;; Just make it look a little nicer.
1819 (forward-line 1)
1820 (kill-line)
1821 (if (not (dired-next-subdir 1 t))
1822 (goto-char (point-max))))))
1823 (goto-char (point-min))))
1824
1825 ;;;###autoload
1826 (defun vc-directory (dirname read-switches)
1827 (interactive "DDired under VC (directory): \nP")
1828 (let ((vc-dired-switches (concat dired-listing-switches
1829 (if vc-dired-recurse "R" ""))))
1830 (if read-switches
1831 (setq vc-dired-switches
1832 (read-string "Dired listing switches: "
1833 vc-dired-switches)))
1834 (require 'dired)
1835 (require 'dired-aux)
1836 ;; force a trailing slash
1837 (if (not (eq (elt dirname (1- (length dirname))) ?/))
1838 (setq dirname (concat dirname "/")))
1839 (switch-to-buffer
1840 (dired-internal-noselect (expand-file-name dirname)
1841 (or vc-dired-switches dired-listing-switches)
1842 'vc-dired-mode))))
1843
1844 ;; Named-configuration support for SCCS
1845
1846 (defun vc-add-triple (name file rev)
1847 (save-excursion
1848 (find-file (expand-file-name
1849 vc-name-assoc-file
1850 (file-name-directory (vc-name file))))
1851 (goto-char (point-max))
1852 (insert name "\t:\t" file "\t" rev "\n")
1853 (basic-save-buffer)
1854 (kill-buffer (current-buffer))
1855 ))
1856
1857 (defun vc-record-rename (file newname)
1858 (save-excursion
1859 (find-file
1860 (expand-file-name
1861 vc-name-assoc-file
1862 (file-name-directory (vc-name file))))
1863 (goto-char (point-min))
1864 ;; (replace-regexp (concat ":" (regexp-quote file) "$") (concat ":" newname))
1865 (while (re-search-forward (concat ":" (regexp-quote file) "$") nil t)
1866 (replace-match (concat ":" newname) nil nil))
1867 (basic-save-buffer)
1868 (kill-buffer (current-buffer))
1869 ))
1870
1871 (defun vc-lookup-triple (file name)
1872 ;; Return the numeric version corresponding to a named snapshot of file
1873 ;; If name is nil or a version number string it's just passed through
1874 (cond ((null name) name)
1875 ((let ((firstchar (aref name 0)))
1876 (and (>= firstchar ?0) (<= firstchar ?9)))
1877 name)
1878 (t
1879 (save-excursion
1880 (set-buffer (get-buffer-create "*vc-info*"))
1881 (vc-insert-file
1882 (expand-file-name
1883 vc-name-assoc-file
1884 (file-name-directory (vc-name file))))
1885 (prog1
1886 (car (vc-parse-buffer
1887 (list (list (concat name "\t:\t" file "\t\\(.+\\)") 1))))
1888 (kill-buffer "*vc-info*"))))
1889 ))
1890
1891 ;; Named-configuration entry points
1892
1893 (defun vc-snapshot-precondition ()
1894 ;; Scan the tree below the current directory.
1895 ;; If any files are locked, return the name of the first such file.
1896 ;; (This means, neither snapshot creation nor retrieval is allowed.)
1897 ;; If one or more of the files are currently visited, return `visited'.
1898 ;; Otherwise, return nil.
1899 (let ((status nil))
1900 (catch 'vc-locked-example
1901 (vc-file-tree-walk
1902 default-directory
1903 (function (lambda (f)
1904 (and (vc-registered f)
1905 (if (vc-locking-user f) (throw 'vc-locked-example f)
1906 (if (get-file-buffer f) (setq status 'visited)))))))
1907 status)))
1908
1909 ;;;###autoload
1910 (defun vc-create-snapshot (name)
1911 "Make a snapshot called NAME.
1912 The snapshot is made from all registered files at or below the current
1913 directory. For each file, the version level of its latest
1914 version becomes part of the named configuration."
1915 (interactive "sNew snapshot name: ")
1916 (let ((result (vc-snapshot-precondition)))
1917 (if (stringp result)
1918 (error "File %s is locked" result)
1919 (vc-file-tree-walk
1920 default-directory
1921 (function (lambda (f) (and
1922 (vc-name f)
1923 (vc-backend-assign-name f name)))))
1924 )))
1925
1926 ;;;###autoload
1927 (defun vc-retrieve-snapshot (name)
1928 "Retrieve the snapshot called NAME, or latest versions if NAME is empty.
1929 When retrieving a snapshot, there must not be any locked files at or below
1930 the current directory. If none are locked, all registered files are
1931 checked out (unlocked) at their version levels in the snapshot NAME.
1932 If NAME is the empty string, all registered files that are not currently
1933 locked are updated to the latest versions."
1934 (interactive "sSnapshot name to retrieve (default latest versions): ")
1935 (let ((update (yes-or-no-p "Update any affected buffers? ")))
1936 (if (string= name "")
1937 (progn
1938 (vc-file-tree-walk
1939 default-directory
1940 (function (lambda (f) (and
1941 (vc-registered f)
1942 (not (vc-locking-user f))
1943 (vc-error-occurred
1944 (vc-backend-checkout f nil "")
1945 (if update (vc-resynch-buffer f t t))))))))
1946 (let ((result (vc-snapshot-precondition)))
1947 (if (stringp result)
1948 (error "File %s is locked" result)
1949 (setq update (and (eq result 'visited) update))
1950 (vc-file-tree-walk
1951 default-directory
1952 (function (lambda (f) (and
1953 (vc-name f)
1954 (vc-error-occurred
1955 (vc-backend-checkout f nil name)
1956 (if update (vc-resynch-buffer f t t)))))))
1957 )))))
1958
1959 ;; Miscellaneous other entry points
1960
1961 ;;;###autoload
1962 (defun vc-print-log ()
1963 "List the change log of the current buffer in a window."
1964 (interactive)
1965 (vc-ensure-vc-buffer)
1966 (let ((file buffer-file-name))
1967 (vc-backend-print-log file)
1968 (pop-to-buffer (get-buffer-create "*vc*"))
1969 (setq default-directory (file-name-directory file))
1970 (goto-char (point-max)) (forward-line -1)
1971 (while (looking-at "=*\n")
1972 (delete-char (- (match-end 0) (match-beginning 0)))
1973 (forward-line -1))
1974 (goto-char (point-min))
1975 (if (looking-at "[\b\t\n\v\f\r ]+")
1976 (delete-char (- (match-end 0) (match-beginning 0))))
1977 (shrink-window-if-larger-than-buffer)
1978 ;; move point to the log entry for the current version
1979 (and (not (eq (vc-backend file) 'SCCS))
1980 (re-search-forward
1981 ;; also match some context, for safety
1982 (concat "----\nrevision " (vc-workfile-version file)
1983 "\\(\tlocked by:.*\n\\|\n\\)date: ") nil t)
1984 ;; set the display window so that
1985 ;; the whole log entry is displayed
1986 (let (start end lines)
1987 (beginning-of-line) (forward-line -1) (setq start (point))
1988 (if (not (re-search-forward "^----*\nrevision" nil t))
1989 (setq end (point-max))
1990 (beginning-of-line) (forward-line -1) (setq end (point)))
1991 (setq lines (count-lines start end))
1992 (cond
1993 ;; if the global information and this log entry fit
1994 ;; into the window, display from the beginning
1995 ((< (count-lines (point-min) end) (window-height))
1996 (goto-char (point-min))
1997 (recenter 0)
1998 (goto-char start))
1999 ;; if the whole entry fits into the window,
2000 ;; display it centered
2001 ((< (1+ lines) (window-height))
2002 (goto-char start)
2003 (recenter (1- (- (/ (window-height) 2) (/ lines 2)))))
2004 ;; otherwise (the entry is too large for the window),
2005 ;; display from the start
2006 (t
2007 (goto-char start)
2008 (recenter 0)))))))
2009
2010 ;;;###autoload
2011 (defun vc-revert-buffer ()
2012 "Revert the current buffer's file back to the version it was based on.
2013 This asks for confirmation if the buffer contents are not identical
2014 to that version. Note that for RCS and CVS, this function does not
2015 automatically pick up newer changes found in the master file;
2016 use C-u \\[vc-next-action] RET to do so."
2017 (interactive)
2018 (vc-ensure-vc-buffer)
2019 (let ((file buffer-file-name)
2020 ;; This operation should always ask for confirmation.
2021 (vc-suppress-confirm nil)
2022 (obuf (current-buffer)) (changed (vc-diff nil t)))
2023 (if changed
2024 (unwind-protect
2025 (if (not (yes-or-no-p "Discard changes? "))
2026 (error "Revert cancelled"))
2027 (if (and (window-dedicated-p (selected-window))
2028 (one-window-p t 'selected-frame))
2029 (make-frame-invisible (selected-frame))
2030 (delete-window))))
2031 (set-buffer obuf)
2032 (vc-backend-revert file)
2033 (vc-resynch-window file t t)))
2034
2035 ;;;###autoload
2036 (defun vc-cancel-version (norevert)
2037 "Get rid of most recently checked in version of this file.
2038 A prefix argument means do not revert the buffer afterwards."
2039 (interactive "P")
2040 (vc-ensure-vc-buffer)
2041 (cond
2042 ((eq (vc-backend (buffer-file-name)) 'CVS)
2043 (error "Unchecking files under CVS is dangerous and not supported in VC"))
2044 ((vc-locking-user (buffer-file-name))
2045 (error "This version is locked; use vc-revert-buffer to discard changes"))
2046 ((not (vc-latest-on-branch-p (buffer-file-name)))
2047 (error "This is not the latest version--VC cannot cancel it")))
2048 (let* ((target (vc-workfile-version (buffer-file-name)))
2049 (recent (if (vc-trunk-p target) "" (vc-branch-part target)))
2050 (config (current-window-configuration)) done)
2051 (if (null (yes-or-no-p (format "Remove version %s from master? " target)))
2052 nil
2053 (setq norevert (or norevert (not
2054 (yes-or-no-p "Revert buffer to most recent remaining version? "))))
2055 (vc-backend-uncheck (buffer-file-name) target)
2056 ;; Check out the most recent remaining version. If it fails, because
2057 ;; the whole branch got deleted, do a double-take and check out the
2058 ;; version where the branch started.
2059 (while (not done)
2060 (condition-case err
2061 (progn
2062 (if norevert
2063 ;; Check out locked, but only to disc, and keep
2064 ;; modifications in the buffer.
2065 (vc-backend-checkout (buffer-file-name) t recent)
2066 ;; Check out unlocked, and revert buffer.
2067 (vc-checkout (buffer-file-name) nil recent))
2068 (setq done t))
2069 ;; If the checkout fails, vc-do-command signals an error.
2070 ;; We catch this error, check the reason, correct the
2071 ;; version number, and try a second time.
2072 (error (set-buffer "*vc*")
2073 (goto-char (point-min))
2074 (if (search-forward "no side branches present for" nil t)
2075 (progn (setq recent (vc-branch-part recent))
2076 ;; vc-do-command popped up a window with
2077 ;; the error message. Get rid of it, by
2078 ;; restoring the old window configuration.
2079 (set-window-configuration config))
2080 ;; No, it was some other error: re-signal it.
2081 (signal (car err) (cdr err))))))
2082 ;; If norevert, clear version headers and mark the buffer modified.
2083 (if norevert
2084 (progn
2085 (set-visited-file-name (buffer-file-name))
2086 (if (not vc-make-backup-files)
2087 ;; inhibit backup for this buffer
2088 (progn (make-local-variable 'backup-inhibited)
2089 (setq backup-inhibited t)))
2090 (if (eq (vc-backend (buffer-file-name)) 'RCS)
2091 (progn (setq buffer-read-only nil)
2092 (vc-clear-headers)))
2093 (vc-mode-line (buffer-file-name))))
2094 (message "Version %s has been removed from the master" target)
2095 )))
2096
2097 ;;;###autoload
2098 (defun vc-rename-file (old new)
2099 "Rename file OLD to NEW, and rename its master file likewise."
2100 (interactive "fVC rename file: \nFRename to: ")
2101 ;; There are several ways of renaming files under CVS 1.3, but they all
2102 ;; have serious disadvantages. See the FAQ (available from think.com in
2103 ;; pub/cvs/). I'd rather send the user an error, than do something he might
2104 ;; consider to be wrong. When the famous, long-awaited rename database is
2105 ;; implemented things might change for the better. This is unlikely to occur
2106 ;; until CVS 2.0 is released. --ceder 1994-01-23 21:27:51
2107 (if (eq (vc-backend old) 'CVS)
2108 (error "Renaming files under CVS is dangerous and not supported in VC"))
2109 (let ((oldbuf (get-file-buffer old)))
2110 (if (and oldbuf (buffer-modified-p oldbuf))
2111 (error "Please save files before moving them"))
2112 (if (get-file-buffer new)
2113 (error "Already editing new file name"))
2114 (if (file-exists-p new)
2115 (error "New file already exists"))
2116 (let ((oldmaster (vc-name old)) newmaster)
2117 (if oldmaster
2118 (progn
2119 (if (vc-locking-user old)
2120 (error "Please check in files before moving them"))
2121 (if (or (file-symlink-p oldmaster)
2122 ;; This had FILE, I changed it to OLD. -- rms.
2123 (file-symlink-p (vc-backend-subdirectory-name old)))
2124 (error "This is not a safe thing to do in the presence of symbolic links"))
2125 (setq newmaster
2126 (let ((backend (vc-backend old))
2127 (newdir (or (file-name-directory new) ""))
2128 (newbase (file-name-nondirectory new)))
2129 (catch 'found
2130 (mapcar
2131 (function
2132 (lambda (s)
2133 (if (eq backend (cdr s))
2134 (let* ((newmaster (format (car s) newdir newbase))
2135 (newmasterdir (file-name-directory newmaster)))
2136 (if (or (not newmasterdir)
2137 (file-directory-p newmasterdir))
2138 (throw 'found newmaster))))))
2139 vc-master-templates)
2140 (error "New file lacks a version control directory"))))
2141 ;; Handle the SCCS PROJECTDIR feature. It is odd that this
2142 ;; is a special case, but a more elegant solution would require
2143 ;; significant changes in other parts of VC.
2144 (if (eq (vc-backend old) 'SCCS)
2145 (let ((project-dir (vc-sccs-project-dir)))
2146 (if project-dir
2147 (setq newmaster
2148 (concat project-dir
2149 (file-name-nondirectory newmaster))))))
2150 (rename-file oldmaster newmaster)))
2151 (if (or (not oldmaster) (file-exists-p old))
2152 (rename-file old new)))
2153 ; ?? Renaming a file might change its contents due to keyword expansion.
2154 ; We should really check out a new copy if the old copy was precisely equal
2155 ; to some checked in version. However, testing for this is tricky....
2156 (if oldbuf
2157 (save-excursion
2158 (set-buffer oldbuf)
2159 (let ((buffer-read-only buffer-read-only))
2160 (set-visited-file-name new))
2161 (vc-backend new)
2162 (vc-mode-line new)
2163 (set-buffer-modified-p nil))))
2164 ;; This had FILE, I changed it to OLD. -- rms.
2165 (vc-backend-dispatch old
2166 (vc-record-rename old new) ;SCCS
2167 nil ;RCS
2168 nil ;CVS
2169 )
2170 )
2171
2172 ;;;###autoload
2173 (defun vc-update-change-log (&rest args)
2174 "Find change log file and add entries from recent RCS/CVS logs.
2175 Normally, find log entries for all registered files in the default
2176 directory using `rcs2log', which finds CVS logs preferentially.
2177 The mark is left at the end of the text prepended to the change log.
2178
2179 With prefix arg of C-u, only find log entries for the current buffer's file.
2180
2181 With any numeric prefix arg, find log entries for all currently visited
2182 files that are under version control. This puts all the entries in the
2183 log for the default directory, which may not be appropriate.
2184
2185 From a program, any arguments are assumed to be filenames and are
2186 passed to the `rcs2log' script after massaging to be relative to the
2187 default directory."
2188 (interactive
2189 (cond ((consp current-prefix-arg) ;C-u
2190 (list buffer-file-name))
2191 (current-prefix-arg ;Numeric argument.
2192 (let ((files nil)
2193 (buffers (buffer-list))
2194 file)
2195 (while buffers
2196 (setq file (buffer-file-name (car buffers)))
2197 (and file (vc-backend file)
2198 (setq files (cons file files)))
2199 (setq buffers (cdr buffers)))
2200 files))
2201 (t
2202 ;; `rcs2log' will find the relevant RCS or CVS files
2203 ;; relative to the curent directory if none supplied.
2204 nil)))
2205 (let ((odefault default-directory)
2206 (changelog (find-change-log))
2207 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
2208 (tempfile (make-temp-name
2209 (expand-file-name "vc" temporary-file-directory)))
2210 (full-name (or add-log-full-name
2211 (user-full-name)
2212 (user-login-name)
2213 (format "uid%d" (number-to-string (user-uid)))))
2214 (mailing-address (or add-log-mailing-address
2215 user-mail-address)))
2216 (find-file-other-window changelog)
2217 (barf-if-buffer-read-only)
2218 (vc-buffer-sync)
2219 (undo-boundary)
2220 (goto-char (point-min))
2221 (push-mark)
2222 (message "Computing change log entries...")
2223 (message "Computing change log entries... %s"
2224 (unwind-protect
2225 (progn
2226 (cd odefault)
2227 (if (eq 0 (apply 'call-process "rcs2log" nil
2228 (list t tempfile) nil
2229 "-c" changelog
2230 "-u" (concat (vc-user-login-name)
2231 "\t" full-name
2232 "\t" mailing-address)
2233 (mapcar
2234 (function
2235 (lambda (f)
2236 (file-relative-name
2237 (if (file-name-absolute-p f)
2238 f
2239 (concat odefault f)))))
2240 args)))
2241 "done"
2242 (pop-to-buffer
2243 (set-buffer (get-buffer-create "*vc*")))
2244 (erase-buffer)
2245 (insert-file tempfile)
2246 "failed"))
2247 (cd (file-name-directory changelog))
2248 (delete-file tempfile)))))
2249 \f
2250 ;; vc-annotate functionality (CVS only).
2251 (defvar vc-annotate-mode nil
2252 "Variable indicating if VC-Annotate mode is active.")
2253
2254 (defvar vc-annotate-mode-map nil
2255 "Local keymap used for VC-Annotate mode.")
2256
2257 (defvar vc-annotate-mode-menu nil
2258 "Local keymap used for VC-Annotate mode's menu bar menu.")
2259
2260 ;; Syntax Table
2261 (defvar vc-annotate-mode-syntax-table nil
2262 "Syntax table used in VC-Annotate mode buffers.")
2263
2264 ;; Declare globally instead of additional parameter to
2265 ;; temp-buffer-show-function (not possible to pass more than one
2266 ;; parameter).
2267 (defvar vc-annotate-ratio nil)
2268
2269 (defun vc-annotate-mode-variables ()
2270 (if (not vc-annotate-mode-syntax-table)
2271 (progn (setq vc-annotate-mode-syntax-table (make-syntax-table))
2272 (set-syntax-table vc-annotate-mode-syntax-table)))
2273 (if (not vc-annotate-mode-map)
2274 (setq vc-annotate-mode-map (make-sparse-keymap)))
2275 (setq vc-annotate-mode-menu (make-sparse-keymap "Annotate"))
2276 (define-key vc-annotate-mode-map [menu-bar]
2277 (make-sparse-keymap "VC-Annotate"))
2278 (define-key vc-annotate-mode-map [menu-bar vc-annotate-mode]
2279 (cons "VC-Annotate" vc-annotate-mode-menu)))
2280
2281 (defun vc-annotate-mode ()
2282 "Major mode for buffers displaying output from the CVS `annotate' command.
2283
2284 You can use the mode-specific menu to alter the time-span of the used
2285 colors. See variable `vc-annotate-menu-elements' for customizing the
2286 menu items."
2287 (interactive)
2288 (kill-all-local-variables) ; Recommended by RMS.
2289 (vc-annotate-mode-variables) ; This defines various variables.
2290 (use-local-map vc-annotate-mode-map) ; This provides the local keymap.
2291 (set-syntax-table vc-annotate-mode-syntax-table)
2292 (setq major-mode 'vc-annotate-mode) ; This is how `describe-mode'
2293 ; finds out what to describe.
2294 (setq mode-name "Annotate") ; This goes into the mode line.
2295 (run-hooks 'vc-annotate-mode-hook)
2296 (vc-annotate-add-menu))
2297
2298 (defun vc-annotate-display-default (&optional event)
2299 "Use the default color spectrum for VC Annotate mode."
2300 (interactive)
2301 (message "Redisplaying annotation...")
2302 (vc-annotate-display (get-buffer (buffer-name)))
2303 (message "Redisplaying annotation...done"))
2304
2305 (defun vc-annotate-add-menu ()
2306 "Adds the menu 'Annotate' to the menu bar in VC-Annotate mode."
2307 (define-key vc-annotate-mode-menu [default]
2308 '("Default" . vc-annotate-display-default))
2309 (let ((menu-elements vc-annotate-menu-elements))
2310 (while menu-elements
2311 (let* ((element (car menu-elements))
2312 (days (round (* element
2313 (vc-annotate-car-last-cons vc-annotate-color-map)
2314 0.7585))))
2315 (setq menu-elements (cdr menu-elements))
2316 (define-key vc-annotate-mode-menu
2317 (vector days)
2318 (cons (format "Span %d days"
2319 days)
2320 `(lambda ()
2321 ,(format "Use colors spanning %d days" days)
2322 (interactive)
2323 (message "Redisplaying annotation...")
2324 (vc-annotate-display
2325 (get-buffer (buffer-name))
2326 (vc-annotate-time-span vc-annotate-color-map ,element))
2327 (message "Redisplaying annotation...done"))))))))
2328
2329 ;;;###autoload
2330 (defun vc-annotate (ratio)
2331 "Display the result of the CVS `annotate' command using colors.
2332 New lines are displayed in red, old in blue.
2333 A prefix argument specifies a factor for stretching the time scale.
2334
2335 `vc-annotate-menu-elements' customizes the menu elements of the
2336 mode-specific menu. `vc-annotate-color-map' and
2337 `vc-annotate-very-old-color' defines the mapping of time to
2338 colors. `vc-annotate-background' specifies the background color."
2339 (interactive "p")
2340 (vc-ensure-vc-buffer)
2341 (if (not (eq (vc-backend (buffer-file-name)) 'CVS))
2342 (error "Sorry, vc-annotate is only implemented for CVS"))
2343 (message "Annotating...")
2344 (let ((temp-buffer-name (concat "*cvs annotate " (buffer-name) "*"))
2345 (temp-buffer-show-function 'vc-annotate-display)
2346 (vc-annotate-ratio ratio))
2347 (with-output-to-temp-buffer temp-buffer-name
2348 (call-process "cvs" nil (get-buffer temp-buffer-name) nil
2349 "annotate" (file-name-nondirectory (buffer-file-name)))))
2350 (message "Annotating... done"))
2351
2352 (defun vc-annotate-car-last-cons (a-list)
2353 "Return car of last cons in association list A-LIST."
2354 (if (not (eq nil (cdr a-list)))
2355 (vc-annotate-car-last-cons (cdr a-list))
2356 (car (car a-list))))
2357
2358 (defun vc-annotate-time-span (a-list span &optional quantize)
2359 "Return an association list with factor SPAN applied to the time-span
2360 of association list A-LIST. Optionaly quantize to the factor of
2361 QUANTIZE."
2362 ;; Apply span to each car of every cons
2363 (if (not (eq nil a-list))
2364 (append (list (cons (* (car (car a-list)) span)
2365 (cdr (car a-list))))
2366 (vc-annotate-time-span (nthcdr (cond (quantize) ; optional
2367 (1)) ; Default to cdr
2368 a-list) span quantize))))
2369
2370 (defun vc-annotate-compcar (threshold a-list)
2371 "Test successive cons cells of association list A-LIST against
2372 THRESHOLD. Return the first cons cell which car is not less than
2373 THRESHOLD, nil otherwise"
2374 (let ((i 1)
2375 (tmp-cons (car a-list)))
2376 (while (and tmp-cons (< (car tmp-cons) threshold))
2377 (setq tmp-cons (car (nthcdr i a-list)))
2378 (setq i (+ i 1)))
2379 tmp-cons)) ; Return the appropriate value
2380
2381
2382 (defun vc-annotate-display (buffer &optional color-map)
2383 "Do the VC-Annotate display in BUFFER using COLOR-MAP."
2384
2385 ;; Handle the case of the global variable vc-annotate-ratio being
2386 ;; set. This variable is used to pass information from function
2387 ;; vc-annotate since it is not possible to use another parameter
2388 ;; (see temp-buffer-show-function).
2389 (if (and (not color-map) vc-annotate-ratio)
2390 ;; This will only be true if called from vc-annotate with ratio
2391 ;; being non-nil.
2392 (setq color-map (vc-annotate-time-span vc-annotate-color-map
2393 vc-annotate-ratio)))
2394
2395 ;; We need a list of months and their corresponding numbers.
2396 (let* ((local-month-numbers
2397 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4)
2398 ("May" . 5) ("Jun" . 6) ("Jul" . 7) ("Aug" . 8)
2399 ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12))))
2400 (set-buffer buffer)
2401 (display-buffer buffer)
2402 (if (not vc-annotate-mode) ; Turn on vc-annotate-mode if not done
2403 (vc-annotate-mode))
2404 (goto-char (point-min)) ; Position at the top of the buffer.
2405 (while (re-search-forward
2406 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): "
2407 ;; "^[0-9]+\\(\.[0-9]+\\)*\\s-+(\\sw+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): "
2408 nil t)
2409
2410 (let* (;; Unfortunately, order is important. match-string will
2411 ;; be corrupted by extent functions in XEmacs. Access
2412 ;; string-matches first.
2413 (day (string-to-number (match-string 1)))
2414 (month (cdr (assoc (match-string 2) local-month-numbers)))
2415 (year-tmp (string-to-number (match-string 3)))
2416 (year (+ (if (> 100 year-tmp) 1900 0) year-tmp)) ; Possible millenium problem
2417 (high (- (car (current-time))
2418 (car (encode-time 0 0 0 day month year))))
2419 (color (cond ((vc-annotate-compcar high (cond (color-map)
2420 (vc-annotate-color-map))))
2421 ((cons nil vc-annotate-very-old-color))))
2422 ;; substring from index 1 to remove any leading `#' in the name
2423 (face-name (concat "vc-annotate-face-" (substring (cdr color) 1)))
2424 ;; Make the face if not done.
2425 (face (cond ((intern-soft face-name))
2426 ((let ((tmp-face (make-face (intern face-name))))
2427 (set-face-foreground tmp-face (cdr color))
2428 (if vc-annotate-background
2429 (set-face-background tmp-face vc-annotate-background))
2430 tmp-face)))) ; Return the face
2431 (point (point)))
2432
2433 (forward-line 1)
2434 (overlay-put (make-overlay point (point) nil) 'face face)))))
2435
2436 \f
2437 ;; Collect back-end-dependent stuff here
2438
2439 (defun vc-backend-admin (file &optional rev comment)
2440 ;; Register a file into the version-control system
2441 ;; Automatically retrieves a read-only version of the file with
2442 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
2443 ;; it deletes the workfile.
2444 (vc-file-clearprops file)
2445 (or vc-default-back-end
2446 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))
2447 (message "Registering %s..." file)
2448 (let* ((switches
2449 (if (stringp vc-register-switches)
2450 (list vc-register-switches)
2451 vc-register-switches))
2452 (project-dir)
2453 (backend
2454 (cond
2455 ((file-exists-p (vc-backend-subdirectory-name)) vc-default-back-end)
2456 ((file-exists-p "RCS") 'RCS)
2457 ((file-exists-p "CVS") 'CVS)
2458 ((file-exists-p "SCCS") 'SCCS)
2459 ((setq project-dir (vc-sccs-project-dir)) 'SCCS)
2460 (t vc-default-back-end))))
2461 (cond ((eq backend 'SCCS)
2462 (let ((vc-name
2463 (if project-dir (concat project-dir
2464 "s." (file-name-nondirectory file))
2465 (format
2466 (car (rassq 'SCCS vc-master-templates))
2467 (or (file-name-directory file) "")
2468 (file-name-nondirectory file)))))
2469 (apply 'vc-do-command nil 0 "admin" nil nil ;; SCCS
2470 (and rev (concat "-r" rev))
2471 "-fb"
2472 (concat "-i" file)
2473 (and comment (concat "-y" comment))
2474 vc-name
2475 switches))
2476 (delete-file file)
2477 (if vc-keep-workfiles
2478 (vc-do-command nil 0 "get" file 'MASTER)))
2479 ((eq backend 'RCS)
2480 (apply 'vc-do-command nil 0 "ci" file 'WORKFILE ;; RCS
2481 ;; if available, use the secure registering option
2482 (and (vc-backend-release-p 'RCS "5.6.4") "-i")
2483 (concat (if vc-keep-workfiles "-u" "-r") rev)
2484 (and comment (concat "-t-" comment))
2485 switches))
2486 ((eq backend 'CVS)
2487 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE ;; CVS
2488 "add"
2489 (and comment (string-match "[^\t\n ]" comment)
2490 (concat "-m" comment))
2491 switches)
2492 )))
2493 (message "Registering %s...done" file)
2494 )
2495
2496 (defun vc-backend-checkout (file &optional writable rev workfile)
2497 ;; Retrieve a copy of a saved version into a workfile
2498 (let ((filename (or workfile file))
2499 (file-buffer (get-file-buffer file))
2500 switches)
2501 (message "Checking out %s..." filename)
2502 (save-excursion
2503 ;; Change buffers to get local value of vc-checkout-switches.
2504 (if file-buffer (set-buffer file-buffer))
2505 (setq switches (if (stringp vc-checkout-switches)
2506 (list vc-checkout-switches)
2507 vc-checkout-switches))
2508 ;; Save this buffer's default-directory
2509 ;; and use save-excursion to make sure it is restored
2510 ;; in the same buffer it was saved in.
2511 (let ((default-directory default-directory))
2512 (save-excursion
2513 ;; Adjust the default-directory so that the check-out creates
2514 ;; the file in the right place.
2515 (setq default-directory (file-name-directory filename))
2516 (vc-backend-dispatch file
2517 (progn ;; SCCS
2518 (and rev (string= rev "") (setq rev nil))
2519 (if workfile
2520 ;; Some SCCS implementations allow checking out directly to a
2521 ;; file using the -G option, but then some don't so use the
2522 ;; least common denominator approach and use the -p option
2523 ;; ala RCS.
2524 (let ((vc-modes (logior (file-modes (vc-name file))
2525 (if writable 128 0)))
2526 (failed t))
2527 (unwind-protect
2528 (progn
2529 (apply 'vc-do-command
2530 nil 0 "/bin/sh" file 'MASTER "-c"
2531 ;; Some shells make the "" dummy argument into $0
2532 ;; while others use the shell's name as $0 and
2533 ;; use the "" as $1. The if-statement
2534 ;; converts the latter case to the former.
2535 (format "if [ x\"$1\" = x ]; then shift; fi; \
2536 umask %o; exec >\"$1\" || exit; \
2537 shift; umask %o; exec get \"$@\""
2538 (logand 511 (lognot vc-modes))
2539 (logand 511 (lognot (default-file-modes))))
2540 "" ; dummy argument for shell's $0
2541 filename
2542 (if writable "-e")
2543 "-p"
2544 (and rev
2545 (concat "-r" (vc-lookup-triple file rev)))
2546 switches)
2547 (setq failed nil))
2548 (and failed (file-exists-p filename)
2549 (delete-file filename))))
2550 (apply 'vc-do-command nil 0 "get" file 'MASTER ;; SCCS
2551 (if writable "-e")
2552 (and rev (concat "-r" (vc-lookup-triple file rev)))
2553 switches)
2554 (vc-file-setprop file 'vc-workfile-version nil)))
2555 (if workfile ;; RCS
2556 ;; RCS doesn't let us check out into arbitrary file names directly.
2557 ;; Use `co -p' and make stdout point to the correct file.
2558 (let ((vc-modes (logior (file-modes (vc-name file))
2559 (if writable 128 0)))
2560 (failed t))
2561 (unwind-protect
2562 (progn
2563 (apply 'vc-do-command
2564 nil 0 "/bin/sh" file 'MASTER "-c"
2565 ;; See the SCCS case, above, regarding the
2566 ;; if-statement.
2567 (format "if [ x\"$1\" = x ]; then shift; fi; \
2568 umask %o; exec >\"$1\" || exit; \
2569 shift; umask %o; exec co \"$@\""
2570 (logand 511 (lognot vc-modes))
2571 (logand 511 (lognot (default-file-modes))))
2572 "" ; dummy argument for shell's $0
2573 filename
2574 (if writable "-l")
2575 (concat "-p" rev)
2576 switches)
2577 (setq failed nil))
2578 (and failed (file-exists-p filename) (delete-file filename))))
2579 (let (new-version)
2580 ;; if we should go to the head of the trunk,
2581 ;; clear the default branch first
2582 (and rev (string= rev "")
2583 (vc-do-command nil 0 "rcs" file 'MASTER "-b"))
2584 ;; now do the checkout
2585 (apply 'vc-do-command
2586 nil 0 "co" file 'MASTER
2587 ;; If locking is not strict, force to overwrite
2588 ;; the writable workfile.
2589 (if (eq (vc-checkout-model file) 'implicit) "-f")
2590 (if writable "-l")
2591 (if rev (concat "-r" rev)
2592 ;; if no explicit revision was specified,
2593 ;; check out that of the working file
2594 (let ((workrev (vc-workfile-version file)))
2595 (if workrev (concat "-r" workrev)
2596 nil)))
2597 switches)
2598 ;; determine the new workfile version
2599 (save-excursion
2600 (set-buffer "*vc*")
2601 (goto-char (point-min))
2602 (setq new-version
2603 (if (re-search-forward "^revision \\([0-9.]+\\).*\n" nil t)
2604 (buffer-substring (match-beginning 1) (match-end 1)))))
2605 (vc-file-setprop file 'vc-workfile-version new-version)
2606 ;; if necessary, adjust the default branch
2607 (and rev (not (string= rev ""))
2608 (vc-do-command nil 0 "rcs" file 'MASTER
2609 (concat "-b" (if (vc-latest-on-branch-p file)
2610 (if (vc-trunk-p new-version) nil
2611 (vc-branch-part new-version))
2612 new-version))))))
2613 (if workfile ;; CVS
2614 ;; CVS is much like RCS
2615 (let ((failed t))
2616 (unwind-protect
2617 (progn
2618 (apply 'vc-do-command
2619 nil 0 "/bin/sh" file 'WORKFILE "-c"
2620 "exec >\"$1\" || exit; shift; exec cvs update \"$@\""
2621 "" ; dummy argument for shell's $0
2622 workfile
2623 (concat "-r" rev)
2624 "-p"
2625 switches)
2626 (setq failed nil))
2627 (and failed (file-exists-p filename) (delete-file filename))))
2628 ;; default for verbose checkout: clear the sticky tag
2629 ;; so that the actual update will get the head of the trunk
2630 (and rev (string= rev "")
2631 (vc-do-command nil 0 "cvs" file 'WORKFILE "update" "-A"))
2632 ;; If a revision was specified, check that out.
2633 (if rev
2634 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE
2635 (and writable (eq (vc-checkout-model file) 'manual) "-w")
2636 "update"
2637 (and rev (not (string= rev ""))
2638 (concat "-r" rev))
2639 switches)
2640 ;; If no revision was specified, call "cvs edit" to make
2641 ;; the file writeable.
2642 (and writable (eq (vc-checkout-model file) 'manual)
2643 (vc-do-command nil 0 "cvs" file 'WORKFILE "edit")))
2644 (if rev (vc-file-setprop file 'vc-workfile-version nil))))
2645 (cond
2646 ((not workfile)
2647 (vc-file-clear-masterprops file)
2648 (if writable
2649 (vc-file-setprop file 'vc-locking-user (vc-user-login-name)))
2650 (vc-file-setprop file
2651 'vc-checkout-time (nth 5 (file-attributes file)))))
2652 (message "Checking out %s...done" filename))))))
2653
2654 (defun vc-backend-logentry-check (file)
2655 (vc-backend-dispatch file
2656 (if (>= (buffer-size) 512) ;; SCCS
2657 (progn
2658 (goto-char 512)
2659 (error
2660 "Log must be less than 512 characters; point is now at pos 512")))
2661 nil ;; RCS
2662 nil) ;; CVS
2663 )
2664
2665 (defun vc-backend-checkin (file rev comment)
2666 ;; Register changes to FILE as level REV with explanatory COMMENT.
2667 ;; Automatically retrieves a read-only version of the file with
2668 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
2669 ;; it deletes the workfile.
2670 ;; Adaptation for RCS branch support: if this is an explicit checkin,
2671 ;; or if the checkin creates a new branch, set the master file branch
2672 ;; accordingly.
2673 (message "Checking in %s..." file)
2674 ;; "This log message intentionally left almost blank".
2675 ;; RCS 5.7 gripes about white-space-only comments too.
2676 (or (and comment (string-match "[^\t\n ]" comment))
2677 (setq comment "*** empty log message ***"))
2678 (save-excursion
2679 ;; Change buffers to get local value of vc-checkin-switches.
2680 (set-buffer (or (get-file-buffer file) (current-buffer)))
2681 (let ((switches
2682 (if (stringp vc-checkin-switches)
2683 (list vc-checkin-switches)
2684 vc-checkin-switches)))
2685 ;; Clear the master-properties. Do that here, not at the
2686 ;; end, because if the check-in fails we want them to get
2687 ;; re-computed before the next try.
2688 (vc-file-clear-masterprops file)
2689 (vc-backend-dispatch file
2690 ;; SCCS
2691 (progn
2692 (apply 'vc-do-command nil 0 "delta" file 'MASTER
2693 (if rev (concat "-r" rev))
2694 (concat "-y" comment)
2695 switches)
2696 (vc-file-setprop file 'vc-locking-user 'none)
2697 (vc-file-setprop file 'vc-workfile-version nil)
2698 (if vc-keep-workfiles
2699 (vc-do-command nil 0 "get" file 'MASTER))
2700 )
2701 ;; RCS
2702 (let ((old-version (vc-workfile-version file)) new-version)
2703 (apply 'vc-do-command nil 0 "ci" file 'MASTER
2704 ;; if available, use the secure check-in option
2705 (and (vc-backend-release-p 'RCS "5.6.4") "-j")
2706 (concat (if vc-keep-workfiles "-u" "-r") rev)
2707 (concat "-m" comment)
2708 switches)
2709 (vc-file-setprop file 'vc-locking-user 'none)
2710 (vc-file-setprop file 'vc-workfile-version nil)
2711
2712 ;; determine the new workfile version
2713 (set-buffer "*vc*")
2714 (goto-char (point-min))
2715 (if (or (re-search-forward
2716 "new revision: \\([0-9.]+\\);" nil t)
2717 (re-search-forward
2718 "reverting to previous revision \\([0-9.]+\\)" nil t))
2719 (progn (setq new-version (buffer-substring (match-beginning 1)
2720 (match-end 1)))
2721 (vc-file-setprop file 'vc-workfile-version new-version)))
2722
2723 ;; if we got to a different branch, adjust the default
2724 ;; branch accordingly
2725 (cond
2726 ((and old-version new-version
2727 (not (string= (vc-branch-part old-version)
2728 (vc-branch-part new-version))))
2729 (vc-do-command nil 0 "rcs" file 'MASTER
2730 (if (vc-trunk-p new-version) "-b"
2731 (concat "-b" (vc-branch-part new-version))))
2732 ;; If this is an old RCS release, we might have
2733 ;; to remove a remaining lock.
2734 (if (not (vc-backend-release-p 'RCS "5.6.2"))
2735 ;; exit status of 1 is also accepted.
2736 ;; It means that the lock was removed before.
2737 (vc-do-command nil 1 "rcs" file 'MASTER
2738 (concat "-u" old-version))))))
2739 ;; CVS
2740 (progn
2741 ;; explicit check-in to the trunk requires a
2742 ;; double check-in (first unexplicit) (CVS-1.3)
2743 (condition-case nil
2744 (progn
2745 (if (and rev (vc-trunk-p rev))
2746 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE
2747 "ci" "-m" "intermediate"
2748 switches))
2749 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE
2750 "ci" (if rev (concat "-r" rev))
2751 (concat "-m" comment)
2752 switches))
2753 (error (if (eq (vc-cvs-status file) 'needs-merge)
2754 ;; The CVS output will be on top of this message.
2755 (error "Type C-x 0 C-x C-q to merge in changes")
2756 (error "Check-in failed"))))
2757 ;; determine and store the new workfile version
2758 (set-buffer "*vc*")
2759 (goto-char (point-min))
2760 (if (re-search-forward
2761 "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" nil t)
2762 (vc-file-setprop file 'vc-workfile-version
2763 (buffer-substring (match-beginning 2)
2764 (match-end 2)))
2765 (vc-file-setprop file 'vc-workfile-version nil))
2766 ;; if this was an explicit check-in, remove the sticky tag
2767 (if rev
2768 (vc-do-command nil 0 "cvs" file 'WORKFILE "update" "-A"))
2769 ;; Forget the checkout model, because we might have assumed
2770 ;; a wrong one when we found the file. After commit, we can
2771 ;; tell it from the permissions of the file
2772 ;; (see vc-checkout-model).
2773 (vc-file-setprop file 'vc-checkout-model nil)
2774 (vc-file-setprop file 'vc-locking-user 'none)
2775 (vc-file-setprop file 'vc-checkout-time
2776 (nth 5 (file-attributes file)))))))
2777 (message "Checking in %s...done" file))
2778
2779 (defun vc-backend-revert (file)
2780 ;; Revert file to the version it was based on.
2781 (message "Reverting %s..." file)
2782 (vc-file-clear-masterprops file)
2783 (vc-backend-dispatch
2784 file
2785 ;; SCCS
2786 (progn
2787 (vc-do-command nil 0 "unget" file 'MASTER nil)
2788 (vc-do-command nil 0 "get" file 'MASTER nil)
2789 ;; Checking out explicit versions is not supported under SCCS, yet.
2790 ;; We always "revert" to the latest version; therefore
2791 ;; vc-workfile-version is cleared here so that it gets recomputed.
2792 (vc-file-setprop file 'vc-workfile-version nil))
2793 ;; RCS
2794 (vc-do-command nil 0 "co" file 'MASTER
2795 "-f" (concat "-u" (vc-workfile-version file)))
2796 ;; CVS
2797 ;; Check out via standard output (caused by the final argument
2798 ;; FILE below), so that no sticky tag is set.
2799 (vc-backend-checkout file nil (vc-workfile-version file) file))
2800 (vc-file-setprop file 'vc-locking-user 'none)
2801 (vc-file-setprop file 'vc-checkout-time (nth 5 (file-attributes file)))
2802 (message "Reverting %s...done" file)
2803 )
2804
2805 (defun vc-backend-steal (file &optional rev)
2806 ;; Steal the lock on the current workfile. Needs RCS 5.6.2 or later for -M.
2807 (message "Stealing lock on %s..." file)
2808 (vc-backend-dispatch file
2809 (progn ;SCCS
2810 (vc-do-command nil 0 "unget" file 'MASTER "-n" (if rev (concat "-r" rev)))
2811 (vc-do-command nil 0 "get" file 'MASTER "-g" (if rev (concat "-r" rev)))
2812 )
2813 (vc-do-command nil 0 "rcs" file 'MASTER ;RCS
2814 "-M" (concat "-u" rev) (concat "-l" rev))
2815 (error "You cannot steal a CVS lock; there are no CVS locks to steal") ;CVS
2816 )
2817 (vc-file-setprop file 'vc-locking-user (vc-user-login-name))
2818 (message "Stealing lock on %s...done" file)
2819 )
2820
2821 (defun vc-backend-uncheck (file target)
2822 ;; Undo the latest checkin.
2823 (message "Removing last change from %s..." file)
2824 (vc-backend-dispatch file
2825 (vc-do-command nil 0 "rmdel" file 'MASTER (concat "-r" target))
2826 (vc-do-command nil 0 "rcs" file 'MASTER (concat "-o" target))
2827 nil ;; this is never reached under CVS
2828 )
2829 (message "Removing last change from %s...done" file)
2830 )
2831
2832 (defun vc-backend-print-log (file)
2833 ;; Get change log associated with FILE.
2834 (vc-backend-dispatch
2835 file
2836 (vc-do-command nil 0 "prs" file 'MASTER)
2837 (vc-do-command nil 0 "rlog" file 'MASTER)
2838 (vc-do-command nil 0 "cvs" file 'WORKFILE "log")))
2839
2840 (defun vc-backend-assign-name (file name)
2841 ;; Assign to a FILE's latest version a given NAME.
2842 (vc-backend-dispatch file
2843 (vc-add-triple name file (vc-latest-version file)) ;; SCCS
2844 (vc-do-command nil 0 "rcs" file 'MASTER (concat "-n" name ":")) ;; RCS
2845 (vc-do-command nil 0 "cvs" file 'WORKFILE "tag" name) ;; CVS
2846 )
2847 )
2848
2849 (defun vc-backend-diff (file &optional oldvers newvers cmp)
2850 ;; Get a difference report between two versions of FILE.
2851 ;; Get only a brief comparison report if CMP, a difference report otherwise.
2852 (let ((backend (vc-backend file)) options status
2853 (diff-switches-list (if (listp diff-switches)
2854 diff-switches
2855 (list diff-switches))))
2856 (cond
2857 ((eq backend 'SCCS)
2858 (setq oldvers (vc-lookup-triple file oldvers))
2859 (setq newvers (vc-lookup-triple file newvers))
2860 (setq options (append (list (and cmp "--brief") "-q"
2861 (and oldvers (concat "-r" oldvers))
2862 (and newvers (concat "-r" newvers)))
2863 (and (not cmp) diff-switches-list)))
2864 (apply 'vc-do-command "*vc-diff*" 1 "vcdiff" file 'MASTER options))
2865 ((eq backend 'RCS)
2866 (if (not oldvers) (setq oldvers (vc-workfile-version file)))
2867 ;; If we know that --brief is not supported, don't try it.
2868 (setq cmp (and cmp (not (eq vc-rcsdiff-knows-brief 'no))))
2869 (setq options (append (list (and cmp "--brief") "-q"
2870 (concat "-r" oldvers)
2871 (and newvers (concat "-r" newvers)))
2872 (and (not cmp) diff-switches-list)))
2873 (setq status (apply 'vc-do-command "*vc-diff*" 2
2874 "rcsdiff" file 'WORKFILE options))
2875 ;; If --brief didn't work, do a double-take and remember it
2876 ;; for the future.
2877 (if (eq status 2)
2878 (prog1
2879 (apply 'vc-do-command "*vc-diff*" 1 "rcsdiff" file 'WORKFILE
2880 (if cmp (cdr options) options))
2881 (if cmp (setq vc-rcsdiff-knows-brief 'no)))
2882 ;; If --brief DID work, remember that, too.
2883 (and cmp (not vc-rcsdiff-knows-brief)
2884 (setq vc-rcsdiff-knows-brief 'yes))
2885 status))
2886 ;; CVS is different.
2887 ((eq backend 'CVS)
2888 (if (string= (vc-workfile-version file) "0")
2889 ;; This file is added but not yet committed; there is no master file.
2890 (if (or oldvers newvers)
2891 (error "No revisions of %s exist" file)
2892 (if cmp 1 ;; file is added but not committed,
2893 ;; we regard this as "changed".
2894 ;; diff it against /dev/null.
2895 (apply 'vc-do-command
2896 "*vc-diff*" 1 "diff" file 'WORKFILE
2897 (append (if (listp diff-switches)
2898 diff-switches
2899 (list diff-switches)) '("/dev/null")))))
2900 ;; cmp is not yet implemented -- we always do a full diff.
2901 (apply 'vc-do-command
2902 "*vc-diff*" 1 "cvs" file 'WORKFILE "diff"
2903 (and oldvers (concat "-r" oldvers))
2904 (and newvers (concat "-r" newvers))
2905 (if (listp diff-switches)
2906 diff-switches
2907 (list diff-switches))))))))
2908
2909 (defun vc-backend-merge-news (file)
2910 ;; Merge in any new changes made to FILE.
2911 (message "Merging changes into %s..." file)
2912 (prog1
2913 (vc-backend-dispatch
2914 file
2915 (error "vc-backend-merge-news not meaningful for SCCS files") ;SCCS
2916 (error "vc-backend-merge-news not meaningful for RCS files") ;RCS
2917 (save-excursion ; CVS
2918 (vc-file-clear-masterprops file)
2919 (vc-file-setprop file 'vc-workfile-version nil)
2920 (vc-file-setprop file 'vc-locking-user nil)
2921 (vc-file-setprop file 'vc-checkout-time nil)
2922 (vc-do-command nil 0 "cvs" file 'WORKFILE "update")
2923 ;; Analyze the merge result reported by CVS, and set
2924 ;; file properties accordingly.
2925 (set-buffer (get-buffer "*vc*"))
2926 (goto-char (point-min))
2927 ;; get new workfile version
2928 (if (re-search-forward (concat "^Merging differences between "
2929 "[01234567890.]* and "
2930 "\\([01234567890.]*\\) into")
2931 nil t)
2932 (vc-file-setprop file 'vc-workfile-version (match-string 1)))
2933 ;; get file status
2934 (if (re-search-forward
2935 (concat "^\\([CMU]\\) "
2936 (regexp-quote (file-name-nondirectory file)))
2937 nil t)
2938 (cond
2939 ;; Merge successful, we are in sync with repository now
2940 ((string= (match-string 1) "U")
2941 (vc-file-setprop file 'vc-locking-user 'none)
2942 (vc-file-setprop file 'vc-checkout-time
2943 (nth 5 (file-attributes file)))
2944 0) ;; indicate success to the caller
2945 ;; Merge successful, but our own changes are still in the file
2946 ((string= (match-string 1) "M")
2947 (vc-file-setprop file 'vc-locking-user (vc-file-owner file))
2948 (vc-file-setprop file 'vc-checkout-time 0)
2949 0) ;; indicate success to the caller
2950 ;; Conflicts detected!
2951 ((string= (match-string 1) "C")
2952 (vc-file-setprop file 'vc-locking-user (vc-file-owner file))
2953 (vc-file-setprop file 'vc-checkout-time 0)
2954 1) ;; signal the error to the caller
2955 )
2956 (pop-to-buffer "*vc*")
2957 (error "Couldn't analyze cvs update result"))))
2958 (message "Merging changes into %s...done" file)))
2959
2960 (defun vc-backend-merge (file first-version &optional second-version)
2961 ;; Merge the changes between FIRST-VERSION and SECOND-VERSION into
2962 ;; the current working copy of FILE. It is assumed that FILE is
2963 ;; locked and writable (vc-merge ensures this).
2964 (vc-backend-dispatch file
2965 ;; SCCS
2966 (error "Sorry, merging is not implemented for SCCS")
2967 ;; RCS
2968 (vc-do-command nil 1 "rcsmerge" file 'MASTER
2969 "-kk" ;; ignore keyword conflicts
2970 (concat "-r" first-version)
2971 (if second-version (concat "-r" second-version)))
2972 ;; CVS
2973 (progn
2974 (vc-do-command nil 0 "cvs" file 'WORKFILE
2975 "update" "-kk"
2976 (concat "-j" first-version)
2977 (concat "-j" second-version))
2978 (save-excursion
2979 (set-buffer (get-buffer "*vc*"))
2980 (goto-char (point-min))
2981 (if (re-search-forward "conflicts during merge" nil t)
2982 1 ;; signal error
2983 0 ;; signal success
2984 )))))
2985
2986 (defun vc-check-headers ()
2987 "Check if the current file has any headers in it."
2988 (interactive)
2989 (save-excursion
2990 (goto-char (point-min))
2991 (vc-backend-dispatch buffer-file-name
2992 (re-search-forward "%[MIRLBSDHTEGUYFPQCZWA]%" nil t) ;; SCCS
2993 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t) ;; RCS
2994 'RCS ;; CVS works like RCS in this regard.
2995 )
2996 ))
2997
2998 ;; Back-end-dependent stuff ends here.
2999
3000 ;; Set up key bindings for use while editing log messages
3001
3002 (defun vc-log-mode (&optional file)
3003 "Minor mode for driving version-control tools.
3004 These bindings are added to the global keymap when you enter this mode:
3005 \\[vc-next-action] perform next logical version-control operation on current file
3006 \\[vc-register] register current file
3007 \\[vc-toggle-read-only] like next-action, but won't register files
3008 \\[vc-insert-headers] insert version-control headers in current file
3009 \\[vc-print-log] display change history of current file
3010 \\[vc-revert-buffer] revert buffer to latest version
3011 \\[vc-cancel-version] undo latest checkin
3012 \\[vc-diff] show diffs between file versions
3013 \\[vc-version-other-window] visit old version in another window
3014 \\[vc-directory] show all files locked by any user in or below .
3015 \\[vc-annotate] colorful display of the cvs annotate command
3016 \\[vc-update-change-log] add change log entry from recent checkins
3017
3018 While you are entering a change log message for a version, the following
3019 additional bindings will be in effect.
3020
3021 \\[vc-finish-logentry] proceed with check in, ending log message entry
3022
3023 Whenever you do a checkin, your log comment is added to a ring of
3024 saved comments. These can be recalled as follows:
3025
3026 \\[vc-next-comment] replace region with next message in comment ring
3027 \\[vc-previous-comment] replace region with previous message in comment ring
3028 \\[vc-comment-search-reverse] search backward for regexp in the comment ring
3029 \\[vc-comment-search-forward] search backward for regexp in the comment ring
3030
3031 Entry to the change-log submode calls the value of text-mode-hook, then
3032 the value of vc-log-mode-hook.
3033
3034 Global user options:
3035 vc-initial-comment If non-nil, require user to enter a change
3036 comment upon first checkin of the file.
3037
3038 vc-keep-workfiles Non-nil value prevents workfiles from being
3039 deleted when changes are checked in
3040
3041 vc-suppress-confirm Suppresses some confirmation prompts,
3042 notably for reversions.
3043
3044 vc-header-alist Which keywords to insert when adding headers
3045 with \\[vc-insert-headers]. Defaults to
3046 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under
3047 RCS and CVS.
3048
3049 vc-static-header-alist By default, version headers inserted in C files
3050 get stuffed in a static string area so that
3051 ident(RCS/CVS) or what(SCCS) can see them in
3052 the compiled object code. You can override
3053 this by setting this variable to nil, or change
3054 the header template by changing it.
3055
3056 vc-command-messages if non-nil, display run messages from the
3057 actual version-control utilities (this is
3058 intended primarily for people hacking vc
3059 itself).
3060 "
3061 (interactive)
3062 (set-syntax-table text-mode-syntax-table)
3063 (use-local-map vc-log-entry-mode)
3064 (setq local-abbrev-table text-mode-abbrev-table)
3065 (setq major-mode 'vc-log-mode)
3066 (setq mode-name "VC-Log")
3067 (make-local-variable 'vc-log-file)
3068 (setq vc-log-file file)
3069 (make-local-variable 'vc-log-version)
3070 (make-local-variable 'vc-comment-ring-index)
3071 (set-buffer-modified-p nil)
3072 (setq buffer-file-name nil)
3073 (run-hooks 'text-mode-hook 'vc-log-mode-hook)
3074 )
3075
3076 ;; Initialization code, to be done just once at load-time
3077 (if vc-log-entry-mode
3078 nil
3079 (setq vc-log-entry-mode (make-sparse-keymap))
3080 (define-key vc-log-entry-mode "\M-n" 'vc-next-comment)
3081 (define-key vc-log-entry-mode "\M-p" 'vc-previous-comment)
3082 (define-key vc-log-entry-mode "\M-r" 'vc-comment-search-reverse)
3083 (define-key vc-log-entry-mode "\M-s" 'vc-comment-search-forward)
3084 (define-key vc-log-entry-mode "\C-c\C-c" 'vc-finish-logentry)
3085 )
3086
3087 ;;; These things should probably be generally available
3088
3089 (defun vc-file-tree-walk (dirname func &rest args)
3090 "Walk recursively through DIRNAME.
3091 Invoke FUNC f ARGS on each non-directory file f underneath it."
3092 (vc-file-tree-walk-internal (expand-file-name dirname) func args)
3093 (message "Traversing directory %s...done" dirname))
3094
3095 (defun vc-file-tree-walk-internal (file func args)
3096 (if (not (file-directory-p file))
3097 (apply func file args)
3098 (message "Traversing directory %s..." (abbreviate-file-name file))
3099 (let ((dir (file-name-as-directory file)))
3100 (mapcar
3101 (function
3102 (lambda (f) (or
3103 (string-equal f ".")
3104 (string-equal f "..")
3105 (member f vc-directory-exclusion-list)
3106 (let ((dirf (concat dir f)))
3107 (or
3108 (file-symlink-p dirf) ;; Avoid possible loops
3109 (vc-file-tree-walk-internal dirf func args))))))
3110 (directory-files dir)))))
3111
3112 (provide 'vc)
3113
3114 ;;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
3115 ;;;
3116 ;;; These may be useful to anyone who has to debug or extend the package.
3117 ;;; (Note that this information corresponds to versions 5.x. Some of it
3118 ;;; might have been invalidated by the additions to support branching
3119 ;;; and RCS keyword lookup. AS, 1995/03/24)
3120 ;;;
3121 ;;; A fundamental problem in VC is that there are time windows between
3122 ;;; vc-next-action's computations of the file's version-control state and
3123 ;;; the actions that change it. This is a window open to lossage in a
3124 ;;; multi-user environment; someone else could nip in and change the state
3125 ;;; of the master during it.
3126 ;;;
3127 ;;; The performance problem is that rlog/prs calls are very expensive; we want
3128 ;;; to avoid them as much as possible.
3129 ;;;
3130 ;;; ANALYSIS:
3131 ;;;
3132 ;;; The performance problem, it turns out, simplifies in practice to the
3133 ;;; problem of making vc-locking-user fast. The two other functions that call
3134 ;;; prs/rlog will not be so commonly used that the slowdown is a problem; one
3135 ;;; makes snapshots, the other deletes the calling user's last change in the
3136 ;;; master.
3137 ;;;
3138 ;;; The race condition implies that we have to either (a) lock the master
3139 ;;; during the entire execution of vc-next-action, or (b) detect and
3140 ;;; recover from errors resulting from dispatch on an out-of-date state.
3141 ;;;
3142 ;;; Alternative (a) appears to be infeasible. The problem is that we can't
3143 ;;; guarantee that the lock will ever be removed. Suppose a user starts a
3144 ;;; checkin, the change message buffer pops up, and the user, having wandered
3145 ;;; off to do something else, simply forgets about it?
3146 ;;;
3147 ;;; Alternative (b), on the other hand, works well with a cheap way to speed up
3148 ;;; vc-locking-user. Usually, if a file is registered, we can read its locked/
3149 ;;; unlocked state and its current owner from its permissions.
3150 ;;;
3151 ;;; This shortcut will fail if someone has manually changed the workfile's
3152 ;;; permissions; also if developers are munging the workfile in several
3153 ;;; directories, with symlinks to a master (in this latter case, the
3154 ;;; permissions shortcut will fail to detect a lock asserted from another
3155 ;;; directory).
3156 ;;;
3157 ;;; Note that these cases correspond exactly to the errors which could happen
3158 ;;; because of a competing checkin/checkout race in between two instances of
3159 ;;; vc-next-action.
3160 ;;;
3161 ;;; For VC's purposes, a workfile/master pair may have the following states:
3162 ;;;
3163 ;;; A. Unregistered. There is a workfile, there is no master.
3164 ;;;
3165 ;;; B. Registered and not locked by anyone.
3166 ;;;
3167 ;;; C. Locked by calling user and unchanged.
3168 ;;;
3169 ;;; D. Locked by the calling user and changed.
3170 ;;;
3171 ;;; E. Locked by someone other than the calling user.
3172 ;;;
3173 ;;; This makes for 25 states and 20 error conditions. Here's the matrix:
3174 ;;;
3175 ;;; VC's idea of state
3176 ;;; |
3177 ;;; V Actual state RCS action SCCS action Effect
3178 ;;; A B C D E
3179 ;;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
3180 ;;; B 5 . 6 7 8 co -l get -e checkout
3181 ;;; C 9 10 . 11 12 co -u unget; get revert
3182 ;;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
3183 ;;; E 17 18 19 20 . rcs -u -M -l unget -n ; get -g steal lock
3184 ;;;
3185 ;;; All commands take the master file name as a last argument (not shown).
3186 ;;;
3187 ;;; In the discussion below, a "self-race" is a pathological situation in
3188 ;;; which VC operations are being attempted simultaneously by two or more
3189 ;;; Emacsen running under the same username.
3190 ;;;
3191 ;;; The vc-next-action code has the following windows:
3192 ;;;
3193 ;;; Window P:
3194 ;;; Between the check for existence of a master file and the call to
3195 ;;; admin/checkin in vc-buffer-admin (apparent state A). This window may
3196 ;;; never close if the initial-comment feature is on.
3197 ;;;
3198 ;;; Window Q:
3199 ;;; Between the call to vc-workfile-unchanged-p in and the immediately
3200 ;;; following revert (apparent state C).
3201 ;;;
3202 ;;; Window R:
3203 ;;; Between the call to vc-workfile-unchanged-p in and the following
3204 ;;; checkin (apparent state D). This window may never close.
3205 ;;;
3206 ;;; Window S:
3207 ;;; Between the unlock and the immediately following checkout during a
3208 ;;; revert operation (apparent state C). Included in window Q.
3209 ;;;
3210 ;;; Window T:
3211 ;;; Between vc-locking-user and the following checkout (apparent state B).
3212 ;;;
3213 ;;; Window U:
3214 ;;; Between vc-locking-user and the following revert (apparent state C).
3215 ;;; Includes windows Q and S.
3216 ;;;
3217 ;;; Window V:
3218 ;;; Between vc-locking-user and the following checkin (apparent state
3219 ;;; D). This window may never be closed if the user fails to complete the
3220 ;;; checkin message. Includes window R.
3221 ;;;
3222 ;;; Window W:
3223 ;;; Between vc-locking-user and the following steal-lock (apparent
3224 ;;; state E). This window may never close if the user fails to complete
3225 ;;; the steal-lock message. Includes window X.
3226 ;;;
3227 ;;; Window X:
3228 ;;; Between the unlock and the immediately following re-lock during a
3229 ;;; steal-lock operation (apparent state E). This window may never cloce
3230 ;;; if the user fails to complete the steal-lock message.
3231 ;;;
3232 ;;; Errors:
3233 ;;;
3234 ;;; Apparent state A ---
3235 ;;;
3236 ;;; 1. File looked unregistered but is actually registered and not locked.
3237 ;;;
3238 ;;; Potential cause: someone else's admin during window P, with
3239 ;;; caller's admin happening before their checkout.
3240 ;;;
3241 ;;; RCS: Prior to version 5.6.4, ci fails with message
3242 ;;; "no lock set by <user>". From 5.6.4 onwards, VC uses the new
3243 ;;; ci -i option and the message is "<file>,v: already exists".
3244 ;;; SCCS: admin will fail with error (ad19).
3245 ;;;
3246 ;;; We can let these errors be passed up to the user.
3247 ;;;
3248 ;;; 2. File looked unregistered but is actually locked by caller, unchanged.
3249 ;;;
3250 ;;; Potential cause: self-race during window P.
3251 ;;;
3252 ;;; RCS: Prior to version 5.6.4, reverts the file to the last saved
3253 ;;; version and unlocks it. From 5.6.4 onwards, VC uses the new
3254 ;;; ci -i option, failing with message "<file>,v: already exists".
3255 ;;; SCCS: will fail with error (ad19).
3256 ;;;
3257 ;;; Either of these consequences is acceptable.
3258 ;;;
3259 ;;; 3. File looked unregistered but is actually locked by caller, changed.
3260 ;;;
3261 ;;; Potential cause: self-race during window P.
3262 ;;;
3263 ;;; RCS: Prior to version 5.6.4, VC registers the caller's workfile as
3264 ;;; a delta with a null change comment (the -t- switch will be
3265 ;;; ignored). From 5.6.4 onwards, VC uses the new ci -i option,
3266 ;;; failing with message "<file>,v: already exists".
3267 ;;; SCCS: will fail with error (ad19).
3268 ;;;
3269 ;;; 4. File looked unregistered but is locked by someone else.
3270 ;;;
3271 ;;; Potential cause: someone else's admin during window P, with
3272 ;;; caller's admin happening *after* their checkout.
3273 ;;;
3274 ;;; RCS: Prior to version 5.6.4, ci fails with a
3275 ;;; "no lock set by <user>" message. From 5.6.4 onwards,
3276 ;;; VC uses the new ci -i option, failing with message
3277 ;;; "<file>,v: already exists".
3278 ;;; SCCS: will fail with error (ad19).
3279 ;;;
3280 ;;; We can let these errors be passed up to the user.
3281 ;;;
3282 ;;; Apparent state B ---
3283 ;;;
3284 ;;; 5. File looked registered and not locked, but is actually unregistered.
3285 ;;;
3286 ;;; Potential cause: master file got nuked during window P.
3287 ;;;
3288 ;;; RCS: will fail with "RCS/<file>: No such file or directory"
3289 ;;; SCCS: will fail with error ut4.
3290 ;;;
3291 ;;; We can let these errors be passed up to the user.
3292 ;;;
3293 ;;; 6. File looked registered and not locked, but is actually locked by the
3294 ;;; calling user and unchanged.
3295 ;;;
3296 ;;; Potential cause: self-race during window T.
3297 ;;;
3298 ;;; RCS: in the same directory as the previous workfile, co -l will fail
3299 ;;; with "co error: writable foo exists; checkout aborted". In any other
3300 ;;; directory, checkout will succeed.
3301 ;;; SCCS: will fail with ge17.
3302 ;;;
3303 ;;; Either of these consequences is acceptable.
3304 ;;;
3305 ;;; 7. File looked registered and not locked, but is actually locked by the
3306 ;;; calling user and changed.
3307 ;;;
3308 ;;; As case 6.
3309 ;;;
3310 ;;; 8. File looked registered and not locked, but is actually locked by another
3311 ;;; user.
3312 ;;;
3313 ;;; Potential cause: someone else checks it out during window T.
3314 ;;;
3315 ;;; RCS: co error: revision 1.3 already locked by <user>
3316 ;;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
3317 ;;;
3318 ;;; We can let these errors be passed up to the user.
3319 ;;;
3320 ;;; Apparent state C ---
3321 ;;;
3322 ;;; 9. File looks locked by calling user and unchanged, but is unregistered.
3323 ;;;
3324 ;;; As case 5.
3325 ;;;
3326 ;;; 10. File looks locked by calling user and unchanged, but is actually not
3327 ;;; locked.
3328 ;;;
3329 ;;; Potential cause: a self-race in window U, or by the revert's
3330 ;;; landing during window X of some other user's steal-lock or window S
3331 ;;; of another user's revert.
3332 ;;;
3333 ;;; RCS: succeeds, refreshing the file from the identical version in
3334 ;;; the master.
3335 ;;; SCCS: fails with error ut4 (p file nonexistent).
3336 ;;;
3337 ;;; Either of these consequences is acceptable.
3338 ;;;
3339 ;;; 11. File is locked by calling user. It looks unchanged, but is actually
3340 ;;; changed.
3341 ;;;
3342 ;;; Potential cause: the file would have to be touched by a self-race
3343 ;;; during window Q.
3344 ;;;
3345 ;;; The revert will succeed, removing whatever changes came with
3346 ;;; the touch. It is theoretically possible that work could be lost.
3347 ;;;
3348 ;;; 12. File looks like it's locked by the calling user and unchanged, but
3349 ;;; it's actually locked by someone else.
3350 ;;;
3351 ;;; Potential cause: a steal-lock in window V.
3352 ;;;
3353 ;;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
3354 ;;; SCCS: fails with error un2
3355 ;;;
3356 ;;; We can pass these errors up to the user.
3357 ;;;
3358 ;;; Apparent state D ---
3359 ;;;
3360 ;;; 13. File looks like it's locked by the calling user and changed, but it's
3361 ;;; actually unregistered.
3362 ;;;
3363 ;;; Potential cause: master file got nuked during window P.
3364 ;;;
3365 ;;; RCS: Prior to version 5.6.4, checks in the user's version as an
3366 ;;; initial delta. From 5.6.4 onwards, VC uses the new ci -j
3367 ;;; option, failing with message "no such file or directory".
3368 ;;; SCCS: will fail with error ut4.
3369 ;;;
3370 ;;; This case is kind of nasty. Under RCS prior to version 5.6.4,
3371 ;;; VC may fail to detect the loss of previous version information.
3372 ;;;
3373 ;;; 14. File looks like it's locked by the calling user and changed, but it's
3374 ;;; actually unlocked.
3375 ;;;
3376 ;;; Potential cause: self-race in window V, or the checkin happening
3377 ;;; during the window X of someone else's steal-lock or window S of
3378 ;;; someone else's revert.
3379 ;;;
3380 ;;; RCS: ci will fail with "no lock set by <user>".
3381 ;;; SCCS: delta will fail with error ut4.
3382 ;;;
3383 ;;; 15. File looks like it's locked by the calling user and changed, but it's
3384 ;;; actually locked by the calling user and unchanged.
3385 ;;;
3386 ;;; Potential cause: another self-race --- a whole checkin/checkout
3387 ;;; sequence by the calling user would have to land in window R.
3388 ;;;
3389 ;;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
3390 ;;; RCS: reverts to the file state as of the second user's checkin, leaving
3391 ;;; the file unlocked.
3392 ;;;
3393 ;;; It is theoretically possible that work could be lost under RCS.
3394 ;;;
3395 ;;; 16. File looks like it's locked by the calling user and changed, but it's
3396 ;;; actually locked by a different user.
3397 ;;;
3398 ;;; RCS: ci error: no lock set by <user>
3399 ;;; SCCS: unget will fail with error un2
3400 ;;;
3401 ;;; We can pass these errors up to the user.
3402 ;;;
3403 ;;; Apparent state E ---
3404 ;;;
3405 ;;; 17. File looks like it's locked by some other user, but it's actually
3406 ;;; unregistered.
3407 ;;;
3408 ;;; As case 13.
3409 ;;;
3410 ;;; 18. File looks like it's locked by some other user, but it's actually
3411 ;;; unlocked.
3412 ;;;
3413 ;;; Potential cause: someone released a lock during window W.
3414 ;;;
3415 ;;; RCS: The calling user will get the lock on the file.
3416 ;;; SCCS: unget -n will fail with cm4.
3417 ;;;
3418 ;;; Either of these consequences will be OK.
3419 ;;;
3420 ;;; 19. File looks like it's locked by some other user, but it's actually
3421 ;;; locked by the calling user and unchanged.
3422 ;;;
3423 ;;; Potential cause: the other user relinquishing a lock followed by
3424 ;;; a self-race, both in window W.
3425 ;;;
3426 ;;; Under both RCS and SCCS, both unlock and lock will succeed, making
3427 ;;; the sequence a no-op.
3428 ;;;
3429 ;;; 20. File looks like it's locked by some other user, but it's actually
3430 ;;; locked by the calling user and changed.
3431 ;;;
3432 ;;; As case 19.
3433 ;;;
3434 ;;; PROBLEM CASES:
3435 ;;;
3436 ;;; In order of decreasing severity:
3437 ;;;
3438 ;;; Cases 11 and 15 are the only ones that potentially lose work.
3439 ;;; They would require a self-race for this to happen.
3440 ;;;
3441 ;;; Case 13 in RCS loses information about previous deltas, retaining
3442 ;;; only the information in the current workfile. This can only happen
3443 ;;; if the master file gets nuked in window P.
3444 ;;;
3445 ;;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
3446 ;;; no change comment in the master. This would require a self-race in
3447 ;;; window P or R respectively.
3448 ;;;
3449 ;;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
3450 ;;;
3451 ;;; Unfortunately, it appears to me that no recovery is possible in these
3452 ;;; cases. They don't yield error messages, so there's no way to tell that
3453 ;;; a race condition has occurred.
3454 ;;;
3455 ;;; All other cases don't change either the workfile or the master, and
3456 ;;; trigger command errors which the user will see.
3457 ;;;
3458 ;;; Thus, there is no explicit recovery code.
3459
3460 ;;; vc.el ends here