1 ;;; vc-rcs.el --- support for RCS version-control -*- lexical-binding:t -*-
3 ;; Copyright (C) 1992-2016 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 (declare-function vc-branch-p
"vc" (rev))
45 (declare-function vc-read-revision
"vc"
46 (prompt &optional files backend default initial-input
))
47 (declare-function vc-buffer-context
"vc-dispatcher" ())
48 (declare-function vc-restore-buffer-context
"vc-dispatcher" (context))
49 (declare-function vc-setup-buffer
"vc-dispatcher" (buf))
56 (defcustom vc-rcs-release nil
57 "The release number of your RCS installation, as a string.
58 If nil, VC itself computes this value when it is first needed."
59 :type
'(choice (const :tag
"Auto" nil
)
60 (string :tag
"Specified")
61 (const :tag
"Unknown" unknown
))
64 (defcustom vc-rcs-register-switches nil
65 "Switches for registering a file in RCS.
66 A string or list of strings passed to the checkin program by
67 \\[vc-register]. If nil, use the value of `vc-register-switches'.
68 If t, use no switches."
69 :type
'(choice (const :tag
"Unspecified" nil
)
71 (string :tag
"Argument String")
72 (repeat :tag
"Argument List" :value
("") string
))
76 (defcustom vc-rcs-diff-switches nil
77 "String or list of strings specifying switches for RCS diff under VC.
78 If nil, use the value of `vc-diff-switches'. If t, use no switches."
79 :type
'(choice (const :tag
"Unspecified" nil
)
81 (string :tag
"Argument String")
82 (repeat :tag
"Argument List" :value
("") string
))
86 (defcustom vc-rcs-header
'("$Id\ $")
87 "Header keywords to be inserted by `vc-insert-headers'."
88 :type
'(repeat string
)
89 :version
"24.1" ; no longer consult the obsolete vc-header-alist
92 (defcustom vc-rcsdiff-knows-brief nil
93 "Indicates whether rcsdiff understands the --brief option.
94 The value is either `yes', `no', or nil. If it is nil, VC tries
95 to use --brief and sets this variable to remember whether it worked."
96 :type
'(choice (const :tag
"Work out" nil
) (const yes
) (const no
))
99 ;; This needs to be autoloaded because vc-rcs-registered uses it (via
100 ;; vc-default-registered), and vc-hooks needs to be able to check
101 ;; for a registered backend without loading every backend.
103 (defcustom vc-rcs-master-templates
104 (purecopy '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
105 "Where to look for RCS master files.
106 For a description of possible values, see `vc-check-master-templates'."
107 :type
'(choice (const :tag
"Use standard RCS file names"
108 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
109 (repeat :tag
"User-specified"
116 ;;; Properties of the backend
118 (defun vc-rcs-revision-granularity () 'file
)
120 (defun vc-rcs-checkout-model (files)
121 "RCS-specific version of `vc-checkout-model'."
122 (let ((file (if (consp files
) (car files
) files
))
124 (when vc-consult-headers
125 (vc-file-setprop file
'vc-checkout-model nil
)
126 (vc-rcs-consult-headers file
)
127 (setq result
(vc-file-getprop file
'vc-checkout-model
)))
129 (progn (vc-rcs-fetch-master-state file
)
130 (vc-file-getprop file
'vc-checkout-model
))
131 ;; For non-existing files we assume strict locking.
135 ;;; State-querying functions
138 ;; The autoload cookie below places vc-rcs-registered directly into
139 ;; loaddefs.el, so that vc-rcs.el does not need to be loaded for
140 ;; every file that is visited.
143 (defun vc-rcs-registered (f) (vc-default-registered 'RCS f
)))
145 (defun vc-rcs-state (file)
146 "Implementation of `vc-state' for RCS."
147 (if (not (vc-rcs-registered file
))
149 (or (boundp 'vc-rcs-headers-result
)
150 (and vc-consult-headers
151 (vc-rcs-consult-headers file
)))
153 ;; vc-working-revision might not be known; in that case the
154 ;; property is nil. vc-rcs-fetch-master-state knows how to
156 (vc-rcs-fetch-master-state file
157 (vc-file-getprop file
158 'vc-working-revision
))))
159 (if (not (eq state
'up-to-date
))
161 (if (vc-rcs-workfile-unchanged-p file
)
163 (if (eq (vc-rcs-checkout-model (list file
)) 'locking
)
167 (autoload 'vc-expand-dirs
"vc")
169 (defun vc-rcs-dir-status-files (dir files update-function
)
170 (if (not files
) (setq files
(vc-expand-dirs (list dir
) 'RCS
)))
173 (let ((state (vc-state file
))
174 (frel (file-relative-name file
)))
175 (when (and (eq (vc-backend file
) 'RCS
)
176 (not (eq state
'up-to-date
)))
177 (push (list frel state
) result
))))
178 (funcall update-function result
)))
180 (defun vc-rcs-working-revision (file)
181 "RCS-specific version of `vc-working-revision'."
182 (or (and vc-consult-headers
183 (vc-rcs-consult-headers file
)
184 (vc-file-getprop file
'vc-working-revision
))
186 (vc-rcs-fetch-master-state file
)
187 (vc-file-getprop file
'vc-working-revision
))))
189 (autoload 'vc-master-name
"vc-filewise")
191 (defun vc-rcs-latest-on-branch-p (file &optional version
)
192 "Return non-nil if workfile version of FILE is the latest on its branch.
193 When VERSION is given, perform check for that version."
194 (unless version
(setq version
(vc-working-revision file
)))
197 (if (vc-rcs-trunk-p version
)
199 ;; Compare VERSION to the head version number.
200 (vc-insert-file (vc-master-name file
) "^[0-9]")
201 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
202 ;; If we are not on the trunk, we need to examine the
203 ;; whole current branch.
204 (vc-insert-file (vc-master-name file
) "^desc")
205 (vc-rcs-find-most-recent-rev (vc-branch-part version
))))))
207 (defun vc-rcs-workfile-unchanged-p (file)
208 "Has FILE remained unchanged since last checkout?"
209 ;; Try to use rcsdiff --brief. If rcsdiff does not understand that,
210 ;; do a double take and remember the fact for the future
211 (let* ((version (concat "-r" (vc-working-revision file
)))
212 (status (if (eq vc-rcsdiff-knows-brief
'no
)
213 (vc-do-command "*vc*" 1 "rcsdiff" file version
)
214 (vc-do-command "*vc*" 2 "rcsdiff" file
"--brief" version
))))
216 (if (not vc-rcsdiff-knows-brief
)
217 (setq vc-rcsdiff-knows-brief
'no
218 status
(vc-do-command "*vc*" 1 "rcsdiff" file version
))
219 (error "rcsdiff failed"))
220 (if (not vc-rcsdiff-knows-brief
) (setq vc-rcsdiff-knows-brief
'yes
)))
221 ;; The workfile is unchanged if rcsdiff found no differences.
226 ;;; State-changing functions
229 (defun vc-rcs-create-repo ()
230 "Create a new RCS repository."
231 ;; RCS is totally file-oriented, so all we have to do is make the directory.
232 (make-directory "RCS"))
234 (autoload 'vc-switches
"vc")
236 (defun vc-rcs-register (files &optional comment
)
237 "Register FILES into the RCS version-control system.
238 Automatically retrieve a read-only version of the file with keywords expanded.
239 COMMENT can be used to provide an initial description for each FILES.
240 Passes either `vc-rcs-register-switches' or `vc-register-switches'
244 (and (not (file-exists-p
245 (setq subdir
(expand-file-name "RCS"
246 (file-name-directory file
)))))
247 (not (directory-files (file-name-directory file
)
249 (yes-or-no-p "Create RCS subdirectory? ")
250 (make-directory subdir
))
251 (apply #'vc-do-command
"*vc*" 0 "ci" file
252 ;; if available, use the secure registering option
253 (and (vc-rcs-release-p "5.6.4") "-i")
255 ;; Some old MS-Windows ports of RCS crash when "ci -i" is
256 ;; invoked without -t; indulge them.
257 (concat "-t-" (or comment
""))
258 (vc-switches 'RCS
'register
))
259 ;; parse output to find master file name and workfile version
260 (with-current-buffer "*vc*"
261 (goto-char (point-min))
263 (if (looking-at (concat "^\\(.*\\) <-- "
264 (file-name-nondirectory file
)))
266 ;; if we couldn't find the master name,
267 ;; run vc-rcs-registered to get it
268 ;; (will be stored into the vc-master-name property)
269 (vc-rcs-registered file
)
270 (vc-file-setprop file
'vc-master-name
271 (if (file-name-absolute-p name
)
275 (file-name-directory file
))))))
276 (vc-file-setprop file
'vc-working-revision
277 (if (re-search-forward
278 "^initial revision: \\([0-9.]+\\).*\n"
280 (match-string 1))))))
282 (defun vc-rcs-responsible-p (file)
283 "Return non-nil if RCS thinks it would be responsible for registering FILE."
284 ;; TODO: check for all the patterns in vc-rcs-master-templates
285 (file-directory-p (expand-file-name "RCS"
286 (if (file-directory-p file
)
288 (file-name-directory file
)))))
290 (defun vc-rcs-receive-file (file rev
)
291 "Implementation of receive-file for RCS."
292 (let ((checkout-model (vc-rcs-checkout-model (list file
))))
293 (vc-rcs-register file
"")
294 (when (eq checkout-model
'implicit
)
295 (vc-rcs-set-non-strict-locking file
))
296 (vc-rcs-set-default-branch file
(concat rev
".1"))))
298 (defun vc-rcs-unregister (file)
299 "Unregister FILE from RCS.
300 If this leaves the RCS subdirectory empty, ask the user
301 whether to remove it."
302 (unless (memq (vc-state file
) '(nil unregistered
))
303 (let* ((master (vc-master-name file
))
304 (dir (file-name-directory master
))
305 (backup-info (find-backup-file-name master
)))
306 (if (not backup-info
)
308 (rename-file master
(car backup-info
) 'ok-if-already-exists
)
309 (dolist (f (cdr backup-info
)) (ignore-errors (delete-file f
))))
310 (and (string= (file-name-nondirectory (directory-file-name dir
)) "RCS")
311 ;; check whether RCS dir is empty, i.e. it does not
312 ;; contain any files except "." and ".."
313 (not (directory-files dir nil
314 "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*"))
315 (yes-or-no-p (format "Directory %s is empty; remove it? " dir
))
316 (delete-directory dir
)))))
318 (defun vc-rcs-checkin (files comment
&optional rev
)
319 "RCS-specific version of `vc-backend-checkin'."
320 (let ((switches (vc-switches 'RCS
'checkin
)))
321 ;; Now operate on the files
322 (dolist (file (vc-expand-dirs files
'RCS
))
323 (let ((old-version (vc-working-revision file
)) new-version
324 (default-branch (vc-file-getprop file
'vc-rcs-default-branch
)))
325 ;; Force branch creation if an appropriate
326 ;; default branch has been set.
329 (string-match (concat "^" (regexp-quote old-version
) "\\.")
331 (setq rev default-branch
)
332 (setq switches
(cons "-f" switches
)))
333 (if (and (not rev
) old-version
)
334 (setq rev
(vc-branch-part old-version
)))
335 (apply #'vc-do-command
"*vc*" 0 "ci" (vc-master-name file
)
336 ;; if available, use the secure check-in option
337 (and (vc-rcs-release-p "5.6.4") "-j")
339 (concat "-m" comment
)
341 (vc-file-setprop file
'vc-working-revision nil
)
343 ;; determine the new workfile version
345 (goto-char (point-min))
346 (when (or (re-search-forward
347 "new revision: \\([0-9.]+\\);" nil t
)
349 "reverting to previous revision \\([0-9.]+\\)" nil t
))
350 (setq new-version
(match-string 1))
351 (vc-file-setprop file
'vc-working-revision new-version
))
353 ;; if we got to a different branch, adjust the default
354 ;; branch accordingly
356 ((and old-version new-version
357 (not (string= (vc-branch-part old-version
)
358 (vc-branch-part new-version
))))
359 (vc-rcs-set-default-branch file
360 (if (vc-rcs-trunk-p new-version
) nil
361 (vc-branch-part new-version
)))
362 ;; If this is an old (pre-1992!) RCS release, we might have
363 ;; to remove a remaining lock.
364 (if (not (vc-rcs-release-p "5.6.2"))
365 ;; exit status of 1 is also accepted.
366 ;; It means that the lock was removed before.
367 (vc-do-command "*vc*" 1 "rcs" (vc-master-name file
)
368 (concat "-u" old-version
)))))))))
370 (defun vc-rcs-find-revision (file rev buffer
)
371 (apply #'vc-do-command
372 (or buffer
"*vc*") 0 "co" (vc-master-name file
)
373 "-q" ;; suppress diagnostic output
375 (vc-switches 'RCS
'checkout
)))
377 (defun vc-rcs-checkout (file &optional rev
)
378 "Retrieve a copy of a saved version of FILE. If FILE is a directory,
379 attempt the checkout for all registered files beneath it."
380 (if (file-directory-p file
)
381 (mapc 'vc-rcs-checkout
(vc-expand-dirs (list file
) 'RCS
))
382 (let ((file-buffer (get-file-buffer file
))
384 (message "Checking out %s..." file
)
386 ;; Change buffers to get local value of vc-checkout-switches.
387 (if file-buffer
(set-buffer file-buffer
))
388 (setq switches
(vc-switches 'RCS
'checkout
))
389 ;; Save this buffer's default-directory
390 ;; and use save-excursion to make sure it is restored
391 ;; in the same buffer it was saved in.
392 (let ((default-directory default-directory
))
394 ;; Adjust the default-directory so that the check-out creates
395 ;; the file in the right place.
396 (setq default-directory
(file-name-directory file
))
398 ;; if we should go to the head of the trunk,
399 ;; clear the default branch first
400 (and rev
(string= rev
"")
401 (vc-rcs-set-default-branch file nil
))
402 ;; now do the checkout
403 (apply #'vc-do-command
404 "*vc*" 0 "co" (vc-master-name file
)
405 ;; If locking is not strict, force to overwrite
406 ;; the writable workfile.
407 (if (eq (vc-rcs-checkout-model (list file
)) 'implicit
) "-f")
410 ;; a literal revision was specified
412 (let ((workrev (vc-working-revision file
)))
416 ;; no revision specified:
417 ;; use current workfile version
420 (if (not (vc-rcs-trunk-p workrev
))
421 ;; ... go to head of current branch
422 (vc-branch-part workrev
)
423 ;; ... go to head of trunk
424 (vc-rcs-set-default-branch file
428 ;; determine the new workfile version
429 (with-current-buffer "*vc*"
431 (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1)))
432 (vc-file-setprop file
'vc-working-revision new-version
)
433 ;; if necessary, adjust the default branch
434 (and rev
(not (string= rev
""))
435 (vc-rcs-set-default-branch
437 (if (vc-rcs-latest-on-branch-p file new-version
)
438 (if (vc-rcs-trunk-p new-version
) nil
439 (vc-branch-part new-version
))
441 (message "Checking out %s...done" file
))))))
443 (defun vc-rcs-revert (file &optional _contents-done
)
444 "Revert FILE to the version it was based on. If FILE is a directory,
445 revert all registered files beneath it."
446 (if (file-directory-p file
)
447 (mapc 'vc-rcs-revert
(vc-expand-dirs (list file
) 'RCS
))
448 (vc-do-command "*vc*" 0 "co" (vc-master-name file
) "-f"
449 (concat (if (eq (vc-state file
) 'edited
) "-u" "-r")
450 (vc-working-revision file
)))))
452 (defun vc-rcs-merge-file (file)
453 "Accept a file merge request, prompting for revisions."
454 (let* ((first-revision
456 (concat "Merge " file
" from branch or revision: ")
461 ((string= first-revision
"")
462 (error "A starting RCS revision is required"))
464 (if (not (vc-branch-p first-revision
))
465 (setq second-revision
467 "Second RCS revision: "
469 (concat (vc-branch-part first-revision
) ".")))
470 ;; We want to merge an entire branch. Set revisions
471 ;; accordingly, so that vc-rcs-merge understands us.
472 (setq second-revision first-revision
)
473 ;; first-revision must be the starting point of the branch
474 (setq first-revision
(vc-branch-part first-revision
)))))
475 (vc-rcs-merge file first-revision second-revision
)))
477 (defun vc-rcs-merge (file first-version
&optional second-version
)
478 "Merge changes into current working copy of FILE.
479 The changes are between FIRST-VERSION and SECOND-VERSION."
480 (vc-do-command "*vc*" 1 "rcsmerge" (vc-master-name file
)
481 "-kk" ; ignore keyword conflicts
482 (concat "-r" first-version
)
483 (if second-version
(concat "-r" second-version
))))
485 (defun vc-rcs-steal-lock (file &optional rev
)
486 "Steal the lock on the current workfile for FILE and revision REV.
487 If FILE is a directory, steal the lock on all registered files beneath it.
488 Needs RCS 5.6.2 or later for -M."
489 (if (file-directory-p file
)
490 (mapc 'vc-rcs-steal-lock
(vc-expand-dirs (list file
) 'RCS
))
491 (vc-do-command "*vc*" 0 "rcs" (vc-master-name file
) "-M" (concat "-u" rev
))
492 ;; Do a real checkout after stealing the lock, so that we see
494 (vc-do-command "*vc*" 0 "co" (vc-master-name file
) "-f" (concat "-l" rev
))
495 ;; Must clear any headers here because they wouldn't
496 ;; show that the file is locked now.
497 (let* ((filename (or file buffer-file-name
))
498 (visited (find-buffer-visiting filename
)))
500 (let ((context (vc-buffer-context)))
501 ;; save-excursion may be able to relocate point and mark
502 ;; properly. If it fails, vc-restore-buffer-context
503 ;; will give it a second try.
505 (vc-rcs-clear-headers))
506 (vc-restore-buffer-context context
))
507 (set-buffer (find-file-noselect filename
))
508 (vc-rcs-clear-headers)
509 (kill-buffer filename
)))))
511 (defun vc-rcs-modify-change-comment (files rev comment
)
512 "Modify the change comments change on FILES on a specified REV. If FILE is a
513 directory the operation is applied to all registered files beneath it."
514 (dolist (file (vc-expand-dirs files
'RCS
))
515 (vc-do-command "*vc*" 0 "rcs" (vc-master-name file
)
516 (concat "-m" rev
":" comment
))))
520 ;;; History functions
523 (defun vc-rcs-print-log-cleanup ()
524 (let ((inhibit-read-only t
))
525 (goto-char (point-max))
527 (while (looking-at "=*\n")
528 (delete-char (- (match-end 0) (match-beginning 0)))
530 (goto-char (point-min))
531 (when (looking-at "[\b\t\n\v\f\r ]+")
532 (delete-char (- (match-end 0) (match-beginning 0))))))
534 (defun vc-rcs-print-log (files buffer
&optional _shortlog
535 _start-revision-ignored limit
)
536 "Print commit log associated with FILES into specified BUFFER.
537 Remaining arguments are ignored.
538 If FILE is a directory the operation is applied to all registered
540 (vc-do-command (or buffer
"*vc*") 0 "rlog"
541 (mapcar 'vc-master-name
(vc-expand-dirs files
'RCS
)))
542 (with-current-buffer (or buffer
"*vc*")
543 (vc-rcs-print-log-cleanup))
544 (when limit
'limit-unsupported
))
546 (defun vc-rcs-diff (files &optional oldvers newvers buffer _async
)
547 "Get a difference report using RCS between two sets of files."
548 (apply #'vc-do-command
(or buffer
"*vc-diff*")
549 ;; The repo is local, so this is fast anyway.
551 "rcsdiff" (vc-expand-dirs files
'RCS
)
553 (and oldvers
(concat "-r" oldvers
))
554 (and newvers
(concat "-r" newvers
)))
555 (vc-switches 'RCS
'diff
))))
557 (defun vc-rcs-find-admin-dir (file)
558 "Return the administrative directory of FILE."
559 (vc-find-root file
"RCS"))
561 (defun vc-rcs-comment-history (file)
562 "Return a string with all log entries stored in BACKEND for FILE."
563 (with-current-buffer "*vc*"
564 ;; Has to be written this way, this function is used by the CVS backend too
565 (vc-call-backend (vc-backend file
) 'print-log
(list file
))
567 (let ((separator (concat "^-+\nrevision [0-9.]+\ndate: .*\n"
568 "\\(branches: .*;\n\\)?"
569 "\\(\\*\\*\\* empty log message \\*\\*\\*\n\\)?")))
570 (goto-char (point-max)) (forward-line -
1)
571 (while (looking-at "=*\n")
572 (delete-char (- (match-end 0) (match-beginning 0)))
574 (goto-char (point-min))
575 (if (looking-at "[\b\t\n\v\f\r ]+")
576 (delete-char (- (match-end 0) (match-beginning 0))))
577 (goto-char (point-min))
578 (re-search-forward separator nil t
)
579 (delete-region (point-min) (point))
580 (while (re-search-forward separator nil t
)
581 (delete-region (match-beginning 0) (match-end 0))))
582 ;; Return the de-crufted comment list
585 (defun vc-rcs-annotate-command (file buffer
&optional revision
)
586 "Annotate FILE, inserting the results in BUFFER.
587 Optional arg REVISION is a revision to annotate from."
588 (vc-setup-buffer buffer
)
589 ;; Aside from the "head revision on the trunk", the instructions for
590 ;; each revision on the trunk are an ordered list of kill and insert
591 ;; commands necessary to go from the chronologically-following
592 ;; revision to this one. That is, associated with revision N are
593 ;; edits that applied to revision N+1 would result in revision N.
595 ;; On a branch, however, (some) things are inverted: the commands
596 ;; listed are those necessary to go from the chronologically-preceding
597 ;; revision to this one. That is, associated with revision N are
598 ;; edits that applied to revision N-1 would result in revision N.
600 ;; So, to get per-line history info, we apply reverse-chronological
601 ;; edits, starting with the head revision on the trunk, all the way
602 ;; back through the initial revision (typically "1.1" or similar),
603 ;; then apply forward-chronological edits -- keeping track of which
604 ;; revision is associated with each inserted line -- until we reach
605 ;; the desired revision for display (which may be either on the trunk
607 (let* ((tree (with-temp-buffer
608 (insert-file-contents (vc-rcs-registered file
))
610 (revisions (cdr (assq 'revisions tree
)))
611 ;; The revision N whose instructions we currently are processing.
612 (cur (cdr (assq 'head
(cdr (assq 'headers tree
)))))
613 ;; Alist from the parse tree for N.
614 (meta (cdr (assoc cur revisions
)))
615 ;; Point and temporary string, respectively.
617 ;; "Next-branch list". Nil means the desired revision to
618 ;; display lives on the trunk. Non-nil means it lives on a
619 ;; branch, in which case the value is a list of revision pairs
620 ;; (PARENT . CHILD), the first PARENT being on the trunk, that
621 ;; links each series of revisions in the path from the initial
622 ;; revision to the desired revision to display.
624 ;; "Path-accumulate-predicate plus revision/date/author".
625 ;; Until set, forward-chronological edits are not accumulated.
626 ;; Once set, its value (updated every revision) is used for
627 ;; the text property `:vc-rcs-r/d/a' for inserts during
628 ;; processing of forward-chronological instructions for N.
629 ;; See internal func `r/d/a'.
631 ;; List of forward-chronological instructions, each of the
632 ;; form: (POS . ACTION), where POS is a buffer position. If
633 ;; ACTION is a string, it is inserted, otherwise it is taken as
634 ;; the number of characters to be deleted.
636 ;; N+1. When `cur' is "", this is the initial revision.
640 (unless (assoc revision revisions
)
641 (error "No such revision: %s" revision
))
642 ;; Find which branches (if any) must be included in the edits.
645 (while (setq bpt
(vc-branch-part par
)
646 par
(vc-branch-part bpt
))
647 (setq kids
(cdr (assq 'branches
(cdr (assoc par revisions
)))))
648 ;; A branchpoint may have multiple children. Find the right one.
649 (while (not (string= bpt
(vc-branch-part (car kids
))))
650 (setq kids
(cdr kids
)))
651 (push (cons par
(car kids
)) nbls
)))
652 ;; Start with the full text.
654 (insert (cdr (assq 'text meta
)))
655 ;; Apply reverse-chronological edits on the trunk, computing and
656 ;; accumulating forward-chronological edits after some point, for
658 (cl-flet ((r/d
/a
() (vector pre
659 (cdr (assq 'date meta
))
660 (cdr (assq 'author meta
)))))
661 (while (when (setq pre cur cur
(cdr (assq 'next meta
)))
662 (not (string= "" cur
)))
664 ;; Start accumulating the forward-chronological edits when N+1
665 ;; on the trunk is either the desired revision to display, or
666 ;; the appropriate branchpoint for it. Do this before
667 ;; updating `meta' since `r/d/a' uses N+1's `meta' value.
668 prda
(when (or prda
(string= (if nbls
(caar nbls
) revision
) pre
))
670 meta
(cdr (assoc cur revisions
)))
671 ;; Edits in the parse tree specify a line number (in the buffer
672 ;; *BEFORE* editing occurs) to start from, but line numbers
673 ;; change as a result of edits. To DTRT, we apply edits in
674 ;; order of descending buffer position so that edits further
675 ;; down in the buffer occur first w/o corrupting specified
676 ;; buffer positions of edits occurring towards the beginning of
677 ;; the buffer. In this way we avoid using markers. A pleasant
678 ;; property of this approach is ability to push instructions
679 ;; onto `path' directly, w/o need to maintain rev boundaries.
680 (dolist (insn (cdr (assq :insn meta
)))
681 (goto-char (point-min))
682 (forward-line (1- (pop insn
)))
685 (`k
(setq s
(buffer-substring-no-properties
686 p
(progn (forward-line (car insn
))
689 (push `(,p .
,(propertize s
:vc-rcs-r
/d
/a prda
)) path
))
690 (delete-region p
(point)))
691 (`i
(setq s
(car insn
))
693 (push `(,p .
,(length s
)) path
))
695 ;; For the initial revision, setting `:vc-rcs-r/d/a' directly is
696 ;; equivalent to pushing an insert instruction (of the entire buffer
697 ;; contents) onto `path' then erasing the buffer, but less wasteful.
698 (put-text-property (point-min) (point-max) :vc-rcs-r
/d
/a
(r/d
/a
))
699 ;; Now apply the forward-chronological edits for the trunk.
701 (goto-char (pop insn
))
705 ;; Now apply the forward-chronological edits (directly from the
706 ;; parse-tree) for the branch(es), if necessary. We re-use vars
707 ;; `pre' and `meta' for the sake of internal func `r/d/a'.
709 (setq pre
(cdr (pop nbls
)))
711 (setq meta
(cdr (assoc pre revisions
))
713 (dolist (insn (cdr (assq :insn meta
)))
714 (goto-char (point-min))
715 (forward-line (1- (pop insn
)))
718 (point) (progn (forward-line (car insn
))
720 (`i
(insert (propertize
723 (or prda
(setq prda
(r/d
/a
))))))))
724 (prog1 (not (string= (if nbls
(caar nbls
) revision
) pre
))
725 (setq pre
(cdr (assq 'next meta
)))))))))
726 ;; Lastly, for each line, insert at bol nicely-formatted history info.
727 ;; We do two passes to collect summary information used to minimize
728 ;; the annotation's usage of screen real-estate: (1) Consider rendered
729 ;; width of revision plus author together as a unit; and (2) Omit
730 ;; author entirely if all authors are the same as the user.
731 (let ((ht (make-hash-table :test
'eq
))
732 (me (user-login-name))
736 (goto-char (point-max))
739 (setq rda
(get-text-property (point) :vc-rcs-r
/d
/a
))
740 (unless (gethash rda ht
)
742 all-me
(and all-me
(string= a me
)))
743 (puthash rda
(setq w
(+ (length (aref rda
0))
746 (setq maxw
(max w maxw
))))
747 (let ((padding (make-string maxw
32)))
748 (cl-flet ((pad (w) (substring-no-properties padding w
))
749 (render (rda &rest ls
)
752 (format-time-string "%Y-%m-%d" (aref rda
1))
756 :vc-annotate-prefix t
761 (puthash rda
(render rda
(pad w
) ": ") ht
))
763 (puthash rda
(render rda
" " (pad w
) " " (aref rda
2) ": ") ht
)))
766 (insert (gethash (get-text-property (point) :vc-rcs-r
/d
/a
) ht
))
769 (declare-function vc-annotate-convert-time
"vc-annotate" (&optional time
))
771 (defun vc-rcs-annotate-current-time ()
772 "Return the current time, based at midnight of the current day, and
773 encoded as fractional days."
774 (vc-annotate-convert-time
775 (apply #'encode-time
0 0 0 (nthcdr 3 (decode-time)))))
777 (defun vc-rcs-annotate-time ()
778 "Return the time of the next annotation (as fraction of days)
779 systime, or nil if there is none. Also, reposition point."
781 (prog1 (vc-annotate-convert-time
782 (aref (get-text-property (point) :vc-rcs-r
/d
/a
) 1))
783 (goto-char (next-single-property-change (point) :vc-annotate-prefix
)))))
785 (defun vc-rcs-annotate-extract-revision-at-line ()
786 (aref (get-text-property (point) :vc-rcs-r
/d
/a
) 0))
793 (autoload 'vc-tag-precondition
"vc")
794 (declare-function vc-file-tree-walk
"vc" (dirname func
&rest args
))
796 (defun vc-rcs-create-tag (dir name branchp
)
798 (error "RCS backend does not support module branches"))
799 (let ((result (vc-tag-precondition dir
)))
801 (error "File %s is not up-to-date" result
)
805 (vc-do-command "*vc*" 0 "rcs" (vc-master-name f
) (concat "-n" name
":")))))))
812 (defun vc-rcs-trunk-p (rev)
813 "Return t if REV is a revision on the trunk."
814 (not (eq nil
(string-match "\\`[0-9]+\\.[0-9]+\\'" rev
))))
816 (defun vc-rcs-minor-part (rev)
817 "Return the minor revision number of a revision number REV."
818 (string-match "[0-9]+\\'" rev
)
819 (substring rev
(match-beginning 0) (match-end 0)))
821 (defun vc-rcs-previous-revision (_file rev
)
822 "Return the revision number immediately preceding REV for FILE,
823 or nil if there is no previous revision. This default
824 implementation works for MAJOR.MINOR-style revision numbers as
825 used by RCS and CVS."
826 (let ((branch (vc-branch-part rev
))
827 (minor-num (string-to-number (vc-rcs-minor-part rev
))))
830 ;; revision does probably not start a branch or release
831 (concat branch
"." (number-to-string (1- minor-num
)))
832 (if (vc-rcs-trunk-p rev
)
833 ;; we are at the beginning of the trunk --
834 ;; don't know anything to return here
836 ;; we are at the beginning of a branch --
837 ;; return revision of starting point
838 (vc-branch-part branch
))))))
840 (defun vc-rcs-next-revision (file rev
)
841 "Return the revision number immediately following REV for FILE,
842 or nil if there is no next revision. This default implementation
843 works for MAJOR.MINOR-style revision numbers as used by RCS
845 (when (not (string= rev
(vc-working-revision file
)))
846 (let ((branch (vc-branch-part rev
))
847 (minor-num (string-to-number (vc-rcs-minor-part rev
))))
848 (concat branch
"." (number-to-string (1+ minor-num
))))))
850 ;; You might think that this should be distributed with RCS, but
851 ;; apparently not. CVS sometimes provides a version of it.
852 ;; http://lists.gnu.org/archive/html/emacs-devel/2014-05/msg00288.html
853 (defvar vc-rcs-rcs2log-program
855 (cond ((file-executable-p
856 (setq exe
(expand-file-name "rcs2log" exec-directory
)))
858 ;; In the unlikely event that someone is running an
859 ;; uninstalled Emacs and wants to do something RCS-related.
861 (setq exe
(expand-file-name "lib-src/rcs2log" source-directory
)))
864 "Path to the `rcs2log' program (normally in `exec-directory').")
866 (autoload 'vc-buffer-sync
"vc-dispatcher")
868 (defun vc-rcs-update-changelog (files)
869 "Default implementation of update-changelog.
870 Uses `rcs2log' which only works for RCS and CVS."
871 ;; FIXME: We (c|sh)ould add support for cvs2cl
872 (let ((odefault default-directory
)
873 (changelog (find-change-log))
874 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
875 (tempfile (make-temp-file
876 (expand-file-name "vc"
877 (or small-temporary-file-directory
878 temporary-file-directory
))))
879 (login-name (or user-login-name
880 (format "uid%d" (number-to-string (user-uid)))))
881 (full-name (or add-log-full-name
884 (format "uid%d" (number-to-string (user-uid)))))
885 (mailing-address (or add-log-mailing-address
887 (find-file-other-window changelog
)
888 (barf-if-buffer-read-only)
891 (goto-char (point-min))
893 (message "Computing change log entries...")
894 (message "Computing change log entries... %s"
897 (setq default-directory odefault
)
898 (if (eq 0 (apply #'call-process vc-rcs-rcs2log-program
899 nil
(list t tempfile
) nil
901 "-u" (concat login-name
903 "\t" mailing-address
)
907 (expand-file-name f odefault
)))
910 (pop-to-buffer (get-buffer-create "*vc*"))
912 (insert-file-contents tempfile
)
914 (setq default-directory
(file-name-directory changelog
))
915 (delete-file tempfile
)))))
917 (defun vc-rcs-check-headers ()
918 "Check if the current file has any headers in it."
920 (goto-char (point-min))
921 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
922 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
924 (defun vc-rcs-clear-headers ()
925 "Clear RCS header value parts."
926 (let ((case-fold-search nil
))
927 (goto-char (point-min))
928 (while (re-search-forward
929 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
930 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
932 (replace-match "$\\1$"))))
934 (autoload 'vc-rename-master
"vc-filewise")
936 (defun vc-rcs-rename-file (old new
)
937 ;; Just move the master file (using vc-rcs-master-templates).
938 (vc-rename-master (vc-master-name old
) new vc-rcs-master-templates
))
940 (defun vc-rcs-find-file-hook ()
941 ;; If the file is locked by some other user, make
942 ;; the buffer read-only. Like this, even root
943 ;; cannot modify a file that someone else has locked.
944 (and (stringp (vc-state buffer-file-name
'RCS
))
945 (setq buffer-read-only t
)))
949 ;;; Internal functions
952 (defun vc-rcs-workfile-is-newer (file)
953 "Return non-nil if FILE is newer than its RCS master.
954 This likely means that FILE has been changed with respect
955 to its master version."
956 (let ((file-time (nth 5 (file-attributes file
)))
957 (master-time (nth 5 (file-attributes (vc-master-name file
)))))
958 (or (> (nth 0 file-time
) (nth 0 master-time
))
959 (and (= (nth 0 file-time
) (nth 0 master-time
))
960 (> (nth 1 file-time
) (nth 1 master-time
))))))
962 (defun vc-rcs-find-most-recent-rev (branch)
963 "Find most recent revision on BRANCH."
964 (goto-char (point-min))
965 (let ((latest-rev -
1) value
)
966 (while (re-search-forward (concat "^\\(" (regexp-quote branch
)
967 "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;")
969 (let ((rev (string-to-number (match-string 2))))
970 (when (< latest-rev rev
)
971 (setq latest-rev rev
)
972 (setq value
(match-string 1)))))
974 (vc-branch-part branch
))))
976 (defun vc-rcs-fetch-master-state (file &optional working-revision
)
977 "Compute the master file's idea of the state of FILE.
978 If a WORKING-REVISION is given, compute the state of that version,
979 otherwise determine the workfile version based on the master file.
980 This function sets the properties `vc-working-revision' and
981 `vc-checkout-model' to their correct values, based on the master
983 (when (and (file-regular-p file
) (vc-master-name file
))
985 (if (or (not (vc-insert-file (vc-master-name file
) "^[0-9]"))
986 (progn (goto-char (point-min))
987 (not (looking-at "^head[ \t\n]+[^;]+;$"))))
988 (error "File %s is not an RCS master file" (vc-master-name file
)))
989 (let ((workfile-is-latest nil
)
990 (default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1)))
991 (vc-file-setprop file
'vc-rcs-default-branch default-branch
)
992 (unless working-revision
993 ;; Workfile version not known yet. Determine that first. It
994 ;; is either the head of the trunk, the head of the default
995 ;; branch, or the "default branch" itself, if that is a full
999 ((or (not default-branch
) (string= "" default-branch
))
1000 (setq working-revision
1001 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
1002 (setq workfile-is-latest t
))
1003 ;; default branch is actually a revision
1004 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
1006 (setq working-revision default-branch
))
1007 ;; else, search for the head of the default branch
1008 (t (vc-insert-file (vc-master-name file
) "^desc")
1009 (setq working-revision
1010 (vc-rcs-find-most-recent-rev default-branch
))
1011 (setq workfile-is-latest t
)))
1012 (vc-file-setprop file
'vc-working-revision working-revision
))
1013 ;; Check strict locking
1014 (goto-char (point-min))
1015 (vc-file-setprop file
'vc-checkout-model
1016 (if (re-search-forward ";[ \t\n]*strict;" nil t
)
1017 'locking
'implicit
))
1018 ;; Compute state of workfile version
1019 (goto-char (point-min))
1021 (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):"
1022 (regexp-quote working-revision
)
1028 (if (or workfile-is-latest
1029 (vc-rcs-latest-on-branch-p file working-revision
))
1030 ;; workfile version is latest on branch
1032 ;; workfile version is not latest on branch
1034 ;; locked by the calling user
1035 ((and (stringp locking-user
)
1036 (string= locking-user
(vc-user-login-name file
)))
1037 ;; Don't call `vc-rcs-checkout-model' to avoid inf-looping.
1038 (if (or (eq (vc-file-getprop file
'vc-checkout-model
) 'locking
)
1040 (vc-rcs-latest-on-branch-p file working-revision
))
1042 ;; Locking is not used for the file, but the owner does
1043 ;; have a lock, and there is a higher version on the current
1044 ;; branch. Not sure if this can occur, and if it is right
1045 ;; to use `needs-merge' in this case.
1047 ;; locked by somebody else
1048 ((stringp locking-user
)
1051 (error "Error getting state of RCS file"))))))))
1053 (defun vc-rcs-consult-headers (file)
1054 "Search for RCS headers in FILE, and set properties accordingly.
1056 Returns: nil if no headers were found
1057 'rev if a workfile revision was found
1058 'rev-and-lock if revision and lock info was found"
1060 ((not (get-file-buffer file
)) nil
)
1061 ((let (status version
)
1062 (with-current-buffer (get-file-buffer file
)
1064 (goto-char (point-min))
1066 ;; search for $Id or $Header
1067 ;; -------------------------
1068 ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file.
1069 ((or (and (search-forward "$Id\ : " nil t
)
1070 (looking-at "[^ ]+ \\([0-9.]+\\) "))
1071 (and (progn (goto-char (point-min))
1072 (search-forward "$Header\ : " nil t
))
1073 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
1074 (goto-char (match-end 0))
1075 ;; if found, store the revision number ...
1076 (setq version
(match-string-no-properties 1))
1077 ;; ... and check for the locking state
1080 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
1081 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
1082 "[^ ]+ [^ ]+ ")) ; author & state
1083 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
1085 ;; unlocked revision
1087 ;;(setq locking-user 'none)
1088 (setq status
'rev-and-lock
))
1089 ;; revision is locked by some user
1090 ((looking-at "\\([^ ]+\\) \\$")
1091 ;;(setq locking-user (match-string-no-properties 1))
1092 (setq status
'rev-and-lock
))
1093 ;; everything else: false
1095 ;; unexpected information in
1096 ;; keyword string --> quit
1098 ;; search for $Revision
1099 ;; --------------------
1100 ((re-search-forward (concat "\\$"
1101 "Revision: \\([0-9.]+\\) \\$")
1103 ;; if found, store the revision number ...
1104 (setq version
(match-string-no-properties 1))
1105 ;; and see if there's any lock information
1106 (goto-char (point-min))
1107 (if (re-search-forward (concat "\\$" "Locker:") nil t
)
1108 (cond ((looking-at " \\([^ ]+\\) \\$")
1109 ;;(setq locking-user (match-string-no-properties 1))
1110 (setq status
'rev-and-lock
))
1111 ((looking-at " *\\$")
1112 ;;(setq locking-user 'none)
1113 (setq status
'rev-and-lock
))
1115 ;;(setq locking-user 'none)
1116 (setq status
'rev-and-lock
)))
1117 (setq status
'rev
)))
1118 ;; else: nothing found
1119 ;; -------------------
1121 (if status
(vc-file-setprop file
'vc-working-revision version
))
1124 (defun vc-release-greater-or-equal (r1 r2
)
1125 "Compare release numbers, represented as strings.
1126 Release components are assumed cardinal numbers, not decimal fractions
1127 \(5.10 is a higher release than 5.9). Omitted fields are considered
1128 lower \(5.6.7 is earlier than 5.6.7.1). Comparison runs till the end
1129 of the string is found, or a non-numeric component shows up \(5.6.7 is
1130 earlier than \"5.6.7 beta\", which is probably not what you want in
1131 some cases). This code is suitable for existing RCS release numbers.
1132 CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5)."
1135 (or (and (string-match "^\\.?\\([0-9]+\\)" r1
)
1136 (setq i1
(match-end 0))
1137 (setq v1
(string-to-number (match-string 1 r1
)))
1138 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
1139 (setq i2
(match-end 0))
1140 (setq v2
(string-to-number (match-string 1 r2
)))
1141 (if (> v1 v2
) (throw 'done t
)
1142 (if (< v1 v2
) (throw 'done nil
)
1144 (vc-release-greater-or-equal
1146 (substring r2 i2
)))))))
1148 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
1152 (defun vc-rcs-release-p (release)
1153 "Return t if we have RELEASE or better."
1154 (let ((installation (vc-rcs-system-release)))
1155 (if (and installation
1156 (not (eq installation
'unknown
)))
1157 (vc-release-greater-or-equal installation release
))))
1159 (defun vc-rcs-system-release ()
1160 "Return the RCS release installed on this system, as a string.
1161 Return symbol `unknown' if the release cannot be deducted. The user can
1162 override this using variable `vc-rcs-release'.
1164 If the user has not set variable `vc-rcs-release' and it is nil,
1165 variable `vc-rcs-release' is set to the returned value."
1167 (setq vc-rcs-release
1168 (or (and (zerop (vc-do-command "*vc*" nil
"rcs" nil
"-V"))
1169 (with-current-buffer (get-buffer "*vc*")
1170 (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1)))
1173 (defun vc-rcs-set-non-strict-locking (file)
1174 (vc-do-command "*vc*" 0 "rcs" file
"-U")
1175 (vc-file-setprop file
'vc-checkout-model
'implicit
)
1176 (set-file-modes file
(logior (file-modes file
) 128)))
1178 (defun vc-rcs-set-default-branch (file branch
)
1179 (vc-do-command "*vc*" 0 "rcs" (vc-master-name file
) (concat "-b" branch
))
1180 (vc-file-setprop file
'vc-rcs-default-branch branch
))
1182 (defun vc-rcs-parse (&optional buffer
)
1183 "Parse current buffer, presumed to be in RCS-style masterfile format.
1184 Optional arg BUFFER specifies another buffer to parse. Return an alist
1185 of two elements, w/ keys `headers' and `revisions' and values in turn
1186 sub-alists. For `headers', the values unless otherwise specified are
1187 strings and the keys are:
1190 head -- latest revision
1191 branch -- the branch the \"head revision\" lies on;
1192 absent if the head revision lies on the trunk
1194 symbols -- sub-alist of (SYMBOL . REVISION) elements
1195 locks -- if file is checked out, something like \"ttn:1.7\"
1196 strict -- t if \"strict locking\" is in effect, otherwise nil
1197 comment -- may be absent; typically something like \"# \" or \"; \"
1198 expand -- may be absent; ???
1200 For `revisions', the car is REVISION (string), the cdr a sub-alist,
1201 with string values (unless otherwise specified) and keys:
1203 date -- a time value (like that returned by `encode-time'); as a
1204 special case, a year value less than 100 is augmented by 1900
1206 state -- typically \"Exp\" or \"Rel\"
1207 branches -- list of revisions that begin branches from this revision
1208 next -- on the trunk: the chronologically-preceding revision, or \"\";
1209 on a branch: the chronologically-following revision, or \"\"
1210 log -- change log entry
1211 text -- for the head revision on the trunk, the body of the file;
1212 other revisions have `:insn' instead
1213 :insn -- for non-head revisions, a list of parsed instructions
1214 in one of two forms, in both cases START meaning \"first
1216 - `(START k COUNT)' -- kill COUNT lines
1217 - `(START i TEXT)' -- insert TEXT (a string)
1218 The list is in descending order by START.
1220 The `:insn' key is a keyword to distinguish it as a vc-rcs.el extension."
1221 (setq buffer
(get-buffer (or buffer
(current-buffer))))
1223 ;; An RCS masterfile can be viewed as containing four regular (for the
1224 ;; most part) sections: (a) the "headers", (b) the "rev headers", (c)
1225 ;; the "description" and (d) the "rev bodies", in that order. In the
1226 ;; returned alist (see docstring), elements from (b) and (d) are
1227 ;; combined pairwise to form the "revisions", while those from (a) and
1228 ;; (c) are simply combined to form the "headers".
1230 ;; Loosely speaking, each section contains a series of alternating
1231 ;; "tags" and "printed representations". In the (b) and (d), many
1232 ;; such series can appear, and a revision number on a line by itself
1233 ;; precedes the series of tags and printed representations associated
1236 ;; In (a) and (b), the printed representations (with the exception of
1237 ;; the `comment' tag in the headers) terminate with a semicolon, which
1238 ;; is NOT part of the "value" finally associated with the tag. All
1239 ;; other printed representations are in "@@-format"; there is an "@",
1240 ;; the middle part (to be translated into the value), another "@" and
1241 ;; a newline. Each "@@" in the middle part indicates the position of
1242 ;; a single "@" (and consequently the requirement of an additional
1243 ;; initial step when translating to the value).
1245 ;; Parser state includes vars that collect parts of the return value...
1246 (let ((desc nil
) (headers nil
) (revs nil
)
1247 ;; ... as well as vars that support a single-pass, tag-assisted,
1248 ;; minimal-data-copying scan. Basically -- skirting around the
1249 ;; grouping by revision required in (b) and (d) -- we repeatedly
1250 ;; and context-sensitively read a tag (that MUST be present),
1251 ;; determine the bounds of the printed representation, translate
1252 ;; it into a value, and push the tag plus value onto one of the
1253 ;; collection vars. Finally, we return the parse tree
1254 ;; incorporating the values of the collection vars (see "rv").
1256 ;; A symbol or string to keep track of context (for error messages).
1258 ;; A symbol, the current tag.
1260 ;; Region (begin and end buffer positions) of the printed
1261 ;; representation for the current tag.
1263 ;; A list of buffer positions where "@@" can be found within the
1264 ;; printed representation region. For each location, we push two
1265 ;; elements onto the list, 1+ and 2+ the location, respectively,
1266 ;; with the 2+ appearing at the head. In this way, the expression
1267 ;; `(,e ,@@-holes ,b)
1268 ;; describes regions that can be concatenated (in reverse order)
1269 ;; to "de-@@-format" the printed representation as the first step
1270 ;; to translating it into some value. See internal func `gather'.
1273 ((sw () (skip-chars-forward " \t\n")) ; i.e., `[:space:]'
1274 (at (tag) (save-excursion (eq tag
(read buffer
))))
1275 (to-eol () (buffer-substring-no-properties
1276 (point) (progn (forward-line 1)
1278 (to-semi () (setq b
(point)
1279 e
(progn (search-forward ";")
1281 (to-one@ () (setq @-holes nil
1282 b
(progn (search-forward "@") (point))
1283 e
(progn (while (and (search-forward "@")
1284 (= ?
@ (char-after)))
1285 (push (point) @-holes
)
1287 (push (point) @-holes
))
1289 (tok+val
(set-b+e name
&optional proc
)
1290 (unless (eq name
(setq tok
(read buffer
)))
1291 (error "Missing `%s' while parsing %s" name context
))
1296 (buffer-substring-no-properties b e
))))
1297 (k-semi (name &optional proc
) (tok+val
#'to-semi name proc
))
1298 (gather (b e
@-holes
)
1299 (let ((pairs `(,e
,@@-holes
,b
))
1302 (push (buffer-substring-no-properties
1303 (cadr pairs
) (car pairs
))
1305 (setq pairs
(cddr pairs
)))
1306 (apply #'concat acc
)))
1307 (gather1 () (gather b e
@-holes
))
1308 (k-one@ (name &optional later
)
1309 (tok+val
#'to-one
@ name
(if later
(lambda () t
) #'gather1
))))
1311 (goto-char (point-min))
1313 (setq context
'headers
)
1314 (cl-flet ((hpush (name &optional proc
)
1315 (push (k-semi name proc
) headers
)))
1322 (mapcar (lambda (together)
1323 (let ((two (split-string together
":")))
1324 (setcar two
(intern (car two
)))
1325 (setcdr two
(cadr two
))
1328 (buffer-substring-no-properties b e
)))))
1330 (push `(strict .
,(when (at 'strict
)
1331 (search-forward ";")
1335 (push (k-one@ 'comment
) headers
)
1336 (search-forward ";"))
1338 (push (k-one@ 'expand
) headers
)
1339 (search-forward ";"))
1340 (setq headers
(nreverse headers
))
1342 (sw) (setq context
'rev-headers
)
1343 (while (looking-at "[0-9]")
1347 (let ((ls (mapcar 'string-to-number
1349 (buffer-substring-no-properties
1352 ;; Hack the year -- verified to be the
1353 ;; same algorithm used in RCS 5.7.
1354 (when (< (car ls
) 100)
1355 (setcar ls
(+ 1900 (car ls
))))
1356 (apply #'encode-time
(nreverse ls
)))))
1357 ,@(mapcar #'k-semi
'(author state
))
1361 (buffer-substring-no-properties b e
))))
1365 (setq revs
(nreverse revs
))
1367 (sw) (setq context
'desc
1368 desc
(k-one@ 'desc
))
1371 ;; Element of `revs' that initially holds only header info.
1372 ;; "Pairwise combination" occurs when we add body info.
1374 ;; Components of the editing commands (aside from the actual
1375 ;; text) that comprise the `text' printed representations
1376 ;; (not including the "head" revision).
1378 ;; Ascending (reversed) `@-holes' which the internal func
1379 ;; `incg' pops to effect incremental gathering.
1381 ;; Function to extract text (for the `a' command), either
1382 ;; `incg' or `buffer-substring-no-properties'. (This is
1383 ;; for speed; strictly speaking, it is sufficient to use
1384 ;; only the former since it behaves identically to the
1385 ;; latter in the absence of "@@".)
1387 (cl-flet ((incg (beg end
)
1388 (let ((b beg
) (e end
) @-holes
)
1389 (while (and asc
(< (car asc
) e
))
1390 (push (pop asc
) @-holes
)
1391 (push (pop asc
) @-holes
))
1392 ;; Self-deprecate when work is done.
1393 ;; Folding many dimensions into one.
1394 ;; Thanks B.Mandelbrot, for complex sum.
1395 ;; O beauteous math! --the Unvexed Bum
1397 (setq sub
#'buffer-substring-no-properties
))
1398 (gather b e
@-holes
))))
1401 (setq context
(to-eol)
1402 rev
(or (assoc context revs
)
1403 (error "Rev `%s' has body but no head"
1405 (push (k-one@ 'log
) (cdr rev
))
1406 ;; For rev body `text' tags, delay translation slightly...
1407 (push (k-one@ 'text t
) (cdr rev
))
1408 ;; ... until we decide which tag and value is appropriate to
1409 ;; collect. For the "head" revision, compute the value of the
1410 ;; `text' printed representation by simple `gather'. For all
1411 ;; other revisions, replace the `text' tag+value with `:insn'
1412 ;; plus value, always scanning in-place.
1413 (if (string= context
(cdr (assq 'head headers
)))
1414 (setcdr (cadr rev
) (gather b e
@-holes
))
1416 (setq asc
(nreverse @-holes
)
1418 (setq sub
#'buffer-substring-no-properties
))
1421 (while (< (point) e
)
1423 (setq cmd
(char-before)
1424 start
(read (current-buffer))
1425 act
(read (current-buffer)))
1429 ;; `d' means "delete lines".
1430 ;; For Emacs spirit, we use `k' for "kill".
1433 ;; `a' means "append after this line" but
1434 ;; internally we normalize it so that START
1435 ;; specifies the actual line for insert, thus
1436 ;; requiring less hair in the realization algs.
1437 ;; For Emacs spirit, we use `i' for "insert".
1439 ,(funcall sub
(point) (progn (forward-line act
)
1441 (_ (error "Bad command `%c' in `text' for rev `%s'"
1445 (setcar (cdr rev
) (cons :insn acc
)))))))
1447 `((headers ,desc
,@headers
)
1448 (revisions ,@revs
)))))
1452 ;;; vc-rcs.el ends here