Commit | Line | Data |
---|---|---|
d8aff077 GM |
1 | ;;; vc-rcs.el --- support for RCS version-control |
2 | ||
f7dd4e98 | 3 | ;; Copyright (C) 1992-2012 Free Software Foundation, Inc. |
d8aff077 GM |
4 | |
5 | ;; Author: FSF (see vc.el for full credits) | |
6 | ;; Maintainer: Andre Spiegel <spiegel@gnu.org> | |
bd78fa1d | 7 | ;; Package: vc |
d8aff077 | 8 | |
d8aff077 GM |
9 | ;; This file is part of GNU Emacs. |
10 | ||
eb3fa2cf | 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
d8aff077 | 12 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
13 | ;; the Free Software Foundation, either version 3 of the License, or |
14 | ;; (at your option) any later version. | |
d8aff077 GM |
15 | |
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
d8aff077 | 23 | |
e8af40ee PJ |
24 | ;;; Commentary: |
25 | ||
26 | ;; See vc.el | |
d8aff077 | 27 | |
ce043df2 | 28 | ;; Some features will not work with ancient RCS versions. Where |
1043ce19 | 29 | ;; appropriate, VC finds out which version you have, and allows or |
ce043df2 GM |
30 | ;; disallows those features. |
31 | ||
1043ce19 DN |
32 | ;; You can support the RCS -x option by customizing vc-rcs-master-templates. |
33 | ||
d8aff077 GM |
34 | ;;; Code: |
35 | ||
8f98485f AS |
36 | ;;; |
37 | ;;; Customization options | |
38 | ;;; | |
39 | ||
0bc58756 | 40 | (eval-when-compile |
a464a6c7 | 41 | (require 'cl-lib) |
10489ed7 | 42 | (require 'vc)) |
0bc58756 | 43 | |
67b0de11 CY |
44 | (defgroup vc-rcs nil |
45 | "VC RCS backend." | |
46 | :version "24.1" | |
47 | :group 'vc) | |
48 | ||
d8aff077 | 49 | (defcustom vc-rcs-release nil |
9201cc28 | 50 | "The release number of your RCS installation, as a string. |
d8aff077 GM |
51 | If nil, VC itself computes this value when it is first needed." |
52 | :type '(choice (const :tag "Auto" nil) | |
53 | (string :tag "Specified") | |
54 | (const :tag "Unknown" unknown)) | |
67b0de11 | 55 | :group 'vc-rcs) |
d8aff077 GM |
56 | |
57 | (defcustom vc-rcs-register-switches nil | |
1e55ee73 GM |
58 | "Switches for registering a file in RCS. |
59 | A string or list of strings passed to the checkin program by | |
60 | \\[vc-register]. If nil, use the value of `vc-register-switches'. | |
61 | If t, use no switches." | |
62 | :type '(choice (const :tag "Unspecified" nil) | |
63 | (const :tag "None" t) | |
d8aff077 | 64 | (string :tag "Argument String") |
1e55ee73 | 65 | (repeat :tag "Argument List" :value ("") string)) |
33c1b7a1 | 66 | :version "21.1" |
67b0de11 | 67 | :group 'vc-rcs) |
d8aff077 | 68 | |
10489ed7 | 69 | (defcustom vc-rcs-diff-switches nil |
69db9cd2 GM |
70 | "String or list of strings specifying switches for RCS diff under VC. |
71 | If nil, use the value of `vc-diff-switches'. If t, use no switches." | |
72 | :type '(choice (const :tag "Unspecified" nil) | |
73 | (const :tag "None" t) | |
10489ed7 | 74 | (string :tag "Argument String") |
69db9cd2 | 75 | (repeat :tag "Argument List" :value ("") string)) |
10489ed7 | 76 | :version "21.1" |
67b0de11 | 77 | :group 'vc-rcs) |
10489ed7 | 78 | |
67141a37 | 79 | (defcustom vc-rcs-header '("\$Id\$") |
9201cc28 | 80 | "Header keywords to be inserted by `vc-insert-headers'." |
f0e7c067 | 81 | :type '(repeat string) |
67141a37 | 82 | :version "24.1" ; no longer consult the obsolete vc-header-alist |
67b0de11 | 83 | :group 'vc-rcs) |
d8aff077 GM |
84 | |
85 | (defcustom vc-rcsdiff-knows-brief nil | |
9201cc28 | 86 | "Indicates whether rcsdiff understands the --brief option. |
d8aff077 GM |
87 | The value is either `yes', `no', or nil. If it is nil, VC tries |
88 | to use --brief and sets this variable to remember whether it worked." | |
89 | :type '(choice (const :tag "Work out" nil) (const yes) (const no)) | |
67b0de11 | 90 | :group 'vc-rcs) |
d8aff077 GM |
91 | |
92 | ;;;###autoload | |
93 | (defcustom vc-rcs-master-templates | |
6bdad9ae | 94 | (purecopy '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s")) |
9201cc28 | 95 | "Where to look for RCS master files. |
d8aff077 GM |
96 | For a description of possible values, see `vc-check-master-templates'." |
97 | :type '(choice (const :tag "Use standard RCS file names" | |
98 | '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s")) | |
99 | (repeat :tag "User-specified" | |
100 | (choice string | |
101 | function))) | |
33c1b7a1 | 102 | :version "21.1" |
67b0de11 | 103 | :group 'vc-rcs) |
d8aff077 | 104 | |
8f98485f | 105 | \f |
8cdd17b4 ER |
106 | ;;; Properties of the backend |
107 | ||
70e2f6c7 ER |
108 | (defun vc-rcs-revision-granularity () 'file) |
109 | ||
110 | (defun vc-rcs-checkout-model (files) | |
111 | "RCS-specific version of `vc-checkout-model'." | |
112 | (let ((file (if (consp files) (car files) files)) | |
113 | result) | |
114 | (when vc-consult-headers | |
115 | (vc-file-setprop file 'vc-checkout-model nil) | |
116 | (vc-rcs-consult-headers file) | |
117 | (setq result (vc-file-getprop file 'vc-checkout-model))) | |
118 | (or result | |
119 | (progn (vc-rcs-fetch-master-state file) | |
120 | (vc-file-getprop file 'vc-checkout-model))))) | |
8cdd17b4 | 121 | |
8f98485f AS |
122 | ;;; |
123 | ;;; State-querying functions | |
124 | ;;; | |
125 | ||
e0607aaa SM |
126 | ;; The autoload cookie below places vc-rcs-registered directly into |
127 | ;; loaddefs.el, so that vc-rcs.el does not need to be loaded for | |
128 | ;; every file that is visited. | |
129 | ;;;###autoload | |
130 | (progn | |
131 | (defun vc-rcs-registered (f) (vc-default-registered 'RCS f))) | |
d8aff077 GM |
132 | |
133 | (defun vc-rcs-state (file) | |
134 | "Implementation of `vc-state' for RCS." | |
15ef1eae | 135 | (if (not (vc-rcs-registered file)) |
3702367b ER |
136 | 'unregistered |
137 | (or (boundp 'vc-rcs-headers-result) | |
138 | (and vc-consult-headers | |
139 | (vc-rcs-consult-headers file))) | |
140 | (let ((state | |
141 | ;; vc-working-revision might not be known; in that case the | |
142 | ;; property is nil. vc-rcs-fetch-master-state knows how to | |
143 | ;; handle that. | |
144 | (vc-rcs-fetch-master-state file | |
145 | (vc-file-getprop file | |
146 | 'vc-working-revision)))) | |
147 | (if (not (eq state 'up-to-date)) | |
148 | state | |
149 | (if (vc-workfile-unchanged-p file) | |
150 | 'up-to-date | |
70e2f6c7 | 151 | (if (eq (vc-rcs-checkout-model (list file)) 'locking) |
3702367b ER |
152 | 'unlocked-changes |
153 | 'edited)))))) | |
d8aff077 GM |
154 | |
155 | (defun vc-rcs-state-heuristic (file) | |
156 | "State heuristic for RCS." | |
157 | (let (vc-rcs-headers-result) | |
158 | (if (and vc-consult-headers | |
33c1b7a1 | 159 | (setq vc-rcs-headers-result |
d8aff077 GM |
160 | (vc-rcs-consult-headers file)) |
161 | (eq vc-rcs-headers-result 'rev-and-lock)) | |
162 | (let ((state (vc-file-getprop file 'vc-state))) | |
163 | ;; If the headers say that the file is not locked, the | |
164 | ;; permissions can tell us whether locking is used for | |
165 | ;; the file or not. | |
166 | (if (and (eq state 'up-to-date) | |
f7ed19a3 SM |
167 | (not (vc-mistrust-permissions file)) |
168 | (file-exists-p file)) | |
d8aff077 GM |
169 | (cond |
170 | ((string-match ".rw..-..-." (nth 8 (file-attributes file))) | |
0db2c43c | 171 | (vc-file-setprop file 'vc-checkout-model 'implicit) |
f1180544 JB |
172 | (setq state |
173 | (if (vc-rcs-workfile-is-newer file) | |
174 | 'edited | |
0db2c43c | 175 | 'up-to-date))) |
d8aff077 GM |
176 | ((string-match ".r-..-..-." (nth 8 (file-attributes file))) |
177 | (vc-file-setprop file 'vc-checkout-model 'locking)))) | |
178 | state) | |
179 | (if (not (vc-mistrust-permissions file)) | |
b010f887 AS |
180 | (let* ((attributes (file-attributes file 'string)) |
181 | (owner-name (nth 2 attributes)) | |
d8aff077 | 182 | (permissions (nth 8 attributes))) |
f7ed19a3 | 183 | (cond ((and permissions (string-match ".r-..-..-." permissions)) |
d8aff077 GM |
184 | (vc-file-setprop file 'vc-checkout-model 'locking) |
185 | 'up-to-date) | |
f7ed19a3 | 186 | ((and permissions (string-match ".rw..-..-." permissions)) |
e0607aaa | 187 | (if (eq (vc-rcs-checkout-model file) 'locking) |
0db2c43c AS |
188 | (if (file-ownership-preserved-p file) |
189 | 'edited | |
b010f887 | 190 | owner-name) |
f1180544 | 191 | (if (vc-rcs-workfile-is-newer file) |
0db2c43c AS |
192 | 'edited |
193 | 'up-to-date))) | |
d8aff077 GM |
194 | (t |
195 | ;; Strange permissions. Fall through to | |
196 | ;; expensive state computation. | |
197 | (vc-rcs-state file)))) | |
198 | (vc-rcs-state file))))) | |
199 | ||
c1b51374 | 200 | (defun vc-rcs-dir-status (dir update-function) |
4b1a01b3 DN |
201 | ;; FIXME: this function should be rewritten or `vc-expand-dirs' |
202 | ;; should be changed to take a backend parameter. Using | |
203 | ;; `vc-expand-dirs' is not TRTD because it returns files from | |
204 | ;; multiple backends. It should also return 'unregistered files. | |
205 | ||
206 | ;; Doing individual vc-state calls is painful but there | |
207 | ;; is no better way in RCS-land. | |
90e9ca17 DN |
208 | (let ((flist (vc-expand-dirs (list dir))) |
209 | (result nil)) | |
210 | (dolist (file flist) | |
211 | (let ((state (vc-state file)) | |
212 | (frel (file-relative-name file))) | |
4b1a01b3 DN |
213 | (when (and (eq (vc-backend file) 'RCS) |
214 | (not (eq state 'up-to-date))) | |
215 | (push (list frel state) result)))) | |
c1b51374 | 216 | (funcall update-function result))) |
90e9ca17 | 217 | |
ac3f4c6f ER |
218 | (defun vc-rcs-working-revision (file) |
219 | "RCS-specific version of `vc-working-revision'." | |
d8aff077 GM |
220 | (or (and vc-consult-headers |
221 | (vc-rcs-consult-headers file) | |
ac3f4c6f | 222 | (vc-file-getprop file 'vc-working-revision)) |
d8aff077 GM |
223 | (progn |
224 | (vc-rcs-fetch-master-state file) | |
ac3f4c6f | 225 | (vc-file-getprop file 'vc-working-revision)))) |
d8aff077 | 226 | |
8f98485f AS |
227 | (defun vc-rcs-latest-on-branch-p (file &optional version) |
228 | "Return non-nil if workfile version of FILE is the latest on its branch. | |
229 | When VERSION is given, perform check for that version." | |
ac3f4c6f | 230 | (unless version (setq version (vc-working-revision file))) |
8f98485f AS |
231 | (with-temp-buffer |
232 | (string= version | |
3b64d86b | 233 | (if (vc-rcs-trunk-p version) |
8f98485f AS |
234 | (progn |
235 | ;; Compare VERSION to the head version number. | |
236 | (vc-insert-file (vc-name file) "^[0-9]") | |
237 | (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1)) | |
238 | ;; If we are not on the trunk, we need to examine the | |
239 | ;; whole current branch. | |
240 | (vc-insert-file (vc-name file) "^desc") | |
7735770b | 241 | (vc-rcs-find-most-recent-rev (vc-branch-part version)))))) |
8f98485f | 242 | |
d8aff077 | 243 | (defun vc-rcs-workfile-unchanged-p (file) |
fa63cb6d | 244 | "RCS-specific implementation of `vc-workfile-unchanged-p'." |
d8aff077 GM |
245 | ;; Try to use rcsdiff --brief. If rcsdiff does not understand that, |
246 | ;; do a double take and remember the fact for the future | |
ac3f4c6f | 247 | (let* ((version (concat "-r" (vc-working-revision file))) |
d8aff077 | 248 | (status (if (eq vc-rcsdiff-knows-brief 'no) |
2888a97e ER |
249 | (vc-do-command "*vc*" 1 "rcsdiff" file version) |
250 | (vc-do-command "*vc*" 2 "rcsdiff" file "--brief" version)))) | |
d8aff077 GM |
251 | (if (eq status 2) |
252 | (if (not vc-rcsdiff-knows-brief) | |
253 | (setq vc-rcsdiff-knows-brief 'no | |
2888a97e | 254 | status (vc-do-command "*vc*" 1 "rcsdiff" file version)) |
d8aff077 GM |
255 | (error "rcsdiff failed")) |
256 | (if (not vc-rcsdiff-knows-brief) (setq vc-rcsdiff-knows-brief 'yes))) | |
257 | ;; The workfile is unchanged if rcsdiff found no differences. | |
258 | (zerop status))) | |
259 | ||
d8aff077 | 260 | \f |
8f98485f AS |
261 | ;;; |
262 | ;;; State-changing functions | |
263 | ;;; | |
d8aff077 | 264 | |
8cdd17b4 ER |
265 | (defun vc-rcs-create-repo () |
266 | "Create a new RCS repository." | |
1e55ee73 | 267 | ;; RCS is totally file-oriented, so all we have to do is make the directory. |
8cdd17b4 ER |
268 | (make-directory "RCS")) |
269 | ||
270 | (defun vc-rcs-register (files &optional rev comment) | |
271 | "Register FILES into the RCS version-control system. | |
272 | REV is the optional revision number for the files. COMMENT can be used | |
273 | to provide an initial description for each FILES. | |
1e55ee73 GM |
274 | Passes either `vc-rcs-register-switches' or `vc-register-switches' |
275 | to the RCS command. | |
d8aff077 GM |
276 | |
277 | Automatically retrieve a read-only version of the file with keywords | |
278 | expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile." | |
09607e62 | 279 | (let (subdir name) |
ac859983 DN |
280 | ;; When REV is specified, we need to force using "-t-". |
281 | (when rev (unless comment (setq comment ""))) | |
8cdd17b4 | 282 | (dolist (file files) |
09607e62 GM |
283 | (and (not (file-exists-p |
284 | (setq subdir (expand-file-name "RCS" | |
285 | (file-name-directory file))))) | |
d8aff077 GM |
286 | (not (directory-files (file-name-directory file) |
287 | nil ".*,v$" t)) | |
288 | (yes-or-no-p "Create RCS subdirectory? ") | |
289 | (make-directory subdir)) | |
2888a97e | 290 | (apply 'vc-do-command "*vc*" 0 "ci" file |
d8aff077 GM |
291 | ;; if available, use the secure registering option |
292 | (and (vc-rcs-release-p "5.6.4") "-i") | |
293 | (concat (if vc-keep-workfiles "-u" "-r") rev) | |
294 | (and comment (concat "-t-" comment)) | |
3e6bab65 | 295 | (vc-switches 'RCS 'register)) |
d8aff077 GM |
296 | ;; parse output to find master file name and workfile version |
297 | (with-current-buffer "*vc*" | |
09607e62 GM |
298 | (goto-char (point-min)) |
299 | (if (not (setq name | |
300 | (if (looking-at (concat "^\\(.*\\) <-- " | |
301 | (file-name-nondirectory file))) | |
302 | (match-string 1)))) | |
303 | ;; if we couldn't find the master name, | |
304 | ;; run vc-rcs-registered to get it | |
305 | ;; (will be stored into the vc-name property) | |
306 | (vc-rcs-registered file) | |
307 | (vc-file-setprop file 'vc-name | |
308 | (if (file-name-absolute-p name) | |
309 | name | |
310 | (expand-file-name | |
311 | name | |
312 | (file-name-directory file)))))) | |
313 | (vc-file-setprop file 'vc-working-revision | |
314 | (if (re-search-forward | |
315 | "^initial revision: \\([0-9.]+\\).*\n" | |
316 | nil t) | |
317 | (match-string 1)))))) | |
d8aff077 | 318 | |
8f98485f AS |
319 | (defun vc-rcs-responsible-p (file) |
320 | "Return non-nil if RCS thinks it would be responsible for registering FILE." | |
321 | ;; TODO: check for all the patterns in vc-rcs-master-templates | |
81ec0c88 TV |
322 | (file-directory-p (expand-file-name "RCS" |
323 | (if (file-directory-p file) | |
324 | file | |
325 | (file-name-directory file))))) | |
8f98485f AS |
326 | |
327 | (defun vc-rcs-receive-file (file rev) | |
328 | "Implementation of receive-file for RCS." | |
70e2f6c7 | 329 | (let ((checkout-model (vc-rcs-checkout-model (list file)))) |
8f98485f AS |
330 | (vc-rcs-register file rev "") |
331 | (when (eq checkout-model 'implicit) | |
332 | (vc-rcs-set-non-strict-locking file)) | |
333 | (vc-rcs-set-default-branch file (concat rev ".1")))) | |
334 | ||
0db2c43c AS |
335 | (defun vc-rcs-unregister (file) |
336 | "Unregister FILE from RCS. | |
337 | If this leaves the RCS subdirectory empty, ask the user | |
338 | whether to remove it." | |
339 | (let* ((master (vc-name file)) | |
7849e179 SM |
340 | (dir (file-name-directory master)) |
341 | (backup-info (find-backup-file-name master))) | |
342 | (if (not backup-info) | |
343 | (delete-file master) | |
344 | (rename-file master (car backup-info) 'ok-if-already-exists) | |
345 | (dolist (f (cdr backup-info)) (ignore-errors (delete-file f)))) | |
0db2c43c AS |
346 | (and (string= (file-name-nondirectory (directory-file-name dir)) "RCS") |
347 | ;; check whether RCS dir is empty, i.e. it does not | |
348 | ;; contain any files except "." and ".." | |
f1180544 | 349 | (not (directory-files dir nil |
0db2c43c AS |
350 | "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*")) |
351 | (yes-or-no-p (format "Directory %s is empty; remove it? " dir)) | |
352 | (delete-directory dir)))) | |
353 | ||
4624de78 | 354 | (defun vc-rcs-checkin (files rev comment) |
8f98485f | 355 | "RCS-specific version of `vc-backend-checkin'." |
3e6bab65 | 356 | (let ((switches (vc-switches 'RCS 'checkin))) |
8cdd17b4 | 357 | ;; Now operate on the files |
c22b0a7d | 358 | (dolist (file (vc-expand-dirs files)) |
ac3f4c6f | 359 | (let ((old-version (vc-working-revision file)) new-version |
8cdd17b4 ER |
360 | (default-branch (vc-file-getprop file 'vc-rcs-default-branch))) |
361 | ;; Force branch creation if an appropriate | |
362 | ;; default branch has been set. | |
363 | (and (not rev) | |
364 | default-branch | |
365 | (string-match (concat "^" (regexp-quote old-version) "\\.") | |
366 | default-branch) | |
367 | (setq rev default-branch) | |
368 | (setq switches (cons "-f" switches))) | |
369 | (if (and (not rev) old-version) | |
370 | (setq rev (vc-branch-part old-version))) | |
2888a97e | 371 | (apply 'vc-do-command "*vc*" 0 "ci" (vc-name file) |
8cdd17b4 ER |
372 | ;; if available, use the secure check-in option |
373 | (and (vc-rcs-release-p "5.6.4") "-j") | |
374 | (concat (if vc-keep-workfiles "-u" "-r") rev) | |
375 | (concat "-m" comment) | |
376 | switches) | |
ac3f4c6f | 377 | (vc-file-setprop file 'vc-working-revision nil) |
8cdd17b4 ER |
378 | |
379 | ;; determine the new workfile version | |
380 | (set-buffer "*vc*") | |
381 | (goto-char (point-min)) | |
382 | (when (or (re-search-forward | |
383 | "new revision: \\([0-9.]+\\);" nil t) | |
384 | (re-search-forward | |
385 | "reverting to previous revision \\([0-9.]+\\)" nil t)) | |
386 | (setq new-version (match-string 1)) | |
ac3f4c6f | 387 | (vc-file-setprop file 'vc-working-revision new-version)) |
8cdd17b4 ER |
388 | |
389 | ;; if we got to a different branch, adjust the default | |
390 | ;; branch accordingly | |
391 | (cond | |
392 | ((and old-version new-version | |
393 | (not (string= (vc-branch-part old-version) | |
394 | (vc-branch-part new-version)))) | |
395 | (vc-rcs-set-default-branch file | |
3b64d86b | 396 | (if (vc-rcs-trunk-p new-version) nil |
8cdd17b4 | 397 | (vc-branch-part new-version))) |
ce043df2 | 398 | ;; If this is an old (pre-1992!) RCS release, we might have |
8cdd17b4 ER |
399 | ;; to remove a remaining lock. |
400 | (if (not (vc-rcs-release-p "5.6.2")) | |
401 | ;; exit status of 1 is also accepted. | |
402 | ;; It means that the lock was removed before. | |
2888a97e | 403 | (vc-do-command "*vc*" 1 "rcs" (vc-name file) |
8cdd17b4 | 404 | (concat "-u" old-version))))))))) |
a7e98271 | 405 | |
ac3f4c6f | 406 | (defun vc-rcs-find-revision (file rev buffer) |
88388365 | 407 | (apply 'vc-do-command |
2888a97e | 408 | (or buffer "*vc*") 0 "co" (vc-name file) |
88388365 SM |
409 | "-q" ;; suppress diagnostic output |
410 | (concat "-p" rev) | |
3e6bab65 | 411 | (vc-switches 'RCS 'checkout))) |
88388365 SM |
412 | |
413 | (defun vc-rcs-checkout (file &optional editable rev) | |
c9f203eb | 414 | "Retrieve a copy of a saved version of FILE. If FILE is a directory, |
c22b0a7d ER |
415 | attempt the checkout for all registered files beneath it." |
416 | (if (file-directory-p file) | |
417 | (mapc 'vc-rcs-checkout (vc-expand-dirs (list file))) | |
418 | (let ((file-buffer (get-file-buffer file)) | |
419 | switches) | |
420 | (message "Checking out %s..." file) | |
421 | (save-excursion | |
422 | ;; Change buffers to get local value of vc-checkout-switches. | |
423 | (if file-buffer (set-buffer file-buffer)) | |
424 | (setq switches (vc-switches 'RCS 'checkout)) | |
425 | ;; Save this buffer's default-directory | |
426 | ;; and use save-excursion to make sure it is restored | |
427 | ;; in the same buffer it was saved in. | |
428 | (let ((default-directory default-directory)) | |
429 | (save-excursion | |
430 | ;; Adjust the default-directory so that the check-out creates | |
431 | ;; the file in the right place. | |
432 | (setq default-directory (file-name-directory file)) | |
433 | (let (new-version) | |
434 | ;; if we should go to the head of the trunk, | |
435 | ;; clear the default branch first | |
436 | (and rev (string= rev "") | |
437 | (vc-rcs-set-default-branch file nil)) | |
438 | ;; now do the checkout | |
439 | (apply 'vc-do-command | |
2888a97e | 440 | "*vc*" 0 "co" (vc-name file) |
c22b0a7d ER |
441 | ;; If locking is not strict, force to overwrite |
442 | ;; the writable workfile. | |
443 | (if (eq (vc-rcs-checkout-model (list file)) 'implicit) "-f") | |
444 | (if editable "-l") | |
445 | (if (stringp rev) | |
446 | ;; a literal revision was specified | |
447 | (concat "-r" rev) | |
448 | (let ((workrev (vc-working-revision file))) | |
449 | (if workrev | |
450 | (concat "-r" | |
451 | (if (not rev) | |
452 | ;; no revision specified: | |
453 | ;; use current workfile version | |
454 | workrev | |
455 | ;; REV is t ... | |
3b64d86b | 456 | (if (not (vc-rcs-trunk-p workrev)) |
c22b0a7d ER |
457 | ;; ... go to head of current branch |
458 | (vc-branch-part workrev) | |
459 | ;; ... go to head of trunk | |
460 | (vc-rcs-set-default-branch file | |
a3294a80 AS |
461 | nil) |
462 | "")))))) | |
88388365 SM |
463 | switches) |
464 | ;; determine the new workfile version | |
465 | (with-current-buffer "*vc*" | |
466 | (setq new-version | |
467 | (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1))) | |
ac3f4c6f | 468 | (vc-file-setprop file 'vc-working-revision new-version) |
88388365 SM |
469 | ;; if necessary, adjust the default branch |
470 | (and rev (not (string= rev "")) | |
3249f234 | 471 | (vc-rcs-set-default-branch |
88388365 SM |
472 | file |
473 | (if (vc-rcs-latest-on-branch-p file new-version) | |
3b64d86b | 474 | (if (vc-rcs-trunk-p new-version) nil |
88388365 SM |
475 | (vc-branch-part new-version)) |
476 | new-version))))) | |
c22b0a7d | 477 | (message "Checking out %s...done" file)))))) |
d8aff077 | 478 | |
8cdd17b4 | 479 | (defun vc-rcs-rollback (files) |
9e4423c5 | 480 | "Roll back, undoing the most recent checkins of FILES. Directories are |
c9f203eb | 481 | expanded to all registered subfiles in them." |
8cdd17b4 | 482 | (if (not files) |
5a0c3f56 | 483 | (error "RCS backend doesn't support directory-level rollback")) |
c22b0a7d | 484 | (dolist (file (vc-expand-dirs files)) |
ac3f4c6f | 485 | (let* ((discard (vc-working-revision file)) |
3b64d86b | 486 | (previous (if (vc-rcs-trunk-p discard) "" (vc-branch-part discard))) |
8cdd17b4 ER |
487 | (config (current-window-configuration)) |
488 | (done nil)) | |
72c70417 | 489 | (if (null (yes-or-no-p (format "Remove version %s from %s history? " |
8cdd17b4 ER |
490 | discard file))) |
491 | (error "Aborted")) | |
492 | (message "Removing revision %s from %s." discard file) | |
2888a97e | 493 | (vc-do-command "*vc*" 0 "rcs" (vc-name file) (concat "-o" discard)) |
8cdd17b4 ER |
494 | ;; Check out the most recent remaining version. If it |
495 | ;; fails, because the whole branch got deleted, do a | |
496 | ;; double-take and check out the version where the branch | |
497 | ;; started. | |
498 | (while (not done) | |
499 | (condition-case err | |
500 | (progn | |
2888a97e | 501 | (vc-do-command "*vc*" 0 "co" (vc-name file) "-f" |
8cdd17b4 ER |
502 | (concat "-u" previous)) |
503 | (setq done t)) | |
504 | (error (set-buffer "*vc*") | |
505 | (goto-char (point-min)) | |
506 | (if (search-forward "no side branches present for" nil t) | |
507 | (progn (setq previous (vc-branch-part previous)) | |
508 | (vc-rcs-set-default-branch file previous) | |
509 | ;; vc-do-command popped up a window with | |
510 | ;; the error message. Get rid of it, by | |
511 | ;; restoring the old window configuration. | |
512 | (set-window-configuration config)) | |
513 | ;; No, it was some other error: re-signal it. | |
514 | (signal (car err) (cdr err))))))))) | |
515 | ||
99739bbf | 516 | (defun vc-rcs-revert (file &optional contents-done) |
9e4423c5 | 517 | "Revert FILE to the version it was based on. If FILE is a directory, |
c22b0a7d ER |
518 | revert all registered files beneath it." |
519 | (if (file-directory-p file) | |
520 | (mapc 'vc-rcs-revert (vc-expand-dirs (list file))) | |
2888a97e | 521 | (vc-do-command "*vc*" 0 "co" (vc-name file) "-f" |
c22b0a7d ER |
522 | (concat (if (eq (vc-state file) 'edited) "-u" "-r") |
523 | (vc-working-revision file))))) | |
8f98485f | 524 | |
8f98485f AS |
525 | (defun vc-rcs-merge (file first-version &optional second-version) |
526 | "Merge changes into current working copy of FILE. | |
527 | The changes are between FIRST-VERSION and SECOND-VERSION." | |
2888a97e | 528 | (vc-do-command "*vc*" 1 "rcsmerge" (vc-name file) |
8f98485f AS |
529 | "-kk" ; ignore keyword conflicts |
530 | (concat "-r" first-version) | |
531 | (if second-version (concat "-r" second-version)))) | |
532 | ||
533 | (defun vc-rcs-steal-lock (file &optional rev) | |
534 | "Steal the lock on the current workfile for FILE and revision REV. | |
c9f203eb | 535 | If FILE is a directory, steal the lock on all registered files beneath it. |
8f98485f | 536 | Needs RCS 5.6.2 or later for -M." |
c22b0a7d ER |
537 | (if (file-directory-p file) |
538 | (mapc 'vc-rcs-steal-lock (vc-expand-dirs (list file))) | |
2888a97e | 539 | (vc-do-command "*vc*" 0 "rcs" (vc-name file) "-M" (concat "-u" rev)) |
c22b0a7d ER |
540 | ;; Do a real checkout after stealing the lock, so that we see |
541 | ;; expanded headers. | |
2888a97e | 542 | (vc-do-command "*vc*" 0 "co" (vc-name file) "-f" (concat "-l" rev)))) |
8f98485f | 543 | |
9b64a7f0 | 544 | (defun vc-rcs-modify-change-comment (files rev comment) |
c22b0a7d ER |
545 | "Modify the change comments change on FILES on a specified REV. If FILE is a |
546 | directory the operation is applied to all registered files beneath it." | |
547 | (dolist (file (vc-expand-dirs files)) | |
2888a97e | 548 | (vc-do-command "*vc*" 0 "rcs" (vc-name file) |
031f1766 | 549 | (concat "-m" rev ":" comment)))) |
8f98485f AS |
550 | |
551 | \f | |
552 | ;;; | |
553 | ;;; History functions | |
554 | ;;; | |
555 | ||
db167d28 DN |
556 | (defun vc-rcs-print-log-cleanup () |
557 | (let ((inhibit-read-only t)) | |
558 | (goto-char (point-max)) | |
559 | (forward-line -1) | |
560 | (while (looking-at "=*\n") | |
561 | (delete-char (- (match-end 0) (match-beginning 0))) | |
562 | (forward-line -1)) | |
563 | (goto-char (point-min)) | |
564 | (when (looking-at "[\b\t\n\v\f\r ]+") | |
565 | (delete-char (- (match-end 0) (match-beginning 0)))))) | |
566 | ||
662c5698 | 567 | (defun vc-rcs-print-log (files buffer &optional shortlog start-revision-ignored limit) |
c22b0a7d ER |
568 | "Get change log associated with FILE. If FILE is a |
569 | directory the operation is applied to all registered files beneath it." | |
db167d28 DN |
570 | (vc-do-command (or buffer "*vc*") 0 "rlog" (mapcar 'vc-name (vc-expand-dirs files))) |
571 | (with-current-buffer (or buffer "*vc*") | |
48b27575 DN |
572 | (vc-rcs-print-log-cleanup)) |
573 | (when limit 'limit-unsupported)) | |
8f98485f | 574 | |
8cdd17b4 ER |
575 | (defun vc-rcs-diff (files &optional oldvers newvers buffer) |
576 | "Get a difference report using RCS between two sets of files." | |
72c70417 | 577 | (apply 'vc-do-command (or buffer "*vc-diff*") |
8cdd17b4 ER |
578 | 1 ;; Always go synchronous, the repo is local |
579 | "rcsdiff" (vc-expand-dirs files) | |
10489ed7 | 580 | (append (list "-q" |
8cdd17b4 | 581 | (and oldvers (concat "-r" oldvers)) |
10489ed7 | 582 | (and newvers (concat "-r" newvers))) |
3e6bab65 | 583 | (vc-switches 'RCS 'diff)))) |
8f98485f | 584 | |
6aa5d910 ER |
585 | (defun vc-rcs-comment-history (file) |
586 | "Return a string with all log entries stored in BACKEND for FILE." | |
587 | (with-current-buffer "*vc*" | |
588 | ;; Has to be written this way, this function is used by the CVS backend too | |
589 | (vc-call-backend (vc-backend file) 'print-log (list file)) | |
590 | ;; Remove cruft | |
591 | (let ((separator (concat "^-+\nrevision [0-9.]+\ndate: .*\n" | |
592 | "\\(branches: .*;\n\\)?" | |
593 | "\\(\\*\\*\\* empty log message \\*\\*\\*\n\\)?"))) | |
594 | (goto-char (point-max)) (forward-line -1) | |
595 | (while (looking-at "=*\n") | |
596 | (delete-char (- (match-end 0) (match-beginning 0))) | |
597 | (forward-line -1)) | |
598 | (goto-char (point-min)) | |
599 | (if (looking-at "[\b\t\n\v\f\r ]+") | |
600 | (delete-char (- (match-end 0) (match-beginning 0)))) | |
601 | (goto-char (point-min)) | |
602 | (re-search-forward separator nil t) | |
603 | (delete-region (point-min) (point)) | |
604 | (while (re-search-forward separator nil t) | |
605 | (delete-region (match-beginning 0) (match-end 0)))) | |
606 | ;; Return the de-crufted comment list | |
607 | (buffer-string))) | |
8cdd17b4 | 608 | |
3249f234 TTN |
609 | (defun vc-rcs-annotate-command (file buffer &optional revision) |
610 | "Annotate FILE, inserting the results in BUFFER. | |
611 | Optional arg REVISION is a revision to annotate from." | |
903d71fb | 612 | (vc-setup-buffer buffer) |
3249f234 TTN |
613 | ;; Aside from the "head revision on the trunk", the instructions for |
614 | ;; each revision on the trunk are an ordered list of kill and insert | |
615 | ;; commands necessary to go from the chronologically-following | |
616 | ;; revision to this one. That is, associated with revision N are | |
617 | ;; edits that applied to revision N+1 would result in revision N. | |
618 | ;; | |
619 | ;; On a branch, however, (some) things are inverted: the commands | |
620 | ;; listed are those necessary to go from the chronologically-preceding | |
621 | ;; revision to this one. That is, associated with revision N are | |
622 | ;; edits that applied to revision N-1 would result in revision N. | |
623 | ;; | |
624 | ;; So, to get per-line history info, we apply reverse-chronological | |
625 | ;; edits, starting with the head revision on the trunk, all the way | |
626 | ;; back through the initial revision (typically "1.1" or similar), | |
627 | ;; then apply forward-chronological edits -- keeping track of which | |
628 | ;; revision is associated with each inserted line -- until we reach | |
629 | ;; the desired revision for display (which may be either on the trunk | |
630 | ;; or on a branch). | |
631 | (let* ((tree (with-temp-buffer | |
632 | (insert-file-contents (vc-rcs-registered file)) | |
633 | (vc-rcs-parse))) | |
634 | (revisions (cdr (assq 'revisions tree))) | |
635 | ;; The revision N whose instructions we currently are processing. | |
636 | (cur (cdr (assq 'head (cdr (assq 'headers tree))))) | |
637 | ;; Alist from the parse tree for N. | |
638 | (meta (cdr (assoc cur revisions))) | |
639 | ;; Point and temporary string, respectively. | |
640 | p s | |
641 | ;; "Next-branch list". Nil means the desired revision to | |
642 | ;; display lives on the trunk. Non-nil means it lives on a | |
643 | ;; branch, in which case the value is a list of revision pairs | |
644 | ;; (PARENT . CHILD), the first PARENT being on the trunk, that | |
645 | ;; links each series of revisions in the path from the initial | |
646 | ;; revision to the desired revision to display. | |
647 | nbls | |
648 | ;; "Path-accumulate-predicate plus revision/date/author". | |
649 | ;; Until set, forward-chronological edits are not accumulated. | |
650 | ;; Once set, its value (updated every revision) is used for | |
651 | ;; the text property `:vc-rcs-r/d/a' for inserts during | |
652 | ;; processing of forward-chronological instructions for N. | |
653 | ;; See internal func `r/d/a'. | |
654 | prda | |
655 | ;; List of forward-chronological instructions, each of the | |
656 | ;; form: (POS . ACTION), where POS is a buffer position. If | |
657 | ;; ACTION is a string, it is inserted, otherwise it is taken as | |
658 | ;; the number of characters to be deleted. | |
659 | path | |
660 | ;; N+1. When `cur' is "", this is the initial revision. | |
661 | pre) | |
662 | (unless revision | |
663 | (setq revision cur)) | |
664 | (unless (assoc revision revisions) | |
665 | (error "No such revision: %s" revision)) | |
666 | ;; Find which branches (if any) must be included in the edits. | |
667 | (let ((par revision) | |
668 | bpt kids) | |
669 | (while (setq bpt (vc-branch-part par) | |
670 | par (vc-branch-part bpt)) | |
671 | (setq kids (cdr (assq 'branches (cdr (assoc par revisions))))) | |
672 | ;; A branchpoint may have multiple children. Find the right one. | |
673 | (while (not (string= bpt (vc-branch-part (car kids)))) | |
674 | (setq kids (cdr kids))) | |
675 | (push (cons par (car kids)) nbls))) | |
676 | ;; Start with the full text. | |
677 | (set-buffer buffer) | |
678 | (insert (cdr (assq 'text meta))) | |
679 | ;; Apply reverse-chronological edits on the trunk, computing and | |
680 | ;; accumulating forward-chronological edits after some point, for | |
681 | ;; later. | |
d5c6faf9 SM |
682 | (cl-flet ((r/d/a () (vector pre |
683 | (cdr (assq 'date meta)) | |
684 | (cdr (assq 'author meta))))) | |
3249f234 TTN |
685 | (while (when (setq pre cur cur (cdr (assq 'next meta))) |
686 | (not (string= "" cur))) | |
687 | (setq | |
688 | ;; Start accumulating the forward-chronological edits when N+1 | |
689 | ;; on the trunk is either the desired revision to display, or | |
690 | ;; the appropriate branchpoint for it. Do this before | |
691 | ;; updating `meta' since `r/d/a' uses N+1's `meta' value. | |
692 | prda (when (or prda (string= (if nbls (caar nbls) revision) pre)) | |
693 | (r/d/a)) | |
694 | meta (cdr (assoc cur revisions))) | |
695 | ;; Edits in the parse tree specify a line number (in the buffer | |
696 | ;; *BEFORE* editing occurs) to start from, but line numbers | |
697 | ;; change as a result of edits. To DTRT, we apply edits in | |
698 | ;; order of descending buffer position so that edits further | |
699 | ;; down in the buffer occur first w/o corrupting specified | |
700 | ;; buffer positions of edits occurring towards the beginning of | |
701 | ;; the buffer. In this way we avoid using markers. A pleasant | |
702 | ;; property of this approach is ability to push instructions | |
703 | ;; onto `path' directly, w/o need to maintain rev boundaries. | |
704 | (dolist (insn (cdr (assq :insn meta))) | |
f76a9756 GM |
705 | (goto-char (point-min)) |
706 | (forward-line (1- (pop insn))) | |
3249f234 | 707 | (setq p (point)) |
a464a6c7 SM |
708 | (pcase (pop insn) |
709 | (`k (setq s (buffer-substring-no-properties | |
710 | p (progn (forward-line (car insn)) | |
711 | (point)))) | |
712 | (when prda | |
713 | (push `(,p . ,(propertize s :vc-rcs-r/d/a prda)) path)) | |
714 | (delete-region p (point))) | |
715 | (`i (setq s (car insn)) | |
716 | (when prda | |
717 | (push `(,p . ,(length s)) path)) | |
718 | (insert s))))) | |
3249f234 TTN |
719 | ;; For the initial revision, setting `:vc-rcs-r/d/a' directly is |
720 | ;; equivalent to pushing an insert instruction (of the entire buffer | |
721 | ;; contents) onto `path' then erasing the buffer, but less wasteful. | |
722 | (put-text-property (point-min) (point-max) :vc-rcs-r/d/a (r/d/a)) | |
723 | ;; Now apply the forward-chronological edits for the trunk. | |
724 | (dolist (insn path) | |
725 | (goto-char (pop insn)) | |
726 | (if (stringp insn) | |
727 | (insert insn) | |
728 | (delete-char insn))) | |
729 | ;; Now apply the forward-chronological edits (directly from the | |
730 | ;; parse-tree) for the branch(es), if necessary. We re-use vars | |
731 | ;; `pre' and `meta' for the sake of internal func `r/d/a'. | |
732 | (while nbls | |
733 | (setq pre (cdr (pop nbls))) | |
734 | (while (progn | |
735 | (setq meta (cdr (assoc pre revisions)) | |
736 | prda nil) | |
737 | (dolist (insn (cdr (assq :insn meta))) | |
f76a9756 GM |
738 | (goto-char (point-min)) |
739 | (forward-line (1- (pop insn))) | |
a464a6c7 SM |
740 | (pcase (pop insn) |
741 | (`k (delete-region | |
742 | (point) (progn (forward-line (car insn)) | |
743 | (point)))) | |
744 | (`i (insert (propertize | |
745 | (car insn) | |
746 | :vc-rcs-r/d/a | |
747 | (or prda (setq prda (r/d/a)))))))) | |
3249f234 TTN |
748 | (prog1 (not (string= (if nbls (caar nbls) revision) pre)) |
749 | (setq pre (cdr (assq 'next meta))))))))) | |
750 | ;; Lastly, for each line, insert at bol nicely-formatted history info. | |
751 | ;; We do two passes to collect summary information used to minimize | |
752 | ;; the annotation's usage of screen real-estate: (1) Consider rendered | |
753 | ;; width of revision plus author together as a unit; and (2) Omit | |
754 | ;; author entirely if all authors are the same as the user. | |
755 | (let ((ht (make-hash-table :test 'eq)) | |
756 | (me (user-login-name)) | |
757 | (maxw 0) | |
758 | (all-me t) | |
759 | rda w a) | |
760 | (goto-char (point-max)) | |
761 | (while (not (bobp)) | |
762 | (forward-line -1) | |
763 | (setq rda (get-text-property (point) :vc-rcs-r/d/a)) | |
764 | (unless (gethash rda ht) | |
765 | (setq a (aref rda 2) | |
766 | all-me (and all-me (string= a me))) | |
767 | (puthash rda (setq w (+ (length (aref rda 0)) | |
768 | (length a))) | |
769 | ht) | |
770 | (setq maxw (max w maxw)))) | |
771 | (let ((padding (make-string maxw 32))) | |
d5c6faf9 SM |
772 | (cl-flet ((pad (w) (substring-no-properties padding w)) |
773 | (render (rda &rest ls) | |
774 | (propertize | |
775 | (apply 'concat | |
776 | (format-time-string "%Y-%m-%d" (aref rda 1)) | |
777 | " " | |
778 | (aref rda 0) | |
779 | ls) | |
780 | :vc-annotate-prefix t | |
781 | :vc-rcs-r/d/a rda))) | |
3249f234 TTN |
782 | (maphash |
783 | (if all-me | |
784 | (lambda (rda w) | |
785 | (puthash rda (render rda (pad w) ": ") ht)) | |
786 | (lambda (rda w) | |
787 | (puthash rda (render rda " " (pad w) " " (aref rda 2) ": ") ht))) | |
788 | ht))) | |
789 | (while (not (eobp)) | |
790 | (insert (gethash (get-text-property (point) :vc-rcs-r/d/a) ht)) | |
791 | (forward-line 1)))) | |
792 | ||
f8bd9ac6 DN |
793 | (declare-function vc-annotate-convert-time "vc-annotate" (time)) |
794 | ||
3249f234 TTN |
795 | (defun vc-rcs-annotate-current-time () |
796 | "Return the current time, based at midnight of the current day, and | |
797 | encoded as fractional days." | |
798 | (vc-annotate-convert-time | |
799 | (apply 'encode-time 0 0 0 (nthcdr 3 (decode-time (current-time)))))) | |
800 | ||
801 | (defun vc-rcs-annotate-time () | |
802 | "Return the time of the next annotation (as fraction of days) | |
803 | systime, or nil if there is none. Also, reposition point." | |
804 | (unless (eobp) | |
53cc5b9c TTN |
805 | (prog1 (vc-annotate-convert-time |
806 | (aref (get-text-property (point) :vc-rcs-r/d/a) 1)) | |
807 | (goto-char (next-single-property-change (point) :vc-annotate-prefix))))) | |
3249f234 TTN |
808 | |
809 | (defun vc-rcs-annotate-extract-revision-at-line () | |
810 | (aref (get-text-property (point) :vc-rcs-r/d/a) 0)) | |
811 | ||
8f98485f AS |
812 | \f |
813 | ;;; | |
370fded4 | 814 | ;;; Tag system |
8f98485f AS |
815 | ;;; |
816 | ||
70df4bbe | 817 | (defun vc-rcs-create-tag (dir name branchp) |
370fded4 | 818 | (when branchp |
70df4bbe | 819 | (error "RCS backend does not support module branches")) |
370fded4 ER |
820 | (let ((result (vc-tag-precondition dir))) |
821 | (if (stringp result) | |
822 | (error "File %s is not up-to-date" result) | |
823 | (vc-file-tree-walk | |
824 | dir | |
825 | (lambda (f) | |
826 | (vc-do-command "*vc*" 0 "rcs" (vc-name f) (concat "-n" name ":"))))))) | |
8f98485f AS |
827 | |
828 | \f | |
829 | ;;; | |
830 | ;;; Miscellaneous | |
831 | ;;; | |
832 | ||
3b64d86b DN |
833 | (defun vc-rcs-trunk-p (rev) |
834 | "Return t if REV is a revision on the trunk." | |
835 | (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev)))) | |
836 | ||
837 | (defun vc-rcs-minor-part (rev) | |
838 | "Return the minor revision number of a revision number REV." | |
839 | (string-match "[0-9]+\\'" rev) | |
840 | (substring rev (match-beginning 0) (match-end 0))) | |
841 | ||
842 | (defun vc-rcs-previous-revision (file rev) | |
843 | "Return the revision number immediately preceding REV for FILE, | |
844 | or nil if there is no previous revision. This default | |
845 | implementation works for MAJOR.MINOR-style revision numbers as | |
846 | used by RCS and CVS." | |
847 | (let ((branch (vc-branch-part rev)) | |
848 | (minor-num (string-to-number (vc-rcs-minor-part rev)))) | |
849 | (when branch | |
850 | (if (> minor-num 1) | |
851 | ;; revision does probably not start a branch or release | |
852 | (concat branch "." (number-to-string (1- minor-num))) | |
853 | (if (vc-rcs-trunk-p rev) | |
854 | ;; we are at the beginning of the trunk -- | |
855 | ;; don't know anything to return here | |
856 | nil | |
857 | ;; we are at the beginning of a branch -- | |
858 | ;; return revision of starting point | |
859 | (vc-branch-part branch)))))) | |
860 | ||
861 | (defun vc-rcs-next-revision (file rev) | |
862 | "Return the revision number immediately following REV for FILE, | |
863 | or nil if there is no next revision. This default implementation | |
864 | works for MAJOR.MINOR-style revision numbers as used by RCS | |
865 | and CVS." | |
866 | (when (not (string= rev (vc-working-revision file))) | |
867 | (let ((branch (vc-branch-part rev)) | |
868 | (minor-num (string-to-number (vc-rcs-minor-part rev)))) | |
869 | (concat branch "." (number-to-string (1+ minor-num)))))) | |
870 | ||
f7dd4e98 GM |
871 | ;; Note that most GNU/Linux distributions seem to supply rcs2log in a |
872 | ;; standard bin directory. Eg both Red Hat and Debian include it in | |
873 | ;; their cvs packages. It's not obvious why Emacs still needs to | |
874 | ;; provide it as well... | |
875 | (defvar vc-rcs-rcs2log-program | |
876 | (let (exe) | |
877 | (cond ((file-executable-p | |
878 | (setq exe (expand-file-name "rcs2log" exec-directory))) | |
879 | exe) | |
880 | ;; In the unlikely event that someone is running an | |
881 | ;; uninstalled Emacs and wants to do something RCS-related. | |
882 | ((file-executable-p | |
883 | (setq exe (expand-file-name "lib-src/rcs2log" source-directory))) | |
884 | exe) | |
885 | (t "rcs2log"))) | |
886 | "Path to the `rcs2log' program (normally in `exec-directory').") | |
887 | ||
3b64d86b DN |
888 | (defun vc-rcs-update-changelog (files) |
889 | "Default implementation of update-changelog. | |
890 | Uses `rcs2log' which only works for RCS and CVS." | |
891 | ;; FIXME: We (c|sh)ould add support for cvs2cl | |
892 | (let ((odefault default-directory) | |
893 | (changelog (find-change-log)) | |
894 | ;; Presumably not portable to non-Unixy systems, along with rcs2log: | |
895 | (tempfile (make-temp-file | |
896 | (expand-file-name "vc" | |
897 | (or small-temporary-file-directory | |
898 | temporary-file-directory)))) | |
899 | (login-name (or user-login-name | |
900 | (format "uid%d" (number-to-string (user-uid))))) | |
901 | (full-name (or add-log-full-name | |
902 | (user-full-name) | |
903 | (user-login-name) | |
904 | (format "uid%d" (number-to-string (user-uid))))) | |
905 | (mailing-address (or add-log-mailing-address | |
906 | user-mail-address))) | |
907 | (find-file-other-window changelog) | |
908 | (barf-if-buffer-read-only) | |
909 | (vc-buffer-sync) | |
910 | (undo-boundary) | |
911 | (goto-char (point-min)) | |
912 | (push-mark) | |
913 | (message "Computing change log entries...") | |
914 | (message "Computing change log entries... %s" | |
915 | (unwind-protect | |
916 | (progn | |
917 | (setq default-directory odefault) | |
f7dd4e98 | 918 | (if (eq 0 (apply 'call-process vc-rcs-rcs2log-program |
3b64d86b DN |
919 | nil (list t tempfile) nil |
920 | "-c" changelog | |
921 | "-u" (concat login-name | |
922 | "\t" full-name | |
923 | "\t" mailing-address) | |
924 | (mapcar | |
925 | (lambda (f) | |
926 | (file-relative-name | |
927 | (expand-file-name f odefault))) | |
928 | files))) | |
929 | "done" | |
930 | (pop-to-buffer (get-buffer-create "*vc*")) | |
931 | (erase-buffer) | |
932 | (insert-file-contents tempfile) | |
933 | "failed")) | |
934 | (setq default-directory (file-name-directory changelog)) | |
935 | (delete-file tempfile))))) | |
936 | ||
8f98485f AS |
937 | (defun vc-rcs-check-headers () |
938 | "Check if the current file has any headers in it." | |
939 | (save-excursion | |
940 | (goto-char (point-min)) | |
941 | (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\ | |
942 | \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t))) | |
943 | ||
944 | (defun vc-rcs-clear-headers () | |
945 | "Implementation of vc-clear-headers for RCS." | |
946 | (let ((case-fold-search nil)) | |
947 | (goto-char (point-min)) | |
948 | (while (re-search-forward | |
949 | (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|" | |
950 | "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$") | |
951 | nil t) | |
952 | (replace-match "$\\1$")))) | |
953 | ||
954 | (defun vc-rcs-rename-file (old new) | |
955 | ;; Just move the master file (using vc-rcs-master-templates). | |
956 | (vc-rename-master (vc-name old) new vc-rcs-master-templates)) | |
957 | ||
77bf3f54 DN |
958 | (defun vc-rcs-find-file-hook () |
959 | ;; If the file is locked by some other user, make | |
960 | ;; the buffer read-only. Like this, even root | |
961 | ;; cannot modify a file that someone else has locked. | |
d56fdcd2 DN |
962 | (and (stringp (vc-state buffer-file-name 'RCS)) |
963 | (setq buffer-read-only t))) | |
77bf3f54 | 964 | |
8f98485f AS |
965 | \f |
966 | ;;; | |
967 | ;;; Internal functions | |
968 | ;;; | |
969 | ||
8f98485f AS |
970 | (defun vc-rcs-workfile-is-newer (file) |
971 | "Return non-nil if FILE is newer than its RCS master. | |
972 | This likely means that FILE has been changed with respect | |
973 | to its master version." | |
974 | (let ((file-time (nth 5 (file-attributes file))) | |
975 | (master-time (nth 5 (file-attributes (vc-name file))))) | |
976 | (or (> (nth 0 file-time) (nth 0 master-time)) | |
977 | (and (= (nth 0 file-time) (nth 0 master-time)) | |
978 | (> (nth 1 file-time) (nth 1 master-time)))))) | |
979 | ||
980 | (defun vc-rcs-find-most-recent-rev (branch) | |
981 | "Find most recent revision on BRANCH." | |
982 | (goto-char (point-min)) | |
983 | (let ((latest-rev -1) value) | |
984 | (while (re-search-forward (concat "^\\(" (regexp-quote branch) | |
985 | "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;") | |
986 | nil t) | |
987 | (let ((rev (string-to-number (match-string 2)))) | |
988 | (when (< latest-rev rev) | |
989 | (setq latest-rev rev) | |
990 | (setq value (match-string 1))))) | |
991 | (or value | |
7735770b | 992 | (vc-branch-part branch)))) |
8f98485f | 993 | |
ac3f4c6f | 994 | (defun vc-rcs-fetch-master-state (file &optional working-revision) |
8f98485f | 995 | "Compute the master file's idea of the state of FILE. |
c9f203eb | 996 | If a WORKING-REVISION is given, compute the state of that version, |
8f98485f | 997 | otherwise determine the workfile version based on the master file. |
ac3f4c6f | 998 | This function sets the properties `vc-working-revision' and |
8f98485f AS |
999 | `vc-checkout-model' to their correct values, based on the master |
1000 | file." | |
1001 | (with-temp-buffer | |
ea28aa35 AS |
1002 | (if (or (not (vc-insert-file (vc-name file) "^[0-9]")) |
1003 | (progn (goto-char (point-min)) | |
1004 | (not (looking-at "^head[ \t\n]+[^;]+;$")))) | |
1005 | (error "File %s is not an RCS master file" (vc-name file))) | |
8f98485f AS |
1006 | (let ((workfile-is-latest nil) |
1007 | (default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1))) | |
1008 | (vc-file-setprop file 'vc-rcs-default-branch default-branch) | |
ac3f4c6f | 1009 | (unless working-revision |
8f98485f AS |
1010 | ;; Workfile version not known yet. Determine that first. It |
1011 | ;; is either the head of the trunk, the head of the default | |
1012 | ;; branch, or the "default branch" itself, if that is a full | |
1013 | ;; revision number. | |
1014 | (cond | |
1015 | ;; no default branch | |
1016 | ((or (not default-branch) (string= "" default-branch)) | |
ac3f4c6f | 1017 | (setq working-revision |
8f98485f AS |
1018 | (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1)) |
1019 | (setq workfile-is-latest t)) | |
1020 | ;; default branch is actually a revision | |
1021 | ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$" | |
1022 | default-branch) | |
ac3f4c6f | 1023 | (setq working-revision default-branch)) |
8f98485f AS |
1024 | ;; else, search for the head of the default branch |
1025 | (t (vc-insert-file (vc-name file) "^desc") | |
ac3f4c6f | 1026 | (setq working-revision |
8f98485f AS |
1027 | (vc-rcs-find-most-recent-rev default-branch)) |
1028 | (setq workfile-is-latest t))) | |
ac3f4c6f | 1029 | (vc-file-setprop file 'vc-working-revision working-revision)) |
8f98485f AS |
1030 | ;; Check strict locking |
1031 | (goto-char (point-min)) | |
1032 | (vc-file-setprop file 'vc-checkout-model | |
1033 | (if (re-search-forward ";[ \t\n]*strict;" nil t) | |
1034 | 'locking 'implicit)) | |
1035 | ;; Compute state of workfile version | |
1036 | (goto-char (point-min)) | |
1037 | (let ((locking-user | |
1038 | (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):" | |
ac3f4c6f | 1039 | (regexp-quote working-revision) |
8f98485f AS |
1040 | "[^0-9.]") |
1041 | 1))) | |
1042 | (cond | |
1043 | ;; not locked | |
1044 | ((not locking-user) | |
1045 | (if (or workfile-is-latest | |
ac3f4c6f | 1046 | (vc-rcs-latest-on-branch-p file working-revision)) |
8f98485f | 1047 | ;; workfile version is latest on branch |
036f45fa | 1048 | 'up-to-date |
8f98485f | 1049 | ;; workfile version is not latest on branch |
3702367b | 1050 | 'needs-update)) |
8f98485f AS |
1051 | ;; locked by the calling user |
1052 | ((and (stringp locking-user) | |
4f147528 | 1053 | (string= locking-user (vc-user-login-name file))) |
11a36f64 SM |
1054 | ;; Don't call `vc-rcs-checkout-model' to avoid inf-looping. |
1055 | (if (or (eq (vc-file-getprop file 'vc-checkout-model) 'locking) | |
8f98485f | 1056 | workfile-is-latest |
ac3f4c6f | 1057 | (vc-rcs-latest-on-branch-p file working-revision)) |
8f98485f AS |
1058 | 'edited |
1059 | ;; Locking is not used for the file, but the owner does | |
1060 | ;; have a lock, and there is a higher version on the current | |
1061 | ;; branch. Not sure if this can occur, and if it is right | |
1062 | ;; to use `needs-merge' in this case. | |
1063 | 'needs-merge)) | |
1064 | ;; locked by somebody else | |
1065 | ((stringp locking-user) | |
1066 | locking-user) | |
1067 | (t | |
1068 | (error "Error getting state of RCS file"))))))) | |
1069 | ||
1070 | (defun vc-rcs-consult-headers (file) | |
1071 | "Search for RCS headers in FILE, and set properties accordingly. | |
1072 | ||
1073 | Returns: nil if no headers were found | |
1074 | 'rev if a workfile revision was found | |
1075 | 'rev-and-lock if revision and lock info was found" | |
1076 | (cond | |
1077 | ((not (get-file-buffer file)) nil) | |
1078 | ((let (status version locking-user) | |
7fdbcd83 | 1079 | (with-current-buffer (get-file-buffer file) |
68d87786 SM |
1080 | (save-excursion |
1081 | (goto-char (point-min)) | |
7fdbcd83 | 1082 | (cond |
68d87786 SM |
1083 | ;; search for $Id or $Header |
1084 | ;; ------------------------- | |
1085 | ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file. | |
1086 | ((or (and (search-forward "$Id\ : " nil t) | |
1087 | (looking-at "[^ ]+ \\([0-9.]+\\) ")) | |
1088 | (and (progn (goto-char (point-min)) | |
1089 | (search-forward "$Header\ : " nil t)) | |
1090 | (looking-at "[^ ]+ \\([0-9.]+\\) "))) | |
1091 | (goto-char (match-end 0)) | |
1092 | ;; if found, store the revision number ... | |
1093 | (setq version (match-string-no-properties 1)) | |
1094 | ;; ... and check for the locking state | |
7fdbcd83 | 1095 | (cond |
68d87786 SM |
1096 | ((looking-at |
1097 | (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date | |
1098 | "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time | |
1099 | "[^ ]+ [^ ]+ ")) ; author & state | |
1100 | (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds | |
1101 | (cond | |
1102 | ;; unlocked revision | |
1103 | ((looking-at "\\$") | |
1104 | (setq locking-user 'none) | |
1105 | (setq status 'rev-and-lock)) | |
1106 | ;; revision is locked by some user | |
1107 | ((looking-at "\\([^ ]+\\) \\$") | |
1108 | (setq locking-user (match-string-no-properties 1)) | |
1109 | (setq status 'rev-and-lock)) | |
1110 | ;; everything else: false | |
1111 | (nil))) | |
1112 | ;; unexpected information in | |
1113 | ;; keyword string --> quit | |
7fdbcd83 | 1114 | (nil))) |
68d87786 SM |
1115 | ;; search for $Revision |
1116 | ;; -------------------- | |
1117 | ((re-search-forward (concat "\\$" | |
1118 | "Revision: \\([0-9.]+\\) \\$") | |
1119 | nil t) | |
1120 | ;; if found, store the revision number ... | |
1121 | (setq version (match-string-no-properties 1)) | |
1122 | ;; and see if there's any lock information | |
1123 | (goto-char (point-min)) | |
1124 | (if (re-search-forward (concat "\\$" "Locker:") nil t) | |
1125 | (cond ((looking-at " \\([^ ]+\\) \\$") | |
1126 | (setq locking-user (match-string-no-properties 1)) | |
1127 | (setq status 'rev-and-lock)) | |
1128 | ((looking-at " *\\$") | |
1129 | (setq locking-user 'none) | |
1130 | (setq status 'rev-and-lock)) | |
1131 | (t | |
1132 | (setq locking-user 'none) | |
1133 | (setq status 'rev-and-lock))) | |
1134 | (setq status 'rev))) | |
1135 | ;; else: nothing found | |
1136 | ;; ------------------- | |
1137 | (t nil)))) | |
ac3f4c6f | 1138 | (if status (vc-file-setprop file 'vc-working-revision version)) |
8f98485f AS |
1139 | (and (eq status 'rev-and-lock) |
1140 | (vc-file-setprop file 'vc-state | |
1141 | (cond | |
1142 | ((eq locking-user 'none) 'up-to-date) | |
53cc5b9c | 1143 | ((string= locking-user (vc-user-login-name file)) |
4f147528 | 1144 | 'edited) |
8f98485f AS |
1145 | (t locking-user))) |
1146 | ;; If the file has headers, we don't want to query the | |
1147 | ;; master file, because that would eliminate all the | |
1148 | ;; performance gain the headers brought us. We therefore | |
1149 | ;; use a heuristic now to find out whether locking is used | |
1150 | ;; for this file. If we trust the file permissions, and the | |
1151 | ;; file is not locked, then if the file is read-only we | |
1152 | ;; assume that locking is used for the file, otherwise | |
1153 | ;; locking is not used. | |
1154 | (not (vc-mistrust-permissions file)) | |
1155 | (vc-up-to-date-p file) | |
1156 | (if (string-match ".r-..-..-." (nth 8 (file-attributes file))) | |
1157 | (vc-file-setprop file 'vc-checkout-model 'locking) | |
1158 | (vc-file-setprop file 'vc-checkout-model 'implicit))) | |
1159 | status)))) | |
1160 | ||
1161 | (defun vc-release-greater-or-equal (r1 r2) | |
1162 | "Compare release numbers, represented as strings. | |
1163 | Release components are assumed cardinal numbers, not decimal fractions | |
1164 | \(5.10 is a higher release than 5.9\). Omitted fields are considered | |
1165 | lower \(5.6.7 is earlier than 5.6.7.1\). Comparison runs till the end | |
1166 | of the string is found, or a non-numeric component shows up \(5.6.7 is | |
1167 | earlier than \"5.6.7 beta\", which is probably not what you want in | |
1168 | some cases\). This code is suitable for existing RCS release numbers. | |
1169 | CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5\)." | |
1170 | (let (v1 v2 i1 i2) | |
1171 | (catch 'done | |
1172 | (or (and (string-match "^\\.?\\([0-9]+\\)" r1) | |
1173 | (setq i1 (match-end 0)) | |
1174 | (setq v1 (string-to-number (match-string 1 r1))) | |
1175 | (or (and (string-match "^\\.?\\([0-9]+\\)" r2) | |
1176 | (setq i2 (match-end 0)) | |
1177 | (setq v2 (string-to-number (match-string 1 r2))) | |
1178 | (if (> v1 v2) (throw 'done t) | |
1179 | (if (< v1 v2) (throw 'done nil) | |
1180 | (throw 'done | |
1181 | (vc-release-greater-or-equal | |
1182 | (substring r1 i1) | |
1183 | (substring r2 i2))))))) | |
1184 | (throw 'done t))) | |
1185 | (or (and (string-match "^\\.?\\([0-9]+\\)" r2) | |
1186 | (throw 'done nil)) | |
1187 | (throw 'done t))))) | |
1188 | ||
1189 | (defun vc-rcs-release-p (release) | |
1190 | "Return t if we have RELEASE or better." | |
1191 | (let ((installation (vc-rcs-system-release))) | |
1192 | (if (and installation | |
1193 | (not (eq installation 'unknown))) | |
1194 | (vc-release-greater-or-equal installation release)))) | |
1195 | ||
8f98485f AS |
1196 | (defun vc-rcs-system-release () |
1197 | "Return the RCS release installed on this system, as a string. | |
c9f203eb | 1198 | Return symbol `unknown' if the release cannot be deducted. The user can |
8f98485f AS |
1199 | override this using variable `vc-rcs-release'. |
1200 | ||
1201 | If the user has not set variable `vc-rcs-release' and it is nil, | |
1202 | variable `vc-rcs-release' is set to the returned value." | |
1203 | (or vc-rcs-release | |
1204 | (setq vc-rcs-release | |
2888a97e | 1205 | (or (and (zerop (vc-do-command "*vc*" nil "rcs" nil "-V")) |
8f98485f AS |
1206 | (with-current-buffer (get-buffer "*vc*") |
1207 | (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1))) | |
1208 | 'unknown)))) | |
1209 | ||
1210 | (defun vc-rcs-set-non-strict-locking (file) | |
2888a97e | 1211 | (vc-do-command "*vc*" 0 "rcs" file "-U") |
8f98485f AS |
1212 | (vc-file-setprop file 'vc-checkout-model 'implicit) |
1213 | (set-file-modes file (logior (file-modes file) 128))) | |
1214 | ||
1215 | (defun vc-rcs-set-default-branch (file branch) | |
2888a97e | 1216 | (vc-do-command "*vc*" 0 "rcs" (vc-name file) (concat "-b" branch)) |
8f98485f AS |
1217 | (vc-file-setprop file 'vc-rcs-default-branch branch)) |
1218 | ||
3249f234 TTN |
1219 | (defun vc-rcs-parse (&optional buffer) |
1220 | "Parse current buffer, presumed to be in RCS-style masterfile format. | |
1221 | Optional arg BUFFER specifies another buffer to parse. Return an alist | |
1222 | of two elements, w/ keys `headers' and `revisions' and values in turn | |
1223 | sub-alists. For `headers', the values unless otherwise specified are | |
1224 | strings and the keys are: | |
1225 | ||
1226 | desc -- description | |
1227 | head -- latest revision | |
1228 | branch -- the branch the \"head revision\" lies on; | |
1229 | absent if the head revision lies on the trunk | |
1230 | access -- ??? | |
1231 | symbols -- sub-alist of (SYMBOL . REVISION) elements | |
1232 | locks -- if file is checked out, something like \"ttn:1.7\" | |
1233 | strict -- t if \"strict locking\" is in effect, otherwise nil | |
1234 | comment -- may be absent; typically something like \"# \" or \"; \" | |
1235 | expand -- may be absent; ??? | |
1236 | ||
1237 | For `revisions', the car is REVISION (string), the cdr a sub-alist, | |
1238 | with string values (unless otherwise specified) and keys: | |
1239 | ||
1240 | date -- a time value (like that returned by `encode-time'); as a | |
1241 | special case, a year value less than 100 is augmented by 1900 | |
1242 | author -- username | |
1243 | state -- typically \"Exp\" or \"Rel\" | |
1244 | branches -- list of revisions that begin branches from this revision | |
1245 | next -- on the trunk: the chronologically-preceding revision, or \"\"; | |
1246 | on a branch: the chronologically-following revision, or \"\" | |
1247 | log -- change log entry | |
1248 | text -- for the head revision on the trunk, the body of the file; | |
1249 | other revisions have `:insn' instead | |
1250 | :insn -- for non-head revisions, a list of parsed instructions | |
1251 | in one of two forms, in both cases START meaning \"first | |
1252 | go to line START\": | |
1253 | - `(START k COUNT)' -- kill COUNT lines | |
1254 | - `(START i TEXT)' -- insert TEXT (a string) | |
1255 | The list is in descending order by START. | |
1256 | ||
1257 | The `:insn' key is a keyword to distinguish it as a vc-rcs.el extension." | |
1258 | (setq buffer (get-buffer (or buffer (current-buffer)))) | |
1259 | (set-buffer buffer) | |
1260 | ;; An RCS masterfile can be viewed as containing four regular (for the | |
1261 | ;; most part) sections: (a) the "headers", (b) the "rev headers", (c) | |
1262 | ;; the "description" and (d) the "rev bodies", in that order. In the | |
1263 | ;; returned alist (see docstring), elements from (b) and (d) are | |
1264 | ;; combined pairwise to form the "revisions", while those from (a) and | |
1265 | ;; (c) are simply combined to form the "headers". | |
1266 | ;; | |
1267 | ;; Loosely speaking, each section contains a series of alternating | |
1268 | ;; "tags" and "printed representations". In the (b) and (d), many | |
1269 | ;; such series can appear, and a revision number on a line by itself | |
1270 | ;; precedes the series of tags and printed representations associated | |
1271 | ;; with it. | |
1272 | ;; | |
1273 | ;; In (a) and (b), the printed representations (with the exception of | |
1274 | ;; the `comment' tag in the headers) terminate with a semicolon, which | |
1275 | ;; is NOT part of the "value" finally associated with the tag. All | |
1276 | ;; other printed representations are in "@@-format"; there is an "@", | |
1277 | ;; the middle part (to be translated into the value), another "@" and | |
1278 | ;; a newline. Each "@@" in the middle part indicates the position of | |
1279 | ;; a single "@" (and consequently the requirement of an additional | |
1280 | ;; initial step when translating to the value). | |
1281 | ;; | |
1282 | ;; Parser state includes vars that collect parts of the return value... | |
1283 | (let ((desc nil) (headers nil) (revs nil) | |
1284 | ;; ... as well as vars that support a single-pass, tag-assisted, | |
1285 | ;; minimal-data-copying scan. Basically -- skirting around the | |
1286 | ;; grouping by revision required in (b) and (d) -- we repeatedly | |
1287 | ;; and context-sensitively read a tag (that MUST be present), | |
1288 | ;; determine the bounds of the printed representation, translate | |
1289 | ;; it into a value, and push the tag plus value onto one of the | |
1290 | ;; collection vars. Finally, we return the parse tree | |
1291 | ;; incorporating the values of the collection vars (see "rv"). | |
1292 | ;; | |
1293 | ;; A symbol or string to keep track of context (for error messages). | |
1294 | context | |
1295 | ;; A symbol, the current tag. | |
1296 | tok | |
1297 | ;; Region (begin and end buffer positions) of the printed | |
1298 | ;; representation for the current tag. | |
1299 | b e | |
1300 | ;; A list of buffer positions where "@@" can be found within the | |
1301 | ;; printed representation region. For each location, we push two | |
1302 | ;; elements onto the list, 1+ and 2+ the location, respectively, | |
1303 | ;; with the 2+ appearing at the head. In this way, the expression | |
1304 | ;; `(,e ,@@-holes ,b) | |
1305 | ;; describes regions that can be concatenated (in reverse order) | |
1306 | ;; to "de-@@-format" the printed representation as the first step | |
1307 | ;; to translating it into some value. See internal func `gather'. | |
1308 | @-holes) | |
d5c6faf9 SM |
1309 | (cl-flet* |
1310 | ((sw () (skip-chars-forward " \t\n")) ; i.e., `[:space:]' | |
1311 | (at (tag) (save-excursion (eq tag (read buffer)))) | |
1312 | (to-eol () (buffer-substring-no-properties | |
1313 | (point) (progn (forward-line 1) | |
1314 | (1- (point))))) | |
1315 | (to-semi () (setq b (point) | |
1316 | e (progn (search-forward ";") | |
1317 | (1- (point))))) | |
1318 | (to-one@ () (setq @-holes nil | |
1319 | b (progn (search-forward "@") (point)) | |
1320 | e (progn (while (and (search-forward "@") | |
1321 | (= ?@ (char-after)) | |
1322 | (progn | |
1323 | (push (point) @-holes) | |
1324 | (forward-char 1) | |
1325 | (push (point) @-holes)))) | |
1326 | (1- (point))))) | |
1327 | (tok+val (set-b+e name &optional proc) | |
1328 | (unless (eq name (setq tok (read buffer))) | |
1329 | (error "Missing `%s' while parsing %s" name context)) | |
1330 | (sw) | |
1331 | (funcall set-b+e) | |
1332 | (cons tok (if proc | |
1333 | (funcall proc) | |
1334 | (buffer-substring-no-properties b e)))) | |
1335 | (k-semi (name &optional proc) (tok+val #'to-semi name proc)) | |
1336 | (gather () (let ((pairs `(,e ,@@-holes ,b)) | |
1337 | acc) | |
1338 | (while pairs | |
1339 | (push (buffer-substring-no-properties | |
1340 | (cadr pairs) (car pairs)) | |
1341 | acc) | |
1342 | (setq pairs (cddr pairs))) | |
1343 | (apply 'concat acc))) | |
1344 | (k-one@ (name &optional later) (tok+val #'to-one@ name | |
1345 | (if later | |
1346 | (lambda () t) | |
1347 | #'gather)))) | |
3249f234 TTN |
1348 | (save-excursion |
1349 | (goto-char (point-min)) | |
1350 | ;; headers | |
1351 | (setq context 'headers) | |
d5c6faf9 SM |
1352 | (cl-flet ((hpush (name &optional proc) |
1353 | (push (k-semi name proc) headers))) | |
3249f234 TTN |
1354 | (hpush 'head) |
1355 | (when (at 'branch) | |
1356 | (hpush 'branch)) | |
1357 | (hpush 'access) | |
1358 | (hpush 'symbols | |
1359 | (lambda () | |
1360 | (mapcar (lambda (together) | |
1361 | (let ((two (split-string together ":"))) | |
1362 | (setcar two (intern (car two))) | |
1363 | (setcdr two (cadr two)) | |
1364 | two)) | |
1365 | (split-string | |
1366 | (buffer-substring-no-properties b e))))) | |
1367 | (hpush 'locks)) | |
1368 | (push `(strict . ,(when (at 'strict) | |
1369 | (search-forward ";") | |
1370 | t)) | |
1371 | headers) | |
1372 | (when (at 'comment) | |
1373 | (push (k-one@ 'comment) headers) | |
1374 | (search-forward ";")) | |
1375 | (when (at 'expand) | |
1376 | (push (k-one@ 'expand) headers) | |
1377 | (search-forward ";")) | |
1378 | (setq headers (nreverse headers)) | |
1379 | ;; rev headers | |
1380 | (sw) (setq context 'rev-headers) | |
1381 | (while (looking-at "[0-9]") | |
1382 | (push `(,(to-eol) | |
1383 | ,(k-semi 'date | |
1384 | (lambda () | |
1385 | (let ((ls (mapcar 'string-to-number | |
1386 | (split-string | |
1387 | (buffer-substring-no-properties | |
1388 | b e) | |
1389 | "\\.")))) | |
1390 | ;; Hack the year -- verified to be the | |
1391 | ;; same algorithm used in RCS 5.7. | |
1392 | (when (< (car ls) 100) | |
1393 | (setcar ls (+ 1900 (car ls)))) | |
1394 | (apply 'encode-time (nreverse ls))))) | |
d5c6faf9 | 1395 | ,@(mapcar #'k-semi '(author state)) |
3249f234 TTN |
1396 | ,(k-semi 'branches |
1397 | (lambda () | |
1398 | (split-string | |
1399 | (buffer-substring-no-properties b e)))) | |
1400 | ,(k-semi 'next)) | |
1401 | revs) | |
1402 | (sw)) | |
1403 | (setq revs (nreverse revs)) | |
1404 | ;; desc | |
1405 | (sw) (setq context 'desc | |
1406 | desc (k-one@ 'desc)) | |
1407 | ;; rev bodies | |
1408 | (let (acc | |
1409 | ;; Element of `revs' that initially holds only header info. | |
1410 | ;; "Pairwise combination" occurs when we add body info. | |
1411 | rev | |
1412 | ;; Components of the editing commands (aside from the actual | |
1413 | ;; text) that comprise the `text' printed representations | |
1414 | ;; (not including the "head" revision). | |
1415 | cmd start act | |
1416 | ;; Ascending (reversed) `@-holes' which the internal func | |
1417 | ;; `incg' pops to effect incremental gathering. | |
1418 | asc | |
1419 | ;; Function to extract text (for the `a' command), either | |
1420 | ;; `incg' or `buffer-substring-no-properties'. (This is | |
1421 | ;; for speed; strictly speaking, it is sufficient to use | |
1422 | ;; only the former since it behaves identically to the | |
91af3942 | 1423 | ;; latter in the absence of "@@".) |
3249f234 | 1424 | sub) |
d5c6faf9 SM |
1425 | (cl-flet ((incg (beg end) |
1426 | (let ((b beg) (e end) @-holes) | |
1427 | (while (and asc (< (car asc) e)) | |
1428 | (push (pop asc) @-holes)) | |
1429 | ;; Self-deprecate when work is done. | |
1430 | ;; Folding many dimensions into one. | |
1431 | ;; Thanks B.Mandelbrot, for complex sum. | |
1432 | ;; O beauteous math! --the Unvexed Bum | |
1433 | (unless asc | |
1434 | (setq sub #'buffer-substring-no-properties)) | |
1435 | (gather)))) | |
3249f234 TTN |
1436 | (while (and (sw) |
1437 | (not (eobp)) | |
1438 | (setq context (to-eol) | |
1439 | rev (or (assoc context revs) | |
1440 | (error "Rev `%s' has body but no head" | |
1441 | context)))) | |
1442 | (push (k-one@ 'log) (cdr rev)) | |
1443 | ;; For rev body `text' tags, delay translation slightly... | |
1444 | (push (k-one@ 'text t) (cdr rev)) | |
1445 | ;; ... until we decide which tag and value is appropriate to | |
1446 | ;; collect. For the "head" revision, compute the value of the | |
1447 | ;; `text' printed representation by simple `gather'. For all | |
1448 | ;; other revisions, replace the `text' tag+value with `:insn' | |
1449 | ;; plus value, always scanning in-place. | |
1450 | (if (string= context (cdr (assq 'head headers))) | |
1451 | (setcdr (cadr rev) (gather)) | |
1452 | (if @-holes | |
1453 | (setq asc (nreverse @-holes) | |
d5c6faf9 SM |
1454 | sub #'incg) |
1455 | (setq sub #'buffer-substring-no-properties)) | |
3249f234 TTN |
1456 | (goto-char b) |
1457 | (setq acc nil) | |
1458 | (while (< (point) e) | |
1459 | (forward-char 1) | |
1460 | (setq cmd (char-before) | |
1461 | start (read (current-buffer)) | |
1462 | act (read (current-buffer))) | |
1463 | (forward-char 1) | |
a464a6c7 | 1464 | (push (pcase cmd |
3249f234 TTN |
1465 | (?d |
1466 | ;; `d' means "delete lines". | |
1467 | ;; For Emacs spirit, we use `k' for "kill". | |
1468 | `(,start k ,act)) | |
1469 | (?a | |
1470 | ;; `a' means "append after this line" but | |
1471 | ;; internally we normalize it so that START | |
1472 | ;; specifies the actual line for insert, thus | |
1473 | ;; requiring less hair in the realization algs. | |
1474 | ;; For Emacs spirit, we use `i' for "insert". | |
1475 | `(,(1+ start) i | |
1476 | ,(funcall sub (point) (progn (forward-line act) | |
1477 | (point))))) | |
a464a6c7 | 1478 | (_ (error "Bad command `%c' in `text' for rev `%s'" |
3249f234 TTN |
1479 | cmd context))) |
1480 | acc)) | |
1481 | (goto-char (1+ e)) | |
1482 | (setcar (cdr rev) (cons :insn acc))))))) | |
1483 | ;; rv | |
1484 | `((headers ,desc ,@headers) | |
1485 | (revisions ,@revs))))) | |
1486 | ||
d8aff077 GM |
1487 | (provide 'vc-rcs) |
1488 | ||
1489 | ;;; vc-rcs.el ends here |