1 ;;; vc-rcs.el --- support for RCS version-control
3 ;; Copyright (C) 1992,93,94,95,96,97,98,99,2000 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.10 2000/10/03 11:33:59 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.
27 ;;; Commentary: see vc.el
34 (defcustom vc-rcs-release nil
35 "*The release number of your RCS installation, as a string.
36 If nil, VC itself computes this value when it is first needed."
37 :type
'(choice (const :tag
"Auto" nil
)
38 (string :tag
"Specified")
39 (const :tag
"Unknown" unknown
))
42 (defcustom vc-rcs-register-switches nil
43 "*Extra switches for registering a file in RCS.
44 A string or list of strings. These are passed to the checkin program
45 by \\[vc-rcs-register]."
46 :type
'(choice (const :tag
"None" nil
)
47 (string :tag
"Argument String")
48 (repeat :tag
"Argument List"
54 (defcustom vc-rcs-checkin-switches nil
55 "*A string or list of strings specifying extra switches for RCS checkin.
56 These are passed to the checkin program by \\[vc-rcs-checkin]."
57 :type
'(choice (const :tag
"None" nil
)
58 (string :tag
"Argument String")
59 (repeat :tag
"Argument List"
65 (defcustom vc-rcs-checkout-switches nil
66 "*A string or list of strings specifying extra switches for RCS checkout.
67 These are passed to the checkout program by \\[vc-rcs-checkout]."
68 :type
'(choice (const :tag
"None" nil
)
69 (string :tag
"Argument String")
70 (repeat :tag
"Argument List"
76 (defcustom vc-rcs-header
(or (cdr (assoc 'RCS vc-header-alist
)) '("\$Id\$"))
77 "*Header keywords to be inserted by `vc-insert-headers'."
82 (defcustom vc-rcsdiff-knows-brief nil
83 "*Indicates whether rcsdiff understands the --brief option.
84 The value is either `yes', `no', or nil. If it is nil, VC tries
85 to use --brief and sets this variable to remember whether it worked."
86 :type
'(choice (const :tag
"Work out" nil
) (const yes
) (const no
))
90 (defcustom vc-rcs-master-templates
91 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s")
92 "*Where to look for RCS master files.
93 For a description of possible values, see `vc-check-master-templates'."
94 :type
'(choice (const :tag
"Use standard RCS file names"
95 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
96 (repeat :tag
"User-specified"
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 (eq state
'up-to-date
)
118 (if (vc-workfile-unchanged-p file
)
123 (defun vc-rcs-state-heuristic (file)
124 "State heuristic for RCS."
125 (let (vc-rcs-headers-result)
126 (if (and vc-consult-headers
127 (setq vc-rcs-headers-result
128 (vc-rcs-consult-headers file
))
129 (eq vc-rcs-headers-result
'rev-and-lock
))
130 (let ((state (vc-file-getprop file
'vc-state
)))
131 ;; If the headers say that the file is not locked, the
132 ;; permissions can tell us whether locking is used for
134 (if (and (eq state
'up-to-date
)
135 (not (vc-mistrust-permissions file
)))
137 ((string-match ".rw..-..-." (nth 8 (file-attributes file
)))
138 (vc-file-setprop file
'vc-checkout-model
'implicit
)
140 (if (vc-rcs-workfile-is-newer file
)
143 ((string-match ".r-..-..-." (nth 8 (file-attributes file
)))
144 (vc-file-setprop file
'vc-checkout-model
'locking
))))
146 (if (not (vc-mistrust-permissions file
))
147 (let* ((attributes (file-attributes file
))
148 (owner-uid (nth 2 attributes
))
149 (permissions (nth 8 attributes
)))
150 (cond ((string-match ".r-..-..-." permissions
)
151 (vc-file-setprop file
'vc-checkout-model
'locking
)
153 ((string-match ".rw..-..-." permissions
)
154 (if (eq (vc-checkout-model file
) 'locking
)
155 (if (file-ownership-preserved-p file
)
157 (vc-user-login-name owner-uid
))
158 (if (vc-rcs-workfile-is-newer file
)
162 ;; Strange permissions. Fall through to
163 ;; expensive state computation.
164 (vc-rcs-state file
))))
165 (vc-rcs-state file
)))))
167 (defun vc-rcs-workfile-is-newer (file)
168 "Return non-nil if FILE is newer than its RCS master.
169 This likely means that FILE has been changed with respect
170 to its master version."
171 (let ((file-time (nth 5 (file-attributes file
)))
172 (master-time (nth 5 (file-attributes (vc-name file
)))))
173 (or (> (nth 0 file-time
) (nth 0 master-time
))
174 (and (= (nth 0 file-time
) (nth 0 master-time
))
175 (> (nth 1 file-time
) (nth 1 master-time
))))))
177 (defun vc-rcs-workfile-version (file)
178 "RCS-specific version of `vc-workfile-version'."
179 (or (and vc-consult-headers
180 (vc-rcs-consult-headers file
)
181 (vc-file-getprop file
'vc-workfile-version
))
183 (vc-rcs-fetch-master-state file
)
184 (vc-file-getprop file
'vc-workfile-version
))))
186 (defun vc-rcs-checkout-model (file)
187 "RCS-specific version of `vc-checkout-model'."
188 (vc-rcs-consult-headers file
)
189 (or (vc-file-getprop file
'vc-checkout-model
)
190 (progn (vc-rcs-fetch-master-state file
)
191 (vc-file-getprop file
'vc-checkout-model
))))
195 (defun vc-rcs-find-most-recent-rev (branch)
196 "Find most recent revision on BRANCH."
197 (goto-char (point-min))
198 (let ((latest-rev -
1) value
)
199 (while (re-search-forward (concat "^\\(" (regexp-quote branch
)
200 "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;")
202 (let ((rev (string-to-number (match-string 2))))
203 (when (< latest-rev rev
)
204 (setq latest-rev rev
)
205 (setq value
(match-string 1)))))
207 (vc-rcs-branch-part branch
))))
209 (defun vc-rcs-fetch-master-state (file &optional workfile-version
)
210 "Compute the master file's idea of the state of FILE.
211 If a WORKFILE-VERSION is given, compute the state of that version,
212 otherwise determine the workfile version based on the master file.
213 This function sets the properties `vc-workfile-version' and
214 `vc-checkout-model' to their correct values, based on the master
217 (vc-insert-file (vc-name file
) "^[0-9]")
218 (let ((workfile-is-latest nil
)
219 (default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1)))
220 (vc-file-setprop file
'vc-rcs-default-branch default-branch
)
221 (unless workfile-version
222 ;; Workfile version not known yet. Determine that first. It
223 ;; is either the head of the trunk, the head of the default
224 ;; branch, or the "default branch" itself, if that is a full
228 ((or (not default-branch
) (string= "" default-branch
))
229 (setq workfile-version
230 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
231 (setq workfile-is-latest t
))
232 ;; default branch is actually a revision
233 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
235 (setq workfile-version default-branch
))
236 ;; else, search for the head of the default branch
237 (t (vc-insert-file (vc-name file
) "^desc")
238 (setq workfile-version
239 (vc-rcs-find-most-recent-rev default-branch
))
240 (setq workfile-is-latest t
)))
241 (vc-file-setprop file
'vc-workfile-version workfile-version
))
242 ;; Check strict locking
243 (goto-char (point-min))
244 (vc-file-setprop file
'vc-checkout-model
245 (if (re-search-forward ";[ \t\n]*strict;" nil t
)
247 ;; Compute state of workfile version
248 (goto-char (point-min))
250 (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):"
251 (regexp-quote workfile-version
)
257 (if (or workfile-is-latest
258 (vc-rcs-latest-on-branch-p file workfile-version
))
259 ;; workfile version is latest on branch
260 (if (eq (vc-checkout-model file
) 'locking
)
263 (if (vc-workfile-unchanged-p file
)
266 ;; workfile version is not latest on branch
268 ;; locked by the calling user
269 ((and (stringp locking-user
)
270 (string= locking-user
(vc-user-login-name)))
271 (if (or (eq (vc-checkout-model file
) 'locking
)
273 (vc-rcs-latest-on-branch-p file workfile-version
))
275 ;; Locking is not used for the file, but the owner does
276 ;; have a lock, and there is a higher version on the current
277 ;; branch. Not sure if this can occur, and if it is right
278 ;; to use `needs-merge' in this case.
280 ;; locked by somebody else
281 ((stringp locking-user
)
284 (error "Error getting state of RCS file")))))))
286 (defun vc-rcs-consult-headers (file)
287 "Search for RCS headers in FILE, and set properties accordingly.
289 Returns: nil if no headers were found
290 'rev if a workfile revision was found
291 'rev-and-lock if revision and lock info was found"
293 ((not (get-file-buffer file
)) nil
)
294 ((let (status version locking-user
)
296 (set-buffer (get-file-buffer file
))
297 (goto-char (point-min))
299 ;; search for $Id or $Header
300 ;; -------------------------
301 ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file.
302 ((or (and (search-forward "$Id\ : " nil t
)
303 (looking-at "[^ ]+ \\([0-9.]+\\) "))
304 (and (progn (goto-char (point-min))
305 (search-forward "$Header\ : " nil t
))
306 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
307 (goto-char (match-end 0))
308 ;; if found, store the revision number ...
309 (setq version
(match-string-no-properties 1))
310 ;; ... and check for the locking state
313 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
314 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
315 "[^ ]+ [^ ]+ ")) ; author & state
316 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
320 (setq locking-user
'none
)
321 (setq status
'rev-and-lock
))
322 ;; revision is locked by some user
323 ((looking-at "\\([^ ]+\\) \\$")
324 (setq locking-user
(match-string-no-properties 1))
325 (setq status
'rev-and-lock
))
326 ;; everything else: false
328 ;; unexpected information in
329 ;; keyword string --> quit
331 ;; search for $Revision
332 ;; --------------------
333 ((re-search-forward (concat "\\$"
334 "Revision: \\([0-9.]+\\) \\$")
336 ;; if found, store the revision number ...
337 (setq version
(match-string-no-properties 1))
338 ;; and see if there's any lock information
339 (goto-char (point-min))
340 (if (re-search-forward (concat "\\$" "Locker:") nil t
)
341 (cond ((looking-at " \\([^ ]+\\) \\$")
342 (setq locking-user
(match-string-no-properties 1))
343 (setq status
'rev-and-lock
))
344 ((looking-at " *\\$")
345 (setq locking-user
'none
)
346 (setq status
'rev-and-lock
))
348 (setq locking-user
'none
)
349 (setq status
'rev-and-lock
)))
351 ;; else: nothing found
352 ;; -------------------
354 (if status
(vc-file-setprop file
'vc-workfile-version version
))
355 (and (eq status
'rev-and-lock
)
356 (vc-file-setprop file
'vc-state
358 ((eq locking-user
'none
) 'up-to-date
)
359 ((string= locking-user
(vc-user-login-name)) 'edited
)
361 ;; If the file has headers, we don't want to query the
362 ;; master file, because that would eliminate all the
363 ;; performance gain the headers brought us. We therefore
364 ;; use a heuristic now to find out whether locking is used
365 ;; for this file. If we trust the file permissions, and the
366 ;; file is not locked, then if the file is read-only we
367 ;; assume that locking is used for the file, otherwise
368 ;; locking is not used.
369 (not (vc-mistrust-permissions file
))
370 (vc-up-to-date-p file
)
371 (if (string-match ".r-..-..-." (nth 8 (file-attributes file
)))
372 (vc-file-setprop file
'vc-checkout-model
'locking
)
373 (vc-file-setprop file
'vc-checkout-model
'implicit
)))
376 (defun vc-rcs-workfile-unchanged-p (file)
377 "RCS-specific implementation of vc-workfile-unchanged-p."
378 ;; Try to use rcsdiff --brief. If rcsdiff does not understand that,
379 ;; do a double take and remember the fact for the future
380 (let* ((version (concat "-r" (vc-workfile-version file
)))
381 (status (if (eq vc-rcsdiff-knows-brief
'no
)
382 (vc-do-command nil
1 "rcsdiff" file version
)
383 (vc-do-command nil
2 "rcsdiff" file
"--brief" version
))))
385 (if (not vc-rcsdiff-knows-brief
)
386 (setq vc-rcsdiff-knows-brief
'no
387 status
(vc-do-command nil
1 "rcsdiff" file version
))
388 (error "rcsdiff failed"))
389 (if (not vc-rcsdiff-knows-brief
) (setq vc-rcsdiff-knows-brief
'yes
)))
390 ;; The workfile is unchanged if rcsdiff found no differences.
393 (defun vc-rcs-trunk-p (rev)
394 "Return t if REV is an RCS revision on the trunk."
395 (not (eq nil
(string-match "\\`[0-9]+\\.[0-9]+\\'" rev
))))
397 (defun vc-rcs-branch-part (rev)
398 "Return the branch part of an RCS revision number REV"
399 (substring rev
0 (string-match "\\.[0-9]+\\'" rev
)))
401 (defun vc-rcs-latest-on-branch-p (file &optional version
)
402 "Return non-nil if workfile version of FILE is the latest on its branch.
403 When VERSION is given, perform check for that version."
404 (unless version
(setq version
(vc-workfile-version file
)))
407 (if (vc-rcs-trunk-p version
)
409 ;; Compare VERSION to the head version number.
410 (vc-insert-file (vc-name file
) "^[0-9]")
411 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
412 ;; If we are not on the trunk, we need to examine the
413 ;; whole current branch.
414 (vc-insert-file (vc-name file
) "^desc")
415 (vc-rcs-find-most-recent-rev (vc-rcs-branch-part version
))))))
417 (defun vc-rcs-branch-p (rev)
418 "Return t if REV is an RCS branch revision"
419 (not (eq nil
(string-match "\\`[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*\\'" rev
))))
421 (defun vc-rcs-minor-part (rev)
422 "Return the minor version number of an RCS revision number REV."
423 (string-match "[0-9]+\\'" rev
)
424 (substring rev
(match-beginning 0) (match-end 0)))
426 (defun vc-rcs-previous-version (rev)
427 "Guess the previous RCS version number"
428 (let ((branch (vc-rcs-branch-part rev
))
429 (minor-num (string-to-number (vc-rcs-minor-part rev
))))
431 ;; version does probably not start a branch or release
432 (concat branch
"." (number-to-string (1- minor-num
)))
433 (if (vc-rcs-trunk-p rev
)
434 ;; we are at the beginning of the trunk --
435 ;; don't know anything to return here
437 ;; we are at the beginning of a branch --
438 ;; return version of starting point
439 (vc-rcs-branch-part branch
)))))
441 (defun vc-rcs-print-log (file)
442 "Get change log associated with FILE."
443 (vc-do-command t
0 "rlog" (vc-name file
)))
445 (defun vc-rcs-show-log-entry (version)
446 (when (re-search-forward
447 ;; also match some context, for safety
448 (concat "----\nrevision " version
449 "\\(\tlocked by:.*\n\\|\n\\)date: ") nil t
)
450 ;; set the display window so that
451 ;; the whole log entry is displayed
452 (let (start end lines
)
453 (beginning-of-line) (forward-line -
1) (setq start
(point))
454 (if (not (re-search-forward "^----*\nrevision" nil t
))
455 (setq end
(point-max))
456 (beginning-of-line) (forward-line -
1) (setq end
(point)))
457 (setq lines
(count-lines start end
))
459 ;; if the global information and this log entry fit
460 ;; into the window, display from the beginning
461 ((< (count-lines (point-min) end
) (window-height))
462 (goto-char (point-min))
465 ;; if the whole entry fits into the window,
466 ;; display it centered
467 ((< (1+ lines
) (window-height))
469 (recenter (1- (- (/ (window-height) 2) (/ lines
2)))))
470 ;; otherwise (the entry is too large for the window),
471 ;; display from the start
476 (defun vc-rcs-assign-name (file name
)
477 "Assign to FILE's latest version a given NAME."
478 (vc-do-command nil
0 "rcs" (vc-name file
) (concat "-n" name
":")))
480 (defun vc-rcs-merge (file first-version
&optional second-version
)
481 "Merge changes into current working copy of FILE.
482 The changes are between FIRST-VERSION and SECOND-VERSION."
483 (vc-do-command nil
1 "rcsmerge" (vc-name file
)
484 "-kk" ; ignore keyword conflicts
485 (concat "-r" first-version
)
486 (if second-version
(concat "-r" second-version
))))
488 (defun vc-rcs-check-headers ()
489 "Check if the current file has any headers in it."
491 (goto-char (point-min))
492 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
493 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t
)))
495 (defun vc-rcs-clear-headers ()
496 "Implementation of vc-clear-headers for RCS."
497 (let ((case-fold-search nil
))
498 (goto-char (point-min))
499 (while (re-search-forward
500 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
501 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
503 (replace-match "$\\1$"))))
505 (defun vc-rcs-steal-lock (file &optional rev
)
506 "Steal the lock on the current workfile for FILE and revision REV.
507 Needs RCS 5.6.2 or later for -M."
508 (vc-do-command nil
0 "rcs" (vc-name file
) "-M"
509 (concat "-u" rev
) (concat "-l" rev
)))
511 (defun vc-rcs-cancel-version (file writable
)
512 "Undo the most recent checkin of FILE.
513 WRITABLE non-nil means previous version should be locked."
514 (let* ((target (vc-workfile-version file
))
515 (previous (if (vc-trunk-p target
) "" (vc-branch-part target
)))
516 (config (current-window-configuration))
518 (vc-do-command nil
0 "rcs" (vc-name file
) (concat "-o" target
))
519 ;; Check out the most recent remaining version. If it fails, because
520 ;; the whole branch got deleted, do a double-take and check out the
521 ;; version where the branch started.
525 (vc-do-command nil
0 "co" (vc-name file
) "-f"
526 (concat (if writable
"-l" "-u") previous
))
528 (error (set-buffer "*vc*")
529 (goto-char (point-min))
530 (if (search-forward "no side branches present for" nil t
)
531 (progn (setq previous
(vc-branch-part previous
))
532 (vc-rcs-set-default-branch file previous
)
533 ;; vc-do-command popped up a window with
534 ;; the error message. Get rid of it, by
535 ;; restoring the old window configuration.
536 (set-window-configuration config
))
537 ;; No, it was some other error: re-signal it.
538 (signal (car err
) (cdr err
))))))))
540 (defun vc-rcs-revert (file)
541 "Revert FILE to the version it was based on."
542 (vc-do-command nil
0 "co" (vc-name file
) "-f"
543 (concat "-u" (vc-workfile-version file
))))
545 (defun vc-rcs-rename-file (old new
)
546 ;; Just move the master file (using vc-rcs-master-templates).
547 (vc-rename-master (vc-name old
) new vc-rcs-master-templates
))
549 (defun vc-release-greater-or-equal (r1 r2
)
550 "Compare release numbers, represented as strings.
551 Release components are assumed cardinal numbers, not decimal fractions
552 \(5.10 is a higher release than 5.9\). Omitted fields are considered
553 lower \(5.6.7 is earlier than 5.6.7.1\). Comparison runs till the end
554 of the string is found, or a non-numeric component shows up \(5.6.7 is
555 earlier than \"5.6.7 beta\", which is probably not what you want in
556 some cases\). This code is suitable for existing RCS release numbers.
557 CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5\)."
560 (or (and (string-match "^\\.?\\([0-9]+\\)" r1
)
561 (setq i1
(match-end 0))
562 (setq v1
(string-to-number (match-string 1 r1
)))
563 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
564 (setq i2
(match-end 0))
565 (setq v2
(string-to-number (match-string 1 r2
)))
566 (if (> v1 v2
) (throw 'done t
)
567 (if (< v1 v2
) (throw 'done nil
)
569 (vc-release-greater-or-equal
571 (substring r2 i2
)))))))
573 (or (and (string-match "^\\.?\\([0-9]+\\)" r2
)
577 (defun vc-rcs-release-p (release)
578 "Return t if we have RELEASE or better."
579 (let ((installation (vc-rcs-system-release)))
580 (if (and installation
581 (not (eq installation
'unknown
)))
582 (vc-release-greater-or-equal installation release
))))
584 (defun vc-rcs-checkin (file rev comment
)
585 "RCS-specific version of `vc-backend-checkin'."
586 (let ((switches (if (stringp vc-checkin-switches
)
587 (list vc-checkin-switches
)
588 vc-checkin-switches
)))
589 (let ((old-version (vc-workfile-version file
)) new-version
590 (default-branch (vc-file-getprop file
'vc-rcs-default-branch
)))
591 ;; Force branch creation if an appropriate
592 ;; default branch has been set.
595 (string-match (concat "^" (regexp-quote old-version
) "\\.")
597 (setq rev default-branch
)
598 (setq switches
(cons "-f" switches
)))
599 (apply 'vc-do-command nil
0 "ci" (vc-name file
)
600 ;; if available, use the secure check-in option
601 (and (vc-rcs-release-p "5.6.4") "-j")
602 (concat (if vc-keep-workfiles
"-u" "-r") rev
)
603 (concat "-m" comment
)
605 (vc-file-setprop file
'vc-workfile-version nil
)
607 ;; determine the new workfile version
609 (goto-char (point-min))
610 (when (or (re-search-forward
611 "new revision: \\([0-9.]+\\);" nil t
)
613 "reverting to previous revision \\([0-9.]+\\)" nil t
))
614 (setq new-version
(match-string 1))
615 (vc-file-setprop file
'vc-workfile-version new-version
))
617 ;; if we got to a different branch, adjust the default
618 ;; branch accordingly
620 ((and old-version new-version
621 (not (string= (vc-rcs-branch-part old-version
)
622 (vc-rcs-branch-part new-version
))))
623 (vc-rcs-set-default-branch file
624 (if (vc-rcs-trunk-p new-version
) nil
625 (vc-rcs-branch-part new-version
)))
626 ;; If this is an old RCS release, we might have
627 ;; to remove a remaining lock.
628 (if (not (vc-rcs-release-p "5.6.2"))
629 ;; exit status of 1 is also accepted.
630 ;; It means that the lock was removed before.
631 (vc-do-command nil
1 "rcs" (vc-name file
)
632 (concat "-u" old-version
))))))))
634 (defun vc-rcs-system-release ()
635 "Return the RCS release installed on this system, as a string.
636 Return symbol UNKNOWN if the release cannot be deducted. The user can
637 override this using variable `vc-rcs-release'.
639 If the user has not set variable `vc-rcs-release' and it is nil,
640 variable `vc-rcs-release' is set to the returned value."
643 (or (and (zerop (vc-do-command nil nil
"rcs" nil
"-V"))
644 (with-current-buffer (get-buffer "*vc*")
645 (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1)))
648 (defun vc-rcs-diff (file &optional oldvers newvers
)
649 "Get a difference report using RCS between two versions of FILE."
650 (if (not oldvers
) (setq oldvers
(vc-workfile-version file
)))
651 ;; If we know that --brief is not supported, don't try it.
652 (let* ((diff-switches-list (if (listp diff-switches
)
654 (list diff-switches
)))
655 (options (append (list "-q"
656 (concat "-r" oldvers
)
657 (and newvers
(concat "-r" newvers
)))
658 diff-switches-list
)))
659 (apply 'vc-do-command t
1 "rcsdiff" file options
)))
661 (defun vc-rcs-responsible-p (file)
662 "Return non-nil if RCS thinks it would be responsible for registering FILE."
663 ;; TODO: check for all the patterns in vc-rcs-master-templates
664 (file-directory-p (expand-file-name "RCS" (file-name-directory file
))))
666 (defun vc-rcs-register (file &optional rev comment
)
667 "Register FILE into the RCS version-control system.
668 REV is the optional revision number for the file. COMMENT can be used
669 to provide an initial description of FILE.
671 `vc-register-switches' and `vc-rcs-register-switches' are passed to
672 the RCS command (in that order).
674 Automatically retrieve a read-only version of the file with keywords
675 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
676 (let ((subdir (expand-file-name "RCS" (file-name-directory file
)))
678 (if (stringp vc-register-switches
)
679 (list vc-register-switches
)
680 vc-register-switches
)
681 (if (stringp vc-rcs-register-switches
)
682 (list vc-rcs-register-switches
)
683 vc-rcs-register-switches
))))
685 (and (not (file-exists-p subdir
))
686 (not (directory-files (file-name-directory file
)
688 (yes-or-no-p "Create RCS subdirectory? ")
689 (make-directory subdir
))
690 (apply 'vc-do-command nil
0 "ci" file
691 ;; if available, use the secure registering option
692 (and (vc-rcs-release-p "5.6.4") "-i")
693 (concat (if vc-keep-workfiles
"-u" "-r") rev
)
694 (and comment
(concat "-t-" comment
))
696 ;; parse output to find master file name and workfile version
697 (with-current-buffer "*vc*"
698 (goto-char (point-min))
699 (let ((name (if (looking-at (concat "^\\(.*\\) <-- "
700 (file-name-nondirectory file
)))
703 ;; if we couldn't find the master name,
704 ;; run vc-rcs-registered to get it
705 ;; (will be stored into the vc-name property)
706 (vc-rcs-registered file
)
707 (vc-file-setprop file
'vc-name
708 (if (file-name-absolute-p name
)
712 (file-name-directory file
))))))
713 (vc-file-setprop file
'vc-workfile-version
714 (if (re-search-forward
715 "^initial revision: \\([0-9.]+\\).*\n"
717 (match-string 1))))))
719 (defun vc-rcs-unregister (file)
720 "Unregister FILE from RCS.
721 If this leaves the RCS subdirectory empty, ask the user
722 whether to remove it."
723 (let* ((master (vc-name file
))
724 (dir (file-name-directory master
))
725 (backup-info (find-backup-file-name master
)))
726 (if (not backup-info
)
728 (rename-file master
(car backup-info
) 'ok-if-already-exists
)
729 (dolist (f (cdr backup-info
)) (ignore-errors (delete-file f
))))
730 (and (string= (file-name-nondirectory (directory-file-name dir
)) "RCS")
731 ;; check whether RCS dir is empty, i.e. it does not
732 ;; contain any files except "." and ".."
733 (not (directory-files dir nil
734 "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*"))
735 (yes-or-no-p (format "Directory %s is empty; remove it? " dir
))
736 (delete-directory dir
))))
738 (defun vc-rcs-receive-file (file rev
)
739 "Implementation of receive-file for RCS."
740 (let ((checkout-model (vc-checkout-model file
)))
741 (vc-rcs-register file rev
"")
742 (when (eq checkout-model
'implicit
)
743 (vc-rcs-set-non-strict-locking file
))
744 (vc-rcs-set-default-branch file
(concat rev
".1"))))
746 (defun vc-rcs-set-non-strict-locking (file)
747 (vc-do-command nil
0 "rcs" file
"-U")
748 (vc-file-setprop file
'vc-checkout-model
'implicit
)
749 (set-file-modes file
(logior (file-modes file
) 128)))
751 (defun vc-rcs-set-default-branch (file branch
)
752 (vc-do-command nil
0 "rcs" (vc-name file
) (concat "-b" branch
))
753 (vc-file-setprop file
'vc-rcs-default-branch branch
))
755 (defun vc-rcs-checkout (file &optional writable rev workfile
)
756 "Retrieve a copy of a saved version of FILE into a workfile."
757 (let ((filename (or workfile file
))
758 (file-buffer (get-file-buffer file
))
760 (message "Checking out %s..." filename
)
762 ;; Change buffers to get local value of vc-checkout-switches.
763 (if file-buffer
(set-buffer file-buffer
))
764 (setq switches
(if (stringp vc-checkout-switches
)
765 (list vc-checkout-switches
)
766 vc-checkout-switches
))
767 ;; Save this buffer's default-directory
768 ;; and use save-excursion to make sure it is restored
769 ;; in the same buffer it was saved in.
770 (let ((default-directory default-directory
))
772 ;; Adjust the default-directory so that the check-out creates
773 ;; the file in the right place.
774 (setq default-directory
(file-name-directory filename
))
776 ;; RCS can't check out into arbitrary file names directly.
777 ;; Use `co -p' and make stdout point to the correct file.
778 (let ((vc-modes (logior (file-modes (vc-name file
))
779 (if writable
128 0)))
783 (let ((coding-system-for-read 'no-conversion
)
784 (coding-system-for-write 'no-conversion
))
785 (with-temp-file filename
786 (apply 'vc-do-command
787 (current-buffer) 0 "co" (vc-name file
)
788 "-q" ;; suppress diagnostic output
792 (set-file-modes filename
793 (logior (file-modes (vc-name file
))
794 (if writable
128 0)))
796 (and failed
(file-exists-p filename
)
797 (delete-file filename
))))
799 ;; if we should go to the head of the trunk,
800 ;; clear the default branch first
801 (and rev
(string= rev
"")
802 (vc-rcs-set-default-branch file nil
))
803 ;; now do the checkout
804 (apply 'vc-do-command
805 nil
0 "co" (vc-name file
)
806 ;; If locking is not strict, force to overwrite
807 ;; the writable workfile.
808 (if (eq (vc-checkout-model file
) 'implicit
) "-f")
810 (if rev
(concat "-r" rev
)
811 ;; if no explicit revision was specified,
812 ;; check out that of the working file
813 (let ((workrev (vc-workfile-version file
)))
814 (if workrev
(concat "-r" workrev
)
817 ;; determine the new workfile version
818 (with-current-buffer "*vc*"
820 (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1)))
821 (vc-file-setprop file
'vc-workfile-version new-version
)
822 ;; if necessary, adjust the default branch
823 (and rev
(not (string= rev
""))
824 (vc-rcs-set-default-branch
826 (if (vc-rcs-latest-on-branch-p file new-version
)
827 (if (vc-rcs-trunk-p new-version
) nil
828 (vc-rcs-branch-part new-version
))
830 (message "Checking out %s...done" filename
)))))
834 ;;; vc-rcs.el ends here