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