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