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