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