1 ;;; vc-rcs.el --- support for RCS version-control
3 ;; Copyright (C) 1992-2011 Free Software Foundation, Inc.
5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; Some features will not work with ancient RCS versions. Where
29 ;; appropriate, VC finds out which version you have, and allows or
30 ;; disallows those features.
32 ;; You can support the RCS -x option by customizing vc-rcs-master-templates.
37 ;;; Customization options
44 (defcustom vc-rcs-release nil
45 "The release number of your RCS installation, as a string.
46 If nil, VC itself computes this value when it is first needed."
47 :type
'(choice (const :tag
"Auto" nil
)
48 (string :tag
"Specified")
49 (const :tag
"Unknown" unknown
))
52 (defcustom vc-rcs-register-switches nil
53 "Switches for registering a file in RCS.
54 A string or list of strings passed to the checkin program by
55 \\[vc-register]. If nil, use the value of `vc-register-switches'.
56 If t, use no switches."
57 :type
'(choice (const :tag
"Unspecified" nil
)
59 (string :tag
"Argument String")
60 (repeat :tag
"Argument List" :value
("") string
))
64 (defcustom vc-rcs-diff-switches nil
65 "String or list of strings specifying switches for RCS diff under VC.
66 If nil, use the value of `vc-diff-switches'. If t, use no switches."
67 :type
'(choice (const :tag
"Unspecified" nil
)
69 (string :tag
"Argument String")
70 (repeat :tag
"Argument List" :value
("") string
))
74 (defcustom vc-rcs-header
'("\$Id\$")
75 "Header keywords to be inserted by `vc-insert-headers'."
76 :type
'(repeat string
)
77 :version
"24.1" ; no longer consult the obsolete vc-header-alist
80 (defcustom vc-rcsdiff-knows-brief nil
81 "Indicates whether rcsdiff understands the --brief option.
82 The value is either `yes', `no', or nil. If it is nil, VC tries
83 to use --brief and sets this variable to remember whether it worked."
84 :type
'(choice (const :tag
"Work out" nil
) (const yes
) (const no
))
88 (defcustom vc-rcs-master-templates
89 (purecopy '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
90 "Where to look for RCS master files.
91 For a description of possible values, see `vc-check-master-templates'."
92 :type
'(choice (const :tag
"Use standard RCS file names"
93 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
94 (repeat :tag
"User-specified"
101 ;;; Properties of the backend
103 (defun vc-rcs-revision-granularity () 'file
)
105 (defun vc-rcs-checkout-model (files)
106 "RCS-specific version of `vc-checkout-model'."
107 (let ((file (if (consp files
) (car files
) files
))
109 (when vc-consult-headers
110 (vc-file-setprop file
'vc-checkout-model nil
)
111 (vc-rcs-consult-headers file
)
112 (setq result
(vc-file-getprop file
'vc-checkout-model
)))
114 (progn (vc-rcs-fetch-master-state file
)
115 (vc-file-getprop file
'vc-checkout-model
)))))
118 ;;; State-querying functions
121 ;; The autoload cookie below places vc-rcs-registered directly into
122 ;; loaddefs.el, so that vc-rcs.el does not need to be loaded for
123 ;; every file that is visited.
126 (defun vc-rcs-registered (f) (vc-default-registered 'RCS f
)))
128 (defun vc-rcs-state (file)
129 "Implementation of `vc-state' for RCS."
130 (if (not (vc-rcs-registered file
))
132 (or (boundp 'vc-rcs-headers-result
)
133 (and vc-consult-headers
134 (vc-rcs-consult-headers file
)))
136 ;; vc-working-revision might not be known; in that case the
137 ;; property is nil. vc-rcs-fetch-master-state knows how to
139 (vc-rcs-fetch-master-state file
140 (vc-file-getprop file
141 'vc-working-revision
))))
142 (if (not (eq state
'up-to-date
))
144 (if (vc-workfile-unchanged-p file
)
146 (if (eq (vc-rcs-checkout-model (list file
)) 'locking
)
150 (defun vc-rcs-state-heuristic (file)
151 "State heuristic for RCS."
152 (let (vc-rcs-headers-result)
153 (if (and vc-consult-headers
154 (setq vc-rcs-headers-result
155 (vc-rcs-consult-headers file
))
156 (eq vc-rcs-headers-result
'rev-and-lock
))
157 (let ((state (vc-file-getprop file
'vc-state
)))
158 ;; If the headers say that the file is not locked, the
159 ;; permissions can tell us whether locking is used for
161 (if (and (eq state
'up-to-date
)
162 (not (vc-mistrust-permissions file
))
163 (file-exists-p file
))
165 ((string-match ".rw..-..-." (nth 8 (file-attributes file
)))
166 (vc-file-setprop file
'vc-checkout-model
'implicit
)
168 (if (vc-rcs-workfile-is-newer file
)
171 ((string-match ".r-..-..-." (nth 8 (file-attributes file
)))
172 (vc-file-setprop file
'vc-checkout-model
'locking
))))
174 (if (not (vc-mistrust-permissions file
))
175 (let* ((attributes (file-attributes file
'string
))
176 (owner-name (nth 2 attributes
))
177 (permissions (nth 8 attributes
)))
178 (cond ((and permissions
(string-match ".r-..-..-." permissions
))
179 (vc-file-setprop file
'vc-checkout-model
'locking
)
181 ((and permissions
(string-match ".rw..-..-." permissions
))
182 (if (eq (vc-rcs-checkout-model file
) 'locking
)
183 (if (file-ownership-preserved-p file
)
186 (if (vc-rcs-workfile-is-newer file
)
190 ;; Strange permissions. Fall through to
191 ;; expensive state computation.
192 (vc-rcs-state file
))))
193 (vc-rcs-state file
)))))
195 (defun vc-rcs-dir-status (dir update-function
)
196 ;; FIXME: this function should be rewritten or `vc-expand-dirs'
197 ;; should be changed to take a backend parameter. Using
198 ;; `vc-expand-dirs' is not TRTD because it returns files from
199 ;; multiple backends. It should also return 'unregistered files.
201 ;; Doing individual vc-state calls is painful but there
202 ;; is no better way in RCS-land.
203 (let ((flist (vc-expand-dirs (list dir
)))
206 (let ((state (vc-state file
))
207 (frel (file-relative-name file
)))
208 (when (and (eq (vc-backend file
) 'RCS
)
209 (not (eq state
'up-to-date
)))
210 (push (list frel state
) result
))))
211 (funcall update-function result
)))
213 (defun vc-rcs-working-revision (file)
214 "RCS-specific version of `vc-working-revision'."
215 (or (and vc-consult-headers
216 (vc-rcs-consult-headers file
)
217 (vc-file-getprop file
'vc-working-revision
))
219 (vc-rcs-fetch-master-state file
)
220 (vc-file-getprop file
'vc-working-revision
))))
222 (defun vc-rcs-latest-on-branch-p (file &optional version
)
223 "Return non-nil if workfile version of FILE is the latest on its branch.
224 When VERSION is given, perform check for that version."
225 (unless version
(setq version
(vc-working-revision file
)))
228 (if (vc-rcs-trunk-p version
)
230 ;; Compare VERSION to the head version number.
231 (vc-insert-file (vc-name file
) "^[0-9]")
232 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
233 ;; If we are not on the trunk, we need to examine the
234 ;; whole current branch.
235 (vc-insert-file (vc-name file
) "^desc")
236 (vc-rcs-find-most-recent-rev (vc-branch-part version
))))))
238 (defun vc-rcs-workfile-unchanged-p (file)
239 "RCS-specific implementation of `vc-workfile-unchanged-p'."
240 ;; Try to use rcsdiff --brief. If rcsdiff does not understand that,
241 ;; do a double take and remember the fact for the future
242 (let* ((version (concat "-r" (vc-working-revision file
)))
243 (status (if (eq vc-rcsdiff-knows-brief
'no
)
244 (vc-do-command "*vc*" 1 "rcsdiff" file version
)
245 (vc-do-command "*vc*" 2 "rcsdiff" file
"--brief" version
))))
247 (if (not vc-rcsdiff-knows-brief
)
248 (setq vc-rcsdiff-knows-brief
'no
249 status
(vc-do-command "*vc*" 1 "rcsdiff" file version
))
250 (error "rcsdiff failed"))
251 (if (not vc-rcsdiff-knows-brief
) (setq vc-rcsdiff-knows-brief
'yes
)))
252 ;; The workfile is unchanged if rcsdiff found no differences.
257 ;;; State-changing functions
260 (defun vc-rcs-create-repo ()
261 "Create a new RCS repository."
262 ;; RCS is totally file-oriented, so all we have to do is make the directory.
263 (make-directory "RCS"))
265 (defun vc-rcs-register (files &optional rev comment
)
266 "Register FILES into the RCS version-control system.
267 REV is the optional revision number for the files. COMMENT can be used
268 to provide an initial description for each FILES.
269 Passes either `vc-rcs-register-switches' or `vc-register-switches'
272 Automatically retrieve a read-only version of the file with keywords
273 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
275 ;; When REV is specified, we need to force using "-t-".
276 (when rev
(unless comment
(setq comment
"")))
278 (and (not (file-exists-p
279 (setq subdir
(expand-file-name "RCS"
280 (file-name-directory file
)))))
281 (not (directory-files (file-name-directory file
)
283 (yes-or-no-p "Create RCS subdirectory? ")
284 (make-directory subdir
))
285 (apply 'vc-do-command
"*vc*" 0 "ci" file
286 ;; if available, use the secure registering option
287 (and (vc-rcs-release-p "5.6.4") "-i")
288 (concat (if vc-keep-workfiles
"-u" "-r") rev
)
289 (and comment
(concat "-t-" comment
))
290 (vc-switches 'RCS
'register
))
291 ;; parse output to find master file name and workfile version
292 (with-current-buffer "*vc*"
293 (goto-char (point-min))
295 (if (looking-at (concat "^\\(.*\\) <-- "
296 (file-name-nondirectory file
)))
298 ;; if we couldn't find the master name,
299 ;; run vc-rcs-registered to get it
300 ;; (will be stored into the vc-name property)
301 (vc-rcs-registered file
)
302 (vc-file-setprop file
'vc-name
303 (if (file-name-absolute-p name
)
307 (file-name-directory file
))))))
308 (vc-file-setprop file
'vc-working-revision
309 (if (re-search-forward
310 "^initial revision: \\([0-9.]+\\).*\n"
312 (match-string 1))))))
314 (defun vc-rcs-responsible-p (file)
315 "Return non-nil if RCS thinks it would be responsible for registering FILE."
316 ;; TODO: check for all the patterns in vc-rcs-master-templates
317 (file-directory-p (expand-file-name "RCS" (file-name-directory file
))))
319 (defun vc-rcs-receive-file (file rev
)
320 "Implementation of receive-file for RCS."
321 (let ((checkout-model (vc-rcs-checkout-model (list file
))))
322 (vc-rcs-register file rev
"")
323 (when (eq checkout-model
'implicit
)
324 (vc-rcs-set-non-strict-locking file
))
325 (vc-rcs-set-default-branch file
(concat rev
".1"))))
327 (defun vc-rcs-unregister (file)
328 "Unregister FILE from RCS.
329 If this leaves the RCS subdirectory empty, ask the user
330 whether to remove it."
331 (let* ((master (vc-name file
))
332 (dir (file-name-directory master
))
333 (backup-info (find-backup-file-name master
)))
334 (if (not backup-info
)
336 (rename-file master
(car backup-info
) 'ok-if-already-exists
)
337 (dolist (f (cdr backup-info
)) (ignore-errors (delete-file f
))))
338 (and (string= (file-name-nondirectory (directory-file-name dir
)) "RCS")
339 ;; check whether RCS dir is empty, i.e. it does not
340 ;; contain any files except "." and ".."
341 (not (directory-files dir nil
342 "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*"))
343 (yes-or-no-p (format "Directory %s is empty; remove it? " dir
))
344 (delete-directory dir
))))
346 (defun vc-rcs-checkin (files rev comment
)
347 "RCS-specific version of `vc-backend-checkin'."
348 (let ((switches (vc-switches 'RCS
'checkin
)))
349 ;; Now operate on the files
350 (dolist (file (vc-expand-dirs files
))
351 (let ((old-version (vc-working-revision file
)) new-version
352 (default-branch (vc-file-getprop file
'vc-rcs-default-branch
)))
353 ;; Force branch creation if an appropriate
354 ;; default branch has been set.
357 (string-match (concat "^" (regexp-quote old-version
) "\\.")
359 (setq rev default-branch
)
360 (setq switches
(cons "-f" switches
)))
361 (if (and (not rev
) old-version
)
362 (setq rev
(vc-branch-part old-version
)))
363 (apply 'vc-do-command
"*vc*" 0 "ci" (vc-name file
)
364 ;; if available, use the secure check-in option
365 (and (vc-rcs-release-p "5.6.4") "-j")
366 (concat (if vc-keep-workfiles
"-u" "-r") rev
)
367 (concat "-m" comment
)
369 (vc-file-setprop file
'vc-working-revision nil
)
371 ;; determine the new workfile version
373 (goto-char (point-min))
374 (when (or (re-search-forward
375 "new revision: \\([0-9.]+\\);" nil t
)
377 "reverting to previous revision \\([0-9.]+\\)" nil t
))
378 (setq new-version
(match-string 1))
379 (vc-file-setprop file
'vc-working-revision new-version
))
381 ;; if we got to a different branch, adjust the default
382 ;; branch accordingly
384 ((and old-version new-version
385 (not (string= (vc-branch-part old-version
)
386 (vc-branch-part new-version
))))
387 (vc-rcs-set-default-branch file
388 (if (vc-rcs-trunk-p new-version
) nil
389 (vc-branch-part new-version
)))
390 ;; If this is an old (pre-1992!) RCS release, we might have
391 ;; to remove a remaining lock.
392 (if (not (vc-rcs-release-p "5.6.2"))
393 ;; exit status of 1 is also accepted.
394 ;; It means that the lock was removed before.
395 (vc-do-command "*vc*" 1 "rcs" (vc-name file
)
396 (concat "-u" old-version
)))))))))
398 (defun vc-rcs-find-revision (file rev buffer
)
399 (apply 'vc-do-command
400 (or buffer
"*vc*") 0 "co" (vc-name file
)
401 "-q" ;; suppress diagnostic output
403 (vc-switches 'RCS
'checkout
)))
405 (defun vc-rcs-checkout (file &optional editable rev
)
406 "Retrieve a copy of a saved version of FILE. If FILE is a directory,
407 attempt the checkout for all registered files beneath it."
408 (if (file-directory-p file
)
409 (mapc 'vc-rcs-checkout
(vc-expand-dirs (list file
)))
410 (let ((file-buffer (get-file-buffer file
))
412 (message "Checking out %s..." file
)
414 ;; Change buffers to get local value of vc-checkout-switches.
415 (if file-buffer
(set-buffer file-buffer
))
416 (setq switches
(vc-switches 'RCS
'checkout
))
417 ;; Save this buffer's default-directory
418 ;; and use save-excursion to make sure it is restored
419 ;; in the same buffer it was saved in.
420 (let ((default-directory default-directory
))
422 ;; Adjust the default-directory so that the check-out creates
423 ;; the file in the right place.
424 (setq default-directory
(file-name-directory file
))
426 ;; if we should go to the head of the trunk,
427 ;; clear the default branch first
428 (and rev
(string= rev
"")
429 (vc-rcs-set-default-branch file nil
))
430 ;; now do the checkout
431 (apply 'vc-do-command
432 "*vc*" 0 "co" (vc-name file
)
433 ;; If locking is not strict, force to overwrite
434 ;; the writable workfile.
435 (if (eq (vc-rcs-checkout-model (list file
)) 'implicit
) "-f")
438 ;; a literal revision was specified
440 (let ((workrev (vc-working-revision file
)))
444 ;; no revision specified:
445 ;; use current workfile version
448 (if (not (vc-rcs-trunk-p workrev
))
449 ;; ... go to head of current branch
450 (vc-branch-part workrev
)
451 ;; ... go to head of trunk
452 (vc-rcs-set-default-branch file
456 ;; determine the new workfile version
457 (with-current-buffer "*vc*"
459 (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1)))
460 (vc-file-setprop file
'vc-working-revision new-version
)
461 ;; if necessary, adjust the default branch
462 (and rev
(not (string= rev
""))
463 (vc-rcs-set-default-branch
465 (if (vc-rcs-latest-on-branch-p file new-version
)
466 (if (vc-rcs-trunk-p new-version
) nil
467 (vc-branch-part new-version
))
469 (message "Checking out %s...done" file
))))))
471 (defun vc-rcs-rollback (files)
472 "Roll back, undoing the most recent checkins of FILES. Directories are
473 expanded to all registered subfiles in them."
475 (error "RCS backend doesn't support directory-level rollback"))
476 (dolist (file (vc-expand-dirs files
))
477 (let* ((discard (vc-working-revision file
))
478 (previous (if (vc-rcs-trunk-p discard
) "" (vc-branch-part discard
)))
479 (config (current-window-configuration))
481 (if (null (yes-or-no-p (format "Remove version %s from %s history? "
484 (message "Removing revision %s from %s." discard file
)
485 (vc-do-command "*vc*" 0 "rcs" (vc-name file
) (concat "-o" discard
))
486 ;; Check out the most recent remaining version. If it
487 ;; fails, because the whole branch got deleted, do a
488 ;; double-take and check out the version where the branch
493 (vc-do-command "*vc*" 0 "co" (vc-name file
) "-f"
494 (concat "-u" previous
))
496 (error (set-buffer "*vc*")
497 (goto-char (point-min))
498 (if (search-forward "no side branches present for" nil t
)
499 (progn (setq previous
(vc-branch-part previous
))
500 (vc-rcs-set-default-branch file previous
)
501 ;; vc-do-command popped up a window with
502 ;; the error message. Get rid of it, by
503 ;; restoring the old window configuration.
504 (set-window-configuration config
))
505 ;; No, it was some other error: re-signal it.
506 (signal (car err
) (cdr err
)))))))))
508 (defun vc-rcs-revert (file &optional contents-done
)
509 "Revert FILE to the version it was based on. If FILE is a directory,
510 revert all registered files beneath it."
511 (if (file-directory-p file
)
512 (mapc 'vc-rcs-revert
(vc-expand-dirs (list file
)))
513 (vc-do-command "*vc*" 0 "co" (vc-name file
) "-f"
514 (concat (if (eq (vc-state file
) 'edited
) "-u" "-r")
515 (vc-working-revision file
)))))
517 (defun vc-rcs-merge (file first-version
&optional second-version
)
518 "Merge changes into current working copy of FILE.
519 The changes are between FIRST-VERSION and SECOND-VERSION."
520 (vc-do-command "*vc*" 1 "rcsmerge" (vc-name file
)
521 "-kk" ; ignore keyword conflicts
522 (concat "-r" first-version
)
523 (if second-version
(concat "-r" second-version
))))
525 (defun vc-rcs-steal-lock (file &optional rev
)
526 "Steal the lock on the current workfile for FILE and revision REV.
527 If FILE is a directory, steal the lock on all registered files beneath it.
528 Needs RCS 5.6.2 or later for -M."
529 (if (file-directory-p file
)
530 (mapc 'vc-rcs-steal-lock
(vc-expand-dirs (list file
)))
531 (vc-do-command "*vc*" 0 "rcs" (vc-name file
) "-M" (concat "-u" rev
))
532 ;; Do a real checkout after stealing the lock, so that we see
534 (vc-do-command "*vc*" 0 "co" (vc-name file
) "-f" (concat "-l" rev
))))
536 (defun vc-rcs-modify-change-comment (files rev comment
)
537 "Modify the change comments change on FILES on a specified REV. If FILE is a
538 directory the operation is applied to all registered files beneath it."
539 (dolist (file (vc-expand-dirs files
))
540 (vc-do-command "*vc*" 0 "rcs" (vc-name file
)
541 (concat "-m" rev
":" comment
))))
545 ;;; History functions
548 (defun vc-rcs-print-log-cleanup ()
549 (let ((inhibit-read-only t
))
550 (goto-char (point-max))
552 (while (looking-at "=*\n")
553 (delete-char (- (match-end 0) (match-beginning 0)))
555 (goto-char (point-min))
556 (when (looking-at "[\b\t\n\v\f\r ]+")
557 (delete-char (- (match-end 0) (match-beginning 0))))))
559 (defun vc-rcs-print-log (files buffer
&optional shortlog start-revision-ignored limit
)
560 "Get change log associated with FILE. If FILE is a
561 directory the operation is applied to all registered files beneath it."
562 (vc-do-command (or buffer
"*vc*") 0 "rlog" (mapcar 'vc-name
(vc-expand-dirs files
)))
563 (with-current-buffer (or buffer
"*vc*")
564 (vc-rcs-print-log-cleanup))
565 (when limit
'limit-unsupported
))
567 (defun vc-rcs-diff (files &optional oldvers newvers buffer
)
568 "Get a difference report using RCS between two sets of files."
569 (apply 'vc-do-command
(or buffer
"*vc-diff*")
570 1 ;; Always go synchronous, the repo is local
571 "rcsdiff" (vc-expand-dirs files
)
573 (and oldvers
(concat "-r" oldvers
))
574 (and newvers
(concat "-r" newvers
)))
575 (vc-switches 'RCS
'diff
))))
577 (defun vc-rcs-comment-history (file)
578 "Return a string with all log entries stored in BACKEND for FILE."
579 (with-current-buffer "*vc*"
580 ;; Has to be written this way, this function is used by the CVS backend too
581 (vc-call-backend (vc-backend file
) 'print-log
(list file
))
583 (let ((separator (concat "^-+\nrevision [0-9.]+\ndate: .*\n"
584 "\\(branches: .*;\n\\)?"
585 "\\(\\*\\*\\* empty log message \\*\\*\\*\n\\)?")))
586 (goto-char (point-max)) (forward-line -
1)
587 (while (looking-at "=*\n")
588 (delete-char (- (match-end 0) (match-beginning 0)))
590 (goto-char (point-min))
591 (if (looking-at "[\b\t\n\v\f\r ]+")
592 (delete-char (- (match-end 0) (match-beginning 0))))
593 (goto-char (point-min))
594 (re-search-forward separator nil t
)
595 (delete-region (point-min) (point))
596 (while (re-search-forward separator nil t
)
597 (delete-region (match-beginning 0) (match-end 0))))
598 ;; Return the de-crufted comment list
601 (defun vc-rcs-annotate-command (file buffer
&optional revision
)
602 "Annotate FILE, inserting the results in BUFFER.
603 Optional arg REVISION is a revision to annotate from."
604 (vc-setup-buffer buffer
)
605 ;; Aside from the "head revision on the trunk", the instructions for
606 ;; each revision on the trunk are an ordered list of kill and insert
607 ;; commands necessary to go from the chronologically-following
608 ;; revision to this one. That is, associated with revision N are
609 ;; edits that applied to revision N+1 would result in revision N.
611 ;; On a branch, however, (some) things are inverted: the commands
612 ;; listed are those necessary to go from the chronologically-preceding
613 ;; revision to this one. That is, associated with revision N are
614 ;; edits that applied to revision N-1 would result in revision N.
616 ;; So, to get per-line history info, we apply reverse-chronological
617 ;; edits, starting with the head revision on the trunk, all the way
618 ;; back through the initial revision (typically "1.1" or similar),
619 ;; then apply forward-chronological edits -- keeping track of which
620 ;; revision is associated with each inserted line -- until we reach
621 ;; the desired revision for display (which may be either on the trunk
623 (let* ((tree (with-temp-buffer
624 (insert-file-contents (vc-rcs-registered file
))
626 (revisions (cdr (assq 'revisions tree
)))
627 ;; The revision N whose instructions we currently are processing.
628 (cur (cdr (assq 'head
(cdr (assq 'headers tree
)))))
629 ;; Alist from the parse tree for N.
630 (meta (cdr (assoc cur revisions
)))
631 ;; Point and temporary string, respectively.
633 ;; "Next-branch list". Nil means the desired revision to
634 ;; display lives on the trunk. Non-nil means it lives on a
635 ;; branch, in which case the value is a list of revision pairs
636 ;; (PARENT . CHILD), the first PARENT being on the trunk, that
637 ;; links each series of revisions in the path from the initial
638 ;; revision to the desired revision to display.
640 ;; "Path-accumulate-predicate plus revision/date/author".
641 ;; Until set, forward-chronological edits are not accumulated.
642 ;; Once set, its value (updated every revision) is used for
643 ;; the text property `:vc-rcs-r/d/a' for inserts during
644 ;; processing of forward-chronological instructions for N.
645 ;; See internal func `r/d/a'.
647 ;; List of forward-chronological instructions, each of the
648 ;; form: (POS . ACTION), where POS is a buffer position. If
649 ;; ACTION is a string, it is inserted, otherwise it is taken as
650 ;; the number of characters to be deleted.
652 ;; N+1. When `cur' is "", this is the initial revision.
656 (unless (assoc revision revisions
)
657 (error "No such revision: %s" revision
))
658 ;; Find which branches (if any) must be included in the edits.
661 (while (setq bpt
(vc-branch-part par
)
662 par
(vc-branch-part bpt
))
663 (setq kids
(cdr (assq 'branches
(cdr (assoc par revisions
)))))
664 ;; A branchpoint may have multiple children. Find the right one.
665 (while (not (string= bpt
(vc-branch-part (car kids
))))
666 (setq kids
(cdr kids
)))
667 (push (cons par
(car kids
)) nbls
)))
668 ;; Start with the full text.
670 (insert (cdr (assq 'text meta
)))
671 ;; Apply reverse-chronological edits on the trunk, computing and
672 ;; accumulating forward-chronological edits after some point, for
674 (flet ((r/d
/a
() (vector pre
675 (cdr (assq 'date meta
))
676 (cdr (assq 'author meta
)))))
677 (while (when (setq pre cur cur
(cdr (assq 'next meta
)))
678 (not (string= "" cur
)))
680 ;; Start accumulating the forward-chronological edits when N+1
681 ;; on the trunk is either the desired revision to display, or
682 ;; the appropriate branchpoint for it. Do this before
683 ;; updating `meta' since `r/d/a' uses N+1's `meta' value.
684 prda
(when (or prda
(string= (if nbls
(caar nbls
) revision
) pre
))
686 meta
(cdr (assoc cur revisions
)))
687 ;; Edits in the parse tree specify a line number (in the buffer
688 ;; *BEFORE* editing occurs) to start from, but line numbers
689 ;; change as a result of edits. To DTRT, we apply edits in
690 ;; order of descending buffer position so that edits further
691 ;; down in the buffer occur first w/o corrupting specified
692 ;; buffer positions of edits occurring towards the beginning of
693 ;; the buffer. In this way we avoid using markers. A pleasant
694 ;; property of this approach is ability to push instructions
695 ;; onto `path' directly, w/o need to maintain rev boundaries.
696 (dolist (insn (cdr (assq :insn meta
)))
697 (goto-char (point-min))
698 (forward-line (1- (pop insn
)))
701 (k (setq s
(buffer-substring-no-properties
702 p
(progn (forward-line (car insn
))
705 (push `(,p .
,(propertize s
:vc-rcs-r
/d
/a prda
)) path
))
706 (delete-region p
(point)))
707 (i (setq s
(car insn
))
709 (push `(,p .
,(length s
)) path
))
711 ;; For the initial revision, setting `:vc-rcs-r/d/a' directly is
712 ;; equivalent to pushing an insert instruction (of the entire buffer
713 ;; contents) onto `path' then erasing the buffer, but less wasteful.
714 (put-text-property (point-min) (point-max) :vc-rcs-r
/d
/a
(r/d
/a
))
715 ;; Now apply the forward-chronological edits for the trunk.
717 (goto-char (pop insn
))
721 ;; Now apply the forward-chronological edits (directly from the
722 ;; parse-tree) for the branch(es), if necessary. We re-use vars
723 ;; `pre' and `meta' for the sake of internal func `r/d/a'.
725 (setq pre
(cdr (pop nbls
)))
727 (setq meta
(cdr (assoc pre revisions
))
729 (dolist (insn (cdr (assq :insn meta
)))
730 (goto-char (point-min))
731 (forward-line (1- (pop insn
)))
734 (point) (progn (forward-line (car insn
))
736 (i (insert (propertize
739 (or prda
(setq prda
(r/d
/a
))))))))
740 (prog1 (not (string= (if nbls
(caar nbls
) revision
) pre
))
741 (setq pre
(cdr (assq 'next meta
)))))))))
742 ;; Lastly, for each line, insert at bol nicely-formatted history info.
743 ;; We do two passes to collect summary information used to minimize
744 ;; the annotation's usage of screen real-estate: (1) Consider rendered
745 ;; width of revision plus author together as a unit; and (2) Omit
746 ;; author entirely if all authors are the same as the user.
747 (let ((ht (make-hash-table :test
'eq
))
748 (me (user-login-name))
752 (goto-char (point-max))
755 (setq rda
(get-text-property (point) :vc-rcs-r
/d
/a
))
756 (unless (gethash rda ht
)
758 all-me
(and all-me
(string= a me
)))
759 (puthash rda
(setq w
(+ (length (aref rda
0))
762 (setq maxw
(max w maxw
))))
763 (let ((padding (make-string maxw
32)))
764 (flet ((pad (w) (substring-no-properties padding w
))
765 (render (rda &rest ls
)
768 (format-time-string "%Y-%m-%d" (aref rda
1))
772 :vc-annotate-prefix t
777 (puthash rda
(render rda
(pad w
) ": ") ht
))
779 (puthash rda
(render rda
" " (pad w
) " " (aref rda
2) ": ") ht
)))
782 (insert (gethash (get-text-property (point) :vc-rcs-r
/d
/a
) ht
))
785 (declare-function vc-annotate-convert-time
"vc-annotate" (time))
787 (defun vc-rcs-annotate-current-time ()
788 "Return the current time, based at midnight of the current day, and
789 encoded as fractional days."
790 (vc-annotate-convert-time
791 (apply 'encode-time
0 0 0 (nthcdr 3 (decode-time (current-time))))))
793 (defun vc-rcs-annotate-time ()
794 "Return the time of the next annotation (as fraction of days)
795 systime, or nil if there is none. Also, reposition point."
797 (prog1 (vc-annotate-convert-time
798 (aref (get-text-property (point) :vc-rcs-r
/d
/a
) 1))
799 (goto-char (next-single-property-change (point) :vc-annotate-prefix
)))))
801 (defun vc-rcs-annotate-extract-revision-at-line ()
802 (aref (get-text-property (point) :vc-rcs-r
/d
/a
) 0))
809 (defun vc-rcs-create-tag (backend dir name branchp
)
811 (error "RCS backend %s does not support module branches" backend
))
812 (let ((result (vc-tag-precondition dir
)))
814 (error "File %s is not up-to-date" result
)
818 (vc-do-command "*vc*" 0 "rcs" (vc-name f
) (concat "-n" name
":")))))))
825 (defun vc-rcs-trunk-p (rev)
826 "Return t if REV is a revision on the trunk."
827 (not (eq nil
(string-match "\\`[0-9]+\\.[0-9]+\\'" rev
))))
829 (defun vc-rcs-minor-part (rev)
830 "Return the minor revision number of a revision number REV."
831 (string-match "[0-9]+\\'" rev
)
832 (substring rev
(match-beginning 0) (match-end 0)))
834 (defun vc-rcs-previous-revision (file rev
)
835 "Return the revision number immediately preceding REV for FILE,
836 or nil if there is no previous revision. This default
837 implementation works for MAJOR.MINOR-style revision numbers as
838 used by RCS and CVS."
839 (let ((branch (vc-branch-part rev
))
840 (minor-num (string-to-number (vc-rcs-minor-part rev
))))
843 ;; revision does probably not start a branch or release
844 (concat branch
"." (number-to-string (1- minor-num
)))
845 (if (vc-rcs-trunk-p rev
)
846 ;; we are at the beginning of the trunk --
847 ;; don't know anything to return here
849 ;; we are at the beginning of a branch --
850 ;; return revision of starting point
851 (vc-branch-part branch
))))))
853 (defun vc-rcs-next-revision (file rev
)
854 "Return the revision number immediately following REV for FILE,
855 or nil if there is no next revision. This default implementation
856 works for MAJOR.MINOR-style revision numbers as used by RCS
858 (when (not (string= rev
(vc-working-revision file
)))
859 (let ((branch (vc-branch-part rev
))
860 (minor-num (string-to-number (vc-rcs-minor-part rev
))))
861 (concat branch
"." (number-to-string (1+ minor-num
))))))
863 (defun vc-rcs-update-changelog (files)
864 "Default implementation of update-changelog.
865 Uses `rcs2log' which only works for RCS and CVS."
866 ;; FIXME: We (c|sh)ould add support for cvs2cl
867 (let ((odefault default-directory
)
868 (changelog (find-change-log))
869 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
870 (tempfile (make-temp-file
871 (expand-file-name "vc"
872 (or small-temporary-file-directory
873 temporary-file-directory
))))
874 (login-name (or user-login-name
875 (format "uid%d" (number-to-string (user-uid)))))
876 (full-name (or add-log-full-name
879 (format "uid%d" (number-to-string (user-uid)))))
880 (mailing-address (or add-log-mailing-address
882 (find-file-other-window changelog
)
883 (barf-if-buffer-read-only)
886 (goto-char (point-min))
888 (message "Computing change log entries...")
889 (message "Computing change log entries... %s"
892 (setq default-directory odefault
)
893 (if (eq 0 (apply 'call-process
894 (expand-file-name "rcs2log"
896 nil
(list t tempfile
) nil
898 "-u" (concat login-name
900 "\t" mailing-address
)
904 (expand-file-name f odefault
)))
907 (pop-to-buffer (get-buffer-create "*vc*"))
909 (insert-file-contents tempfile
)
911 (setq default-directory
(file-name-directory changelog
))
912 (delete-file tempfile
)))))
914 (defun vc-rcs-check-headers ()
915 "Check if the current file has any headers in it."
917 (goto-char (point-min))
918 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
919 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
921 (defun vc-rcs-clear-headers ()
922 "Implementation of vc-clear-headers for RCS."
923 (let ((case-fold-search nil
))
924 (goto-char (point-min))
925 (while (re-search-forward
926 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
927 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
929 (replace-match "$\\1$"))))
931 (defun vc-rcs-rename-file (old new
)
932 ;; Just move the master file (using vc-rcs-master-templates).
933 (vc-rename-master (vc-name old
) new vc-rcs-master-templates
))
935 (defun vc-rcs-find-file-hook ()
936 ;; If the file is locked by some other user, make
937 ;; the buffer read-only. Like this, even root
938 ;; cannot modify a file that someone else has locked.
939 (and (stringp (vc-state buffer-file-name
'RCS
))
940 (setq buffer-read-only t
)))
944 ;;; Internal functions
947 (defun vc-rcs-workfile-is-newer (file)
948 "Return non-nil if FILE is newer than its RCS master.
949 This likely means that FILE has been changed with respect
950 to its master version."
951 (let ((file-time (nth 5 (file-attributes file
)))
952 (master-time (nth 5 (file-attributes (vc-name file
)))))
953 (or (> (nth 0 file-time
) (nth 0 master-time
))
954 (and (= (nth 0 file-time
) (nth 0 master-time
))
955 (> (nth 1 file-time
) (nth 1 master-time
))))))
957 (defun vc-rcs-find-most-recent-rev (branch)
958 "Find most recent revision on BRANCH."
959 (goto-char (point-min))
960 (let ((latest-rev -
1) value
)
961 (while (re-search-forward (concat "^\\(" (regexp-quote branch
)
962 "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;")
964 (let ((rev (string-to-number (match-string 2))))
965 (when (< latest-rev rev
)
966 (setq latest-rev rev
)
967 (setq value
(match-string 1)))))
969 (vc-branch-part branch
))))
971 (defun vc-rcs-fetch-master-state (file &optional working-revision
)
972 "Compute the master file's idea of the state of FILE.
973 If a WORKING-REVISION is given, compute the state of that version,
974 otherwise determine the workfile version based on the master file.
975 This function sets the properties `vc-working-revision' and
976 `vc-checkout-model' to their correct values, based on the master
979 (if (or (not (vc-insert-file (vc-name file
) "^[0-9]"))
980 (progn (goto-char (point-min))
981 (not (looking-at "^head[ \t\n]+[^;]+;$"))))
982 (error "File %s is not an RCS master file" (vc-name file
)))
983 (let ((workfile-is-latest nil
)
984 (default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1)))
985 (vc-file-setprop file
'vc-rcs-default-branch default-branch
)
986 (unless working-revision
987 ;; Workfile version not known yet. Determine that first. It
988 ;; is either the head of the trunk, the head of the default
989 ;; branch, or the "default branch" itself, if that is a full
993 ((or (not default-branch
) (string= "" default-branch
))
994 (setq working-revision
995 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
996 (setq workfile-is-latest t
))
997 ;; default branch is actually a revision
998 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
1000 (setq working-revision default-branch
))
1001 ;; else, search for the head of the default branch
1002 (t (vc-insert-file (vc-name file
) "^desc")
1003 (setq working-revision
1004 (vc-rcs-find-most-recent-rev default-branch
))
1005 (setq workfile-is-latest t
)))
1006 (vc-file-setprop file
'vc-working-revision working-revision
))
1007 ;; Check strict locking
1008 (goto-char (point-min))
1009 (vc-file-setprop file
'vc-checkout-model
1010 (if (re-search-forward ";[ \t\n]*strict;" nil t
)
1011 'locking
'implicit
))
1012 ;; Compute state of workfile version
1013 (goto-char (point-min))
1015 (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):"
1016 (regexp-quote working-revision
)
1022 (if (or workfile-is-latest
1023 (vc-rcs-latest-on-branch-p file working-revision
))
1024 ;; workfile version is latest on branch
1026 ;; workfile version is not latest on branch
1028 ;; locked by the calling user
1029 ((and (stringp locking-user
)
1030 (string= locking-user
(vc-user-login-name file
)))
1031 ;; Don't call `vc-rcs-checkout-model' to avoid inf-looping.
1032 (if (or (eq (vc-file-getprop file
'vc-checkout-model
) 'locking
)
1034 (vc-rcs-latest-on-branch-p file working-revision
))
1036 ;; Locking is not used for the file, but the owner does
1037 ;; have a lock, and there is a higher version on the current
1038 ;; branch. Not sure if this can occur, and if it is right
1039 ;; to use `needs-merge' in this case.
1041 ;; locked by somebody else
1042 ((stringp locking-user
)
1045 (error "Error getting state of RCS file")))))))
1047 (defun vc-rcs-consult-headers (file)
1048 "Search for RCS headers in FILE, and set properties accordingly.
1050 Returns: nil if no headers were found
1051 'rev if a workfile revision was found
1052 'rev-and-lock if revision and lock info was found"
1054 ((not (get-file-buffer file
)) nil
)
1055 ((let (status version locking-user
)
1056 (with-current-buffer (get-file-buffer file
)
1058 (goto-char (point-min))
1060 ;; search for $Id or $Header
1061 ;; -------------------------
1062 ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file.
1063 ((or (and (search-forward "$Id\ : " nil t
)
1064 (looking-at "[^ ]+ \\([0-9.]+\\) "))
1065 (and (progn (goto-char (point-min))
1066 (search-forward "$Header\ : " nil t
))
1067 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
1068 (goto-char (match-end 0))
1069 ;; if found, store the revision number ...
1070 (setq version
(match-string-no-properties 1))
1071 ;; ... and check for the locking state
1074 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
1075 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
1076 "[^ ]+ [^ ]+ ")) ; author & state
1077 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
1079 ;; unlocked revision
1081 (setq locking-user
'none
)
1082 (setq status
'rev-and-lock
))
1083 ;; revision is locked by some user
1084 ((looking-at "\\([^ ]+\\) \\$")
1085 (setq locking-user
(match-string-no-properties 1))
1086 (setq status
'rev-and-lock
))
1087 ;; everything else: false
1089 ;; unexpected information in
1090 ;; keyword string --> quit
1092 ;; search for $Revision
1093 ;; --------------------
1094 ((re-search-forward (concat "\\$"
1095 "Revision: \\([0-9.]+\\) \\$")
1097 ;; if found, store the revision number ...
1098 (setq version
(match-string-no-properties 1))
1099 ;; and see if there's any lock information
1100 (goto-char (point-min))
1101 (if (re-search-forward (concat "\\$" "Locker:") nil t
)
1102 (cond ((looking-at " \\([^ ]+\\) \\$")
1103 (setq locking-user
(match-string-no-properties 1))
1104 (setq status
'rev-and-lock
))
1105 ((looking-at " *\\$")
1106 (setq locking-user
'none
)
1107 (setq status
'rev-and-lock
))
1109 (setq locking-user
'none
)
1110 (setq status
'rev-and-lock
)))
1111 (setq status
'rev
)))
1112 ;; else: nothing found
1113 ;; -------------------
1115 (if status
(vc-file-setprop file
'vc-working-revision version
))
1116 (and (eq status
'rev-and-lock
)
1117 (vc-file-setprop file
'vc-state
1119 ((eq locking-user
'none
) 'up-to-date
)
1120 ((string= locking-user
(vc-user-login-name file
))
1123 ;; If the file has headers, we don't want to query the
1124 ;; master file, because that would eliminate all the
1125 ;; performance gain the headers brought us. We therefore
1126 ;; use a heuristic now to find out whether locking is used
1127 ;; for this file. If we trust the file permissions, and the
1128 ;; file is not locked, then if the file is read-only we
1129 ;; assume that locking is used for the file, otherwise
1130 ;; locking is not used.
1131 (not (vc-mistrust-permissions file
))
1132 (vc-up-to-date-p file
)
1133 (if (string-match ".r-..-..-." (nth 8 (file-attributes file
)))
1134 (vc-file-setprop file
'vc-checkout-model
'locking
)
1135 (vc-file-setprop file
'vc-checkout-model
'implicit
)))
1138 (defun vc-release-greater-or-equal (r1 r2
)
1139 "Compare release numbers, represented as strings.
1140 Release components are assumed cardinal numbers, not decimal fractions
1141 \(5.10 is a higher release than 5.9\). Omitted fields are considered
1142 lower \(5.6.7 is earlier than 5.6.7.1\). Comparison runs till the end
1143 of the string is found, or a non-numeric component shows up \(5.6.7 is
1144 earlier than \"5.6.7 beta\", which is probably not what you want in
1145 some cases\). This code is suitable for existing RCS release numbers.
1146 CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5\)."
1149 (or (and (string-match "^\\.?\\([0-9]+\\)" r1
)
1150 (setq i1
(match-end 0))
1151 (setq v1
(string-to-number (match-string 1 r1
)))
1152 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
1153 (setq i2
(match-end 0))
1154 (setq v2
(string-to-number (match-string 1 r2
)))
1155 (if (> v1 v2
) (throw 'done t
)
1156 (if (< v1 v2
) (throw 'done nil
)
1158 (vc-release-greater-or-equal
1160 (substring r2 i2
)))))))
1162 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
1166 (defun vc-rcs-release-p (release)
1167 "Return t if we have RELEASE or better."
1168 (let ((installation (vc-rcs-system-release)))
1169 (if (and installation
1170 (not (eq installation
'unknown
)))
1171 (vc-release-greater-or-equal installation release
))))
1173 (defun vc-rcs-system-release ()
1174 "Return the RCS release installed on this system, as a string.
1175 Return symbol `unknown' if the release cannot be deducted. The user can
1176 override this using variable `vc-rcs-release'.
1178 If the user has not set variable `vc-rcs-release' and it is nil,
1179 variable `vc-rcs-release' is set to the returned value."
1181 (setq vc-rcs-release
1182 (or (and (zerop (vc-do-command "*vc*" nil
"rcs" nil
"-V"))
1183 (with-current-buffer (get-buffer "*vc*")
1184 (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1)))
1187 (defun vc-rcs-set-non-strict-locking (file)
1188 (vc-do-command "*vc*" 0 "rcs" file
"-U")
1189 (vc-file-setprop file
'vc-checkout-model
'implicit
)
1190 (set-file-modes file
(logior (file-modes file
) 128)))
1192 (defun vc-rcs-set-default-branch (file branch
)
1193 (vc-do-command "*vc*" 0 "rcs" (vc-name file
) (concat "-b" branch
))
1194 (vc-file-setprop file
'vc-rcs-default-branch branch
))
1196 (defun vc-rcs-parse (&optional buffer
)
1197 "Parse current buffer, presumed to be in RCS-style masterfile format.
1198 Optional arg BUFFER specifies another buffer to parse. Return an alist
1199 of two elements, w/ keys `headers' and `revisions' and values in turn
1200 sub-alists. For `headers', the values unless otherwise specified are
1201 strings and the keys are:
1204 head -- latest revision
1205 branch -- the branch the \"head revision\" lies on;
1206 absent if the head revision lies on the trunk
1208 symbols -- sub-alist of (SYMBOL . REVISION) elements
1209 locks -- if file is checked out, something like \"ttn:1.7\"
1210 strict -- t if \"strict locking\" is in effect, otherwise nil
1211 comment -- may be absent; typically something like \"# \" or \"; \"
1212 expand -- may be absent; ???
1214 For `revisions', the car is REVISION (string), the cdr a sub-alist,
1215 with string values (unless otherwise specified) and keys:
1217 date -- a time value (like that returned by `encode-time'); as a
1218 special case, a year value less than 100 is augmented by 1900
1220 state -- typically \"Exp\" or \"Rel\"
1221 branches -- list of revisions that begin branches from this revision
1222 next -- on the trunk: the chronologically-preceding revision, or \"\";
1223 on a branch: the chronologically-following revision, or \"\"
1224 log -- change log entry
1225 text -- for the head revision on the trunk, the body of the file;
1226 other revisions have `:insn' instead
1227 :insn -- for non-head revisions, a list of parsed instructions
1228 in one of two forms, in both cases START meaning \"first
1230 - `(START k COUNT)' -- kill COUNT lines
1231 - `(START i TEXT)' -- insert TEXT (a string)
1232 The list is in descending order by START.
1234 The `:insn' key is a keyword to distinguish it as a vc-rcs.el extension."
1235 (setq buffer
(get-buffer (or buffer
(current-buffer))))
1237 ;; An RCS masterfile can be viewed as containing four regular (for the
1238 ;; most part) sections: (a) the "headers", (b) the "rev headers", (c)
1239 ;; the "description" and (d) the "rev bodies", in that order. In the
1240 ;; returned alist (see docstring), elements from (b) and (d) are
1241 ;; combined pairwise to form the "revisions", while those from (a) and
1242 ;; (c) are simply combined to form the "headers".
1244 ;; Loosely speaking, each section contains a series of alternating
1245 ;; "tags" and "printed representations". In the (b) and (d), many
1246 ;; such series can appear, and a revision number on a line by itself
1247 ;; precedes the series of tags and printed representations associated
1250 ;; In (a) and (b), the printed representations (with the exception of
1251 ;; the `comment' tag in the headers) terminate with a semicolon, which
1252 ;; is NOT part of the "value" finally associated with the tag. All
1253 ;; other printed representations are in "@@-format"; there is an "@",
1254 ;; the middle part (to be translated into the value), another "@" and
1255 ;; a newline. Each "@@" in the middle part indicates the position of
1256 ;; a single "@" (and consequently the requirement of an additional
1257 ;; initial step when translating to the value).
1259 ;; Parser state includes vars that collect parts of the return value...
1260 (let ((desc nil
) (headers nil
) (revs nil
)
1261 ;; ... as well as vars that support a single-pass, tag-assisted,
1262 ;; minimal-data-copying scan. Basically -- skirting around the
1263 ;; grouping by revision required in (b) and (d) -- we repeatedly
1264 ;; and context-sensitively read a tag (that MUST be present),
1265 ;; determine the bounds of the printed representation, translate
1266 ;; it into a value, and push the tag plus value onto one of the
1267 ;; collection vars. Finally, we return the parse tree
1268 ;; incorporating the values of the collection vars (see "rv").
1270 ;; A symbol or string to keep track of context (for error messages).
1272 ;; A symbol, the current tag.
1274 ;; Region (begin and end buffer positions) of the printed
1275 ;; representation for the current tag.
1277 ;; A list of buffer positions where "@@" can be found within the
1278 ;; printed representation region. For each location, we push two
1279 ;; elements onto the list, 1+ and 2+ the location, respectively,
1280 ;; with the 2+ appearing at the head. In this way, the expression
1281 ;; `(,e ,@@-holes ,b)
1282 ;; describes regions that can be concatenated (in reverse order)
1283 ;; to "de-@@-format" the printed representation as the first step
1284 ;; to translating it into some value. See internal func `gather'.
1286 (flet ((sw () (skip-chars-forward " \t\n")) ; i.e., `[:space:]'
1287 (at (tag) (save-excursion (eq tag
(read buffer
))))
1288 (to-eol () (buffer-substring-no-properties
1289 (point) (progn (forward-line 1)
1291 (to-semi () (setq b
(point)
1292 e
(progn (search-forward ";")
1294 (to-one@ () (setq @-holes nil
1295 b
(progn (search-forward "@") (point))
1296 e
(progn (while (and (search-forward "@")
1299 (push (point) @-holes
)
1301 (push (point) @-holes
))))
1303 (tok+val
(set-b+e name
&optional proc
)
1304 (unless (eq name
(setq tok
(read buffer
)))
1305 (error "Missing `%s' while parsing %s" name context
))
1310 (buffer-substring-no-properties b e
))))
1311 (k-semi (name &optional proc
) (tok+val
'to-semi name proc
))
1312 (gather () (let ((pairs `(,e
,@@-holes
,b
))
1315 (push (buffer-substring-no-properties
1316 (cadr pairs
) (car pairs
))
1318 (setq pairs
(cddr pairs
)))
1319 (apply 'concat acc
)))
1320 (k-one@ (name &optional later
) (tok+val
'to-one
@ name
1325 (goto-char (point-min))
1327 (setq context
'headers
)
1328 (flet ((hpush (name &optional proc
)
1329 (push (k-semi name proc
) headers
)))
1336 (mapcar (lambda (together)
1337 (let ((two (split-string together
":")))
1338 (setcar two
(intern (car two
)))
1339 (setcdr two
(cadr two
))
1342 (buffer-substring-no-properties b e
)))))
1344 (push `(strict .
,(when (at 'strict
)
1345 (search-forward ";")
1349 (push (k-one@ 'comment
) headers
)
1350 (search-forward ";"))
1352 (push (k-one@ 'expand
) headers
)
1353 (search-forward ";"))
1354 (setq headers
(nreverse headers
))
1356 (sw) (setq context
'rev-headers
)
1357 (while (looking-at "[0-9]")
1361 (let ((ls (mapcar 'string-to-number
1363 (buffer-substring-no-properties
1366 ;; Hack the year -- verified to be the
1367 ;; same algorithm used in RCS 5.7.
1368 (when (< (car ls
) 100)
1369 (setcar ls
(+ 1900 (car ls
))))
1370 (apply 'encode-time
(nreverse ls
)))))
1371 ,@(mapcar 'k-semi
'(author state
))
1375 (buffer-substring-no-properties b e
))))
1379 (setq revs
(nreverse revs
))
1381 (sw) (setq context
'desc
1382 desc
(k-one@ 'desc
))
1385 ;; Element of `revs' that initially holds only header info.
1386 ;; "Pairwise combination" occurs when we add body info.
1388 ;; Components of the editing commands (aside from the actual
1389 ;; text) that comprise the `text' printed representations
1390 ;; (not including the "head" revision).
1392 ;; Ascending (reversed) `@-holes' which the internal func
1393 ;; `incg' pops to effect incremental gathering.
1395 ;; Function to extract text (for the `a' command), either
1396 ;; `incg' or `buffer-substring-no-properties'. (This is
1397 ;; for speed; strictly speaking, it is sufficient to use
1398 ;; only the former since it behaves identically to the
1399 ;; latter in the absense of "@@".)
1401 (flet ((incg (beg end
) (let ((b beg
) (e end
) @-holes
)
1402 (while (and asc
(< (car asc
) e
))
1403 (push (pop asc
) @-holes
))
1404 ;; Self-deprecate when work is done.
1405 ;; Folding many dimensions into one.
1406 ;; Thanks B.Mandelbrot, for complex sum.
1407 ;; O beauteous math! --the Unvexed Bum
1409 (setq sub
'buffer-substring-no-properties
))
1413 (setq context
(to-eol)
1414 rev
(or (assoc context revs
)
1415 (error "Rev `%s' has body but no head"
1417 (push (k-one@ 'log
) (cdr rev
))
1418 ;; For rev body `text' tags, delay translation slightly...
1419 (push (k-one@ 'text t
) (cdr rev
))
1420 ;; ... until we decide which tag and value is appropriate to
1421 ;; collect. For the "head" revision, compute the value of the
1422 ;; `text' printed representation by simple `gather'. For all
1423 ;; other revisions, replace the `text' tag+value with `:insn'
1424 ;; plus value, always scanning in-place.
1425 (if (string= context
(cdr (assq 'head headers
)))
1426 (setcdr (cadr rev
) (gather))
1428 (setq asc
(nreverse @-holes
)
1430 (setq sub
'buffer-substring-no-properties
))
1433 (while (< (point) e
)
1435 (setq cmd
(char-before)
1436 start
(read (current-buffer))
1437 act
(read (current-buffer)))
1441 ;; `d' means "delete lines".
1442 ;; For Emacs spirit, we use `k' for "kill".
1445 ;; `a' means "append after this line" but
1446 ;; internally we normalize it so that START
1447 ;; specifies the actual line for insert, thus
1448 ;; requiring less hair in the realization algs.
1449 ;; For Emacs spirit, we use `i' for "insert".
1451 ,(funcall sub
(point) (progn (forward-line act
)
1453 (t (error "Bad command `%c' in `text' for rev `%s'"
1457 (setcar (cdr rev
) (cons :insn acc
)))))))
1459 `((headers ,desc
,@headers
)
1460 (revisions ,@revs
)))))
1464 ;;; vc-rcs.el ends here