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.34 2003/01/03 15:27:35 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
102 ;;; The autoload cookie below places vc-rcs-registered directly into
103 ;;; loaddefs.el, so that vc-rcs.el does not need to be loaded for
104 ;;; every file that is visited. The definition is repeated below
105 ;;; so that Help and etags can find it.
107 ;;;###autoload (defun vc-rcs-registered (f) (vc-default-registered 'RCS f))
108 (defun vc-rcs-registered (f) (vc-default-registered 'RCS f
))
110 (defun vc-rcs-state (file)
111 "Implementation of `vc-state' for RCS."
112 (or (boundp 'vc-rcs-headers-result
)
113 (and vc-consult-headers
114 (vc-rcs-consult-headers file
)))
116 ;; vc-workfile-version might not be known; in that case the
117 ;; property is nil. vc-rcs-fetch-master-state knows how to
119 (vc-rcs-fetch-master-state file
120 (vc-file-getprop file
121 'vc-workfile-version
))))
122 (if (not (eq state
'up-to-date
))
124 (if (vc-workfile-unchanged-p file
)
126 (if (eq (vc-checkout-model file
) 'locking
)
130 (defun vc-rcs-state-heuristic (file)
131 "State heuristic for RCS."
132 (let (vc-rcs-headers-result)
133 (if (and vc-consult-headers
134 (setq vc-rcs-headers-result
135 (vc-rcs-consult-headers file
))
136 (eq vc-rcs-headers-result
'rev-and-lock
))
137 (let ((state (vc-file-getprop file
'vc-state
)))
138 ;; If the headers say that the file is not locked, the
139 ;; permissions can tell us whether locking is used for
141 (if (and (eq state
'up-to-date
)
142 (not (vc-mistrust-permissions file
)))
144 ((string-match ".rw..-..-." (nth 8 (file-attributes file
)))
145 (vc-file-setprop file
'vc-checkout-model
'implicit
)
147 (if (vc-rcs-workfile-is-newer file
)
150 ((string-match ".r-..-..-." (nth 8 (file-attributes file
)))
151 (vc-file-setprop file
'vc-checkout-model
'locking
))))
153 (if (not (vc-mistrust-permissions file
))
154 (let* ((attributes (file-attributes file
))
155 (owner-uid (nth 2 attributes
))
156 (permissions (nth 8 attributes
)))
157 (cond ((string-match ".r-..-..-." permissions
)
158 (vc-file-setprop file
'vc-checkout-model
'locking
)
160 ((string-match ".rw..-..-." permissions
)
161 (if (eq (vc-checkout-model file
) 'locking
)
162 (if (file-ownership-preserved-p file
)
164 (vc-user-login-name owner-uid
))
165 (if (vc-rcs-workfile-is-newer file
)
169 ;; Strange permissions. Fall through to
170 ;; expensive state computation.
171 (vc-rcs-state file
))))
172 (vc-rcs-state file
)))))
174 (defun vc-rcs-workfile-version (file)
175 "RCS-specific version of `vc-workfile-version'."
176 (or (and vc-consult-headers
177 (vc-rcs-consult-headers file
)
178 (vc-file-getprop file
'vc-workfile-version
))
180 (vc-rcs-fetch-master-state file
)
181 (vc-file-getprop file
'vc-workfile-version
))))
183 (defun vc-rcs-latest-on-branch-p (file &optional version
)
184 "Return non-nil if workfile version of FILE is the latest on its branch.
185 When VERSION is given, perform check for that version."
186 (unless version
(setq version
(vc-workfile-version file
)))
189 (if (vc-trunk-p version
)
191 ;; Compare VERSION to the head version number.
192 (vc-insert-file (vc-name file
) "^[0-9]")
193 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
194 ;; If we are not on the trunk, we need to examine the
195 ;; whole current branch.
196 (vc-insert-file (vc-name file
) "^desc")
197 (vc-rcs-find-most-recent-rev (vc-branch-part version
))))))
199 (defun vc-rcs-checkout-model (file)
200 "RCS-specific version of `vc-checkout-model'."
201 (vc-rcs-consult-headers file
)
202 (or (vc-file-getprop file
'vc-checkout-model
)
203 (progn (vc-rcs-fetch-master-state file
)
204 (vc-file-getprop file
'vc-checkout-model
))))
206 (defun vc-rcs-workfile-unchanged-p (file)
207 "RCS-specific implementation of vc-workfile-unchanged-p."
208 ;; Try to use rcsdiff --brief. If rcsdiff does not understand that,
209 ;; do a double take and remember the fact for the future
210 (let* ((version (concat "-r" (vc-workfile-version file
)))
211 (status (if (eq vc-rcsdiff-knows-brief
'no
)
212 (vc-do-command nil
1 "rcsdiff" file version
)
213 (vc-do-command nil
2 "rcsdiff" file
"--brief" version
))))
215 (if (not vc-rcsdiff-knows-brief
)
216 (setq vc-rcsdiff-knows-brief
'no
217 status
(vc-do-command nil
1 "rcsdiff" file version
))
218 (error "rcsdiff failed"))
219 (if (not vc-rcsdiff-knows-brief
) (setq vc-rcsdiff-knows-brief
'yes
)))
220 ;; The workfile is unchanged if rcsdiff found no differences.
225 ;;; State-changing functions
228 (defun vc-rcs-register (file &optional rev comment
)
229 "Register FILE into the RCS version-control system.
230 REV is the optional revision number for the file. COMMENT can be used
231 to provide an initial description of FILE.
233 `vc-register-switches' and `vc-rcs-register-switches' are passed to
234 the RCS command (in that order).
236 Automatically retrieve a read-only version of the file with keywords
237 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
238 (let ((subdir (expand-file-name "RCS" (file-name-directory file
)))
240 (if (stringp vc-register-switches
)
241 (list vc-register-switches
)
242 vc-register-switches
)
243 (if (stringp vc-rcs-register-switches
)
244 (list vc-rcs-register-switches
)
245 vc-rcs-register-switches
))))
247 (and (not (file-exists-p subdir
))
248 (not (directory-files (file-name-directory file
)
250 (yes-or-no-p "Create RCS subdirectory? ")
251 (make-directory subdir
))
252 (apply 'vc-do-command nil
0 "ci" file
253 ;; if available, use the secure registering option
254 (and (vc-rcs-release-p "5.6.4") "-i")
255 (concat (if vc-keep-workfiles
"-u" "-r") rev
)
256 (and comment
(concat "-t-" comment
))
258 ;; parse output to find master file name and workfile version
259 (with-current-buffer "*vc*"
260 (goto-char (point-min))
261 (let ((name (if (looking-at (concat "^\\(.*\\) <-- "
262 (file-name-nondirectory file
)))
265 ;; if we couldn't find the master name,
266 ;; run vc-rcs-registered to get it
267 ;; (will be stored into the vc-name property)
268 (vc-rcs-registered file
)
269 (vc-file-setprop file
'vc-name
270 (if (file-name-absolute-p name
)
274 (file-name-directory file
))))))
275 (vc-file-setprop file
'vc-workfile-version
276 (if (re-search-forward
277 "^initial revision: \\([0-9.]+\\).*\n"
279 (match-string 1))))))
281 (defun vc-rcs-responsible-p (file)
282 "Return non-nil if RCS thinks it would be responsible for registering FILE."
283 ;; TODO: check for all the patterns in vc-rcs-master-templates
284 (file-directory-p (expand-file-name "RCS" (file-name-directory file
))))
286 (defun vc-rcs-receive-file (file rev
)
287 "Implementation of receive-file for RCS."
288 (let ((checkout-model (vc-checkout-model file
)))
289 (vc-rcs-register file rev
"")
290 (when (eq checkout-model
'implicit
)
291 (vc-rcs-set-non-strict-locking file
))
292 (vc-rcs-set-default-branch file
(concat rev
".1"))))
294 (defun vc-rcs-unregister (file)
295 "Unregister FILE from RCS.
296 If this leaves the RCS subdirectory empty, ask the user
297 whether to remove it."
298 (let* ((master (vc-name file
))
299 (dir (file-name-directory master
))
300 (backup-info (find-backup-file-name master
)))
301 (if (not backup-info
)
303 (rename-file master
(car backup-info
) 'ok-if-already-exists
)
304 (dolist (f (cdr backup-info
)) (ignore-errors (delete-file f
))))
305 (and (string= (file-name-nondirectory (directory-file-name dir
)) "RCS")
306 ;; check whether RCS dir is empty, i.e. it does not
307 ;; contain any files except "." and ".."
308 (not (directory-files dir nil
309 "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*"))
310 (yes-or-no-p (format "Directory %s is empty; remove it? " dir
))
311 (delete-directory dir
))))
313 (defun vc-rcs-checkin (file rev comment
)
314 "RCS-specific version of `vc-backend-checkin'."
315 (let ((switches (if (stringp vc-checkin-switches
)
316 (list vc-checkin-switches
)
317 vc-checkin-switches
)))
318 (let ((old-version (vc-workfile-version file
)) new-version
319 (default-branch (vc-file-getprop file
'vc-rcs-default-branch
)))
320 ;; Force branch creation if an appropriate
321 ;; default branch has been set.
324 (string-match (concat "^" (regexp-quote old-version
) "\\.")
326 (setq rev default-branch
)
327 (setq switches
(cons "-f" switches
)))
328 (if (and (not rev
) old-version
)
329 (setq rev
(vc-branch-part old-version
)))
330 (apply 'vc-do-command nil
0 "ci" (vc-name file
)
331 ;; if available, use the secure check-in option
332 (and (vc-rcs-release-p "5.6.4") "-j")
333 (concat (if vc-keep-workfiles
"-u" "-r") rev
)
334 (concat "-m" comment
)
336 (vc-file-setprop file
'vc-workfile-version nil
)
338 ;; determine the new workfile version
340 (goto-char (point-min))
341 (when (or (re-search-forward
342 "new revision: \\([0-9.]+\\);" nil t
)
344 "reverting to previous revision \\([0-9.]+\\)" nil t
))
345 (setq new-version
(match-string 1))
346 (vc-file-setprop file
'vc-workfile-version new-version
))
348 ;; if we got to a different branch, adjust the default
349 ;; branch accordingly
351 ((and old-version new-version
352 (not (string= (vc-branch-part old-version
)
353 (vc-branch-part new-version
))))
354 (vc-rcs-set-default-branch file
355 (if (vc-trunk-p new-version
) nil
356 (vc-branch-part new-version
)))
357 ;; If this is an old RCS release, we might have
358 ;; to remove a remaining lock.
359 (if (not (vc-rcs-release-p "5.6.2"))
360 ;; exit status of 1 is also accepted.
361 ;; It means that the lock was removed before.
362 (vc-do-command nil
1 "rcs" (vc-name file
)
363 (concat "-u" old-version
))))))))
365 (defun vc-rcs-find-version (file rev buffer
)
366 (apply 'vc-do-command
367 buffer
0 "co" (vc-name file
)
368 "-q" ;; suppress diagnostic output
370 (if (stringp vc-checkout-switches
)
371 (list vc-checkout-switches
)
372 vc-checkout-switches
)))
374 (defun vc-rcs-checkout (file &optional editable rev
)
375 "Retrieve a copy of a saved version of FILE."
376 (let ((file-buffer (get-file-buffer file
))
378 (message "Checking out %s..." file
)
380 ;; Change buffers to get local value of vc-checkout-switches.
381 (if file-buffer
(set-buffer file-buffer
))
382 (setq switches
(if (stringp vc-checkout-switches
)
383 (list vc-checkout-switches
)
384 vc-checkout-switches
))
385 ;; Save this buffer's default-directory
386 ;; and use save-excursion to make sure it is restored
387 ;; in the same buffer it was saved in.
388 (let ((default-directory default-directory
))
390 ;; Adjust the default-directory so that the check-out creates
391 ;; the file in the right place.
392 (setq default-directory
(file-name-directory file
))
394 ;; if we should go to the head of the trunk,
395 ;; clear the default branch first
396 (and rev
(string= rev
"")
397 (vc-rcs-set-default-branch file nil
))
398 ;; now do the checkout
399 (apply 'vc-do-command
400 nil
0 "co" (vc-name file
)
401 ;; If locking is not strict, force to overwrite
402 ;; the writable workfile.
403 (if (eq (vc-checkout-model file
) 'implicit
) "-f")
406 ;; a literal revision was specified
408 (let ((workrev (vc-workfile-version file
)))
412 ;; no revision specified:
413 ;; use current workfile version
416 (if (not (vc-trunk-p workrev
))
417 ;; ... go to head of current branch
418 (vc-branch-part workrev
)
419 ;; ... go to head of trunk
420 (vc-rcs-set-default-branch file
424 ;; determine the new workfile version
425 (with-current-buffer "*vc*"
427 (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1)))
428 (vc-file-setprop file
'vc-workfile-version new-version
)
429 ;; if necessary, adjust the default branch
430 (and rev
(not (string= rev
""))
431 (vc-rcs-set-default-branch
433 (if (vc-rcs-latest-on-branch-p file new-version
)
434 (if (vc-trunk-p new-version
) nil
435 (vc-branch-part new-version
))
437 (message "Checking out %s...done" file
)))))
439 (defun vc-rcs-revert (file &optional contents-done
)
440 "Revert FILE to the version it was based on."
441 (vc-do-command nil
0 "co" (vc-name file
) "-f"
442 (concat (if (eq (vc-state file
) 'edited
) "-u" "-r")
443 (vc-workfile-version file
))))
445 (defun vc-rcs-cancel-version (file editable
)
446 "Undo the most recent checkin of FILE.
447 EDITABLE non-nil means previous version should be locked."
448 (let* ((target (vc-workfile-version file
))
449 (previous (if (vc-trunk-p target
) "" (vc-branch-part target
)))
450 (config (current-window-configuration))
452 (vc-do-command nil
0 "rcs" (vc-name file
) (concat "-o" target
))
453 ;; Check out the most recent remaining version. If it fails, because
454 ;; the whole branch got deleted, do a double-take and check out the
455 ;; version where the branch started.
459 (vc-do-command nil
0 "co" (vc-name file
) "-f"
460 (concat (if editable
"-l" "-u") previous
))
462 (error (set-buffer "*vc*")
463 (goto-char (point-min))
464 (if (search-forward "no side branches present for" nil t
)
465 (progn (setq previous
(vc-branch-part previous
))
466 (vc-rcs-set-default-branch file previous
)
467 ;; vc-do-command popped up a window with
468 ;; the error message. Get rid of it, by
469 ;; restoring the old window configuration.
470 (set-window-configuration config
))
471 ;; No, it was some other error: re-signal it.
472 (signal (car err
) (cdr err
))))))))
474 (defun vc-rcs-merge (file first-version
&optional second-version
)
475 "Merge changes into current working copy of FILE.
476 The changes are between FIRST-VERSION and SECOND-VERSION."
477 (vc-do-command nil
1 "rcsmerge" (vc-name file
)
478 "-kk" ; ignore keyword conflicts
479 (concat "-r" first-version
)
480 (if second-version
(concat "-r" second-version
))))
482 (defun vc-rcs-steal-lock (file &optional rev
)
483 "Steal the lock on the current workfile for FILE and revision REV.
484 Needs RCS 5.6.2 or later for -M."
485 (vc-do-command nil
0 "rcs" (vc-name file
) "-M" (concat "-u" rev
))
486 ;; Do a real checkout after stealing the lock, so that we see
488 (vc-do-command nil
0 "co" (vc-name file
) "-f" (concat "-l" rev
)))
493 ;;; History functions
496 (defun vc-rcs-print-log (file)
497 "Get change log associated with FILE."
498 (vc-do-command nil
0 "rlog" (vc-name file
)))
500 (defun vc-rcs-diff (file &optional oldvers newvers
)
501 "Get a difference report using RCS between two versions of FILE."
502 (if (not oldvers
) (setq oldvers
(vc-workfile-version file
)))
503 (apply 'vc-do-command
"*vc-diff*" 1 "rcsdiff" file
505 (concat "-r" oldvers
)
506 (and newvers
(concat "-r" newvers
)))
507 (vc-diff-switches-list 'RCS
))))
514 (defun vc-rcs-assign-name (file name
)
515 "Assign to FILE's latest version a given NAME."
516 (vc-do-command nil
0 "rcs" (vc-name file
) (concat "-n" name
":")))
523 (defun vc-rcs-check-headers ()
524 "Check if the current file has any headers in it."
526 (goto-char (point-min))
527 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
528 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
530 (defun vc-rcs-clear-headers ()
531 "Implementation of vc-clear-headers for RCS."
532 (let ((case-fold-search nil
))
533 (goto-char (point-min))
534 (while (re-search-forward
535 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
536 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
538 (replace-match "$\\1$"))))
540 (defun vc-rcs-rename-file (old new
)
541 ;; Just move the master file (using vc-rcs-master-templates).
542 (vc-rename-master (vc-name old
) new vc-rcs-master-templates
))
546 ;;; Internal functions
549 (defun vc-rcs-workfile-is-newer (file)
550 "Return non-nil if FILE is newer than its RCS master.
551 This likely means that FILE has been changed with respect
552 to its master version."
553 (let ((file-time (nth 5 (file-attributes file
)))
554 (master-time (nth 5 (file-attributes (vc-name file
)))))
555 (or (> (nth 0 file-time
) (nth 0 master-time
))
556 (and (= (nth 0 file-time
) (nth 0 master-time
))
557 (> (nth 1 file-time
) (nth 1 master-time
))))))
559 (defun vc-rcs-find-most-recent-rev (branch)
560 "Find most recent revision on BRANCH."
561 (goto-char (point-min))
562 (let ((latest-rev -
1) value
)
563 (while (re-search-forward (concat "^\\(" (regexp-quote branch
)
564 "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;")
566 (let ((rev (string-to-number (match-string 2))))
567 (when (< latest-rev rev
)
568 (setq latest-rev rev
)
569 (setq value
(match-string 1)))))
571 (vc-branch-part branch
))))
573 (defun vc-rcs-fetch-master-state (file &optional workfile-version
)
574 "Compute the master file's idea of the state of FILE.
575 If a WORKFILE-VERSION is given, compute the state of that version,
576 otherwise determine the workfile version based on the master file.
577 This function sets the properties `vc-workfile-version' and
578 `vc-checkout-model' to their correct values, based on the master
581 (if (or (not (vc-insert-file (vc-name file
) "^[0-9]"))
582 (progn (goto-char (point-min))
583 (not (looking-at "^head[ \t\n]+[^;]+;$"))))
584 (error "File %s is not an RCS master file" (vc-name file
)))
585 (let ((workfile-is-latest nil
)
586 (default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1)))
587 (vc-file-setprop file
'vc-rcs-default-branch default-branch
)
588 (unless workfile-version
589 ;; Workfile version not known yet. Determine that first. It
590 ;; is either the head of the trunk, the head of the default
591 ;; branch, or the "default branch" itself, if that is a full
595 ((or (not default-branch
) (string= "" default-branch
))
596 (setq workfile-version
597 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
598 (setq workfile-is-latest t
))
599 ;; default branch is actually a revision
600 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
602 (setq workfile-version default-branch
))
603 ;; else, search for the head of the default branch
604 (t (vc-insert-file (vc-name file
) "^desc")
605 (setq workfile-version
606 (vc-rcs-find-most-recent-rev default-branch
))
607 (setq workfile-is-latest t
)))
608 (vc-file-setprop file
'vc-workfile-version workfile-version
))
609 ;; Check strict locking
610 (goto-char (point-min))
611 (vc-file-setprop file
'vc-checkout-model
612 (if (re-search-forward ";[ \t\n]*strict;" nil t
)
614 ;; Compute state of workfile version
615 (goto-char (point-min))
617 (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):"
618 (regexp-quote workfile-version
)
624 (if (or workfile-is-latest
625 (vc-rcs-latest-on-branch-p file workfile-version
))
626 ;; workfile version is latest on branch
628 ;; workfile version is not latest on branch
630 ;; locked by the calling user
631 ((and (stringp locking-user
)
632 (string= locking-user
(vc-user-login-name)))
633 (if (or (eq (vc-checkout-model file
) 'locking
)
635 (vc-rcs-latest-on-branch-p file workfile-version
))
637 ;; Locking is not used for the file, but the owner does
638 ;; have a lock, and there is a higher version on the current
639 ;; branch. Not sure if this can occur, and if it is right
640 ;; to use `needs-merge' in this case.
642 ;; locked by somebody else
643 ((stringp locking-user
)
646 (error "Error getting state of RCS file")))))))
648 (defun vc-rcs-consult-headers (file)
649 "Search for RCS headers in FILE, and set properties accordingly.
651 Returns: nil if no headers were found
652 'rev if a workfile revision was found
653 'rev-and-lock if revision and lock info was found"
655 ((not (get-file-buffer file
)) nil
)
656 ((let (status version locking-user
)
658 (set-buffer (get-file-buffer file
))
659 (goto-char (point-min))
661 ;; search for $Id or $Header
662 ;; -------------------------
663 ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file.
664 ((or (and (search-forward "$Id\ : " nil t
)
665 (looking-at "[^ ]+ \\([0-9.]+\\) "))
666 (and (progn (goto-char (point-min))
667 (search-forward "$Header\ : " nil t
))
668 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
669 (goto-char (match-end 0))
670 ;; if found, store the revision number ...
671 (setq version
(match-string-no-properties 1))
672 ;; ... and check for the locking state
675 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
676 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
677 "[^ ]+ [^ ]+ ")) ; author & state
678 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
682 (setq locking-user
'none
)
683 (setq status
'rev-and-lock
))
684 ;; revision is locked by some user
685 ((looking-at "\\([^ ]+\\) \\$")
686 (setq locking-user
(match-string-no-properties 1))
687 (setq status
'rev-and-lock
))
688 ;; everything else: false
690 ;; unexpected information in
691 ;; keyword string --> quit
693 ;; search for $Revision
694 ;; --------------------
695 ((re-search-forward (concat "\\$"
696 "Revision: \\([0-9.]+\\) \\$")
698 ;; if found, store the revision number ...
699 (setq version
(match-string-no-properties 1))
700 ;; and see if there's any lock information
701 (goto-char (point-min))
702 (if (re-search-forward (concat "\\$" "Locker:") nil t
)
703 (cond ((looking-at " \\([^ ]+\\) \\$")
704 (setq locking-user
(match-string-no-properties 1))
705 (setq status
'rev-and-lock
))
706 ((looking-at " *\\$")
707 (setq locking-user
'none
)
708 (setq status
'rev-and-lock
))
710 (setq locking-user
'none
)
711 (setq status
'rev-and-lock
)))
713 ;; else: nothing found
714 ;; -------------------
716 (if status
(vc-file-setprop file
'vc-workfile-version version
))
717 (and (eq status
'rev-and-lock
)
718 (vc-file-setprop file
'vc-state
720 ((eq locking-user
'none
) 'up-to-date
)
721 ((string= locking-user
(vc-user-login-name)) 'edited
)
723 ;; If the file has headers, we don't want to query the
724 ;; master file, because that would eliminate all the
725 ;; performance gain the headers brought us. We therefore
726 ;; use a heuristic now to find out whether locking is used
727 ;; for this file. If we trust the file permissions, and the
728 ;; file is not locked, then if the file is read-only we
729 ;; assume that locking is used for the file, otherwise
730 ;; locking is not used.
731 (not (vc-mistrust-permissions file
))
732 (vc-up-to-date-p file
)
733 (if (string-match ".r-..-..-." (nth 8 (file-attributes file
)))
734 (vc-file-setprop file
'vc-checkout-model
'locking
)
735 (vc-file-setprop file
'vc-checkout-model
'implicit
)))
738 (defun vc-release-greater-or-equal (r1 r2
)
739 "Compare release numbers, represented as strings.
740 Release components are assumed cardinal numbers, not decimal fractions
741 \(5.10 is a higher release than 5.9\). Omitted fields are considered
742 lower \(5.6.7 is earlier than 5.6.7.1\). Comparison runs till the end
743 of the string is found, or a non-numeric component shows up \(5.6.7 is
744 earlier than \"5.6.7 beta\", which is probably not what you want in
745 some cases\). This code is suitable for existing RCS release numbers.
746 CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5\)."
749 (or (and (string-match "^\\.?\\([0-9]+\\)" r1
)
750 (setq i1
(match-end 0))
751 (setq v1
(string-to-number (match-string 1 r1
)))
752 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
753 (setq i2
(match-end 0))
754 (setq v2
(string-to-number (match-string 1 r2
)))
755 (if (> v1 v2
) (throw 'done t
)
756 (if (< v1 v2
) (throw 'done nil
)
758 (vc-release-greater-or-equal
760 (substring r2 i2
)))))))
762 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
766 (defun vc-rcs-release-p (release)
767 "Return t if we have RELEASE or better."
768 (let ((installation (vc-rcs-system-release)))
769 (if (and installation
770 (not (eq installation
'unknown
)))
771 (vc-release-greater-or-equal installation release
))))
774 (defun vc-rcs-system-release ()
775 "Return the RCS release installed on this system, as a string.
776 Return symbol UNKNOWN if the release cannot be deducted. The user can
777 override this using variable `vc-rcs-release'.
779 If the user has not set variable `vc-rcs-release' and it is nil,
780 variable `vc-rcs-release' is set to the returned value."
783 (or (and (zerop (vc-do-command nil nil
"rcs" nil
"-V"))
784 (with-current-buffer (get-buffer "*vc*")
785 (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1)))
788 (defun vc-rcs-set-non-strict-locking (file)
789 (vc-do-command nil
0 "rcs" file
"-U")
790 (vc-file-setprop file
'vc-checkout-model
'implicit
)
791 (set-file-modes file
(logior (file-modes file
) 128)))
793 (defun vc-rcs-set-default-branch (file branch
)
794 (vc-do-command nil
0 "rcs" (vc-name file
) (concat "-b" branch
))
795 (vc-file-setprop file
'vc-rcs-default-branch branch
))
799 ;;; vc-rcs.el ends here