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