1 ;;; vc-rcs.el --- support for RCS version-control
3 ;; Copyright (C) 1992,93,94,95,96,97,98,99,2000,2001 Free Software Foundation, Inc.
5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
8 ;; $Id: vc-rcs.el,v 1.23 2002/02/25 22:04:29 spiegel Exp $
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 2, or (at your option)
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; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
34 ;;; Customization options
41 (defcustom vc-rcs-release nil
42 "*The release number of your RCS installation, as a string.
43 If nil, VC itself computes this value when it is first needed."
44 :type
'(choice (const :tag
"Auto" nil
)
45 (string :tag
"Specified")
46 (const :tag
"Unknown" unknown
))
49 (defcustom vc-rcs-register-switches nil
50 "*Extra switches for registering a file in RCS.
51 A string or list of strings. These are passed to the checkin program
52 by \\[vc-rcs-register]."
53 :type
'(choice (const :tag
"None" nil
)
54 (string :tag
"Argument String")
55 (repeat :tag
"Argument List"
61 (defcustom vc-rcs-diff-switches nil
62 "*A string or list of strings specifying extra switches for rcsdiff under VC."
63 :type
'(choice (const :tag
"None" nil
)
64 (string :tag
"Argument String")
65 (repeat :tag
"Argument List"
71 (defcustom vc-rcs-header
(or (cdr (assoc 'RCS vc-header-alist
)) '("\$Id\$"))
72 "*Header keywords to be inserted by `vc-insert-headers'."
73 :type
'(repeat string
)
77 (defcustom vc-rcsdiff-knows-brief nil
78 "*Indicates whether rcsdiff understands the --brief option.
79 The value is either `yes', `no', or nil. If it is nil, VC tries
80 to use --brief and sets this variable to remember whether it worked."
81 :type
'(choice (const :tag
"Work out" nil
) (const yes
) (const no
))
85 (defcustom vc-rcs-master-templates
86 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s")
87 "*Where to look for RCS master files.
88 For a description of possible values, see `vc-check-master-templates'."
89 :type
'(choice (const :tag
"Use standard RCS file names"
90 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
91 (repeat :tag
"User-specified"
99 ;;; State-querying functions
103 (progn (defun vc-rcs-registered (f) (vc-default-registered 'RCS f
)))
105 (defun vc-rcs-state (file)
106 "Implementation of `vc-state' for RCS."
107 (or (boundp 'vc-rcs-headers-result
)
108 (and vc-consult-headers
109 (vc-rcs-consult-headers file
)))
111 ;; vc-workfile-version might not be known; in that case the
112 ;; property is nil. vc-rcs-fetch-master-state knows how to
114 (vc-rcs-fetch-master-state file
115 (vc-file-getprop file
116 'vc-workfile-version
))))
117 (if (not (eq state
'up-to-date
))
120 (if (vc-workfile-unchanged-p file
)
122 (if (eq (vc-checkout-model file
) 'locking
)
126 (defun vc-rcs-state-heuristic (file)
127 "State heuristic for RCS."
128 (let (vc-rcs-headers-result)
129 (if (and vc-consult-headers
130 (setq vc-rcs-headers-result
131 (vc-rcs-consult-headers file
))
132 (eq vc-rcs-headers-result
'rev-and-lock
))
133 (let ((state (vc-file-getprop file
'vc-state
)))
134 ;; If the headers say that the file is not locked, the
135 ;; permissions can tell us whether locking is used for
137 (if (and (eq state
'up-to-date
)
138 (not (vc-mistrust-permissions file
)))
140 ((string-match ".rw..-..-." (nth 8 (file-attributes file
)))
141 (vc-file-setprop file
'vc-checkout-model
'implicit
)
143 (if (vc-rcs-workfile-is-newer file
)
146 ((string-match ".r-..-..-." (nth 8 (file-attributes file
)))
147 (vc-file-setprop file
'vc-checkout-model
'locking
))))
149 (if (not (vc-mistrust-permissions file
))
150 (let* ((attributes (file-attributes file
))
151 (owner-uid (nth 2 attributes
))
152 (permissions (nth 8 attributes
)))
153 (cond ((string-match ".r-..-..-." permissions
)
154 (vc-file-setprop file
'vc-checkout-model
'locking
)
156 ((string-match ".rw..-..-." permissions
)
157 (if (eq (vc-checkout-model file
) 'locking
)
158 (if (file-ownership-preserved-p file
)
160 (vc-user-login-name owner-uid
))
161 (if (vc-rcs-workfile-is-newer file
)
165 ;; Strange permissions. Fall through to
166 ;; expensive state computation.
167 (vc-rcs-state file
))))
168 (vc-rcs-state file
)))))
170 (defun vc-rcs-workfile-version (file)
171 "RCS-specific version of `vc-workfile-version'."
172 (or (and vc-consult-headers
173 (vc-rcs-consult-headers file
)
174 (vc-file-getprop file
'vc-workfile-version
))
176 (vc-rcs-fetch-master-state file
)
177 (vc-file-getprop file
'vc-workfile-version
))))
179 (defun vc-rcs-latest-on-branch-p (file &optional version
)
180 "Return non-nil if workfile version of FILE is the latest on its branch.
181 When VERSION is given, perform check for that version."
182 (unless version
(setq version
(vc-workfile-version file
)))
185 (if (vc-trunk-p version
)
187 ;; Compare VERSION to the head version number.
188 (vc-insert-file (vc-name file
) "^[0-9]")
189 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
190 ;; If we are not on the trunk, we need to examine the
191 ;; whole current branch.
192 (vc-insert-file (vc-name file
) "^desc")
193 (vc-rcs-find-most-recent-rev (vc-branch-part version
))))))
195 (defun vc-rcs-checkout-model (file)
196 "RCS-specific version of `vc-checkout-model'."
197 (vc-rcs-consult-headers file
)
198 (or (vc-file-getprop file
'vc-checkout-model
)
199 (progn (vc-rcs-fetch-master-state file
)
200 (vc-file-getprop file
'vc-checkout-model
))))
202 (defun vc-rcs-workfile-unchanged-p (file)
203 "RCS-specific implementation of vc-workfile-unchanged-p."
204 ;; Try to use rcsdiff --brief. If rcsdiff does not understand that,
205 ;; do a double take and remember the fact for the future
206 (let* ((version (concat "-r" (vc-workfile-version file
)))
207 (status (if (eq vc-rcsdiff-knows-brief
'no
)
208 (vc-do-command nil
1 "rcsdiff" file version
)
209 (vc-do-command nil
2 "rcsdiff" file
"--brief" version
))))
211 (if (not vc-rcsdiff-knows-brief
)
212 (setq vc-rcsdiff-knows-brief
'no
213 status
(vc-do-command nil
1 "rcsdiff" file version
))
214 (error "rcsdiff failed"))
215 (if (not vc-rcsdiff-knows-brief
) (setq vc-rcsdiff-knows-brief
'yes
)))
216 ;; The workfile is unchanged if rcsdiff found no differences.
221 ;;; State-changing functions
224 (defun vc-rcs-register (file &optional rev comment
)
225 "Register FILE into the RCS version-control system.
226 REV is the optional revision number for the file. COMMENT can be used
227 to provide an initial description of FILE.
229 `vc-register-switches' and `vc-rcs-register-switches' are passed to
230 the RCS command (in that order).
232 Automatically retrieve a read-only version of the file with keywords
233 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
234 (let ((subdir (expand-file-name "RCS" (file-name-directory file
)))
236 (if (stringp vc-register-switches
)
237 (list vc-register-switches
)
238 vc-register-switches
)
239 (if (stringp vc-rcs-register-switches
)
240 (list vc-rcs-register-switches
)
241 vc-rcs-register-switches
))))
243 (and (not (file-exists-p subdir
))
244 (not (directory-files (file-name-directory file
)
246 (yes-or-no-p "Create RCS subdirectory? ")
247 (make-directory subdir
))
248 (apply 'vc-do-command nil
0 "ci" file
249 ;; if available, use the secure registering option
250 (and (vc-rcs-release-p "5.6.4") "-i")
251 (concat (if vc-keep-workfiles
"-u" "-r") rev
)
252 (and comment
(concat "-t-" comment
))
254 ;; parse output to find master file name and workfile version
255 (with-current-buffer "*vc*"
256 (goto-char (point-min))
257 (let ((name (if (looking-at (concat "^\\(.*\\) <-- "
258 (file-name-nondirectory file
)))
261 ;; if we couldn't find the master name,
262 ;; run vc-rcs-registered to get it
263 ;; (will be stored into the vc-name property)
264 (vc-rcs-registered file
)
265 (vc-file-setprop file
'vc-name
266 (if (file-name-absolute-p name
)
270 (file-name-directory file
))))))
271 (vc-file-setprop file
'vc-workfile-version
272 (if (re-search-forward
273 "^initial revision: \\([0-9.]+\\).*\n"
275 (match-string 1))))))
277 (defun vc-rcs-responsible-p (file)
278 "Return non-nil if RCS thinks it would be responsible for registering FILE."
279 ;; TODO: check for all the patterns in vc-rcs-master-templates
280 (file-directory-p (expand-file-name "RCS" (file-name-directory file
))))
282 (defun vc-rcs-receive-file (file rev
)
283 "Implementation of receive-file for RCS."
284 (let ((checkout-model (vc-checkout-model file
)))
285 (vc-rcs-register file rev
"")
286 (when (eq checkout-model
'implicit
)
287 (vc-rcs-set-non-strict-locking file
))
288 (vc-rcs-set-default-branch file
(concat rev
".1"))))
290 (defun vc-rcs-unregister (file)
291 "Unregister FILE from RCS.
292 If this leaves the RCS subdirectory empty, ask the user
293 whether to remove it."
294 (let* ((master (vc-name file
))
295 (dir (file-name-directory master
))
296 (backup-info (find-backup-file-name master
)))
297 (if (not backup-info
)
299 (rename-file master
(car backup-info
) 'ok-if-already-exists
)
300 (dolist (f (cdr backup-info
)) (ignore-errors (delete-file f
))))
301 (and (string= (file-name-nondirectory (directory-file-name dir
)) "RCS")
302 ;; check whether RCS dir is empty, i.e. it does not
303 ;; contain any files except "." and ".."
304 (not (directory-files dir nil
305 "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*"))
306 (yes-or-no-p (format "Directory %s is empty; remove it? " dir
))
307 (delete-directory dir
))))
309 (defun vc-rcs-checkin (file rev comment
)
310 "RCS-specific version of `vc-backend-checkin'."
311 (let ((switches (if (stringp vc-checkin-switches
)
312 (list vc-checkin-switches
)
313 vc-checkin-switches
)))
314 (let ((old-version (vc-workfile-version file
)) new-version
315 (default-branch (vc-file-getprop file
'vc-rcs-default-branch
)))
316 ;; Force branch creation if an appropriate
317 ;; default branch has been set.
320 (string-match (concat "^" (regexp-quote old-version
) "\\.")
322 (setq rev default-branch
)
323 (setq switches
(cons "-f" switches
)))
324 (apply 'vc-do-command nil
0 "ci" (vc-name file
)
325 ;; if available, use the secure check-in option
326 (and (vc-rcs-release-p "5.6.4") "-j")
327 (concat (if vc-keep-workfiles
"-u" "-r") rev
)
328 (concat "-m" comment
)
330 (vc-file-setprop file
'vc-workfile-version nil
)
332 ;; determine the new workfile version
334 (goto-char (point-min))
335 (when (or (re-search-forward
336 "new revision: \\([0-9.]+\\);" nil t
)
338 "reverting to previous revision \\([0-9.]+\\)" nil t
))
339 (setq new-version
(match-string 1))
340 (vc-file-setprop file
'vc-workfile-version new-version
))
342 ;; if we got to a different branch, adjust the default
343 ;; branch accordingly
345 ((and old-version new-version
346 (not (string= (vc-branch-part old-version
)
347 (vc-branch-part new-version
))))
348 (vc-rcs-set-default-branch file
349 (if (vc-trunk-p new-version
) nil
350 (vc-branch-part new-version
)))
351 ;; If this is an old RCS release, we might have
352 ;; to remove a remaining lock.
353 (if (not (vc-rcs-release-p "5.6.2"))
354 ;; exit status of 1 is also accepted.
355 ;; It means that the lock was removed before.
356 (vc-do-command nil
1 "rcs" (vc-name file
)
357 (concat "-u" old-version
))))))))
359 (defun vc-rcs-checkout (file &optional editable rev workfile
)
360 "Retrieve a copy of a saved version of FILE into a workfile."
361 (let ((filename (or workfile file
))
362 (file-buffer (get-file-buffer file
))
364 (message "Checking out %s..." filename
)
366 ;; Change buffers to get local value of vc-checkout-switches.
367 (if file-buffer
(set-buffer file-buffer
))
368 (setq switches
(if (stringp vc-checkout-switches
)
369 (list vc-checkout-switches
)
370 vc-checkout-switches
))
371 ;; Save this buffer's default-directory
372 ;; and use save-excursion to make sure it is restored
373 ;; in the same buffer it was saved in.
374 (let ((default-directory default-directory
))
376 ;; Adjust the default-directory so that the check-out creates
377 ;; the file in the right place.
378 (setq default-directory
(file-name-directory filename
))
380 ;; RCS can't check out into arbitrary file names directly.
381 ;; Use `co -p' and make stdout point to the correct file.
382 (let ((vc-modes (logior (file-modes (vc-name file
))
383 (if editable
128 0)))
387 (let ((coding-system-for-read 'no-conversion
)
388 (coding-system-for-write 'no-conversion
))
389 (with-temp-file filename
390 (apply 'vc-do-command
391 (current-buffer) 0 "co" (vc-name file
)
392 "-q" ;; suppress diagnostic output
396 (set-file-modes filename
397 (logior (file-modes (vc-name file
))
398 (if editable
128 0)))
400 (and failed
(file-exists-p filename
)
401 (delete-file filename
))))
403 ;; if we should go to the head of the trunk,
404 ;; clear the default branch first
405 (and rev
(string= rev
"")
406 (vc-rcs-set-default-branch file nil
))
407 ;; now do the checkout
408 (apply 'vc-do-command
409 nil
0 "co" (vc-name file
)
410 ;; If locking is not strict, force to overwrite
411 ;; the writable workfile.
412 (if (eq (vc-checkout-model file
) 'implicit
) "-f")
414 (if rev
(concat "-r" rev
)
415 ;; if no explicit revision was specified,
416 ;; check out that of the working file
417 (let ((workrev (vc-workfile-version file
)))
418 (if workrev
(concat "-r" workrev
)
421 ;; determine the new workfile version
422 (with-current-buffer "*vc*"
424 (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1)))
425 (vc-file-setprop file
'vc-workfile-version new-version
)
426 ;; if necessary, adjust the default branch
427 (and rev
(not (string= rev
""))
428 (vc-rcs-set-default-branch
430 (if (vc-rcs-latest-on-branch-p file new-version
)
431 (if (vc-trunk-p new-version
) nil
432 (vc-branch-part new-version
))
434 (message "Checking out %s...done" filename
)))))
436 (defun vc-rcs-revert (file &optional contents-done
)
437 "Revert FILE to the version it was based on."
438 (vc-do-command nil
0 "co" (vc-name file
) "-f"
439 (concat "-u" (vc-workfile-version file
))))
441 (defun vc-rcs-cancel-version (file editable
)
442 "Undo the most recent checkin of FILE.
443 EDITABLE non-nil means previous version should be locked."
444 (let* ((target (vc-workfile-version file
))
445 (previous (if (vc-trunk-p target
) "" (vc-branch-part target
)))
446 (config (current-window-configuration))
448 (vc-do-command nil
0 "rcs" (vc-name file
) (concat "-o" target
))
449 ;; Check out the most recent remaining version. If it fails, because
450 ;; the whole branch got deleted, do a double-take and check out the
451 ;; version where the branch started.
455 (vc-do-command nil
0 "co" (vc-name file
) "-f"
456 (concat (if editable
"-l" "-u") previous
))
458 (error (set-buffer "*vc*")
459 (goto-char (point-min))
460 (if (search-forward "no side branches present for" nil t
)
461 (progn (setq previous
(vc-branch-part previous
))
462 (vc-rcs-set-default-branch file previous
)
463 ;; vc-do-command popped up a window with
464 ;; the error message. Get rid of it, by
465 ;; restoring the old window configuration.
466 (set-window-configuration config
))
467 ;; No, it was some other error: re-signal it.
468 (signal (car err
) (cdr err
))))))))
470 (defun vc-rcs-merge (file first-version
&optional second-version
)
471 "Merge changes into current working copy of FILE.
472 The changes are between FIRST-VERSION and SECOND-VERSION."
473 (vc-do-command nil
1 "rcsmerge" (vc-name file
)
474 "-kk" ; ignore keyword conflicts
475 (concat "-r" first-version
)
476 (if second-version
(concat "-r" second-version
))))
478 (defun vc-rcs-steal-lock (file &optional rev
)
479 "Steal the lock on the current workfile for FILE and revision REV.
480 Needs RCS 5.6.2 or later for -M."
481 (vc-do-command nil
0 "rcs" (vc-name file
) "-M" (concat "-u" rev
))
482 ;; Do a real checkout after stealing the lock, so that we see
484 (vc-do-command nil
0 "co" (vc-name file
) "-f" (concat "-l" rev
)))
489 ;;; History functions
492 (defun vc-rcs-print-log (file)
493 "Get change log associated with FILE."
494 (vc-do-command nil
0 "rlog" (vc-name file
)))
496 (defun vc-rcs-show-log-entry (version)
497 (when (re-search-forward
498 ;; also match some context, for safety
499 (concat "----\nrevision " version
500 "\\(\tlocked by:.*\n\\|\n\\)date: ") nil t
)
501 ;; set the display window so that
502 ;; the whole log entry is displayed
503 (let (start end lines
)
504 (beginning-of-line) (forward-line -
1) (setq start
(point))
505 (if (not (re-search-forward "^----*\nrevision" nil t
))
506 (setq end
(point-max))
507 (beginning-of-line) (forward-line -
1) (setq end
(point)))
508 (setq lines
(count-lines start end
))
510 ;; if the global information and this log entry fit
511 ;; into the window, display from the beginning
512 ((< (count-lines (point-min) end
) (window-height))
513 (goto-char (point-min))
516 ;; if the whole entry fits into the window,
517 ;; display it centered
518 ((< (1+ lines
) (window-height))
520 (recenter (1- (- (/ (window-height) 2) (/ lines
2)))))
521 ;; otherwise (the entry is too large for the window),
522 ;; display from the start
527 (defun vc-rcs-diff (file &optional oldvers newvers
)
528 "Get a difference report using RCS between two versions of FILE."
529 (if (not oldvers
) (setq oldvers
(vc-workfile-version file
)))
530 (apply 'vc-do-command
"*vc-diff*" 1 "rcsdiff" file
532 (concat "-r" oldvers
)
533 (and newvers
(concat "-r" newvers
)))
534 (vc-diff-switches-list 'RCS
))))
541 (defun vc-rcs-assign-name (file name
)
542 "Assign to FILE's latest version a given NAME."
543 (vc-do-command nil
0 "rcs" (vc-name file
) (concat "-n" name
":")))
550 (defun vc-rcs-check-headers ()
551 "Check if the current file has any headers in it."
553 (goto-char (point-min))
554 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
555 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
557 (defun vc-rcs-clear-headers ()
558 "Implementation of vc-clear-headers for RCS."
559 (let ((case-fold-search nil
))
560 (goto-char (point-min))
561 (while (re-search-forward
562 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
563 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
565 (replace-match "$\\1$"))))
567 (defun vc-rcs-rename-file (old new
)
568 ;; Just move the master file (using vc-rcs-master-templates).
569 (vc-rename-master (vc-name old
) new vc-rcs-master-templates
))
573 ;;; Internal functions
576 (defun vc-rcs-workfile-is-newer (file)
577 "Return non-nil if FILE is newer than its RCS master.
578 This likely means that FILE has been changed with respect
579 to its master version."
580 (let ((file-time (nth 5 (file-attributes file
)))
581 (master-time (nth 5 (file-attributes (vc-name file
)))))
582 (or (> (nth 0 file-time
) (nth 0 master-time
))
583 (and (= (nth 0 file-time
) (nth 0 master-time
))
584 (> (nth 1 file-time
) (nth 1 master-time
))))))
586 (defun vc-rcs-find-most-recent-rev (branch)
587 "Find most recent revision on BRANCH."
588 (goto-char (point-min))
589 (let ((latest-rev -
1) value
)
590 (while (re-search-forward (concat "^\\(" (regexp-quote branch
)
591 "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;")
593 (let ((rev (string-to-number (match-string 2))))
594 (when (< latest-rev rev
)
595 (setq latest-rev rev
)
596 (setq value
(match-string 1)))))
598 (vc-branch-part branch
))))
600 (defun vc-rcs-fetch-master-state (file &optional workfile-version
)
601 "Compute the master file's idea of the state of FILE.
602 If a WORKFILE-VERSION is given, compute the state of that version,
603 otherwise determine the workfile version based on the master file.
604 This function sets the properties `vc-workfile-version' and
605 `vc-checkout-model' to their correct values, based on the master
608 (vc-insert-file (vc-name file
) "^[0-9]")
609 (let ((workfile-is-latest nil
)
610 (default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1)))
611 (vc-file-setprop file
'vc-rcs-default-branch default-branch
)
612 (unless workfile-version
613 ;; Workfile version not known yet. Determine that first. It
614 ;; is either the head of the trunk, the head of the default
615 ;; branch, or the "default branch" itself, if that is a full
619 ((or (not default-branch
) (string= "" default-branch
))
620 (setq workfile-version
621 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
622 (setq workfile-is-latest t
))
623 ;; default branch is actually a revision
624 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
626 (setq workfile-version default-branch
))
627 ;; else, search for the head of the default branch
628 (t (vc-insert-file (vc-name file
) "^desc")
629 (setq workfile-version
630 (vc-rcs-find-most-recent-rev default-branch
))
631 (setq workfile-is-latest t
)))
632 (vc-file-setprop file
'vc-workfile-version workfile-version
))
633 ;; Check strict locking
634 (goto-char (point-min))
635 (vc-file-setprop file
'vc-checkout-model
636 (if (re-search-forward ";[ \t\n]*strict;" nil t
)
638 ;; Compute state of workfile version
639 (goto-char (point-min))
641 (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):"
642 (regexp-quote workfile-version
)
648 (if (or workfile-is-latest
649 (vc-rcs-latest-on-branch-p file workfile-version
))
650 ;; workfile version is latest on branch
652 ;; workfile version is not latest on branch
654 ;; locked by the calling user
655 ((and (stringp locking-user
)
656 (string= locking-user
(vc-user-login-name)))
657 (if (or (eq (vc-checkout-model file
) 'locking
)
659 (vc-rcs-latest-on-branch-p file workfile-version
))
661 ;; Locking is not used for the file, but the owner does
662 ;; have a lock, and there is a higher version on the current
663 ;; branch. Not sure if this can occur, and if it is right
664 ;; to use `needs-merge' in this case.
666 ;; locked by somebody else
667 ((stringp locking-user
)
670 (error "Error getting state of RCS file")))))))
672 (defun vc-rcs-consult-headers (file)
673 "Search for RCS headers in FILE, and set properties accordingly.
675 Returns: nil if no headers were found
676 'rev if a workfile revision was found
677 'rev-and-lock if revision and lock info was found"
679 ((not (get-file-buffer file
)) nil
)
680 ((let (status version locking-user
)
682 (set-buffer (get-file-buffer file
))
683 (goto-char (point-min))
685 ;; search for $Id or $Header
686 ;; -------------------------
687 ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file.
688 ((or (and (search-forward "$Id\ : " nil t
)
689 (looking-at "[^ ]+ \\([0-9.]+\\) "))
690 (and (progn (goto-char (point-min))
691 (search-forward "$Header\ : " nil t
))
692 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
693 (goto-char (match-end 0))
694 ;; if found, store the revision number ...
695 (setq version
(match-string-no-properties 1))
696 ;; ... and check for the locking state
699 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
700 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
701 "[^ ]+ [^ ]+ ")) ; author & state
702 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
706 (setq locking-user
'none
)
707 (setq status
'rev-and-lock
))
708 ;; revision is locked by some user
709 ((looking-at "\\([^ ]+\\) \\$")
710 (setq locking-user
(match-string-no-properties 1))
711 (setq status
'rev-and-lock
))
712 ;; everything else: false
714 ;; unexpected information in
715 ;; keyword string --> quit
717 ;; search for $Revision
718 ;; --------------------
719 ((re-search-forward (concat "\\$"
720 "Revision: \\([0-9.]+\\) \\$")
722 ;; if found, store the revision number ...
723 (setq version
(match-string-no-properties 1))
724 ;; and see if there's any lock information
725 (goto-char (point-min))
726 (if (re-search-forward (concat "\\$" "Locker:") nil t
)
727 (cond ((looking-at " \\([^ ]+\\) \\$")
728 (setq locking-user
(match-string-no-properties 1))
729 (setq status
'rev-and-lock
))
730 ((looking-at " *\\$")
731 (setq locking-user
'none
)
732 (setq status
'rev-and-lock
))
734 (setq locking-user
'none
)
735 (setq status
'rev-and-lock
)))
737 ;; else: nothing found
738 ;; -------------------
740 (if status
(vc-file-setprop file
'vc-workfile-version version
))
741 (and (eq status
'rev-and-lock
)
742 (vc-file-setprop file
'vc-state
744 ((eq locking-user
'none
) 'up-to-date
)
745 ((string= locking-user
(vc-user-login-name)) 'edited
)
747 ;; If the file has headers, we don't want to query the
748 ;; master file, because that would eliminate all the
749 ;; performance gain the headers brought us. We therefore
750 ;; use a heuristic now to find out whether locking is used
751 ;; for this file. If we trust the file permissions, and the
752 ;; file is not locked, then if the file is read-only we
753 ;; assume that locking is used for the file, otherwise
754 ;; locking is not used.
755 (not (vc-mistrust-permissions file
))
756 (vc-up-to-date-p file
)
757 (if (string-match ".r-..-..-." (nth 8 (file-attributes file
)))
758 (vc-file-setprop file
'vc-checkout-model
'locking
)
759 (vc-file-setprop file
'vc-checkout-model
'implicit
)))
762 (defun vc-release-greater-or-equal (r1 r2
)
763 "Compare release numbers, represented as strings.
764 Release components are assumed cardinal numbers, not decimal fractions
765 \(5.10 is a higher release than 5.9\). Omitted fields are considered
766 lower \(5.6.7 is earlier than 5.6.7.1\). Comparison runs till the end
767 of the string is found, or a non-numeric component shows up \(5.6.7 is
768 earlier than \"5.6.7 beta\", which is probably not what you want in
769 some cases\). This code is suitable for existing RCS release numbers.
770 CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5\)."
773 (or (and (string-match "^\\.?\\([0-9]+\\)" r1
)
774 (setq i1
(match-end 0))
775 (setq v1
(string-to-number (match-string 1 r1
)))
776 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
777 (setq i2
(match-end 0))
778 (setq v2
(string-to-number (match-string 1 r2
)))
779 (if (> v1 v2
) (throw 'done t
)
780 (if (< v1 v2
) (throw 'done nil
)
782 (vc-release-greater-or-equal
784 (substring r2 i2
)))))))
786 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
790 (defun vc-rcs-release-p (release)
791 "Return t if we have RELEASE or better."
792 (let ((installation (vc-rcs-system-release)))
793 (if (and installation
794 (not (eq installation
'unknown
)))
795 (vc-release-greater-or-equal installation release
))))
798 (defun vc-rcs-system-release ()
799 "Return the RCS release installed on this system, as a string.
800 Return symbol UNKNOWN if the release cannot be deducted. The user can
801 override this using variable `vc-rcs-release'.
803 If the user has not set variable `vc-rcs-release' and it is nil,
804 variable `vc-rcs-release' is set to the returned value."
807 (or (and (zerop (vc-do-command nil nil
"rcs" nil
"-V"))
808 (with-current-buffer (get-buffer "*vc*")
809 (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1)))
812 (defun vc-rcs-set-non-strict-locking (file)
813 (vc-do-command nil
0 "rcs" file
"-U")
814 (vc-file-setprop file
'vc-checkout-model
'implicit
)
815 (set-file-modes file
(logior (file-modes file
) 128)))
817 (defun vc-rcs-set-default-branch (file branch
)
818 (vc-do-command nil
0 "rcs" (vc-name file
) (concat "-b" branch
))
819 (vc-file-setprop file
'vc-rcs-default-branch branch
))
823 ;;; vc-rcs.el ends here