Mercurial > emacs
annotate lisp/vc.el @ 2229:bd3c525fa6fc
Added standard library headers.
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Wed, 17 Mar 1993 15:20:58 +0000 |
parents | b2216b3b8f57 |
children | 61e1f8813d03 |
rev | line source |
---|---|
904 | 1 ;;; vc.el --- drive a version-control system from within Emacs |
2 | |
3 ;; Copyright (C) 1992 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> | |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
6 ;; Version: 5.2 |
904 | 7 |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
8 ;; $Id: vc.el,v 1.27 1993/03/16 21:09:56 eggert Exp eric $ |
904 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; This was designed and implemented by Eric Raymond <esr@snark.thyrsus.com>. | |
29 ;; Paul Eggert <eggert@twinsun.com>, Sebastian Kremer <sk@thp.uni-koeln.de>, | |
30 ;; and Richard Stallman contributed valuable criticism, support, and testing. | |
31 ;; | |
32 ;; Supported version-control systems presently include SCCS and RCS; | |
33 ;; your RCS version should be 5.6.2 or later for proper operation of | |
34 ;; the lock-breaking code. | |
35 ;; | |
36 ;; The RCS code assumes strict locking. You can support the RCS -x option | |
37 ;; by adding pairs to the vc-master-templates list. | |
38 ;; | |
39 ;; Proper function of the SCCS diff commands requires the shellscript vcdiff | |
40 ;; to be installed somewhere on Emacs's path for executables. | |
41 ;; | |
42 ;; This code depends on call-process passing back the subprocess exit | |
43 ;; status. Thus, you need Emacs 18.58 or later to run it. | |
44 ;; | |
45 ;; The vc code maintains some internal state in order to reduce expensive | |
46 ;; version-control operations to a minimum. Some names are only computed | |
47 ;; once. If you perform version control operations with RCS/SCCS/CVS while | |
48 ;; vc's back is turned, or move/rename master files while vc is running, | |
49 ;; vc may get seriously confused. Don't do these things! | |
50 ;; | |
51 ;; Developer's notes on some concurrency issues are included at the end of | |
52 ;; the file. | |
53 | |
54 ;;; Code: | |
55 | |
56 (require 'vc-hooks) | |
57 | |
58 ;; General customization | |
59 | |
60 (defvar vc-default-back-end nil | |
61 "*Back-end actually used by this interface; may be SCCS or RCS. | |
62 The value is only computed when needed to avoid an expensive search.") | |
63 (defvar vc-diff-options '("-a" "-c1") | |
64 "*The command/flags list to be used in constructing diff commands.") | |
65 (defvar vc-suppress-confirm nil | |
66 "*If non-nil, reat user as expert; suppress yes-no prompts on some things.") | |
67 (defvar vc-keep-workfiles t | |
68 "*If non-nil, don't delete working files after registering changes.") | |
69 (defvar vc-initial-comment nil | |
70 "*Prompt for initial comment when a file is registered.") | |
71 (defvar vc-command-messages nil | |
72 "*Display run messages from back-end commands.") | |
73 (defvar vc-mistrust-permissions 'file-symlink-p | |
74 "*Don't assume that permissions and ownership track version-control status.") | |
75 | |
1335
d649d430148d
(vc-checkin-switches): New defvar.
Roland McGrath <roland@gnu.org>
parents:
1243
diff
changeset
|
76 (defvar vc-checkin-switches nil |
d649d430148d
(vc-checkin-switches): New defvar.
Roland McGrath <roland@gnu.org>
parents:
1243
diff
changeset
|
77 "*Extra switches passed to the checkin program by \\[vc-checkin].") |
d649d430148d
(vc-checkin-switches): New defvar.
Roland McGrath <roland@gnu.org>
parents:
1243
diff
changeset
|
78 |
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
79 ;;;###autoload |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
80 (defvar vc-checkin-hook nil |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
81 "*List of functions called after a vc-checkin is done. See `run-hooks'.") |
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
82 |
904 | 83 ;; Header-insertion hair |
84 | |
85 (defvar vc-header-alist | |
86 '((SCCS "\%W\%") (RCS "\$Id\$")) | |
87 "*Header keywords to be inserted when vc-insert-header is executed.") | |
88 (defconst vc-static-header-alist | |
89 '(("\\.c$" . | |
90 "\n#ifndef lint\nstatic char vcid[] = \"\%s\";\n#endif /* lint */\n")) | |
91 "*Associate static header string templates with file types. A \%s in the | |
92 template is replaced with the first string associated with the file's | |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
93 verson-control type in vc-header-alist.") |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
94 |
904 | 95 (defvar vc-comment-alist |
96 '((nroff-mode ".\\\"" "")) | |
97 "*Special comment delimiters to be used in generating vc headers only. | |
98 Add an entry in this list if you need to override the normal comment-start | |
99 and comment-end variables. This will only be necessary if the mode language | |
100 is sensitive to blank lines.") | |
101 | |
102 ;; Variables the user doesn't need to know about. | |
103 (defvar vc-log-entry-mode nil) | |
104 (defvar vc-log-operation nil) | |
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
105 (defvar vc-log-after-operation-hook nil) |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
106 (defvar vc-checkout-writeable-buffer-hook 'vc-checkout-writeable-buffer) |
904 | 107 |
1494
64f5e84c822b
(vc-admin): Pass t as noquery arg to vc-resynch-window.
Richard M. Stallman <rms@gnu.org>
parents:
1478
diff
changeset
|
108 (defvar vc-log-file) |
64f5e84c822b
(vc-admin): Pass t as noquery arg to vc-resynch-window.
Richard M. Stallman <rms@gnu.org>
parents:
1478
diff
changeset
|
109 (defvar vc-log-version) |
64f5e84c822b
(vc-admin): Pass t as noquery arg to vc-resynch-window.
Richard M. Stallman <rms@gnu.org>
parents:
1478
diff
changeset
|
110 |
904 | 111 (defconst vc-name-assoc-file "VC-names") |
112 | |
113 ;; File property caching | |
114 | |
115 (defun vc-file-clearprops (file) | |
116 ;; clear all properties of a given file | |
117 (setplist (intern file vc-file-prop-obarray) nil)) | |
118 | |
119 ;; Random helper functions | |
120 | |
121 (defun vc-name (file) | |
122 "Return the master name of a file, nil if it is not registered" | |
123 (or (vc-file-getprop file 'vc-name) | |
124 (vc-file-setprop file 'vc-name | |
125 (let ((name-and-type (vc-registered file))) | |
126 (and name-and-type (car name-and-type)))))) | |
127 | |
128 (defvar vc-binary-assoc nil) | |
129 | |
130 (defun vc-find-binary (name) | |
131 "Look for a command anywhere on the subprocess-command search path." | |
132 (or (cdr (assoc name vc-binary-assoc)) | |
133 (let ((full nil)) | |
134 (catch 'found | |
135 (mapcar | |
136 (function (lambda (s) | |
137 (if (and s (file-exists-p (setq full (concat s "/" name)))) | |
138 (throw 'found nil)))) | |
139 exec-path)) | |
140 (if full | |
141 (setq vc-binary-assoc (cons (cons name full) vc-binary-assoc))) | |
142 full))) | |
143 | |
144 (defun vc-do-command (okstatus command file &rest flags) | |
145 "Execute a version-control command, notifying user and checking for errors. | |
146 The command is successful if its exit status does not exceed OKSTATUS. | |
147 Output from COMMAND goes to buffer *vc*. The last argument of the command is | |
148 the master name of FILE; this is appended to an optional list of FLAGS." | |
149 (setq file (expand-file-name file)) | |
150 (if vc-command-messages | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
151 (message "Running %s on %s..." command file)) |
904 | 152 (let ((obuf (current-buffer)) |
153 (squeezed nil) | |
154 (vc-file (and file (vc-name file))) | |
155 status) | |
156 (set-buffer (get-buffer-create "*vc*")) | |
157 (erase-buffer) | |
1674
75e8a7f920c7
* vc.el (vc-do-command): Set the default directory of the *vc*
Jim Blandy <jimb@redhat.com>
parents:
1636
diff
changeset
|
158 |
75e8a7f920c7
* vc.el (vc-do-command): Set the default directory of the *vc*
Jim Blandy <jimb@redhat.com>
parents:
1636
diff
changeset
|
159 ;; This is so that command arguments typed in the *vc* buffer will |
75e8a7f920c7
* vc.el (vc-do-command): Set the default directory of the *vc*
Jim Blandy <jimb@redhat.com>
parents:
1636
diff
changeset
|
160 ;; have reasonable defaults. |
75e8a7f920c7
* vc.el (vc-do-command): Set the default directory of the *vc*
Jim Blandy <jimb@redhat.com>
parents:
1636
diff
changeset
|
161 (setq default-directory (file-name-directory file)) |
75e8a7f920c7
* vc.el (vc-do-command): Set the default directory of the *vc*
Jim Blandy <jimb@redhat.com>
parents:
1636
diff
changeset
|
162 |
904 | 163 (mapcar |
164 (function (lambda (s) (and s (setq squeezed (append squeezed (list s)))))) | |
165 flags) | |
166 (if vc-file | |
167 (setq squeezed (append squeezed (list vc-file)))) | |
168 (let | |
169 ((default-directory (file-name-directory (or file "./")))) | |
170 (setq status (apply 'call-process command nil t nil squeezed)) | |
171 ) | |
172 (goto-char (point-max)) | |
173 (previous-line 1) | |
174 (if (or (not (integerp status)) (< okstatus status)) | |
175 (progn | |
176 (previous-line 1) | |
177 (print (cons command squeezed)) | |
178 (next-line 1) | |
179 (pop-to-buffer "*vc*") | |
180 (vc-shrink-to-fit) | |
181 (goto-char (point-min)) | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
182 (error "Running %s...FAILED (%s)" command |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
183 (if (integerp status) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
184 (format "status %d" status) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
185 status)) |
904 | 186 ) |
187 (if vc-command-messages | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
188 (message "Running %s...OK" command)) |
904 | 189 ) |
190 (set-buffer obuf) | |
191 status) | |
192 ) | |
193 | |
1635
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
194 ;;; Save a bit of the text around POSN in the current buffer, to help |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
195 ;;; us find the corresponding position again later. This works even |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
196 ;;; if all markers are destroyed or corrupted. |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
197 (defun vc-position-context (posn) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
198 (list posn |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
199 (buffer-size) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
200 (buffer-substring posn |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
201 (min (point-max) (+ posn 100))))) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
202 |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
203 ;;; Return the position of CONTEXT in the current buffer, or nil if we |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
204 ;;; couldn't find it. |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
205 (defun vc-find-position-by-context (context) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
206 (let ((context-string (nth 2 context))) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
207 (if (equal "" context-string) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
208 (point-max) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
209 (save-excursion |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
210 (let ((diff (- (nth 1 context) (buffer-size)))) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
211 (if (< diff 0) (setq diff (- diff))) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
212 (goto-char (nth 0 context)) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
213 (if (or (search-forward context-string nil t) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
214 ;; Can't use search-backward since the match may continue |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
215 ;; after point. |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
216 (progn (goto-char (- (point) diff (length context-string))) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
217 ;; goto-char doesn't signal an error at |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
218 ;; beginning of buffer like backward-char would |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
219 (search-forward context-string nil t))) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
220 ;; to beginning of OSTRING |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
221 (- (point) (length context-string)))))))) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
222 |
904 | 223 (defun vc-revert-buffer1 (&optional arg no-confirm) |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
224 ;; Most of this was shamelessly lifted from Sebastian Kremer's rcs.el mode. |
1635
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
225 ;; Revert buffer, try to keep point and mark where user expects them in spite |
904 | 226 ;; of changes because of expanded version-control key words. |
227 ;; This is quite important since otherwise typeahead won't work as expected. | |
228 (interactive "P") | |
229 (widen) | |
1635
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
230 (let ((point-context (vc-position-context (point))) |
2041
ccb75415543a
(vc-revert-buffer1): Use mark-marker; don't alter mark-active.
Richard M. Stallman <rms@gnu.org>
parents:
1905
diff
changeset
|
231 ;; Use mark-marker to avoid confusion in transient-mark-mode. |
ccb75415543a
(vc-revert-buffer1): Use mark-marker; don't alter mark-active.
Richard M. Stallman <rms@gnu.org>
parents:
1905
diff
changeset
|
232 (mark-context (if (eq (marker-buffer (mark-marker)) (current-buffer)) |
ccb75415543a
(vc-revert-buffer1): Use mark-marker; don't alter mark-active.
Richard M. Stallman <rms@gnu.org>
parents:
1905
diff
changeset
|
233 (vc-position-context (mark-marker)))) |
ccb75415543a
(vc-revert-buffer1): Use mark-marker; don't alter mark-active.
Richard M. Stallman <rms@gnu.org>
parents:
1905
diff
changeset
|
234 ;; Make the right thing happen in transient-mark-mode. |
ccb75415543a
(vc-revert-buffer1): Use mark-marker; don't alter mark-active.
Richard M. Stallman <rms@gnu.org>
parents:
1905
diff
changeset
|
235 (mark-active nil)) |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
236 |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
237 ;; the actual revisit |
904 | 238 (revert-buffer arg no-confirm) |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
239 |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
240 ;; Restore point and mark |
1635
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
241 (let ((new-point (vc-find-position-by-context point-context))) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
242 (if new-point (goto-char new-point))) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
243 (if mark-context |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
244 (let ((new-mark (vc-find-position-by-context mark-context))) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
245 (if new-mark (set-mark new-mark)))))) |
e3c02a517030
Thu Nov 19 16:44:24 1992 Jim Blandy (jimb@totoro.cs.oberlin.edu)
Jim Blandy <jimb@redhat.com>
parents:
1575
diff
changeset
|
246 |
904 | 247 |
248 (defun vc-buffer-sync () | |
249 ;; Make sure the current buffer and its working file are in sync | |
250 (if (and (buffer-modified-p) | |
251 (or | |
252 vc-suppress-confirm | |
253 (y-or-n-p (format "%s has been modified. Write it out? " | |
254 (buffer-name))))) | |
255 (save-buffer))) | |
256 | |
257 (defun vc-workfile-unchanged-p (file) | |
258 ;; Has the given workfile changed since last checkout? | |
259 (let ((checkout-time (vc-file-getprop file 'vc-checkout-time)) | |
260 (lastmod (nth 5 (file-attributes file)))) | |
261 (if checkout-time | |
262 (equal lastmod checkout-time) | |
263 (if (zerop (vc-backend-diff file nil)) | |
264 (progn | |
265 (vc-file-setprop file 'vc-checkout-time lastmod) | |
266 t) | |
267 (progn | |
268 (vc-file-setprop file 'vc-checkout-time '(0 . 0)) | |
269 nil | |
270 )) | |
271 ))) | |
272 | |
927 | 273 ;; Here's the major entry point. |
904 | 274 |
927 | 275 ;;;###autoload |
904 | 276 (defun vc-next-action (verbose) |
277 "Do the next logical checkin or checkout operation on the current file. | |
278 If the file is not already registered, this registers it for version | |
279 control and then retrieves a writeable, locked copy for editing. | |
280 If the file is registered and not locked by anyone, this checks out | |
281 a writeable and locked file ready for editing. | |
282 If the file is checked out and locked by the calling user, this | |
283 first checks to see if the file has changed since checkout. If not, | |
284 it performs a revert. | |
285 If the file has been changed, this pops up a buffer for creation of | |
286 a log message; when the message has been entered, it checks in the | |
287 resulting changes along with the log message as change commentary. If | |
288 the variable vc-keep-workfiles is non-nil (which is its default), a | |
289 read-only copy of the changed file is left in place afterwards. | |
290 If the file is registered and locked by someone else, you are given | |
291 the option to steal the lock." | |
292 (interactive "P") | |
293 (if buffer-file-name | |
294 (let | |
295 (do-update owner version | |
296 (file buffer-file-name) | |
297 (vc-file (vc-name buffer-file-name)) | |
298 (err-msg nil) | |
299 owner) | |
300 | |
301 (cond | |
302 | |
303 ;; if there is no master file corresponding, create one | |
304 ((not vc-file) | |
305 (vc-register verbose) | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
306 (if vc-initial-comment |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
307 (setq vc-log-after-operation-hook |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
308 'vc-checkout-writeable-buffer-hook) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
309 (vc-checkout-writeable-buffer))) |
904 | 310 |
311 ;; if there is no lock on the file, assert one and get it | |
312 ((not (setq owner (vc-locking-user file))) | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
313 (vc-checkout-writeable-buffer)) |
904 | 314 |
315 ;; a checked-out version exists, but the user may not own the lock | |
316 ((not (string-equal owner (user-login-name))) | |
317 (vc-steal-lock | |
318 file | |
319 (and verbose (read-string "Version to steal: ")) | |
320 owner)) | |
321 | |
322 ;; OK, user owns the lock on the file | |
323 (t (progn | |
324 | |
325 ;; give luser a chance to save before checking in. | |
326 (vc-buffer-sync) | |
327 | |
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
328 ;; Revert if file is unchanged and buffer is too. |
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
329 ;; If buffer is modified, that means the user just said no |
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
330 ;; to saving it; in that case, don't revert, |
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
331 ;; because the user might intend to save |
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
332 ;; after finishing the log entry. |
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
333 (if (and (vc-workfile-unchanged-p file) |
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
334 (not (buffer-modified-p))) |
904 | 335 (progn |
336 (vc-backend-revert file) | |
1636
c2bea3f2f8cb
(vc-next-action): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
1635
diff
changeset
|
337 ;; DO NOT revert the file without asking the user! |
c2bea3f2f8cb
(vc-next-action): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
1635
diff
changeset
|
338 (vc-resynch-window file t nil)) |
904 | 339 |
340 ;; user may want to set nonstandard parameters | |
341 (if verbose | |
342 (setq version (read-string "New version level: "))) | |
343 | |
344 ;; OK, let's do the checkin | |
345 (vc-checkin file version)))))) | |
346 (error "There is no file associated with buffer %s" (buffer-name)))) | |
347 | |
348 ;;; These functions help the vc-next-action entry point | |
349 | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
350 (defun vc-checkout-writeable-buffer () |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
351 "Retrieve a writeable copy of the latest version of the current buffer's file." |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
352 (vc-checkout (buffer-file-name) t) |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
353 ) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
354 |
927 | 355 ;;;###autoload |
904 | 356 (defun vc-register (&optional override) |
357 "Register the current file into your version-control system." | |
358 (interactive "P") | |
359 (if (vc-name buffer-file-name) | |
360 (error "This file is already registered.")) | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
361 ;; Watch out for new buffers of size 0: the corresponding file |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
362 ;; does not exist yet, even though buffer-modified-p is nil. |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
363 (if (and (not (buffer-modified-p)) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
364 (zerop (buffer-size)) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
365 (not (file-exists-p buffer-file-name))) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
366 (set-buffer-modified-p t)) |
904 | 367 (vc-buffer-sync) |
368 (vc-admin | |
369 buffer-file-name | |
370 (and override (read-string "Initial version level: "))) | |
371 ) | |
372 | |
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
373 (defun vc-resynch-window (file &optional keep noquery) |
904 | 374 ;; If the given file is in the current buffer, |
375 ;; either revert on it so we see expanded keyworks, | |
376 ;; or unvisit it (depending on vc-keep-workfiles) | |
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
377 ;; NOQUERY if non-nil inhibits confirmation for reverting. |
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
378 ;; NOQUERY should be t *only* if it is known the only difference |
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
379 ;; between the buffer and the file is due to RCS rather than user editing! |
904 | 380 (and (string= buffer-file-name file) |
381 (if keep | |
382 (progn | |
1905
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1674
diff
changeset
|
383 (vc-revert-buffer1 t noquery) |
904 | 384 (vc-mode-line buffer-file-name)) |
385 (progn | |
386 (delete-window) | |
387 (kill-buffer (current-buffer)))))) | |
388 | |
389 | |
390 (defun vc-admin (file rev) | |
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
391 "Check a file into your version-control system. |
904 | 392 FILE is the unmodified name of the file. REV should be the base version |
393 level to check it in under." | |
394 (if vc-initial-comment | |
395 (progn | |
396 (pop-to-buffer (get-buffer-create "*VC-log*")) | |
397 (vc-log-mode) | |
398 (narrow-to-region (point-max) (point-max)) | |
399 (vc-mode-line file (file-name-nondirectory file)) | |
400 (setq vc-log-operation 'vc-backend-admin) | |
401 (setq vc-log-file file) | |
402 (setq vc-log-version rev) | |
403 (message "Enter initial comment. Type C-c C-c when done.")) | |
404 (progn | |
405 (vc-backend-admin file rev) | |
1494
64f5e84c822b
(vc-admin): Pass t as noquery arg to vc-resynch-window.
Richard M. Stallman <rms@gnu.org>
parents:
1478
diff
changeset
|
406 ;; Inhibit query here, since otherwise we always get asked. |
64f5e84c822b
(vc-admin): Pass t as noquery arg to vc-resynch-window.
Richard M. Stallman <rms@gnu.org>
parents:
1478
diff
changeset
|
407 (vc-resynch-window file vc-keep-workfiles t)))) |
904 | 408 |
409 (defun vc-steal-lock (file rev &optional owner) | |
410 "Steal the lock on the current workfile." | |
411 (interactive) | |
412 (if (not owner) | |
413 (setq owner (vc-locking-user file))) | |
414 (if (not (y-or-n-p (format "Take the lock on %s:%s from %s?" file rev owner))) | |
415 (error "Steal cancelled.")) | |
1343
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
416 (require 'sendmail) |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
417 (pop-to-buffer (get-buffer-create "*VC-mail*")) |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
418 (setq default-directory (expand-file-name "~/")) |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
419 (auto-save-mode auto-save-default) |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
420 (mail-mode) |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
421 (erase-buffer) |
2087 | 422 (mail-setup owner (format "%s:%s" file rev) nil nil nil |
1343
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
423 (list (list 'vc-finish-steal file rev))) |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
424 (goto-char (point-max)) |
904 | 425 (insert |
1343
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
426 (format "I stole the lock on %s:%s, " file rev) |
904 | 427 (current-time-string) |
1343
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
428 ".\n") |
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
429 (message "Please explain why you stole the lock. Type C-c C-c when done.")) |
904 | 430 |
1343
9b5cb40cb6c8
(vc-steal-lock): Use mail-setup, and do like `mail'.
Richard M. Stallman <rms@gnu.org>
parents:
1337
diff
changeset
|
431 ;; This is called when the notification has been sent. |
904 | 432 (defun vc-finish-steal (file version) |
433 (vc-backend-steal file version) | |
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
434 (vc-resynch-window file t t)) |
904 | 435 |
436 (defun vc-checkout (file &optional writeable) | |
437 "Retrieve a copy of the latest version of the given file." | |
438 (vc-backend-checkout file writeable) | |
439 (if (string-equal file buffer-file-name) | |
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
440 (vc-resynch-window file t t)) |
904 | 441 ) |
442 | |
443 (defun vc-checkin (file &optional rev comment) | |
444 "Check in the file specified by FILE. | |
445 The optional argument REV may be a string specifying the new version level | |
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
446 \(if nil increment the current level). The file is either retained with write |
904 | 447 permissions zeroed, or deleted (according to the value of vc-keep-workfiles). |
448 COMMENT is a comment string; if omitted, a buffer is | |
449 popped up to accept a comment." | |
450 (pop-to-buffer (get-buffer-create "*VC-log*")) | |
451 (vc-log-mode) | |
452 (narrow-to-region (point-max) (point-max)) | |
453 (vc-mode-line file (file-name-nondirectory file)) | |
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
454 (setq vc-log-operation 'vc-backend-checkin |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
455 vc-log-file file |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
456 vc-log-version rev |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
457 vc-log-after-operation-hook 'vc-checkin-hook) |
904 | 458 (message "Enter log message. Type C-c C-c when done.") |
459 (if comment | |
460 (progn | |
461 (insert comment) | |
462 (vc-finish-logentry)))) | |
463 | |
464 (defun vc-finish-logentry () | |
465 "Complete the operation implied by the current log entry." | |
466 (interactive) | |
467 (goto-char (point-max)) | |
468 (if (not (bolp)) (newline)) | |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
469 ;; Append the contents of the log buffer to the comment ring |
904 | 470 (save-excursion |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
471 (set-buffer (get-buffer-create "*VC-comment-ring*")) |
904 | 472 (goto-char (point-max)) |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
473 (set-mark (point)) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
474 (insert-buffer-substring "*VC-log*") |
904 | 475 (if (and (not (bobp)) (not (= (char-after (1- (point))) ?\f))) |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
476 (insert-char ?\f 1)) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
477 (if (not (bobp)) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
478 (forward-char -1)) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
479 (exchange-point-and-mark) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
480 ;; Check for errors |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
481 (vc-backend-logentry-check vc-log-file) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
482 ) |
904 | 483 ;; OK, do it to it |
484 (if vc-log-operation | |
485 (funcall vc-log-operation | |
486 vc-log-file | |
487 vc-log-version | |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
488 (buffer-string)) |
904 | 489 (error "No log operation is pending.")) |
490 ;; Return to "parent" buffer of this checkin and remove checkin window | |
491 (pop-to-buffer (get-file-buffer vc-log-file)) | |
492 (delete-window (get-buffer-window "*VC-log*")) | |
493 (bury-buffer "*VC-log*") | |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
494 (bury-buffer "*VC-comment-ring*") |
904 | 495 ;; Now make sure we see the expanded headers |
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
496 (vc-resynch-window buffer-file-name vc-keep-workfiles t) |
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
497 (run-hooks vc-log-after-operation-hook) |
904 | 498 ) |
499 | |
500 ;; Code for access to the comment ring | |
501 | |
502 (defun vc-next-comment () | |
503 "Fill the log buffer with the next message in the msg ring." | |
504 (interactive) | |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
505 (erase-buffer) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
506 (save-excursion |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
507 (set-buffer "*VC-comment-ring*") |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
508 (forward-page) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
509 (if (= (point) (point-max)) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
510 (goto-char (point-min))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
511 (mark-page) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
512 (append-to-buffer "*VC-log*" (point) (1- (mark))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
513 )) |
904 | 514 |
515 (defun vc-previous-comment () | |
516 "Fill the log buffer with the previous message in the msg ring." | |
517 (interactive) | |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
518 (erase-buffer) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
519 (save-excursion |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
520 (set-buffer "*VC-comment-ring*") |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
521 (if (= (point) (point-min)) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
522 (goto-char (point-max))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
523 (backward-page) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
524 (mark-page) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
525 (append-to-buffer "*VC-log*" (point) (1- (mark))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
526 )) |
904 | 527 |
528 (defun vc-comment-search-backward (regexp) | |
529 "Fill the log buffer with the last message in the msg ring matching REGEXP." | |
530 (interactive "sSearch backward for: ") | |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
531 (erase-buffer) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
532 (save-excursion |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
533 (set-buffer "*VC-comment-ring*") |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
534 (if (= (point) (point-min)) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
535 (goto-char (point-max))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
536 (re-search-backward regexp nil t) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
537 (mark-page) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
538 (append-to-buffer "*VC-log*" (point) (1- (mark))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
539 )) |
904 | 540 |
541 (defun vc-comment-search-forward (regexp) | |
542 "Fill the log buffer with the next message in the msg ring matching REGEXP." | |
543 (interactive "sSearch forward for: ") | |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
544 (erase-buffer) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
545 (save-excursion |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
546 (set-buffer "*VC-comment-ring*") |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
547 (if (= (point) (point-max)) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
548 (goto-char (point-min))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
549 (re-search-forward regexp nil t) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
550 (mark-page) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
551 (append-to-buffer "*VC-log*" (point) (1- (mark))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
552 )) |
904 | 553 |
554 ;; Additional entry points for examining version histories | |
555 | |
927 | 556 ;;;###autoload |
904 | 557 (defun vc-diff (historic) |
558 "Display diffs between file versions." | |
559 (interactive "P") | |
560 (if historic | |
561 (call-interactively 'vc-version-diff) | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
562 (let ((file buffer-file-name) |
904 | 563 unchanged) |
564 (vc-buffer-sync) | |
565 (setq unchanged (vc-workfile-unchanged-p buffer-file-name)) | |
566 (if unchanged | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
567 (message "No changes to %s since latest version." file) |
904 | 568 (pop-to-buffer "*vc*") |
569 (vc-backend-diff file nil) | |
570 (goto-char (point-min)) | |
571 ) | |
572 (not unchanged) | |
573 ) | |
574 ) | |
575 ) | |
576 | |
577 (defun vc-version-diff (file rel1 rel2) | |
578 "For FILE, report diffs between two stored versions REL1 and REL2 of it. | |
579 If FILE is a directory, generate diffs between versions for all registered | |
580 files in or below it." | |
2085
a5e2213a5c4a
Version 5 baseline.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2054
diff
changeset
|
581 (interactive "FFile or directory to diff: \nsOlder version: \nsNewer version: ") |
904 | 582 (if (string-equal rel1 "") (setq rel1 nil)) |
583 (if (string-equal rel2 "") (setq rel2 nil)) | |
584 (if (file-directory-p file) | |
585 (progn | |
586 (set-buffer (get-buffer-create "*vc-status*")) | |
587 (erase-buffer) | |
2085
a5e2213a5c4a
Version 5 baseline.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2054
diff
changeset
|
588 (insert "Diffs between " |
a5e2213a5c4a
Version 5 baseline.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2054
diff
changeset
|
589 (or rel1 "last version checked in") |
a5e2213a5c4a
Version 5 baseline.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2054
diff
changeset
|
590 " and " |
a5e2213a5c4a
Version 5 baseline.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2054
diff
changeset
|
591 (or rel2 "current workfile(s)") |
a5e2213a5c4a
Version 5 baseline.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2054
diff
changeset
|
592 ":\n\n") |
904 | 593 (set-buffer (get-buffer-create "*vc*")) |
594 (vc-file-tree-walk | |
595 (function (lambda (f) | |
2219
a729b16f7427
(vc-version-diff): Use (message ...), not (message (format ...)).
Paul Eggert <eggert@twinsun.com>
parents:
2212
diff
changeset
|
596 (message "Looking at %s" f) |
904 | 597 (and |
2085
a5e2213a5c4a
Version 5 baseline.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2054
diff
changeset
|
598 (not (file-directory-p f)) |
a5e2213a5c4a
Version 5 baseline.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2054
diff
changeset
|
599 (vc-registered f) |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
600 (vc-backend-diff f rel1 rel2) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
601 (append-to-buffer "*vc-status*" (point-min) (point-max))) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
602 ))) |
904 | 603 (pop-to-buffer "*vc-status*") |
604 (insert "\nEnd of diffs.\n") | |
605 (goto-char (point-min)) | |
606 (set-buffer-modified-p nil) | |
607 ) | |
608 (progn | |
609 (vc-backend-diff file rel1 rel2) | |
610 (goto-char (point-min)) | |
611 (if (equal (point-min) (point-max)) | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
612 (message "No changes to %s between %s and %s." file rel1 rel2) |
904 | 613 (pop-to-buffer "*vc*") |
614 (goto-char (point-min)) | |
615 ) | |
616 ) | |
617 ) | |
618 ) | |
619 | |
620 ;; Header-insertion code | |
621 | |
927 | 622 ;;;###autoload |
904 | 623 (defun vc-insert-headers () |
624 "Insert headers in a file for use with your version-control system. | |
625 Headers desired are inserted at the start of the buffer, and are pulled from | |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
626 the variable vc-header-alist" |
904 | 627 (interactive) |
628 (save-excursion | |
629 (save-restriction | |
630 (widen) | |
631 (if (or (not (vc-check-headers)) | |
632 (y-or-n-p "Version headers already exist. Insert another set?")) | |
633 (progn | |
634 (let* ((delims (cdr (assq major-mode vc-comment-alist))) | |
635 (comment-start-vc (or (car delims) comment-start "#")) | |
636 (comment-end-vc (or (car (cdr delims)) comment-end "")) | |
637 (hdstrings (cdr (assoc (vc-backend-deduce (buffer-file-name)) vc-header-alist)))) | |
638 (mapcar (function (lambda (s) | |
639 (insert comment-start-vc "\t" s "\t" | |
640 comment-end-vc "\n"))) | |
641 hdstrings) | |
642 (if vc-static-header-alist | |
643 (mapcar (function (lambda (f) | |
644 (if (string-match (car f) buffer-file-name) | |
645 (insert (format (cdr f) (car hdstrings)))))) | |
646 vc-static-header-alist)) | |
647 ) | |
648 ))))) | |
649 | |
650 ;; Status-checking functions | |
651 | |
927 | 652 ;;;###autoload |
904 | 653 (defun vc-directory (verbose) |
654 "Show version-control status of all files under the current directory." | |
655 (interactive "P") | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
656 (let (nonempty) |
904 | 657 (save-excursion |
658 (set-buffer (get-buffer-create "*vc-status*")) | |
659 (erase-buffer) | |
660 (vc-file-tree-walk | |
661 (function (lambda (f) | |
662 (if (vc-registered f) | |
663 (let ((user (vc-locking-user f))) | |
664 (if (or user verbose) | |
665 (insert (format | |
666 "%s %s\n" | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
667 (concat user) f)))))))) |
904 | 668 (setq nonempty (not (zerop (buffer-size))))) |
669 (if nonempty | |
670 (progn | |
671 (pop-to-buffer "*vc-status*" t) | |
672 (vc-shrink-to-fit) | |
673 (goto-char (point-min))) | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
674 (message "No files are currently %s under %s" |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
675 (if verbose "registered" "locked") default-directory)) |
904 | 676 )) |
677 | |
678 ;; Named-configuration support for SCCS | |
679 | |
680 (defun vc-add-triple (name file rev) | |
681 (save-excursion | |
682 (find-file (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file)) | |
683 (goto-char (point-max)) | |
684 (insert name "\t:\t" file "\t" rev "\n") | |
685 (basic-save-buffer) | |
686 (kill-buffer (current-buffer)) | |
687 )) | |
688 | |
689 (defun vc-record-rename (file newname) | |
690 (save-excursion | |
691 (find-file (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file)) | |
692 (goto-char (point-min)) | |
693 (replace-regexp (concat ":" (regexp-quote file) "$") (concat ":" newname)) | |
694 (basic-save-buffer) | |
695 (kill-buffer (current-buffer)) | |
696 )) | |
697 | |
698 (defun vc-lookup-triple (file name) | |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
699 ;; Return the numeric version corresponding to a named snapshot of file |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
700 ;; If name is nil or a version number string it's just passed through |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
701 (cond ((null name) "") |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
702 ((let ((firstchar (aref name 0))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
703 (and (>= firstchar ?0) (<= firstchar ?9))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
704 name) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
705 (t |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
706 (car (vc-master-info |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
707 (concat (vc-backend-subdirectory-name file) "/" vc-name-assoc-file) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
708 (list (concat name "\t:\t" file "\t\\(.+\\)")))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
709 ))) |
904 | 710 |
711 ;; Named-configuration entry points | |
712 | |
713 (defun vc-quiescent-p () | |
714 ;; Is the current directory ready to be snapshot? | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
715 (catch 'quiet |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
716 (vc-file-tree-walk |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
717 (function (lambda (f) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
718 (if (and (vc-registered f) (vc-locking-user f)) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
719 (throw 'quiet nil))))) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
720 t)) |
904 | 721 |
927 | 722 ;;;###autoload |
904 | 723 (defun vc-create-snapshot (name) |
724 "Make a snapshot called NAME. | |
725 The snapshot is made from all registered files at or below the current | |
726 directory. For each file, the version level of its latest | |
727 version becomes part of the named configuration." | |
728 (interactive "sNew snapshot name: ") | |
729 (if (not (vc-quiescent-p)) | |
730 (error "Can't make a snapshot, locked files are in the way.") | |
731 (vc-file-tree-walk | |
732 (function (lambda (f) (and | |
733 (vc-name f) | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
734 (vc-backend-assign-name f name))))) |
904 | 735 )) |
736 | |
927 | 737 ;;;###autoload |
904 | 738 (defun vc-retrieve-snapshot (name) |
739 "Retrieve the snapshot called NAME. | |
740 This function fails if any files are locked at or below the current directory | |
741 Otherwise, all registered files are checked out (unlocked) at their version | |
742 levels in the snapshot." | |
743 (interactive "sSnapshot name to retrieve: ") | |
744 (if (not (vc-quiescent-p)) | |
745 (error "Can't retrieve a snapshot, locked files are in the way.") | |
746 (vc-file-tree-walk | |
747 (function (lambda (f) (and | |
748 (vc-name f) | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
749 (vc-error-occurred (vc-backend-checkout f nil name)))))) |
904 | 750 )) |
751 | |
752 ;; Miscellaneous other entry points | |
753 | |
927 | 754 ;;;###autoload |
904 | 755 (defun vc-print-log () |
756 "List the change log of the current buffer in a window." | |
757 (interactive) | |
758 (if (and buffer-file-name (vc-name buffer-file-name)) | |
759 (progn | |
760 (vc-backend-print-log buffer-file-name) | |
761 (pop-to-buffer (get-buffer-create "*vc*")) | |
762 (goto-char (point-min)) | |
763 ) | |
764 (error "There is no version-control master associated with this buffer") | |
765 ) | |
766 ) | |
767 | |
927 | 768 ;;;###autoload |
904 | 769 (defun vc-revert-buffer () |
952 | 770 "Revert the current buffer's file back to the latest checked-in version. |
771 This asks for confirmation if the buffer contents are not identical | |
772 to that version." | |
904 | 773 (interactive) |
774 (let ((file buffer-file-name) | |
775 (obuf (current-buffer)) (changed (vc-diff nil))) | |
952 | 776 (if (and changed (or vc-suppress-confirm |
777 (not (yes-or-no-p "Discard changes? ")))) | |
904 | 778 (progn |
779 (delete-window) | |
780 (error "Revert cancelled.")) | |
781 (set-buffer obuf)) | |
782 (if changed | |
783 (delete-window)) | |
784 (vc-backend-revert file) | |
1478
429e23e87072
(vc-resynch-window): New arg NOQUERY. Pass it to vc-revert-buffer1.
Richard M. Stallman <rms@gnu.org>
parents:
1352
diff
changeset
|
785 (vc-resynch-window file t t) |
904 | 786 ) |
787 ) | |
788 | |
927 | 789 ;;;###autoload |
904 | 790 (defun vc-cancel-version (norevert) |
791 "Undo your latest checkin." | |
792 (interactive "P") | |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
793 (let ((target (concat (vc-latest-version (buffer-file-name)))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
794 (yours (concat (vc-your-latest-version))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
795 (prompt (if (string-equal yours target) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
796 "Remove your version %s from master?" |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
797 "Version %s was not your change. Remove it anyway?"))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
798 (if (null (yes-or-no-p (format prompt target))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
799 nil |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
800 (vc-backend-uncheck (buffer-file-name) target) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
801 (if norevert |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
802 (vc-mode-line (buffer-file-name)) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
803 (vc-checkout (buffer-file-name) nil))) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
804 ) |
904 | 805 ) |
806 | |
807 (defun vc-rename-file (old new) | |
808 "Rename a file, taking its master files with it." | |
809 (interactive "fOld name: \nFNew name: ") | |
810 (let ((oldbuf (get-file-buffer old))) | |
811 (if (buffer-modified-p oldbuf) | |
812 (error "Please save files before moving them.")) | |
813 (if (get-file-buffer new) | |
814 (error "Already editing new file name.")) | |
815 (let ((oldmaster (vc-name old))) | |
816 (if oldmaster | |
817 (if (vc-locking-user old) | |
818 (error "Please check in files before moving them.")) | |
819 (if (or (file-symlink-p oldmaster) | |
1243
de79e26e67cf
(vc-rename-file): Use OLD, not FILE which is unbound.
Richard M. Stallman <rms@gnu.org>
parents:
1232
diff
changeset
|
820 ;; This had FILE, I changed it to OLD. -- rms. |
de79e26e67cf
(vc-rename-file): Use OLD, not FILE which is unbound.
Richard M. Stallman <rms@gnu.org>
parents:
1232
diff
changeset
|
821 (file-symlink-p (vc-backend-subdirectory-name old))) |
904 | 822 (error "This is not a safe thing to do in the presence of symbolic links.")) |
823 (rename-file oldmaster (vc-name new))) | |
824 (if (or (not oldmaster) (file-exists-p old)) | |
825 (rename-file old new))) | |
826 ; ?? Renaming a file might change its contents due to keyword expansion. | |
827 ; We should really check out a new copy if the old copy was precisely equal | |
828 ; to some checked in version. However, testing for this is tricky.... | |
829 (if oldbuf | |
830 (save-excursion | |
831 (set-buffer oldbuf) | |
832 (set-visited-file-name new) | |
833 (set-buffer-modified-p nil)))) | |
1243
de79e26e67cf
(vc-rename-file): Use OLD, not FILE which is unbound.
Richard M. Stallman <rms@gnu.org>
parents:
1232
diff
changeset
|
834 ;; This had FILE, I changed it to OLD. -- rms. |
de79e26e67cf
(vc-rename-file): Use OLD, not FILE which is unbound.
Richard M. Stallman <rms@gnu.org>
parents:
1232
diff
changeset
|
835 (vc-backend-dispatch old |
904 | 836 (vc-record-rename old new) |
837 nil) | |
838 ) | |
839 | |
927 | 840 ;;;###autoload |
1226
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
841 (defun vc-update-change-log (&rest args) |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
842 "Find change log file and add entries from recent RCS logs. |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
843 The mark is left at the end of the text prepended to the change log. |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
844 With prefix arg of C-u, only find log entries for the current buffer's file. |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
845 With any numeric prefix arg, find log entries for all files currently visited. |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
846 From a program, any arguments are passed to the `rcs2log' script." |
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
847 (interactive |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
848 (cond ((consp current-prefix-arg) ;C-u |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
849 (list buffer-file-name)) |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
850 (current-prefix-arg ;Numeric argument. |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
851 (let ((files nil) |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
852 (buffers (buffer-list)) |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
853 file) |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
854 (while buffers |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
855 (setq file (buffer-file-name (car buffers))) |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
856 (and file (vc-backend-deduce file) |
1232
2c56a159c9b6
(vc-update-change-log): Use file-relative-name.
Roland McGrath <roland@gnu.org>
parents:
1227
diff
changeset
|
857 (setq files (cons (file-relative-name file) files))) |
1227
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
858 (setq buffers (cdr buffers))) |
d07030650283
(vc-checkin-hook): New user hook variable.
Roland McGrath <roland@gnu.org>
parents:
1226
diff
changeset
|
859 files)))) |
1226
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
860 (find-file-other-window "ChangeLog") |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
861 (barf-if-buffer-read-only) |
1226
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
862 (vc-buffer-sync) |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
863 (undo-boundary) |
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
864 (goto-char (point-min)) |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
865 (push-mark) |
1226
573df03a54d8
(vc-update-change-log): Use shell-command, not shell-command-on-region.
Roland McGrath <roland@gnu.org>
parents:
952
diff
changeset
|
866 (message "Computing change log entries...") |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
867 (message "Computing change log entries... %s" |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
868 (if (eq 0 (apply 'call-process "rcs2log" nil t nil args)) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
869 "done" "failed"))) |
904 | 870 |
871 ;; Functions for querying the master and lock files. | |
872 | |
873 (defun match-substring (bn) | |
874 (buffer-substring (match-beginning bn) (match-end bn))) | |
875 | |
876 (defun vc-parse-buffer (patterns &optional file properties) | |
877 ;; Use PATTERNS to parse information out of the current buffer | |
878 ;; by matching each regular expression in the list and returning \\1. | |
879 ;; If a regexp has two tag brackets, assume the second is a date | |
880 ;; field and we want the most recent entry matching the template. | |
881 ;; If FILE and PROPERTIES are given, the latter must be a list of | |
882 ;; properties of the same length as PATTERNS; each property is assigned | |
883 ;; the corresponding value. | |
884 (mapcar (function (lambda (p) | |
885 (goto-char (point-min)) | |
886 (if (string-match "\\\\(.*\\\\(" p) | |
887 (let ((latest-date "") (latest-val)) | |
888 (while (re-search-forward p nil t) | |
889 (let ((date (match-substring 2))) | |
890 (if (string< latest-date date) | |
891 (progn | |
892 (setq latest-date date) | |
893 (setq latest-val | |
894 (match-substring 1)))))) | |
895 latest-val)) | |
896 (prog1 | |
897 (and (re-search-forward p nil t) | |
898 (let ((value (match-substring 1))) | |
899 (if file | |
900 (vc-file-setprop file (car properties) value)) | |
901 value)) | |
902 (setq properties (cdr properties))))) | |
903 patterns) | |
904 ) | |
905 | |
906 (defun vc-master-info (file fields &optional rfile properties) | |
907 ;; Search for information in a master file. | |
908 (if (and file (file-exists-p file)) | |
909 (save-excursion | |
910 (let ((buf)) | |
911 (setq buf (create-file-buffer file)) | |
912 (set-buffer buf)) | |
913 (erase-buffer) | |
914 (insert-file-contents file nil) | |
915 (set-buffer-modified-p nil) | |
916 (auto-save-mode nil) | |
917 (prog1 | |
918 (vc-parse-buffer fields rfile properties) | |
919 (kill-buffer (current-buffer))) | |
920 ) | |
921 (if rfile | |
922 (mapcar | |
923 (function (lambda (p) (vc-file-setprop rfile p nil))) | |
924 properties)) | |
925 ) | |
926 ) | |
927 | |
928 (defun vc-log-info (command file patterns &optional properties) | |
929 ;; Search for information in log program output | |
930 (if (and file (file-exists-p file)) | |
931 (save-excursion | |
932 (let ((buf)) | |
933 (setq buf (get-buffer-create "*vc*")) | |
934 (set-buffer buf)) | |
935 (apply 'vc-do-command 0 command file nil) | |
936 (set-buffer-modified-p nil) | |
937 (prog1 | |
938 (vc-parse-buffer patterns file properties) | |
939 (kill-buffer (current-buffer)) | |
940 ) | |
941 ) | |
942 (if file | |
943 (mapcar | |
944 (function (lambda (p) (vc-file-setprop file p nil))) | |
945 properties)) | |
946 ) | |
947 ) | |
948 | |
949 (defun vc-locking-user (file) | |
950 "Return the name of the person currently holding a lock on FILE. | |
951 Return nil if there is no such person." | |
952 (if (or (not vc-keep-workfiles) | |
953 (eq vc-mistrust-permissions 't) | |
954 (and vc-mistrust-permissions | |
955 (funcall vc-mistrust-permissions (vc-backend-subdirectory-name file)))) | |
956 (vc-true-locking-user file) | |
957 ;; This implementation assumes that any file which is under version | |
958 ;; control and has -rw-r--r-- is locked by its owner. This is true | |
959 ;; for both RCS and SCCS, which keep unlocked files at -r--r--r--. | |
960 ;; We have to be careful not to exclude files with execute bits on; | |
961 ;; scripts can be under version control too. The advantage of this | |
962 ;; hack is that calls to the very expensive vc-fetch-properties | |
963 ;; function only have to be made if (a) the file is locked by someone | |
964 ;; other than the current user, or (b) some untoward manipulation | |
965 ;; behind vc's back has twiddled the `group' or `other' write bits. | |
966 (let ((attributes (file-attributes file))) | |
967 (cond ((string-match ".r-.r-.r-." (nth 8 attributes)) | |
968 nil) | |
969 ((and (= (nth 2 attributes) (user-uid)) | |
970 (string-match ".rw.r-.r-." (nth 8 attributes))) | |
971 (user-login-name)) | |
972 (t | |
973 (vc-true-locking-user file)))))) | |
974 | |
975 (defun vc-true-locking-user (file) | |
976 ;; The slow but reliable version | |
977 (vc-fetch-properties file) | |
978 (vc-file-getprop file 'vc-locking-user)) | |
979 | |
980 (defun vc-latest-version (file) | |
981 ;; Return version level of the latest version of FILE | |
982 (vc-fetch-properties file) | |
983 (vc-file-getprop file 'vc-latest-version)) | |
984 | |
985 (defun vc-your-latest-version (file) | |
986 ;; Return version level of the latest version of FILE checked in by you | |
987 (vc-fetch-properties file) | |
988 (vc-file-getprop file 'vc-your-latest-version)) | |
989 | |
990 ;; Collect back-end-dependent stuff here | |
991 ;; | |
992 ;; Everything eventually funnels through these functions. To implement | |
993 ;; support for a new version-control system, add another branch to the | |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
994 ;; vc-backend-dispatch macro and fill it in in each call. The variable |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
995 ;; vc-master-templates in vc-hooks.el will also have to change. |
904 | 996 |
997 (defmacro vc-backend-dispatch (f s r) | |
998 "Execute FORM1 or FORM2 depending on whether we're using SCCS or RCS." | |
999 (list 'let (list (list 'type (list 'vc-backend-deduce f))) | |
1000 (list 'cond | |
1001 (list (list 'eq 'type (quote 'SCCS)) s) ;; SCCS | |
1002 (list (list 'eq 'type (quote 'RCS)) r) ;; RCS | |
1003 ))) | |
1004 | |
1005 (defun vc-lock-file (file) | |
1006 ;; Generate lock file name corresponding to FILE | |
1007 (let ((master (vc-name file))) | |
1008 (and | |
1009 master | |
1010 (string-match "\\(.*/\\)s\\.\\(.*\\)" master) | |
1011 (concat | |
1012 (substring master (match-beginning 1) (match-end 1)) | |
1013 "p." | |
1014 (substring master (match-beginning 2) (match-end 2)))))) | |
1015 | |
1016 | |
1017 (defun vc-fetch-properties (file) | |
1018 ;; Re-fetch all properties associated with the given file. | |
1019 ;; Currently these properties are: | |
1020 ;; vc-locking-user | |
1021 ;; vc-locked-version | |
1022 ;; vc-latest-version | |
1023 ;; vc-your-latest-version | |
1024 (vc-backend-dispatch | |
1025 file | |
1026 ;; SCCS | |
1027 (progn | |
1028 (vc-master-info (vc-lock-file file) | |
1029 (list | |
1030 "^[^ ]+ [^ ]+ \\([^ ]+\\)" | |
1031 "^\\([^ ]+\\)") | |
1032 file | |
1033 '(vc-locking-user vc-locked-version)) | |
1034 (vc-master-info (vc-name file) | |
1035 (list | |
1036 "^\001d D \\([^ ]+\\)" | |
1037 (concat "^\001d D \\([^ ]+\\) .* " | |
1038 (regexp-quote (user-login-name)) " ") | |
1039 ) | |
1040 file | |
1041 '(vc-latest-version vc-your-latest-version)) | |
1042 ) | |
1043 ;; RCS | |
1044 (vc-log-info "rlog" file | |
1045 (list | |
1046 "^locks: strict\n\t\\([^:]+\\)" | |
1047 "^locks: strict\n\t[^:]+: \\(.+\\)" | |
1048 "^revision[\t ]+\\([0-9.]+\\).*\ndate: \\([ /0-9:]+\\);" | |
1049 (concat | |
2085
a5e2213a5c4a
Version 5 baseline.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2054
diff
changeset
|
1050 "^revision[\t ]+\\([0-9.]+\\)\n.*author: " |
904 | 1051 (regexp-quote (user-login-name)) |
2085
a5e2213a5c4a
Version 5 baseline.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2054
diff
changeset
|
1052 ";")) |
904 | 1053 '(vc-locking-user vc-locked-version |
1054 vc-latest-version vc-your-latest-version)) | |
1055 )) | |
1056 | |
1057 (defun vc-backend-subdirectory-name (&optional file) | |
1058 ;; Where the master and lock files for the current directory are kept | |
1059 (symbol-name | |
1060 (or | |
1061 (and file (vc-backend-deduce file)) | |
1062 vc-default-back-end | |
1063 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS))))) | |
1064 | |
1065 (defun vc-backend-admin (file &optional rev comment) | |
1066 ;; Register a file into the version-control system | |
1067 ;; Automatically retrieves a read-only version of the file with | |
1068 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise | |
1069 ;; it deletes the workfile. | |
1070 (vc-file-clearprops file) | |
1071 (or vc-default-back-end | |
1072 (setq vc-default-back-end (if (vc-find-binary "rcs") 'RCS 'SCCS))) | |
1073 (message "Registering %s..." file) | |
1074 (let ((backend | |
1075 (cond | |
1076 ((file-exists-p (vc-backend-subdirectory-name)) vc-default-back-end) | |
1077 ((file-exists-p "RCS") 'RCS) | |
1078 ((file-exists-p "SCCS") 'SCCS) | |
1079 (t vc-default-back-end)))) | |
1080 (cond ((eq backend 'SCCS) | |
1081 (vc-do-command 0 "admin" file ;; SCCS | |
1082 (and rev (concat "-r" rev)) | |
1083 "-fb" | |
1084 (concat "-i" file) | |
1085 (and comment (concat "-y" comment)) | |
1086 (format | |
1087 (car (rassq 'SCCS vc-master-templates)) | |
1088 (or (file-name-directory file) "") | |
1089 (file-name-nondirectory file))) | |
1090 (delete-file file) | |
1091 (if vc-keep-workfiles | |
1092 (vc-do-command 0 "get" file))) | |
1093 ((eq backend 'RCS) | |
1094 (vc-do-command 0 "ci" file ;; RCS | |
1095 (concat (if vc-keep-workfiles "-u" "-r") rev) | |
1096 (and comment (concat "-t-" comment)) | |
1097 file) | |
1098 ))) | |
1099 (message "Registering %s...done" file) | |
1100 ) | |
1101 | |
1102 (defun vc-backend-checkout (file &optional writeable rev) | |
1103 ;; Retrieve a copy of a saved version into a workfile | |
2219
a729b16f7427
(vc-version-diff): Use (message ...), not (message (format ...)).
Paul Eggert <eggert@twinsun.com>
parents:
2212
diff
changeset
|
1104 (message "Checking out %s..." file) |
904 | 1105 (vc-backend-dispatch file |
1106 (progn | |
1107 (vc-do-command 0 "get" file ;; SCCS | |
1108 (if writeable "-e") | |
1109 (and rev (concat "-r" (vc-lookup-triple file rev)))) | |
1110 ) | |
1111 (vc-do-command 0 "co" file ;; RCS | |
1112 (if writeable "-l") | |
1113 (and rev (concat "-r" rev))) | |
1114 ) | |
1115 (vc-file-setprop file 'vc-checkout-time (nth 5 (file-attributes file))) | |
1116 (message "Checking out %s...done" file) | |
1117 ) | |
1118 | |
1119 (defun vc-backend-logentry-check (file) | |
1120 (vc-backend-dispatch file | |
1121 (if (>= (- (region-end) (region-beginning)) 512) ;; SCCS | |
1122 (progn | |
1123 (goto-char 512) | |
1124 (error | |
1125 "Log must be less than 512 characters. Point is now at char 512."))) | |
1126 nil) | |
1127 ) | |
1128 | |
1129 (defun vc-backend-checkin (file &optional rev comment) | |
1130 ;; Register changes to FILE as level REV with explanatory COMMENT. | |
1131 ;; Automatically retrieves a read-only version of the file with | |
1132 ;; keywords expanded if vc-keep-workfiles is non-nil, otherwise | |
1133 ;; it deletes the workfile. | |
1134 (message "Checking in %s..." file) | |
1337
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1135 (save-excursion |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1136 ;; Change buffers to get local value of vc-checkin-switches. |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1137 (set-buffer (or (get-file-buffer file) (current-buffer))) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1138 (vc-backend-dispatch file |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1139 (progn |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1140 (apply 'vc-do-command 0 "delta" file |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1141 (if rev (concat "-r" rev)) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1142 (concat "-y" comment) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1143 vc-checkin-switches) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1144 (if vc-keep-workfiles |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1145 (vc-do-command 0 "get" file)) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1146 ) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1147 (apply 'vc-do-command 0 "ci" file |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1148 (concat (if vc-keep-workfiles "-u" "-r") rev) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1149 (concat "-m" comment) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1150 vc-checkin-switches) |
ab589b426055
(vc-backend-checkin): Change buffers to get local value of vc-checkin-switches.
Roland McGrath <roland@gnu.org>
parents:
1336
diff
changeset
|
1151 )) |
904 | 1152 (vc-file-setprop file 'vc-locking-user nil) |
1153 (message "Checking in %s...done" file) | |
1154 ) | |
1155 | |
1156 (defun vc-backend-revert (file) | |
1157 ;; Revert file to latest checked-in version. | |
1158 (message "Reverting %s..." file) | |
1159 (vc-backend-dispatch | |
1160 file | |
1161 (progn ;; SCCS | |
1162 (vc-do-command 0 "unget" file nil) | |
1163 (vc-do-command 0 "get" file nil)) | |
1164 (progn | |
1165 (delete-file file) ;; RCS | |
1166 (vc-do-command 0 "co" file "-u"))) | |
1167 (vc-file-setprop file 'vc-locking-user nil) | |
1168 (message "Reverting %s...done" file) | |
1169 ) | |
1170 | |
1171 (defun vc-backend-steal (file &optional rev) | |
1172 ;; Steal the lock on the current workfile. Needs RCS 5.6.2 or later for -M. | |
1173 (message "Stealing lock on %s..." file) | |
1174 (progn | |
1175 (vc-do-command 0 "unget" file "-n" (if rev (concat "-r" rev))) | |
1176 (vc-do-command 0 "get" file "-g" (if rev (concat "-r" rev))) | |
1177 ) | |
1178 (progn | |
1344
8d047d2d2592
(vc-backend-steal): Put filename after options in rcs commands.
Richard M. Stallman <rms@gnu.org>
parents:
1343
diff
changeset
|
1179 (vc-do-command 0 "rcs" "-M" (concat "-u" rev) file) |
1352
a8623439066b
(vc-backend-steal): Delete the workfile after the rcs -M -u.
Richard M. Stallman <rms@gnu.org>
parents:
1344
diff
changeset
|
1180 (delete-file file) |
1344
8d047d2d2592
(vc-backend-steal): Put filename after options in rcs commands.
Richard M. Stallman <rms@gnu.org>
parents:
1343
diff
changeset
|
1181 (vc-do-command 0 "rcs" (concat "-l" rev) file) |
904 | 1182 ) |
1183 (vc-file-setprop file 'vc-locking-user (user-login-name)) | |
1184 (message "Stealing lock on %s...done" file) | |
1185 ) | |
1186 | |
1187 (defun vc-backend-uncheck (file target) | |
1188 ;; Undo the latest checkin. Note: this code will have to get a lot | |
1189 ;; smarter when we support multiple branches. | |
1190 (message "Removing last change from %s..." file) | |
1191 (vc-backend-dispatch file | |
1192 (vc-do-command 0 "rmdel" file (concat "-r" target)) | |
1193 (vc-do-command 0 "rcs" file (concat "-o" target)) | |
1194 ) | |
1195 (message "Removing last change from %s...done" file) | |
1196 ) | |
1197 | |
1198 (defun vc-backend-print-log (file) | |
1199 ;; Print change log associated with FILE to buffer *vc*. | |
1200 (vc-do-command 0 | |
1201 (vc-backend-dispatch file "prs" "rlog") | |
1202 file) | |
1203 ) | |
1204 | |
1205 (defun vc-backend-assign-name (file name) | |
1206 ;; Assign to a FILE's latest version a given NAME. | |
1207 (vc-backend-dispatch file | |
1208 (vc-add-triple name file (vc-latest-version file)) ;; SCCS | |
1209 (vc-do-command 0 "rcs" file (concat "-n" name ":")) ;; RCS | |
2085
a5e2213a5c4a
Version 5 baseline.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2054
diff
changeset
|
1210 ) |
a5e2213a5c4a
Version 5 baseline.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2054
diff
changeset
|
1211 ) |
904 | 1212 |
1213 (defun vc-backend-diff (file oldvers &optional newvers) | |
1214 ;; Get a difference report between two versions | |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
1215 (if (eq (vc-backend-deduce file) 'SCCS) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
1216 (setq oldvers (vc-lookup-triple file oldvers)) |
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
1217 (setq newvers (vc-lookup-triple file newvers))) |
904 | 1218 (apply 'vc-do-command 1 |
1219 (or (vc-backend-dispatch file "vcdiff" "rcsdiff") | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1220 (error "File %s is not under version control." file)) |
904 | 1221 file |
1222 (and oldvers (concat "-r" oldvers)) | |
1223 (and newvers (concat "-r" newvers)) | |
1224 vc-diff-options | |
1225 )) | |
1226 | |
1227 (defun vc-check-headers () | |
1228 "Check if the current file has any headers in it." | |
1229 (interactive) | |
1230 (save-excursion | |
1231 (goto-char (point-min)) | |
1232 (vc-backend-dispatch buffer-file-name | |
1233 (re-search-forward "%[MIRLBSDHTEGUYFPQCZWA]%" nil t) ;; SCCS | |
1234 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t) ;; RCS | |
1235 ) | |
1236 )) | |
1237 | |
1238 ;; Back-end-dependent stuff ends here. | |
1239 | |
1240 ;; Set up key bindings for use while editing log messages | |
1241 | |
1242 (defun vc-log-mode () | |
1243 "Minor mode for driving version-control tools. | |
1244 These bindings are added to the global keymap when you enter this mode: | |
1245 \\[vc-next-action] perform next logical version-control operation on current file | |
1246 \\[vc-register] register current file | |
1247 \\[vc-toggle-read-only] like next-action, but won't register files | |
1248 \\[vc-insert-headers] insert version-control headers in current file | |
1249 \\[vc-print-log] display change history of current file | |
1250 \\[vc-revert-buffer] revert buffer to latest version | |
1251 \\[vc-cancel-version] undo latest checkin | |
1252 \\[vc-diff] show diffs between file versions | |
1253 \\[vc-directory] show all files locked by any user in or below . | |
1254 \\[vc-update-change-log] add change log entry from recent checkins | |
1255 | |
1256 While you are entering a change log message for a version, the following | |
1257 additional bindings will be in effect. | |
1258 | |
1259 \\[vc-finish-logentry] proceed with check in, ending log message entry | |
1260 | |
1261 Whenever you do a checkin, your log comment is added to a ring of | |
1262 saved comments. These can be recalled as follows: | |
1263 | |
1264 \\[vc-next-comment] replace region with next message in comment ring | |
1265 \\[vc-previous-comment] replace region with previous message in comment ring | |
1266 \\[vc-search-comment-reverse] search backward for regexp in the comment ring | |
1267 \\[vc-search-comment-forward] search backward for regexp in the comment ring | |
1268 | |
1269 Entry to the change-log submode calls the value of text-mode-hook, then | |
1270 the value of vc-log-mode-hook. | |
1271 | |
1272 Global user options: | |
1273 vc-initial-comment If non-nil, require user to enter a change | |
1274 comment upon first checkin of the file. | |
1275 | |
1276 vc-keep-workfiles Non-nil value prevents workfiles from being | |
1277 deleted when changes are checked in | |
1278 | |
1279 vc-suppress-confirm Suppresses some confirmation prompts, | |
1280 notably for reversions. | |
1281 | |
1282 vc-diff-options A list consisting of the flags | |
1283 to be used for generating context diffs. | |
1284 | |
2226
b2216b3b8f57
(vc-header-strings) Name changed to vc-header-alist, to match the
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2219
diff
changeset
|
1285 vc-header-alist Which keywords to insert when adding headers |
904 | 1286 with \\[vc-insert-headers]. Defaults to |
1287 '(\"\%\W\%\") under SCCS, '(\"\$Id\$\") under RCS. | |
1288 | |
1289 vc-static-header-alist By default, version headers inserted in C files | |
1290 get stuffed in a static string area so that | |
1291 ident(RCS) or what(SCCS) can see them in the | |
1292 compiled object code. You can override this | |
1293 by setting this variable to nil, or change | |
1294 the header template by changing it. | |
1295 | |
1296 vc-command-messages if non-nil, display run messages from the | |
1297 actual version-control utilities (this is | |
1298 intended primarily for people hacking vc | |
1299 itself). | |
1300 " | |
1301 (interactive) | |
1302 (set-syntax-table text-mode-syntax-table) | |
1303 (use-local-map vc-log-entry-mode) | |
1304 (setq local-abbrev-table text-mode-abbrev-table) | |
1305 (setq major-mode 'vc-log-mode) | |
1306 (setq mode-name "VC-Log") | |
1307 (make-local-variable 'vc-log-file) | |
1308 (make-local-variable 'vc-log-version) | |
1309 (set-buffer-modified-p nil) | |
1310 (setq buffer-file-name nil) | |
1311 (run-hooks 'text-mode-hook 'vc-log-mode-hook) | |
1312 ) | |
1313 | |
1314 ;; Initialization code, to be done just once at load-time | |
1315 (if vc-log-entry-mode | |
1316 nil | |
1317 (setq vc-log-entry-mode (make-sparse-keymap)) | |
1318 (define-key vc-log-entry-mode "\M-n" 'vc-next-comment) | |
1319 (define-key vc-log-entry-mode "\M-p" 'vc-previous-comment) | |
1320 (define-key vc-log-entry-mode "\M-r" 'vc-comment-search-backward) | |
1321 (define-key vc-log-entry-mode "\M-s" 'vc-comment-search-forward) | |
1322 (define-key vc-log-entry-mode "\C-c\C-c" 'vc-finish-logentry) | |
1323 ) | |
1324 | |
1325 ;;; These things should probably be generally available | |
1326 | |
1327 (defun vc-shrink-to-fit () | |
1328 "Shrink a window vertically until it's just large enough to contain its text" | |
1329 (let ((minsize (1+ (count-lines (point-min) (point-max))))) | |
1330 (if (< minsize (window-height)) | |
1331 (let ((window-min-height 2)) | |
1332 (shrink-window (- (window-height) minsize)))))) | |
1333 | |
2054
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1334 (defun vc-file-tree-walk (func &rest args) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1335 "Walk recursively through default directory, |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1336 invoking FUNC f ARGS on all non-directory files f underneath it." |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1337 (vc-file-tree-walk-internal default-directory func args) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1338 (message "Traversing directory %s...done" default-directory)) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1339 |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1340 (defun vc-file-tree-walk-internal (file func args) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1341 (if (not (file-directory-p file)) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1342 (apply func file args) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1343 (message "Traversing directory %s..." file) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1344 (let ((dir (file-name-as-directory file))) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1345 (mapcar |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1346 (function |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1347 (lambda (f) (or |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1348 (string-equal f ".") |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1349 (string-equal f "..") |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1350 (let ((dirf (concat dir f))) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1351 (or |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1352 (file-symlink-p dirf) ;; Avoid possible loops |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1353 (vc-file-tree-walk-internal dirf func args)))))) |
341337259785
(vc-update-change-log): Check that ChangeLog is writable
Paul Eggert <eggert@twinsun.com>
parents:
2041
diff
changeset
|
1354 (directory-files dir))))) |
904 | 1355 |
1356 (provide 'vc) | |
1357 | |
1358 ;;; DEVELOPER'S NOTES ON CONCURRENCY PROBLEMS IN THIS CODE | |
1359 ;;; | |
1360 ;;; These may be useful to anyone who has to debug or extend the package. | |
1361 ;;; | |
1362 ;;; A fundamental problem in VC is that there are time windows between | |
1363 ;;; vc-next-action's computations of the file's version-control state and | |
1364 ;;; the actions that change it. This is a window open to lossage in a | |
1365 ;;; multi-user environment; someone else could nip in and change the state | |
1366 ;;; of the master during it. | |
1367 ;;; | |
1368 ;;; The performance problem is that rlog/prs calls are very expensive; we want | |
1369 ;;; to avoid them as much as possible. | |
1370 ;;; | |
1371 ;;; ANALYSIS: | |
1372 ;;; | |
1373 ;;; The performance problem, it turns out, simplifies in practice to the | |
1374 ;;; problem of making vc-locking-user fast. The two other functions that call | |
1375 ;;; prs/rlog will not be so commonly used that the slowdown is a problem; one | |
1376 ;;; makes snapshots, the other deletes the calling user's last change in the | |
1377 ;;; master. | |
1378 ;;; | |
1379 ;;; The race condition implies that we have to either (a) lock the master | |
1380 ;;; during the entire execution of vc-next-action, or (b) detect and | |
1381 ;;; recover from errors resulting from dispatch on an out-of-date state. | |
1382 ;;; | |
1383 ;;; Alternative (a) appears to be unfeasible. The problem is that we can't | |
1384 ;;; guarantee that the lock will ever be removed. Suppose a user starts a | |
1385 ;;; checkin, the change message buffer pops up, and the user, having wandered | |
1386 ;;; off to do something else, simply forgets about it? | |
1387 ;;; | |
1388 ;;; Alternative (b), on the other hand, works well with a cheap way to speed up | |
1389 ;;; vc-locking-user. Usually, if a file is registered, we can read its locked/ | |
1390 ;;; unlocked state and its current owner from its permissions. | |
1391 ;;; | |
1392 ;;; This shortcut will fail if someone has manually changed the workfile's | |
1393 ;;; permissions; also if developers are munging the workfile in several | |
1394 ;;; directories, with symlinks to a master (in this latter case, the | |
1395 ;;; permissions shortcut will fail to detect a lock asserted from another | |
1396 ;;; directory). | |
1397 ;;; | |
1398 ;;; Note that these cases correspond exactly to the errors which could happen | |
1399 ;;; because of a competing checkin/checkout race in between two instances of | |
1400 ;;; vc-next-action. | |
1401 ;;; | |
1402 ;;; For VC's purposes, a workfile/master pair may have the following states: | |
1403 ;;; | |
1404 ;;; A. Unregistered. There is a workfile, there is no master. | |
1405 ;;; | |
1406 ;;; B. Registered and not locked by anyone. | |
1407 ;;; | |
1408 ;;; C. Locked by calling user and unchanged. | |
1409 ;;; | |
1410 ;;; D. Locked by the calling user and changed. | |
1411 ;;; | |
1412 ;;; E. Locked by someone other than the calling user. | |
1413 ;;; | |
1414 ;;; This makes for 25 states and 20 error conditions. Here's the matrix: | |
1415 ;;; | |
1416 ;;; VC's idea of state | |
1417 ;;; | | |
1418 ;;; V Actual state RCS action SCCS action Effect | |
1419 ;;; A B C D E | |
1420 ;;; A . 1 2 3 4 ci -u -t- admin -fb -i<file> initial admin | |
1421 ;;; B 5 . 6 7 8 co -l get -e checkout | |
1422 ;;; C 9 10 . 11 12 co -u unget; get revert | |
1423 ;;; D 13 14 15 . 16 ci -u -m<comment> delta -y<comment>; get checkin | |
1424 ;;; E 17 18 19 20 . rcs -u -M ; rcs -l unget -n ; get -g steal lock | |
1425 ;;; | |
1426 ;;; All commands take the master file name as a last argument (not shown). | |
1427 ;;; | |
1428 ;;; In the discussion below, a "self-race" is a pathological situation in | |
1429 ;;; which VC operations are being attempted simultaneously by two or more | |
1430 ;;; Emacsen running under the same username. | |
1431 ;;; | |
1432 ;;; The vc-next-action code has the following windows: | |
1433 ;;; | |
1434 ;;; Window P: | |
1435 ;;; Between the check for existence of a master file and the call to | |
1436 ;;; admin/checkin in vc-buffer-admin (apparent state A). This window may | |
1437 ;;; never close if the initial-comment feature is on. | |
1438 ;;; | |
1439 ;;; Window Q: | |
1440 ;;; Between the call to vc-workfile-unchanged-p in and the immediately | |
1441 ;;; following revert (apparent state C). | |
1442 ;;; | |
1443 ;;; Window R: | |
1444 ;;; Between the call to vc-workfile-unchanged-p in and the following | |
1445 ;;; checkin (apparent state D). This window may never close. | |
1446 ;;; | |
1447 ;;; Window S: | |
1448 ;;; Between the unlock and the immediately following checkout during a | |
1449 ;;; revert operation (apparent state C). Included in window Q. | |
1450 ;;; | |
1451 ;;; Window T: | |
1452 ;;; Between vc-locking-user and the following checkout (apparent state B). | |
1453 ;;; | |
1454 ;;; Window U: | |
1455 ;;; Between vc-locking-user and the following revert (apparent state C). | |
1456 ;;; Includes windows Q and S. | |
1457 ;;; | |
1458 ;;; Window V: | |
1459 ;;; Between vc-locking-user and the following checkin (apparent state | |
1460 ;;; D). This window may never be closed if the user fails to complete the | |
1461 ;;; checkin message. Includes window R. | |
1462 ;;; | |
1463 ;;; Window W: | |
1464 ;;; Between vc-locking-user and the following steal-lock (apparent | |
1465 ;;; state E). This window may never cloce if the user fails to complete | |
1466 ;;; the steal-lock message. Includes window X. | |
1467 ;;; | |
1468 ;;; Window X: | |
1469 ;;; Between the unlock and the immediately following re-lock during a | |
1470 ;;; steal-lock operation (apparent state E). This window may never cloce | |
1471 ;;; if the user fails to complete the steal-lock message. | |
1472 ;;; | |
1473 ;;; Errors: | |
1474 ;;; | |
1475 ;;; Apparent state A --- | |
1476 ;;; | |
1477 ;;; 1. File looked unregistered but is actually registered and not locked. | |
1478 ;;; | |
1479 ;;; Potential cause: someone else's admin during window P, with | |
1480 ;;; caller's admin happening before their checkout. | |
1481 ;;; | |
1482 ;;; RCS: ci will fail with a "no lock set by <user>" message. | |
1483 ;;; SCCS: admin will fail with error (ad19). | |
1484 ;;; | |
1485 ;;; We can let these errors be passed up to the user. | |
1486 ;;; | |
1487 ;;; 2. File looked unregistered but is actually locked by caller, unchanged. | |
1488 ;;; | |
1489 ;;; Potential cause: self-race during window P. | |
1490 ;;; | |
1491 ;;; RCS: will revert the file to the last saved version and unlock it. | |
1492 ;;; SCCS: will fail with error (ad19). | |
1493 ;;; | |
1494 ;;; Either of these consequences is acceptable. | |
1495 ;;; | |
1496 ;;; 3. File looked unregistered but is actually locked by caller, changed. | |
1497 ;;; | |
1498 ;;; Potential cause: self-race during window P. | |
1499 ;;; | |
1500 ;;; RCS: will register the caller's workfile as a delta with a | |
1501 ;;; null change comment (the -t- switch will be ignored). | |
1502 ;;; SCCS: will fail with error (ad19). | |
1503 ;;; | |
1504 ;;; 4. File looked unregistered but is locked by someone else. | |
1505 ;;; | |
1506 ;;; Potential cause: someone else's admin during window P, with | |
1507 ;;; caller's admin happening *after* their checkout. | |
1508 ;;; | |
1509 ;;; RCS: will fail with a "no lock set by <user>" message. | |
1510 ;;; SCCS: will fail with error (ad19). | |
1511 ;;; | |
1512 ;;; We can let these errors be passed up to the user. | |
1513 ;;; | |
1514 ;;; Apparent state B --- | |
1515 ;;; | |
1516 ;;; 5. File looked registered and not locked, but is actually unregistered. | |
1517 ;;; | |
1518 ;;; Potential cause: master file got nuked during window P. | |
1519 ;;; | |
1520 ;;; RCS: will fail with "RCS/<file>: No such file or directory" | |
1521 ;;; SCCS: will fail with error ut4. | |
1522 ;;; | |
1523 ;;; We can let these errors be passed up to the user. | |
1524 ;;; | |
1525 ;;; 6. File looked registered and not locked, but is actually locked by the | |
1526 ;;; calling user and unchanged. | |
1527 ;;; | |
1528 ;;; Potential cause: self-race during window T. | |
1529 ;;; | |
1530 ;;; RCS: in the same directory as the previous workfile, co -l will fail | |
1531 ;;; with "co error: writable foo exists; checkout aborted". In any other | |
1532 ;;; directory, checkout will succeed. | |
1533 ;;; SCCS: will fail with ge17. | |
1534 ;;; | |
1535 ;;; Either of these consequences is acceptable. | |
1536 ;;; | |
1537 ;;; 7. File looked registered and not locked, but is actually locked by the | |
1538 ;;; calling user and changed. | |
1539 ;;; | |
1540 ;;; As case 6. | |
1541 ;;; | |
1542 ;;; 8. File looked registered and not locked, but is actually locked by another | |
1543 ;;; user. | |
1544 ;;; | |
1545 ;;; Potential cause: someone else checks it out during window T. | |
1546 ;;; | |
1547 ;;; RCS: co error: revision 1.3 already locked by <user> | |
1548 ;;; SCCS: fails with ge4 (in directory) or ut7 (outside it). | |
1549 ;;; | |
1550 ;;; We can let these errors be passed up to the user. | |
1551 ;;; | |
1552 ;;; Apparent state C --- | |
1553 ;;; | |
1554 ;;; 9. File looks locked by calling user and unchanged, but is unregistered. | |
1555 ;;; | |
1556 ;;; As case 5. | |
1557 ;;; | |
1558 ;;; 10. File looks locked by calling user and unchanged, but is actually not | |
1559 ;;; locked. | |
1560 ;;; | |
1561 ;;; Potential cause: a self-race in window U, or by the revert's | |
1562 ;;; landing during window X of some other user's steal-lock or window S | |
1563 ;;; of another user's revert. | |
1564 ;;; | |
1565 ;;; RCS: succeeds, refreshing the file from the identical version in | |
1566 ;;; the master. | |
1567 ;;; SCCS: fails with error ut4 (p file nonexistent). | |
1568 ;;; | |
1569 ;;; Either of these consequences is acceptable. | |
1570 ;;; | |
1571 ;;; 11. File is locked by calling user. It looks unchanged, but is actually | |
1572 ;;; changed. | |
1573 ;;; | |
1574 ;;; Potential cause: the file would have to be touched by a self-race | |
1575 ;;; during window Q. | |
1576 ;;; | |
1577 ;;; The revert will succeed, removing whatever changes came with | |
1578 ;;; the touch. It is theoretically possible that work could be lost. | |
1579 ;;; | |
1580 ;;; 12. File looks like it's locked by the calling user and unchanged, but | |
1581 ;;; it's actually locked by someone else. | |
1582 ;;; | |
1583 ;;; Potential cause: a steal-lock in window V. | |
1584 ;;; | |
1585 ;;; RCS: co error: revision <rev> locked by <user>; use co -r or rcs -u | |
1586 ;;; SCCS: fails with error un2 | |
1587 ;;; | |
1588 ;;; We can pass these errors up to the user. | |
1589 ;;; | |
1590 ;;; Apparent state D --- | |
1591 ;;; | |
1592 ;;; 13. File looks like it's locked by the calling user and changed, but it's | |
1593 ;;; actually unregistered. | |
1594 ;;; | |
1595 ;;; Potential cause: master file got nuked during window P. | |
1596 ;;; | |
1597 ;;; RCS: Checks in the user's version as an initial delta. | |
1598 ;;; SCCS: will fail with error ut4. | |
1599 ;;; | |
1600 ;;; This case is kind of nasty. It means VC may fail to detect the | |
1601 ;;; loss of previous version information. | |
1602 ;;; | |
1603 ;;; 14. File looks like it's locked by the calling user and changed, but it's | |
1604 ;;; actually unlocked. | |
1605 ;;; | |
1606 ;;; Potential cause: self-race in window V, or the checkin happening | |
1607 ;;; during the window X of someone else's steal-lock or window S of | |
1608 ;;; someone else's revert. | |
1609 ;;; | |
1610 ;;; RCS: ci will fail with "no lock set by <user>". | |
1611 ;;; SCCS: delta will fail with error ut4. | |
1612 ;;; | |
1613 ;;; 15. File looks like it's locked by the calling user and changed, but it's | |
1614 ;;; actually locked by the calling user and unchanged. | |
1615 ;;; | |
1616 ;;; Potential cause: another self-race --- a whole checkin/checkout | |
1617 ;;; sequence by the calling user would have to land in window R. | |
1618 ;;; | |
1619 ;;; SCCS: checks in a redundant delta and leaves the file unlocked as usual. | |
1620 ;;; RCS: reverts to the file state as of the second user's checkin, leaving | |
1621 ;;; the file unlocked. | |
1622 ;;; | |
1623 ;;; It is theoretically possible that work could be lost under RCS. | |
1624 ;;; | |
1625 ;;; 16. File looks like it's locked by the calling user and changed, but it's | |
1626 ;;; actually locked by a different user. | |
1627 ;;; | |
1628 ;;; RCS: ci error: no lock set by <user> | |
1629 ;;; SCCS: unget will fail with error un2 | |
1630 ;;; | |
1631 ;;; We can pass these errors up to the user. | |
1632 ;;; | |
1633 ;;; Apparent state E --- | |
1634 ;;; | |
1635 ;;; 17. File looks like it's locked by some other user, but it's actually | |
1636 ;;; unregistered. | |
1637 ;;; | |
1638 ;;; As case 13. | |
1639 ;;; | |
1640 ;;; 18. File looks like it's locked by some other user, but it's actually | |
1641 ;;; unlocked. | |
1642 ;;; | |
1643 ;;; Potential cause: someone released a lock during window W. | |
1644 ;;; | |
1645 ;;; RCS: The calling user will get the lock on the file. | |
1646 ;;; SCCS: unget -n will fail with cm4. | |
1647 ;;; | |
1648 ;;; Either of these consequences will be OK. | |
1649 ;;; | |
1650 ;;; 19. File looks like it's locked by some other user, but it's actually | |
1651 ;;; locked by the calling user and unchanged. | |
1652 ;;; | |
1653 ;;; Potential cause: the other user relinquishing a lock followed by | |
1654 ;;; a self-race, both in window W. | |
1655 ;;; | |
1656 ;;; Under both RCS and SCCS, both unlock and lock will succeed, making | |
1657 ;;; the sequence a no-op. | |
1658 ;;; | |
1659 ;;; 20. File looks like it's locked by some other user, but it's actually | |
1660 ;;; locked by the calling user and changed. | |
1661 ;;; | |
1662 ;;; As case 19. | |
1663 ;;; | |
1664 ;;; PROBLEM CASES: | |
1665 ;;; | |
1666 ;;; In order of decreasing severity: | |
1667 ;;; | |
1668 ;;; Cases 11 and 15 under RCS are the only one that potentially lose work. | |
1669 ;;; They would require a self-race for this to happen. | |
1670 ;;; | |
1671 ;;; Case 13 in RCS loses information about previous deltas, retaining | |
1672 ;;; only the information in the current workfile. This can only happen | |
1673 ;;; if the master file gets nuked in window P. | |
1674 ;;; | |
1675 ;;; Case 3 in RCS and case 15 under SCCS insert a redundant delta with | |
1676 ;;; no change comment in the master. This would require a self-race in | |
1677 ;;; window P or R respectively. | |
1678 ;;; | |
1679 ;;; Cases 2, 10, 19 and 20 do extra work, but make no changes. | |
1680 ;;; | |
1681 ;;; Unfortunately, it appears to me that no recovery is possible in these | |
1682 ;;; cases. They don't yield error messages, so there's no way to tell that | |
1683 ;;; a race condition has occurred. | |
1684 ;;; | |
1685 ;;; All other cases don't change either the workfile or the master, and | |
1686 ;;; trigger command errors which the user will see. | |
1687 ;;; | |
1688 ;;; Thus, there is no explicit recovery code. | |
1689 | |
1690 ;;; vc.el ends here |