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 old RCS versions. Where
29 ;; appropriate, VC finds out which version you have, and allows or
30 ;; disallows those features (stealing locks, for example, works only
31 ;; from 5.6.2 onwards).
32 ;; Even initial checkins will fail if your RCS version is so old that ci
33 ;; doesn't understand -t-; this has been known to happen to people running
36 ;; You can support the RCS -x option by customizing vc-rcs-master-templates.
41 ;;; Customization options
48 (defcustom vc-rcs-release nil
49 "The release number of your RCS installation, as a string.
50 If nil, VC itself computes this value when it is first needed."
51 :type
'(choice (const :tag
"Auto" nil
)
52 (string :tag
"Specified")
53 (const :tag
"Unknown" unknown
))
56 (defcustom vc-rcs-register-switches nil
57 "Switches for registering a file in RCS.
58 A string or list of strings passed to the checkin program by
59 \\[vc-register]. If nil, use the value of `vc-register-switches'.
60 If t, use no switches."
61 :type
'(choice (const :tag
"Unspecified" nil
)
63 (string :tag
"Argument String")
64 (repeat :tag
"Argument List" :value
("") string
))
68 (defcustom vc-rcs-diff-switches nil
69 "String or list of strings specifying switches for RCS diff under VC.
70 If nil, use the value of `vc-diff-switches'. If t, use no switches."
71 :type
'(choice (const :tag
"Unspecified" nil
)
73 (string :tag
"Argument String")
74 (repeat :tag
"Argument List" :value
("") string
))
78 (defcustom vc-rcs-header
'("\$Id\$")
79 "Header keywords to be inserted by `vc-insert-headers'."
80 :type
'(repeat string
)
81 :version
"24.1" ; no longer consult the obsolete vc-header-alist
84 (defcustom vc-rcsdiff-knows-brief nil
85 "Indicates whether rcsdiff understands the --brief option.
86 The value is either `yes', `no', or nil. If it is nil, VC tries
87 to use --brief and sets this variable to remember whether it worked."
88 :type
'(choice (const :tag
"Work out" nil
) (const yes
) (const no
))
92 (defcustom vc-rcs-master-templates
93 (purecopy '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
94 "Where to look for RCS master files.
95 For a description of possible values, see `vc-check-master-templates'."
96 :type
'(choice (const :tag
"Use standard RCS file names"
97 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
98 (repeat :tag
"User-specified"
105 ;;; Properties of the backend
107 (defun vc-rcs-revision-granularity () 'file
)
109 (defun vc-rcs-checkout-model (files)
110 "RCS-specific version of `vc-checkout-model'."
111 (let ((file (if (consp files
) (car files
) files
))
113 (when vc-consult-headers
114 (vc-file-setprop file
'vc-checkout-model nil
)
115 (vc-rcs-consult-headers file
)
116 (setq result
(vc-file-getprop file
'vc-checkout-model
)))
118 (progn (vc-rcs-fetch-master-state file
)
119 (vc-file-getprop file
'vc-checkout-model
)))))
122 ;;; State-querying functions
125 ;; The autoload cookie below places vc-rcs-registered directly into
126 ;; loaddefs.el, so that vc-rcs.el does not need to be loaded for
127 ;; every file that is visited.
130 (defun vc-rcs-registered (f) (vc-default-registered 'RCS f
)))
132 (defun vc-rcs-state (file)
133 "Implementation of `vc-state' for RCS."
134 (if (not (vc-rcs-registered file
))
136 (or (boundp 'vc-rcs-headers-result
)
137 (and vc-consult-headers
138 (vc-rcs-consult-headers file
)))
140 ;; vc-working-revision might not be known; in that case the
141 ;; property is nil. vc-rcs-fetch-master-state knows how to
143 (vc-rcs-fetch-master-state file
144 (vc-file-getprop file
145 'vc-working-revision
))))
146 (if (not (eq state
'up-to-date
))
148 (if (vc-workfile-unchanged-p file
)
150 (if (eq (vc-rcs-checkout-model (list file
)) 'locking
)
154 (defun vc-rcs-state-heuristic (file)
155 "State heuristic for RCS."
156 (let (vc-rcs-headers-result)
157 (if (and vc-consult-headers
158 (setq vc-rcs-headers-result
159 (vc-rcs-consult-headers file
))
160 (eq vc-rcs-headers-result
'rev-and-lock
))
161 (let ((state (vc-file-getprop file
'vc-state
)))
162 ;; If the headers say that the file is not locked, the
163 ;; permissions can tell us whether locking is used for
165 (if (and (eq state
'up-to-date
)
166 (not (vc-mistrust-permissions file
))
167 (file-exists-p file
))
169 ((string-match ".rw..-..-." (nth 8 (file-attributes file
)))
170 (vc-file-setprop file
'vc-checkout-model
'implicit
)
172 (if (vc-rcs-workfile-is-newer file
)
175 ((string-match ".r-..-..-." (nth 8 (file-attributes file
)))
176 (vc-file-setprop file
'vc-checkout-model
'locking
))))
178 (if (not (vc-mistrust-permissions file
))
179 (let* ((attributes (file-attributes file
'string
))
180 (owner-name (nth 2 attributes
))
181 (permissions (nth 8 attributes
)))
182 (cond ((and permissions
(string-match ".r-..-..-." permissions
))
183 (vc-file-setprop file
'vc-checkout-model
'locking
)
185 ((and permissions
(string-match ".rw..-..-." permissions
))
186 (if (eq (vc-rcs-checkout-model file
) 'locking
)
187 (if (file-ownership-preserved-p file
)
190 (if (vc-rcs-workfile-is-newer file
)
194 ;; Strange permissions. Fall through to
195 ;; expensive state computation.
196 (vc-rcs-state file
))))
197 (vc-rcs-state file
)))))
199 (defun vc-rcs-dir-status (dir update-function
)
200 ;; FIXME: this function should be rewritten or `vc-expand-dirs'
201 ;; should be changed to take a backend parameter. Using
202 ;; `vc-expand-dirs' is not TRTD because it returns files from
203 ;; multiple backends. It should also return 'unregistered files.
205 ;; Doing individual vc-state calls is painful but there
206 ;; is no better way in RCS-land.
207 (let ((flist (vc-expand-dirs (list dir
)))
210 (let ((state (vc-state file
))
211 (frel (file-relative-name file
)))
212 (when (and (eq (vc-backend file
) 'RCS
)
213 (not (eq state
'up-to-date
)))
214 (push (list frel state
) result
))))
215 (funcall update-function result
)))
217 (defun vc-rcs-working-revision (file)
218 "RCS-specific version of `vc-working-revision'."
219 (or (and vc-consult-headers
220 (vc-rcs-consult-headers file
)
221 (vc-file-getprop file
'vc-working-revision
))
223 (vc-rcs-fetch-master-state file
)
224 (vc-file-getprop file
'vc-working-revision
))))
226 (defun vc-rcs-latest-on-branch-p (file &optional version
)
227 "Return non-nil if workfile version of FILE is the latest on its branch.
228 When VERSION is given, perform check for that version."
229 (unless version
(setq version
(vc-working-revision file
)))
232 (if (vc-rcs-trunk-p version
)
234 ;; Compare VERSION to the head version number.
235 (vc-insert-file (vc-name file
) "^[0-9]")
236 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
237 ;; If we are not on the trunk, we need to examine the
238 ;; whole current branch.
239 (vc-insert-file (vc-name file
) "^desc")
240 (vc-rcs-find-most-recent-rev (vc-branch-part version
))))))
242 (defun vc-rcs-workfile-unchanged-p (file)
243 "RCS-specific implementation of `vc-workfile-unchanged-p'."
244 ;; Try to use rcsdiff --brief. If rcsdiff does not understand that,
245 ;; do a double take and remember the fact for the future
246 (let* ((version (concat "-r" (vc-working-revision file
)))
247 (status (if (eq vc-rcsdiff-knows-brief
'no
)
248 (vc-do-command "*vc*" 1 "rcsdiff" file version
)
249 (vc-do-command "*vc*" 2 "rcsdiff" file
"--brief" version
))))
251 (if (not vc-rcsdiff-knows-brief
)
252 (setq vc-rcsdiff-knows-brief
'no
253 status
(vc-do-command "*vc*" 1 "rcsdiff" file version
))
254 (error "rcsdiff failed"))
255 (if (not vc-rcsdiff-knows-brief
) (setq vc-rcsdiff-knows-brief
'yes
)))
256 ;; The workfile is unchanged if rcsdiff found no differences.
261 ;;; State-changing functions
264 (defun vc-rcs-create-repo ()
265 "Create a new RCS repository."
266 ;; RCS is totally file-oriented, so all we have to do is make the directory.
267 (make-directory "RCS"))
269 (defun vc-rcs-register (files &optional rev comment
)
270 "Register FILES into the RCS version-control system.
271 REV is the optional revision number for the files. COMMENT can be used
272 to provide an initial description for each FILES.
273 Passes either `vc-rcs-register-switches' or `vc-register-switches'
276 Automatically retrieve a read-only version of the file with keywords
277 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
279 ;; When REV is specified, we need to force using "-t-".
280 (when rev
(unless comment
(setq comment
"")))
282 (and (not (file-exists-p
283 (setq subdir
(expand-file-name "RCS"
284 (file-name-directory file
)))))
285 (not (directory-files (file-name-directory file
)
287 (yes-or-no-p "Create RCS subdirectory? ")
288 (make-directory subdir
))
289 (apply 'vc-do-command
"*vc*" 0 "ci" file
290 ;; if available, use the secure registering option
291 (and (vc-rcs-release-p "5.6.4") "-i")
292 (concat (if vc-keep-workfiles
"-u" "-r") rev
)
293 (and comment
(concat "-t-" comment
))
294 (vc-switches 'RCS
'register
))
295 ;; parse output to find master file name and workfile version
296 (with-current-buffer "*vc*"
297 (goto-char (point-min))
299 (if (looking-at (concat "^\\(.*\\) <-- "
300 (file-name-nondirectory file
)))
302 ;; if we couldn't find the master name,
303 ;; run vc-rcs-registered to get it
304 ;; (will be stored into the vc-name property)
305 (vc-rcs-registered file
)
306 (vc-file-setprop file
'vc-name
307 (if (file-name-absolute-p name
)
311 (file-name-directory file
))))))
312 (vc-file-setprop file
'vc-working-revision
313 (if (re-search-forward
314 "^initial revision: \\([0-9.]+\\).*\n"
316 (match-string 1))))))
318 (defun vc-rcs-responsible-p (file)
319 "Return non-nil if RCS thinks it would be responsible for registering FILE."
320 ;; TODO: check for all the patterns in vc-rcs-master-templates
321 (file-directory-p (expand-file-name "RCS" (file-name-directory file
))))
323 (defun vc-rcs-receive-file (file rev
)
324 "Implementation of receive-file for RCS."
325 (let ((checkout-model (vc-rcs-checkout-model (list file
))))
326 (vc-rcs-register file rev
"")
327 (when (eq checkout-model
'implicit
)
328 (vc-rcs-set-non-strict-locking file
))
329 (vc-rcs-set-default-branch file
(concat rev
".1"))))
331 (defun vc-rcs-unregister (file)
332 "Unregister FILE from RCS.
333 If this leaves the RCS subdirectory empty, ask the user
334 whether to remove it."
335 (let* ((master (vc-name file
))
336 (dir (file-name-directory master
))
337 (backup-info (find-backup-file-name master
)))
338 (if (not backup-info
)
340 (rename-file master
(car backup-info
) 'ok-if-already-exists
)
341 (dolist (f (cdr backup-info
)) (ignore-errors (delete-file f
))))
342 (and (string= (file-name-nondirectory (directory-file-name dir
)) "RCS")
343 ;; check whether RCS dir is empty, i.e. it does not
344 ;; contain any files except "." and ".."
345 (not (directory-files dir nil
346 "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*"))
347 (yes-or-no-p (format "Directory %s is empty; remove it? " dir
))
348 (delete-directory dir
))))
350 (defun vc-rcs-checkin (files rev comment
)
351 "RCS-specific version of `vc-backend-checkin'."
352 (let ((switches (vc-switches 'RCS
'checkin
)))
353 ;; Now operate on the files
354 (dolist (file (vc-expand-dirs files
))
355 (let ((old-version (vc-working-revision file
)) new-version
356 (default-branch (vc-file-getprop file
'vc-rcs-default-branch
)))
357 ;; Force branch creation if an appropriate
358 ;; default branch has been set.
361 (string-match (concat "^" (regexp-quote old-version
) "\\.")
363 (setq rev default-branch
)
364 (setq switches
(cons "-f" switches
)))
365 (if (and (not rev
) old-version
)
366 (setq rev
(vc-branch-part old-version
)))
367 (apply 'vc-do-command
"*vc*" 0 "ci" (vc-name file
)
368 ;; if available, use the secure check-in option
369 (and (vc-rcs-release-p "5.6.4") "-j")
370 (concat (if vc-keep-workfiles
"-u" "-r") rev
)
371 (concat "-m" comment
)
373 (vc-file-setprop file
'vc-working-revision nil
)
375 ;; determine the new workfile version
377 (goto-char (point-min))
378 (when (or (re-search-forward
379 "new revision: \\([0-9.]+\\);" nil t
)
381 "reverting to previous revision \\([0-9.]+\\)" nil t
))
382 (setq new-version
(match-string 1))
383 (vc-file-setprop file
'vc-working-revision new-version
))
385 ;; if we got to a different branch, adjust the default
386 ;; branch accordingly
388 ((and old-version new-version
389 (not (string= (vc-branch-part old-version
)
390 (vc-branch-part new-version
))))
391 (vc-rcs-set-default-branch file
392 (if (vc-rcs-trunk-p new-version
) nil
393 (vc-branch-part new-version
)))
394 ;; If this is an old RCS release, we might have
395 ;; to remove a remaining lock.
396 (if (not (vc-rcs-release-p "5.6.2"))
397 ;; exit status of 1 is also accepted.
398 ;; It means that the lock was removed before.
399 (vc-do-command "*vc*" 1 "rcs" (vc-name file
)
400 (concat "-u" old-version
)))))))))
402 (defun vc-rcs-find-revision (file rev buffer
)
403 (apply 'vc-do-command
404 (or buffer
"*vc*") 0 "co" (vc-name file
)
405 "-q" ;; suppress diagnostic output
407 (vc-switches 'RCS
'checkout
)))
409 (defun vc-rcs-checkout (file &optional editable rev
)
410 "Retrieve a copy of a saved version of FILE. If FILE is a directory,
411 attempt the checkout for all registered files beneath it."
412 (if (file-directory-p file
)
413 (mapc 'vc-rcs-checkout
(vc-expand-dirs (list file
)))
414 (let ((file-buffer (get-file-buffer file
))
416 (message "Checking out %s..." file
)
418 ;; Change buffers to get local value of vc-checkout-switches.
419 (if file-buffer
(set-buffer file-buffer
))
420 (setq switches
(vc-switches 'RCS
'checkout
))
421 ;; Save this buffer's default-directory
422 ;; and use save-excursion to make sure it is restored
423 ;; in the same buffer it was saved in.
424 (let ((default-directory default-directory
))
426 ;; Adjust the default-directory so that the check-out creates
427 ;; the file in the right place.
428 (setq default-directory
(file-name-directory file
))
430 ;; if we should go to the head of the trunk,
431 ;; clear the default branch first
432 (and rev
(string= rev
"")
433 (vc-rcs-set-default-branch file nil
))
434 ;; now do the checkout
435 (apply 'vc-do-command
436 "*vc*" 0 "co" (vc-name file
)
437 ;; If locking is not strict, force to overwrite
438 ;; the writable workfile.
439 (if (eq (vc-rcs-checkout-model (list file
)) 'implicit
) "-f")
442 ;; a literal revision was specified
444 (let ((workrev (vc-working-revision file
)))
448 ;; no revision specified:
449 ;; use current workfile version
452 (if (not (vc-rcs-trunk-p workrev
))
453 ;; ... go to head of current branch
454 (vc-branch-part workrev
)
455 ;; ... go to head of trunk
456 (vc-rcs-set-default-branch file
460 ;; determine the new workfile version
461 (with-current-buffer "*vc*"
463 (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1)))
464 (vc-file-setprop file
'vc-working-revision new-version
)
465 ;; if necessary, adjust the default branch
466 (and rev
(not (string= rev
""))
467 (vc-rcs-set-default-branch
469 (if (vc-rcs-latest-on-branch-p file new-version
)
470 (if (vc-rcs-trunk-p new-version
) nil
471 (vc-branch-part new-version
))
473 (message "Checking out %s...done" file
))))))
475 (defun vc-rcs-rollback (files)
476 "Roll back, undoing the most recent checkins of FILES. Directories are
477 expanded to all registered subfiles in them."
479 (error "RCS backend doesn't support directory-level rollback"))
480 (dolist (file (vc-expand-dirs files
))
481 (let* ((discard (vc-working-revision file
))
482 (previous (if (vc-rcs-trunk-p discard
) "" (vc-branch-part discard
)))
483 (config (current-window-configuration))
485 (if (null (yes-or-no-p (format "Remove version %s from %s history? "
488 (message "Removing revision %s from %s." discard file
)
489 (vc-do-command "*vc*" 0 "rcs" (vc-name file
) (concat "-o" discard
))
490 ;; Check out the most recent remaining version. If it
491 ;; fails, because the whole branch got deleted, do a
492 ;; double-take and check out the version where the branch
497 (vc-do-command "*vc*" 0 "co" (vc-name file
) "-f"
498 (concat "-u" previous
))
500 (error (set-buffer "*vc*")
501 (goto-char (point-min))
502 (if (search-forward "no side branches present for" nil t
)
503 (progn (setq previous
(vc-branch-part previous
))
504 (vc-rcs-set-default-branch file previous
)
505 ;; vc-do-command popped up a window with
506 ;; the error message. Get rid of it, by
507 ;; restoring the old window configuration.
508 (set-window-configuration config
))
509 ;; No, it was some other error: re-signal it.
510 (signal (car err
) (cdr err
)))))))))
512 (defun vc-rcs-revert (file &optional contents-done
)
513 "Revert FILE to the version it was based on. If FILE is a directory,
514 revert all registered files beneath it."
515 (if (file-directory-p file
)
516 (mapc 'vc-rcs-revert
(vc-expand-dirs (list file
)))
517 (vc-do-command "*vc*" 0 "co" (vc-name file
) "-f"
518 (concat (if (eq (vc-state file
) 'edited
) "-u" "-r")
519 (vc-working-revision file
)))))
521 (defun vc-rcs-merge (file first-version
&optional second-version
)
522 "Merge changes into current working copy of FILE.
523 The changes are between FIRST-VERSION and SECOND-VERSION."
524 (vc-do-command "*vc*" 1 "rcsmerge" (vc-name file
)
525 "-kk" ; ignore keyword conflicts
526 (concat "-r" first-version
)
527 (if second-version
(concat "-r" second-version
))))
529 (defun vc-rcs-steal-lock (file &optional rev
)
530 "Steal the lock on the current workfile for FILE and revision REV.
531 If FILE is a directory, steal the lock on all registered files beneath it.
532 Needs RCS 5.6.2 or later for -M."
533 (if (file-directory-p file
)
534 (mapc 'vc-rcs-steal-lock
(vc-expand-dirs (list file
)))
535 (vc-do-command "*vc*" 0 "rcs" (vc-name file
) "-M" (concat "-u" rev
))
536 ;; Do a real checkout after stealing the lock, so that we see
538 (vc-do-command "*vc*" 0 "co" (vc-name file
) "-f" (concat "-l" rev
))))
540 (defun vc-rcs-modify-change-comment (files rev comment
)
541 "Modify the change comments change on FILES on a specified REV. If FILE is a
542 directory the operation is applied to all registered files beneath it."
543 (dolist (file (vc-expand-dirs files
))
544 (vc-do-command "*vc*" 0 "rcs" (vc-name file
)
545 (concat "-m" rev
":" comment
))))
549 ;;; History functions
552 (defun vc-rcs-print-log-cleanup ()
553 (let ((inhibit-read-only t
))
554 (goto-char (point-max))
556 (while (looking-at "=*\n")
557 (delete-char (- (match-end 0) (match-beginning 0)))
559 (goto-char (point-min))
560 (when (looking-at "[\b\t\n\v\f\r ]+")
561 (delete-char (- (match-end 0) (match-beginning 0))))))
563 (defun vc-rcs-print-log (files buffer
&optional shortlog start-revision-ignored limit
)
564 "Get change log associated with FILE. If FILE is a
565 directory the operation is applied to all registered files beneath it."
566 (vc-do-command (or buffer
"*vc*") 0 "rlog" (mapcar 'vc-name
(vc-expand-dirs files
)))
567 (with-current-buffer (or buffer
"*vc*")
568 (vc-rcs-print-log-cleanup))
569 (when limit
'limit-unsupported
))
571 (defun vc-rcs-diff (files &optional oldvers newvers buffer
)
572 "Get a difference report using RCS between two sets of files."
573 (apply 'vc-do-command
(or buffer
"*vc-diff*")
574 1 ;; Always go synchronous, the repo is local
575 "rcsdiff" (vc-expand-dirs files
)
577 (and oldvers
(concat "-r" oldvers
))
578 (and newvers
(concat "-r" newvers
)))
579 (vc-switches 'RCS
'diff
))))
581 (defun vc-rcs-comment-history (file)
582 "Return a string with all log entries stored in BACKEND for FILE."
583 (with-current-buffer "*vc*"
584 ;; Has to be written this way, this function is used by the CVS backend too
585 (vc-call-backend (vc-backend file
) 'print-log
(list file
))
587 (let ((separator (concat "^-+\nrevision [0-9.]+\ndate: .*\n"
588 "\\(branches: .*;\n\\)?"
589 "\\(\\*\\*\\* empty log message \\*\\*\\*\n\\)?")))
590 (goto-char (point-max)) (forward-line -
1)
591 (while (looking-at "=*\n")
592 (delete-char (- (match-end 0) (match-beginning 0)))
594 (goto-char (point-min))
595 (if (looking-at "[\b\t\n\v\f\r ]+")
596 (delete-char (- (match-end 0) (match-beginning 0))))
597 (goto-char (point-min))
598 (re-search-forward separator nil t
)
599 (delete-region (point-min) (point))
600 (while (re-search-forward separator nil t
)
601 (delete-region (match-beginning 0) (match-end 0))))
602 ;; Return the de-crufted comment list
605 (defun vc-rcs-annotate-command (file buffer
&optional revision
)
606 "Annotate FILE, inserting the results in BUFFER.
607 Optional arg REVISION is a revision to annotate from."
608 (vc-setup-buffer buffer
)
609 ;; Aside from the "head revision on the trunk", the instructions for
610 ;; each revision on the trunk are an ordered list of kill and insert
611 ;; commands necessary to go from the chronologically-following
612 ;; revision to this one. That is, associated with revision N are
613 ;; edits that applied to revision N+1 would result in revision N.
615 ;; On a branch, however, (some) things are inverted: the commands
616 ;; listed are those necessary to go from the chronologically-preceding
617 ;; revision to this one. That is, associated with revision N are
618 ;; edits that applied to revision N-1 would result in revision N.
620 ;; So, to get per-line history info, we apply reverse-chronological
621 ;; edits, starting with the head revision on the trunk, all the way
622 ;; back through the initial revision (typically "1.1" or similar),
623 ;; then apply forward-chronological edits -- keeping track of which
624 ;; revision is associated with each inserted line -- until we reach
625 ;; the desired revision for display (which may be either on the trunk
627 (let* ((tree (with-temp-buffer
628 (insert-file-contents (vc-rcs-registered file
))
630 (revisions (cdr (assq 'revisions tree
)))
631 ;; The revision N whose instructions we currently are processing.
632 (cur (cdr (assq 'head
(cdr (assq 'headers tree
)))))
633 ;; Alist from the parse tree for N.
634 (meta (cdr (assoc cur revisions
)))
635 ;; Point and temporary string, respectively.
637 ;; "Next-branch list". Nil means the desired revision to
638 ;; display lives on the trunk. Non-nil means it lives on a
639 ;; branch, in which case the value is a list of revision pairs
640 ;; (PARENT . CHILD), the first PARENT being on the trunk, that
641 ;; links each series of revisions in the path from the initial
642 ;; revision to the desired revision to display.
644 ;; "Path-accumulate-predicate plus revision/date/author".
645 ;; Until set, forward-chronological edits are not accumulated.
646 ;; Once set, its value (updated every revision) is used for
647 ;; the text property `:vc-rcs-r/d/a' for inserts during
648 ;; processing of forward-chronological instructions for N.
649 ;; See internal func `r/d/a'.
651 ;; List of forward-chronological instructions, each of the
652 ;; form: (POS . ACTION), where POS is a buffer position. If
653 ;; ACTION is a string, it is inserted, otherwise it is taken as
654 ;; the number of characters to be deleted.
656 ;; N+1. When `cur' is "", this is the initial revision.
660 (unless (assoc revision revisions
)
661 (error "No such revision: %s" revision
))
662 ;; Find which branches (if any) must be included in the edits.
665 (while (setq bpt
(vc-branch-part par
)
666 par
(vc-branch-part bpt
))
667 (setq kids
(cdr (assq 'branches
(cdr (assoc par revisions
)))))
668 ;; A branchpoint may have multiple children. Find the right one.
669 (while (not (string= bpt
(vc-branch-part (car kids
))))
670 (setq kids
(cdr kids
)))
671 (push (cons par
(car kids
)) nbls
)))
672 ;; Start with the full text.
674 (insert (cdr (assq 'text meta
)))
675 ;; Apply reverse-chronological edits on the trunk, computing and
676 ;; accumulating forward-chronological edits after some point, for
678 (flet ((r/d
/a
() (vector pre
679 (cdr (assq 'date meta
))
680 (cdr (assq 'author meta
)))))
681 (while (when (setq pre cur cur
(cdr (assq 'next meta
)))
682 (not (string= "" cur
)))
684 ;; Start accumulating the forward-chronological edits when N+1
685 ;; on the trunk is either the desired revision to display, or
686 ;; the appropriate branchpoint for it. Do this before
687 ;; updating `meta' since `r/d/a' uses N+1's `meta' value.
688 prda
(when (or prda
(string= (if nbls
(caar nbls
) revision
) pre
))
690 meta
(cdr (assoc cur revisions
)))
691 ;; Edits in the parse tree specify a line number (in the buffer
692 ;; *BEFORE* editing occurs) to start from, but line numbers
693 ;; change as a result of edits. To DTRT, we apply edits in
694 ;; order of descending buffer position so that edits further
695 ;; down in the buffer occur first w/o corrupting specified
696 ;; buffer positions of edits occurring towards the beginning of
697 ;; the buffer. In this way we avoid using markers. A pleasant
698 ;; property of this approach is ability to push instructions
699 ;; onto `path' directly, w/o need to maintain rev boundaries.
700 (dolist (insn (cdr (assq :insn meta
)))
701 (goto-char (point-min))
702 (forward-line (1- (pop insn
)))
705 (k (setq s
(buffer-substring-no-properties
706 p
(progn (forward-line (car insn
))
709 (push `(,p .
,(propertize s
:vc-rcs-r
/d
/a prda
)) path
))
710 (delete-region p
(point)))
711 (i (setq s
(car insn
))
713 (push `(,p .
,(length s
)) path
))
715 ;; For the initial revision, setting `:vc-rcs-r/d/a' directly is
716 ;; equivalent to pushing an insert instruction (of the entire buffer
717 ;; contents) onto `path' then erasing the buffer, but less wasteful.
718 (put-text-property (point-min) (point-max) :vc-rcs-r
/d
/a
(r/d
/a
))
719 ;; Now apply the forward-chronological edits for the trunk.
721 (goto-char (pop insn
))
725 ;; Now apply the forward-chronological edits (directly from the
726 ;; parse-tree) for the branch(es), if necessary. We re-use vars
727 ;; `pre' and `meta' for the sake of internal func `r/d/a'.
729 (setq pre
(cdr (pop nbls
)))
731 (setq meta
(cdr (assoc pre revisions
))
733 (dolist (insn (cdr (assq :insn meta
)))
734 (goto-char (point-min))
735 (forward-line (1- (pop insn
)))
738 (point) (progn (forward-line (car insn
))
740 (i (insert (propertize
743 (or prda
(setq prda
(r/d
/a
))))))))
744 (prog1 (not (string= (if nbls
(caar nbls
) revision
) pre
))
745 (setq pre
(cdr (assq 'next meta
)))))))))
746 ;; Lastly, for each line, insert at bol nicely-formatted history info.
747 ;; We do two passes to collect summary information used to minimize
748 ;; the annotation's usage of screen real-estate: (1) Consider rendered
749 ;; width of revision plus author together as a unit; and (2) Omit
750 ;; author entirely if all authors are the same as the user.
751 (let ((ht (make-hash-table :test
'eq
))
752 (me (user-login-name))
756 (goto-char (point-max))
759 (setq rda
(get-text-property (point) :vc-rcs-r
/d
/a
))
760 (unless (gethash rda ht
)
762 all-me
(and all-me
(string= a me
)))
763 (puthash rda
(setq w
(+ (length (aref rda
0))
766 (setq maxw
(max w maxw
))))
767 (let ((padding (make-string maxw
32)))
768 (flet ((pad (w) (substring-no-properties padding w
))
769 (render (rda &rest ls
)
772 (format-time-string "%Y-%m-%d" (aref rda
1))
776 :vc-annotate-prefix t
781 (puthash rda
(render rda
(pad w
) ": ") ht
))
783 (puthash rda
(render rda
" " (pad w
) " " (aref rda
2) ": ") ht
)))
786 (insert (gethash (get-text-property (point) :vc-rcs-r
/d
/a
) ht
))
789 (declare-function vc-annotate-convert-time
"vc-annotate" (time))
791 (defun vc-rcs-annotate-current-time ()
792 "Return the current time, based at midnight of the current day, and
793 encoded as fractional days."
794 (vc-annotate-convert-time
795 (apply 'encode-time
0 0 0 (nthcdr 3 (decode-time (current-time))))))
797 (defun vc-rcs-annotate-time ()
798 "Return the time of the next annotation (as fraction of days)
799 systime, or nil if there is none. Also, reposition point."
801 (prog1 (vc-annotate-convert-time
802 (aref (get-text-property (point) :vc-rcs-r
/d
/a
) 1))
803 (goto-char (next-single-property-change (point) :vc-annotate-prefix
)))))
805 (defun vc-rcs-annotate-extract-revision-at-line ()
806 (aref (get-text-property (point) :vc-rcs-r
/d
/a
) 0))
813 (defun vc-rcs-create-tag (backend dir name branchp
)
815 (error "RCS backend %s does not support module branches" backend
))
816 (let ((result (vc-tag-precondition dir
)))
818 (error "File %s is not up-to-date" result
)
822 (vc-do-command "*vc*" 0 "rcs" (vc-name f
) (concat "-n" name
":")))))))
829 (defun vc-rcs-trunk-p (rev)
830 "Return t if REV is a revision on the trunk."
831 (not (eq nil
(string-match "\\`[0-9]+\\.[0-9]+\\'" rev
))))
833 (defun vc-rcs-minor-part (rev)
834 "Return the minor revision number of a revision number REV."
835 (string-match "[0-9]+\\'" rev
)
836 (substring rev
(match-beginning 0) (match-end 0)))
838 (defun vc-rcs-previous-revision (file rev
)
839 "Return the revision number immediately preceding REV for FILE,
840 or nil if there is no previous revision. This default
841 implementation works for MAJOR.MINOR-style revision numbers as
842 used by RCS and CVS."
843 (let ((branch (vc-branch-part rev
))
844 (minor-num (string-to-number (vc-rcs-minor-part rev
))))
847 ;; revision does probably not start a branch or release
848 (concat branch
"." (number-to-string (1- minor-num
)))
849 (if (vc-rcs-trunk-p rev
)
850 ;; we are at the beginning of the trunk --
851 ;; don't know anything to return here
853 ;; we are at the beginning of a branch --
854 ;; return revision of starting point
855 (vc-branch-part branch
))))))
857 (defun vc-rcs-next-revision (file rev
)
858 "Return the revision number immediately following REV for FILE,
859 or nil if there is no next revision. This default implementation
860 works for MAJOR.MINOR-style revision numbers as used by RCS
862 (when (not (string= rev
(vc-working-revision file
)))
863 (let ((branch (vc-branch-part rev
))
864 (minor-num (string-to-number (vc-rcs-minor-part rev
))))
865 (concat branch
"." (number-to-string (1+ minor-num
))))))
867 (defun vc-rcs-update-changelog (files)
868 "Default implementation of update-changelog.
869 Uses `rcs2log' which only works for RCS and CVS."
870 ;; FIXME: We (c|sh)ould add support for cvs2cl
871 (let ((odefault default-directory
)
872 (changelog (find-change-log))
873 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
874 (tempfile (make-temp-file
875 (expand-file-name "vc"
876 (or small-temporary-file-directory
877 temporary-file-directory
))))
878 (login-name (or user-login-name
879 (format "uid%d" (number-to-string (user-uid)))))
880 (full-name (or add-log-full-name
883 (format "uid%d" (number-to-string (user-uid)))))
884 (mailing-address (or add-log-mailing-address
886 (find-file-other-window changelog
)
887 (barf-if-buffer-read-only)
890 (goto-char (point-min))
892 (message "Computing change log entries...")
893 (message "Computing change log entries... %s"
896 (setq default-directory odefault
)
897 (if (eq 0 (apply 'call-process
898 (expand-file-name "rcs2log"
900 nil
(list t tempfile
) nil
902 "-u" (concat login-name
904 "\t" mailing-address
)
908 (expand-file-name f odefault
)))
911 (pop-to-buffer (get-buffer-create "*vc*"))
913 (insert-file-contents tempfile
)
915 (setq default-directory
(file-name-directory changelog
))
916 (delete-file tempfile
)))))
918 (defun vc-rcs-check-headers ()
919 "Check if the current file has any headers in it."
921 (goto-char (point-min))
922 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
923 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
925 (defun vc-rcs-clear-headers ()
926 "Implementation of vc-clear-headers for RCS."
927 (let ((case-fold-search nil
))
928 (goto-char (point-min))
929 (while (re-search-forward
930 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
931 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
933 (replace-match "$\\1$"))))
935 (defun vc-rcs-rename-file (old new
)
936 ;; Just move the master file (using vc-rcs-master-templates).
937 (vc-rename-master (vc-name old
) new vc-rcs-master-templates
))
939 (defun vc-rcs-find-file-hook ()
940 ;; If the file is locked by some other user, make
941 ;; the buffer read-only. Like this, even root
942 ;; cannot modify a file that someone else has locked.
943 (and (stringp (vc-state buffer-file-name
'RCS
))
944 (setq buffer-read-only t
)))
948 ;;; Internal functions
951 (defun vc-rcs-workfile-is-newer (file)
952 "Return non-nil if FILE is newer than its RCS master.
953 This likely means that FILE has been changed with respect
954 to its master version."
955 (let ((file-time (nth 5 (file-attributes file
)))
956 (master-time (nth 5 (file-attributes (vc-name file
)))))
957 (or (> (nth 0 file-time
) (nth 0 master-time
))
958 (and (= (nth 0 file-time
) (nth 0 master-time
))
959 (> (nth 1 file-time
) (nth 1 master-time
))))))
961 (defun vc-rcs-find-most-recent-rev (branch)
962 "Find most recent revision on BRANCH."
963 (goto-char (point-min))
964 (let ((latest-rev -
1) value
)
965 (while (re-search-forward (concat "^\\(" (regexp-quote branch
)
966 "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;")
968 (let ((rev (string-to-number (match-string 2))))
969 (when (< latest-rev rev
)
970 (setq latest-rev rev
)
971 (setq value
(match-string 1)))))
973 (vc-branch-part branch
))))
975 (defun vc-rcs-fetch-master-state (file &optional working-revision
)
976 "Compute the master file's idea of the state of FILE.
977 If a WORKING-REVISION is given, compute the state of that version,
978 otherwise determine the workfile version based on the master file.
979 This function sets the properties `vc-working-revision' and
980 `vc-checkout-model' to their correct values, based on the master
983 (if (or (not (vc-insert-file (vc-name file
) "^[0-9]"))
984 (progn (goto-char (point-min))
985 (not (looking-at "^head[ \t\n]+[^;]+;$"))))
986 (error "File %s is not an RCS master file" (vc-name file
)))
987 (let ((workfile-is-latest nil
)
988 (default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1)))
989 (vc-file-setprop file
'vc-rcs-default-branch default-branch
)
990 (unless working-revision
991 ;; Workfile version not known yet. Determine that first. It
992 ;; is either the head of the trunk, the head of the default
993 ;; branch, or the "default branch" itself, if that is a full
997 ((or (not default-branch
) (string= "" default-branch
))
998 (setq working-revision
999 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
1000 (setq workfile-is-latest t
))
1001 ;; default branch is actually a revision
1002 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
1004 (setq working-revision default-branch
))
1005 ;; else, search for the head of the default branch
1006 (t (vc-insert-file (vc-name file
) "^desc")
1007 (setq working-revision
1008 (vc-rcs-find-most-recent-rev default-branch
))
1009 (setq workfile-is-latest t
)))
1010 (vc-file-setprop file
'vc-working-revision working-revision
))
1011 ;; Check strict locking
1012 (goto-char (point-min))
1013 (vc-file-setprop file
'vc-checkout-model
1014 (if (re-search-forward ";[ \t\n]*strict;" nil t
)
1015 'locking
'implicit
))
1016 ;; Compute state of workfile version
1017 (goto-char (point-min))
1019 (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):"
1020 (regexp-quote working-revision
)
1026 (if (or workfile-is-latest
1027 (vc-rcs-latest-on-branch-p file working-revision
))
1028 ;; workfile version is latest on branch
1030 ;; workfile version is not latest on branch
1032 ;; locked by the calling user
1033 ((and (stringp locking-user
)
1034 (string= locking-user
(vc-user-login-name file
)))
1035 ;; Don't call `vc-rcs-checkout-model' to avoid inf-looping.
1036 (if (or (eq (vc-file-getprop file
'vc-checkout-model
) 'locking
)
1038 (vc-rcs-latest-on-branch-p file working-revision
))
1040 ;; Locking is not used for the file, but the owner does
1041 ;; have a lock, and there is a higher version on the current
1042 ;; branch. Not sure if this can occur, and if it is right
1043 ;; to use `needs-merge' in this case.
1045 ;; locked by somebody else
1046 ((stringp locking-user
)
1049 (error "Error getting state of RCS file")))))))
1051 (defun vc-rcs-consult-headers (file)
1052 "Search for RCS headers in FILE, and set properties accordingly.
1054 Returns: nil if no headers were found
1055 'rev if a workfile revision was found
1056 'rev-and-lock if revision and lock info was found"
1058 ((not (get-file-buffer file
)) nil
)
1059 ((let (status version locking-user
)
1060 (with-current-buffer (get-file-buffer file
)
1062 (goto-char (point-min))
1064 ;; search for $Id or $Header
1065 ;; -------------------------
1066 ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file.
1067 ((or (and (search-forward "$Id\ : " nil t
)
1068 (looking-at "[^ ]+ \\([0-9.]+\\) "))
1069 (and (progn (goto-char (point-min))
1070 (search-forward "$Header\ : " nil t
))
1071 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
1072 (goto-char (match-end 0))
1073 ;; if found, store the revision number ...
1074 (setq version
(match-string-no-properties 1))
1075 ;; ... and check for the locking state
1078 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
1079 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
1080 "[^ ]+ [^ ]+ ")) ; author & state
1081 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
1083 ;; unlocked revision
1085 (setq locking-user
'none
)
1086 (setq status
'rev-and-lock
))
1087 ;; revision is locked by some user
1088 ((looking-at "\\([^ ]+\\) \\$")
1089 (setq locking-user
(match-string-no-properties 1))
1090 (setq status
'rev-and-lock
))
1091 ;; everything else: false
1093 ;; unexpected information in
1094 ;; keyword string --> quit
1096 ;; search for $Revision
1097 ;; --------------------
1098 ((re-search-forward (concat "\\$"
1099 "Revision: \\([0-9.]+\\) \\$")
1101 ;; if found, store the revision number ...
1102 (setq version
(match-string-no-properties 1))
1103 ;; and see if there's any lock information
1104 (goto-char (point-min))
1105 (if (re-search-forward (concat "\\$" "Locker:") nil t
)
1106 (cond ((looking-at " \\([^ ]+\\) \\$")
1107 (setq locking-user
(match-string-no-properties 1))
1108 (setq status
'rev-and-lock
))
1109 ((looking-at " *\\$")
1110 (setq locking-user
'none
)
1111 (setq status
'rev-and-lock
))
1113 (setq locking-user
'none
)
1114 (setq status
'rev-and-lock
)))
1115 (setq status
'rev
)))
1116 ;; else: nothing found
1117 ;; -------------------
1119 (if status
(vc-file-setprop file
'vc-working-revision version
))
1120 (and (eq status
'rev-and-lock
)
1121 (vc-file-setprop file
'vc-state
1123 ((eq locking-user
'none
) 'up-to-date
)
1124 ((string= locking-user
(vc-user-login-name file
))
1127 ;; If the file has headers, we don't want to query the
1128 ;; master file, because that would eliminate all the
1129 ;; performance gain the headers brought us. We therefore
1130 ;; use a heuristic now to find out whether locking is used
1131 ;; for this file. If we trust the file permissions, and the
1132 ;; file is not locked, then if the file is read-only we
1133 ;; assume that locking is used for the file, otherwise
1134 ;; locking is not used.
1135 (not (vc-mistrust-permissions file
))
1136 (vc-up-to-date-p file
)
1137 (if (string-match ".r-..-..-." (nth 8 (file-attributes file
)))
1138 (vc-file-setprop file
'vc-checkout-model
'locking
)
1139 (vc-file-setprop file
'vc-checkout-model
'implicit
)))
1142 (defun vc-release-greater-or-equal (r1 r2
)
1143 "Compare release numbers, represented as strings.
1144 Release components are assumed cardinal numbers, not decimal fractions
1145 \(5.10 is a higher release than 5.9\). Omitted fields are considered
1146 lower \(5.6.7 is earlier than 5.6.7.1\). Comparison runs till the end
1147 of the string is found, or a non-numeric component shows up \(5.6.7 is
1148 earlier than \"5.6.7 beta\", which is probably not what you want in
1149 some cases\). This code is suitable for existing RCS release numbers.
1150 CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5\)."
1153 (or (and (string-match "^\\.?\\([0-9]+\\)" r1
)
1154 (setq i1
(match-end 0))
1155 (setq v1
(string-to-number (match-string 1 r1
)))
1156 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
1157 (setq i2
(match-end 0))
1158 (setq v2
(string-to-number (match-string 1 r2
)))
1159 (if (> v1 v2
) (throw 'done t
)
1160 (if (< v1 v2
) (throw 'done nil
)
1162 (vc-release-greater-or-equal
1164 (substring r2 i2
)))))))
1166 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
1170 (defun vc-rcs-release-p (release)
1171 "Return t if we have RELEASE or better."
1172 (let ((installation (vc-rcs-system-release)))
1173 (if (and installation
1174 (not (eq installation
'unknown
)))
1175 (vc-release-greater-or-equal installation release
))))
1177 (defun vc-rcs-system-release ()
1178 "Return the RCS release installed on this system, as a string.
1179 Return symbol `unknown' if the release cannot be deducted. The user can
1180 override this using variable `vc-rcs-release'.
1182 If the user has not set variable `vc-rcs-release' and it is nil,
1183 variable `vc-rcs-release' is set to the returned value."
1185 (setq vc-rcs-release
1186 (or (and (zerop (vc-do-command "*vc*" nil
"rcs" nil
"-V"))
1187 (with-current-buffer (get-buffer "*vc*")
1188 (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1)))
1191 (defun vc-rcs-set-non-strict-locking (file)
1192 (vc-do-command "*vc*" 0 "rcs" file
"-U")
1193 (vc-file-setprop file
'vc-checkout-model
'implicit
)
1194 (set-file-modes file
(logior (file-modes file
) 128)))
1196 (defun vc-rcs-set-default-branch (file branch
)
1197 (vc-do-command "*vc*" 0 "rcs" (vc-name file
) (concat "-b" branch
))
1198 (vc-file-setprop file
'vc-rcs-default-branch branch
))
1200 (defun vc-rcs-parse (&optional buffer
)
1201 "Parse current buffer, presumed to be in RCS-style masterfile format.
1202 Optional arg BUFFER specifies another buffer to parse. Return an alist
1203 of two elements, w/ keys `headers' and `revisions' and values in turn
1204 sub-alists. For `headers', the values unless otherwise specified are
1205 strings and the keys are:
1208 head -- latest revision
1209 branch -- the branch the \"head revision\" lies on;
1210 absent if the head revision lies on the trunk
1212 symbols -- sub-alist of (SYMBOL . REVISION) elements
1213 locks -- if file is checked out, something like \"ttn:1.7\"
1214 strict -- t if \"strict locking\" is in effect, otherwise nil
1215 comment -- may be absent; typically something like \"# \" or \"; \"
1216 expand -- may be absent; ???
1218 For `revisions', the car is REVISION (string), the cdr a sub-alist,
1219 with string values (unless otherwise specified) and keys:
1221 date -- a time value (like that returned by `encode-time'); as a
1222 special case, a year value less than 100 is augmented by 1900
1224 state -- typically \"Exp\" or \"Rel\"
1225 branches -- list of revisions that begin branches from this revision
1226 next -- on the trunk: the chronologically-preceding revision, or \"\";
1227 on a branch: the chronologically-following revision, or \"\"
1228 log -- change log entry
1229 text -- for the head revision on the trunk, the body of the file;
1230 other revisions have `:insn' instead
1231 :insn -- for non-head revisions, a list of parsed instructions
1232 in one of two forms, in both cases START meaning \"first
1234 - `(START k COUNT)' -- kill COUNT lines
1235 - `(START i TEXT)' -- insert TEXT (a string)
1236 The list is in descending order by START.
1238 The `:insn' key is a keyword to distinguish it as a vc-rcs.el extension."
1239 (setq buffer
(get-buffer (or buffer
(current-buffer))))
1241 ;; An RCS masterfile can be viewed as containing four regular (for the
1242 ;; most part) sections: (a) the "headers", (b) the "rev headers", (c)
1243 ;; the "description" and (d) the "rev bodies", in that order. In the
1244 ;; returned alist (see docstring), elements from (b) and (d) are
1245 ;; combined pairwise to form the "revisions", while those from (a) and
1246 ;; (c) are simply combined to form the "headers".
1248 ;; Loosely speaking, each section contains a series of alternating
1249 ;; "tags" and "printed representations". In the (b) and (d), many
1250 ;; such series can appear, and a revision number on a line by itself
1251 ;; precedes the series of tags and printed representations associated
1254 ;; In (a) and (b), the printed representations (with the exception of
1255 ;; the `comment' tag in the headers) terminate with a semicolon, which
1256 ;; is NOT part of the "value" finally associated with the tag. All
1257 ;; other printed representations are in "@@-format"; there is an "@",
1258 ;; the middle part (to be translated into the value), another "@" and
1259 ;; a newline. Each "@@" in the middle part indicates the position of
1260 ;; a single "@" (and consequently the requirement of an additional
1261 ;; initial step when translating to the value).
1263 ;; Parser state includes vars that collect parts of the return value...
1264 (let ((desc nil
) (headers nil
) (revs nil
)
1265 ;; ... as well as vars that support a single-pass, tag-assisted,
1266 ;; minimal-data-copying scan. Basically -- skirting around the
1267 ;; grouping by revision required in (b) and (d) -- we repeatedly
1268 ;; and context-sensitively read a tag (that MUST be present),
1269 ;; determine the bounds of the printed representation, translate
1270 ;; it into a value, and push the tag plus value onto one of the
1271 ;; collection vars. Finally, we return the parse tree
1272 ;; incorporating the values of the collection vars (see "rv").
1274 ;; A symbol or string to keep track of context (for error messages).
1276 ;; A symbol, the current tag.
1278 ;; Region (begin and end buffer positions) of the printed
1279 ;; representation for the current tag.
1281 ;; A list of buffer positions where "@@" can be found within the
1282 ;; printed representation region. For each location, we push two
1283 ;; elements onto the list, 1+ and 2+ the location, respectively,
1284 ;; with the 2+ appearing at the head. In this way, the expression
1285 ;; `(,e ,@@-holes ,b)
1286 ;; describes regions that can be concatenated (in reverse order)
1287 ;; to "de-@@-format" the printed representation as the first step
1288 ;; to translating it into some value. See internal func `gather'.
1290 (flet ((sw () (skip-chars-forward " \t\n")) ; i.e., `[:space:]'
1291 (at (tag) (save-excursion (eq tag
(read buffer
))))
1292 (to-eol () (buffer-substring-no-properties
1293 (point) (progn (forward-line 1)
1295 (to-semi () (setq b
(point)
1296 e
(progn (search-forward ";")
1298 (to-one@ () (setq @-holes nil
1299 b
(progn (search-forward "@") (point))
1300 e
(progn (while (and (search-forward "@")
1303 (push (point) @-holes
)
1305 (push (point) @-holes
))))
1307 (tok+val
(set-b+e name
&optional proc
)
1308 (unless (eq name
(setq tok
(read buffer
)))
1309 (error "Missing `%s' while parsing %s" name context
))
1314 (buffer-substring-no-properties b e
))))
1315 (k-semi (name &optional proc
) (tok+val
'to-semi name proc
))
1316 (gather () (let ((pairs `(,e
,@@-holes
,b
))
1319 (push (buffer-substring-no-properties
1320 (cadr pairs
) (car pairs
))
1322 (setq pairs
(cddr pairs
)))
1323 (apply 'concat acc
)))
1324 (k-one@ (name &optional later
) (tok+val
'to-one
@ name
1329 (goto-char (point-min))
1331 (setq context
'headers
)
1332 (flet ((hpush (name &optional proc
)
1333 (push (k-semi name proc
) headers
)))
1340 (mapcar (lambda (together)
1341 (let ((two (split-string together
":")))
1342 (setcar two
(intern (car two
)))
1343 (setcdr two
(cadr two
))
1346 (buffer-substring-no-properties b e
)))))
1348 (push `(strict .
,(when (at 'strict
)
1349 (search-forward ";")
1353 (push (k-one@ 'comment
) headers
)
1354 (search-forward ";"))
1356 (push (k-one@ 'expand
) headers
)
1357 (search-forward ";"))
1358 (setq headers
(nreverse headers
))
1360 (sw) (setq context
'rev-headers
)
1361 (while (looking-at "[0-9]")
1365 (let ((ls (mapcar 'string-to-number
1367 (buffer-substring-no-properties
1370 ;; Hack the year -- verified to be the
1371 ;; same algorithm used in RCS 5.7.
1372 (when (< (car ls
) 100)
1373 (setcar ls
(+ 1900 (car ls
))))
1374 (apply 'encode-time
(nreverse ls
)))))
1375 ,@(mapcar 'k-semi
'(author state
))
1379 (buffer-substring-no-properties b e
))))
1383 (setq revs
(nreverse revs
))
1385 (sw) (setq context
'desc
1386 desc
(k-one@ 'desc
))
1389 ;; Element of `revs' that initially holds only header info.
1390 ;; "Pairwise combination" occurs when we add body info.
1392 ;; Components of the editing commands (aside from the actual
1393 ;; text) that comprise the `text' printed representations
1394 ;; (not including the "head" revision).
1396 ;; Ascending (reversed) `@-holes' which the internal func
1397 ;; `incg' pops to effect incremental gathering.
1399 ;; Function to extract text (for the `a' command), either
1400 ;; `incg' or `buffer-substring-no-properties'. (This is
1401 ;; for speed; strictly speaking, it is sufficient to use
1402 ;; only the former since it behaves identically to the
1403 ;; latter in the absense of "@@".)
1405 (flet ((incg (beg end
) (let ((b beg
) (e end
) @-holes
)
1406 (while (and asc
(< (car asc
) e
))
1407 (push (pop asc
) @-holes
))
1408 ;; Self-deprecate when work is done.
1409 ;; Folding many dimensions into one.
1410 ;; Thanks B.Mandelbrot, for complex sum.
1411 ;; O beauteous math! --the Unvexed Bum
1413 (setq sub
'buffer-substring-no-properties
))
1417 (setq context
(to-eol)
1418 rev
(or (assoc context revs
)
1419 (error "Rev `%s' has body but no head"
1421 (push (k-one@ 'log
) (cdr rev
))
1422 ;; For rev body `text' tags, delay translation slightly...
1423 (push (k-one@ 'text t
) (cdr rev
))
1424 ;; ... until we decide which tag and value is appropriate to
1425 ;; collect. For the "head" revision, compute the value of the
1426 ;; `text' printed representation by simple `gather'. For all
1427 ;; other revisions, replace the `text' tag+value with `:insn'
1428 ;; plus value, always scanning in-place.
1429 (if (string= context
(cdr (assq 'head headers
)))
1430 (setcdr (cadr rev
) (gather))
1432 (setq asc
(nreverse @-holes
)
1434 (setq sub
'buffer-substring-no-properties
))
1437 (while (< (point) e
)
1439 (setq cmd
(char-before)
1440 start
(read (current-buffer))
1441 act
(read (current-buffer)))
1445 ;; `d' means "delete lines".
1446 ;; For Emacs spirit, we use `k' for "kill".
1449 ;; `a' means "append after this line" but
1450 ;; internally we normalize it so that START
1451 ;; specifies the actual line for insert, thus
1452 ;; requiring less hair in the realization algs.
1453 ;; For Emacs spirit, we use `i' for "insert".
1455 ,(funcall sub
(point) (progn (forward-line act
)
1457 (t (error "Bad command `%c' in `text' for rev `%s'"
1461 (setcar (cdr rev
) (cons :insn acc
)))))))
1463 `((headers ,desc
,@headers
)
1464 (revisions ,@revs
)))))
1468 ;;; vc-rcs.el ends here