1 ;;; vc-rcs.el --- support for RCS version-control
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 ;; 2000, 2001, 2004 Free Software Foundation, Inc.
6 ;; Author: FSF (see vc.el for full credits)
7 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
35 ;;; Customization options
42 (defcustom vc-rcs-release nil
43 "*The release number of your RCS installation, as a string.
44 If nil, VC itself computes this value when it is first needed."
45 :type
'(choice (const :tag
"Auto" nil
)
46 (string :tag
"Specified")
47 (const :tag
"Unknown" unknown
))
50 (defcustom vc-rcs-register-switches nil
51 "*Extra switches for registering a file in RCS.
52 A string or list of strings. These are passed to the checkin program
53 by \\[vc-rcs-register]."
54 :type
'(choice (const :tag
"None" nil
)
55 (string :tag
"Argument String")
56 (repeat :tag
"Argument List"
62 (defcustom vc-rcs-diff-switches nil
63 "*A string or list of strings specifying extra switches for rcsdiff under VC."
64 :type
'(choice (const :tag
"None" nil
)
65 (string :tag
"Argument String")
66 (repeat :tag
"Argument List"
72 (defcustom vc-rcs-header
(or (cdr (assoc 'RCS vc-header-alist
)) '("\$Id\$"))
73 "*Header keywords to be inserted by `vc-insert-headers'."
74 :type
'(repeat string
)
78 (defcustom vc-rcsdiff-knows-brief nil
79 "*Indicates whether rcsdiff understands the --brief option.
80 The value is either `yes', `no', or nil. If it is nil, VC tries
81 to use --brief and sets this variable to remember whether it worked."
82 :type
'(choice (const :tag
"Work out" nil
) (const yes
) (const no
))
86 (defcustom vc-rcs-master-templates
87 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s")
88 "*Where to look for RCS master files.
89 For a description of possible values, see `vc-check-master-templates'."
90 :type
'(choice (const :tag
"Use standard RCS file names"
91 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
92 (repeat :tag
"User-specified"
100 ;;; State-querying functions
103 ;;; The autoload cookie below places vc-rcs-registered directly into
104 ;;; loaddefs.el, so that vc-rcs.el does not need to be loaded for
105 ;;; every file that is visited. The definition is repeated below
106 ;;; so that Help and etags can find it.
108 ;;;###autoload (defun vc-rcs-registered (f) (vc-default-registered 'RCS f))
109 (defun vc-rcs-registered (f) (vc-default-registered 'RCS f
))
111 (defun vc-rcs-state (file)
112 "Implementation of `vc-state' for RCS."
113 (or (boundp 'vc-rcs-headers-result
)
114 (and vc-consult-headers
115 (vc-rcs-consult-headers file
)))
117 ;; vc-workfile-version might not be known; in that case the
118 ;; property is nil. vc-rcs-fetch-master-state knows how to
120 (vc-rcs-fetch-master-state file
121 (vc-file-getprop file
122 'vc-workfile-version
))))
123 (if (not (eq state
'up-to-date
))
125 (if (vc-workfile-unchanged-p file
)
127 (if (eq (vc-checkout-model file
) 'locking
)
131 (defun vc-rcs-state-heuristic (file)
132 "State heuristic for RCS."
133 (let (vc-rcs-headers-result)
134 (if (and vc-consult-headers
135 (setq vc-rcs-headers-result
136 (vc-rcs-consult-headers file
))
137 (eq vc-rcs-headers-result
'rev-and-lock
))
138 (let ((state (vc-file-getprop file
'vc-state
)))
139 ;; If the headers say that the file is not locked, the
140 ;; permissions can tell us whether locking is used for
142 (if (and (eq state
'up-to-date
)
143 (not (vc-mistrust-permissions file
)))
145 ((string-match ".rw..-..-." (nth 8 (file-attributes file
)))
146 (vc-file-setprop file
'vc-checkout-model
'implicit
)
148 (if (vc-rcs-workfile-is-newer file
)
151 ((string-match ".r-..-..-." (nth 8 (file-attributes file
)))
152 (vc-file-setprop file
'vc-checkout-model
'locking
))))
154 (if (not (vc-mistrust-permissions file
))
155 (let* ((attributes (file-attributes file
))
156 (owner-uid (nth 2 attributes
))
157 (permissions (nth 8 attributes
)))
158 (cond ((string-match ".r-..-..-." permissions
)
159 (vc-file-setprop file
'vc-checkout-model
'locking
)
161 ((string-match ".rw..-..-." permissions
)
162 (if (eq (vc-checkout-model file
) 'locking
)
163 (if (file-ownership-preserved-p file
)
165 (vc-user-login-name owner-uid
))
166 (if (vc-rcs-workfile-is-newer file
)
170 ;; Strange permissions. Fall through to
171 ;; expensive state computation.
172 (vc-rcs-state file
))))
173 (vc-rcs-state file
)))))
175 (defun vc-rcs-workfile-version (file)
176 "RCS-specific version of `vc-workfile-version'."
177 (or (and vc-consult-headers
178 (vc-rcs-consult-headers file
)
179 (vc-file-getprop file
'vc-workfile-version
))
181 (vc-rcs-fetch-master-state file
)
182 (vc-file-getprop file
'vc-workfile-version
))))
184 (defun vc-rcs-latest-on-branch-p (file &optional version
)
185 "Return non-nil if workfile version of FILE is the latest on its branch.
186 When VERSION is given, perform check for that version."
187 (unless version
(setq version
(vc-workfile-version file
)))
190 (if (vc-trunk-p version
)
192 ;; Compare VERSION to the head version number.
193 (vc-insert-file (vc-name file
) "^[0-9]")
194 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
195 ;; If we are not on the trunk, we need to examine the
196 ;; whole current branch.
197 (vc-insert-file (vc-name file
) "^desc")
198 (vc-rcs-find-most-recent-rev (vc-branch-part version
))))))
200 (defun vc-rcs-checkout-model (file)
201 "RCS-specific version of `vc-checkout-model'."
203 (when vc-consult-headers
204 (vc-file-setprop file
'vc-checkout-model nil
)
205 (vc-rcs-consult-headers file
)
206 (setq result
(vc-file-getprop file
'vc-checkout-model
)))
208 (progn (vc-rcs-fetch-master-state file
)
209 (vc-file-getprop file
'vc-checkout-model
)))))
211 (defun vc-rcs-workfile-unchanged-p (file)
212 "RCS-specific implementation of `vc-workfile-unchanged-p'."
213 ;; Try to use rcsdiff --brief. If rcsdiff does not understand that,
214 ;; do a double take and remember the fact for the future
215 (let* ((version (concat "-r" (vc-workfile-version file
)))
216 (status (if (eq vc-rcsdiff-knows-brief
'no
)
217 (vc-do-command nil
1 "rcsdiff" file version
)
218 (vc-do-command nil
2 "rcsdiff" file
"--brief" version
))))
220 (if (not vc-rcsdiff-knows-brief
)
221 (setq vc-rcsdiff-knows-brief
'no
222 status
(vc-do-command nil
1 "rcsdiff" file version
))
223 (error "rcsdiff failed"))
224 (if (not vc-rcsdiff-knows-brief
) (setq vc-rcsdiff-knows-brief
'yes
)))
225 ;; The workfile is unchanged if rcsdiff found no differences.
230 ;;; State-changing functions
233 (defun vc-rcs-register (file &optional rev comment
)
234 "Register FILE into the RCS version-control system.
235 REV is the optional revision number for the file. COMMENT can be used
236 to provide an initial description of FILE.
238 `vc-register-switches' and `vc-rcs-register-switches' are passed to
239 the RCS command (in that order).
241 Automatically retrieve a read-only version of the file with keywords
242 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
243 (let ((subdir (expand-file-name "RCS" (file-name-directory file
))))
244 (and (not (file-exists-p subdir
))
245 (not (directory-files (file-name-directory file
)
247 (yes-or-no-p "Create RCS subdirectory? ")
248 (make-directory subdir
))
249 (apply 'vc-do-command nil
0 "ci" file
250 ;; if available, use the secure registering option
251 (and (vc-rcs-release-p "5.6.4") "-i")
252 (concat (if vc-keep-workfiles
"-u" "-r") rev
)
253 (and comment
(concat "-t-" comment
))
254 (vc-switches 'RCS
'register
))
255 ;; parse output to find master file name and workfile version
256 (with-current-buffer "*vc*"
257 (goto-char (point-min))
258 (let ((name (if (looking-at (concat "^\\(.*\\) <-- "
259 (file-name-nondirectory file
)))
262 ;; if we couldn't find the master name,
263 ;; run vc-rcs-registered to get it
264 ;; (will be stored into the vc-name property)
265 (vc-rcs-registered file
)
266 (vc-file-setprop file
'vc-name
267 (if (file-name-absolute-p name
)
271 (file-name-directory file
))))))
272 (vc-file-setprop file
'vc-workfile-version
273 (if (re-search-forward
274 "^initial revision: \\([0-9.]+\\).*\n"
276 (match-string 1))))))
278 (defun vc-rcs-responsible-p (file)
279 "Return non-nil if RCS thinks it would be responsible for registering FILE."
280 ;; TODO: check for all the patterns in vc-rcs-master-templates
281 (file-directory-p (expand-file-name "RCS" (file-name-directory file
))))
283 (defun vc-rcs-receive-file (file rev
)
284 "Implementation of receive-file for RCS."
285 (let ((checkout-model (vc-checkout-model file
)))
286 (vc-rcs-register file rev
"")
287 (when (eq checkout-model
'implicit
)
288 (vc-rcs-set-non-strict-locking file
))
289 (vc-rcs-set-default-branch file
(concat rev
".1"))))
291 (defun vc-rcs-unregister (file)
292 "Unregister FILE from RCS.
293 If this leaves the RCS subdirectory empty, ask the user
294 whether to remove it."
295 (let* ((master (vc-name file
))
296 (dir (file-name-directory master
))
297 (backup-info (find-backup-file-name master
)))
298 (if (not backup-info
)
300 (rename-file master
(car backup-info
) 'ok-if-already-exists
)
301 (dolist (f (cdr backup-info
)) (ignore-errors (delete-file f
))))
302 (and (string= (file-name-nondirectory (directory-file-name dir
)) "RCS")
303 ;; check whether RCS dir is empty, i.e. it does not
304 ;; contain any files except "." and ".."
305 (not (directory-files dir nil
306 "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*"))
307 (yes-or-no-p (format "Directory %s is empty; remove it? " dir
))
308 (delete-directory dir
))))
310 (defun vc-rcs-checkin (file rev comment
)
311 "RCS-specific version of `vc-backend-checkin'."
312 (let ((switches (vc-switches 'RCS
'checkin
)))
313 (let ((old-version (vc-workfile-version file
)) new-version
314 (default-branch (vc-file-getprop file
'vc-rcs-default-branch
)))
315 ;; Force branch creation if an appropriate
316 ;; default branch has been set.
319 (string-match (concat "^" (regexp-quote old-version
) "\\.")
321 (setq rev default-branch
)
322 (setq switches
(cons "-f" switches
)))
323 (if (and (not rev
) old-version
)
324 (setq rev
(vc-branch-part old-version
)))
325 (apply 'vc-do-command nil
0 "ci" (vc-name file
)
326 ;; if available, use the secure check-in option
327 (and (vc-rcs-release-p "5.6.4") "-j")
328 (concat (if vc-keep-workfiles
"-u" "-r") rev
)
329 (concat "-m" comment
)
331 (vc-file-setprop file
'vc-workfile-version nil
)
333 ;; determine the new workfile version
335 (goto-char (point-min))
336 (when (or (re-search-forward
337 "new revision: \\([0-9.]+\\);" nil t
)
339 "reverting to previous revision \\([0-9.]+\\)" nil t
))
340 (setq new-version
(match-string 1))
341 (vc-file-setprop file
'vc-workfile-version new-version
))
343 ;; if we got to a different branch, adjust the default
344 ;; branch accordingly
346 ((and old-version new-version
347 (not (string= (vc-branch-part old-version
)
348 (vc-branch-part new-version
))))
349 (vc-rcs-set-default-branch file
350 (if (vc-trunk-p new-version
) nil
351 (vc-branch-part new-version
)))
352 ;; If this is an old RCS release, we might have
353 ;; to remove a remaining lock.
354 (if (not (vc-rcs-release-p "5.6.2"))
355 ;; exit status of 1 is also accepted.
356 ;; It means that the lock was removed before.
357 (vc-do-command nil
1 "rcs" (vc-name file
)
358 (concat "-u" old-version
))))))))
360 (defun vc-rcs-find-version (file rev buffer
)
361 (apply 'vc-do-command
362 buffer
0 "co" (vc-name file
)
363 "-q" ;; suppress diagnostic output
365 (vc-switches 'RCS
'checkout
)))
367 (defun vc-rcs-checkout (file &optional editable rev
)
368 "Retrieve a copy of a saved version of FILE."
369 (let ((file-buffer (get-file-buffer file
))
371 (message "Checking out %s..." file
)
373 ;; Change buffers to get local value of vc-checkout-switches.
374 (if file-buffer
(set-buffer file-buffer
))
375 (setq switches
(vc-switches 'RCS
'checkout
))
376 ;; Save this buffer's default-directory
377 ;; and use save-excursion to make sure it is restored
378 ;; in the same buffer it was saved in.
379 (let ((default-directory default-directory
))
381 ;; Adjust the default-directory so that the check-out creates
382 ;; the file in the right place.
383 (setq default-directory
(file-name-directory file
))
385 ;; if we should go to the head of the trunk,
386 ;; clear the default branch first
387 (and rev
(string= rev
"")
388 (vc-rcs-set-default-branch file nil
))
389 ;; now do the checkout
390 (apply 'vc-do-command
391 nil
0 "co" (vc-name file
)
392 ;; If locking is not strict, force to overwrite
393 ;; the writable workfile.
394 (if (eq (vc-checkout-model file
) 'implicit
) "-f")
397 ;; a literal revision was specified
399 (let ((workrev (vc-workfile-version file
)))
403 ;; no revision specified:
404 ;; use current workfile version
407 (if (not (vc-trunk-p workrev
))
408 ;; ... go to head of current branch
409 (vc-branch-part workrev
)
410 ;; ... go to head of trunk
411 (vc-rcs-set-default-branch file
415 ;; determine the new workfile version
416 (with-current-buffer "*vc*"
418 (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1)))
419 (vc-file-setprop file
'vc-workfile-version new-version
)
420 ;; if necessary, adjust the default branch
421 (and rev
(not (string= rev
""))
422 (vc-rcs-set-default-branch
424 (if (vc-rcs-latest-on-branch-p file new-version
)
425 (if (vc-trunk-p new-version
) nil
426 (vc-branch-part new-version
))
428 (message "Checking out %s...done" file
)))))
430 (defun vc-rcs-revert (file &optional contents-done
)
431 "Revert FILE to the version it was based on."
432 (vc-do-command nil
0 "co" (vc-name file
) "-f"
433 (concat (if (eq (vc-state file
) 'edited
) "-u" "-r")
434 (vc-workfile-version file
))))
436 (defun vc-rcs-cancel-version (file editable
)
437 "Undo the most recent checkin of FILE.
438 EDITABLE non-nil means previous version should be locked."
439 (let* ((target (vc-workfile-version file
))
440 (previous (if (vc-trunk-p target
) "" (vc-branch-part target
)))
441 (config (current-window-configuration))
443 (vc-do-command nil
0 "rcs" (vc-name file
) (concat "-o" target
))
444 ;; Check out the most recent remaining version. If it fails, because
445 ;; the whole branch got deleted, do a double-take and check out the
446 ;; version where the branch started.
450 (vc-do-command nil
0 "co" (vc-name file
) "-f"
451 (concat (if editable
"-l" "-u") previous
))
453 (error (set-buffer "*vc*")
454 (goto-char (point-min))
455 (if (search-forward "no side branches present for" nil t
)
456 (progn (setq previous
(vc-branch-part previous
))
457 (vc-rcs-set-default-branch file previous
)
458 ;; vc-do-command popped up a window with
459 ;; the error message. Get rid of it, by
460 ;; restoring the old window configuration.
461 (set-window-configuration config
))
462 ;; No, it was some other error: re-signal it.
463 (signal (car err
) (cdr err
))))))))
465 (defun vc-rcs-merge (file first-version
&optional second-version
)
466 "Merge changes into current working copy of FILE.
467 The changes are between FIRST-VERSION and SECOND-VERSION."
468 (vc-do-command nil
1 "rcsmerge" (vc-name file
)
469 "-kk" ; ignore keyword conflicts
470 (concat "-r" first-version
)
471 (if second-version
(concat "-r" second-version
))))
473 (defun vc-rcs-steal-lock (file &optional rev
)
474 "Steal the lock on the current workfile for FILE and revision REV.
475 Needs RCS 5.6.2 or later for -M."
476 (vc-do-command nil
0 "rcs" (vc-name file
) "-M" (concat "-u" rev
))
477 ;; Do a real checkout after stealing the lock, so that we see
479 (vc-do-command nil
0 "co" (vc-name file
) "-f" (concat "-l" rev
)))
484 ;;; History functions
487 (defun vc-rcs-print-log (file &optional buffer
)
488 "Get change log associated with FILE."
489 (vc-do-command buffer
0 "rlog" (vc-name file
)))
491 (defun vc-rcs-diff (file &optional oldvers newvers buffer
)
492 "Get a difference report using RCS between two versions of FILE."
493 (if (not oldvers
) (setq oldvers
(vc-workfile-version file
)))
494 (apply 'vc-do-command
(or buffer
"*vc-diff*") 1 "rcsdiff" file
496 (concat "-r" oldvers
)
497 (and newvers
(concat "-r" newvers
)))
498 (vc-switches 'RCS
'diff
))))
505 (defun vc-rcs-assign-name (file name
)
506 "Assign to FILE's latest version a given NAME."
507 (vc-do-command nil
0 "rcs" (vc-name file
) (concat "-n" name
":")))
514 (defun vc-rcs-check-headers ()
515 "Check if the current file has any headers in it."
517 (goto-char (point-min))
518 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
519 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
521 (defun vc-rcs-clear-headers ()
522 "Implementation of vc-clear-headers for RCS."
523 (let ((case-fold-search nil
))
524 (goto-char (point-min))
525 (while (re-search-forward
526 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
527 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
529 (replace-match "$\\1$"))))
531 (defun vc-rcs-rename-file (old new
)
532 ;; Just move the master file (using vc-rcs-master-templates).
533 (vc-rename-master (vc-name old
) new vc-rcs-master-templates
))
537 ;;; Internal functions
540 (defun vc-rcs-workfile-is-newer (file)
541 "Return non-nil if FILE is newer than its RCS master.
542 This likely means that FILE has been changed with respect
543 to its master version."
544 (let ((file-time (nth 5 (file-attributes file
)))
545 (master-time (nth 5 (file-attributes (vc-name file
)))))
546 (or (> (nth 0 file-time
) (nth 0 master-time
))
547 (and (= (nth 0 file-time
) (nth 0 master-time
))
548 (> (nth 1 file-time
) (nth 1 master-time
))))))
550 (defun vc-rcs-find-most-recent-rev (branch)
551 "Find most recent revision on BRANCH."
552 (goto-char (point-min))
553 (let ((latest-rev -
1) value
)
554 (while (re-search-forward (concat "^\\(" (regexp-quote branch
)
555 "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;")
557 (let ((rev (string-to-number (match-string 2))))
558 (when (< latest-rev rev
)
559 (setq latest-rev rev
)
560 (setq value
(match-string 1)))))
562 (vc-branch-part branch
))))
564 (defun vc-rcs-fetch-master-state (file &optional workfile-version
)
565 "Compute the master file's idea of the state of FILE.
566 If a WORKFILE-VERSION is given, compute the state of that version,
567 otherwise determine the workfile version based on the master file.
568 This function sets the properties `vc-workfile-version' and
569 `vc-checkout-model' to their correct values, based on the master
572 (if (or (not (vc-insert-file (vc-name file
) "^[0-9]"))
573 (progn (goto-char (point-min))
574 (not (looking-at "^head[ \t\n]+[^;]+;$"))))
575 (error "File %s is not an RCS master file" (vc-name file
)))
576 (let ((workfile-is-latest nil
)
577 (default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1)))
578 (vc-file-setprop file
'vc-rcs-default-branch default-branch
)
579 (unless workfile-version
580 ;; Workfile version not known yet. Determine that first. It
581 ;; is either the head of the trunk, the head of the default
582 ;; branch, or the "default branch" itself, if that is a full
586 ((or (not default-branch
) (string= "" default-branch
))
587 (setq workfile-version
588 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
589 (setq workfile-is-latest t
))
590 ;; default branch is actually a revision
591 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
593 (setq workfile-version default-branch
))
594 ;; else, search for the head of the default branch
595 (t (vc-insert-file (vc-name file
) "^desc")
596 (setq workfile-version
597 (vc-rcs-find-most-recent-rev default-branch
))
598 (setq workfile-is-latest t
)))
599 (vc-file-setprop file
'vc-workfile-version workfile-version
))
600 ;; Check strict locking
601 (goto-char (point-min))
602 (vc-file-setprop file
'vc-checkout-model
603 (if (re-search-forward ";[ \t\n]*strict;" nil t
)
605 ;; Compute state of workfile version
606 (goto-char (point-min))
608 (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):"
609 (regexp-quote workfile-version
)
615 (if (or workfile-is-latest
616 (vc-rcs-latest-on-branch-p file workfile-version
))
617 ;; workfile version is latest on branch
619 ;; workfile version is not latest on branch
621 ;; locked by the calling user
622 ((and (stringp locking-user
)
623 (string= locking-user
(vc-user-login-name)))
624 (if (or (eq (vc-checkout-model file
) 'locking
)
626 (vc-rcs-latest-on-branch-p file workfile-version
))
628 ;; Locking is not used for the file, but the owner does
629 ;; have a lock, and there is a higher version on the current
630 ;; branch. Not sure if this can occur, and if it is right
631 ;; to use `needs-merge' in this case.
633 ;; locked by somebody else
634 ((stringp locking-user
)
637 (error "Error getting state of RCS file")))))))
639 (defun vc-rcs-consult-headers (file)
640 "Search for RCS headers in FILE, and set properties accordingly.
642 Returns: nil if no headers were found
643 'rev if a workfile revision was found
644 'rev-and-lock if revision and lock info was found"
646 ((not (get-file-buffer file
)) nil
)
647 ((let (status version locking-user
)
649 (set-buffer (get-file-buffer file
))
650 (goto-char (point-min))
652 ;; search for $Id or $Header
653 ;; -------------------------
654 ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file.
655 ((or (and (search-forward "$Id\ : " nil t
)
656 (looking-at "[^ ]+ \\([0-9.]+\\) "))
657 (and (progn (goto-char (point-min))
658 (search-forward "$Header\ : " nil t
))
659 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
660 (goto-char (match-end 0))
661 ;; if found, store the revision number ...
662 (setq version
(match-string-no-properties 1))
663 ;; ... and check for the locking state
666 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
667 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
668 "[^ ]+ [^ ]+ ")) ; author & state
669 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
673 (setq locking-user
'none
)
674 (setq status
'rev-and-lock
))
675 ;; revision is locked by some user
676 ((looking-at "\\([^ ]+\\) \\$")
677 (setq locking-user
(match-string-no-properties 1))
678 (setq status
'rev-and-lock
))
679 ;; everything else: false
681 ;; unexpected information in
682 ;; keyword string --> quit
684 ;; search for $Revision
685 ;; --------------------
686 ((re-search-forward (concat "\\$"
687 "Revision: \\([0-9.]+\\) \\$")
689 ;; if found, store the revision number ...
690 (setq version
(match-string-no-properties 1))
691 ;; and see if there's any lock information
692 (goto-char (point-min))
693 (if (re-search-forward (concat "\\$" "Locker:") nil t
)
694 (cond ((looking-at " \\([^ ]+\\) \\$")
695 (setq locking-user
(match-string-no-properties 1))
696 (setq status
'rev-and-lock
))
697 ((looking-at " *\\$")
698 (setq locking-user
'none
)
699 (setq status
'rev-and-lock
))
701 (setq locking-user
'none
)
702 (setq status
'rev-and-lock
)))
704 ;; else: nothing found
705 ;; -------------------
707 (if status
(vc-file-setprop file
'vc-workfile-version version
))
708 (and (eq status
'rev-and-lock
)
709 (vc-file-setprop file
'vc-state
711 ((eq locking-user
'none
) 'up-to-date
)
712 ((string= locking-user
(vc-user-login-name)) 'edited
)
714 ;; If the file has headers, we don't want to query the
715 ;; master file, because that would eliminate all the
716 ;; performance gain the headers brought us. We therefore
717 ;; use a heuristic now to find out whether locking is used
718 ;; for this file. If we trust the file permissions, and the
719 ;; file is not locked, then if the file is read-only we
720 ;; assume that locking is used for the file, otherwise
721 ;; locking is not used.
722 (not (vc-mistrust-permissions file
))
723 (vc-up-to-date-p file
)
724 (if (string-match ".r-..-..-." (nth 8 (file-attributes file
)))
725 (vc-file-setprop file
'vc-checkout-model
'locking
)
726 (vc-file-setprop file
'vc-checkout-model
'implicit
)))
729 (defun vc-release-greater-or-equal (r1 r2
)
730 "Compare release numbers, represented as strings.
731 Release components are assumed cardinal numbers, not decimal fractions
732 \(5.10 is a higher release than 5.9\). Omitted fields are considered
733 lower \(5.6.7 is earlier than 5.6.7.1\). Comparison runs till the end
734 of the string is found, or a non-numeric component shows up \(5.6.7 is
735 earlier than \"5.6.7 beta\", which is probably not what you want in
736 some cases\). This code is suitable for existing RCS release numbers.
737 CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5\)."
740 (or (and (string-match "^\\.?\\([0-9]+\\)" r1
)
741 (setq i1
(match-end 0))
742 (setq v1
(string-to-number (match-string 1 r1
)))
743 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
744 (setq i2
(match-end 0))
745 (setq v2
(string-to-number (match-string 1 r2
)))
746 (if (> v1 v2
) (throw 'done t
)
747 (if (< v1 v2
) (throw 'done nil
)
749 (vc-release-greater-or-equal
751 (substring r2 i2
)))))))
753 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
757 (defun vc-rcs-release-p (release)
758 "Return t if we have RELEASE or better."
759 (let ((installation (vc-rcs-system-release)))
760 (if (and installation
761 (not (eq installation
'unknown
)))
762 (vc-release-greater-or-equal installation release
))))
765 (defun vc-rcs-system-release ()
766 "Return the RCS release installed on this system, as a string.
767 Return symbol UNKNOWN if the release cannot be deducted. The user can
768 override this using variable `vc-rcs-release'.
770 If the user has not set variable `vc-rcs-release' and it is nil,
771 variable `vc-rcs-release' is set to the returned value."
774 (or (and (zerop (vc-do-command nil nil
"rcs" nil
"-V"))
775 (with-current-buffer (get-buffer "*vc*")
776 (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1)))
779 (defun vc-rcs-set-non-strict-locking (file)
780 (vc-do-command nil
0 "rcs" file
"-U")
781 (vc-file-setprop file
'vc-checkout-model
'implicit
)
782 (set-file-modes file
(logior (file-modes file
) 128)))
784 (defun vc-rcs-set-default-branch (file branch
)
785 (vc-do-command nil
0 "rcs" (vc-name file
) (concat "-b" branch
))
786 (vc-file-setprop file
'vc-rcs-default-branch branch
))
790 ;; arch-tag: 759b4916-5b0d-431d-b647-b185b8c652cf
791 ;;; vc-rcs.el ends here