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