Fix typo.
[emacs.git] / lisp / vc-rcs.el
blob0f2551d49a3221a48063929aab7ad834e54deb02
1 ;;; vc-rcs.el --- support for RCS version-control
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: FSF (see vc.el for full credits)
7 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
9 ;; $Id$
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 3, or (at your option)
16 ;; any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
28 ;;; Commentary:
30 ;; See vc.el
32 ;; TODO:
33 ;; - remove call to vc-expand-dirs by implementing our own (which can just
34 ;; list the RCS subdir instead).
36 ;;; Code:
38 ;;;
39 ;;; Customization options
40 ;;;
42 (eval-when-compile
43 (require 'cl)
44 (require 'vc))
46 (defcustom vc-rcs-release nil
47 "*The release number of your RCS installation, as a string.
48 If nil, VC itself computes this value when it is first needed."
49 :type '(choice (const :tag "Auto" nil)
50 (string :tag "Specified")
51 (const :tag "Unknown" unknown))
52 :group 'vc)
54 (defcustom vc-rcs-register-switches nil
55 "*Extra switches for registering a file in RCS.
56 A string or list of strings. These are passed to the checkin program
57 by \\[vc-rcs-register]."
58 :type '(choice (const :tag "None" nil)
59 (string :tag "Argument String")
60 (repeat :tag "Argument List"
61 :value ("")
62 string))
63 :version "21.1"
64 :group 'vc)
66 (defcustom vc-rcs-diff-switches nil
67 "*A string or list of strings specifying extra switches for rcsdiff under VC."
68 :type '(choice (const :tag "None" nil)
69 (string :tag "Argument String")
70 (repeat :tag "Argument List"
71 :value ("")
72 string))
73 :version "21.1"
74 :group 'vc)
76 (defcustom vc-rcs-header (or (cdr (assoc 'RCS vc-header-alist)) '("\$Id\$"))
77 "*Header keywords to be inserted by `vc-insert-headers'."
78 :type '(repeat string)
79 :version "21.1"
80 :group 'vc)
82 (defcustom vc-rcsdiff-knows-brief nil
83 "*Indicates whether rcsdiff understands the --brief option.
84 The value is either `yes', `no', or nil. If it is nil, VC tries
85 to use --brief and sets this variable to remember whether it worked."
86 :type '(choice (const :tag "Work out" nil) (const yes) (const no))
87 :group 'vc)
89 ;;;###autoload
90 (defcustom vc-rcs-master-templates
91 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s")
92 "*Where to look for RCS master files.
93 For a description of possible values, see `vc-check-master-templates'."
94 :type '(choice (const :tag "Use standard RCS file names"
95 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
96 (repeat :tag "User-specified"
97 (choice string
98 function)))
99 :version "21.1"
100 :group 'vc)
103 ;;; Properties of the backend
105 (defun vc-rcs-revision-granularity ()
106 'file)
109 ;;; State-querying functions
112 ;;; The autoload cookie below places vc-rcs-registered directly into
113 ;;; loaddefs.el, so that vc-rcs.el does not need to be loaded for
114 ;;; every file that is visited. The definition is repeated below
115 ;;; so that Help and etags can find it.
117 ;;;###autoload (defun vc-rcs-registered (f) (vc-default-registered 'RCS f))
118 (defun vc-rcs-registered (f) (vc-default-registered 'RCS f))
120 (defun vc-rcs-state (file)
121 "Implementation of `vc-state' for RCS."
122 (or (boundp 'vc-rcs-headers-result)
123 (and vc-consult-headers
124 (vc-rcs-consult-headers file)))
125 (let ((state
126 ;; vc-working-revision might not be known; in that case the
127 ;; property is nil. vc-rcs-fetch-master-state knows how to
128 ;; handle that.
129 (vc-rcs-fetch-master-state file
130 (vc-file-getprop file
131 'vc-working-revision))))
132 (if (not (eq state 'up-to-date))
133 state
134 (if (vc-workfile-unchanged-p file)
135 'up-to-date
136 (if (eq (vc-checkout-model file) 'locking)
137 'unlocked-changes
138 'edited)))))
140 (defun vc-rcs-state-heuristic (file)
141 "State heuristic for RCS."
142 (let (vc-rcs-headers-result)
143 (if (and vc-consult-headers
144 (setq vc-rcs-headers-result
145 (vc-rcs-consult-headers file))
146 (eq vc-rcs-headers-result 'rev-and-lock))
147 (let ((state (vc-file-getprop file 'vc-state)))
148 ;; If the headers say that the file is not locked, the
149 ;; permissions can tell us whether locking is used for
150 ;; the file or not.
151 (if (and (eq state 'up-to-date)
152 (not (vc-mistrust-permissions file)))
153 (cond
154 ((string-match ".rw..-..-." (nth 8 (file-attributes file)))
155 (vc-file-setprop file 'vc-checkout-model 'implicit)
156 (setq state
157 (if (vc-rcs-workfile-is-newer file)
158 'edited
159 'up-to-date)))
160 ((string-match ".r-..-..-." (nth 8 (file-attributes file)))
161 (vc-file-setprop file 'vc-checkout-model 'locking))))
162 state)
163 (if (not (vc-mistrust-permissions file))
164 (let* ((attributes (file-attributes file 'string))
165 (owner-name (nth 2 attributes))
166 (permissions (nth 8 attributes)))
167 (cond ((string-match ".r-..-..-." permissions)
168 (vc-file-setprop file 'vc-checkout-model 'locking)
169 'up-to-date)
170 ((string-match ".rw..-..-." permissions)
171 (if (eq (vc-checkout-model file) 'locking)
172 (if (file-ownership-preserved-p file)
173 'edited
174 owner-name)
175 (if (vc-rcs-workfile-is-newer file)
176 'edited
177 'up-to-date)))
179 ;; Strange permissions. Fall through to
180 ;; expensive state computation.
181 (vc-rcs-state file))))
182 (vc-rcs-state file)))))
184 (defun vc-rcs-working-revision (file)
185 "RCS-specific version of `vc-working-revision'."
186 (or (and vc-consult-headers
187 (vc-rcs-consult-headers file)
188 (vc-file-getprop file 'vc-working-revision))
189 (progn
190 (vc-rcs-fetch-master-state file)
191 (vc-file-getprop file 'vc-working-revision))))
193 (defun vc-rcs-latest-on-branch-p (file &optional version)
194 "Return non-nil if workfile version of FILE is the latest on its branch.
195 When VERSION is given, perform check for that version."
196 (unless version (setq version (vc-working-revision file)))
197 (with-temp-buffer
198 (string= version
199 (if (vc-trunk-p version)
200 (progn
201 ;; Compare VERSION to the head version number.
202 (vc-insert-file (vc-name file) "^[0-9]")
203 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
204 ;; If we are not on the trunk, we need to examine the
205 ;; whole current branch.
206 (vc-insert-file (vc-name file) "^desc")
207 (vc-rcs-find-most-recent-rev (vc-branch-part version))))))
209 (defun vc-rcs-checkout-model (file)
210 "RCS-specific version of `vc-checkout-model'."
211 (let (result)
212 (when vc-consult-headers
213 (vc-file-setprop file 'vc-checkout-model nil)
214 (vc-rcs-consult-headers file)
215 (setq result (vc-file-getprop file 'vc-checkout-model)))
216 (or result
217 (progn (vc-rcs-fetch-master-state file)
218 (vc-file-getprop file 'vc-checkout-model)))))
220 (defun vc-rcs-workfile-unchanged-p (file)
221 "RCS-specific implementation of `vc-workfile-unchanged-p'."
222 ;; Try to use rcsdiff --brief. If rcsdiff does not understand that,
223 ;; do a double take and remember the fact for the future
224 (let* ((version (concat "-r" (vc-working-revision file)))
225 (status (if (eq vc-rcsdiff-knows-brief 'no)
226 (vc-do-command nil 1 "rcsdiff" file version)
227 (vc-do-command nil 2 "rcsdiff" file "--brief" version))))
228 (if (eq status 2)
229 (if (not vc-rcsdiff-knows-brief)
230 (setq vc-rcsdiff-knows-brief 'no
231 status (vc-do-command nil 1 "rcsdiff" file version))
232 (error "rcsdiff failed"))
233 (if (not vc-rcsdiff-knows-brief) (setq vc-rcsdiff-knows-brief 'yes)))
234 ;; The workfile is unchanged if rcsdiff found no differences.
235 (zerop status)))
237 (defun vc-rcs-find-file-not-found-hook ()
238 (if (yes-or-no-p
239 (format "File %s was lost; check out from version control? "
240 (file-name-nondirectory buffer-file-name)))
241 (save-excursion
242 (require 'vc)
243 (let ((default-directory (file-name-directory buffer-file-name)))
244 (not (vc-error-occurred (vc-checkout buffer-file-name)))))))
247 ;;; State-changing functions
250 (defun vc-rcs-create-repo ()
251 "Create a new RCS repository."
252 ;; RCS is totally file-oriented, so all we have to do is make the directory
253 (make-directory "RCS"))
255 (defun vc-rcs-register (files &optional rev comment)
256 "Register FILES into the RCS version-control system.
257 REV is the optional revision number for the files. COMMENT can be used
258 to provide an initial description for each FILES.
260 `vc-register-switches' and `vc-rcs-register-switches' are passed to
261 the RCS command (in that order).
263 Automatically retrieve a read-only version of the file with keywords
264 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
265 (let ((subdir (expand-file-name "RCS" (file-name-directory file))))
266 (dolist (file files)
267 (and (not (file-exists-p subdir))
268 (not (directory-files (file-name-directory file)
269 nil ".*,v$" t))
270 (yes-or-no-p "Create RCS subdirectory? ")
271 (make-directory subdir))
272 (apply 'vc-do-command nil 0 "ci" file
273 ;; if available, use the secure registering option
274 (and (vc-rcs-release-p "5.6.4") "-i")
275 (concat (if vc-keep-workfiles "-u" "-r") rev)
276 (and comment (concat "-t-" comment))
277 (vc-switches 'RCS 'register))
278 ;; parse output to find master file name and workfile version
279 (with-current-buffer "*vc*"
280 (goto-char (point-min))
281 (let ((name (if (looking-at (concat "^\\(.*\\) <-- "
282 (file-name-nondirectory file)))
283 (match-string 1))))
284 (if (not name)
285 ;; if we couldn't find the master name,
286 ;; run vc-rcs-registered to get it
287 ;; (will be stored into the vc-name property)
288 (vc-rcs-registered file)
289 (vc-file-setprop file 'vc-name
290 (if (file-name-absolute-p name)
291 name
292 (expand-file-name
293 name
294 (file-name-directory file))))))
295 (vc-file-setprop file 'vc-working-revision
296 (if (re-search-forward
297 "^initial revision: \\([0-9.]+\\).*\n"
298 nil t)
299 (match-string 1)))))))
301 (defun vc-rcs-responsible-p (file)
302 "Return non-nil if RCS thinks it would be responsible for registering FILE."
303 ;; TODO: check for all the patterns in vc-rcs-master-templates
304 (file-directory-p (expand-file-name "RCS" (file-name-directory file))))
306 (defun vc-rcs-receive-file (file rev)
307 "Implementation of receive-file for RCS."
308 (let ((checkout-model (vc-checkout-model file)))
309 (vc-rcs-register file rev "")
310 (when (eq checkout-model 'implicit)
311 (vc-rcs-set-non-strict-locking file))
312 (vc-rcs-set-default-branch file (concat rev ".1"))))
314 (defun vc-rcs-unregister (file)
315 "Unregister FILE from RCS.
316 If this leaves the RCS subdirectory empty, ask the user
317 whether to remove it."
318 (let* ((master (vc-name file))
319 (dir (file-name-directory master))
320 (backup-info (find-backup-file-name master)))
321 (if (not backup-info)
322 (delete-file master)
323 (rename-file master (car backup-info) 'ok-if-already-exists)
324 (dolist (f (cdr backup-info)) (ignore-errors (delete-file f))))
325 (and (string= (file-name-nondirectory (directory-file-name dir)) "RCS")
326 ;; check whether RCS dir is empty, i.e. it does not
327 ;; contain any files except "." and ".."
328 (not (directory-files dir nil
329 "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*"))
330 (yes-or-no-p (format "Directory %s is empty; remove it? " dir))
331 (delete-directory dir))))
333 (defun vc-rcs-checkin (files rev comment)
334 "RCS-specific version of `vc-backend-checkin'."
335 (let ((switches (vc-switches 'RCS 'checkin)))
336 ;; Now operate on the files
337 (dolist (file files)
338 (let ((old-version (vc-working-revision file)) new-version
339 (default-branch (vc-file-getprop file 'vc-rcs-default-branch)))
340 ;; Force branch creation if an appropriate
341 ;; default branch has been set.
342 (and (not rev)
343 default-branch
344 (string-match (concat "^" (regexp-quote old-version) "\\.")
345 default-branch)
346 (setq rev default-branch)
347 (setq switches (cons "-f" switches)))
348 (if (and (not rev) old-version)
349 (setq rev (vc-branch-part old-version)))
350 (apply 'vc-do-command nil 0 "ci" (vc-name file)
351 ;; if available, use the secure check-in option
352 (and (vc-rcs-release-p "5.6.4") "-j")
353 (concat (if vc-keep-workfiles "-u" "-r") rev)
354 (concat "-m" comment)
355 switches)
356 (vc-file-setprop file 'vc-working-revision nil)
358 ;; determine the new workfile version
359 (set-buffer "*vc*")
360 (goto-char (point-min))
361 (when (or (re-search-forward
362 "new revision: \\([0-9.]+\\);" nil t)
363 (re-search-forward
364 "reverting to previous revision \\([0-9.]+\\)" nil t))
365 (setq new-version (match-string 1))
366 (vc-file-setprop file 'vc-working-revision new-version))
368 ;; if we got to a different branch, adjust the default
369 ;; branch accordingly
370 (cond
371 ((and old-version new-version
372 (not (string= (vc-branch-part old-version)
373 (vc-branch-part new-version))))
374 (vc-rcs-set-default-branch file
375 (if (vc-trunk-p new-version) nil
376 (vc-branch-part new-version)))
377 ;; If this is an old RCS release, we might have
378 ;; to remove a remaining lock.
379 (if (not (vc-rcs-release-p "5.6.2"))
380 ;; exit status of 1 is also accepted.
381 ;; It means that the lock was removed before.
382 (vc-do-command nil 1 "rcs" (vc-name file)
383 (concat "-u" old-version)))))))))
385 (defun vc-rcs-find-revision (file rev buffer)
386 (apply 'vc-do-command
387 buffer 0 "co" (vc-name file)
388 "-q" ;; suppress diagnostic output
389 (concat "-p" rev)
390 (vc-switches 'RCS 'checkout)))
392 (defun vc-rcs-checkout (file &optional editable rev)
393 "Retrieve a copy of a saved version of FILE."
394 (let ((file-buffer (get-file-buffer file))
395 switches)
396 (message "Checking out %s..." file)
397 (save-excursion
398 ;; Change buffers to get local value of vc-checkout-switches.
399 (if file-buffer (set-buffer file-buffer))
400 (setq switches (vc-switches 'RCS 'checkout))
401 ;; Save this buffer's default-directory
402 ;; and use save-excursion to make sure it is restored
403 ;; in the same buffer it was saved in.
404 (let ((default-directory default-directory))
405 (save-excursion
406 ;; Adjust the default-directory so that the check-out creates
407 ;; the file in the right place.
408 (setq default-directory (file-name-directory file))
409 (let (new-version)
410 ;; if we should go to the head of the trunk,
411 ;; clear the default branch first
412 (and rev (string= rev "")
413 (vc-rcs-set-default-branch file nil))
414 ;; now do the checkout
415 (apply 'vc-do-command
416 nil 0 "co" (vc-name file)
417 ;; If locking is not strict, force to overwrite
418 ;; the writable workfile.
419 (if (eq (vc-checkout-model file) 'implicit) "-f")
420 (if editable "-l")
421 (if (stringp rev)
422 ;; a literal revision was specified
423 (concat "-r" rev)
424 (let ((workrev (vc-working-revision file)))
425 (if workrev
426 (concat "-r"
427 (if (not rev)
428 ;; no revision specified:
429 ;; use current workfile version
430 workrev
431 ;; REV is t ...
432 (if (not (vc-trunk-p workrev))
433 ;; ... go to head of current branch
434 (vc-branch-part workrev)
435 ;; ... go to head of trunk
436 (vc-rcs-set-default-branch file
437 nil)
438 ""))))))
439 switches)
440 ;; determine the new workfile version
441 (with-current-buffer "*vc*"
442 (setq new-version
443 (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1)))
444 (vc-file-setprop file 'vc-working-revision new-version)
445 ;; if necessary, adjust the default branch
446 (and rev (not (string= rev ""))
447 (vc-rcs-set-default-branch
448 file
449 (if (vc-rcs-latest-on-branch-p file new-version)
450 (if (vc-trunk-p new-version) nil
451 (vc-branch-part new-version))
452 new-version)))))
453 (message "Checking out %s...done" file)))))
455 (defun vc-rcs-rollback (files)
456 "Roll back, undoing the most recent checkins of FILES."
457 (if (not files)
458 (error "RCS backend doesn't support directory-level rollback."))
459 (dolist (file files)
460 (let* ((discard (vc-working-revision file))
461 (previous (if (vc-trunk-p discard) "" (vc-branch-part discard)))
462 (config (current-window-configuration))
463 (done nil))
464 (if (null (yes-or-no-p (format "Remove version %s from %s history? "
465 discard file)))
466 (error "Aborted"))
467 (message "Removing revision %s from %s." discard file)
468 (vc-do-command nil 0 "rcs" (vc-name file) (concat "-o" discard))
469 ;; Check out the most recent remaining version. If it
470 ;; fails, because the whole branch got deleted, do a
471 ;; double-take and check out the version where the branch
472 ;; started.
473 (while (not done)
474 (condition-case err
475 (progn
476 (vc-do-command nil 0 "co" (vc-name file) "-f"
477 (concat "-u" previous))
478 (setq done t))
479 (error (set-buffer "*vc*")
480 (goto-char (point-min))
481 (if (search-forward "no side branches present for" nil t)
482 (progn (setq previous (vc-branch-part previous))
483 (vc-rcs-set-default-branch file previous)
484 ;; vc-do-command popped up a window with
485 ;; the error message. Get rid of it, by
486 ;; restoring the old window configuration.
487 (set-window-configuration config))
488 ;; No, it was some other error: re-signal it.
489 (signal (car err) (cdr err)))))))))
491 (defun vc-rcs-revert (file &optional contents-done)
492 "Revert FILE to the version it was based on."
493 (vc-do-command nil 0 "co" (vc-name file) "-f"
494 (concat (if (eq (vc-state file) 'edited) "-u" "-r")
495 (vc-working-revision file))))
497 (defun vc-rcs-merge (file first-version &optional second-version)
498 "Merge changes into current working copy of FILE.
499 The changes are between FIRST-VERSION and SECOND-VERSION."
500 (vc-do-command nil 1 "rcsmerge" (vc-name file)
501 "-kk" ; ignore keyword conflicts
502 (concat "-r" first-version)
503 (if second-version (concat "-r" second-version))))
505 (defun vc-rcs-steal-lock (file &optional rev)
506 "Steal the lock on the current workfile for FILE and revision REV.
507 Needs RCS 5.6.2 or later for -M."
508 (vc-do-command nil 0 "rcs" (vc-name file) "-M" (concat "-u" rev))
509 ;; Do a real checkout after stealing the lock, so that we see
510 ;; expanded headers.
511 (vc-do-command nil 0 "co" (vc-name file) "-f" (concat "-l" rev)))
513 (defun vc-rcs-modify-change-comment (files rev comment)
514 "Modify the change comments change on FILES on a specified REV."
515 (dolist (file files)
516 (vc-do-command nil 0 "rcs" (vc-name file)
517 (concat "-m" comment ":" rev))))
521 ;;; History functions
524 (defun vc-rcs-print-log (files &optional buffer)
525 "Get change log associated with FILE."
526 (vc-do-command buffer 0 "rlog" (mapcar 'vc-name files)))
528 (defun vc-rcs-diff (files &optional oldvers newvers buffer)
529 "Get a difference report using RCS between two sets of files."
530 (apply 'vc-do-command (or buffer "*vc-diff*")
531 1 ;; Always go synchronous, the repo is local
532 "rcsdiff" (vc-expand-dirs files)
533 (append (list "-q"
534 (and oldvers (concat "-r" oldvers))
535 (and newvers (concat "-r" newvers)))
536 (vc-switches 'RCS 'diff))))
538 (defun vc-rcs-wash-log ()
539 "Remove all non-comment information from log output."
540 (let ((separator (concat "^-+\nrevision [0-9.]+\ndate: .*\n"
541 "\\(branches: .*;\n\\)?"
542 "\\(\\*\\*\\* empty log message \\*\\*\\*\n\\)?")))
543 (goto-char (point-max)) (forward-line -1)
544 (while (looking-at "=*\n")
545 (delete-char (- (match-end 0) (match-beginning 0)))
546 (forward-line -1))
547 (goto-char (point-min))
548 (if (looking-at "[\b\t\n\v\f\r ]+")
549 (delete-char (- (match-end 0) (match-beginning 0))))
550 (goto-char (point-min))
551 (re-search-forward separator nil t)
552 (delete-region (point-min) (point))
553 (while (re-search-forward separator nil t)
554 (delete-region (match-beginning 0) (match-end 0)))))
556 (defun vc-rcs-annotate-command (file buffer &optional revision)
557 "Annotate FILE, inserting the results in BUFFER.
558 Optional arg REVISION is a revision to annotate from."
559 (vc-setup-buffer buffer)
560 ;; Aside from the "head revision on the trunk", the instructions for
561 ;; each revision on the trunk are an ordered list of kill and insert
562 ;; commands necessary to go from the chronologically-following
563 ;; revision to this one. That is, associated with revision N are
564 ;; edits that applied to revision N+1 would result in revision N.
566 ;; On a branch, however, (some) things are inverted: the commands
567 ;; listed are those necessary to go from the chronologically-preceding
568 ;; revision to this one. That is, associated with revision N are
569 ;; edits that applied to revision N-1 would result in revision N.
571 ;; So, to get per-line history info, we apply reverse-chronological
572 ;; edits, starting with the head revision on the trunk, all the way
573 ;; back through the initial revision (typically "1.1" or similar),
574 ;; then apply forward-chronological edits -- keeping track of which
575 ;; revision is associated with each inserted line -- until we reach
576 ;; the desired revision for display (which may be either on the trunk
577 ;; or on a branch).
578 (let* ((tree (with-temp-buffer
579 (insert-file-contents (vc-rcs-registered file))
580 (vc-rcs-parse)))
581 (revisions (cdr (assq 'revisions tree)))
582 ;; The revision N whose instructions we currently are processing.
583 (cur (cdr (assq 'head (cdr (assq 'headers tree)))))
584 ;; Alist from the parse tree for N.
585 (meta (cdr (assoc cur revisions)))
586 ;; Point and temporary string, respectively.
588 ;; "Next-branch list". Nil means the desired revision to
589 ;; display lives on the trunk. Non-nil means it lives on a
590 ;; branch, in which case the value is a list of revision pairs
591 ;; (PARENT . CHILD), the first PARENT being on the trunk, that
592 ;; links each series of revisions in the path from the initial
593 ;; revision to the desired revision to display.
594 nbls
595 ;; "Path-accumulate-predicate plus revision/date/author".
596 ;; Until set, forward-chronological edits are not accumulated.
597 ;; Once set, its value (updated every revision) is used for
598 ;; the text property `:vc-rcs-r/d/a' for inserts during
599 ;; processing of forward-chronological instructions for N.
600 ;; See internal func `r/d/a'.
601 prda
602 ;; List of forward-chronological instructions, each of the
603 ;; form: (POS . ACTION), where POS is a buffer position. If
604 ;; ACTION is a string, it is inserted, otherwise it is taken as
605 ;; the number of characters to be deleted.
606 path
607 ;; N+1. When `cur' is "", this is the initial revision.
608 pre)
609 (unless revision
610 (setq revision cur))
611 (unless (assoc revision revisions)
612 (error "No such revision: %s" revision))
613 ;; Find which branches (if any) must be included in the edits.
614 (let ((par revision)
615 bpt kids)
616 (while (setq bpt (vc-branch-part par)
617 par (vc-branch-part bpt))
618 (setq kids (cdr (assq 'branches (cdr (assoc par revisions)))))
619 ;; A branchpoint may have multiple children. Find the right one.
620 (while (not (string= bpt (vc-branch-part (car kids))))
621 (setq kids (cdr kids)))
622 (push (cons par (car kids)) nbls)))
623 ;; Start with the full text.
624 (set-buffer buffer)
625 (insert (cdr (assq 'text meta)))
626 ;; Apply reverse-chronological edits on the trunk, computing and
627 ;; accumulating forward-chronological edits after some point, for
628 ;; later.
629 (flet ((r/d/a () (vector pre
630 (cdr (assq 'date meta))
631 (cdr (assq 'author meta)))))
632 (while (when (setq pre cur cur (cdr (assq 'next meta)))
633 (not (string= "" cur)))
634 (setq
635 ;; Start accumulating the forward-chronological edits when N+1
636 ;; on the trunk is either the desired revision to display, or
637 ;; the appropriate branchpoint for it. Do this before
638 ;; updating `meta' since `r/d/a' uses N+1's `meta' value.
639 prda (when (or prda (string= (if nbls (caar nbls) revision) pre))
640 (r/d/a))
641 meta (cdr (assoc cur revisions)))
642 ;; Edits in the parse tree specify a line number (in the buffer
643 ;; *BEFORE* editing occurs) to start from, but line numbers
644 ;; change as a result of edits. To DTRT, we apply edits in
645 ;; order of descending buffer position so that edits further
646 ;; down in the buffer occur first w/o corrupting specified
647 ;; buffer positions of edits occurring towards the beginning of
648 ;; the buffer. In this way we avoid using markers. A pleasant
649 ;; property of this approach is ability to push instructions
650 ;; onto `path' directly, w/o need to maintain rev boundaries.
651 (dolist (insn (cdr (assq :insn meta)))
652 (goto-line (pop insn))
653 (setq p (point))
654 (case (pop insn)
655 (k (setq s (buffer-substring-no-properties
656 p (progn (forward-line (car insn))
657 (point))))
658 (when prda
659 (push `(,p . ,(propertize s :vc-rcs-r/d/a prda)) path))
660 (delete-region p (point)))
661 (i (setq s (car insn))
662 (when prda
663 (push `(,p . ,(length s)) path))
664 (insert s)))))
665 ;; For the initial revision, setting `:vc-rcs-r/d/a' directly is
666 ;; equivalent to pushing an insert instruction (of the entire buffer
667 ;; contents) onto `path' then erasing the buffer, but less wasteful.
668 (put-text-property (point-min) (point-max) :vc-rcs-r/d/a (r/d/a))
669 ;; Now apply the forward-chronological edits for the trunk.
670 (dolist (insn path)
671 (goto-char (pop insn))
672 (if (stringp insn)
673 (insert insn)
674 (delete-char insn)))
675 ;; Now apply the forward-chronological edits (directly from the
676 ;; parse-tree) for the branch(es), if necessary. We re-use vars
677 ;; `pre' and `meta' for the sake of internal func `r/d/a'.
678 (while nbls
679 (setq pre (cdr (pop nbls)))
680 (while (progn
681 (setq meta (cdr (assoc pre revisions))
682 prda nil)
683 (dolist (insn (cdr (assq :insn meta)))
684 (goto-line (pop insn))
685 (case (pop insn)
686 (k (delete-region
687 (point) (progn (forward-line (car insn))
688 (point))))
689 (i (insert (propertize
690 (car insn)
691 :vc-rcs-r/d/a
692 (or prda (setq prda (r/d/a))))))))
693 (prog1 (not (string= (if nbls (caar nbls) revision) pre))
694 (setq pre (cdr (assq 'next meta)))))))))
695 ;; Lastly, for each line, insert at bol nicely-formatted history info.
696 ;; We do two passes to collect summary information used to minimize
697 ;; the annotation's usage of screen real-estate: (1) Consider rendered
698 ;; width of revision plus author together as a unit; and (2) Omit
699 ;; author entirely if all authors are the same as the user.
700 (let ((ht (make-hash-table :test 'eq))
701 (me (user-login-name))
702 (maxw 0)
703 (all-me t)
704 rda w a)
705 (goto-char (point-max))
706 (while (not (bobp))
707 (forward-line -1)
708 (setq rda (get-text-property (point) :vc-rcs-r/d/a))
709 (unless (gethash rda ht)
710 (setq a (aref rda 2)
711 all-me (and all-me (string= a me)))
712 (puthash rda (setq w (+ (length (aref rda 0))
713 (length a)))
715 (setq maxw (max w maxw))))
716 (let ((padding (make-string maxw 32)))
717 (flet ((pad (w) (substring-no-properties padding w))
718 (render (rda &rest ls)
719 (propertize
720 (apply 'concat
721 (format-time-string "%Y-%m-%d" (aref rda 1))
723 (aref rda 0)
725 :vc-annotate-prefix t
726 :vc-rcs-r/d/a rda)))
727 (maphash
728 (if all-me
729 (lambda (rda w)
730 (puthash rda (render rda (pad w) ": ") ht))
731 (lambda (rda w)
732 (puthash rda (render rda " " (pad w) " " (aref rda 2) ": ") ht)))
733 ht)))
734 (while (not (eobp))
735 (insert (gethash (get-text-property (point) :vc-rcs-r/d/a) ht))
736 (forward-line 1))))
738 (defun vc-rcs-annotate-current-time ()
739 "Return the current time, based at midnight of the current day, and
740 encoded as fractional days."
741 (vc-annotate-convert-time
742 (apply 'encode-time 0 0 0 (nthcdr 3 (decode-time (current-time))))))
744 (defun vc-rcs-annotate-time ()
745 "Return the time of the next annotation (as fraction of days)
746 systime, or nil if there is none. Also, reposition point."
747 (unless (eobp)
748 (prog1 (vc-annotate-convert-time
749 (aref (get-text-property (point) :vc-rcs-r/d/a) 1))
750 (goto-char (next-single-property-change (point) :vc-annotate-prefix)))))
752 (defun vc-rcs-annotate-extract-revision-at-line ()
753 (aref (get-text-property (point) :vc-rcs-r/d/a) 0))
757 ;;; Snapshot system
760 (defun vc-rcs-assign-name (file name)
761 "Assign to FILE's latest version a given NAME."
762 (vc-do-command nil 0 "rcs" (vc-name file) (concat "-n" name ":")))
766 ;;; Miscellaneous
769 (defun vc-rcs-check-headers ()
770 "Check if the current file has any headers in it."
771 (save-excursion
772 (goto-char (point-min))
773 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
774 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
776 (defun vc-rcs-clear-headers ()
777 "Implementation of vc-clear-headers for RCS."
778 (let ((case-fold-search nil))
779 (goto-char (point-min))
780 (while (re-search-forward
781 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
782 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
783 nil t)
784 (replace-match "$\\1$"))))
786 (defun vc-rcs-rename-file (old new)
787 ;; Just move the master file (using vc-rcs-master-templates).
788 (vc-rename-master (vc-name old) new vc-rcs-master-templates))
792 ;;; Internal functions
795 (defun vc-rcs-root (dir)
796 (vc-find-root dir "RCS" t))
798 (defun vc-rcs-workfile-is-newer (file)
799 "Return non-nil if FILE is newer than its RCS master.
800 This likely means that FILE has been changed with respect
801 to its master version."
802 (let ((file-time (nth 5 (file-attributes file)))
803 (master-time (nth 5 (file-attributes (vc-name file)))))
804 (or (> (nth 0 file-time) (nth 0 master-time))
805 (and (= (nth 0 file-time) (nth 0 master-time))
806 (> (nth 1 file-time) (nth 1 master-time))))))
808 (defun vc-rcs-find-most-recent-rev (branch)
809 "Find most recent revision on BRANCH."
810 (goto-char (point-min))
811 (let ((latest-rev -1) value)
812 (while (re-search-forward (concat "^\\(" (regexp-quote branch)
813 "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;")
814 nil t)
815 (let ((rev (string-to-number (match-string 2))))
816 (when (< latest-rev rev)
817 (setq latest-rev rev)
818 (setq value (match-string 1)))))
819 (or value
820 (vc-branch-part branch))))
822 (defun vc-rcs-fetch-master-state (file &optional working-revision)
823 "Compute the master file's idea of the state of FILE.
824 If a WORKFILE-VERSION is given, compute the state of that version,
825 otherwise determine the workfile version based on the master file.
826 This function sets the properties `vc-working-revision' and
827 `vc-checkout-model' to their correct values, based on the master
828 file."
829 (with-temp-buffer
830 (if (or (not (vc-insert-file (vc-name file) "^[0-9]"))
831 (progn (goto-char (point-min))
832 (not (looking-at "^head[ \t\n]+[^;]+;$"))))
833 (error "File %s is not an RCS master file" (vc-name file)))
834 (let ((workfile-is-latest nil)
835 (default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1)))
836 (vc-file-setprop file 'vc-rcs-default-branch default-branch)
837 (unless working-revision
838 ;; Workfile version not known yet. Determine that first. It
839 ;; is either the head of the trunk, the head of the default
840 ;; branch, or the "default branch" itself, if that is a full
841 ;; revision number.
842 (cond
843 ;; no default branch
844 ((or (not default-branch) (string= "" default-branch))
845 (setq working-revision
846 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
847 (setq workfile-is-latest t))
848 ;; default branch is actually a revision
849 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
850 default-branch)
851 (setq working-revision default-branch))
852 ;; else, search for the head of the default branch
853 (t (vc-insert-file (vc-name file) "^desc")
854 (setq working-revision
855 (vc-rcs-find-most-recent-rev default-branch))
856 (setq workfile-is-latest t)))
857 (vc-file-setprop file 'vc-working-revision working-revision))
858 ;; Check strict locking
859 (goto-char (point-min))
860 (vc-file-setprop file 'vc-checkout-model
861 (if (re-search-forward ";[ \t\n]*strict;" nil t)
862 'locking 'implicit))
863 ;; Compute state of workfile version
864 (goto-char (point-min))
865 (let ((locking-user
866 (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):"
867 (regexp-quote working-revision)
868 "[^0-9.]")
869 1)))
870 (cond
871 ;; not locked
872 ((not locking-user)
873 (if (or workfile-is-latest
874 (vc-rcs-latest-on-branch-p file working-revision))
875 ;; workfile version is latest on branch
876 'up-to-date
877 ;; workfile version is not latest on branch
878 'needs-patch))
879 ;; locked by the calling user
880 ((and (stringp locking-user)
881 (string= locking-user (vc-user-login-name file)))
882 (if (or (eq (vc-checkout-model file) 'locking)
883 workfile-is-latest
884 (vc-rcs-latest-on-branch-p file working-revision))
885 'edited
886 ;; Locking is not used for the file, but the owner does
887 ;; have a lock, and there is a higher version on the current
888 ;; branch. Not sure if this can occur, and if it is right
889 ;; to use `needs-merge' in this case.
890 'needs-merge))
891 ;; locked by somebody else
892 ((stringp locking-user)
893 locking-user)
895 (error "Error getting state of RCS file")))))))
897 (defun vc-rcs-consult-headers (file)
898 "Search for RCS headers in FILE, and set properties accordingly.
900 Returns: nil if no headers were found
901 'rev if a workfile revision was found
902 'rev-and-lock if revision and lock info was found"
903 (cond
904 ((not (get-file-buffer file)) nil)
905 ((let (status version locking-user)
906 (save-excursion
907 (set-buffer (get-file-buffer file))
908 (goto-char (point-min))
909 (cond
910 ;; search for $Id or $Header
911 ;; -------------------------
912 ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file.
913 ((or (and (search-forward "$Id\ : " nil t)
914 (looking-at "[^ ]+ \\([0-9.]+\\) "))
915 (and (progn (goto-char (point-min))
916 (search-forward "$Header\ : " nil t))
917 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
918 (goto-char (match-end 0))
919 ;; if found, store the revision number ...
920 (setq version (match-string-no-properties 1))
921 ;; ... and check for the locking state
922 (cond
923 ((looking-at
924 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
925 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
926 "[^ ]+ [^ ]+ ")) ; author & state
927 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
928 (cond
929 ;; unlocked revision
930 ((looking-at "\\$")
931 (setq locking-user 'none)
932 (setq status 'rev-and-lock))
933 ;; revision is locked by some user
934 ((looking-at "\\([^ ]+\\) \\$")
935 (setq locking-user (match-string-no-properties 1))
936 (setq status 'rev-and-lock))
937 ;; everything else: false
938 (nil)))
939 ;; unexpected information in
940 ;; keyword string --> quit
941 (nil)))
942 ;; search for $Revision
943 ;; --------------------
944 ((re-search-forward (concat "\\$"
945 "Revision: \\([0-9.]+\\) \\$")
946 nil t)
947 ;; if found, store the revision number ...
948 (setq version (match-string-no-properties 1))
949 ;; and see if there's any lock information
950 (goto-char (point-min))
951 (if (re-search-forward (concat "\\$" "Locker:") nil t)
952 (cond ((looking-at " \\([^ ]+\\) \\$")
953 (setq locking-user (match-string-no-properties 1))
954 (setq status 'rev-and-lock))
955 ((looking-at " *\\$")
956 (setq locking-user 'none)
957 (setq status 'rev-and-lock))
959 (setq locking-user 'none)
960 (setq status 'rev-and-lock)))
961 (setq status 'rev)))
962 ;; else: nothing found
963 ;; -------------------
964 (t nil)))
965 (if status (vc-file-setprop file 'vc-working-revision version))
966 (and (eq status 'rev-and-lock)
967 (vc-file-setprop file 'vc-state
968 (cond
969 ((eq locking-user 'none) 'up-to-date)
970 ((string= locking-user (vc-user-login-name file))
971 'edited)
972 (t locking-user)))
973 ;; If the file has headers, we don't want to query the
974 ;; master file, because that would eliminate all the
975 ;; performance gain the headers brought us. We therefore
976 ;; use a heuristic now to find out whether locking is used
977 ;; for this file. If we trust the file permissions, and the
978 ;; file is not locked, then if the file is read-only we
979 ;; assume that locking is used for the file, otherwise
980 ;; locking is not used.
981 (not (vc-mistrust-permissions file))
982 (vc-up-to-date-p file)
983 (if (string-match ".r-..-..-." (nth 8 (file-attributes file)))
984 (vc-file-setprop file 'vc-checkout-model 'locking)
985 (vc-file-setprop file 'vc-checkout-model 'implicit)))
986 status))))
988 (defun vc-release-greater-or-equal (r1 r2)
989 "Compare release numbers, represented as strings.
990 Release components are assumed cardinal numbers, not decimal fractions
991 \(5.10 is a higher release than 5.9\). Omitted fields are considered
992 lower \(5.6.7 is earlier than 5.6.7.1\). Comparison runs till the end
993 of the string is found, or a non-numeric component shows up \(5.6.7 is
994 earlier than \"5.6.7 beta\", which is probably not what you want in
995 some cases\). This code is suitable for existing RCS release numbers.
996 CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5\)."
997 (let (v1 v2 i1 i2)
998 (catch 'done
999 (or (and (string-match "^\\.?\\([0-9]+\\)" r1)
1000 (setq i1 (match-end 0))
1001 (setq v1 (string-to-number (match-string 1 r1)))
1002 (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
1003 (setq i2 (match-end 0))
1004 (setq v2 (string-to-number (match-string 1 r2)))
1005 (if (> v1 v2) (throw 'done t)
1006 (if (< v1 v2) (throw 'done nil)
1007 (throw 'done
1008 (vc-release-greater-or-equal
1009 (substring r1 i1)
1010 (substring r2 i2)))))))
1011 (throw 'done t)))
1012 (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
1013 (throw 'done nil))
1014 (throw 'done t)))))
1016 (defun vc-rcs-release-p (release)
1017 "Return t if we have RELEASE or better."
1018 (let ((installation (vc-rcs-system-release)))
1019 (if (and installation
1020 (not (eq installation 'unknown)))
1021 (vc-release-greater-or-equal installation release))))
1023 (defun vc-rcs-system-release ()
1024 "Return the RCS release installed on this system, as a string.
1025 Return symbol UNKNOWN if the release cannot be deducted. The user can
1026 override this using variable `vc-rcs-release'.
1028 If the user has not set variable `vc-rcs-release' and it is nil,
1029 variable `vc-rcs-release' is set to the returned value."
1030 (or vc-rcs-release
1031 (setq vc-rcs-release
1032 (or (and (zerop (vc-do-command nil nil "rcs" nil "-V"))
1033 (with-current-buffer (get-buffer "*vc*")
1034 (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1)))
1035 'unknown))))
1037 (defun vc-rcs-set-non-strict-locking (file)
1038 (vc-do-command nil 0 "rcs" file "-U")
1039 (vc-file-setprop file 'vc-checkout-model 'implicit)
1040 (set-file-modes file (logior (file-modes file) 128)))
1042 (defun vc-rcs-set-default-branch (file branch)
1043 (vc-do-command nil 0 "rcs" (vc-name file) (concat "-b" branch))
1044 (vc-file-setprop file 'vc-rcs-default-branch branch))
1046 (defun vc-rcs-parse (&optional buffer)
1047 "Parse current buffer, presumed to be in RCS-style masterfile format.
1048 Optional arg BUFFER specifies another buffer to parse. Return an alist
1049 of two elements, w/ keys `headers' and `revisions' and values in turn
1050 sub-alists. For `headers', the values unless otherwise specified are
1051 strings and the keys are:
1053 desc -- description
1054 head -- latest revision
1055 branch -- the branch the \"head revision\" lies on;
1056 absent if the head revision lies on the trunk
1057 access -- ???
1058 symbols -- sub-alist of (SYMBOL . REVISION) elements
1059 locks -- if file is checked out, something like \"ttn:1.7\"
1060 strict -- t if \"strict locking\" is in effect, otherwise nil
1061 comment -- may be absent; typically something like \"# \" or \"; \"
1062 expand -- may be absent; ???
1064 For `revisions', the car is REVISION (string), the cdr a sub-alist,
1065 with string values (unless otherwise specified) and keys:
1067 date -- a time value (like that returned by `encode-time'); as a
1068 special case, a year value less than 100 is augmented by 1900
1069 author -- username
1070 state -- typically \"Exp\" or \"Rel\"
1071 branches -- list of revisions that begin branches from this revision
1072 next -- on the trunk: the chronologically-preceding revision, or \"\";
1073 on a branch: the chronologically-following revision, or \"\"
1074 log -- change log entry
1075 text -- for the head revision on the trunk, the body of the file;
1076 other revisions have `:insn' instead
1077 :insn -- for non-head revisions, a list of parsed instructions
1078 in one of two forms, in both cases START meaning \"first
1079 go to line START\":
1080 - `(START k COUNT)' -- kill COUNT lines
1081 - `(START i TEXT)' -- insert TEXT (a string)
1082 The list is in descending order by START.
1084 The `:insn' key is a keyword to distinguish it as a vc-rcs.el extension."
1085 (setq buffer (get-buffer (or buffer (current-buffer))))
1086 (set-buffer buffer)
1087 ;; An RCS masterfile can be viewed as containing four regular (for the
1088 ;; most part) sections: (a) the "headers", (b) the "rev headers", (c)
1089 ;; the "description" and (d) the "rev bodies", in that order. In the
1090 ;; returned alist (see docstring), elements from (b) and (d) are
1091 ;; combined pairwise to form the "revisions", while those from (a) and
1092 ;; (c) are simply combined to form the "headers".
1094 ;; Loosely speaking, each section contains a series of alternating
1095 ;; "tags" and "printed representations". In the (b) and (d), many
1096 ;; such series can appear, and a revision number on a line by itself
1097 ;; precedes the series of tags and printed representations associated
1098 ;; with it.
1100 ;; In (a) and (b), the printed representations (with the exception of
1101 ;; the `comment' tag in the headers) terminate with a semicolon, which
1102 ;; is NOT part of the "value" finally associated with the tag. All
1103 ;; other printed representations are in "@@-format"; there is an "@",
1104 ;; the middle part (to be translated into the value), another "@" and
1105 ;; a newline. Each "@@" in the middle part indicates the position of
1106 ;; a single "@" (and consequently the requirement of an additional
1107 ;; initial step when translating to the value).
1109 ;; Parser state includes vars that collect parts of the return value...
1110 (let ((desc nil) (headers nil) (revs nil)
1111 ;; ... as well as vars that support a single-pass, tag-assisted,
1112 ;; minimal-data-copying scan. Basically -- skirting around the
1113 ;; grouping by revision required in (b) and (d) -- we repeatedly
1114 ;; and context-sensitively read a tag (that MUST be present),
1115 ;; determine the bounds of the printed representation, translate
1116 ;; it into a value, and push the tag plus value onto one of the
1117 ;; collection vars. Finally, we return the parse tree
1118 ;; incorporating the values of the collection vars (see "rv").
1120 ;; A symbol or string to keep track of context (for error messages).
1121 context
1122 ;; A symbol, the current tag.
1124 ;; Region (begin and end buffer positions) of the printed
1125 ;; representation for the current tag.
1127 ;; A list of buffer positions where "@@" can be found within the
1128 ;; printed representation region. For each location, we push two
1129 ;; elements onto the list, 1+ and 2+ the location, respectively,
1130 ;; with the 2+ appearing at the head. In this way, the expression
1131 ;; `(,e ,@@-holes ,b)
1132 ;; describes regions that can be concatenated (in reverse order)
1133 ;; to "de-@@-format" the printed representation as the first step
1134 ;; to translating it into some value. See internal func `gather'.
1135 @-holes)
1136 (flet ((sw () (skip-chars-forward " \t\n")) ; i.e., `[:space:]'
1137 (at (tag) (save-excursion (eq tag (read buffer))))
1138 (to-eol () (buffer-substring-no-properties
1139 (point) (progn (forward-line 1)
1140 (1- (point)))))
1141 (to-semi () (setq b (point)
1142 e (progn (search-forward ";")
1143 (1- (point)))))
1144 (to-one@ () (setq @-holes nil
1145 b (progn (search-forward "@") (point))
1146 e (progn (while (and (search-forward "@")
1147 (= ?@ (char-after))
1148 (progn
1149 (push (point) @-holes)
1150 (forward-char 1)
1151 (push (point) @-holes))))
1152 (1- (point)))))
1153 (tok+val (set-b+e name &optional proc)
1154 (unless (eq name (setq tok (read buffer)))
1155 (error "Missing `%s' while parsing %s" name context))
1156 (sw)
1157 (funcall set-b+e)
1158 (cons tok (if proc
1159 (funcall proc)
1160 (buffer-substring-no-properties b e))))
1161 (k-semi (name &optional proc) (tok+val 'to-semi name proc))
1162 (gather () (let ((pairs `(,e ,@@-holes ,b))
1163 acc)
1164 (while pairs
1165 (push (buffer-substring-no-properties
1166 (cadr pairs) (car pairs))
1167 acc)
1168 (setq pairs (cddr pairs)))
1169 (apply 'concat acc)))
1170 (k-one@ (name &optional later) (tok+val 'to-one@ name
1171 (if later
1172 (lambda () t)
1173 'gather))))
1174 (save-excursion
1175 (goto-char (point-min))
1176 ;; headers
1177 (setq context 'headers)
1178 (flet ((hpush (name &optional proc)
1179 (push (k-semi name proc) headers)))
1180 (hpush 'head)
1181 (when (at 'branch)
1182 (hpush 'branch))
1183 (hpush 'access)
1184 (hpush 'symbols
1185 (lambda ()
1186 (mapcar (lambda (together)
1187 (let ((two (split-string together ":")))
1188 (setcar two (intern (car two)))
1189 (setcdr two (cadr two))
1190 two))
1191 (split-string
1192 (buffer-substring-no-properties b e)))))
1193 (hpush 'locks))
1194 (push `(strict . ,(when (at 'strict)
1195 (search-forward ";")
1197 headers)
1198 (when (at 'comment)
1199 (push (k-one@ 'comment) headers)
1200 (search-forward ";"))
1201 (when (at 'expand)
1202 (push (k-one@ 'expand) headers)
1203 (search-forward ";"))
1204 (setq headers (nreverse headers))
1205 ;; rev headers
1206 (sw) (setq context 'rev-headers)
1207 (while (looking-at "[0-9]")
1208 (push `(,(to-eol)
1209 ,(k-semi 'date
1210 (lambda ()
1211 (let ((ls (mapcar 'string-to-number
1212 (split-string
1213 (buffer-substring-no-properties
1214 b e)
1215 "\\."))))
1216 ;; Hack the year -- verified to be the
1217 ;; same algorithm used in RCS 5.7.
1218 (when (< (car ls) 100)
1219 (setcar ls (+ 1900 (car ls))))
1220 (apply 'encode-time (nreverse ls)))))
1221 ,@(mapcar 'k-semi '(author state))
1222 ,(k-semi 'branches
1223 (lambda ()
1224 (split-string
1225 (buffer-substring-no-properties b e))))
1226 ,(k-semi 'next))
1227 revs)
1228 (sw))
1229 (setq revs (nreverse revs))
1230 ;; desc
1231 (sw) (setq context 'desc
1232 desc (k-one@ 'desc))
1233 ;; rev bodies
1234 (let (acc
1235 ;; Element of `revs' that initially holds only header info.
1236 ;; "Pairwise combination" occurs when we add body info.
1238 ;; Components of the editing commands (aside from the actual
1239 ;; text) that comprise the `text' printed representations
1240 ;; (not including the "head" revision).
1241 cmd start act
1242 ;; Ascending (reversed) `@-holes' which the internal func
1243 ;; `incg' pops to effect incremental gathering.
1245 ;; Function to extract text (for the `a' command), either
1246 ;; `incg' or `buffer-substring-no-properties'. (This is
1247 ;; for speed; strictly speaking, it is sufficient to use
1248 ;; only the former since it behaves identically to the
1249 ;; latter in the absense of "@@".)
1250 sub)
1251 (flet ((incg (beg end) (let ((b beg) (e end) @-holes)
1252 (while (and asc (< (car asc) e))
1253 (push (pop asc) @-holes))
1254 ;; Self-deprecate when work is done.
1255 ;; Folding many dimensions into one.
1256 ;; Thanks B.Mandelbrot, for complex sum.
1257 ;; O beauteous math! --the Unvexed Bum
1258 (unless asc
1259 (setq sub 'buffer-substring-no-properties))
1260 (gather))))
1261 (while (and (sw)
1262 (not (eobp))
1263 (setq context (to-eol)
1264 rev (or (assoc context revs)
1265 (error "Rev `%s' has body but no head"
1266 context))))
1267 (push (k-one@ 'log) (cdr rev))
1268 ;; For rev body `text' tags, delay translation slightly...
1269 (push (k-one@ 'text t) (cdr rev))
1270 ;; ... until we decide which tag and value is appropriate to
1271 ;; collect. For the "head" revision, compute the value of the
1272 ;; `text' printed representation by simple `gather'. For all
1273 ;; other revisions, replace the `text' tag+value with `:insn'
1274 ;; plus value, always scanning in-place.
1275 (if (string= context (cdr (assq 'head headers)))
1276 (setcdr (cadr rev) (gather))
1277 (if @-holes
1278 (setq asc (nreverse @-holes)
1279 sub 'incg)
1280 (setq sub 'buffer-substring-no-properties))
1281 (goto-char b)
1282 (setq acc nil)
1283 (while (< (point) e)
1284 (forward-char 1)
1285 (setq cmd (char-before)
1286 start (read (current-buffer))
1287 act (read (current-buffer)))
1288 (forward-char 1)
1289 (push (case cmd
1291 ;; `d' means "delete lines".
1292 ;; For Emacs spirit, we use `k' for "kill".
1293 `(,start k ,act))
1295 ;; `a' means "append after this line" but
1296 ;; internally we normalize it so that START
1297 ;; specifies the actual line for insert, thus
1298 ;; requiring less hair in the realization algs.
1299 ;; For Emacs spirit, we use `i' for "insert".
1300 `(,(1+ start) i
1301 ,(funcall sub (point) (progn (forward-line act)
1302 (point)))))
1303 (t (error "Bad command `%c' in `text' for rev `%s'"
1304 cmd context)))
1305 acc))
1306 (goto-char (1+ e))
1307 (setcar (cdr rev) (cons :insn acc)))))))
1308 ;; rv
1309 `((headers ,desc ,@headers)
1310 (revisions ,@revs)))))
1312 (provide 'vc-rcs)
1314 ;; arch-tag: 759b4916-5b0d-431d-b647-b185b8c652cf
1315 ;;; vc-rcs.el ends here