Commit | Line | Data |
---|---|---|
d8aff077 GM |
1 | ;;; vc-rcs.el --- support for RCS version-control |
2 | ||
3 | ;; Copyright (C) 1992,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc. | |
4 | ||
5 | ;; Author: FSF (see vc.el for full credits) | |
6 | ;; Maintainer: Andre Spiegel <spiegel@gnu.org> | |
7 | ||
fb0d6a79 | 8 | ;; $Id: vc-rcs.el,v 1.10 2000/10/03 11:33:59 spiegel Exp $ |
d8aff077 GM |
9 | |
10 | ;; This file is part of GNU Emacs. | |
11 | ||
12 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 | ;; it under the terms of the GNU General Public License as published by | |
14 | ;; the Free Software Foundation; either version 2, or (at your option) | |
15 | ;; any later version. | |
16 | ||
17 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ;; GNU General Public License for more details. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
23 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 | ;; Boston, MA 02111-1307, USA. | |
26 | ||
27 | ;;; Commentary: see vc.el | |
28 | ||
29 | ;;; Code: | |
30 | ||
0bc58756 | 31 | (eval-when-compile |
7849e179 | 32 | (require 'cl)) |
0bc58756 | 33 | |
d8aff077 GM |
34 | (defcustom vc-rcs-release nil |
35 | "*The release number of your RCS installation, as a string. | |
36 | If nil, VC itself computes this value when it is first needed." | |
37 | :type '(choice (const :tag "Auto" nil) | |
38 | (string :tag "Specified") | |
39 | (const :tag "Unknown" unknown)) | |
40 | :group 'vc) | |
41 | ||
42 | (defcustom vc-rcs-register-switches nil | |
33c1b7a1 DL |
43 | "*Extra switches for registering a file in RCS. |
44 | A string or list of strings. These are passed to the checkin program | |
45 | by \\[vc-rcs-register]." | |
d8aff077 GM |
46 | :type '(choice (const :tag "None" nil) |
47 | (string :tag "Argument String") | |
48 | (repeat :tag "Argument List" | |
49 | :value ("") | |
50 | string)) | |
33c1b7a1 | 51 | :version "21.1" |
d8aff077 GM |
52 | :group 'vc) |
53 | ||
54 | (defcustom vc-rcs-checkin-switches nil | |
55 | "*A string or list of strings specifying extra switches for RCS checkin. | |
56 | These are passed to the checkin program by \\[vc-rcs-checkin]." | |
57 | :type '(choice (const :tag "None" nil) | |
58 | (string :tag "Argument String") | |
59 | (repeat :tag "Argument List" | |
60 | :value ("") | |
61 | string)) | |
33c1b7a1 | 62 | :version "21.1" |
d8aff077 GM |
63 | :group 'vc) |
64 | ||
65 | (defcustom vc-rcs-checkout-switches nil | |
66 | "*A string or list of strings specifying extra switches for RCS checkout. | |
67 | These are passed to the checkout program by \\[vc-rcs-checkout]." | |
68 | :type '(choice (const :tag "None" nil) | |
69 | (string :tag "Argument String") | |
70 | (repeat :tag "Argument List" | |
71 | :value ("") | |
72 | string)) | |
33c1b7a1 | 73 | :version "21.1" |
d8aff077 GM |
74 | :group 'vc) |
75 | ||
76 | (defcustom vc-rcs-header (or (cdr (assoc 'RCS vc-header-alist)) '("\$Id\$")) | |
77 | "*Header keywords to be inserted by `vc-insert-headers'." | |
78 | :type 'string | |
33c1b7a1 | 79 | :version "21.1" |
d8aff077 GM |
80 | :group 'vc) |
81 | ||
82 | (defcustom vc-rcsdiff-knows-brief nil | |
83 | "*Indicates whether rcsdiff understands the --brief option. | |
84 | The value is either `yes', `no', or nil. If it is nil, VC tries | |
85 | to use --brief and sets this variable to remember whether it worked." | |
86 | :type '(choice (const :tag "Work out" nil) (const yes) (const no)) | |
87 | :group 'vc) | |
88 | ||
89 | ;;;###autoload | |
90 | (defcustom vc-rcs-master-templates | |
91 | '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s") | |
92 | "*Where to look for RCS master files. | |
93 | For a description of possible values, see `vc-check-master-templates'." | |
94 | :type '(choice (const :tag "Use standard RCS file names" | |
95 | '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s")) | |
96 | (repeat :tag "User-specified" | |
97 | (choice string | |
98 | function))) | |
33c1b7a1 | 99 | :version "21.1" |
d8aff077 GM |
100 | :group 'vc) |
101 | ||
102 | ;;;###autoload | |
103 | (progn (defun vc-rcs-registered (f) (vc-default-registered 'RCS f))) | |
104 | ||
105 | (defun vc-rcs-state (file) | |
106 | "Implementation of `vc-state' for RCS." | |
107 | (or (boundp 'vc-rcs-headers-result) | |
108 | (and vc-consult-headers | |
109 | (vc-rcs-consult-headers file))) | |
110 | (let ((state | |
111 | ;; vc-workfile-version might not be known; in that case the | |
112 | ;; property is nil. vc-rcs-fetch-master-state knows how to | |
113 | ;; handle that. | |
33c1b7a1 DL |
114 | (vc-rcs-fetch-master-state file |
115 | (vc-file-getprop file | |
d8aff077 GM |
116 | 'vc-workfile-version)))) |
117 | (if (eq state 'up-to-date) | |
33c1b7a1 DL |
118 | (if (vc-workfile-unchanged-p file) |
119 | 'up-to-date | |
d8aff077 GM |
120 | 'unlocked-changes) |
121 | state))) | |
122 | ||
123 | (defun vc-rcs-state-heuristic (file) | |
124 | "State heuristic for RCS." | |
125 | (let (vc-rcs-headers-result) | |
126 | (if (and vc-consult-headers | |
33c1b7a1 | 127 | (setq vc-rcs-headers-result |
d8aff077 GM |
128 | (vc-rcs-consult-headers file)) |
129 | (eq vc-rcs-headers-result 'rev-and-lock)) | |
130 | (let ((state (vc-file-getprop file 'vc-state))) | |
131 | ;; If the headers say that the file is not locked, the | |
132 | ;; permissions can tell us whether locking is used for | |
133 | ;; the file or not. | |
134 | (if (and (eq state 'up-to-date) | |
135 | (not (vc-mistrust-permissions file))) | |
136 | (cond | |
137 | ((string-match ".rw..-..-." (nth 8 (file-attributes file))) | |
0db2c43c AS |
138 | (vc-file-setprop file 'vc-checkout-model 'implicit) |
139 | (setq state | |
140 | (if (vc-rcs-workfile-is-newer file) | |
141 | 'edited | |
142 | 'up-to-date))) | |
d8aff077 GM |
143 | ((string-match ".r-..-..-." (nth 8 (file-attributes file))) |
144 | (vc-file-setprop file 'vc-checkout-model 'locking)))) | |
145 | state) | |
146 | (if (not (vc-mistrust-permissions file)) | |
147 | (let* ((attributes (file-attributes file)) | |
148 | (owner-uid (nth 2 attributes)) | |
149 | (permissions (nth 8 attributes))) | |
150 | (cond ((string-match ".r-..-..-." permissions) | |
151 | (vc-file-setprop file 'vc-checkout-model 'locking) | |
152 | 'up-to-date) | |
153 | ((string-match ".rw..-..-." permissions) | |
0db2c43c AS |
154 | (if (eq (vc-checkout-model file) 'locking) |
155 | (if (file-ownership-preserved-p file) | |
156 | 'edited | |
157 | (vc-user-login-name owner-uid)) | |
158 | (if (vc-rcs-workfile-is-newer file) | |
159 | 'edited | |
160 | 'up-to-date))) | |
d8aff077 GM |
161 | (t |
162 | ;; Strange permissions. Fall through to | |
163 | ;; expensive state computation. | |
164 | (vc-rcs-state file)))) | |
165 | (vc-rcs-state file))))) | |
166 | ||
0db2c43c AS |
167 | (defun vc-rcs-workfile-is-newer (file) |
168 | "Return non-nil if FILE is newer than its RCS master. | |
169 | This likely means that FILE has been changed with respect | |
170 | to its master version." | |
171 | (let ((file-time (nth 5 (file-attributes file))) | |
172 | (master-time (nth 5 (file-attributes (vc-name file))))) | |
173 | (or (> (nth 0 file-time) (nth 0 master-time)) | |
174 | (and (= (nth 0 file-time) (nth 0 master-time)) | |
175 | (> (nth 1 file-time) (nth 1 master-time)))))) | |
176 | ||
d8aff077 GM |
177 | (defun vc-rcs-workfile-version (file) |
178 | "RCS-specific version of `vc-workfile-version'." | |
179 | (or (and vc-consult-headers | |
180 | (vc-rcs-consult-headers file) | |
181 | (vc-file-getprop file 'vc-workfile-version)) | |
182 | (progn | |
183 | (vc-rcs-fetch-master-state file) | |
184 | (vc-file-getprop file 'vc-workfile-version)))) | |
185 | ||
186 | (defun vc-rcs-checkout-model (file) | |
187 | "RCS-specific version of `vc-checkout-model'." | |
188 | (vc-rcs-consult-headers file) | |
189 | (or (vc-file-getprop file 'vc-checkout-model) | |
190 | (progn (vc-rcs-fetch-master-state file) | |
191 | (vc-file-getprop file 'vc-checkout-model)))) | |
192 | ||
193 | ;;; internal code | |
194 | ||
195 | (defun vc-rcs-find-most-recent-rev (branch) | |
196 | "Find most recent revision on BRANCH." | |
197 | (goto-char (point-min)) | |
198 | (let ((latest-rev -1) value) | |
199 | (while (re-search-forward (concat "^\\(" (regexp-quote branch) | |
200 | "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;") | |
201 | nil t) | |
202 | (let ((rev (string-to-number (match-string 2)))) | |
203 | (when (< latest-rev rev) | |
204 | (setq latest-rev rev) | |
205 | (setq value (match-string 1))))) | |
0db2c43c AS |
206 | (or value |
207 | (vc-rcs-branch-part branch)))) | |
d8aff077 GM |
208 | |
209 | (defun vc-rcs-fetch-master-state (file &optional workfile-version) | |
33c1b7a1 DL |
210 | "Compute the master file's idea of the state of FILE. |
211 | If a WORKFILE-VERSION is given, compute the state of that version, | |
d8aff077 GM |
212 | otherwise determine the workfile version based on the master file. |
213 | This function sets the properties `vc-workfile-version' and | |
214 | `vc-checkout-model' to their correct values, based on the master | |
215 | file." | |
216 | (with-temp-buffer | |
217 | (vc-insert-file (vc-name file) "^[0-9]") | |
a7e98271 AS |
218 | (let ((workfile-is-latest nil) |
219 | (default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1))) | |
220 | (vc-file-setprop file 'vc-rcs-default-branch default-branch) | |
d8aff077 | 221 | (unless workfile-version |
a7e98271 AS |
222 | ;; Workfile version not known yet. Determine that first. It |
223 | ;; is either the head of the trunk, the head of the default | |
224 | ;; branch, or the "default branch" itself, if that is a full | |
225 | ;; revision number. | |
226 | (cond | |
227 | ;; no default branch | |
228 | ((or (not default-branch) (string= "" default-branch)) | |
229 | (setq workfile-version | |
230 | (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1)) | |
231 | (setq workfile-is-latest t)) | |
232 | ;; default branch is actually a revision | |
233 | ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$" | |
234 | default-branch) | |
235 | (setq workfile-version default-branch)) | |
236 | ;; else, search for the head of the default branch | |
237 | (t (vc-insert-file (vc-name file) "^desc") | |
d8aff077 | 238 | (setq workfile-version |
a7e98271 AS |
239 | (vc-rcs-find-most-recent-rev default-branch)) |
240 | (setq workfile-is-latest t))) | |
241 | (vc-file-setprop file 'vc-workfile-version workfile-version)) | |
d8aff077 GM |
242 | ;; Check strict locking |
243 | (goto-char (point-min)) | |
244 | (vc-file-setprop file 'vc-checkout-model | |
245 | (if (re-search-forward ";[ \t\n]*strict;" nil t) | |
246 | 'locking 'implicit)) | |
247 | ;; Compute state of workfile version | |
248 | (goto-char (point-min)) | |
249 | (let ((locking-user | |
250 | (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):" | |
251 | (regexp-quote workfile-version) | |
252 | "[^0-9.]") | |
253 | 1))) | |
254 | (cond | |
255 | ;; not locked | |
256 | ((not locking-user) | |
33c1b7a1 | 257 | (if (or workfile-is-latest |
d8aff077 GM |
258 | (vc-rcs-latest-on-branch-p file workfile-version)) |
259 | ;; workfile version is latest on branch | |
0db2c43c AS |
260 | (if (eq (vc-checkout-model file) 'locking) |
261 | 'up-to-date | |
262 | (require 'vc) | |
263 | (if (vc-workfile-unchanged-p file) | |
264 | 'up-to-date | |
265 | 'edited)) | |
d8aff077 GM |
266 | ;; workfile version is not latest on branch |
267 | 'needs-patch)) | |
268 | ;; locked by the calling user | |
269 | ((and (stringp locking-user) | |
270 | (string= locking-user (vc-user-login-name))) | |
271 | (if (or (eq (vc-checkout-model file) 'locking) | |
272 | workfile-is-latest | |
273 | (vc-rcs-latest-on-branch-p file workfile-version)) | |
274 | 'edited | |
275 | ;; Locking is not used for the file, but the owner does | |
276 | ;; have a lock, and there is a higher version on the current | |
277 | ;; branch. Not sure if this can occur, and if it is right | |
278 | ;; to use `needs-merge' in this case. | |
279 | 'needs-merge)) | |
280 | ;; locked by somebody else | |
281 | ((stringp locking-user) | |
282 | locking-user) | |
283 | (t | |
284 | (error "Error getting state of RCS file"))))))) | |
285 | ||
286 | (defun vc-rcs-consult-headers (file) | |
287 | "Search for RCS headers in FILE, and set properties accordingly. | |
288 | ||
289 | Returns: nil if no headers were found | |
290 | 'rev if a workfile revision was found | |
291 | 'rev-and-lock if revision and lock info was found" | |
292 | (cond | |
293 | ((not (get-file-buffer file)) nil) | |
294 | ((let (status version locking-user) | |
295 | (save-excursion | |
296 | (set-buffer (get-file-buffer file)) | |
297 | (goto-char (point-min)) | |
298 | (cond | |
299 | ;; search for $Id or $Header | |
300 | ;; ------------------------- | |
301 | ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file. | |
302 | ((or (and (search-forward "$Id\ : " nil t) | |
303 | (looking-at "[^ ]+ \\([0-9.]+\\) ")) | |
304 | (and (progn (goto-char (point-min)) | |
305 | (search-forward "$Header\ : " nil t)) | |
306 | (looking-at "[^ ]+ \\([0-9.]+\\) "))) | |
307 | (goto-char (match-end 0)) | |
308 | ;; if found, store the revision number ... | |
309 | (setq version (match-string-no-properties 1)) | |
310 | ;; ... and check for the locking state | |
311 | (cond | |
312 | ((looking-at | |
313 | (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date | |
314 | "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time | |
315 | "[^ ]+ [^ ]+ ")) ; author & state | |
316 | (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds | |
317 | (cond | |
318 | ;; unlocked revision | |
319 | ((looking-at "\\$") | |
320 | (setq locking-user 'none) | |
321 | (setq status 'rev-and-lock)) | |
322 | ;; revision is locked by some user | |
323 | ((looking-at "\\([^ ]+\\) \\$") | |
324 | (setq locking-user (match-string-no-properties 1)) | |
325 | (setq status 'rev-and-lock)) | |
326 | ;; everything else: false | |
327 | (nil))) | |
328 | ;; unexpected information in | |
329 | ;; keyword string --> quit | |
330 | (nil))) | |
331 | ;; search for $Revision | |
332 | ;; -------------------- | |
333 | ((re-search-forward (concat "\\$" | |
334 | "Revision: \\([0-9.]+\\) \\$") | |
335 | nil t) | |
336 | ;; if found, store the revision number ... | |
337 | (setq version (match-string-no-properties 1)) | |
338 | ;; and see if there's any lock information | |
339 | (goto-char (point-min)) | |
340 | (if (re-search-forward (concat "\\$" "Locker:") nil t) | |
341 | (cond ((looking-at " \\([^ ]+\\) \\$") | |
342 | (setq locking-user (match-string-no-properties 1)) | |
343 | (setq status 'rev-and-lock)) | |
344 | ((looking-at " *\\$") | |
345 | (setq locking-user 'none) | |
346 | (setq status 'rev-and-lock)) | |
347 | (t | |
348 | (setq locking-user 'none) | |
349 | (setq status 'rev-and-lock))) | |
350 | (setq status 'rev))) | |
351 | ;; else: nothing found | |
352 | ;; ------------------- | |
353 | (t nil))) | |
354 | (if status (vc-file-setprop file 'vc-workfile-version version)) | |
355 | (and (eq status 'rev-and-lock) | |
356 | (vc-file-setprop file 'vc-state | |
357 | (cond | |
358 | ((eq locking-user 'none) 'up-to-date) | |
359 | ((string= locking-user (vc-user-login-name)) 'edited) | |
360 | (t locking-user))) | |
361 | ;; If the file has headers, we don't want to query the | |
362 | ;; master file, because that would eliminate all the | |
363 | ;; performance gain the headers brought us. We therefore | |
364 | ;; use a heuristic now to find out whether locking is used | |
365 | ;; for this file. If we trust the file permissions, and the | |
366 | ;; file is not locked, then if the file is read-only we | |
367 | ;; assume that locking is used for the file, otherwise | |
368 | ;; locking is not used. | |
369 | (not (vc-mistrust-permissions file)) | |
370 | (vc-up-to-date-p file) | |
371 | (if (string-match ".r-..-..-." (nth 8 (file-attributes file))) | |
372 | (vc-file-setprop file 'vc-checkout-model 'locking) | |
373 | (vc-file-setprop file 'vc-checkout-model 'implicit))) | |
374 | status)))) | |
375 | ||
376 | (defun vc-rcs-workfile-unchanged-p (file) | |
377 | "RCS-specific implementation of vc-workfile-unchanged-p." | |
378 | ;; Try to use rcsdiff --brief. If rcsdiff does not understand that, | |
379 | ;; do a double take and remember the fact for the future | |
380 | (let* ((version (concat "-r" (vc-workfile-version file))) | |
381 | (status (if (eq vc-rcsdiff-knows-brief 'no) | |
382 | (vc-do-command nil 1 "rcsdiff" file version) | |
383 | (vc-do-command nil 2 "rcsdiff" file "--brief" version)))) | |
384 | (if (eq status 2) | |
385 | (if (not vc-rcsdiff-knows-brief) | |
386 | (setq vc-rcsdiff-knows-brief 'no | |
387 | status (vc-do-command nil 1 "rcsdiff" file version)) | |
388 | (error "rcsdiff failed")) | |
389 | (if (not vc-rcsdiff-knows-brief) (setq vc-rcsdiff-knows-brief 'yes))) | |
390 | ;; The workfile is unchanged if rcsdiff found no differences. | |
391 | (zerop status))) | |
392 | ||
393 | (defun vc-rcs-trunk-p (rev) | |
394 | "Return t if REV is an RCS revision on the trunk." | |
395 | (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev)))) | |
396 | ||
397 | (defun vc-rcs-branch-part (rev) | |
398 | "Return the branch part of an RCS revision number REV" | |
399 | (substring rev 0 (string-match "\\.[0-9]+\\'" rev))) | |
400 | ||
401 | (defun vc-rcs-latest-on-branch-p (file &optional version) | |
402 | "Return non-nil if workfile version of FILE is the latest on its branch. | |
403 | When VERSION is given, perform check for that version." | |
404 | (unless version (setq version (vc-workfile-version file))) | |
405 | (with-temp-buffer | |
406 | (string= version | |
407 | (if (vc-rcs-trunk-p version) | |
408 | (progn | |
409 | ;; Compare VERSION to the head version number. | |
410 | (vc-insert-file (vc-name file) "^[0-9]") | |
411 | (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1)) | |
412 | ;; If we are not on the trunk, we need to examine the | |
413 | ;; whole current branch. | |
414 | (vc-insert-file (vc-name file) "^desc") | |
415 | (vc-rcs-find-most-recent-rev (vc-rcs-branch-part version)))))) | |
416 | \f | |
417 | (defun vc-rcs-branch-p (rev) | |
418 | "Return t if REV is an RCS branch revision" | |
419 | (not (eq nil (string-match "\\`[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*\\'" rev)))) | |
420 | ||
421 | (defun vc-rcs-minor-part (rev) | |
422 | "Return the minor version number of an RCS revision number REV." | |
423 | (string-match "[0-9]+\\'" rev) | |
424 | (substring rev (match-beginning 0) (match-end 0))) | |
425 | ||
426 | (defun vc-rcs-previous-version (rev) | |
427 | "Guess the previous RCS version number" | |
428 | (let ((branch (vc-rcs-branch-part rev)) | |
429 | (minor-num (string-to-number (vc-rcs-minor-part rev)))) | |
430 | (if (> minor-num 1) | |
431 | ;; version does probably not start a branch or release | |
432 | (concat branch "." (number-to-string (1- minor-num))) | |
433 | (if (vc-rcs-trunk-p rev) | |
434 | ;; we are at the beginning of the trunk -- | |
435 | ;; don't know anything to return here | |
436 | "" | |
437 | ;; we are at the beginning of a branch -- | |
438 | ;; return version of starting point | |
439 | (vc-rcs-branch-part branch))))) | |
440 | ||
441 | (defun vc-rcs-print-log (file) | |
442 | "Get change log associated with FILE." | |
443 | (vc-do-command t 0 "rlog" (vc-name file))) | |
444 | ||
445 | (defun vc-rcs-show-log-entry (version) | |
446 | (when (re-search-forward | |
447 | ;; also match some context, for safety | |
448 | (concat "----\nrevision " version | |
449 | "\\(\tlocked by:.*\n\\|\n\\)date: ") nil t) | |
450 | ;; set the display window so that | |
451 | ;; the whole log entry is displayed | |
452 | (let (start end lines) | |
453 | (beginning-of-line) (forward-line -1) (setq start (point)) | |
454 | (if (not (re-search-forward "^----*\nrevision" nil t)) | |
455 | (setq end (point-max)) | |
456 | (beginning-of-line) (forward-line -1) (setq end (point))) | |
457 | (setq lines (count-lines start end)) | |
458 | (cond | |
459 | ;; if the global information and this log entry fit | |
460 | ;; into the window, display from the beginning | |
461 | ((< (count-lines (point-min) end) (window-height)) | |
462 | (goto-char (point-min)) | |
463 | (recenter 0) | |
464 | (goto-char start)) | |
465 | ;; if the whole entry fits into the window, | |
466 | ;; display it centered | |
467 | ((< (1+ lines) (window-height)) | |
468 | (goto-char start) | |
469 | (recenter (1- (- (/ (window-height) 2) (/ lines 2))))) | |
470 | ;; otherwise (the entry is too large for the window), | |
471 | ;; display from the start | |
472 | (t | |
473 | (goto-char start) | |
474 | (recenter 0)))))) | |
475 | ||
476 | (defun vc-rcs-assign-name (file name) | |
477 | "Assign to FILE's latest version a given NAME." | |
478 | (vc-do-command nil 0 "rcs" (vc-name file) (concat "-n" name ":"))) | |
479 | ||
480 | (defun vc-rcs-merge (file first-version &optional second-version) | |
481 | "Merge changes into current working copy of FILE. | |
482 | The changes are between FIRST-VERSION and SECOND-VERSION." | |
483 | (vc-do-command nil 1 "rcsmerge" (vc-name file) | |
484 | "-kk" ; ignore keyword conflicts | |
485 | (concat "-r" first-version) | |
486 | (if second-version (concat "-r" second-version)))) | |
487 | ||
488 | (defun vc-rcs-check-headers () | |
489 | "Check if the current file has any headers in it." | |
490 | (save-excursion | |
491 | (goto-char (point-min)) | |
492 | (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\ | |
493 | \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t))) | |
494 | ||
495 | (defun vc-rcs-clear-headers () | |
496 | "Implementation of vc-clear-headers for RCS." | |
497 | (let ((case-fold-search nil)) | |
498 | (goto-char (point-min)) | |
499 | (while (re-search-forward | |
500 | (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|" | |
501 | "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$") | |
502 | nil t) | |
503 | (replace-match "$\\1$")))) | |
504 | ||
505 | (defun vc-rcs-steal-lock (file &optional rev) | |
506 | "Steal the lock on the current workfile for FILE and revision REV. | |
507 | Needs RCS 5.6.2 or later for -M." | |
508 | (vc-do-command nil 0 "rcs" (vc-name file) "-M" | |
509 | (concat "-u" rev) (concat "-l" rev))) | |
510 | ||
099bd78a SM |
511 | (defun vc-rcs-cancel-version (file writable) |
512 | "Undo the most recent checkin of FILE. | |
513 | WRITABLE non-nil means previous version should be locked." | |
514 | (let* ((target (vc-workfile-version file)) | |
515 | (previous (if (vc-trunk-p target) "" (vc-branch-part target))) | |
516 | (config (current-window-configuration)) | |
517 | (done nil)) | |
518 | (vc-do-command nil 0 "rcs" (vc-name file) (concat "-o" target)) | |
519 | ;; Check out the most recent remaining version. If it fails, because | |
520 | ;; the whole branch got deleted, do a double-take and check out the | |
521 | ;; version where the branch started. | |
522 | (while (not done) | |
523 | (condition-case err | |
524 | (progn | |
525 | (vc-do-command nil 0 "co" (vc-name file) "-f" | |
526 | (concat (if writable "-l" "-u") previous)) | |
527 | (setq done t)) | |
528 | (error (set-buffer "*vc*") | |
529 | (goto-char (point-min)) | |
530 | (if (search-forward "no side branches present for" nil t) | |
531 | (progn (setq previous (vc-branch-part previous)) | |
a7e98271 | 532 | (vc-rcs-set-default-branch file previous) |
099bd78a SM |
533 | ;; vc-do-command popped up a window with |
534 | ;; the error message. Get rid of it, by | |
535 | ;; restoring the old window configuration. | |
536 | (set-window-configuration config)) | |
537 | ;; No, it was some other error: re-signal it. | |
538 | (signal (car err) (cdr err)))))))) | |
d8aff077 GM |
539 | |
540 | (defun vc-rcs-revert (file) | |
541 | "Revert FILE to the version it was based on." | |
542 | (vc-do-command nil 0 "co" (vc-name file) "-f" | |
543 | (concat "-u" (vc-workfile-version file)))) | |
544 | ||
545 | (defun vc-rcs-rename-file (old new) | |
546 | ;; Just move the master file (using vc-rcs-master-templates). | |
547 | (vc-rename-master (vc-name old) new vc-rcs-master-templates)) | |
548 | ||
549 | (defun vc-release-greater-or-equal (r1 r2) | |
33c1b7a1 DL |
550 | "Compare release numbers, represented as strings. |
551 | Release components are assumed cardinal numbers, not decimal fractions | |
552 | \(5.10 is a higher release than 5.9\). Omitted fields are considered | |
553 | lower \(5.6.7 is earlier than 5.6.7.1\). Comparison runs till the end | |
554 | of the string is found, or a non-numeric component shows up \(5.6.7 is | |
d8aff077 GM |
555 | earlier than \"5.6.7 beta\", which is probably not what you want in |
556 | some cases\). This code is suitable for existing RCS release numbers. | |
557 | CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5\)." | |
558 | (let (v1 v2 i1 i2) | |
559 | (catch 'done | |
560 | (or (and (string-match "^\\.?\\([0-9]+\\)" r1) | |
561 | (setq i1 (match-end 0)) | |
562 | (setq v1 (string-to-number (match-string 1 r1))) | |
563 | (or (and (string-match "^\\.?\\([0-9]+\\)" r2) | |
564 | (setq i2 (match-end 0)) | |
565 | (setq v2 (string-to-number (match-string 1 r2))) | |
566 | (if (> v1 v2) (throw 'done t) | |
567 | (if (< v1 v2) (throw 'done nil) | |
568 | (throw 'done | |
569 | (vc-release-greater-or-equal | |
570 | (substring r1 i1) | |
571 | (substring r2 i2))))))) | |
572 | (throw 'done t))) | |
573 | (or (and (string-match "^\\.?\\([0-9]+\\)" r2) | |
574 | (throw 'done nil)) | |
575 | (throw 'done t))))) | |
576 | ||
577 | (defun vc-rcs-release-p (release) | |
33c1b7a1 | 578 | "Return t if we have RELEASE or better." |
d8aff077 GM |
579 | (let ((installation (vc-rcs-system-release))) |
580 | (if (and installation | |
581 | (not (eq installation 'unknown))) | |
582 | (vc-release-greater-or-equal installation release)))) | |
583 | ||
584 | (defun vc-rcs-checkin (file rev comment) | |
585 | "RCS-specific version of `vc-backend-checkin'." | |
d8aff077 GM |
586 | (let ((switches (if (stringp vc-checkin-switches) |
587 | (list vc-checkin-switches) | |
588 | vc-checkin-switches))) | |
a7e98271 AS |
589 | (let ((old-version (vc-workfile-version file)) new-version |
590 | (default-branch (vc-file-getprop file 'vc-rcs-default-branch))) | |
591 | ;; Force branch creation if an appropriate | |
592 | ;; default branch has been set. | |
593 | (and (not rev) | |
594 | default-branch | |
595 | (string-match (concat "^" (regexp-quote old-version) "\\.") | |
596 | default-branch) | |
597 | (setq rev default-branch) | |
598 | (setq switches (cons "-f" switches))) | |
d8aff077 GM |
599 | (apply 'vc-do-command nil 0 "ci" (vc-name file) |
600 | ;; if available, use the secure check-in option | |
601 | (and (vc-rcs-release-p "5.6.4") "-j") | |
602 | (concat (if vc-keep-workfiles "-u" "-r") rev) | |
603 | (concat "-m" comment) | |
604 | switches) | |
605 | (vc-file-setprop file 'vc-workfile-version nil) | |
606 | ||
607 | ;; determine the new workfile version | |
608 | (set-buffer "*vc*") | |
609 | (goto-char (point-min)) | |
610 | (when (or (re-search-forward | |
611 | "new revision: \\([0-9.]+\\);" nil t) | |
612 | (re-search-forward | |
613 | "reverting to previous revision \\([0-9.]+\\)" nil t)) | |
614 | (setq new-version (match-string 1)) | |
615 | (vc-file-setprop file 'vc-workfile-version new-version)) | |
616 | ||
617 | ;; if we got to a different branch, adjust the default | |
618 | ;; branch accordingly | |
619 | (cond | |
620 | ((and old-version new-version | |
621 | (not (string= (vc-rcs-branch-part old-version) | |
622 | (vc-rcs-branch-part new-version)))) | |
a7e98271 AS |
623 | (vc-rcs-set-default-branch file |
624 | (if (vc-rcs-trunk-p new-version) nil | |
625 | (vc-rcs-branch-part new-version))) | |
d8aff077 GM |
626 | ;; If this is an old RCS release, we might have |
627 | ;; to remove a remaining lock. | |
628 | (if (not (vc-rcs-release-p "5.6.2")) | |
629 | ;; exit status of 1 is also accepted. | |
630 | ;; It means that the lock was removed before. | |
631 | (vc-do-command nil 1 "rcs" (vc-name file) | |
632 | (concat "-u" old-version)))))))) | |
633 | ||
634 | (defun vc-rcs-system-release () | |
635 | "Return the RCS release installed on this system, as a string. | |
636 | Return symbol UNKNOWN if the release cannot be deducted. The user can | |
637 | override this using variable `vc-rcs-release'. | |
638 | ||
639 | If the user has not set variable `vc-rcs-release' and it is nil, | |
640 | variable `vc-rcs-release' is set to the returned value." | |
641 | (or vc-rcs-release | |
642 | (setq vc-rcs-release | |
643 | (or (and (zerop (vc-do-command nil nil "rcs" nil "-V")) | |
644 | (with-current-buffer (get-buffer "*vc*") | |
645 | (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1))) | |
646 | 'unknown)))) | |
647 | ||
648 | (defun vc-rcs-diff (file &optional oldvers newvers) | |
649 | "Get a difference report using RCS between two versions of FILE." | |
650 | (if (not oldvers) (setq oldvers (vc-workfile-version file))) | |
651 | ;; If we know that --brief is not supported, don't try it. | |
652 | (let* ((diff-switches-list (if (listp diff-switches) | |
653 | diff-switches | |
654 | (list diff-switches))) | |
655 | (options (append (list "-q" | |
656 | (concat "-r" oldvers) | |
657 | (and newvers (concat "-r" newvers))) | |
658 | diff-switches-list))) | |
659 | (apply 'vc-do-command t 1 "rcsdiff" file options))) | |
660 | ||
661 | (defun vc-rcs-responsible-p (file) | |
662 | "Return non-nil if RCS thinks it would be responsible for registering FILE." | |
663 | ;; TODO: check for all the patterns in vc-rcs-master-templates | |
664 | (file-directory-p (expand-file-name "RCS" (file-name-directory file)))) | |
665 | ||
666 | (defun vc-rcs-register (file &optional rev comment) | |
667 | "Register FILE into the RCS version-control system. | |
668 | REV is the optional revision number for the file. COMMENT can be used | |
669 | to provide an initial description of FILE. | |
670 | ||
671 | `vc-register-switches' and `vc-rcs-register-switches' are passed to | |
672 | the RCS command (in that order). | |
673 | ||
674 | Automatically retrieve a read-only version of the file with keywords | |
675 | expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile." | |
d8aff077 GM |
676 | (let ((subdir (expand-file-name "RCS" (file-name-directory file))) |
677 | (switches (list | |
678 | (if (stringp vc-register-switches) | |
679 | (list vc-register-switches) | |
680 | vc-register-switches) | |
681 | (if (stringp vc-rcs-register-switches) | |
682 | (list vc-rcs-register-switches) | |
683 | vc-rcs-register-switches)))) | |
684 | ||
685 | (and (not (file-exists-p subdir)) | |
686 | (not (directory-files (file-name-directory file) | |
687 | nil ".*,v$" t)) | |
688 | (yes-or-no-p "Create RCS subdirectory? ") | |
689 | (make-directory subdir)) | |
690 | (apply 'vc-do-command nil 0 "ci" file | |
691 | ;; if available, use the secure registering option | |
692 | (and (vc-rcs-release-p "5.6.4") "-i") | |
693 | (concat (if vc-keep-workfiles "-u" "-r") rev) | |
694 | (and comment (concat "-t-" comment)) | |
695 | switches) | |
696 | ;; parse output to find master file name and workfile version | |
697 | (with-current-buffer "*vc*" | |
698 | (goto-char (point-min)) | |
699 | (let ((name (if (looking-at (concat "^\\(.*\\) <-- " | |
700 | (file-name-nondirectory file))) | |
701 | (match-string 1)))) | |
702 | (if (not name) | |
703 | ;; if we couldn't find the master name, | |
704 | ;; run vc-rcs-registered to get it | |
705 | ;; (will be stored into the vc-name property) | |
706 | (vc-rcs-registered file) | |
707 | (vc-file-setprop file 'vc-name | |
708 | (if (file-name-absolute-p name) | |
709 | name | |
33c1b7a1 DL |
710 | (expand-file-name |
711 | name | |
d8aff077 GM |
712 | (file-name-directory file)))))) |
713 | (vc-file-setprop file 'vc-workfile-version | |
33c1b7a1 | 714 | (if (re-search-forward |
d8aff077 GM |
715 | "^initial revision: \\([0-9.]+\\).*\n" |
716 | nil t) | |
717 | (match-string 1)))))) | |
718 | ||
0db2c43c AS |
719 | (defun vc-rcs-unregister (file) |
720 | "Unregister FILE from RCS. | |
721 | If this leaves the RCS subdirectory empty, ask the user | |
722 | whether to remove it." | |
723 | (let* ((master (vc-name file)) | |
7849e179 SM |
724 | (dir (file-name-directory master)) |
725 | (backup-info (find-backup-file-name master))) | |
726 | (if (not backup-info) | |
727 | (delete-file master) | |
728 | (rename-file master (car backup-info) 'ok-if-already-exists) | |
729 | (dolist (f (cdr backup-info)) (ignore-errors (delete-file f)))) | |
0db2c43c AS |
730 | (and (string= (file-name-nondirectory (directory-file-name dir)) "RCS") |
731 | ;; check whether RCS dir is empty, i.e. it does not | |
732 | ;; contain any files except "." and ".." | |
733 | (not (directory-files dir nil | |
734 | "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*")) | |
735 | (yes-or-no-p (format "Directory %s is empty; remove it? " dir)) | |
736 | (delete-directory dir)))) | |
737 | ||
fb0d6a79 | 738 | (defun vc-rcs-receive-file (file rev) |
0db2c43c | 739 | "Implementation of receive-file for RCS." |
fb0d6a79 AS |
740 | (let ((checkout-model (vc-checkout-model file))) |
741 | (vc-rcs-register file rev "") | |
742 | (when (eq checkout-model 'implicit) | |
743 | (vc-rcs-set-non-strict-locking file)) | |
744 | (vc-rcs-set-default-branch file (concat rev ".1")))) | |
0db2c43c AS |
745 | |
746 | (defun vc-rcs-set-non-strict-locking (file) | |
747 | (vc-do-command nil 0 "rcs" file "-U") | |
748 | (vc-file-setprop file 'vc-checkout-model 'implicit) | |
749 | (set-file-modes file (logior (file-modes file) 128))) | |
750 | ||
a7e98271 AS |
751 | (defun vc-rcs-set-default-branch (file branch) |
752 | (vc-do-command nil 0 "rcs" (vc-name file) (concat "-b" branch)) | |
753 | (vc-file-setprop file 'vc-rcs-default-branch branch)) | |
754 | ||
d8aff077 GM |
755 | (defun vc-rcs-checkout (file &optional writable rev workfile) |
756 | "Retrieve a copy of a saved version of FILE into a workfile." | |
757 | (let ((filename (or workfile file)) | |
758 | (file-buffer (get-file-buffer file)) | |
759 | switches) | |
760 | (message "Checking out %s..." filename) | |
761 | (save-excursion | |
762 | ;; Change buffers to get local value of vc-checkout-switches. | |
763 | (if file-buffer (set-buffer file-buffer)) | |
764 | (setq switches (if (stringp vc-checkout-switches) | |
765 | (list vc-checkout-switches) | |
766 | vc-checkout-switches)) | |
767 | ;; Save this buffer's default-directory | |
768 | ;; and use save-excursion to make sure it is restored | |
769 | ;; in the same buffer it was saved in. | |
770 | (let ((default-directory default-directory)) | |
771 | (save-excursion | |
772 | ;; Adjust the default-directory so that the check-out creates | |
773 | ;; the file in the right place. | |
774 | (setq default-directory (file-name-directory filename)) | |
775 | (if workfile ;; RCS | |
776 | ;; RCS can't check out into arbitrary file names directly. | |
777 | ;; Use `co -p' and make stdout point to the correct file. | |
778 | (let ((vc-modes (logior (file-modes (vc-name file)) | |
779 | (if writable 128 0))) | |
780 | (failed t)) | |
781 | (unwind-protect | |
782 | (progn | |
783 | (let ((coding-system-for-read 'no-conversion) | |
784 | (coding-system-for-write 'no-conversion)) | |
785 | (with-temp-file filename | |
786 | (apply 'vc-do-command | |
787 | (current-buffer) 0 "co" (vc-name file) | |
788 | "-q" ;; suppress diagnostic output | |
789 | (if writable "-l") | |
790 | (concat "-p" rev) | |
791 | switches))) | |
33c1b7a1 | 792 | (set-file-modes filename |
d8aff077 GM |
793 | (logior (file-modes (vc-name file)) |
794 | (if writable 128 0))) | |
795 | (setq failed nil)) | |
33c1b7a1 | 796 | (and failed (file-exists-p filename) |
d8aff077 GM |
797 | (delete-file filename)))) |
798 | (let (new-version) | |
799 | ;; if we should go to the head of the trunk, | |
800 | ;; clear the default branch first | |
801 | (and rev (string= rev "") | |
a7e98271 | 802 | (vc-rcs-set-default-branch file nil)) |
d8aff077 GM |
803 | ;; now do the checkout |
804 | (apply 'vc-do-command | |
805 | nil 0 "co" (vc-name file) | |
806 | ;; If locking is not strict, force to overwrite | |
807 | ;; the writable workfile. | |
808 | (if (eq (vc-checkout-model file) 'implicit) "-f") | |
809 | (if writable "-l") | |
810 | (if rev (concat "-r" rev) | |
811 | ;; if no explicit revision was specified, | |
812 | ;; check out that of the working file | |
813 | (let ((workrev (vc-workfile-version file))) | |
814 | (if workrev (concat "-r" workrev) | |
815 | nil))) | |
816 | switches) | |
817 | ;; determine the new workfile version | |
818 | (with-current-buffer "*vc*" | |
819 | (setq new-version | |
820 | (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1))) | |
821 | (vc-file-setprop file 'vc-workfile-version new-version) | |
822 | ;; if necessary, adjust the default branch | |
823 | (and rev (not (string= rev "")) | |
a7e98271 AS |
824 | (vc-rcs-set-default-branch |
825 | file | |
826 | (if (vc-rcs-latest-on-branch-p file new-version) | |
827 | (if (vc-rcs-trunk-p new-version) nil | |
828 | (vc-rcs-branch-part new-version)) | |
829 | new-version)))))) | |
d8aff077 GM |
830 | (message "Checking out %s...done" filename))))) |
831 | ||
832 | (provide 'vc-rcs) | |
833 | ||
834 | ;;; vc-rcs.el ends here |