]> code.delx.au - gnu-emacs/blob - lisp/vc-rcs.el
* vc-sccs.el (vc-sccs-register):
[gnu-emacs] / lisp / vc-rcs.el
1 ;;; vc-rcs.el --- support for RCS version-control
2
3 ;; Copyright (C) 1992,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc.
4
5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
7
8 ;; $Id: vc-rcs.el,v 1.3 2000/09/07 20:02:38 fx Exp $
9
10 ;; This file is part of GNU Emacs.
11
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)
15 ;; any later version.
16
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.
21
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.
26
27 ;;; Commentary: see vc.el
28
29 ;;; Code:
30
31 (defcustom vc-rcs-release nil
32 "*The release number of your RCS installation, as a string.
33 If nil, VC itself computes this value when it is first needed."
34 :type '(choice (const :tag "Auto" nil)
35 (string :tag "Specified")
36 (const :tag "Unknown" unknown))
37 :group 'vc)
38
39 (defcustom vc-rcs-register-switches nil
40 "*Extra switches for registering a file in RCS.
41 A string or list of strings. These are passed to the checkin program
42 by \\[vc-rcs-register]."
43 :type '(choice (const :tag "None" nil)
44 (string :tag "Argument String")
45 (repeat :tag "Argument List"
46 :value ("")
47 string))
48 :version "21.1"
49 :group 'vc)
50
51 (defcustom vc-rcs-checkin-switches nil
52 "*A string or list of strings specifying extra switches for RCS checkin.
53 These are passed to the checkin program by \\[vc-rcs-checkin]."
54 :type '(choice (const :tag "None" nil)
55 (string :tag "Argument String")
56 (repeat :tag "Argument List"
57 :value ("")
58 string))
59 :version "21.1"
60 :group 'vc)
61
62 (defcustom vc-rcs-checkout-switches nil
63 "*A string or list of strings specifying extra switches for RCS checkout.
64 These are passed to the checkout program by \\[vc-rcs-checkout]."
65 :type '(choice (const :tag "None" nil)
66 (string :tag "Argument String")
67 (repeat :tag "Argument List"
68 :value ("")
69 string))
70 :version "21.1"
71 :group 'vc)
72
73 (defcustom vc-rcs-header (or (cdr (assoc 'RCS vc-header-alist)) '("\$Id\$"))
74 "*Header keywords to be inserted by `vc-insert-headers'."
75 :type 'string
76 :version "21.1"
77 :group 'vc)
78
79 (defcustom vc-rcsdiff-knows-brief nil
80 "*Indicates whether rcsdiff understands the --brief option.
81 The value is either `yes', `no', or nil. If it is nil, VC tries
82 to use --brief and sets this variable to remember whether it worked."
83 :type '(choice (const :tag "Work out" nil) (const yes) (const no))
84 :group 'vc)
85
86 ;;;###autoload
87 (defcustom vc-rcs-master-templates
88 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s")
89 "*Where to look for RCS master files.
90 For a description of possible values, see `vc-check-master-templates'."
91 :type '(choice (const :tag "Use standard RCS file names"
92 '("%sRCS/%s,v" "%s%s,v" "%sRCS/%s"))
93 (repeat :tag "User-specified"
94 (choice string
95 function)))
96 :version "21.1"
97 :group 'vc)
98
99 ;;;###autoload
100 (progn (defun vc-rcs-registered (f) (vc-default-registered 'RCS f)))
101
102 (defun vc-rcs-state (file)
103 "Implementation of `vc-state' for RCS."
104 (or (boundp 'vc-rcs-headers-result)
105 (and vc-consult-headers
106 (vc-rcs-consult-headers file)))
107 (let ((state
108 ;; vc-workfile-version might not be known; in that case the
109 ;; property is nil. vc-rcs-fetch-master-state knows how to
110 ;; handle that.
111 (vc-rcs-fetch-master-state file
112 (vc-file-getprop file
113 'vc-workfile-version))))
114 (if (eq state 'up-to-date)
115 (if (vc-workfile-unchanged-p file)
116 'up-to-date
117 'unlocked-changes)
118 state)))
119
120 (defun vc-rcs-state-heuristic (file)
121 "State heuristic for RCS."
122 (let (vc-rcs-headers-result)
123 (if (and vc-consult-headers
124 (setq vc-rcs-headers-result
125 (vc-rcs-consult-headers file))
126 (eq vc-rcs-headers-result 'rev-and-lock))
127 (let ((state (vc-file-getprop file 'vc-state)))
128 ;; If the headers say that the file is not locked, the
129 ;; permissions can tell us whether locking is used for
130 ;; the file or not.
131 (if (and (eq state 'up-to-date)
132 (not (vc-mistrust-permissions file)))
133 (cond
134 ((string-match ".rw..-..-." (nth 8 (file-attributes file)))
135 (vc-file-setprop file 'vc-checkout-model 'implicit))
136 ((string-match ".r-..-..-." (nth 8 (file-attributes file)))
137 (vc-file-setprop file 'vc-checkout-model 'locking))))
138 state)
139 (if (not (vc-mistrust-permissions file))
140 (let* ((attributes (file-attributes file))
141 (owner-uid (nth 2 attributes))
142 (permissions (nth 8 attributes)))
143 (cond ((string-match ".r-..-..-." permissions)
144 (vc-file-setprop file 'vc-checkout-model 'locking)
145 'up-to-date)
146 ((string-match ".rw..-..-." permissions)
147 (if (file-ownership-preserved-p file)
148 'edited
149 (vc-user-login-name owner-uid)))
150 (t
151 ;; Strange permissions. Fall through to
152 ;; expensive state computation.
153 (vc-rcs-state file))))
154 (vc-rcs-state file)))))
155
156 (defun vc-rcs-workfile-version (file)
157 "RCS-specific version of `vc-workfile-version'."
158 (or (and vc-consult-headers
159 (vc-rcs-consult-headers file)
160 (vc-file-getprop file 'vc-workfile-version))
161 (progn
162 (vc-rcs-fetch-master-state file)
163 (vc-file-getprop file 'vc-workfile-version))))
164
165 (defun vc-rcs-checkout-model (file)
166 "RCS-specific version of `vc-checkout-model'."
167 (vc-rcs-consult-headers file)
168 (or (vc-file-getprop file 'vc-checkout-model)
169 (progn (vc-rcs-fetch-master-state file)
170 (vc-file-getprop file 'vc-checkout-model))))
171
172 ;;; internal code
173
174 (defun vc-rcs-find-most-recent-rev (branch)
175 "Find most recent revision on BRANCH."
176 (goto-char (point-min))
177 (let ((latest-rev -1) value)
178 (while (re-search-forward (concat "^\\(" (regexp-quote branch)
179 "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;")
180 nil t)
181 (let ((rev (string-to-number (match-string 2))))
182 (when (< latest-rev rev)
183 (setq latest-rev rev)
184 (setq value (match-string 1)))))
185 value))
186
187 (defun vc-rcs-fetch-master-state (file &optional workfile-version)
188 "Compute the master file's idea of the state of FILE.
189 If a WORKFILE-VERSION is given, compute the state of that version,
190 otherwise determine the workfile version based on the master file.
191 This function sets the properties `vc-workfile-version' and
192 `vc-checkout-model' to their correct values, based on the master
193 file."
194 (with-temp-buffer
195 (vc-insert-file (vc-name file) "^[0-9]")
196 (let ((workfile-is-latest nil))
197 (unless workfile-version
198 (let ((default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1)))
199 ;; Workfile version not known yet. Determine that first. It
200 ;; is either the head of the trunk, the head of the default
201 ;; branch, or the "default branch" itself, if that is a full
202 ;; revision number.
203 (cond
204 ;; no default branch
205 ((or (not default-branch) (string= "" default-branch))
206 (setq workfile-version
207 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
208 (setq workfile-is-latest t))
209 ;; default branch is actually a revision
210 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
211 default-branch)
212 (setq workfile-version default-branch))
213 ;; else, search for the head of the default branch
214 (t (vc-insert-file (vc-name file) "^desc")
215 (setq workfile-version
216 (vc-rcs-find-most-recent-rev default-branch))
217 (setq workfile-is-latest t)))
218 (vc-file-setprop file 'vc-workfile-version workfile-version)))
219 ;; Check strict locking
220 (goto-char (point-min))
221 (vc-file-setprop file 'vc-checkout-model
222 (if (re-search-forward ";[ \t\n]*strict;" nil t)
223 'locking 'implicit))
224 ;; Compute state of workfile version
225 (goto-char (point-min))
226 (let ((locking-user
227 (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):"
228 (regexp-quote workfile-version)
229 "[^0-9.]")
230 1)))
231 (cond
232 ;; not locked
233 ((not locking-user)
234 (if (or workfile-is-latest
235 (vc-rcs-latest-on-branch-p file workfile-version))
236 ;; workfile version is latest on branch
237 'up-to-date
238 ;; workfile version is not latest on branch
239 'needs-patch))
240 ;; locked by the calling user
241 ((and (stringp locking-user)
242 (string= locking-user (vc-user-login-name)))
243 (if (or (eq (vc-checkout-model file) 'locking)
244 workfile-is-latest
245 (vc-rcs-latest-on-branch-p file workfile-version))
246 'edited
247 ;; Locking is not used for the file, but the owner does
248 ;; have a lock, and there is a higher version on the current
249 ;; branch. Not sure if this can occur, and if it is right
250 ;; to use `needs-merge' in this case.
251 'needs-merge))
252 ;; locked by somebody else
253 ((stringp locking-user)
254 locking-user)
255 (t
256 (error "Error getting state of RCS file")))))))
257
258 (defun vc-rcs-consult-headers (file)
259 "Search for RCS headers in FILE, and set properties accordingly.
260
261 Returns: nil if no headers were found
262 'rev if a workfile revision was found
263 'rev-and-lock if revision and lock info was found"
264 (cond
265 ((not (get-file-buffer file)) nil)
266 ((let (status version locking-user)
267 (save-excursion
268 (set-buffer (get-file-buffer file))
269 (goto-char (point-min))
270 (cond
271 ;; search for $Id or $Header
272 ;; -------------------------
273 ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file.
274 ((or (and (search-forward "$Id\ : " nil t)
275 (looking-at "[^ ]+ \\([0-9.]+\\) "))
276 (and (progn (goto-char (point-min))
277 (search-forward "$Header\ : " nil t))
278 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
279 (goto-char (match-end 0))
280 ;; if found, store the revision number ...
281 (setq version (match-string-no-properties 1))
282 ;; ... and check for the locking state
283 (cond
284 ((looking-at
285 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
286 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
287 "[^ ]+ [^ ]+ ")) ; author & state
288 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
289 (cond
290 ;; unlocked revision
291 ((looking-at "\\$")
292 (setq locking-user 'none)
293 (setq status 'rev-and-lock))
294 ;; revision is locked by some user
295 ((looking-at "\\([^ ]+\\) \\$")
296 (setq locking-user (match-string-no-properties 1))
297 (setq status 'rev-and-lock))
298 ;; everything else: false
299 (nil)))
300 ;; unexpected information in
301 ;; keyword string --> quit
302 (nil)))
303 ;; search for $Revision
304 ;; --------------------
305 ((re-search-forward (concat "\\$"
306 "Revision: \\([0-9.]+\\) \\$")
307 nil t)
308 ;; if found, store the revision number ...
309 (setq version (match-string-no-properties 1))
310 ;; and see if there's any lock information
311 (goto-char (point-min))
312 (if (re-search-forward (concat "\\$" "Locker:") nil t)
313 (cond ((looking-at " \\([^ ]+\\) \\$")
314 (setq locking-user (match-string-no-properties 1))
315 (setq status 'rev-and-lock))
316 ((looking-at " *\\$")
317 (setq locking-user 'none)
318 (setq status 'rev-and-lock))
319 (t
320 (setq locking-user 'none)
321 (setq status 'rev-and-lock)))
322 (setq status 'rev)))
323 ;; else: nothing found
324 ;; -------------------
325 (t nil)))
326 (if status (vc-file-setprop file 'vc-workfile-version version))
327 (and (eq status 'rev-and-lock)
328 (vc-file-setprop file 'vc-state
329 (cond
330 ((eq locking-user 'none) 'up-to-date)
331 ((string= locking-user (vc-user-login-name)) 'edited)
332 (t locking-user)))
333 ;; If the file has headers, we don't want to query the
334 ;; master file, because that would eliminate all the
335 ;; performance gain the headers brought us. We therefore
336 ;; use a heuristic now to find out whether locking is used
337 ;; for this file. If we trust the file permissions, and the
338 ;; file is not locked, then if the file is read-only we
339 ;; assume that locking is used for the file, otherwise
340 ;; locking is not used.
341 (not (vc-mistrust-permissions file))
342 (vc-up-to-date-p file)
343 (if (string-match ".r-..-..-." (nth 8 (file-attributes file)))
344 (vc-file-setprop file 'vc-checkout-model 'locking)
345 (vc-file-setprop file 'vc-checkout-model 'implicit)))
346 status))))
347
348 (defun vc-rcs-workfile-unchanged-p (file)
349 "RCS-specific implementation of vc-workfile-unchanged-p."
350 ;; Try to use rcsdiff --brief. If rcsdiff does not understand that,
351 ;; do a double take and remember the fact for the future
352 (let* ((version (concat "-r" (vc-workfile-version file)))
353 (status (if (eq vc-rcsdiff-knows-brief 'no)
354 (vc-do-command nil 1 "rcsdiff" file version)
355 (vc-do-command nil 2 "rcsdiff" file "--brief" version))))
356 (if (eq status 2)
357 (if (not vc-rcsdiff-knows-brief)
358 (setq vc-rcsdiff-knows-brief 'no
359 status (vc-do-command nil 1 "rcsdiff" file version))
360 (error "rcsdiff failed"))
361 (if (not vc-rcsdiff-knows-brief) (setq vc-rcsdiff-knows-brief 'yes)))
362 ;; The workfile is unchanged if rcsdiff found no differences.
363 (zerop status)))
364
365 (defun vc-rcs-trunk-p (rev)
366 "Return t if REV is an RCS revision on the trunk."
367 (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev))))
368
369 (defun vc-rcs-branch-part (rev)
370 "Return the branch part of an RCS revision number REV"
371 (substring rev 0 (string-match "\\.[0-9]+\\'" rev)))
372
373 (defun vc-rcs-latest-on-branch-p (file &optional version)
374 "Return non-nil if workfile version of FILE is the latest on its branch.
375 When VERSION is given, perform check for that version."
376 (unless version (setq version (vc-workfile-version file)))
377 (with-temp-buffer
378 (string= version
379 (if (vc-rcs-trunk-p version)
380 (progn
381 ;; Compare VERSION to the head version number.
382 (vc-insert-file (vc-name file) "^[0-9]")
383 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
384 ;; If we are not on the trunk, we need to examine the
385 ;; whole current branch.
386 (vc-insert-file (vc-name file) "^desc")
387 (vc-rcs-find-most-recent-rev (vc-rcs-branch-part version))))))
388 \f
389 (defun vc-rcs-branch-p (rev)
390 "Return t if REV is an RCS branch revision"
391 (not (eq nil (string-match "\\`[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*\\'" rev))))
392
393 (defun vc-rcs-minor-part (rev)
394 "Return the minor version number of an RCS revision number REV."
395 (string-match "[0-9]+\\'" rev)
396 (substring rev (match-beginning 0) (match-end 0)))
397
398 (defun vc-rcs-previous-version (rev)
399 "Guess the previous RCS version number"
400 (let ((branch (vc-rcs-branch-part rev))
401 (minor-num (string-to-number (vc-rcs-minor-part rev))))
402 (if (> minor-num 1)
403 ;; version does probably not start a branch or release
404 (concat branch "." (number-to-string (1- minor-num)))
405 (if (vc-rcs-trunk-p rev)
406 ;; we are at the beginning of the trunk --
407 ;; don't know anything to return here
408 ""
409 ;; we are at the beginning of a branch --
410 ;; return version of starting point
411 (vc-rcs-branch-part branch)))))
412
413 (defun vc-rcs-print-log (file)
414 "Get change log associated with FILE."
415 (vc-do-command t 0 "rlog" (vc-name file)))
416
417 (defun vc-rcs-show-log-entry (version)
418 (when (re-search-forward
419 ;; also match some context, for safety
420 (concat "----\nrevision " version
421 "\\(\tlocked by:.*\n\\|\n\\)date: ") nil t)
422 ;; set the display window so that
423 ;; the whole log entry is displayed
424 (let (start end lines)
425 (beginning-of-line) (forward-line -1) (setq start (point))
426 (if (not (re-search-forward "^----*\nrevision" nil t))
427 (setq end (point-max))
428 (beginning-of-line) (forward-line -1) (setq end (point)))
429 (setq lines (count-lines start end))
430 (cond
431 ;; if the global information and this log entry fit
432 ;; into the window, display from the beginning
433 ((< (count-lines (point-min) end) (window-height))
434 (goto-char (point-min))
435 (recenter 0)
436 (goto-char start))
437 ;; if the whole entry fits into the window,
438 ;; display it centered
439 ((< (1+ lines) (window-height))
440 (goto-char start)
441 (recenter (1- (- (/ (window-height) 2) (/ lines 2)))))
442 ;; otherwise (the entry is too large for the window),
443 ;; display from the start
444 (t
445 (goto-char start)
446 (recenter 0))))))
447
448 (defun vc-rcs-assign-name (file name)
449 "Assign to FILE's latest version a given NAME."
450 (vc-do-command nil 0 "rcs" (vc-name file) (concat "-n" name ":")))
451
452 (defun vc-rcs-merge (file first-version &optional second-version)
453 "Merge changes into current working copy of FILE.
454 The changes are between FIRST-VERSION and SECOND-VERSION."
455 (vc-do-command nil 1 "rcsmerge" (vc-name file)
456 "-kk" ; ignore keyword conflicts
457 (concat "-r" first-version)
458 (if second-version (concat "-r" second-version))))
459
460 (defun vc-rcs-check-headers ()
461 "Check if the current file has any headers in it."
462 (save-excursion
463 (goto-char (point-min))
464 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
465 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
466
467 (defun vc-rcs-clear-headers ()
468 "Implementation of vc-clear-headers for RCS."
469 (let ((case-fold-search nil))
470 (goto-char (point-min))
471 (while (re-search-forward
472 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
473 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
474 nil t)
475 (replace-match "$\\1$"))))
476
477 (defun vc-rcs-steal-lock (file &optional rev)
478 "Steal the lock on the current workfile for FILE and revision REV.
479 Needs RCS 5.6.2 or later for -M."
480 (vc-do-command nil 0 "rcs" (vc-name file) "-M"
481 (concat "-u" rev) (concat "-l" rev)))
482
483 (defun vc-rcs-cancel-version (file writable)
484 "Undo the most recent checkin of FILE.
485 WRITABLE non-nil means previous version should be locked."
486 (let* ((target (vc-workfile-version file))
487 (previous (if (vc-trunk-p target) "" (vc-branch-part target)))
488 (config (current-window-configuration))
489 (done nil))
490 (vc-do-command nil 0 "rcs" (vc-name file) (concat "-o" target))
491 ;; Check out the most recent remaining version. If it fails, because
492 ;; the whole branch got deleted, do a double-take and check out the
493 ;; version where the branch started.
494 (while (not done)
495 (condition-case err
496 (progn
497 (vc-do-command nil 0 "co" (vc-name file) "-f"
498 (concat (if writable "-l" "-u") previous))
499 (setq done t))
500 (error (set-buffer "*vc*")
501 (goto-char (point-min))
502 (if (search-forward "no side branches present for" nil t)
503 (progn (setq previous (vc-branch-part previous))
504 (vc-do-command nil 0 "rcs" (vc-name file)
505 (concat "-b" previous))
506 ;; vc-do-command popped up a window with
507 ;; the error message. Get rid of it, by
508 ;; restoring the old window configuration.
509 (set-window-configuration config))
510 ;; No, it was some other error: re-signal it.
511 (signal (car err) (cdr err))))))))
512
513 (defun vc-rcs-revert (file)
514 "Revert FILE to the version it was based on."
515 (vc-do-command nil 0 "co" (vc-name file) "-f"
516 (concat "-u" (vc-workfile-version file))))
517
518 (defun vc-rcs-rename-file (old new)
519 ;; Just move the master file (using vc-rcs-master-templates).
520 (vc-rename-master (vc-name old) new vc-rcs-master-templates))
521
522 (defun vc-release-greater-or-equal (r1 r2)
523 "Compare release numbers, represented as strings.
524 Release components are assumed cardinal numbers, not decimal fractions
525 \(5.10 is a higher release than 5.9\). Omitted fields are considered
526 lower \(5.6.7 is earlier than 5.6.7.1\). Comparison runs till the end
527 of the string is found, or a non-numeric component shows up \(5.6.7 is
528 earlier than \"5.6.7 beta\", which is probably not what you want in
529 some cases\). This code is suitable for existing RCS release numbers.
530 CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5\)."
531 (let (v1 v2 i1 i2)
532 (catch 'done
533 (or (and (string-match "^\\.?\\([0-9]+\\)" r1)
534 (setq i1 (match-end 0))
535 (setq v1 (string-to-number (match-string 1 r1)))
536 (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
537 (setq i2 (match-end 0))
538 (setq v2 (string-to-number (match-string 1 r2)))
539 (if (> v1 v2) (throw 'done t)
540 (if (< v1 v2) (throw 'done nil)
541 (throw 'done
542 (vc-release-greater-or-equal
543 (substring r1 i1)
544 (substring r2 i2)))))))
545 (throw 'done t)))
546 (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
547 (throw 'done nil))
548 (throw 'done t)))))
549
550 (defun vc-rcs-release-p (release)
551 "Return t if we have RELEASE or better."
552 (let ((installation (vc-rcs-system-release)))
553 (if (and installation
554 (not (eq installation 'unknown)))
555 (vc-release-greater-or-equal installation release))))
556
557 (defun vc-rcs-checkin (file rev comment)
558 "RCS-specific version of `vc-backend-checkin'."
559 (let ((switches (if (stringp vc-checkin-switches)
560 (list vc-checkin-switches)
561 vc-checkin-switches)))
562 (let ((old-version (vc-workfile-version file)) new-version)
563 (apply 'vc-do-command nil 0 "ci" (vc-name file)
564 ;; if available, use the secure check-in option
565 (and (vc-rcs-release-p "5.6.4") "-j")
566 (concat (if vc-keep-workfiles "-u" "-r") rev)
567 (concat "-m" comment)
568 switches)
569 (vc-file-setprop file 'vc-workfile-version nil)
570
571 ;; determine the new workfile version
572 (set-buffer "*vc*")
573 (goto-char (point-min))
574 (when (or (re-search-forward
575 "new revision: \\([0-9.]+\\);" nil t)
576 (re-search-forward
577 "reverting to previous revision \\([0-9.]+\\)" nil t))
578 (setq new-version (match-string 1))
579 (vc-file-setprop file 'vc-workfile-version new-version))
580
581 ;; if we got to a different branch, adjust the default
582 ;; branch accordingly
583 (cond
584 ((and old-version new-version
585 (not (string= (vc-rcs-branch-part old-version)
586 (vc-rcs-branch-part new-version))))
587 (vc-do-command nil 0 "rcs" (vc-name file)
588 (if (vc-rcs-trunk-p new-version) "-b"
589 (concat "-b" (vc-rcs-branch-part new-version))))
590 ;; If this is an old RCS release, we might have
591 ;; to remove a remaining lock.
592 (if (not (vc-rcs-release-p "5.6.2"))
593 ;; exit status of 1 is also accepted.
594 ;; It means that the lock was removed before.
595 (vc-do-command nil 1 "rcs" (vc-name file)
596 (concat "-u" old-version))))))))
597
598 (defun vc-rcs-system-release ()
599 "Return the RCS release installed on this system, as a string.
600 Return symbol UNKNOWN if the release cannot be deducted. The user can
601 override this using variable `vc-rcs-release'.
602
603 If the user has not set variable `vc-rcs-release' and it is nil,
604 variable `vc-rcs-release' is set to the returned value."
605 (or vc-rcs-release
606 (setq vc-rcs-release
607 (or (and (zerop (vc-do-command nil nil "rcs" nil "-V"))
608 (with-current-buffer (get-buffer "*vc*")
609 (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1)))
610 'unknown))))
611
612 (defun vc-rcs-diff (file &optional oldvers newvers)
613 "Get a difference report using RCS between two versions of FILE."
614 (if (not oldvers) (setq oldvers (vc-workfile-version file)))
615 ;; If we know that --brief is not supported, don't try it.
616 (let* ((diff-switches-list (if (listp diff-switches)
617 diff-switches
618 (list diff-switches)))
619 (options (append (list "-q"
620 (concat "-r" oldvers)
621 (and newvers (concat "-r" newvers)))
622 diff-switches-list)))
623 (apply 'vc-do-command t 1 "rcsdiff" file options)))
624
625 (defun vc-rcs-responsible-p (file)
626 "Return non-nil if RCS thinks it would be responsible for registering FILE."
627 ;; TODO: check for all the patterns in vc-rcs-master-templates
628 (file-directory-p (expand-file-name "RCS" (file-name-directory file))))
629
630 (defun vc-rcs-register (file &optional rev comment)
631 "Register FILE into the RCS version-control system.
632 REV is the optional revision number for the file. COMMENT can be used
633 to provide an initial description of FILE.
634
635 `vc-register-switches' and `vc-rcs-register-switches' are passed to
636 the RCS command (in that order).
637
638 Automatically retrieve a read-only version of the file with keywords
639 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
640 (let ((subdir (expand-file-name "RCS" (file-name-directory file)))
641 (switches (list
642 (if (stringp vc-register-switches)
643 (list vc-register-switches)
644 vc-register-switches)
645 (if (stringp vc-rcs-register-switches)
646 (list vc-rcs-register-switches)
647 vc-rcs-register-switches))))
648
649 (and (not (file-exists-p subdir))
650 (not (directory-files (file-name-directory file)
651 nil ".*,v$" t))
652 (yes-or-no-p "Create RCS subdirectory? ")
653 (make-directory subdir))
654 (apply 'vc-do-command nil 0 "ci" file
655 ;; if available, use the secure registering option
656 (and (vc-rcs-release-p "5.6.4") "-i")
657 (concat (if vc-keep-workfiles "-u" "-r") rev)
658 (and comment (concat "-t-" comment))
659 switches)
660 ;; parse output to find master file name and workfile version
661 (with-current-buffer "*vc*"
662 (goto-char (point-min))
663 (let ((name (if (looking-at (concat "^\\(.*\\) <-- "
664 (file-name-nondirectory file)))
665 (match-string 1))))
666 (if (not name)
667 ;; if we couldn't find the master name,
668 ;; run vc-rcs-registered to get it
669 ;; (will be stored into the vc-name property)
670 (vc-rcs-registered file)
671 (vc-file-setprop file 'vc-name
672 (if (file-name-absolute-p name)
673 name
674 (expand-file-name
675 name
676 (file-name-directory file))))))
677 (vc-file-setprop file 'vc-workfile-version
678 (if (re-search-forward
679 "^initial revision: \\([0-9.]+\\).*\n"
680 nil t)
681 (match-string 1))))))
682
683 (defun vc-rcs-checkout (file &optional writable rev workfile)
684 "Retrieve a copy of a saved version of FILE into a workfile."
685 (let ((filename (or workfile file))
686 (file-buffer (get-file-buffer file))
687 switches)
688 (message "Checking out %s..." filename)
689 (save-excursion
690 ;; Change buffers to get local value of vc-checkout-switches.
691 (if file-buffer (set-buffer file-buffer))
692 (setq switches (if (stringp vc-checkout-switches)
693 (list vc-checkout-switches)
694 vc-checkout-switches))
695 ;; Save this buffer's default-directory
696 ;; and use save-excursion to make sure it is restored
697 ;; in the same buffer it was saved in.
698 (let ((default-directory default-directory))
699 (save-excursion
700 ;; Adjust the default-directory so that the check-out creates
701 ;; the file in the right place.
702 (setq default-directory (file-name-directory filename))
703 (if workfile ;; RCS
704 ;; RCS can't check out into arbitrary file names directly.
705 ;; Use `co -p' and make stdout point to the correct file.
706 (let ((vc-modes (logior (file-modes (vc-name file))
707 (if writable 128 0)))
708 (failed t))
709 (unwind-protect
710 (progn
711 (let ((coding-system-for-read 'no-conversion)
712 (coding-system-for-write 'no-conversion))
713 (with-temp-file filename
714 (apply 'vc-do-command
715 (current-buffer) 0 "co" (vc-name file)
716 "-q" ;; suppress diagnostic output
717 (if writable "-l")
718 (concat "-p" rev)
719 switches)))
720 (set-file-modes filename
721 (logior (file-modes (vc-name file))
722 (if writable 128 0)))
723 (setq failed nil))
724 (and failed (file-exists-p filename)
725 (delete-file filename))))
726 (let (new-version)
727 ;; if we should go to the head of the trunk,
728 ;; clear the default branch first
729 (and rev (string= rev "")
730 (vc-do-command nil 0 "rcs" (vc-name file) "-b"))
731 ;; now do the checkout
732 (apply 'vc-do-command
733 nil 0 "co" (vc-name file)
734 ;; If locking is not strict, force to overwrite
735 ;; the writable workfile.
736 (if (eq (vc-checkout-model file) 'implicit) "-f")
737 (if writable "-l")
738 (if rev (concat "-r" rev)
739 ;; if no explicit revision was specified,
740 ;; check out that of the working file
741 (let ((workrev (vc-workfile-version file)))
742 (if workrev (concat "-r" workrev)
743 nil)))
744 switches)
745 ;; determine the new workfile version
746 (with-current-buffer "*vc*"
747 (setq new-version
748 (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1)))
749 (vc-file-setprop file 'vc-workfile-version new-version)
750 ;; if necessary, adjust the default branch
751 (and rev (not (string= rev ""))
752 (vc-do-command
753 nil 0 "rcs" (vc-name file)
754 (concat "-b"
755 (if (vc-rcs-latest-on-branch-p file new-version)
756 (if (vc-rcs-trunk-p new-version) nil
757 (vc-rcs-branch-part new-version))
758 new-version)))))))
759 (message "Checking out %s...done" filename)))))
760
761 (provide 'vc-rcs)
762
763 ;;; vc-rcs.el ends here