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