Added wording for the regex files and the --ignore-case-regex option.
[emacs.git] / lisp / vc.el
blob1848a950d7209b61d1a6b9767e7402b0beaae22f
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.256 1999/10/02 10:53:18 spiegel 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 "rcs2log" nil
2288 (list t tempfile) nil
2289 "-c" changelog
2290 "-u" (concat (vc-user-login-name)
2291 "\t" full-name
2292 "\t" mailing-address)
2293 (mapcar
2294 (function
2295 (lambda (f)
2296 (file-relative-name
2297 (if (file-name-absolute-p f)
2299 (concat odefault f)))))
2300 args)))
2301 "done"
2302 (pop-to-buffer
2303 (set-buffer (get-buffer-create "*vc*")))
2304 (erase-buffer)
2305 (insert-file tempfile)
2306 "failed"))
2307 (cd (file-name-directory changelog))
2308 (delete-file tempfile)))))
2310 ;; vc-annotate functionality (CVS only).
2311 (defvar vc-annotate-mode-map nil
2312 "Local keymap used for VC-Annotate mode.")
2314 (defvar vc-annotate-mode-menu nil
2315 "Local keymap used for VC-Annotate mode's menu bar menu.")
2317 ;; Syntax Table
2318 (defvar vc-annotate-mode-syntax-table nil
2319 "Syntax table used in VC-Annotate mode buffers.")
2321 ;; Declare globally instead of additional parameter to
2322 ;; temp-buffer-show-function (not possible to pass more than one
2323 ;; parameter).
2324 (defvar vc-annotate-ratio nil)
2326 (defun vc-annotate-mode-variables ()
2327 (if (not vc-annotate-mode-syntax-table)
2328 (progn (setq vc-annotate-mode-syntax-table (make-syntax-table))
2329 (set-syntax-table vc-annotate-mode-syntax-table)))
2330 (if (not vc-annotate-mode-map)
2331 (setq vc-annotate-mode-map (make-sparse-keymap)))
2332 (setq vc-annotate-mode-menu (make-sparse-keymap "Annotate"))
2333 (define-key vc-annotate-mode-map [menu-bar]
2334 (make-sparse-keymap "VC-Annotate"))
2335 (define-key vc-annotate-mode-map [menu-bar vc-annotate-mode]
2336 (cons "VC-Annotate" vc-annotate-mode-menu)))
2338 (defun vc-annotate-mode ()
2339 "Major mode for buffers displaying output from the CVS `annotate' command.
2341 You can use the mode-specific menu to alter the time-span of the used
2342 colors. See variable `vc-annotate-menu-elements' for customizing the
2343 menu items."
2344 (interactive)
2345 (kill-all-local-variables) ; Recommended by RMS.
2346 (vc-annotate-mode-variables) ; This defines various variables.
2347 (use-local-map vc-annotate-mode-map) ; This provides the local keymap.
2348 (set-syntax-table vc-annotate-mode-syntax-table)
2349 (setq major-mode 'vc-annotate-mode) ; This is how `describe-mode'
2350 ; finds out what to describe.
2351 (setq mode-name "Annotate") ; This goes into the mode line.
2352 (run-hooks 'vc-annotate-mode-hook)
2353 (vc-annotate-add-menu))
2355 (defun vc-annotate-display-default (&optional event)
2356 "Use the default color spectrum for VC Annotate mode."
2357 (interactive)
2358 (message "Redisplaying annotation...")
2359 (vc-annotate-display (get-buffer (buffer-name)))
2360 (message "Redisplaying annotation...done"))
2362 (defun vc-annotate-add-menu ()
2363 "Adds the menu 'Annotate' to the menu bar in VC-Annotate mode."
2364 (define-key vc-annotate-mode-menu [default]
2365 '("Default" . vc-annotate-display-default))
2366 (let ((menu-elements vc-annotate-menu-elements))
2367 (while menu-elements
2368 (let* ((element (car menu-elements))
2369 (days (round (* element
2370 (vc-annotate-car-last-cons vc-annotate-color-map)
2371 0.7585))))
2372 (setq menu-elements (cdr menu-elements))
2373 (define-key vc-annotate-mode-menu
2374 (vector days)
2375 (cons (format "Span %d days"
2376 days)
2377 `(lambda ()
2378 ,(format "Use colors spanning %d days" days)
2379 (interactive)
2380 (message "Redisplaying annotation...")
2381 (vc-annotate-display
2382 (get-buffer (buffer-name))
2383 (vc-annotate-time-span vc-annotate-color-map ,element))
2384 (message "Redisplaying annotation...done"))))))))
2386 ;;;###autoload
2387 (defun vc-annotate (ratio)
2388 "Display the result of the CVS `annotate' command using colors.
2389 New lines are displayed in red, old in blue.
2390 A prefix argument specifies a factor for stretching the time scale.
2392 `vc-annotate-menu-elements' customizes the menu elements of the
2393 mode-specific menu. `vc-annotate-color-map' and
2394 `vc-annotate-very-old-color' defines the mapping of time to
2395 colors. `vc-annotate-background' specifies the background color."
2396 (interactive "p")
2397 (vc-ensure-vc-buffer)
2398 (if (not (eq (vc-backend (buffer-file-name)) 'CVS))
2399 (error "Sorry, vc-annotate is only implemented for CVS"))
2400 (message "Annotating...")
2401 (let ((temp-buffer-name (concat "*cvs annotate " (buffer-name) "*"))
2402 (temp-buffer-show-function 'vc-annotate-display)
2403 (vc-annotate-ratio ratio))
2404 (with-output-to-temp-buffer temp-buffer-name
2405 (call-process "cvs" nil (get-buffer temp-buffer-name) nil
2406 "annotate" (file-name-nondirectory (buffer-file-name)))))
2407 (message "Annotating... done"))
2409 (defun vc-annotate-car-last-cons (a-list)
2410 "Return car of last cons in association list A-LIST."
2411 (if (not (eq nil (cdr a-list)))
2412 (vc-annotate-car-last-cons (cdr a-list))
2413 (car (car a-list))))
2415 (defun vc-annotate-time-span (a-list span &optional quantize)
2416 "Return an association list with factor SPAN applied to the time-span
2417 of association list A-LIST. Optionaly quantize to the factor of
2418 QUANTIZE."
2419 ;; Apply span to each car of every cons
2420 (if (not (eq nil a-list))
2421 (append (list (cons (* (car (car a-list)) span)
2422 (cdr (car a-list))))
2423 (vc-annotate-time-span (nthcdr (cond (quantize) ; optional
2424 (1)) ; Default to cdr
2425 a-list) span quantize))))
2427 (defun vc-annotate-compcar (threshold a-list)
2428 "Test successive cons cells of association list A-LIST against
2429 THRESHOLD. Return the first cons cell which car is not less than
2430 THRESHOLD, nil otherwise"
2431 (let ((i 1)
2432 (tmp-cons (car a-list)))
2433 (while (and tmp-cons (< (car tmp-cons) threshold))
2434 (setq tmp-cons (car (nthcdr i a-list)))
2435 (setq i (+ i 1)))
2436 tmp-cons)) ; Return the appropriate value
2439 (defun vc-annotate-display (buffer &optional color-map)
2440 "Do the VC-Annotate display in BUFFER using COLOR-MAP."
2442 ;; Handle the case of the global variable vc-annotate-ratio being
2443 ;; set. This variable is used to pass information from function
2444 ;; vc-annotate since it is not possible to use another parameter
2445 ;; (see temp-buffer-show-function).
2446 (if (and (not color-map) vc-annotate-ratio)
2447 ;; This will only be true if called from vc-annotate with ratio
2448 ;; being non-nil.
2449 (setq color-map (vc-annotate-time-span vc-annotate-color-map
2450 vc-annotate-ratio)))
2452 ;; We need a list of months and their corresponding numbers.
2453 (let* ((local-month-numbers
2454 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4)
2455 ("May" . 5) ("Jun" . 6) ("Jul" . 7) ("Aug" . 8)
2456 ("Sep" . 9) ("Oct" . 10) ("Nov" . 11) ("Dec" . 12))))
2457 (set-buffer buffer)
2458 (display-buffer buffer)
2459 (or (eq major-mode 'vc-annotate-mode) ; Turn on vc-annotate-mode if not done
2460 (vc-annotate-mode))
2461 ;; Delete old overlays
2462 (mapcar
2463 (lambda (overlay)
2464 (if (overlay-get overlay 'vc-annotation)
2465 (delete-overlay overlay)))
2466 (overlays-in (point-min) (point-max)))
2467 (goto-char (point-min)) ; Position at the top of the buffer.
2468 (while (re-search-forward
2469 "^\\S-+\\s-+\\S-+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): "
2470 ;; "^[0-9]+\\(\.[0-9]+\\)*\\s-+(\\sw+\\s-+\\([0-9]+\\)-\\(\\sw+\\)-\\([0-9]+\\)): "
2471 nil t)
2473 (let* (;; Unfortunately, order is important. match-string will
2474 ;; be corrupted by extent functions in XEmacs. Access
2475 ;; string-matches first.
2476 (day (string-to-number (match-string 1)))
2477 (month (cdr (assoc (match-string 2) local-month-numbers)))
2478 (year-tmp (string-to-number (match-string 3)))
2479 ;; Years 0..68 are 2000..2068.
2480 ;; Years 69..99 are 1969..1999.
2481 (year (+ (cond ((> 69 year-tmp) 2000)
2482 ((> 100 year-tmp) 1900)
2483 (t 0))
2484 year-tmp))
2485 (high (- (car (current-time))
2486 (car (encode-time 0 0 0 day month year))))
2487 (color (cond ((vc-annotate-compcar high (cond (color-map)
2488 (vc-annotate-color-map))))
2489 ((cons nil vc-annotate-very-old-color))))
2490 ;; substring from index 1 to remove any leading `#' in the name
2491 (face-name (concat "vc-annotate-face-" (substring (cdr color) 1)))
2492 ;; Make the face if not done.
2493 (face (cond ((intern-soft face-name))
2494 ((let ((tmp-face (make-face (intern face-name))))
2495 (set-face-foreground tmp-face (cdr color))
2496 (if vc-annotate-background
2497 (set-face-background tmp-face vc-annotate-background))
2498 tmp-face)))) ; Return the face
2499 (point (point))
2500 overlay)
2502 (forward-line 1)
2503 (setq overlay (make-overlay point (point)))
2504 (overlay-put overlay 'face face)
2505 (overlay-put overlay 'vc-annotation t)))))
2508 ;; Collect back-end-dependent stuff here
2510 (defun vc-backend-admin (file &optional rev comment)
2511 ;; Register a file into the version-control system
2512 ;; Automatically retrieves a read-only version of the file with
2513 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
2514 ;; it deletes the workfile.
2515 (vc-file-clearprops file)
2516 (or vc-default-back-end
2517 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS)))
2518 (message "Registering %s..." file)
2519 (let* ((switches
2520 (if (stringp vc-register-switches)
2521 (list vc-register-switches)
2522 vc-register-switches))
2523 (project-dir)
2524 (backend
2525 (cond
2526 ((file-exists-p (vc-backend-subdirectory-name)) vc-default-back-end)
2527 ((file-exists-p "RCS") 'RCS)
2528 ((file-exists-p "CVS") 'CVS)
2529 ((file-exists-p "SCCS") 'SCCS)
2530 ((setq project-dir (vc-sccs-project-dir)) 'SCCS)
2531 (t vc-default-back-end))))
2532 (cond ((eq backend 'SCCS)
2533 (let ((vc-name
2534 (if project-dir (concat project-dir
2535 "s." (file-name-nondirectory file))
2536 (format
2537 (car (rassq 'SCCS vc-master-templates))
2538 (or (file-name-directory file) "")
2539 (file-name-nondirectory file)))))
2540 (apply 'vc-do-command nil 0 "admin" nil nil ;; SCCS
2541 (and rev (concat "-r" rev))
2542 "-fb"
2543 (concat "-i" file)
2544 (and comment (concat "-y" comment))
2545 vc-name
2546 switches))
2547 (delete-file file)
2548 (if vc-keep-workfiles
2549 (vc-do-command nil 0 "get" file 'MASTER)))
2550 ((eq backend 'RCS)
2551 (apply 'vc-do-command nil 0 "ci" file 'WORKFILE ;; RCS
2552 ;; if available, use the secure registering option
2553 (and (vc-backend-release-p 'RCS "5.6.4") "-i")
2554 (concat (if vc-keep-workfiles "-u" "-r") rev)
2555 (and comment (concat "-t-" comment))
2556 switches))
2557 ((eq backend 'CVS)
2558 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE ;; CVS
2559 "add"
2560 (and comment (string-match "[^\t\n ]" comment)
2561 (concat "-m" comment))
2562 switches)
2564 (message "Registering %s...done" file)
2567 (defun vc-backend-checkout (file &optional writable rev workfile)
2568 ;; Retrieve a copy of a saved version into a workfile
2569 (let ((filename (or workfile file))
2570 (file-buffer (get-file-buffer file))
2571 switches)
2572 (message "Checking out %s..." filename)
2573 (save-excursion
2574 ;; Change buffers to get local value of vc-checkout-switches.
2575 (if file-buffer (set-buffer file-buffer))
2576 (setq switches (if (stringp vc-checkout-switches)
2577 (list vc-checkout-switches)
2578 vc-checkout-switches))
2579 ;; Save this buffer's default-directory
2580 ;; and use save-excursion to make sure it is restored
2581 ;; in the same buffer it was saved in.
2582 (let ((default-directory default-directory))
2583 (save-excursion
2584 ;; Adjust the default-directory so that the check-out creates
2585 ;; the file in the right place.
2586 (setq default-directory (file-name-directory filename))
2587 (vc-backend-dispatch file
2588 (progn ;; SCCS
2589 (and rev (string= rev "") (setq rev nil))
2590 (if workfile
2591 ;; Some SCCS implementations allow checking out directly to a
2592 ;; file using the -G option, but then some don't so use the
2593 ;; least common denominator approach and use the -p option
2594 ;; ala RCS.
2595 (let ((vc-modes (logior (file-modes (vc-name file))
2596 (if writable 128 0)))
2597 (failed t))
2598 (unwind-protect
2599 (progn
2600 (let ((coding-system-for-read 'no-conversion)
2601 (coding-system-for-write 'no-conversion))
2602 (with-temp-file filename
2603 (apply 'vc-do-command
2604 (current-buffer) 0 "get" file 'MASTER
2605 "-s" ;; suppress diagnostic output
2606 (if writable "-e")
2607 "-p"
2608 (and rev
2609 (concat "-r"
2610 (vc-lookup-triple file rev)))
2611 switches)))
2612 (set-file-modes filename
2613 (logior (file-modes (vc-name file))
2614 (if writable 128 0)))
2615 (setq failed nil))
2616 (and failed (file-exists-p filename)
2617 (delete-file filename))))
2618 (apply 'vc-do-command nil 0 "get" file 'MASTER ;; SCCS
2619 (if writable "-e")
2620 (and rev (concat "-r" (vc-lookup-triple file rev)))
2621 switches)
2622 (vc-file-setprop file 'vc-workfile-version nil)))
2623 (if workfile ;; RCS
2624 ;; RCS doesn't let us check out into arbitrary file names directly.
2625 ;; Use `co -p' and make stdout point to the correct file.
2626 (let ((vc-modes (logior (file-modes (vc-name file))
2627 (if writable 128 0)))
2628 (failed t))
2629 (unwind-protect
2630 (progn
2631 (let ((coding-system-for-read 'no-conversion)
2632 (coding-system-for-write 'no-conversion))
2633 (with-temp-file filename
2634 (apply 'vc-do-command
2635 (current-buffer) 0 "co" file 'MASTER
2636 "-q" ;; suppress diagnostic output
2637 (if writable "-l")
2638 (concat "-p" rev)
2639 switches)))
2640 (set-file-modes filename
2641 (logior (file-modes (vc-name file))
2642 (if writable 128 0)))
2643 (setq failed nil))
2644 (and failed (file-exists-p filename) (delete-file filename))))
2645 (let (new-version)
2646 ;; if we should go to the head of the trunk,
2647 ;; clear the default branch first
2648 (and rev (string= rev "")
2649 (vc-do-command nil 0 "rcs" file 'MASTER "-b"))
2650 ;; now do the checkout
2651 (apply 'vc-do-command
2652 nil 0 "co" file 'MASTER
2653 ;; If locking is not strict, force to overwrite
2654 ;; the writable workfile.
2655 (if (eq (vc-checkout-model file) 'implicit) "-f")
2656 (if writable "-l")
2657 (if rev (concat "-r" rev)
2658 ;; if no explicit revision was specified,
2659 ;; check out that of the working file
2660 (let ((workrev (vc-workfile-version file)))
2661 (if workrev (concat "-r" workrev)
2662 nil)))
2663 switches)
2664 ;; determine the new workfile version
2665 (save-excursion
2666 (set-buffer "*vc*")
2667 (goto-char (point-min))
2668 (setq new-version
2669 (if (re-search-forward "^revision \\([0-9.]+\\).*\n" nil t)
2670 (buffer-substring (match-beginning 1) (match-end 1)))))
2671 (vc-file-setprop file 'vc-workfile-version new-version)
2672 ;; if necessary, adjust the default branch
2673 (and rev (not (string= rev ""))
2674 (vc-do-command nil 0 "rcs" file 'MASTER
2675 (concat "-b" (if (vc-latest-on-branch-p file)
2676 (if (vc-trunk-p new-version) nil
2677 (vc-branch-part new-version))
2678 new-version))))))
2679 (if workfile ;; CVS
2680 ;; CVS is much like RCS
2681 (let ((failed t))
2682 (unwind-protect
2683 (progn
2684 (let ((coding-system-for-read 'no-conversion)
2685 (coding-system-for-write 'no-conversion))
2686 (with-temp-file filename
2687 (apply 'vc-do-command
2688 (current-buffer) 0 "cvs" file 'WORKFILE
2689 "-Q" ;; suppress diagnostic output
2690 "update"
2691 (concat "-r" rev)
2692 "-p"
2693 switches)))
2694 (setq failed nil))
2695 (and failed (file-exists-p filename) (delete-file filename))))
2696 ;; default for verbose checkout: clear the sticky tag
2697 ;; so that the actual update will get the head of the trunk
2698 (and rev (string= rev "")
2699 (vc-do-command nil 0 "cvs" file 'WORKFILE "update" "-A"))
2700 ;; If a revision was specified, check that out.
2701 (if rev
2702 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE
2703 (and writable (eq (vc-checkout-model file) 'manual) "-w")
2704 "update"
2705 (and rev (not (string= rev ""))
2706 (concat "-r" rev))
2707 switches)
2708 ;; If no revision was specified, call "cvs edit" to make
2709 ;; the file writeable.
2710 (and writable (eq (vc-checkout-model file) 'manual)
2711 (vc-do-command nil 0 "cvs" file 'WORKFILE "edit")))
2712 (if rev (vc-file-setprop file 'vc-workfile-version nil))))
2713 (cond
2714 ((not workfile)
2715 (vc-file-clear-masterprops file)
2716 (if writable
2717 (vc-file-setprop file 'vc-locking-user (vc-user-login-name)))
2718 (vc-file-setprop file
2719 'vc-checkout-time (nth 5 (file-attributes file)))))
2720 (message "Checking out %s...done" filename))))))
2722 (defun vc-backend-logentry-check (file)
2723 (vc-backend-dispatch file
2724 (if (>= (buffer-size) 512) ;; SCCS
2725 (progn
2726 (goto-char 512)
2727 (error
2728 "Log must be less than 512 characters; point is now at pos 512")))
2729 nil ;; RCS
2730 nil) ;; CVS
2733 (defun vc-backend-checkin (file rev comment)
2734 ;; Register changes to FILE as level REV with explanatory COMMENT.
2735 ;; Automatically retrieves a read-only version of the file with
2736 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise
2737 ;; it deletes the workfile.
2738 ;; Adaptation for RCS branch support: if this is an explicit checkin,
2739 ;; or if the checkin creates a new branch, set the master file branch
2740 ;; accordingly.
2741 (message "Checking in %s..." file)
2742 ;; "This log message intentionally left almost blank".
2743 ;; RCS 5.7 gripes about white-space-only comments too.
2744 (or (and comment (string-match "[^\t\n ]" comment))
2745 (setq comment "*** empty log message ***"))
2746 (save-excursion
2747 ;; Change buffers to get local value of vc-checkin-switches.
2748 (set-buffer (or (get-file-buffer file) (current-buffer)))
2749 (let ((switches
2750 (if (stringp vc-checkin-switches)
2751 (list vc-checkin-switches)
2752 vc-checkin-switches)))
2753 ;; Clear the master-properties. Do that here, not at the
2754 ;; end, because if the check-in fails we want them to get
2755 ;; re-computed before the next try.
2756 (vc-file-clear-masterprops file)
2757 (vc-backend-dispatch file
2758 ;; SCCS
2759 (progn
2760 (apply 'vc-do-command nil 0 "delta" file 'MASTER
2761 (if rev (concat "-r" rev))
2762 (concat "-y" comment)
2763 switches)
2764 (vc-file-setprop file 'vc-locking-user 'none)
2765 (vc-file-setprop file 'vc-workfile-version nil)
2766 (if vc-keep-workfiles
2767 (vc-do-command nil 0 "get" file 'MASTER))
2769 ;; RCS
2770 (let ((old-version (vc-workfile-version file)) new-version)
2771 (apply 'vc-do-command nil 0 "ci" file 'MASTER
2772 ;; if available, use the secure check-in option
2773 (and (vc-backend-release-p 'RCS "5.6.4") "-j")
2774 (concat (if vc-keep-workfiles "-u" "-r") rev)
2775 (concat "-m" comment)
2776 switches)
2777 (vc-file-setprop file 'vc-locking-user 'none)
2778 (vc-file-setprop file 'vc-workfile-version nil)
2780 ;; determine the new workfile version
2781 (set-buffer "*vc*")
2782 (goto-char (point-min))
2783 (if (or (re-search-forward
2784 "new revision: \\([0-9.]+\\);" nil t)
2785 (re-search-forward
2786 "reverting to previous revision \\([0-9.]+\\)" nil t))
2787 (progn (setq new-version (buffer-substring (match-beginning 1)
2788 (match-end 1)))
2789 (vc-file-setprop file 'vc-workfile-version new-version)))
2791 ;; if we got to a different branch, adjust the default
2792 ;; branch accordingly
2793 (cond
2794 ((and old-version new-version
2795 (not (string= (vc-branch-part old-version)
2796 (vc-branch-part new-version))))
2797 (vc-do-command nil 0 "rcs" file 'MASTER
2798 (if (vc-trunk-p new-version) "-b"
2799 (concat "-b" (vc-branch-part new-version))))
2800 ;; If this is an old RCS release, we might have
2801 ;; to remove a remaining lock.
2802 (if (not (vc-backend-release-p 'RCS "5.6.2"))
2803 ;; exit status of 1 is also accepted.
2804 ;; It means that the lock was removed before.
2805 (vc-do-command nil 1 "rcs" file 'MASTER
2806 (concat "-u" old-version))))))
2807 ;; CVS
2808 (progn
2809 ;; explicit check-in to the trunk requires a
2810 ;; double check-in (first unexplicit) (CVS-1.3)
2811 (condition-case nil
2812 (progn
2813 (if (and rev (vc-trunk-p rev))
2814 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE
2815 "ci" "-m" "intermediate"
2816 switches))
2817 (apply 'vc-do-command nil 0 "cvs" file 'WORKFILE
2818 "ci" (if rev (concat "-r" rev))
2819 (concat "-m" comment)
2820 switches))
2821 (error (if (eq (vc-cvs-status file) 'needs-merge)
2822 ;; The CVS output will be on top of this message.
2823 (error "Type C-x 0 C-x C-q to merge in changes")
2824 (error "Check-in failed"))))
2825 ;; determine and store the new workfile version
2826 (set-buffer "*vc*")
2827 (goto-char (point-min))
2828 (if (re-search-forward
2829 "^\\(new\\|initial\\) revision: \\([0-9.]+\\)" nil t)
2830 (vc-file-setprop file 'vc-workfile-version
2831 (buffer-substring (match-beginning 2)
2832 (match-end 2)))
2833 (vc-file-setprop file 'vc-workfile-version nil))
2834 ;; if this was an explicit check-in, remove the sticky tag
2835 (if rev
2836 (vc-do-command nil 0 "cvs" file 'WORKFILE "update" "-A"))
2837 ;; Forget the checkout model, because we might have assumed
2838 ;; a wrong one when we found the file. After commit, we can
2839 ;; tell it from the permissions of the file
2840 ;; (see vc-checkout-model).
2841 (vc-file-setprop file 'vc-checkout-model nil)
2842 (vc-file-setprop file 'vc-locking-user 'none)
2843 (vc-file-setprop file 'vc-checkout-time
2844 (nth 5 (file-attributes file)))))))
2845 (message "Checking in %s...done" file))
2847 (defun vc-backend-revert (file)
2848 ;; Revert file to the version it was based on.
2849 (message "Reverting %s..." file)
2850 (vc-file-clear-masterprops file)
2851 (vc-backend-dispatch
2852 file
2853 ;; SCCS
2854 (progn
2855 (vc-do-command nil 0 "unget" file 'MASTER nil)
2856 (vc-do-command nil 0 "get" file 'MASTER nil)
2857 ;; Checking out explicit versions is not supported under SCCS, yet.
2858 ;; We always "revert" to the latest version; therefore
2859 ;; vc-workfile-version is cleared here so that it gets recomputed.
2860 (vc-file-setprop file 'vc-workfile-version nil))
2861 ;; RCS
2862 (vc-do-command nil 0 "co" file 'MASTER
2863 "-f" (concat "-u" (vc-workfile-version file)))
2864 ;; CVS
2865 (progn
2866 ;; Check out via standard output (caused by the final argument
2867 ;; FILE below), so that no sticky tag is set.
2868 (vc-backend-checkout file nil (vc-workfile-version file) file)
2869 ;; If "cvs edit" was used to make the file writeable,
2870 ;; call "cvs unedit" now to undo that.
2871 (if (eq (vc-checkout-model file) 'manual)
2872 (vc-do-command nil 0 "cvs" file 'WORKFILE "unedit"))))
2873 (vc-file-setprop file 'vc-locking-user 'none)
2874 (vc-file-setprop file 'vc-checkout-time (nth 5 (file-attributes file)))
2875 (message "Reverting %s...done" file)
2878 (defun vc-backend-steal (file &optional rev)
2879 ;; Steal the lock on the current workfile. Needs RCS 5.6.2 or later for -M.
2880 (message "Stealing lock on %s..." file)
2881 (vc-backend-dispatch file
2882 (progn ;SCCS
2883 (vc-do-command nil 0 "unget" file 'MASTER "-n" (if rev (concat "-r" rev)))
2884 (vc-do-command nil 0 "get" file 'MASTER "-g" (if rev (concat "-r" rev)))
2886 (vc-do-command nil 0 "rcs" file 'MASTER ;RCS
2887 "-M" (concat "-u" rev) (concat "-l" rev))
2888 (error "You cannot steal a CVS lock; there are no CVS locks to steal") ;CVS
2890 (vc-file-setprop file 'vc-locking-user (vc-user-login-name))
2891 (message "Stealing lock on %s...done" file)
2894 (defun vc-backend-uncheck (file target)
2895 ;; Undo the latest checkin.
2896 (message "Removing last change from %s..." file)
2897 (vc-backend-dispatch file
2898 (vc-do-command nil 0 "rmdel" file 'MASTER (concat "-r" target))
2899 (vc-do-command nil 0 "rcs" file 'MASTER (concat "-o" target))
2900 nil ;; this is never reached under CVS
2902 (message "Removing last change from %s...done" file)
2905 (defun vc-backend-print-log (file)
2906 ;; Get change log associated with FILE.
2907 (vc-backend-dispatch
2908 file
2909 (vc-do-command nil 0 "prs" file 'MASTER)
2910 (vc-do-command nil 0 "rlog" file 'MASTER)
2911 (vc-do-command nil 0 "cvs" file 'WORKFILE "log")))
2913 (defun vc-backend-assign-name (file name)
2914 ;; Assign to a FILE's latest version a given NAME.
2915 (vc-backend-dispatch file
2916 (vc-add-triple name file (vc-latest-version file)) ;; SCCS
2917 (vc-do-command nil 0 "rcs" file 'MASTER (concat "-n" name ":")) ;; RCS
2918 (vc-do-command nil 0 "cvs" file 'WORKFILE "tag" name) ;; CVS
2922 (defun vc-backend-diff (file &optional oldvers newvers cmp)
2923 ;; Get a difference report between two versions of FILE.
2924 ;; Get only a brief comparison report if CMP, a difference report otherwise.
2925 (let ((backend (vc-backend file)) options status
2926 (diff-switches-list (if (listp diff-switches)
2927 diff-switches
2928 (list diff-switches))))
2929 (cond
2930 ((eq backend 'SCCS)
2931 (setq oldvers (vc-lookup-triple file oldvers))
2932 (setq newvers (vc-lookup-triple file newvers))
2933 (setq options (append (list (and cmp "--brief") "-q"
2934 (and oldvers (concat "-r" oldvers))
2935 (and newvers (concat "-r" newvers)))
2936 (and (not cmp) diff-switches-list)))
2937 (apply 'vc-do-command "*vc-diff*" 1 "vcdiff" file 'MASTER options))
2938 ((eq backend 'RCS)
2939 (if (not oldvers) (setq oldvers (vc-workfile-version file)))
2940 ;; If we know that --brief is not supported, don't try it.
2941 (setq cmp (and cmp (not (eq vc-rcsdiff-knows-brief 'no))))
2942 (setq options (append (list (and cmp "--brief") "-q"
2943 (concat "-r" oldvers)
2944 (and newvers (concat "-r" newvers)))
2945 (and (not cmp) diff-switches-list)))
2946 (setq status (apply 'vc-do-command "*vc-diff*" 2
2947 "rcsdiff" file 'WORKFILE options))
2948 ;; If --brief didn't work, do a double-take and remember it
2949 ;; for the future.
2950 (if (eq status 2)
2951 (prog1
2952 (apply 'vc-do-command "*vc-diff*" 1 "rcsdiff" file 'WORKFILE
2953 (if cmp (cdr options) options))
2954 (if cmp (setq vc-rcsdiff-knows-brief 'no)))
2955 ;; If --brief DID work, remember that, too.
2956 (and cmp (not vc-rcsdiff-knows-brief)
2957 (setq vc-rcsdiff-knows-brief 'yes))
2958 status))
2959 ;; CVS is different.
2960 ((eq backend 'CVS)
2961 (if (string= (vc-workfile-version file) "0")
2962 ;; This file is added but not yet committed; there is no master file.
2963 (if (or oldvers newvers)
2964 (error "No revisions of %s exist" file)
2965 (if cmp 1 ;; file is added but not committed,
2966 ;; we regard this as "changed".
2967 ;; diff it against /dev/null.
2968 (apply 'vc-do-command
2969 "*vc-diff*" 1 "diff" file 'WORKFILE
2970 (append diff-switches-list '("/dev/null")))))
2971 ;; cmp is not yet implemented -- we always do a full diff.
2972 (apply 'vc-do-command
2973 "*vc-diff*" 1 "cvs" file 'WORKFILE "diff"
2974 (and oldvers (concat "-r" oldvers))
2975 (and newvers (concat "-r" newvers))
2976 diff-switches-list))))))
2978 (defun vc-backend-merge-news (file)
2979 ;; Merge in any new changes made to FILE.
2980 (message "Merging changes into %s..." file)
2981 (prog1
2982 (vc-backend-dispatch
2983 file
2984 (error "vc-backend-merge-news not meaningful for SCCS files") ;SCCS
2985 (error "vc-backend-merge-news not meaningful for RCS files") ;RCS
2986 (save-excursion ; CVS
2987 (vc-file-clear-masterprops file)
2988 (vc-file-setprop file 'vc-workfile-version nil)
2989 (vc-file-setprop file 'vc-locking-user nil)
2990 (vc-file-setprop file 'vc-checkout-time nil)
2991 (vc-do-command nil 0 "cvs" file 'WORKFILE "update")
2992 ;; Analyze the merge result reported by CVS, and set
2993 ;; file properties accordingly.
2994 (set-buffer (get-buffer "*vc*"))
2995 (goto-char (point-min))
2996 ;; get new workfile version
2997 (if (re-search-forward (concat "^Merging differences between "
2998 "[01234567890.]* and "
2999 "\\([01234567890.]*\\) into")
3000 nil t)
3001 (vc-file-setprop file 'vc-workfile-version (match-string 1)))
3002 ;; get file status
3003 (if (re-search-forward
3004 (concat "^\\(\\([CMUP]\\) \\)?"
3005 (regexp-quote (file-name-nondirectory file))
3006 "\\( already contains the differences between \\)?")
3007 nil t)
3008 (cond
3009 ;; Merge successful, we are in sync with repository now
3010 ((or (string= (match-string 2) "U")
3011 (string= (match-string 2) "P")
3012 ;; Special case: file contents in sync with
3013 ;; repository anyhow:
3014 (match-string 3))
3015 (vc-file-setprop file 'vc-locking-user 'none)
3016 (vc-file-setprop file 'vc-checkout-time
3017 (nth 5 (file-attributes file)))
3018 0) ;; indicate success to the caller
3019 ;; Merge successful, but our own changes are still in the file
3020 ((string= (match-string 2) "M")
3021 (vc-file-setprop file 'vc-locking-user (vc-file-owner file))
3022 (vc-file-setprop file 'vc-checkout-time 0)
3023 0) ;; indicate success to the caller
3024 ;; Conflicts detected!
3025 ((string= (match-string 2) "C")
3026 (vc-file-setprop file 'vc-locking-user (vc-file-owner file))
3027 (vc-file-setprop file 'vc-checkout-time 0)
3028 1) ;; signal the error to the caller
3030 (pop-to-buffer "*vc*")
3031 (error "Couldn't analyze cvs update result"))))
3032 (message "Merging changes into %s...done" file)))
3034 (defun vc-backend-merge (file first-version &optional second-version)
3035 ;; Merge the changes between FIRST-VERSION and SECOND-VERSION into
3036 ;; the current working copy of FILE. It is assumed that FILE is
3037 ;; locked and writable (vc-merge ensures this).
3038 (vc-backend-dispatch file
3039 ;; SCCS
3040 (error "Sorry, merging is not implemented for SCCS")
3041 ;; RCS
3042 (vc-do-command nil 1 "rcsmerge" file 'MASTER
3043 "-kk" ;; ignore keyword conflicts
3044 (concat "-r" first-version)
3045 (if second-version (concat "-r" second-version)))
3046 ;; CVS
3047 (progn
3048 (vc-do-command nil 0 "cvs" file 'WORKFILE
3049 "update" "-kk"
3050 (concat "-j" first-version)
3051 (concat "-j" second-version))
3052 (save-excursion
3053 (set-buffer (get-buffer "*vc*"))
3054 (goto-char (point-min))
3055 (if (re-search-forward "conflicts during merge" nil t)
3056 1 ;; signal error
3057 0 ;; signal success
3058 )))))
3060 (defun vc-check-headers ()
3061 "Check if the current file has any headers in it."
3062 (interactive)
3063 (save-excursion
3064 (goto-char (point-min))
3065 (vc-backend-dispatch buffer-file-name
3066 (re-search-forward "%[MIRLBSDHTEGUYFPQCZWA]%" nil t) ;; SCCS
3067 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t) ;; RCS
3068 'RCS ;; CVS works like RCS in this regard.
3072 ;; Back-end-dependent stuff ends here.
3074 ;; Set up key bindings for use while editing log messages
3076 (defun vc-log-mode (&optional file)
3077 "Minor mode for driving version-control tools.
3078 These bindings are added to the global keymap when you enter this mode:
3079 \\[vc-next-action] perform next logical version-control operation on current file
3080 \\[vc-register] register current file
3081 \\[vc-toggle-read-only] like next-action, but won't register files
3082 \\[vc-insert-headers] insert version-control headers in current file
3083 \\[vc-print-log] display change history of current file
3084 \\[vc-revert-buffer] revert buffer to latest version
3085 \\[vc-cancel-version] undo latest checkin
3086 \\[vc-diff] show diffs between file versions
3087 \\[vc-version-other-window] visit old version in another window
3088 \\[vc-directory] show all files locked by any user in or below .
3089 \\[vc-annotate] colorful display of the cvs annotate command
3090 \\[vc-update-change-log] add change log entry from recent checkins
3092 While you are entering a change log message for a version, the following
3093 additional bindings will be in effect.
3095 \\[vc-finish-logentry] proceed with check in, ending log message entry
3097 Whenever you do a checkin, your log comment is added to a ring of
3098 saved comments. These can be recalled as follows:
3100 \\[vc-next-comment] replace region with next message in comment ring
3101 \\[vc-previous-comment] replace region with previous message in comment ring
3102 \\[vc-comment-search-reverse] search backward for regexp in the comment ring
3103 \\[vc-comment-search-forward] search backward for regexp in the comment ring
3105 Entry to the change-log submode calls the value of text-mode-hook, then
3106 the value of vc-log-mode-hook.
3108 Global user options:
3109 vc-initial-comment If non-nil, require user to enter a change
3110 comment upon first checkin of the file.
3112 vc-keep-workfiles Non-nil value prevents workfiles from being
3113 deleted when changes are checked in
3115 vc-suppress-confirm Suppresses some confirmation prompts,
3116 notably for reversions.
3118 vc-header-alist Which keywords to insert when adding headers
3119 with \\[vc-insert-headers]. Defaults to
3120 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under
3121 RCS and CVS.
3123 vc-static-header-alist By default, version headers inserted in C files
3124 get stuffed in a static string area so that
3125 ident(RCS/CVS) or what(SCCS) can see them in
3126 the compiled object code. You can override
3127 this by setting this variable to nil, or change
3128 the header template by changing it.
3130 vc-command-messages if non-nil, display run messages from the
3131 actual version-control utilities (this is
3132 intended primarily for people hacking vc
3133 itself).
3135 (interactive)
3136 (set-syntax-table text-mode-syntax-table)
3137 (use-local-map vc-log-entry-mode)
3138 (setq local-abbrev-table text-mode-abbrev-table)
3139 (setq major-mode 'vc-log-mode)
3140 (setq mode-name "VC-Log")
3141 (make-local-variable 'vc-log-file)
3142 (setq vc-log-file file)
3143 (make-local-variable 'vc-log-version)
3144 (make-local-variable 'vc-comment-ring-index)
3145 (set-buffer-modified-p nil)
3146 (setq buffer-file-name nil)
3147 (run-hooks 'text-mode-hook 'vc-log-mode-hook)
3150 ;; Initialization code, to be done just once at load-time
3151 (if vc-log-entry-mode
3153 (setq vc-log-entry-mode (make-sparse-keymap))
3154 (define-key vc-log-entry-mode "\M-n" 'vc-next-comment)
3155 (define-key vc-log-entry-mode "\M-p" 'vc-previous-comment)
3156 (define-key vc-log-entry-mode "\M-r" 'vc-comment-search-reverse)
3157 (define-key vc-log-entry-mode "\M-s" 'vc-comment-search-forward)
3158 (define-key vc-log-entry-mode "\C-c\C-c" 'vc-finish-logentry)
3161 ;;; These things should probably be generally available
3163 (defun vc-file-tree-walk (dirname func &rest args)
3164 "Walk recursively through DIRNAME.
3165 Invoke FUNC f ARGS on each non-directory file f underneath it."
3166 (vc-file-tree-walk-internal (expand-file-name dirname) func args)
3167 (message "Traversing directory %s...done" dirname))
3169 (defun vc-file-tree-walk-internal (file func args)
3170 (if (not (file-directory-p file))
3171 (apply func file args)
3172 (message "Traversing directory %s..." (abbreviate-file-name file))
3173 (let ((dir (file-name-as-directory file)))
3174 (mapcar
3175 (function
3176 (lambda (f) (or
3177 (string-equal f ".")
3178 (string-equal f "..")
3179 (member f vc-directory-exclusion-list)
3180 (let ((dirf (concat dir f)))
3182 (file-symlink-p dirf) ;; Avoid possible loops
3183 (vc-file-tree-walk-internal dirf func args))))))
3184 (directory-files dir)))))
3186 (provide 'vc)
3188 ;;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE
3190 ;;; These may be useful to anyone who has to debug or extend the package.
3191 ;;; (Note that this information corresponds to versions 5.x. Some of it
3192 ;;; might have been invalidated by the additions to support branching
3193 ;;; and RCS keyword lookup. AS, 1995/03/24)
3194 ;;;
3195 ;;; A fundamental problem in VC is that there are time windows between
3196 ;;; vc-next-action's computations of the file's version-control state and
3197 ;;; the actions that change it. This is a window open to lossage in a
3198 ;;; multi-user environment; someone else could nip in and change the state
3199 ;;; of the master during it.
3200 ;;;
3201 ;;; The performance problem is that rlog/prs calls are very expensive; we want
3202 ;;; to avoid them as much as possible.
3203 ;;;
3204 ;;; ANALYSIS:
3205 ;;;
3206 ;;; The performance problem, it turns out, simplifies in practice to the
3207 ;;; problem of making vc-locking-user fast. The two other functions that call
3208 ;;; prs/rlog will not be so commonly used that the slowdown is a problem; one
3209 ;;; makes snapshots, the other deletes the calling user's last change in the
3210 ;;; master.
3211 ;;;
3212 ;;; The race condition implies that we have to either (a) lock the master
3213 ;;; during the entire execution of vc-next-action, or (b) detect and
3214 ;;; recover from errors resulting from dispatch on an out-of-date state.
3215 ;;;
3216 ;;; Alternative (a) appears to be infeasible. The problem is that we can't
3217 ;;; guarantee that the lock will ever be removed. Suppose a user starts a
3218 ;;; checkin, the change message buffer pops up, and the user, having wandered
3219 ;;; off to do something else, simply forgets about it?
3220 ;;;
3221 ;;; Alternative (b), on the other hand, works well with a cheap way to speed up
3222 ;;; vc-locking-user. Usually, if a file is registered, we can read its locked/
3223 ;;; unlocked state and its current owner from its permissions.
3224 ;;;
3225 ;;; This shortcut will fail if someone has manually changed the workfile's
3226 ;;; permissions; also if developers are munging the workfile in several
3227 ;;; directories, with symlinks to a master (in this latter case, the
3228 ;;; permissions shortcut will fail to detect a lock asserted from another
3229 ;;; directory).
3230 ;;;
3231 ;;; Note that these cases correspond exactly to the errors which could happen
3232 ;;; because of a competing checkin/checkout race in between two instances of
3233 ;;; vc-next-action.
3234 ;;;
3235 ;;; For VC's purposes, a workfile/master pair may have the following states:
3236 ;;;
3237 ;;; A. Unregistered. There is a workfile, there is no master.
3238 ;;;
3239 ;;; B. Registered and not locked by anyone.
3240 ;;;
3241 ;;; C. Locked by calling user and unchanged.
3242 ;;;
3243 ;;; D. Locked by the calling user and changed.
3244 ;;;
3245 ;;; E. Locked by someone other than the calling user.
3246 ;;;
3247 ;;; This makes for 25 states and 20 error conditions. Here's the matrix:
3248 ;;;
3249 ;;; VC's idea of state
3250 ;;; |
3251 ;;; V Actual state RCS action SCCS action Effect
3252 ;;; A B C D E
3253 ;;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin
3254 ;;; B 5 . 6 7 8 co -l get -e checkout
3255 ;;; C 9 10 . 11 12 co -u unget; get revert
3256 ;;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin
3257 ;;; E 17 18 19 20 . rcs -u -M -l unget -n ; get -g steal lock
3258 ;;;
3259 ;;; All commands take the master file name as a last argument (not shown).
3260 ;;;
3261 ;;; In the discussion below, a "self-race" is a pathological situation in
3262 ;;; which VC operations are being attempted simultaneously by two or more
3263 ;;; Emacsen running under the same username.
3264 ;;;
3265 ;;; The vc-next-action code has the following windows:
3266 ;;;
3267 ;;; Window P:
3268 ;;; Between the check for existence of a master file and the call to
3269 ;;; admin/checkin in vc-buffer-admin (apparent state A). This window may
3270 ;;; never close if the initial-comment feature is on.
3271 ;;;
3272 ;;; Window Q:
3273 ;;; Between the call to vc-workfile-unchanged-p in and the immediately
3274 ;;; following revert (apparent state C).
3275 ;;;
3276 ;;; Window R:
3277 ;;; Between the call to vc-workfile-unchanged-p in and the following
3278 ;;; checkin (apparent state D). This window may never close.
3279 ;;;
3280 ;;; Window S:
3281 ;;; Between the unlock and the immediately following checkout during a
3282 ;;; revert operation (apparent state C). Included in window Q.
3283 ;;;
3284 ;;; Window T:
3285 ;;; Between vc-locking-user and the following checkout (apparent state B).
3286 ;;;
3287 ;;; Window U:
3288 ;;; Between vc-locking-user and the following revert (apparent state C).
3289 ;;; Includes windows Q and S.
3290 ;;;
3291 ;;; Window V:
3292 ;;; Between vc-locking-user and the following checkin (apparent state
3293 ;;; D). This window may never be closed if the user fails to complete the
3294 ;;; checkin message. Includes window R.
3295 ;;;
3296 ;;; Window W:
3297 ;;; Between vc-locking-user and the following steal-lock (apparent
3298 ;;; state E). This window may never close if the user fails to complete
3299 ;;; the steal-lock message. Includes window X.
3300 ;;;
3301 ;;; Window X:
3302 ;;; Between the unlock and the immediately following re-lock during a
3303 ;;; steal-lock operation (apparent state E). This window may never cloce
3304 ;;; if the user fails to complete the steal-lock message.
3305 ;;;
3306 ;;; Errors:
3307 ;;;
3308 ;;; Apparent state A ---
3310 ;;; 1. File looked unregistered but is actually registered and not locked.
3311 ;;;
3312 ;;; Potential cause: someone else's admin during window P, with
3313 ;;; caller's admin happening before their checkout.
3314 ;;;
3315 ;;; RCS: Prior to version 5.6.4, ci fails with message
3316 ;;; "no lock set by <user>". From 5.6.4 onwards, VC uses the new
3317 ;;; ci -i option and the message is "<file>,v: already exists".
3318 ;;; SCCS: admin will fail with error (ad19).
3319 ;;;
3320 ;;; We can let these errors be passed up to the user.
3321 ;;;
3322 ;;; 2. File looked unregistered but is actually locked by caller, unchanged.
3323 ;;;
3324 ;;; Potential cause: self-race during window P.
3325 ;;;
3326 ;;; RCS: Prior to version 5.6.4, reverts the file to the last saved
3327 ;;; version and unlocks it. From 5.6.4 onwards, VC uses the new
3328 ;;; ci -i option, failing with message "<file>,v: already exists".
3329 ;;; SCCS: will fail with error (ad19).
3330 ;;;
3331 ;;; Either of these consequences is acceptable.
3332 ;;;
3333 ;;; 3. File looked unregistered but is actually locked by caller, changed.
3334 ;;;
3335 ;;; Potential cause: self-race during window P.
3336 ;;;
3337 ;;; RCS: Prior to version 5.6.4, VC registers the caller's workfile as
3338 ;;; a delta with a null change comment (the -t- switch will be
3339 ;;; ignored). From 5.6.4 onwards, VC uses the new ci -i option,
3340 ;;; failing with message "<file>,v: already exists".
3341 ;;; SCCS: will fail with error (ad19).
3342 ;;;
3343 ;;; 4. File looked unregistered but is locked by someone else.
3344 ;;;
3345 ;;; Potential cause: someone else's admin during window P, with
3346 ;;; caller's admin happening *after* their checkout.
3347 ;;;
3348 ;;; RCS: Prior to version 5.6.4, ci fails with a
3349 ;;; "no lock set by <user>" message. From 5.6.4 onwards,
3350 ;;; VC uses the new ci -i option, failing with message
3351 ;;; "<file>,v: already exists".
3352 ;;; SCCS: will fail with error (ad19).
3353 ;;;
3354 ;;; We can let these errors be passed up to the user.
3355 ;;;
3356 ;;; Apparent state B ---
3358 ;;; 5. File looked registered and not locked, but is actually unregistered.
3359 ;;;
3360 ;;; Potential cause: master file got nuked during window P.
3361 ;;;
3362 ;;; RCS: will fail with "RCS/<file>: No such file or directory"
3363 ;;; SCCS: will fail with error ut4.
3364 ;;;
3365 ;;; We can let these errors be passed up to the user.
3366 ;;;
3367 ;;; 6. File looked registered and not locked, but is actually locked by the
3368 ;;; calling user and unchanged.
3369 ;;;
3370 ;;; Potential cause: self-race during window T.
3371 ;;;
3372 ;;; RCS: in the same directory as the previous workfile, co -l will fail
3373 ;;; with "co error: writable foo exists; checkout aborted". In any other
3374 ;;; directory, checkout will succeed.
3375 ;;; SCCS: will fail with ge17.
3376 ;;;
3377 ;;; Either of these consequences is acceptable.
3378 ;;;
3379 ;;; 7. File looked registered and not locked, but is actually locked by the
3380 ;;; calling user and changed.
3381 ;;;
3382 ;;; As case 6.
3383 ;;;
3384 ;;; 8. File looked registered and not locked, but is actually locked by another
3385 ;;; user.
3386 ;;;
3387 ;;; Potential cause: someone else checks it out during window T.
3388 ;;;
3389 ;;; RCS: co error: revision 1.3 already locked by <user>
3390 ;;; SCCS: fails with ge4 (in directory) or ut7 (outside it).
3391 ;;;
3392 ;;; We can let these errors be passed up to the user.
3393 ;;;
3394 ;;; Apparent state C ---
3396 ;;; 9. File looks locked by calling user and unchanged, but is unregistered.
3397 ;;;
3398 ;;; As case 5.
3399 ;;;
3400 ;;; 10. File looks locked by calling user and unchanged, but is actually not
3401 ;;; locked.
3402 ;;;
3403 ;;; Potential cause: a self-race in window U, or by the revert's
3404 ;;; landing during window X of some other user's steal-lock or window S
3405 ;;; of another user's revert.
3406 ;;;
3407 ;;; RCS: succeeds, refreshing the file from the identical version in
3408 ;;; the master.
3409 ;;; SCCS: fails with error ut4 (p file nonexistent).
3411 ;;; Either of these consequences is acceptable.
3412 ;;;
3413 ;;; 11. File is locked by calling user. It looks unchanged, but is actually
3414 ;;; changed.
3415 ;;;
3416 ;;; Potential cause: the file would have to be touched by a self-race
3417 ;;; during window Q.
3418 ;;;
3419 ;;; The revert will succeed, removing whatever changes came with
3420 ;;; the touch. It is theoretically possible that work could be lost.
3421 ;;;
3422 ;;; 12. File looks like it's locked by the calling user and unchanged, but
3423 ;;; it's actually locked by someone else.
3424 ;;;
3425 ;;; Potential cause: a steal-lock in window V.
3426 ;;;
3427 ;;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u
3428 ;;; SCCS: fails with error un2
3429 ;;;
3430 ;;; We can pass these errors up to the user.
3431 ;;;
3432 ;;; Apparent state D ---
3434 ;;; 13. File looks like it's locked by the calling user and changed, but it's
3435 ;;; actually unregistered.
3436 ;;;
3437 ;;; Potential cause: master file got nuked during window P.
3438 ;;;
3439 ;;; RCS: Prior to version 5.6.4, checks in the user's version as an
3440 ;;; initial delta. From 5.6.4 onwards, VC uses the new ci -j
3441 ;;; option, failing with message "no such file or directory".
3442 ;;; SCCS: will fail with error ut4.
3444 ;;; This case is kind of nasty. Under RCS prior to version 5.6.4,
3445 ;;; VC may fail to detect the loss of previous version information.
3446 ;;;
3447 ;;; 14. File looks like it's locked by the calling user and changed, but it's
3448 ;;; actually unlocked.
3449 ;;;
3450 ;;; Potential cause: self-race in window V, or the checkin happening
3451 ;;; during the window X of someone else's steal-lock or window S of
3452 ;;; someone else's revert.
3453 ;;;
3454 ;;; RCS: ci will fail with "no lock set by <user>".
3455 ;;; SCCS: delta will fail with error ut4.
3456 ;;;
3457 ;;; 15. File looks like it's locked by the calling user and changed, but it's
3458 ;;; actually locked by the calling user and unchanged.
3459 ;;;
3460 ;;; Potential cause: another self-race --- a whole checkin/checkout
3461 ;;; sequence by the calling user would have to land in window R.
3462 ;;;
3463 ;;; SCCS: checks in a redundant delta and leaves the file unlocked as usual.
3464 ;;; RCS: reverts to the file state as of the second user's checkin, leaving
3465 ;;; the file unlocked.
3467 ;;; It is theoretically possible that work could be lost under RCS.
3468 ;;;
3469 ;;; 16. File looks like it's locked by the calling user and changed, but it's
3470 ;;; actually locked by a different user.
3471 ;;;
3472 ;;; RCS: ci error: no lock set by <user>
3473 ;;; SCCS: unget will fail with error un2
3474 ;;;
3475 ;;; We can pass these errors up to the user.
3476 ;;;
3477 ;;; Apparent state E ---
3479 ;;; 17. File looks like it's locked by some other user, but it's actually
3480 ;;; unregistered.
3481 ;;;
3482 ;;; As case 13.
3483 ;;;
3484 ;;; 18. File looks like it's locked by some other user, but it's actually
3485 ;;; unlocked.
3486 ;;;
3487 ;;; Potential cause: someone released a lock during window W.
3488 ;;;
3489 ;;; RCS: The calling user will get the lock on the file.
3490 ;;; SCCS: unget -n will fail with cm4.
3491 ;;;
3492 ;;; Either of these consequences will be OK.
3493 ;;;
3494 ;;; 19. File looks like it's locked by some other user, but it's actually
3495 ;;; locked by the calling user and unchanged.
3496 ;;;
3497 ;;; Potential cause: the other user relinquishing a lock followed by
3498 ;;; a self-race, both in window W.
3499 ;;;
3500 ;;; Under both RCS and SCCS, both unlock and lock will succeed, making
3501 ;;; the sequence a no-op.
3502 ;;;
3503 ;;; 20. File looks like it's locked by some other user, but it's actually
3504 ;;; locked by the calling user and changed.
3505 ;;;
3506 ;;; As case 19.
3507 ;;;
3508 ;;; PROBLEM CASES:
3509 ;;;
3510 ;;; In order of decreasing severity:
3511 ;;;
3512 ;;; Cases 11 and 15 are the only ones that potentially lose work.
3513 ;;; They would require a self-race for this to happen.
3514 ;;;
3515 ;;; Case 13 in RCS loses information about previous deltas, retaining
3516 ;;; only the information in the current workfile. This can only happen
3517 ;;; if the master file gets nuked in window P.
3518 ;;;
3519 ;;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with
3520 ;;; no change comment in the master. This would require a self-race in
3521 ;;; window P or R respectively.
3522 ;;;
3523 ;;; Cases 2, 10, 19 and 20 do extra work, but make no changes.
3524 ;;;
3525 ;;; Unfortunately, it appears to me that no recovery is possible in these
3526 ;;; cases. They don't yield error messages, so there's no way to tell that
3527 ;;; a race condition has occurred.
3528 ;;;
3529 ;;; All other cases don't change either the workfile or the master, and
3530 ;;; trigger command errors which the user will see.
3531 ;;;
3532 ;;; Thus, there is no explicit recovery code.
3534 ;;; vc.el ends here