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