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, 2009
5 ;; Free Software Foundation, Inc.
7 ;; Author: FSF (see vc.el for full credits)
8 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
32 ;;; Customization options
39 (defcustom vc-rcs-release nil
40 "The release number of your RCS installation, as a string.
41 If nil, VC itself computes this value when it is first needed."
42 :type '(choice (const :tag "Auto" nil)
43 (string :tag "Specified")
44 (const :tag "Unknown" unknown))
47 (defcustom vc-rcs-register-switches nil
48 "Switches for registering a file in RCS.
49 A string or list of strings passed to the checkin program by
50 \\[vc-register]. If nil, use the value of `vc-register-switches'.
51 If t, use no switches."
52 :type '(choice (const :tag "Unspecified" nil)
54 (string :tag "Argument String")
55 (repeat :tag "Argument List" :value ("") string))
59 (defcustom vc-rcs-diff-switches nil
60 "String or list of strings specifying switches for RCS diff under VC.
61 If nil, use the value of `vc-diff-switches'. If t, use no switches."
62 :type '(choice (const :tag "Unspecified" nil)
64 (string :tag "Argument String")
65 (repeat :tag "Argument List" :value ("") string))
69 (defcustom vc-rcs-header (or (cdr (assoc 'RCS vc-header-alist)) '("\$Id\$"))
70 "Header keywords to be inserted by `vc-insert-headers'."
71 :type '(repeat string)
75 (defcustom vc-rcsdiff-knows-brief nil
76 "Indicates whether rcsdiff understands the --brief option.
77 The value is either `yes', `no', or nil. If it is nil, VC tries
78 to use --brief and sets this variable to remember whether it worked."
79 :type '(choice (const :tag "Work out" nil) (const yes) (const no))
83 (defcustom vc-rcs-master-templates
84 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s")
85 "Where to look for RCS master files.
86 For a description of possible values, see `vc-check-master-templates'."
87 :type '(choice (const :tag "Use standard RCS file names"
88 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
89 (repeat :tag "User-specified"
96 ;;; Properties of the backend
98 (defun vc-rcs-revision-granularity () 'file)
100 (defun vc-rcs-checkout-model (files)
101 "RCS-specific version of `vc-checkout-model'."
102 (let ((file (if (consp files) (car files) files))
104 (when vc-consult-headers
105 (vc-file-setprop file 'vc-checkout-model nil)
106 (vc-rcs-consult-headers file)
107 (setq result (vc-file-getprop file 'vc-checkout-model)))
109 (progn (vc-rcs-fetch-master-state file)
110 (vc-file-getprop file 'vc-checkout-model)))))
113 ;;; State-querying functions
116 ;; The autoload cookie below places vc-rcs-registered directly into
117 ;; loaddefs.el, so that vc-rcs.el does not need to be loaded for
118 ;; every file that is visited.
121 (defun vc-rcs-registered (f) (vc-default-registered 'RCS f)))
123 (defun vc-rcs-state (file)
124 "Implementation of `vc-state' for RCS."
125 (if (not (vc-rcs-registered file))
127 (or (boundp 'vc-rcs-headers-result)
128 (and vc-consult-headers
129 (vc-rcs-consult-headers file)))
131 ;; vc-working-revision might not be known; in that case the
132 ;; property is nil. vc-rcs-fetch-master-state knows how to
134 (vc-rcs-fetch-master-state file
135 (vc-file-getprop file
136 'vc-working-revision))))
137 (if (not (eq state 'up-to-date))
139 (if (vc-workfile-unchanged-p file)
141 (if (eq (vc-rcs-checkout-model (list file)) 'locking)
145 (defun vc-rcs-state-heuristic (file)
146 "State heuristic for RCS."
147 (let (vc-rcs-headers-result)
148 (if (and vc-consult-headers
149 (setq vc-rcs-headers-result
150 (vc-rcs-consult-headers file))
151 (eq vc-rcs-headers-result 'rev-and-lock))
152 (let ((state (vc-file-getprop file 'vc-state)))
153 ;; If the headers say that the file is not locked, the
154 ;; permissions can tell us whether locking is used for
156 (if (and (eq state 'up-to-date)
157 (not (vc-mistrust-permissions file))
158 (file-exists-p file))
160 ((string-match ".rw..-..-." (nth 8 (file-attributes file)))
161 (vc-file-setprop file 'vc-checkout-model 'implicit)
163 (if (vc-rcs-workfile-is-newer file)
166 ((string-match ".r-..-..-." (nth 8 (file-attributes file)))
167 (vc-file-setprop file 'vc-checkout-model 'locking))))
169 (if (not (vc-mistrust-permissions file))
170 (let* ((attributes (file-attributes file 'string))
171 (owner-name (nth 2 attributes))
172 (permissions (nth 8 attributes)))
173 (cond ((and permissions (string-match ".r-..-..-." permissions))
174 (vc-file-setprop file 'vc-checkout-model 'locking)
176 ((and permissions (string-match ".rw..-..-." permissions))
177 (if (eq (vc-rcs-checkout-model file) 'locking)
178 (if (file-ownership-preserved-p file)
181 (if (vc-rcs-workfile-is-newer file)
185 ;; Strange permissions. Fall through to
186 ;; expensive state computation.
187 (vc-rcs-state file))))
188 (vc-rcs-state file)))))
190 (defun vc-rcs-dir-status (dir update-function)
191 ;; FIXME: this function should be rewritten or `vc-expand-dirs'
192 ;; should be changed to take a backend parameter. Using
193 ;; `vc-expand-dirs' is not TRTD because it returns files from
194 ;; multiple backends. It should also return 'unregistered files.
196 ;; Doing individual vc-state calls is painful but there
197 ;; is no better way in RCS-land.
198 (let ((flist (vc-expand-dirs (list dir)))
201 (let ((state (vc-state file))
202 (frel (file-relative-name file)))
203 (when (and (eq (vc-backend file) 'RCS)
204 (not (eq state 'up-to-date)))
205 (push (list frel state) result))))
206 (funcall update-function result)))
208 (defun vc-rcs-working-revision (file)
209 "RCS-specific version of `vc-working-revision'."
210 (or (and vc-consult-headers
211 (vc-rcs-consult-headers file)
212 (vc-file-getprop file 'vc-working-revision))
214 (vc-rcs-fetch-master-state file)
215 (vc-file-getprop file 'vc-working-revision))))
217 (defun vc-rcs-latest-on-branch-p (file &optional version)
218 "Return non-nil if workfile version of FILE is the latest on its branch.
219 When VERSION is given, perform check for that version."
220 (unless version (setq version (vc-working-revision file)))
223 (if (vc-rcs-trunk-p version)
225 ;; Compare VERSION to the head version number.
226 (vc-insert-file (vc-name file) "^[0-9]")
227 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
228 ;; If we are not on the trunk, we need to examine the
229 ;; whole current branch.
230 (vc-insert-file (vc-name file) "^desc")
231 (vc-rcs-find-most-recent-rev (vc-branch-part version))))))
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 "*vc*" 1 "rcsdiff" file version)
240 (vc-do-command "*vc*" 2 "rcsdiff" file "--brief" version))))
242 (if (not vc-rcsdiff-knows-brief)
243 (setq vc-rcsdiff-knows-brief 'no
244 status (vc-do-command "*vc*" 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.
252 ;;; State-changing functions
255 (defun vc-rcs-create-repo ()
256 "Create a new RCS repository."
257 ;; RCS is totally file-oriented, so all we have to do is make the directory.
258 (make-directory "RCS"))
260 (defun vc-rcs-register (files &optional rev comment)
261 "Register FILES into the RCS version-control system.
262 REV is the optional revision number for the files. COMMENT can be used
263 to provide an initial description for each FILES.
264 Passes either `vc-rcs-register-switches' or `vc-register-switches'
267 Automatically retrieve a read-only version of the file with keywords
268 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
271 (and (not (file-exists-p
272 (setq subdir (expand-file-name "RCS"
273 (file-name-directory file)))))
274 (not (directory-files (file-name-directory file)
276 (yes-or-no-p "Create RCS subdirectory? ")
277 (make-directory subdir))
278 (apply 'vc-do-command "*vc*" 0 "ci" file
279 ;; if available, use the secure registering option
280 (and (vc-rcs-release-p "5.6.4") "-i")
281 (concat (if vc-keep-workfiles "-u" "-r") rev)
282 (and comment (concat "-t-" comment))
283 (vc-switches 'RCS 'register))
284 ;; parse output to find master file name and workfile version
285 (with-current-buffer "*vc*"
286 (goto-char (point-min))
288 (if (looking-at (concat "^\\(.*\\) <-- "
289 (file-name-nondirectory file)))
291 ;; if we couldn't find the master name,
292 ;; run vc-rcs-registered to get it
293 ;; (will be stored into the vc-name property)
294 (vc-rcs-registered file)
295 (vc-file-setprop file 'vc-name
296 (if (file-name-absolute-p name)
300 (file-name-directory file))))))
301 (vc-file-setprop file 'vc-working-revision
302 (if (re-search-forward
303 "^initial revision: \\([0-9.]+\\).*\n"
305 (match-string 1))))))
307 (defun vc-rcs-responsible-p (file)
308 "Return non-nil if RCS thinks it would be responsible for registering FILE."
309 ;; TODO: check for all the patterns in vc-rcs-master-templates
310 (file-directory-p (expand-file-name "RCS" (file-name-directory file))))
312 (defun vc-rcs-receive-file (file rev)
313 "Implementation of receive-file for RCS."
314 (let ((checkout-model (vc-rcs-checkout-model (list file))))
315 (vc-rcs-register file rev "")
316 (when (eq checkout-model 'implicit)
317 (vc-rcs-set-non-strict-locking file))
318 (vc-rcs-set-default-branch file (concat rev ".1"))))
320 (defun vc-rcs-unregister (file)
321 "Unregister FILE from RCS.
322 If this leaves the RCS subdirectory empty, ask the user
323 whether to remove it."
324 (let* ((master (vc-name file))
325 (dir (file-name-directory master))
326 (backup-info (find-backup-file-name master)))
327 (if (not backup-info)
329 (rename-file master (car backup-info) 'ok-if-already-exists)
330 (dolist (f (cdr backup-info)) (ignore-errors (delete-file f))))
331 (and (string= (file-name-nondirectory (directory-file-name dir)) "RCS")
332 ;; check whether RCS dir is empty, i.e. it does not
333 ;; contain any files except "." and ".."
334 (not (directory-files dir nil
335 "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*"))
336 (yes-or-no-p (format "Directory %s is empty; remove it? " dir))
337 (delete-directory dir))))
339 (defun vc-rcs-checkin (files rev comment)
340 "RCS-specific version of `vc-backend-checkin'."
341 (let ((switches (vc-switches 'RCS 'checkin)))
342 ;; Now operate on the files
343 (dolist (file (vc-expand-dirs files))
344 (let ((old-version (vc-working-revision file)) new-version
345 (default-branch (vc-file-getprop file 'vc-rcs-default-branch)))
346 ;; Force branch creation if an appropriate
347 ;; default branch has been set.
350 (string-match (concat "^" (regexp-quote old-version) "\\.")
352 (setq rev default-branch)
353 (setq switches (cons "-f" switches)))
354 (if (and (not rev) old-version)
355 (setq rev (vc-branch-part old-version)))
356 (apply 'vc-do-command "*vc*" 0 "ci" (vc-name file)
357 ;; if available, use the secure check-in option
358 (and (vc-rcs-release-p "5.6.4") "-j")
359 (concat (if vc-keep-workfiles "-u" "-r") rev)
360 (concat "-m" comment)
362 (vc-file-setprop file 'vc-working-revision nil)
364 ;; determine the new workfile version
366 (goto-char (point-min))
367 (when (or (re-search-forward
368 "new revision: \\([0-9.]+\\);" nil t)
370 "reverting to previous revision \\([0-9.]+\\)" nil t))
371 (setq new-version (match-string 1))
372 (vc-file-setprop file 'vc-working-revision new-version))
374 ;; if we got to a different branch, adjust the default
375 ;; branch accordingly
377 ((and old-version new-version
378 (not (string= (vc-branch-part old-version)
379 (vc-branch-part new-version))))
380 (vc-rcs-set-default-branch file
381 (if (vc-rcs-trunk-p new-version) nil
382 (vc-branch-part new-version)))
383 ;; If this is an old RCS release, we might have
384 ;; to remove a remaining lock.
385 (if (not (vc-rcs-release-p "5.6.2"))
386 ;; exit status of 1 is also accepted.
387 ;; It means that the lock was removed before.
388 (vc-do-command "*vc*" 1 "rcs" (vc-name file)
389 (concat "-u" old-version)))))))))
391 (defun vc-rcs-find-revision (file rev buffer)
392 (apply 'vc-do-command
393 (or buffer "*vc*") 0 "co" (vc-name file)
394 "-q" ;; suppress diagnostic output
396 (vc-switches 'RCS 'checkout)))
398 (defun vc-rcs-checkout (file &optional editable rev)
399 "Retrieve a copy of a saved version of FILE. If FILE is a directory,
400 attempt the checkout for all registered files beneath it."
401 (if (file-directory-p file)
402 (mapc 'vc-rcs-checkout (vc-expand-dirs (list file)))
403 (let ((file-buffer (get-file-buffer file))
405 (message "Checking out %s..." file)
407 ;; Change buffers to get local value of vc-checkout-switches.
408 (if file-buffer (set-buffer file-buffer))
409 (setq switches (vc-switches 'RCS 'checkout))
410 ;; Save this buffer's default-directory
411 ;; and use save-excursion to make sure it is restored
412 ;; in the same buffer it was saved in.
413 (let ((default-directory default-directory))
415 ;; Adjust the default-directory so that the check-out creates
416 ;; the file in the right place.
417 (setq default-directory (file-name-directory file))
419 ;; if we should go to the head of the trunk,
420 ;; clear the default branch first
421 (and rev (string= rev "")
422 (vc-rcs-set-default-branch file nil))
423 ;; now do the checkout
424 (apply 'vc-do-command
425 "*vc*" 0 "co" (vc-name file)
426 ;; If locking is not strict, force to overwrite
427 ;; the writable workfile.
428 (if (eq (vc-rcs-checkout-model (list file)) 'implicit) "-f")
431 ;; a literal revision was specified
433 (let ((workrev (vc-working-revision file)))
437 ;; no revision specified:
438 ;; use current workfile version
441 (if (not (vc-rcs-trunk-p workrev))
442 ;; ... go to head of current branch
443 (vc-branch-part workrev)
444 ;; ... go to head of trunk
445 (vc-rcs-set-default-branch file
449 ;; determine the new workfile version
450 (with-current-buffer "*vc*"
452 (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1)))
453 (vc-file-setprop file 'vc-working-revision new-version)
454 ;; if necessary, adjust the default branch
455 (and rev (not (string= rev ""))
456 (vc-rcs-set-default-branch
458 (if (vc-rcs-latest-on-branch-p file new-version)
459 (if (vc-rcs-trunk-p new-version) nil
460 (vc-branch-part new-version))
462 (message "Checking out %s...done" file))))))
464 (defun vc-rcs-rollback (files)
465 "Roll back, undoing the most recent checkins of FILES. Directories are
466 expanded to all registered subfiles in them."
468 (error "RCS backend doesn't support directory-level rollback."))
469 (dolist (file (vc-expand-dirs files))
470 (let* ((discard (vc-working-revision file))
471 (previous (if (vc-rcs-trunk-p discard) "" (vc-branch-part discard)))
472 (config (current-window-configuration))
474 (if (null (yes-or-no-p (format "Remove version %s from %s history? "
477 (message "Removing revision %s from %s." discard file)
478 (vc-do-command "*vc*" 0 "rcs" (vc-name file) (concat "-o" discard))
479 ;; Check out the most recent remaining version. If it
480 ;; fails, because the whole branch got deleted, do a
481 ;; double-take and check out the version where the branch
486 (vc-do-command "*vc*" 0 "co" (vc-name file) "-f"
487 (concat "-u" previous))
489 (error (set-buffer "*vc*")
490 (goto-char (point-min))
491 (if (search-forward "no side branches present for" nil t)
492 (progn (setq previous (vc-branch-part previous))
493 (vc-rcs-set-default-branch file previous)
494 ;; vc-do-command popped up a window with
495 ;; the error message. Get rid of it, by
496 ;; restoring the old window configuration.
497 (set-window-configuration config))
498 ;; No, it was some other error: re-signal it.
499 (signal (car err) (cdr err)))))))))
501 (defun vc-rcs-revert (file &optional contents-done)
502 "Revert FILE to the version it was based on. If FILE is a directory,
503 revert all registered files beneath it."
504 (if (file-directory-p file)
505 (mapc 'vc-rcs-revert (vc-expand-dirs (list file)))
506 (vc-do-command "*vc*" 0 "co" (vc-name file) "-f"
507 (concat (if (eq (vc-state file) 'edited) "-u" "-r")
508 (vc-working-revision file)))))
510 (defun vc-rcs-merge (file first-version &optional second-version)
511 "Merge changes into current working copy of FILE.
512 The changes are between FIRST-VERSION and SECOND-VERSION."
513 (vc-do-command "*vc*" 1 "rcsmerge" (vc-name file)
514 "-kk" ; ignore keyword conflicts
515 (concat "-r" first-version)
516 (if second-version (concat "-r" second-version))))
518 (defun vc-rcs-steal-lock (file &optional rev)
519 "Steal the lock on the current workfile for FILE and revision REV.
520 If FILE is a directory, steal the lock on all registered files beneath it.
521 Needs RCS 5.6.2 or later for -M."
522 (if (file-directory-p file)
523 (mapc 'vc-rcs-steal-lock (vc-expand-dirs (list file)))
524 (vc-do-command "*vc*" 0 "rcs" (vc-name file) "-M" (concat "-u" rev))
525 ;; Do a real checkout after stealing the lock, so that we see
527 (vc-do-command "*vc*" 0 "co" (vc-name file) "-f" (concat "-l" rev))))
529 (defun vc-rcs-modify-change-comment (files rev comment)
530 "Modify the change comments change on FILES on a specified REV. If FILE is a
531 directory the operation is applied to all registered files beneath it."
532 (dolist (file (vc-expand-dirs files))
533 (vc-do-command "*vc*" 0 "rcs" (vc-name file)
534 (concat "-m" rev ":" comment))))
538 ;;; History functions
541 (defun vc-rcs-print-log (files &optional buffer)
542 "Get change log associated with FILE. If FILE is a
543 directory the operation is applied to all registered files beneath it."
544 (vc-do-command (or buffer "*vc*") 0 "rlog" (mapcar 'vc-name (vc-expand-dirs files))))
546 (defun vc-rcs-diff (files &optional oldvers newvers buffer)
547 "Get a difference report using RCS between two sets of files."
548 (apply 'vc-do-command (or buffer "*vc-diff*")
549 1 ;; Always go synchronous, the repo is local
550 "rcsdiff" (vc-expand-dirs files)
552 (and oldvers (concat "-r" oldvers))
553 (and newvers (concat "-r" newvers)))
554 (vc-switches 'RCS 'diff))))
556 (defun vc-rcs-comment-history (file)
557 "Return a string with all log entries stored in BACKEND for FILE."
558 (with-current-buffer "*vc*"
559 ;; Has to be written this way, this function is used by the CVS backend too
560 (vc-call-backend (vc-backend file) 'print-log (list file))
562 (let ((separator (concat "^-+\nrevision [0-9.]+\ndate: .*\n"
563 "\\(branches: .*;\n\\)?"
564 "\\(\\*\\*\\* empty log message \\*\\*\\*\n\\)?")))
565 (goto-char (point-max)) (forward-line -1)
566 (while (looking-at "=*\n")
567 (delete-char (- (match-end 0) (match-beginning 0)))
569 (goto-char (point-min))
570 (if (looking-at "[\b\t\n\v\f\r ]+")
571 (delete-char (- (match-end 0) (match-beginning 0))))
572 (goto-char (point-min))
573 (re-search-forward separator nil t)
574 (delete-region (point-min) (point))
575 (while (re-search-forward separator nil t)
576 (delete-region (match-beginning 0) (match-end 0))))
577 ;; Return the de-crufted comment list
580 (defun vc-rcs-annotate-command (file buffer &optional revision)
581 "Annotate FILE, inserting the results in BUFFER.
582 Optional arg REVISION is a revision to annotate from."
583 (vc-setup-buffer buffer)
584 ;; Aside from the "head revision on the trunk", the instructions for
585 ;; each revision on the trunk are an ordered list of kill and insert
586 ;; commands necessary to go from the chronologically-following
587 ;; revision to this one. That is, associated with revision N are
588 ;; edits that applied to revision N+1 would result in revision N.
590 ;; On a branch, however, (some) things are inverted: the commands
591 ;; listed are those necessary to go from the chronologically-preceding
592 ;; revision to this one. That is, associated with revision N are
593 ;; edits that applied to revision N-1 would result in revision N.
595 ;; So, to get per-line history info, we apply reverse-chronological
596 ;; edits, starting with the head revision on the trunk, all the way
597 ;; back through the initial revision (typically "1.1" or similar),
598 ;; then apply forward-chronological edits -- keeping track of which
599 ;; revision is associated with each inserted line -- until we reach
600 ;; the desired revision for display (which may be either on the trunk
602 (let* ((tree (with-temp-buffer
603 (insert-file-contents (vc-rcs-registered file))
605 (revisions (cdr (assq 'revisions tree)))
606 ;; The revision N whose instructions we currently are processing.
607 (cur (cdr (assq 'head (cdr (assq 'headers tree)))))
608 ;; Alist from the parse tree for N.
609 (meta (cdr (assoc cur revisions)))
610 ;; Point and temporary string, respectively.
612 ;; "Next-branch list". Nil means the desired revision to
613 ;; display lives on the trunk. Non-nil means it lives on a
614 ;; branch, in which case the value is a list of revision pairs
615 ;; (PARENT . CHILD), the first PARENT being on the trunk, that
616 ;; links each series of revisions in the path from the initial
617 ;; revision to the desired revision to display.
619 ;; "Path-accumulate-predicate plus revision/date/author".
620 ;; Until set, forward-chronological edits are not accumulated.
621 ;; Once set, its value (updated every revision) is used for
622 ;; the text property `:vc-rcs-r/d/a' for inserts during
623 ;; processing of forward-chronological instructions for N.
624 ;; See internal func `r/d/a'.
626 ;; List of forward-chronological instructions, each of the
627 ;; form: (POS . ACTION), where POS is a buffer position. If
628 ;; ACTION is a string, it is inserted, otherwise it is taken as
629 ;; the number of characters to be deleted.
631 ;; N+1. When `cur' is "", this is the initial revision.
635 (unless (assoc revision revisions)
636 (error "No such revision: %s" revision))
637 ;; Find which branches (if any) must be included in the edits.
640 (while (setq bpt (vc-branch-part par)
641 par (vc-branch-part bpt))
642 (setq kids (cdr (assq 'branches (cdr (assoc par revisions)))))
643 ;; A branchpoint may have multiple children. Find the right one.
644 (while (not (string= bpt (vc-branch-part (car kids))))
645 (setq kids (cdr kids)))
646 (push (cons par (car kids)) nbls)))
647 ;; Start with the full text.
649 (insert (cdr (assq 'text meta)))
650 ;; Apply reverse-chronological edits on the trunk, computing and
651 ;; accumulating forward-chronological edits after some point, for
653 (flet ((r/d/a () (vector pre
654 (cdr (assq 'date meta))
655 (cdr (assq 'author meta)))))
656 (while (when (setq pre cur cur (cdr (assq 'next meta)))
657 (not (string= "" cur)))
659 ;; Start accumulating the forward-chronological edits when N+1
660 ;; on the trunk is either the desired revision to display, or
661 ;; the appropriate branchpoint for it. Do this before
662 ;; updating `meta' since `r/d/a' uses N+1's `meta' value.
663 prda (when (or prda (string= (if nbls (caar nbls) revision) pre))
665 meta (cdr (assoc cur revisions)))
666 ;; Edits in the parse tree specify a line number (in the buffer
667 ;; *BEFORE* editing occurs) to start from, but line numbers
668 ;; change as a result of edits. To DTRT, we apply edits in
669 ;; order of descending buffer position so that edits further
670 ;; down in the buffer occur first w/o corrupting specified
671 ;; buffer positions of edits occurring towards the beginning of
672 ;; the buffer. In this way we avoid using markers. A pleasant
673 ;; property of this approach is ability to push instructions
674 ;; onto `path' directly, w/o need to maintain rev boundaries.
675 (dolist (insn (cdr (assq :insn meta)))
676 (goto-line (pop insn))
679 (k (setq s (buffer-substring-no-properties
680 p (progn (forward-line (car insn))
683 (push `(,p . ,(propertize s :vc-rcs-r/d/a prda)) path))
684 (delete-region p (point)))
685 (i (setq s (car insn))
687 (push `(,p . ,(length s)) path))
689 ;; For the initial revision, setting `:vc-rcs-r/d/a' directly is
690 ;; equivalent to pushing an insert instruction (of the entire buffer
691 ;; contents) onto `path' then erasing the buffer, but less wasteful.
692 (put-text-property (point-min) (point-max) :vc-rcs-r/d/a (r/d/a))
693 ;; Now apply the forward-chronological edits for the trunk.
695 (goto-char (pop insn))
699 ;; Now apply the forward-chronological edits (directly from the
700 ;; parse-tree) for the branch(es), if necessary. We re-use vars
701 ;; `pre' and `meta' for the sake of internal func `r/d/a'.
703 (setq pre (cdr (pop nbls)))
705 (setq meta (cdr (assoc pre revisions))
707 (dolist (insn (cdr (assq :insn meta)))
708 (goto-line (pop insn))
711 (point) (progn (forward-line (car insn))
713 (i (insert (propertize
716 (or prda (setq prda (r/d/a))))))))
717 (prog1 (not (string= (if nbls (caar nbls) revision) pre))
718 (setq pre (cdr (assq 'next meta)))))))))
719 ;; Lastly, for each line, insert at bol nicely-formatted history info.
720 ;; We do two passes to collect summary information used to minimize
721 ;; the annotation's usage of screen real-estate: (1) Consider rendered
722 ;; width of revision plus author together as a unit; and (2) Omit
723 ;; author entirely if all authors are the same as the user.
724 (let ((ht (make-hash-table :test 'eq))
725 (me (user-login-name))
729 (goto-char (point-max))
732 (setq rda (get-text-property (point) :vc-rcs-r/d/a))
733 (unless (gethash rda ht)
735 all-me (and all-me (string= a me)))
736 (puthash rda (setq w (+ (length (aref rda 0))
739 (setq maxw (max w maxw))))
740 (let ((padding (make-string maxw 32)))
741 (flet ((pad (w) (substring-no-properties padding w))
742 (render (rda &rest ls)
745 (format-time-string "%Y-%m-%d" (aref rda 1))
749 :vc-annotate-prefix t
754 (puthash rda (render rda (pad w) ": ") ht))
756 (puthash rda (render rda " " (pad w) " " (aref rda 2) ": ") ht)))
759 (insert (gethash (get-text-property (point) :vc-rcs-r/d/a) ht))
762 (declare-function vc-annotate-convert-time "vc-annotate" (time))
764 (defun vc-rcs-annotate-current-time ()
765 "Return the current time, based at midnight of the current day, and
766 encoded as fractional days."
767 (vc-annotate-convert-time
768 (apply 'encode-time 0 0 0 (nthcdr 3 (decode-time (current-time))))))
770 (defun vc-rcs-annotate-time ()
771 "Return the time of the next annotation (as fraction of days)
772 systime, or nil if there is none. Also, reposition point."
774 (prog1 (vc-annotate-convert-time
775 (aref (get-text-property (point) :vc-rcs-r/d/a) 1))
776 (goto-char (next-single-property-change (point) :vc-annotate-prefix)))))
778 (defun vc-rcs-annotate-extract-revision-at-line ()
779 (aref (get-text-property (point) :vc-rcs-r/d/a) 0))
786 (defun vc-rcs-create-tag (backend dir name branchp)
788 (error "RCS backend %s does not support module branches" backend))
789 (let ((result (vc-tag-precondition dir)))
791 (error "File %s is not up-to-date" result)
795 (vc-do-command "*vc*" 0 "rcs" (vc-name f) (concat "-n" name ":")))))))
802 (defun vc-rcs-trunk-p (rev)
803 "Return t if REV is a revision on the trunk."
804 (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev))))
806 (defun vc-rcs-minor-part (rev)
807 "Return the minor revision number of a revision number REV."
808 (string-match "[0-9]+\\'" rev)
809 (substring rev (match-beginning 0) (match-end 0)))
811 (defun vc-rcs-previous-revision (file rev)
812 "Return the revision number immediately preceding REV for FILE,
813 or nil if there is no previous revision. This default
814 implementation works for MAJOR.MINOR-style revision numbers as
815 used by RCS and CVS."
816 (let ((branch (vc-branch-part rev))
817 (minor-num (string-to-number (vc-rcs-minor-part rev))))
820 ;; revision does probably not start a branch or release
821 (concat branch "." (number-to-string (1- minor-num)))
822 (if (vc-rcs-trunk-p rev)
823 ;; we are at the beginning of the trunk --
824 ;; don't know anything to return here
826 ;; we are at the beginning of a branch --
827 ;; return revision of starting point
828 (vc-branch-part branch))))))
830 (defun vc-rcs-next-revision (file rev)
831 "Return the revision number immediately following REV for FILE,
832 or nil if there is no next revision. This default implementation
833 works for MAJOR.MINOR-style revision numbers as used by RCS
835 (when (not (string= rev (vc-working-revision file)))
836 (let ((branch (vc-branch-part rev))
837 (minor-num (string-to-number (vc-rcs-minor-part rev))))
838 (concat branch "." (number-to-string (1+ minor-num))))))
840 (defun vc-rcs-update-changelog (files)
841 "Default implementation of update-changelog.
842 Uses `rcs2log' which only works for RCS and CVS."
843 ;; FIXME: We (c|sh)ould add support for cvs2cl
844 (let ((odefault default-directory)
845 (changelog (find-change-log))
846 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
847 (tempfile (make-temp-file
848 (expand-file-name "vc"
849 (or small-temporary-file-directory
850 temporary-file-directory))))
851 (login-name (or user-login-name
852 (format "uid%d" (number-to-string (user-uid)))))
853 (full-name (or add-log-full-name
856 (format "uid%d" (number-to-string (user-uid)))))
857 (mailing-address (or add-log-mailing-address
859 (find-file-other-window changelog)
860 (barf-if-buffer-read-only)
863 (goto-char (point-min))
865 (message "Computing change log entries...")
866 (message "Computing change log entries... %s"
869 (setq default-directory odefault)
870 (if (eq 0 (apply 'call-process
871 (expand-file-name "rcs2log"
873 nil (list t tempfile) nil
875 "-u" (concat login-name
877 "\t" mailing-address)
881 (expand-file-name f odefault)))
884 (pop-to-buffer (get-buffer-create "*vc*"))
886 (insert-file-contents tempfile)
888 (setq default-directory (file-name-directory changelog))
889 (delete-file tempfile)))))
891 (defun vc-rcs-check-headers ()
892 "Check if the current file has any headers in it."
894 (goto-char (point-min))
895 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
896 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
898 (defun vc-rcs-clear-headers ()
899 "Implementation of vc-clear-headers for RCS."
900 (let ((case-fold-search nil))
901 (goto-char (point-min))
902 (while (re-search-forward
903 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
904 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
906 (replace-match "$\\1$"))))
908 (defun vc-rcs-rename-file (old new)
909 ;; Just move the master file (using vc-rcs-master-templates).
910 (vc-rename-master (vc-name old) new vc-rcs-master-templates))
912 (defun vc-rcs-find-file-hook ()
913 ;; If the file is locked by some other user, make
914 ;; the buffer read-only. Like this, even root
915 ;; cannot modify a file that someone else has locked.
916 (and (stringp (vc-state buffer-file-name 'RCS))
917 (setq buffer-read-only t)))
921 ;;; Internal functions
924 (defun vc-rcs-workfile-is-newer (file)
925 "Return non-nil if FILE is newer than its RCS master.
926 This likely means that FILE has been changed with respect
927 to its master version."
928 (let ((file-time (nth 5 (file-attributes file)))
929 (master-time (nth 5 (file-attributes (vc-name file)))))
930 (or (> (nth 0 file-time) (nth 0 master-time))
931 (and (= (nth 0 file-time) (nth 0 master-time))
932 (> (nth 1 file-time) (nth 1 master-time))))))
934 (defun vc-rcs-find-most-recent-rev (branch)
935 "Find most recent revision on BRANCH."
936 (goto-char (point-min))
937 (let ((latest-rev -1) value)
938 (while (re-search-forward (concat "^\\(" (regexp-quote branch)
939 "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;")
941 (let ((rev (string-to-number (match-string 2))))
942 (when (< latest-rev rev)
943 (setq latest-rev rev)
944 (setq value (match-string 1)))))
946 (vc-branch-part branch))))
948 (defun vc-rcs-fetch-master-state (file &optional working-revision)
949 "Compute the master file's idea of the state of FILE.
950 If a WORKING-REVISION is given, compute the state of that version,
951 otherwise determine the workfile version based on the master file.
952 This function sets the properties `vc-working-revision' and
953 `vc-checkout-model' to their correct values, based on the master
956 (if (or (not (vc-insert-file (vc-name file) "^[0-9]"))
957 (progn (goto-char (point-min))
958 (not (looking-at "^head[ \t\n]+[^;]+;$"))))
959 (error "File %s is not an RCS master file" (vc-name file)))
960 (let ((workfile-is-latest nil)
961 (default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1)))
962 (vc-file-setprop file 'vc-rcs-default-branch default-branch)
963 (unless working-revision
964 ;; Workfile version not known yet. Determine that first. It
965 ;; is either the head of the trunk, the head of the default
966 ;; branch, or the "default branch" itself, if that is a full
970 ((or (not default-branch) (string= "" default-branch))
971 (setq working-revision
972 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
973 (setq workfile-is-latest t))
974 ;; default branch is actually a revision
975 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
977 (setq working-revision default-branch))
978 ;; else, search for the head of the default branch
979 (t (vc-insert-file (vc-name file) "^desc")
980 (setq working-revision
981 (vc-rcs-find-most-recent-rev default-branch))
982 (setq workfile-is-latest t)))
983 (vc-file-setprop file 'vc-working-revision working-revision))
984 ;; Check strict locking
985 (goto-char (point-min))
986 (vc-file-setprop file 'vc-checkout-model
987 (if (re-search-forward ";[ \t\n]*strict;" nil t)
989 ;; Compute state of workfile version
990 (goto-char (point-min))
992 (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):"
993 (regexp-quote working-revision)
999 (if (or workfile-is-latest
1000 (vc-rcs-latest-on-branch-p file working-revision))
1001 ;; workfile version is latest on branch
1003 ;; workfile version is not latest on branch
1005 ;; locked by the calling user
1006 ((and (stringp locking-user)
1007 (string= locking-user (vc-user-login-name file)))
1008 ;; Don't call `vc-rcs-checkout-model' to avoid inf-looping.
1009 (if (or (eq (vc-file-getprop file 'vc-checkout-model) 'locking)
1011 (vc-rcs-latest-on-branch-p file working-revision))
1013 ;; Locking is not used for the file, but the owner does
1014 ;; have a lock, and there is a higher version on the current
1015 ;; branch. Not sure if this can occur, and if it is right
1016 ;; to use `needs-merge' in this case.
1018 ;; locked by somebody else
1019 ((stringp locking-user)
1022 (error "Error getting state of RCS file")))))))
1024 (defun vc-rcs-consult-headers (file)
1025 "Search for RCS headers in FILE, and set properties accordingly.
1027 Returns: nil if no headers were found
1028 'rev if a workfile revision was found
1029 'rev-and-lock if revision and lock info was found"
1031 ((not (get-file-buffer file)) nil)
1032 ((let (status version locking-user)
1034 (set-buffer (get-file-buffer file))
1035 (goto-char (point-min))
1037 ;; search for $Id or $Header
1038 ;; -------------------------
1039 ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file.
1040 ((or (and (search-forward "$Id\ : " nil t)
1041 (looking-at "[^ ]+ \\([0-9.]+\\) "))
1042 (and (progn (goto-char (point-min))
1043 (search-forward "$Header\ : " nil t))
1044 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
1045 (goto-char (match-end 0))
1046 ;; if found, store the revision number ...
1047 (setq version (match-string-no-properties 1))
1048 ;; ... and check for the locking state
1051 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
1052 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
1053 "[^ ]+ [^ ]+ ")) ; author & state
1054 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
1056 ;; unlocked revision
1058 (setq locking-user 'none)
1059 (setq status 'rev-and-lock))
1060 ;; revision is locked by some user
1061 ((looking-at "\\([^ ]+\\) \\$")
1062 (setq locking-user (match-string-no-properties 1))
1063 (setq status 'rev-and-lock))
1064 ;; everything else: false
1066 ;; unexpected information in
1067 ;; keyword string --> quit
1069 ;; search for $Revision
1070 ;; --------------------
1071 ((re-search-forward (concat "\\$"
1072 "Revision: \\([0-9.]+\\) \\$")
1074 ;; if found, store the revision number ...
1075 (setq version (match-string-no-properties 1))
1076 ;; and see if there's any lock information
1077 (goto-char (point-min))
1078 (if (re-search-forward (concat "\\$" "Locker:") nil t)
1079 (cond ((looking-at " \\([^ ]+\\) \\$")
1080 (setq locking-user (match-string-no-properties 1))
1081 (setq status 'rev-and-lock))
1082 ((looking-at " *\\$")
1083 (setq locking-user 'none)
1084 (setq status 'rev-and-lock))
1086 (setq locking-user 'none)
1087 (setq status 'rev-and-lock)))
1088 (setq status 'rev)))
1089 ;; else: nothing found
1090 ;; -------------------
1092 (if status (vc-file-setprop file 'vc-working-revision version))
1093 (and (eq status 'rev-and-lock)
1094 (vc-file-setprop file 'vc-state
1096 ((eq locking-user 'none) 'up-to-date)
1097 ((string= locking-user (vc-user-login-name file))
1100 ;; If the file has headers, we don't want to query the
1101 ;; master file, because that would eliminate all the
1102 ;; performance gain the headers brought us. We therefore
1103 ;; use a heuristic now to find out whether locking is used
1104 ;; for this file. If we trust the file permissions, and the
1105 ;; file is not locked, then if the file is read-only we
1106 ;; assume that locking is used for the file, otherwise
1107 ;; locking is not used.
1108 (not (vc-mistrust-permissions file))
1109 (vc-up-to-date-p file)
1110 (if (string-match ".r-..-..-." (nth 8 (file-attributes file)))
1111 (vc-file-setprop file 'vc-checkout-model 'locking)
1112 (vc-file-setprop file 'vc-checkout-model 'implicit)))
1115 (defun vc-release-greater-or-equal (r1 r2)
1116 "Compare release numbers, represented as strings.
1117 Release components are assumed cardinal numbers, not decimal fractions
1118 \(5.10 is a higher release than 5.9\). Omitted fields are considered
1119 lower \(5.6.7 is earlier than 5.6.7.1\). Comparison runs till the end
1120 of the string is found, or a non-numeric component shows up \(5.6.7 is
1121 earlier than \"5.6.7 beta\", which is probably not what you want in
1122 some cases\). This code is suitable for existing RCS release numbers.
1123 CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5\)."
1126 (or (and (string-match "^\\.?\\([0-9]+\\)" r1)
1127 (setq i1 (match-end 0))
1128 (setq v1 (string-to-number (match-string 1 r1)))
1129 (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
1130 (setq i2 (match-end 0))
1131 (setq v2 (string-to-number (match-string 1 r2)))
1132 (if (> v1 v2) (throw 'done t)
1133 (if (< v1 v2) (throw 'done nil)
1135 (vc-release-greater-or-equal
1137 (substring r2 i2)))))))
1139 (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
1143 (defun vc-rcs-release-p (release)
1144 "Return t if we have RELEASE or better."
1145 (let ((installation (vc-rcs-system-release)))
1146 (if (and installation
1147 (not (eq installation 'unknown)))
1148 (vc-release-greater-or-equal installation release))))
1150 (defun vc-rcs-system-release ()
1151 "Return the RCS release installed on this system, as a string.
1152 Return symbol `unknown' if the release cannot be deducted. The user can
1153 override this using variable `vc-rcs-release'.
1155 If the user has not set variable `vc-rcs-release' and it is nil,
1156 variable `vc-rcs-release' is set to the returned value."
1158 (setq vc-rcs-release
1159 (or (and (zerop (vc-do-command "*vc*" nil "rcs" nil "-V"))
1160 (with-current-buffer (get-buffer "*vc*")
1161 (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1)))
1164 (defun vc-rcs-set-non-strict-locking (file)
1165 (vc-do-command "*vc*" 0 "rcs" file "-U")
1166 (vc-file-setprop file 'vc-checkout-model 'implicit)
1167 (set-file-modes file (logior (file-modes file) 128)))
1169 (defun vc-rcs-set-default-branch (file branch)
1170 (vc-do-command "*vc*" 0 "rcs" (vc-name file) (concat "-b" branch))
1171 (vc-file-setprop file 'vc-rcs-default-branch branch))
1173 (defun vc-rcs-parse (&optional buffer)
1174 "Parse current buffer, presumed to be in RCS-style masterfile format.
1175 Optional arg BUFFER specifies another buffer to parse. Return an alist
1176 of two elements, w/ keys `headers' and `revisions' and values in turn
1177 sub-alists. For `headers', the values unless otherwise specified are
1178 strings and the keys are:
1181 head -- latest revision
1182 branch -- the branch the \"head revision\" lies on;
1183 absent if the head revision lies on the trunk
1185 symbols -- sub-alist of (SYMBOL . REVISION) elements
1186 locks -- if file is checked out, something like \"ttn:1.7\"
1187 strict -- t if \"strict locking\" is in effect, otherwise nil
1188 comment -- may be absent; typically something like \"# \" or \"; \"
1189 expand -- may be absent; ???
1191 For `revisions', the car is REVISION (string), the cdr a sub-alist,
1192 with string values (unless otherwise specified) and keys:
1194 date -- a time value (like that returned by `encode-time'); as a
1195 special case, a year value less than 100 is augmented by 1900
1197 state -- typically \"Exp\" or \"Rel\"
1198 branches -- list of revisions that begin branches from this revision
1199 next -- on the trunk: the chronologically-preceding revision, or \"\";
1200 on a branch: the chronologically-following revision, or \"\"
1201 log -- change log entry
1202 text -- for the head revision on the trunk, the body of the file;
1203 other revisions have `:insn' instead
1204 :insn -- for non-head revisions, a list of parsed instructions
1205 in one of two forms, in both cases START meaning \"first
1207 - `(START k COUNT)' -- kill COUNT lines
1208 - `(START i TEXT)' -- insert TEXT (a string)
1209 The list is in descending order by START.
1211 The `:insn' key is a keyword to distinguish it as a vc-rcs.el extension."
1212 (setq buffer (get-buffer (or buffer (current-buffer))))
1214 ;; An RCS masterfile can be viewed as containing four regular (for the
1215 ;; most part) sections: (a) the "headers", (b) the "rev headers", (c)
1216 ;; the "description" and (d) the "rev bodies", in that order. In the
1217 ;; returned alist (see docstring), elements from (b) and (d) are
1218 ;; combined pairwise to form the "revisions", while those from (a) and
1219 ;; (c) are simply combined to form the "headers".
1221 ;; Loosely speaking, each section contains a series of alternating
1222 ;; "tags" and "printed representations". In the (b) and (d), many
1223 ;; such series can appear, and a revision number on a line by itself
1224 ;; precedes the series of tags and printed representations associated
1227 ;; In (a) and (b), the printed representations (with the exception of
1228 ;; the `comment' tag in the headers) terminate with a semicolon, which
1229 ;; is NOT part of the "value" finally associated with the tag. All
1230 ;; other printed representations are in "@@-format"; there is an "@",
1231 ;; the middle part (to be translated into the value), another "@" and
1232 ;; a newline. Each "@@" in the middle part indicates the position of
1233 ;; a single "@" (and consequently the requirement of an additional
1234 ;; initial step when translating to the value).
1236 ;; Parser state includes vars that collect parts of the return value...
1237 (let ((desc nil) (headers nil) (revs nil)
1238 ;; ... as well as vars that support a single-pass, tag-assisted,
1239 ;; minimal-data-copying scan. Basically -- skirting around the
1240 ;; grouping by revision required in (b) and (d) -- we repeatedly
1241 ;; and context-sensitively read a tag (that MUST be present),
1242 ;; determine the bounds of the printed representation, translate
1243 ;; it into a value, and push the tag plus value onto one of the
1244 ;; collection vars. Finally, we return the parse tree
1245 ;; incorporating the values of the collection vars (see "rv").
1247 ;; A symbol or string to keep track of context (for error messages).
1249 ;; A symbol, the current tag.
1251 ;; Region (begin and end buffer positions) of the printed
1252 ;; representation for the current tag.
1254 ;; A list of buffer positions where "@@" can be found within the
1255 ;; printed representation region. For each location, we push two
1256 ;; elements onto the list, 1+ and 2+ the location, respectively,
1257 ;; with the 2+ appearing at the head. In this way, the expression
1258 ;; `(,e ,@@-holes ,b)
1259 ;; describes regions that can be concatenated (in reverse order)
1260 ;; to "de-@@-format" the printed representation as the first step
1261 ;; to translating it into some value. See internal func `gather'.
1263 (flet ((sw () (skip-chars-forward " \t\n")) ; i.e., `[:space:]'
1264 (at (tag) (save-excursion (eq tag (read buffer))))
1265 (to-eol () (buffer-substring-no-properties
1266 (point) (progn (forward-line 1)
1268 (to-semi () (setq b (point)
1269 e (progn (search-forward ";")
1271 (to-one@ () (setq @-holes nil
1272 b (progn (search-forward "@") (point))
1273 e (progn (while (and (search-forward "@")
1276 (push (point) @-holes)
1278 (push (point) @-holes))))
1280 (tok+val (set-b+e name &optional proc)
1281 (unless (eq name (setq tok (read buffer)))
1282 (error "Missing `%s' while parsing %s" name context))
1287 (buffer-substring-no-properties b e))))
1288 (k-semi (name &optional proc) (tok+val 'to-semi name proc))
1289 (gather () (let ((pairs `(,e ,@@-holes ,b))
1292 (push (buffer-substring-no-properties
1293 (cadr pairs) (car pairs))
1295 (setq pairs (cddr pairs)))
1296 (apply 'concat acc)))
1297 (k-one@ (name &optional later) (tok+val 'to-one@ name
1302 (goto-char (point-min))
1304 (setq context 'headers)
1305 (flet ((hpush (name &optional proc)
1306 (push (k-semi name proc) headers)))
1313 (mapcar (lambda (together)
1314 (let ((two (split-string together ":")))
1315 (setcar two (intern (car two)))
1316 (setcdr two (cadr two))
1319 (buffer-substring-no-properties b e)))))
1321 (push `(strict . ,(when (at 'strict)
1322 (search-forward ";")
1326 (push (k-one@ 'comment) headers)
1327 (search-forward ";"))
1329 (push (k-one@ 'expand) headers)
1330 (search-forward ";"))
1331 (setq headers (nreverse headers))
1333 (sw) (setq context 'rev-headers)
1334 (while (looking-at "[0-9]")
1338 (let ((ls (mapcar 'string-to-number
1340 (buffer-substring-no-properties
1343 ;; Hack the year -- verified to be the
1344 ;; same algorithm used in RCS 5.7.
1345 (when (< (car ls) 100)
1346 (setcar ls (+ 1900 (car ls))))
1347 (apply 'encode-time (nreverse ls)))))
1348 ,@(mapcar 'k-semi '(author state))
1352 (buffer-substring-no-properties b e))))
1356 (setq revs (nreverse revs))
1358 (sw) (setq context 'desc
1359 desc (k-one@ 'desc))
1362 ;; Element of `revs' that initially holds only header info.
1363 ;; "Pairwise combination" occurs when we add body info.
1365 ;; Components of the editing commands (aside from the actual
1366 ;; text) that comprise the `text' printed representations
1367 ;; (not including the "head" revision).
1369 ;; Ascending (reversed) `@-holes' which the internal func
1370 ;; `incg' pops to effect incremental gathering.
1372 ;; Function to extract text (for the `a' command), either
1373 ;; `incg' or `buffer-substring-no-properties'. (This is
1374 ;; for speed; strictly speaking, it is sufficient to use
1375 ;; only the former since it behaves identically to the
1376 ;; latter in the absense of "@@".)
1378 (flet ((incg (beg end) (let ((b beg) (e end) @-holes)
1379 (while (and asc (< (car asc) e))
1380 (push (pop asc) @-holes))
1381 ;; Self-deprecate when work is done.
1382 ;; Folding many dimensions into one.
1383 ;; Thanks B.Mandelbrot, for complex sum.
1384 ;; O beauteous math! --the Unvexed Bum
1386 (setq sub 'buffer-substring-no-properties))
1390 (setq context (to-eol)
1391 rev (or (assoc context revs)
1392 (error "Rev `%s' has body but no head"
1394 (push (k-one@ 'log) (cdr rev))
1395 ;; For rev body `text' tags, delay translation slightly...
1396 (push (k-one@ 'text t) (cdr rev))
1397 ;; ... until we decide which tag and value is appropriate to
1398 ;; collect. For the "head" revision, compute the value of the
1399 ;; `text' printed representation by simple `gather'. For all
1400 ;; other revisions, replace the `text' tag+value with `:insn'
1401 ;; plus value, always scanning in-place.
1402 (if (string= context (cdr (assq 'head headers)))
1403 (setcdr (cadr rev) (gather))
1405 (setq asc (nreverse @-holes)
1407 (setq sub 'buffer-substring-no-properties))
1410 (while (< (point) e)
1412 (setq cmd (char-before)
1413 start (read (current-buffer))
1414 act (read (current-buffer)))
1418 ;; `d' means "delete lines".
1419 ;; For Emacs spirit, we use `k' for "kill".
1422 ;; `a' means "append after this line" but
1423 ;; internally we normalize it so that START
1424 ;; specifies the actual line for insert, thus
1425 ;; requiring less hair in the realization algs.
1426 ;; For Emacs spirit, we use `i' for "insert".
1428 ,(funcall sub (point) (progn (forward-line act)
1430 (t (error "Bad command `%c' in `text' for rev `%s'"
1434 (setcar (cdr rev) (cons :insn acc)))))))
1436 `((headers ,desc ,@headers)
1437 (revisions ,@revs)))))
1441 ;; arch-tag: 759b4916-5b0d-431d-b647-b185b8c652cf
1442 ;;; vc-rcs.el ends here