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