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