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
49 (defcustom vc-rcs-release nil
50 "The release number of your RCS installation, as a string.
51 If nil, VC itself computes this value when it is first needed."
52 :type
'(choice (const :tag
"Auto" nil
)
53 (string :tag
"Specified")
54 (const :tag
"Unknown" unknown
))
57 (defcustom vc-rcs-register-switches nil
58 "Switches for registering a file in RCS.
59 A string or list of strings passed to the checkin program by
60 \\[vc-register]. If nil, use the value of `vc-register-switches'.
61 If t, use no switches."
62 :type
'(choice (const :tag
"Unspecified" nil
)
64 (string :tag
"Argument String")
65 (repeat :tag
"Argument List" :value
("") string
))
69 (defcustom vc-rcs-diff-switches nil
70 "String or list of strings specifying switches for RCS diff under VC.
71 If nil, use the value of `vc-diff-switches'. If t, use no switches."
72 :type
'(choice (const :tag
"Unspecified" nil
)
74 (string :tag
"Argument String")
75 (repeat :tag
"Argument List" :value
("") string
))
79 (defcustom vc-rcs-header
'("$Id\ $")
80 "Header keywords to be inserted by `vc-insert-headers'."
81 :type
'(repeat string
)
82 :version
"24.1" ; no longer consult the obsolete vc-header-alist
85 (defcustom vc-rcsdiff-knows-brief nil
86 "Indicates whether rcsdiff understands the --brief option.
87 The value is either `yes', `no', or nil. If it is nil, VC tries
88 to use --brief and sets this variable to remember whether it worked."
89 :type
'(choice (const :tag
"Work out" nil
) (const yes
) (const no
))
92 ;; This needs to be autoloaded because vc-rcs-registered uses it (via
93 ;; vc-default-registered), and vc-hooks needs to be able to check
94 ;; for a registered backend without loading every backend.
96 (defcustom vc-rcs-master-templates
97 (purecopy '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
98 "Where to look for RCS master files.
99 For a description of possible values, see `vc-check-master-templates'."
100 :type
'(choice (const :tag
"Use standard RCS file names"
101 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
102 (repeat :tag
"User-specified"
109 ;;; Properties of the backend
111 (defun vc-rcs-revision-granularity () 'file
)
113 (defun vc-rcs-checkout-model (files)
114 "RCS-specific version of `vc-checkout-model'."
115 (let ((file (if (consp files
) (car files
) files
))
117 (when vc-consult-headers
118 (vc-file-setprop file
'vc-checkout-model nil
)
119 (vc-rcs-consult-headers file
)
120 (setq result
(vc-file-getprop file
'vc-checkout-model
)))
122 (progn (vc-rcs-fetch-master-state file
)
123 (vc-file-getprop file
'vc-checkout-model
)))))
126 ;;; State-querying functions
129 ;; The autoload cookie below places vc-rcs-registered directly into
130 ;; loaddefs.el, so that vc-rcs.el does not need to be loaded for
131 ;; every file that is visited.
134 (defun vc-rcs-registered (f) (vc-default-registered 'RCS f
)))
136 (defun vc-rcs-state (file)
137 "Implementation of `vc-state' for RCS."
138 (if (not (vc-rcs-registered file
))
140 (or (boundp 'vc-rcs-headers-result
)
141 (and vc-consult-headers
142 (vc-rcs-consult-headers file
)))
144 ;; vc-working-revision might not be known; in that case the
145 ;; property is nil. vc-rcs-fetch-master-state knows how to
147 (vc-rcs-fetch-master-state file
148 (vc-file-getprop file
149 'vc-working-revision
))))
150 (if (not (eq state
'up-to-date
))
152 (if (vc-rcs-workfile-unchanged-p file
)
154 (if (eq (vc-rcs-checkout-model (list file
)) 'locking
)
158 (autoload 'vc-expand-dirs
"vc")
160 (defun vc-rcs-dir-status-files (dir files update-function
)
161 (if (not files
) (setq files
(vc-expand-dirs (list dir
) 'RCS
)))
164 (let ((state (vc-state file
))
165 (frel (file-relative-name file
)))
166 (when (and (eq (vc-backend file
) 'RCS
)
167 (not (eq state
'up-to-date
)))
168 (push (list frel state
) result
))))
169 (funcall update-function result
)))
171 (defun vc-rcs-working-revision (file)
172 "RCS-specific version of `vc-working-revision'."
173 (or (and vc-consult-headers
174 (vc-rcs-consult-headers file
)
175 (vc-file-getprop file
'vc-working-revision
))
177 (vc-rcs-fetch-master-state file
)
178 (vc-file-getprop file
'vc-working-revision
))))
180 (autoload 'vc-master-name
"vc-filewise")
182 (defun vc-rcs-latest-on-branch-p (file &optional version
)
183 "Return non-nil if workfile version of FILE is the latest on its branch.
184 When VERSION is given, perform check for that version."
185 (unless version
(setq version
(vc-working-revision file
)))
188 (if (vc-rcs-trunk-p version
)
190 ;; Compare VERSION to the head version number.
191 (vc-insert-file (vc-master-name file
) "^[0-9]")
192 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
193 ;; If we are not on the trunk, we need to examine the
194 ;; whole current branch.
195 (vc-insert-file (vc-master-name file
) "^desc")
196 (vc-rcs-find-most-recent-rev (vc-branch-part version
))))))
198 (defun vc-rcs-workfile-unchanged-p (file)
199 "Has FILE remained unchanged since last checkout?"
200 ;; Try to use rcsdiff --brief. If rcsdiff does not understand that,
201 ;; do a double take and remember the fact for the future
202 (let* ((version (concat "-r" (vc-working-revision file
)))
203 (status (if (eq vc-rcsdiff-knows-brief
'no
)
204 (vc-do-command "*vc*" 1 "rcsdiff" file version
)
205 (vc-do-command "*vc*" 2 "rcsdiff" file
"--brief" version
))))
207 (if (not vc-rcsdiff-knows-brief
)
208 (setq vc-rcsdiff-knows-brief
'no
209 status
(vc-do-command "*vc*" 1 "rcsdiff" file version
))
210 (error "rcsdiff failed"))
211 (if (not vc-rcsdiff-knows-brief
) (setq vc-rcsdiff-knows-brief
'yes
)))
212 ;; The workfile is unchanged if rcsdiff found no differences.
217 ;;; State-changing functions
220 (defun vc-rcs-create-repo ()
221 "Create a new RCS repository."
222 ;; RCS is totally file-oriented, so all we have to do is make the directory.
223 (make-directory "RCS"))
225 (autoload 'vc-switches
"vc")
227 (defun vc-rcs-register (files &optional comment
)
228 "Register FILES into the RCS version-control system.
229 Automatically retrieve a read-only version of the file with keywords expanded.
230 COMMENT can be used to provide an initial description for each FILES.
231 Passes either `vc-rcs-register-switches' or `vc-register-switches'
235 (and (not (file-exists-p
236 (setq subdir
(expand-file-name "RCS"
237 (file-name-directory file
)))))
238 (not (directory-files (file-name-directory file
)
240 (yes-or-no-p "Create RCS subdirectory? ")
241 (make-directory subdir
))
242 (apply #'vc-do-command
"*vc*" 0 "ci" file
243 ;; if available, use the secure registering option
244 (and (vc-rcs-release-p "5.6.4") "-i")
246 ;; Some old MS-Windows ports of RCS crash when "ci -i" is
247 ;; invoked without -t; indulge them.
248 (concat "-t-" (or comment
""))
249 (vc-switches 'RCS
'register
))
250 ;; parse output to find master file name and workfile version
251 (with-current-buffer "*vc*"
252 (goto-char (point-min))
254 (if (looking-at (concat "^\\(.*\\) <-- "
255 (file-name-nondirectory file
)))
257 ;; if we couldn't find the master name,
258 ;; run vc-rcs-registered to get it
259 ;; (will be stored into the vc-master-name property)
260 (vc-rcs-registered file
)
261 (vc-file-setprop file
'vc-master-name
262 (if (file-name-absolute-p name
)
266 (file-name-directory file
))))))
267 (vc-file-setprop file
'vc-working-revision
268 (if (re-search-forward
269 "^initial revision: \\([0-9.]+\\).*\n"
271 (match-string 1))))))
273 (defun vc-rcs-responsible-p (file)
274 "Return non-nil if RCS thinks it would be responsible for registering FILE."
275 ;; TODO: check for all the patterns in vc-rcs-master-templates
276 (file-directory-p (expand-file-name "RCS"
277 (if (file-directory-p file
)
279 (file-name-directory file
)))))
281 (defun vc-rcs-receive-file (file rev
)
282 "Implementation of receive-file for RCS."
283 (let ((checkout-model (vc-rcs-checkout-model (list file
))))
284 (vc-rcs-register file
"")
285 (when (eq checkout-model
'implicit
)
286 (vc-rcs-set-non-strict-locking file
))
287 (vc-rcs-set-default-branch file
(concat rev
".1"))))
289 (defun vc-rcs-unregister (file)
290 "Unregister FILE from RCS.
291 If this leaves the RCS subdirectory empty, ask the user
292 whether to remove it."
293 (unless (memq (vc-state file
) '(nil unregistered
))
294 (let* ((master (vc-master-name file
))
295 (dir (file-name-directory master
))
296 (backup-info (find-backup-file-name master
)))
297 (if (not backup-info
)
299 (rename-file master
(car backup-info
) 'ok-if-already-exists
)
300 (dolist (f (cdr backup-info
)) (ignore-errors (delete-file f
))))
301 (and (string= (file-name-nondirectory (directory-file-name dir
)) "RCS")
302 ;; check whether RCS dir is empty, i.e. it does not
303 ;; contain any files except "." and ".."
304 (not (directory-files dir nil
305 "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*"))
306 (yes-or-no-p (format "Directory %s is empty; remove it? " dir
))
307 (delete-directory dir
)))))
309 (defun vc-rcs-checkin (files comment
&optional rev
)
310 "RCS-specific version of `vc-backend-checkin'."
311 (let ((switches (vc-switches 'RCS
'checkin
)))
312 ;; Now operate on the files
313 (dolist (file (vc-expand-dirs files
'RCS
))
314 (let ((old-version (vc-working-revision file
)) new-version
315 (default-branch (vc-file-getprop file
'vc-rcs-default-branch
)))
316 ;; Force branch creation if an appropriate
317 ;; default branch has been set.
320 (string-match (concat "^" (regexp-quote old-version
) "\\.")
322 (setq rev default-branch
)
323 (setq switches
(cons "-f" switches
)))
324 (if (and (not rev
) old-version
)
325 (setq rev
(vc-branch-part old-version
)))
326 (apply #'vc-do-command
"*vc*" 0 "ci" (vc-master-name file
)
327 ;; if available, use the secure check-in option
328 (and (vc-rcs-release-p "5.6.4") "-j")
330 (concat "-m" comment
)
332 (vc-file-setprop file
'vc-working-revision nil
)
334 ;; determine the new workfile version
336 (goto-char (point-min))
337 (when (or (re-search-forward
338 "new revision: \\([0-9.]+\\);" nil t
)
340 "reverting to previous revision \\([0-9.]+\\)" nil t
))
341 (setq new-version
(match-string 1))
342 (vc-file-setprop file
'vc-working-revision new-version
))
344 ;; if we got to a different branch, adjust the default
345 ;; branch accordingly
347 ((and old-version new-version
348 (not (string= (vc-branch-part old-version
)
349 (vc-branch-part new-version
))))
350 (vc-rcs-set-default-branch file
351 (if (vc-rcs-trunk-p new-version
) nil
352 (vc-branch-part new-version
)))
353 ;; If this is an old (pre-1992!) RCS release, we might have
354 ;; to remove a remaining lock.
355 (if (not (vc-rcs-release-p "5.6.2"))
356 ;; exit status of 1 is also accepted.
357 ;; It means that the lock was removed before.
358 (vc-do-command "*vc*" 1 "rcs" (vc-master-name file
)
359 (concat "-u" old-version
)))))))))
361 (defun vc-rcs-find-revision (file rev buffer
)
362 (apply #'vc-do-command
363 (or buffer
"*vc*") 0 "co" (vc-master-name file
)
364 "-q" ;; suppress diagnostic output
366 (vc-switches 'RCS
'checkout
)))
368 (defun vc-rcs-checkout (file &optional rev
)
369 "Retrieve a copy of a saved version of FILE. If FILE is a directory,
370 attempt the checkout for all registered files beneath it."
371 (if (file-directory-p file
)
372 (mapc 'vc-rcs-checkout
(vc-expand-dirs (list file
) 'RCS
))
373 (let ((file-buffer (get-file-buffer file
))
375 (message "Checking out %s..." file
)
377 ;; Change buffers to get local value of vc-checkout-switches.
378 (if file-buffer
(set-buffer file-buffer
))
379 (setq switches
(vc-switches 'RCS
'checkout
))
380 ;; Save this buffer's default-directory
381 ;; and use save-excursion to make sure it is restored
382 ;; in the same buffer it was saved in.
383 (let ((default-directory default-directory
))
385 ;; Adjust the default-directory so that the check-out creates
386 ;; the file in the right place.
387 (setq default-directory
(file-name-directory file
))
389 ;; if we should go to the head of the trunk,
390 ;; clear the default branch first
391 (and rev
(string= rev
"")
392 (vc-rcs-set-default-branch file nil
))
393 ;; now do the checkout
394 (apply #'vc-do-command
395 "*vc*" 0 "co" (vc-master-name file
)
396 ;; If locking is not strict, force to overwrite
397 ;; the writable workfile.
398 (if (eq (vc-rcs-checkout-model (list file
)) 'implicit
) "-f")
401 ;; a literal revision was specified
403 (let ((workrev (vc-working-revision file
)))
407 ;; no revision specified:
408 ;; use current workfile version
411 (if (not (vc-rcs-trunk-p workrev
))
412 ;; ... go to head of current branch
413 (vc-branch-part workrev
)
414 ;; ... go to head of trunk
415 (vc-rcs-set-default-branch file
419 ;; determine the new workfile version
420 (with-current-buffer "*vc*"
422 (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1)))
423 (vc-file-setprop file
'vc-working-revision new-version
)
424 ;; if necessary, adjust the default branch
425 (and rev
(not (string= rev
""))
426 (vc-rcs-set-default-branch
428 (if (vc-rcs-latest-on-branch-p file new-version
)
429 (if (vc-rcs-trunk-p new-version
) nil
430 (vc-branch-part new-version
))
432 (message "Checking out %s...done" file
))))))
434 (defun vc-rcs-revert (file &optional _contents-done
)
435 "Revert FILE to the version it was based on. If FILE is a directory,
436 revert all registered files beneath it."
437 (if (file-directory-p file
)
438 (mapc 'vc-rcs-revert
(vc-expand-dirs (list file
) 'RCS
))
439 (vc-do-command "*vc*" 0 "co" (vc-master-name file
) "-f"
440 (concat (if (eq (vc-state file
) 'edited
) "-u" "-r")
441 (vc-working-revision file
)))))
443 (defun vc-rcs-merge-file (file)
444 "Accept a file merge request, prompting for revisions."
445 (let* ((first-revision
447 (concat "Merge " file
" from branch or revision: ")
452 ((string= first-revision
"")
453 (error "A starting RCS revision is required"))
455 (if (not (vc-branch-p first-revision
))
456 (setq second-revision
458 "Second RCS revision: "
460 (concat (vc-branch-part first-revision
) ".")))
461 ;; We want to merge an entire branch. Set revisions
462 ;; accordingly, so that vc-rcs-merge understands us.
463 (setq second-revision first-revision
)
464 ;; first-revision must be the starting point of the branch
465 (setq first-revision
(vc-branch-part first-revision
)))))
466 (vc-rcs-merge file first-revision second-revision
)))
468 (defun vc-rcs-merge (file first-version
&optional second-version
)
469 "Merge changes into current working copy of FILE.
470 The changes are between FIRST-VERSION and SECOND-VERSION."
471 (vc-do-command "*vc*" 1 "rcsmerge" (vc-master-name file
)
472 "-kk" ; ignore keyword conflicts
473 (concat "-r" first-version
)
474 (if second-version
(concat "-r" second-version
))))
476 (defun vc-rcs-steal-lock (file &optional rev
)
477 "Steal the lock on the current workfile for FILE and revision REV.
478 If FILE is a directory, steal the lock on all registered files beneath it.
479 Needs RCS 5.6.2 or later for -M."
480 (if (file-directory-p file
)
481 (mapc 'vc-rcs-steal-lock
(vc-expand-dirs (list file
) 'RCS
))
482 (vc-do-command "*vc*" 0 "rcs" (vc-master-name file
) "-M" (concat "-u" rev
))
483 ;; Do a real checkout after stealing the lock, so that we see
485 (vc-do-command "*vc*" 0 "co" (vc-master-name file
) "-f" (concat "-l" rev
))
486 ;; Must clear any headers here because they wouldn't
487 ;; show that the file is locked now.
488 (let* ((filename (or file buffer-file-name
))
489 (visited (find-buffer-visiting filename
)))
491 (let ((context (vc-buffer-context)))
492 ;; save-excursion may be able to relocate point and mark
493 ;; properly. If it fails, vc-restore-buffer-context
494 ;; will give it a second try.
496 (vc-rcs-clear-headers))
497 (vc-restore-buffer-context context
))
498 (set-buffer (find-file-noselect filename
))
499 (vc-rcs-clear-headers)
500 (kill-buffer filename
)))))
502 (defun vc-rcs-modify-change-comment (files rev comment
)
503 "Modify the change comments change on FILES on a specified REV. If FILE is a
504 directory the operation is applied to all registered files beneath it."
505 (dolist (file (vc-expand-dirs files
'RCS
))
506 (vc-do-command "*vc*" 0 "rcs" (vc-master-name file
)
507 (concat "-m" rev
":" comment
))))
511 ;;; History functions
514 (defun vc-rcs-print-log-cleanup ()
515 (let ((inhibit-read-only t
))
516 (goto-char (point-max))
518 (while (looking-at "=*\n")
519 (delete-char (- (match-end 0) (match-beginning 0)))
521 (goto-char (point-min))
522 (when (looking-at "[\b\t\n\v\f\r ]+")
523 (delete-char (- (match-end 0) (match-beginning 0))))))
525 (defun vc-rcs-print-log (files buffer
&optional _shortlog
526 _start-revision-ignored limit
)
527 "Print commit log associated with FILES into specified BUFFER.
528 Remaining arguments are ignored.
529 If FILE is a directory the operation is applied to all registered
531 (vc-do-command (or buffer
"*vc*") 0 "rlog"
532 (mapcar 'vc-master-name
(vc-expand-dirs files
'RCS
)))
533 (with-current-buffer (or buffer
"*vc*")
534 (vc-rcs-print-log-cleanup))
535 (when limit
'limit-unsupported
))
537 (defun vc-rcs-diff (files &optional oldvers newvers buffer _async
)
538 "Get a difference report using RCS between two sets of files."
539 (apply #'vc-do-command
(or buffer
"*vc-diff*")
540 ;; The repo is local, so this is fast anyway.
542 "rcsdiff" (vc-expand-dirs files
'RCS
)
544 (and oldvers
(concat "-r" oldvers
))
545 (and newvers
(concat "-r" newvers
)))
546 (vc-switches 'RCS
'diff
))))
548 (defun vc-rcs-find-admin-dir (file)
549 "Return the administrative directory of FILE."
550 (vc-find-root file
"RCS"))
552 (defun vc-rcs-comment-history (file)
553 "Return a string with all log entries stored in BACKEND for FILE."
554 (with-current-buffer "*vc*"
555 ;; Has to be written this way, this function is used by the CVS backend too
556 (vc-call-backend (vc-backend file
) 'print-log
(list file
))
558 (let ((separator (concat "^-+\nrevision [0-9.]+\ndate: .*\n"
559 "\\(branches: .*;\n\\)?"
560 "\\(\\*\\*\\* empty log message \\*\\*\\*\n\\)?")))
561 (goto-char (point-max)) (forward-line -
1)
562 (while (looking-at "=*\n")
563 (delete-char (- (match-end 0) (match-beginning 0)))
565 (goto-char (point-min))
566 (if (looking-at "[\b\t\n\v\f\r ]+")
567 (delete-char (- (match-end 0) (match-beginning 0))))
568 (goto-char (point-min))
569 (re-search-forward separator nil t
)
570 (delete-region (point-min) (point))
571 (while (re-search-forward separator nil t
)
572 (delete-region (match-beginning 0) (match-end 0))))
573 ;; Return the de-crufted comment list
576 (defun vc-rcs-annotate-command (file buffer
&optional revision
)
577 "Annotate FILE, inserting the results in BUFFER.
578 Optional arg REVISION is a revision to annotate from."
579 (vc-setup-buffer buffer
)
580 ;; Aside from the "head revision on the trunk", the instructions for
581 ;; each revision on the trunk are an ordered list of kill and insert
582 ;; commands necessary to go from the chronologically-following
583 ;; revision to this one. That is, associated with revision N are
584 ;; edits that applied to revision N+1 would result in revision N.
586 ;; On a branch, however, (some) things are inverted: the commands
587 ;; listed are those necessary to go from the chronologically-preceding
588 ;; revision to this one. That is, associated with revision N are
589 ;; edits that applied to revision N-1 would result in revision N.
591 ;; So, to get per-line history info, we apply reverse-chronological
592 ;; edits, starting with the head revision on the trunk, all the way
593 ;; back through the initial revision (typically "1.1" or similar),
594 ;; then apply forward-chronological edits -- keeping track of which
595 ;; revision is associated with each inserted line -- until we reach
596 ;; the desired revision for display (which may be either on the trunk
598 (let* ((tree (with-temp-buffer
599 (insert-file-contents (vc-rcs-registered file
))
601 (revisions (cdr (assq 'revisions tree
)))
602 ;; The revision N whose instructions we currently are processing.
603 (cur (cdr (assq 'head
(cdr (assq 'headers tree
)))))
604 ;; Alist from the parse tree for N.
605 (meta (cdr (assoc cur revisions
)))
606 ;; Point and temporary string, respectively.
608 ;; "Next-branch list". Nil means the desired revision to
609 ;; display lives on the trunk. Non-nil means it lives on a
610 ;; branch, in which case the value is a list of revision pairs
611 ;; (PARENT . CHILD), the first PARENT being on the trunk, that
612 ;; links each series of revisions in the path from the initial
613 ;; revision to the desired revision to display.
615 ;; "Path-accumulate-predicate plus revision/date/author".
616 ;; Until set, forward-chronological edits are not accumulated.
617 ;; Once set, its value (updated every revision) is used for
618 ;; the text property `:vc-rcs-r/d/a' for inserts during
619 ;; processing of forward-chronological instructions for N.
620 ;; See internal func `r/d/a'.
622 ;; List of forward-chronological instructions, each of the
623 ;; form: (POS . ACTION), where POS is a buffer position. If
624 ;; ACTION is a string, it is inserted, otherwise it is taken as
625 ;; the number of characters to be deleted.
627 ;; N+1. When `cur' is "", this is the initial revision.
631 (unless (assoc revision revisions
)
632 (error "No such revision: %s" revision
))
633 ;; Find which branches (if any) must be included in the edits.
636 (while (setq bpt
(vc-branch-part par
)
637 par
(vc-branch-part bpt
))
638 (setq kids
(cdr (assq 'branches
(cdr (assoc par revisions
)))))
639 ;; A branchpoint may have multiple children. Find the right one.
640 (while (not (string= bpt
(vc-branch-part (car kids
))))
641 (setq kids
(cdr kids
)))
642 (push (cons par
(car kids
)) nbls
)))
643 ;; Start with the full text.
645 (insert (cdr (assq 'text meta
)))
646 ;; Apply reverse-chronological edits on the trunk, computing and
647 ;; accumulating forward-chronological edits after some point, for
649 (cl-flet ((r/d
/a
() (vector pre
650 (cdr (assq 'date meta
))
651 (cdr (assq 'author meta
)))))
652 (while (when (setq pre cur cur
(cdr (assq 'next meta
)))
653 (not (string= "" cur
)))
655 ;; Start accumulating the forward-chronological edits when N+1
656 ;; on the trunk is either the desired revision to display, or
657 ;; the appropriate branchpoint for it. Do this before
658 ;; updating `meta' since `r/d/a' uses N+1's `meta' value.
659 prda
(when (or prda
(string= (if nbls
(caar nbls
) revision
) pre
))
661 meta
(cdr (assoc cur revisions
)))
662 ;; Edits in the parse tree specify a line number (in the buffer
663 ;; *BEFORE* editing occurs) to start from, but line numbers
664 ;; change as a result of edits. To DTRT, we apply edits in
665 ;; order of descending buffer position so that edits further
666 ;; down in the buffer occur first w/o corrupting specified
667 ;; buffer positions of edits occurring towards the beginning of
668 ;; the buffer. In this way we avoid using markers. A pleasant
669 ;; property of this approach is ability to push instructions
670 ;; onto `path' directly, w/o need to maintain rev boundaries.
671 (dolist (insn (cdr (assq :insn meta
)))
672 (goto-char (point-min))
673 (forward-line (1- (pop insn
)))
676 (`k
(setq s
(buffer-substring-no-properties
677 p
(progn (forward-line (car insn
))
680 (push `(,p .
,(propertize s
:vc-rcs-r
/d
/a prda
)) path
))
681 (delete-region p
(point)))
682 (`i
(setq s
(car insn
))
684 (push `(,p .
,(length s
)) path
))
686 ;; For the initial revision, setting `:vc-rcs-r/d/a' directly is
687 ;; equivalent to pushing an insert instruction (of the entire buffer
688 ;; contents) onto `path' then erasing the buffer, but less wasteful.
689 (put-text-property (point-min) (point-max) :vc-rcs-r
/d
/a
(r/d
/a
))
690 ;; Now apply the forward-chronological edits for the trunk.
692 (goto-char (pop insn
))
696 ;; Now apply the forward-chronological edits (directly from the
697 ;; parse-tree) for the branch(es), if necessary. We re-use vars
698 ;; `pre' and `meta' for the sake of internal func `r/d/a'.
700 (setq pre
(cdr (pop nbls
)))
702 (setq meta
(cdr (assoc pre revisions
))
704 (dolist (insn (cdr (assq :insn meta
)))
705 (goto-char (point-min))
706 (forward-line (1- (pop insn
)))
709 (point) (progn (forward-line (car insn
))
711 (`i
(insert (propertize
714 (or prda
(setq prda
(r/d
/a
))))))))
715 (prog1 (not (string= (if nbls
(caar nbls
) revision
) pre
))
716 (setq pre
(cdr (assq 'next meta
)))))))))
717 ;; Lastly, for each line, insert at bol nicely-formatted history info.
718 ;; We do two passes to collect summary information used to minimize
719 ;; the annotation's usage of screen real-estate: (1) Consider rendered
720 ;; width of revision plus author together as a unit; and (2) Omit
721 ;; author entirely if all authors are the same as the user.
722 (let ((ht (make-hash-table :test
'eq
))
723 (me (user-login-name))
727 (goto-char (point-max))
730 (setq rda
(get-text-property (point) :vc-rcs-r
/d
/a
))
731 (unless (gethash rda ht
)
733 all-me
(and all-me
(string= a me
)))
734 (puthash rda
(setq w
(+ (length (aref rda
0))
737 (setq maxw
(max w maxw
))))
738 (let ((padding (make-string maxw
32)))
739 (cl-flet ((pad (w) (substring-no-properties padding w
))
740 (render (rda &rest ls
)
743 (format-time-string "%Y-%m-%d" (aref rda
1))
747 :vc-annotate-prefix t
752 (puthash rda
(render rda
(pad w
) ": ") ht
))
754 (puthash rda
(render rda
" " (pad w
) " " (aref rda
2) ": ") ht
)))
757 (insert (gethash (get-text-property (point) :vc-rcs-r
/d
/a
) ht
))
760 (declare-function vc-annotate-convert-time
"vc-annotate" (&optional time
))
762 (defun vc-rcs-annotate-current-time ()
763 "Return the current time, based at midnight of the current day, and
764 encoded as fractional days."
765 (vc-annotate-convert-time
766 (apply #'encode-time
0 0 0 (nthcdr 3 (decode-time)))))
768 (defun vc-rcs-annotate-time ()
769 "Return the time of the next annotation (as fraction of days)
770 systime, or nil if there is none. Also, reposition point."
772 (prog1 (vc-annotate-convert-time
773 (aref (get-text-property (point) :vc-rcs-r
/d
/a
) 1))
774 (goto-char (next-single-property-change (point) :vc-annotate-prefix
)))))
776 (defun vc-rcs-annotate-extract-revision-at-line ()
777 (aref (get-text-property (point) :vc-rcs-r
/d
/a
) 0))
784 (autoload 'vc-tag-precondition
"vc")
785 (declare-function vc-file-tree-walk
"vc" (dirname func
&rest args
))
787 (defun vc-rcs-create-tag (dir name branchp
)
789 (error "RCS backend does not support module branches"))
790 (let ((result (vc-tag-precondition dir
)))
792 (error "File %s is not up-to-date" result
)
796 (vc-do-command "*vc*" 0 "rcs" (vc-master-name f
) (concat "-n" name
":")))))))
803 (defun vc-rcs-trunk-p (rev)
804 "Return t if REV is a revision on the trunk."
805 (not (eq nil
(string-match "\\`[0-9]+\\.[0-9]+\\'" rev
))))
807 (defun vc-rcs-minor-part (rev)
808 "Return the minor revision number of a revision number REV."
809 (string-match "[0-9]+\\'" rev
)
810 (substring rev
(match-beginning 0) (match-end 0)))
812 (defun vc-rcs-previous-revision (_file rev
)
813 "Return the revision number immediately preceding REV for FILE,
814 or nil if there is no previous revision. This default
815 implementation works for MAJOR.MINOR-style revision numbers as
816 used by RCS and CVS."
817 (let ((branch (vc-branch-part rev
))
818 (minor-num (string-to-number (vc-rcs-minor-part rev
))))
821 ;; revision does probably not start a branch or release
822 (concat branch
"." (number-to-string (1- minor-num
)))
823 (if (vc-rcs-trunk-p rev
)
824 ;; we are at the beginning of the trunk --
825 ;; don't know anything to return here
827 ;; we are at the beginning of a branch --
828 ;; return revision of starting point
829 (vc-branch-part branch
))))))
831 (defun vc-rcs-next-revision (file rev
)
832 "Return the revision number immediately following REV for FILE,
833 or nil if there is no next revision. This default implementation
834 works for MAJOR.MINOR-style revision numbers as used by RCS
836 (when (not (string= rev
(vc-working-revision file
)))
837 (let ((branch (vc-branch-part rev
))
838 (minor-num (string-to-number (vc-rcs-minor-part rev
))))
839 (concat branch
"." (number-to-string (1+ minor-num
))))))
841 ;; You might think that this should be distributed with RCS, but
842 ;; apparently not. CVS sometimes provides a version of it.
843 ;; http://lists.gnu.org/archive/html/emacs-devel/2014-05/msg00288.html
844 (defvar vc-rcs-rcs2log-program
846 (cond ((file-executable-p
847 (setq exe
(expand-file-name "rcs2log" exec-directory
)))
849 ;; In the unlikely event that someone is running an
850 ;; uninstalled Emacs and wants to do something RCS-related.
852 (setq exe
(expand-file-name "lib-src/rcs2log" source-directory
)))
855 "Path to the `rcs2log' program (normally in `exec-directory').")
857 (autoload 'vc-buffer-sync
"vc-dispatcher")
859 (defun vc-rcs-update-changelog (files)
860 "Default implementation of update-changelog.
861 Uses `rcs2log' which only works for RCS and CVS."
862 ;; FIXME: We (c|sh)ould add support for cvs2cl
863 (let ((odefault default-directory
)
864 (changelog (find-change-log))
865 ;; Presumably not portable to non-Unixy systems, along with rcs2log:
866 (tempfile (make-temp-file
867 (expand-file-name "vc"
868 (or small-temporary-file-directory
869 temporary-file-directory
))))
870 (login-name (or user-login-name
871 (format "uid%d" (number-to-string (user-uid)))))
872 (full-name (or add-log-full-name
875 (format "uid%d" (number-to-string (user-uid)))))
876 (mailing-address (or add-log-mailing-address
878 (find-file-other-window changelog
)
879 (barf-if-buffer-read-only)
882 (goto-char (point-min))
884 (message "Computing change log entries...")
885 (message "Computing change log entries... %s"
888 (setq default-directory odefault
)
889 (if (eq 0 (apply #'call-process vc-rcs-rcs2log-program
890 nil
(list t tempfile
) nil
892 "-u" (concat login-name
894 "\t" mailing-address
)
898 (expand-file-name f odefault
)))
901 (pop-to-buffer (get-buffer-create "*vc*"))
903 (insert-file-contents tempfile
)
905 (setq default-directory
(file-name-directory changelog
))
906 (delete-file tempfile
)))))
908 (defun vc-rcs-check-headers ()
909 "Check if the current file has any headers in it."
911 (goto-char (point-min))
912 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
913 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
915 (defun vc-rcs-clear-headers ()
916 "Clear RCS header value parts."
917 (let ((case-fold-search nil
))
918 (goto-char (point-min))
919 (while (re-search-forward
920 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
921 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
923 (replace-match "$\\1$"))))
925 (autoload 'vc-rename-master
"vc-filewise")
927 (defun vc-rcs-rename-file (old new
)
928 ;; Just move the master file (using vc-rcs-master-templates).
929 (vc-rename-master (vc-master-name old
) new vc-rcs-master-templates
))
931 (defun vc-rcs-find-file-hook ()
932 ;; If the file is locked by some other user, make
933 ;; the buffer read-only. Like this, even root
934 ;; cannot modify a file that someone else has locked.
935 (and (stringp (vc-state buffer-file-name
'RCS
))
936 (setq buffer-read-only t
)))
940 ;;; Internal functions
943 (defun vc-rcs-workfile-is-newer (file)
944 "Return non-nil if FILE is newer than its RCS master.
945 This likely means that FILE has been changed with respect
946 to its master version."
947 (let ((file-time (nth 5 (file-attributes file
)))
948 (master-time (nth 5 (file-attributes (vc-master-name file
)))))
949 (or (> (nth 0 file-time
) (nth 0 master-time
))
950 (and (= (nth 0 file-time
) (nth 0 master-time
))
951 (> (nth 1 file-time
) (nth 1 master-time
))))))
953 (defun vc-rcs-find-most-recent-rev (branch)
954 "Find most recent revision on BRANCH."
955 (goto-char (point-min))
956 (let ((latest-rev -
1) value
)
957 (while (re-search-forward (concat "^\\(" (regexp-quote branch
)
958 "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;")
960 (let ((rev (string-to-number (match-string 2))))
961 (when (< latest-rev rev
)
962 (setq latest-rev rev
)
963 (setq value
(match-string 1)))))
965 (vc-branch-part branch
))))
967 (defun vc-rcs-fetch-master-state (file &optional working-revision
)
968 "Compute the master file's idea of the state of FILE.
969 If a WORKING-REVISION is given, compute the state of that version,
970 otherwise determine the workfile version based on the master file.
971 This function sets the properties `vc-working-revision' and
972 `vc-checkout-model' to their correct values, based on the master
974 (when (and (file-regular-p file
) (vc-master-name file
))
976 (if (or (not (vc-insert-file (vc-master-name file
) "^[0-9]"))
977 (progn (goto-char (point-min))
978 (not (looking-at "^head[ \t\n]+[^;]+;$"))))
979 (error "File %s is not an RCS master file" (vc-master-name file
)))
980 (let ((workfile-is-latest nil
)
981 (default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1)))
982 (vc-file-setprop file
'vc-rcs-default-branch default-branch
)
983 (unless working-revision
984 ;; Workfile version not known yet. Determine that first. It
985 ;; is either the head of the trunk, the head of the default
986 ;; branch, or the "default branch" itself, if that is a full
990 ((or (not default-branch
) (string= "" default-branch
))
991 (setq working-revision
992 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
993 (setq workfile-is-latest t
))
994 ;; default branch is actually a revision
995 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
997 (setq working-revision default-branch
))
998 ;; else, search for the head of the default branch
999 (t (vc-insert-file (vc-master-name file
) "^desc")
1000 (setq working-revision
1001 (vc-rcs-find-most-recent-rev default-branch
))
1002 (setq workfile-is-latest t
)))
1003 (vc-file-setprop file
'vc-working-revision working-revision
))
1004 ;; Check strict locking
1005 (goto-char (point-min))
1006 (vc-file-setprop file
'vc-checkout-model
1007 (if (re-search-forward ";[ \t\n]*strict;" nil t
)
1008 'locking
'implicit
))
1009 ;; Compute state of workfile version
1010 (goto-char (point-min))
1012 (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):"
1013 (regexp-quote working-revision
)
1019 (if (or workfile-is-latest
1020 (vc-rcs-latest-on-branch-p file working-revision
))
1021 ;; workfile version is latest on branch
1023 ;; workfile version is not latest on branch
1025 ;; locked by the calling user
1026 ((and (stringp locking-user
)
1027 (string= locking-user
(vc-user-login-name file
)))
1028 ;; Don't call `vc-rcs-checkout-model' to avoid inf-looping.
1029 (if (or (eq (vc-file-getprop file
'vc-checkout-model
) 'locking
)
1031 (vc-rcs-latest-on-branch-p file working-revision
))
1033 ;; Locking is not used for the file, but the owner does
1034 ;; have a lock, and there is a higher version on the current
1035 ;; branch. Not sure if this can occur, and if it is right
1036 ;; to use `needs-merge' in this case.
1038 ;; locked by somebody else
1039 ((stringp locking-user
)
1042 (error "Error getting state of RCS file"))))))))
1044 (defun vc-rcs-consult-headers (file)
1045 "Search for RCS headers in FILE, and set properties accordingly.
1047 Returns: nil if no headers were found
1048 'rev if a workfile revision was found
1049 'rev-and-lock if revision and lock info was found"
1051 ((not (get-file-buffer file
)) nil
)
1052 ((let (status version
)
1053 (with-current-buffer (get-file-buffer file
)
1055 (goto-char (point-min))
1057 ;; search for $Id or $Header
1058 ;; -------------------------
1059 ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file.
1060 ((or (and (search-forward "$Id\ : " nil t
)
1061 (looking-at "[^ ]+ \\([0-9.]+\\) "))
1062 (and (progn (goto-char (point-min))
1063 (search-forward "$Header\ : " nil t
))
1064 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
1065 (goto-char (match-end 0))
1066 ;; if found, store the revision number ...
1067 (setq version
(match-string-no-properties 1))
1068 ;; ... and check for the locking state
1071 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
1072 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
1073 "[^ ]+ [^ ]+ ")) ; author & state
1074 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
1076 ;; unlocked revision
1078 ;;(setq locking-user 'none)
1079 (setq status
'rev-and-lock
))
1080 ;; revision is locked by some user
1081 ((looking-at "\\([^ ]+\\) \\$")
1082 ;;(setq locking-user (match-string-no-properties 1))
1083 (setq status
'rev-and-lock
))
1084 ;; everything else: false
1086 ;; unexpected information in
1087 ;; keyword string --> quit
1089 ;; search for $Revision
1090 ;; --------------------
1091 ((re-search-forward (concat "\\$"
1092 "Revision: \\([0-9.]+\\) \\$")
1094 ;; if found, store the revision number ...
1095 (setq version
(match-string-no-properties 1))
1096 ;; and see if there's any lock information
1097 (goto-char (point-min))
1098 (if (re-search-forward (concat "\\$" "Locker:") nil t
)
1099 (cond ((looking-at " \\([^ ]+\\) \\$")
1100 ;;(setq locking-user (match-string-no-properties 1))
1101 (setq status
'rev-and-lock
))
1102 ((looking-at " *\\$")
1103 ;;(setq locking-user 'none)
1104 (setq status
'rev-and-lock
))
1106 ;;(setq locking-user 'none)
1107 (setq status
'rev-and-lock
)))
1108 (setq status
'rev
)))
1109 ;; else: nothing found
1110 ;; -------------------
1112 (if status
(vc-file-setprop file
'vc-working-revision version
))
1115 (defun vc-release-greater-or-equal (r1 r2
)
1116 "Compare release numbers, represented as strings.
1117 Release components are assumed cardinal numbers, not decimal fractions
1118 \(5.10 is a higher release than 5.9). Omitted fields are considered
1119 lower \(5.6.7 is earlier than 5.6.7.1). Comparison runs till the end
1120 of the string is found, or a non-numeric component shows up \(5.6.7 is
1121 earlier than \"5.6.7 beta\", which is probably not what you want in
1122 some cases). This code is suitable for existing RCS release numbers.
1123 CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5)."
1126 (or (and (string-match "^\\.?\\([0-9]+\\)" r1
)
1127 (setq i1
(match-end 0))
1128 (setq v1
(string-to-number (match-string 1 r1
)))
1129 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
1130 (setq i2
(match-end 0))
1131 (setq v2
(string-to-number (match-string 1 r2
)))
1132 (if (> v1 v2
) (throw 'done t
)
1133 (if (< v1 v2
) (throw 'done nil
)
1135 (vc-release-greater-or-equal
1137 (substring r2 i2
)))))))
1139 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
1143 (defun vc-rcs-release-p (release)
1144 "Return t if we have RELEASE or better."
1145 (let ((installation (vc-rcs-system-release)))
1146 (if (and installation
1147 (not (eq installation
'unknown
)))
1148 (vc-release-greater-or-equal installation release
))))
1150 (defun vc-rcs-system-release ()
1151 "Return the RCS release installed on this system, as a string.
1152 Return symbol `unknown' if the release cannot be deducted. The user can
1153 override this using variable `vc-rcs-release'.
1155 If the user has not set variable `vc-rcs-release' and it is nil,
1156 variable `vc-rcs-release' is set to the returned value."
1158 (setq vc-rcs-release
1159 (or (and (zerop (vc-do-command "*vc*" nil
"rcs" nil
"-V"))
1160 (with-current-buffer (get-buffer "*vc*")
1161 (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1)))
1164 (defun vc-rcs-set-non-strict-locking (file)
1165 (vc-do-command "*vc*" 0 "rcs" file
"-U")
1166 (vc-file-setprop file
'vc-checkout-model
'implicit
)
1167 (set-file-modes file
(logior (file-modes file
) 128)))
1169 (defun vc-rcs-set-default-branch (file branch
)
1170 (vc-do-command "*vc*" 0 "rcs" (vc-master-name file
) (concat "-b" branch
))
1171 (vc-file-setprop file
'vc-rcs-default-branch branch
))
1173 (defun vc-rcs-parse (&optional buffer
)
1174 "Parse current buffer, presumed to be in RCS-style masterfile format.
1175 Optional arg BUFFER specifies another buffer to parse. Return an alist
1176 of two elements, w/ keys `headers' and `revisions' and values in turn
1177 sub-alists. For `headers', the values unless otherwise specified are
1178 strings and the keys are:
1181 head -- latest revision
1182 branch -- the branch the \"head revision\" lies on;
1183 absent if the head revision lies on the trunk
1185 symbols -- sub-alist of (SYMBOL . REVISION) elements
1186 locks -- if file is checked out, something like \"ttn:1.7\"
1187 strict -- t if \"strict locking\" is in effect, otherwise nil
1188 comment -- may be absent; typically something like \"# \" or \"; \"
1189 expand -- may be absent; ???
1191 For `revisions', the car is REVISION (string), the cdr a sub-alist,
1192 with string values (unless otherwise specified) and keys:
1194 date -- a time value (like that returned by `encode-time'); as a
1195 special case, a year value less than 100 is augmented by 1900
1197 state -- typically \"Exp\" or \"Rel\"
1198 branches -- list of revisions that begin branches from this revision
1199 next -- on the trunk: the chronologically-preceding revision, or \"\";
1200 on a branch: the chronologically-following revision, or \"\"
1201 log -- change log entry
1202 text -- for the head revision on the trunk, the body of the file;
1203 other revisions have `:insn' instead
1204 :insn -- for non-head revisions, a list of parsed instructions
1205 in one of two forms, in both cases START meaning \"first
1207 - `(START k COUNT)' -- kill COUNT lines
1208 - `(START i TEXT)' -- insert TEXT (a string)
1209 The list is in descending order by START.
1211 The `:insn' key is a keyword to distinguish it as a vc-rcs.el extension."
1212 (setq buffer
(get-buffer (or buffer
(current-buffer))))
1214 ;; An RCS masterfile can be viewed as containing four regular (for the
1215 ;; most part) sections: (a) the "headers", (b) the "rev headers", (c)
1216 ;; the "description" and (d) the "rev bodies", in that order. In the
1217 ;; returned alist (see docstring), elements from (b) and (d) are
1218 ;; combined pairwise to form the "revisions", while those from (a) and
1219 ;; (c) are simply combined to form the "headers".
1221 ;; Loosely speaking, each section contains a series of alternating
1222 ;; "tags" and "printed representations". In the (b) and (d), many
1223 ;; such series can appear, and a revision number on a line by itself
1224 ;; precedes the series of tags and printed representations associated
1227 ;; In (a) and (b), the printed representations (with the exception of
1228 ;; the `comment' tag in the headers) terminate with a semicolon, which
1229 ;; is NOT part of the "value" finally associated with the tag. All
1230 ;; other printed representations are in "@@-format"; there is an "@",
1231 ;; the middle part (to be translated into the value), another "@" and
1232 ;; a newline. Each "@@" in the middle part indicates the position of
1233 ;; a single "@" (and consequently the requirement of an additional
1234 ;; initial step when translating to the value).
1236 ;; Parser state includes vars that collect parts of the return value...
1237 (let ((desc nil
) (headers nil
) (revs nil
)
1238 ;; ... as well as vars that support a single-pass, tag-assisted,
1239 ;; minimal-data-copying scan. Basically -- skirting around the
1240 ;; grouping by revision required in (b) and (d) -- we repeatedly
1241 ;; and context-sensitively read a tag (that MUST be present),
1242 ;; determine the bounds of the printed representation, translate
1243 ;; it into a value, and push the tag plus value onto one of the
1244 ;; collection vars. Finally, we return the parse tree
1245 ;; incorporating the values of the collection vars (see "rv").
1247 ;; A symbol or string to keep track of context (for error messages).
1249 ;; A symbol, the current tag.
1251 ;; Region (begin and end buffer positions) of the printed
1252 ;; representation for the current tag.
1254 ;; A list of buffer positions where "@@" can be found within the
1255 ;; printed representation region. For each location, we push two
1256 ;; elements onto the list, 1+ and 2+ the location, respectively,
1257 ;; with the 2+ appearing at the head. In this way, the expression
1258 ;; `(,e ,@@-holes ,b)
1259 ;; describes regions that can be concatenated (in reverse order)
1260 ;; to "de-@@-format" the printed representation as the first step
1261 ;; to translating it into some value. See internal func `gather'.
1264 ((sw () (skip-chars-forward " \t\n")) ; i.e., `[:space:]'
1265 (at (tag) (save-excursion (eq tag
(read buffer
))))
1266 (to-eol () (buffer-substring-no-properties
1267 (point) (progn (forward-line 1)
1269 (to-semi () (setq b
(point)
1270 e
(progn (search-forward ";")
1272 (to-one@ () (setq @-holes nil
1273 b
(progn (search-forward "@") (point))
1274 e
(progn (while (and (search-forward "@")
1275 (= ?
@ (char-after)))
1276 (push (point) @-holes
)
1278 (push (point) @-holes
))
1280 (tok+val
(set-b+e name
&optional proc
)
1281 (unless (eq name
(setq tok
(read buffer
)))
1282 (error "Missing `%s' while parsing %s" name context
))
1287 (buffer-substring-no-properties b e
))))
1288 (k-semi (name &optional proc
) (tok+val
#'to-semi name proc
))
1289 (gather (b e
@-holes
)
1290 (let ((pairs `(,e
,@@-holes
,b
))
1293 (push (buffer-substring-no-properties
1294 (cadr pairs
) (car pairs
))
1296 (setq pairs
(cddr pairs
)))
1297 (apply #'concat acc
)))
1298 (gather1 () (gather b e
@-holes
))
1299 (k-one@ (name &optional later
)
1300 (tok+val
#'to-one
@ name
(if later
(lambda () t
) #'gather1
))))
1302 (goto-char (point-min))
1304 (setq context
'headers
)
1305 (cl-flet ((hpush (name &optional proc
)
1306 (push (k-semi name proc
) headers
)))
1313 (mapcar (lambda (together)
1314 (let ((two (split-string together
":")))
1315 (setcar two
(intern (car two
)))
1316 (setcdr two
(cadr two
))
1319 (buffer-substring-no-properties b e
)))))
1321 (push `(strict .
,(when (at 'strict
)
1322 (search-forward ";")
1326 (push (k-one@ 'comment
) headers
)
1327 (search-forward ";"))
1329 (push (k-one@ 'expand
) headers
)
1330 (search-forward ";"))
1331 (setq headers
(nreverse headers
))
1333 (sw) (setq context
'rev-headers
)
1334 (while (looking-at "[0-9]")
1338 (let ((ls (mapcar 'string-to-number
1340 (buffer-substring-no-properties
1343 ;; Hack the year -- verified to be the
1344 ;; same algorithm used in RCS 5.7.
1345 (when (< (car ls
) 100)
1346 (setcar ls
(+ 1900 (car ls
))))
1347 (apply #'encode-time
(nreverse ls
)))))
1348 ,@(mapcar #'k-semi
'(author state
))
1352 (buffer-substring-no-properties b e
))))
1356 (setq revs
(nreverse revs
))
1358 (sw) (setq context
'desc
1359 desc
(k-one@ 'desc
))
1362 ;; Element of `revs' that initially holds only header info.
1363 ;; "Pairwise combination" occurs when we add body info.
1365 ;; Components of the editing commands (aside from the actual
1366 ;; text) that comprise the `text' printed representations
1367 ;; (not including the "head" revision).
1369 ;; Ascending (reversed) `@-holes' which the internal func
1370 ;; `incg' pops to effect incremental gathering.
1372 ;; Function to extract text (for the `a' command), either
1373 ;; `incg' or `buffer-substring-no-properties'. (This is
1374 ;; for speed; strictly speaking, it is sufficient to use
1375 ;; only the former since it behaves identically to the
1376 ;; latter in the absence of "@@".)
1378 (cl-flet ((incg (beg end
)
1379 (let ((b beg
) (e end
) @-holes
)
1380 (while (and asc
(< (car asc
) e
))
1381 (push (pop asc
) @-holes
)
1382 (push (pop asc
) @-holes
))
1383 ;; Self-deprecate when work is done.
1384 ;; Folding many dimensions into one.
1385 ;; Thanks B.Mandelbrot, for complex sum.
1386 ;; O beauteous math! --the Unvexed Bum
1388 (setq sub
#'buffer-substring-no-properties
))
1389 (gather b e
@-holes
))))
1392 (setq context
(to-eol)
1393 rev
(or (assoc context revs
)
1394 (error "Rev `%s' has body but no head"
1396 (push (k-one@ 'log
) (cdr rev
))
1397 ;; For rev body `text' tags, delay translation slightly...
1398 (push (k-one@ 'text t
) (cdr rev
))
1399 ;; ... until we decide which tag and value is appropriate to
1400 ;; collect. For the "head" revision, compute the value of the
1401 ;; `text' printed representation by simple `gather'. For all
1402 ;; other revisions, replace the `text' tag+value with `:insn'
1403 ;; plus value, always scanning in-place.
1404 (if (string= context
(cdr (assq 'head headers
)))
1405 (setcdr (cadr rev
) (gather b e
@-holes
))
1407 (setq asc
(nreverse @-holes
)
1409 (setq sub
#'buffer-substring-no-properties
))
1412 (while (< (point) e
)
1414 (setq cmd
(char-before)
1415 start
(read (current-buffer))
1416 act
(read (current-buffer)))
1420 ;; `d' means "delete lines".
1421 ;; For Emacs spirit, we use `k' for "kill".
1424 ;; `a' means "append after this line" but
1425 ;; internally we normalize it so that START
1426 ;; specifies the actual line for insert, thus
1427 ;; requiring less hair in the realization algs.
1428 ;; For Emacs spirit, we use `i' for "insert".
1430 ,(funcall sub
(point) (progn (forward-line act
)
1432 (_ (error "Bad command `%c' in `text' for rev `%s'"
1436 (setcar (cdr rev
) (cons :insn acc
)))))))
1438 `((headers ,desc
,@headers
)
1439 (revisions ,@revs
)))))
1443 ;;; vc-rcs.el ends here