(setwins_almost): Renamed from finder_setwins.
[emacs.git] / lisp / vc-rcs.el
blob290d59687aceccd9e4769b1888381c9c75af807e
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.30 2002/11/12 19:46:47 rost 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)
15 ;; any later version.
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:
29 ;; See vc.el
31 ;;; Code:
33 ;;;
34 ;;; Customization options
35 ;;;
37 (eval-when-compile
38 (require 'cl)
39 (require 'vc))
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))
47 :group 'vc)
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"
56 :value ("")
57 string))
58 :version "21.1"
59 :group 'vc)
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"
66 :value ("")
67 string))
68 :version "21.1"
69 :group 'vc)
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)
74 :version "21.1"
75 :group 'vc)
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))
82 :group 'vc)
84 ;;;###autoload
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"
92 (choice string
93 function)))
94 :version "21.1"
95 :group 'vc)
98 ;;;
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)))
115 (let ((state
116 ;; vc-workfile-version might not be known; in that case the
117 ;; property is nil. vc-rcs-fetch-master-state knows how to
118 ;; handle that.
119 (vc-rcs-fetch-master-state file
120 (vc-file-getprop file
121 'vc-workfile-version))))
122 (if (not (eq state 'up-to-date))
123 state
124 (if (vc-workfile-unchanged-p file)
125 'up-to-date
126 (if (eq (vc-checkout-model file) 'locking)
127 'unlocked-changes
128 'edited)))))
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
140 ;; the file or not.
141 (if (and (eq state 'up-to-date)
142 (not (vc-mistrust-permissions file)))
143 (cond
144 ((string-match ".rw..-..-." (nth 8 (file-attributes file)))
145 (vc-file-setprop file 'vc-checkout-model 'implicit)
146 (setq state
147 (if (vc-rcs-workfile-is-newer file)
148 'edited
149 'up-to-date)))
150 ((string-match ".r-..-..-." (nth 8 (file-attributes file)))
151 (vc-file-setprop file 'vc-checkout-model 'locking))))
152 state)
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)
159 'up-to-date)
160 ((string-match ".rw..-..-." permissions)
161 (if (eq (vc-checkout-model file) 'locking)
162 (if (file-ownership-preserved-p file)
163 'edited
164 (vc-user-login-name owner-uid))
165 (if (vc-rcs-workfile-is-newer file)
166 'edited
167 'up-to-date)))
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))
179 (progn
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)))
187 (with-temp-buffer
188 (string= version
189 (if (vc-trunk-p version)
190 (progn
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))))
214 (if (eq status 2)
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.
221 (zerop status)))
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)))
239 (switches (append
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)
249 nil ".*,v$" t))
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))
257 switches)
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)))
263 (match-string 1))))
264 (if (not name)
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)
271 name
272 (expand-file-name
273 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"
278 nil t)
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)
302 (delete-file master)
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.
322 (and (not rev)
323 default-branch
324 (string-match (concat "^" (regexp-quote old-version) "\\.")
325 default-branch)
326 (setq rev default-branch)
327 (setq switches (cons "-f" switches)))
328 (apply 'vc-do-command nil 0 "ci" (vc-name file)
329 ;; if available, use the secure check-in option
330 (and (vc-rcs-release-p "5.6.4") "-j")
331 (concat (if vc-keep-workfiles "-u" "-r") rev)
332 (concat "-m" comment)
333 switches)
334 (vc-file-setprop file 'vc-workfile-version nil)
336 ;; determine the new workfile version
337 (set-buffer "*vc*")
338 (goto-char (point-min))
339 (when (or (re-search-forward
340 "new revision: \\([0-9.]+\\);" nil t)
341 (re-search-forward
342 "reverting to previous revision \\([0-9.]+\\)" nil t))
343 (setq new-version (match-string 1))
344 (vc-file-setprop file 'vc-workfile-version new-version))
346 ;; if we got to a different branch, adjust the default
347 ;; branch accordingly
348 (cond
349 ((and old-version new-version
350 (not (string= (vc-branch-part old-version)
351 (vc-branch-part new-version))))
352 (vc-rcs-set-default-branch file
353 (if (vc-trunk-p new-version) nil
354 (vc-branch-part new-version)))
355 ;; If this is an old RCS release, we might have
356 ;; to remove a remaining lock.
357 (if (not (vc-rcs-release-p "5.6.2"))
358 ;; exit status of 1 is also accepted.
359 ;; It means that the lock was removed before.
360 (vc-do-command nil 1 "rcs" (vc-name file)
361 (concat "-u" old-version))))))))
363 (defun vc-rcs-find-version (file rev buffer)
364 (apply 'vc-do-command
365 buffer 0 "co" (vc-name file)
366 "-q" ;; suppress diagnostic output
367 (concat "-p" rev)
368 (if (stringp vc-checkout-switches)
369 (list vc-checkout-switches)
370 vc-checkout-switches)))
372 (defun vc-rcs-checkout (file &optional editable rev)
373 "Retrieve a copy of a saved version of FILE."
374 (let ((file-buffer (get-file-buffer file))
375 switches)
376 (message "Checking out %s..." file)
377 (save-excursion
378 ;; Change buffers to get local value of vc-checkout-switches.
379 (if file-buffer (set-buffer file-buffer))
380 (setq switches (if (stringp vc-checkout-switches)
381 (list vc-checkout-switches)
382 vc-checkout-switches))
383 ;; Save this buffer's default-directory
384 ;; and use save-excursion to make sure it is restored
385 ;; in the same buffer it was saved in.
386 (let ((default-directory default-directory))
387 (save-excursion
388 ;; Adjust the default-directory so that the check-out creates
389 ;; the file in the right place.
390 (setq default-directory (file-name-directory file))
391 (let (new-version)
392 ;; if we should go to the head of the trunk,
393 ;; clear the default branch first
394 (and rev (string= rev "")
395 (vc-rcs-set-default-branch file nil))
396 ;; now do the checkout
397 (apply 'vc-do-command
398 nil 0 "co" (vc-name file)
399 ;; If locking is not strict, force to overwrite
400 ;; the writable workfile.
401 (if (eq (vc-checkout-model file) 'implicit) "-f")
402 (if editable "-l")
403 (if rev (concat "-r" rev)
404 ;; if no explicit revision was specified,
405 ;; check out that of the working file
406 (let ((workrev (vc-workfile-version file)))
407 (if workrev (concat "-r" workrev)
408 nil)))
409 switches)
410 ;; determine the new workfile version
411 (with-current-buffer "*vc*"
412 (setq new-version
413 (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1)))
414 (vc-file-setprop file 'vc-workfile-version new-version)
415 ;; if necessary, adjust the default branch
416 (and rev (not (string= rev ""))
417 (vc-rcs-set-default-branch
418 file
419 (if (vc-rcs-latest-on-branch-p file new-version)
420 (if (vc-trunk-p new-version) nil
421 (vc-branch-part new-version))
422 new-version)))))
423 (message "Checking out %s...done" file)))))
425 (defun vc-rcs-revert (file &optional contents-done)
426 "Revert FILE to the version it was based on."
427 (vc-do-command nil 0 "co" (vc-name file) "-f"
428 (concat "-u" (vc-workfile-version file))))
430 (defun vc-rcs-cancel-version (file editable)
431 "Undo the most recent checkin of FILE.
432 EDITABLE non-nil means previous version should be locked."
433 (let* ((target (vc-workfile-version file))
434 (previous (if (vc-trunk-p target) "" (vc-branch-part target)))
435 (config (current-window-configuration))
436 (done nil))
437 (vc-do-command nil 0 "rcs" (vc-name file) (concat "-o" target))
438 ;; Check out the most recent remaining version. If it fails, because
439 ;; the whole branch got deleted, do a double-take and check out the
440 ;; version where the branch started.
441 (while (not done)
442 (condition-case err
443 (progn
444 (vc-do-command nil 0 "co" (vc-name file) "-f"
445 (concat (if editable "-l" "-u") previous))
446 (setq done t))
447 (error (set-buffer "*vc*")
448 (goto-char (point-min))
449 (if (search-forward "no side branches present for" nil t)
450 (progn (setq previous (vc-branch-part previous))
451 (vc-rcs-set-default-branch file previous)
452 ;; vc-do-command popped up a window with
453 ;; the error message. Get rid of it, by
454 ;; restoring the old window configuration.
455 (set-window-configuration config))
456 ;; No, it was some other error: re-signal it.
457 (signal (car err) (cdr err))))))))
459 (defun vc-rcs-merge (file first-version &optional second-version)
460 "Merge changes into current working copy of FILE.
461 The changes are between FIRST-VERSION and SECOND-VERSION."
462 (vc-do-command nil 1 "rcsmerge" (vc-name file)
463 "-kk" ; ignore keyword conflicts
464 (concat "-r" first-version)
465 (if second-version (concat "-r" second-version))))
467 (defun vc-rcs-steal-lock (file &optional rev)
468 "Steal the lock on the current workfile for FILE and revision REV.
469 Needs RCS 5.6.2 or later for -M."
470 (vc-do-command nil 0 "rcs" (vc-name file) "-M" (concat "-u" rev))
471 ;; Do a real checkout after stealing the lock, so that we see
472 ;; expanded headers.
473 (vc-do-command nil 0 "co" (vc-name file) "-f" (concat "-l" rev)))
478 ;;; History functions
481 (defun vc-rcs-print-log (file)
482 "Get change log associated with FILE."
483 (vc-do-command nil 0 "rlog" (vc-name file)))
485 (defun vc-rcs-diff (file &optional oldvers newvers)
486 "Get a difference report using RCS between two versions of FILE."
487 (if (not oldvers) (setq oldvers (vc-workfile-version file)))
488 (apply 'vc-do-command "*vc-diff*" 1 "rcsdiff" file
489 (append (list "-q"
490 (concat "-r" oldvers)
491 (and newvers (concat "-r" newvers)))
492 (vc-diff-switches-list 'RCS))))
496 ;;; Snapshot system
499 (defun vc-rcs-assign-name (file name)
500 "Assign to FILE's latest version a given NAME."
501 (vc-do-command nil 0 "rcs" (vc-name file) (concat "-n" name ":")))
505 ;;; Miscellaneous
508 (defun vc-rcs-check-headers ()
509 "Check if the current file has any headers in it."
510 (save-excursion
511 (goto-char (point-min))
512 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
513 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
515 (defun vc-rcs-clear-headers ()
516 "Implementation of vc-clear-headers for RCS."
517 (let ((case-fold-search nil))
518 (goto-char (point-min))
519 (while (re-search-forward
520 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
521 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
522 nil t)
523 (replace-match "$\\1$"))))
525 (defun vc-rcs-rename-file (old new)
526 ;; Just move the master file (using vc-rcs-master-templates).
527 (vc-rename-master (vc-name old) new vc-rcs-master-templates))
531 ;;; Internal functions
534 (defun vc-rcs-workfile-is-newer (file)
535 "Return non-nil if FILE is newer than its RCS master.
536 This likely means that FILE has been changed with respect
537 to its master version."
538 (let ((file-time (nth 5 (file-attributes file)))
539 (master-time (nth 5 (file-attributes (vc-name file)))))
540 (or (> (nth 0 file-time) (nth 0 master-time))
541 (and (= (nth 0 file-time) (nth 0 master-time))
542 (> (nth 1 file-time) (nth 1 master-time))))))
544 (defun vc-rcs-find-most-recent-rev (branch)
545 "Find most recent revision on BRANCH."
546 (goto-char (point-min))
547 (let ((latest-rev -1) value)
548 (while (re-search-forward (concat "^\\(" (regexp-quote branch)
549 "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;")
550 nil t)
551 (let ((rev (string-to-number (match-string 2))))
552 (when (< latest-rev rev)
553 (setq latest-rev rev)
554 (setq value (match-string 1)))))
555 (or value
556 (vc-branch-part branch))))
558 (defun vc-rcs-fetch-master-state (file &optional workfile-version)
559 "Compute the master file's idea of the state of FILE.
560 If a WORKFILE-VERSION is given, compute the state of that version,
561 otherwise determine the workfile version based on the master file.
562 This function sets the properties `vc-workfile-version' and
563 `vc-checkout-model' to their correct values, based on the master
564 file."
565 (with-temp-buffer
566 (if (or (not (vc-insert-file (vc-name file) "^[0-9]"))
567 (progn (goto-char (point-min))
568 (not (looking-at "^head[ \t\n]+[^;]+;$"))))
569 (error "File %s is not an RCS master file" (vc-name file)))
570 (let ((workfile-is-latest nil)
571 (default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1)))
572 (vc-file-setprop file 'vc-rcs-default-branch default-branch)
573 (unless workfile-version
574 ;; Workfile version not known yet. Determine that first. It
575 ;; is either the head of the trunk, the head of the default
576 ;; branch, or the "default branch" itself, if that is a full
577 ;; revision number.
578 (cond
579 ;; no default branch
580 ((or (not default-branch) (string= "" default-branch))
581 (setq workfile-version
582 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
583 (setq workfile-is-latest t))
584 ;; default branch is actually a revision
585 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
586 default-branch)
587 (setq workfile-version default-branch))
588 ;; else, search for the head of the default branch
589 (t (vc-insert-file (vc-name file) "^desc")
590 (setq workfile-version
591 (vc-rcs-find-most-recent-rev default-branch))
592 (setq workfile-is-latest t)))
593 (vc-file-setprop file 'vc-workfile-version workfile-version))
594 ;; Check strict locking
595 (goto-char (point-min))
596 (vc-file-setprop file 'vc-checkout-model
597 (if (re-search-forward ";[ \t\n]*strict;" nil t)
598 'locking 'implicit))
599 ;; Compute state of workfile version
600 (goto-char (point-min))
601 (let ((locking-user
602 (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):"
603 (regexp-quote workfile-version)
604 "[^0-9.]")
605 1)))
606 (cond
607 ;; not locked
608 ((not locking-user)
609 (if (or workfile-is-latest
610 (vc-rcs-latest-on-branch-p file workfile-version))
611 ;; workfile version is latest on branch
612 'up-to-date
613 ;; workfile version is not latest on branch
614 'needs-patch))
615 ;; locked by the calling user
616 ((and (stringp locking-user)
617 (string= locking-user (vc-user-login-name)))
618 (if (or (eq (vc-checkout-model file) 'locking)
619 workfile-is-latest
620 (vc-rcs-latest-on-branch-p file workfile-version))
621 'edited
622 ;; Locking is not used for the file, but the owner does
623 ;; have a lock, and there is a higher version on the current
624 ;; branch. Not sure if this can occur, and if it is right
625 ;; to use `needs-merge' in this case.
626 'needs-merge))
627 ;; locked by somebody else
628 ((stringp locking-user)
629 locking-user)
631 (error "Error getting state of RCS file")))))))
633 (defun vc-rcs-consult-headers (file)
634 "Search for RCS headers in FILE, and set properties accordingly.
636 Returns: nil if no headers were found
637 'rev if a workfile revision was found
638 'rev-and-lock if revision and lock info was found"
639 (cond
640 ((not (get-file-buffer file)) nil)
641 ((let (status version locking-user)
642 (save-excursion
643 (set-buffer (get-file-buffer file))
644 (goto-char (point-min))
645 (cond
646 ;; search for $Id or $Header
647 ;; -------------------------
648 ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file.
649 ((or (and (search-forward "$Id\ : " nil t)
650 (looking-at "[^ ]+ \\([0-9.]+\\) "))
651 (and (progn (goto-char (point-min))
652 (search-forward "$Header\ : " nil t))
653 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
654 (goto-char (match-end 0))
655 ;; if found, store the revision number ...
656 (setq version (match-string-no-properties 1))
657 ;; ... and check for the locking state
658 (cond
659 ((looking-at
660 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
661 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
662 "[^ ]+ [^ ]+ ")) ; author & state
663 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
664 (cond
665 ;; unlocked revision
666 ((looking-at "\\$")
667 (setq locking-user 'none)
668 (setq status 'rev-and-lock))
669 ;; revision is locked by some user
670 ((looking-at "\\([^ ]+\\) \\$")
671 (setq locking-user (match-string-no-properties 1))
672 (setq status 'rev-and-lock))
673 ;; everything else: false
674 (nil)))
675 ;; unexpected information in
676 ;; keyword string --> quit
677 (nil)))
678 ;; search for $Revision
679 ;; --------------------
680 ((re-search-forward (concat "\\$"
681 "Revision: \\([0-9.]+\\) \\$")
682 nil t)
683 ;; if found, store the revision number ...
684 (setq version (match-string-no-properties 1))
685 ;; and see if there's any lock information
686 (goto-char (point-min))
687 (if (re-search-forward (concat "\\$" "Locker:") nil t)
688 (cond ((looking-at " \\([^ ]+\\) \\$")
689 (setq locking-user (match-string-no-properties 1))
690 (setq status 'rev-and-lock))
691 ((looking-at " *\\$")
692 (setq locking-user 'none)
693 (setq status 'rev-and-lock))
695 (setq locking-user 'none)
696 (setq status 'rev-and-lock)))
697 (setq status 'rev)))
698 ;; else: nothing found
699 ;; -------------------
700 (t nil)))
701 (if status (vc-file-setprop file 'vc-workfile-version version))
702 (and (eq status 'rev-and-lock)
703 (vc-file-setprop file 'vc-state
704 (cond
705 ((eq locking-user 'none) 'up-to-date)
706 ((string= locking-user (vc-user-login-name)) 'edited)
707 (t locking-user)))
708 ;; If the file has headers, we don't want to query the
709 ;; master file, because that would eliminate all the
710 ;; performance gain the headers brought us. We therefore
711 ;; use a heuristic now to find out whether locking is used
712 ;; for this file. If we trust the file permissions, and the
713 ;; file is not locked, then if the file is read-only we
714 ;; assume that locking is used for the file, otherwise
715 ;; locking is not used.
716 (not (vc-mistrust-permissions file))
717 (vc-up-to-date-p file)
718 (if (string-match ".r-..-..-." (nth 8 (file-attributes file)))
719 (vc-file-setprop file 'vc-checkout-model 'locking)
720 (vc-file-setprop file 'vc-checkout-model 'implicit)))
721 status))))
723 (defun vc-release-greater-or-equal (r1 r2)
724 "Compare release numbers, represented as strings.
725 Release components are assumed cardinal numbers, not decimal fractions
726 \(5.10 is a higher release than 5.9\). Omitted fields are considered
727 lower \(5.6.7 is earlier than 5.6.7.1\). Comparison runs till the end
728 of the string is found, or a non-numeric component shows up \(5.6.7 is
729 earlier than \"5.6.7 beta\", which is probably not what you want in
730 some cases\). This code is suitable for existing RCS release numbers.
731 CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5\)."
732 (let (v1 v2 i1 i2)
733 (catch 'done
734 (or (and (string-match "^\\.?\\([0-9]+\\)" r1)
735 (setq i1 (match-end 0))
736 (setq v1 (string-to-number (match-string 1 r1)))
737 (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
738 (setq i2 (match-end 0))
739 (setq v2 (string-to-number (match-string 1 r2)))
740 (if (> v1 v2) (throw 'done t)
741 (if (< v1 v2) (throw 'done nil)
742 (throw 'done
743 (vc-release-greater-or-equal
744 (substring r1 i1)
745 (substring r2 i2)))))))
746 (throw 'done t)))
747 (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
748 (throw 'done nil))
749 (throw 'done t)))))
751 (defun vc-rcs-release-p (release)
752 "Return t if we have RELEASE or better."
753 (let ((installation (vc-rcs-system-release)))
754 (if (and installation
755 (not (eq installation 'unknown)))
756 (vc-release-greater-or-equal installation release))))
759 (defun vc-rcs-system-release ()
760 "Return the RCS release installed on this system, as a string.
761 Return symbol UNKNOWN if the release cannot be deducted. The user can
762 override this using variable `vc-rcs-release'.
764 If the user has not set variable `vc-rcs-release' and it is nil,
765 variable `vc-rcs-release' is set to the returned value."
766 (or vc-rcs-release
767 (setq vc-rcs-release
768 (or (and (zerop (vc-do-command nil nil "rcs" nil "-V"))
769 (with-current-buffer (get-buffer "*vc*")
770 (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1)))
771 'unknown))))
773 (defun vc-rcs-set-non-strict-locking (file)
774 (vc-do-command nil 0 "rcs" file "-U")
775 (vc-file-setprop file 'vc-checkout-model 'implicit)
776 (set-file-modes file (logior (file-modes file) 128)))
778 (defun vc-rcs-set-default-branch (file branch)
779 (vc-do-command nil 0 "rcs" (vc-name file) (concat "-b" branch))
780 (vc-file-setprop file 'vc-rcs-default-branch branch))
782 (provide 'vc-rcs)
784 ;;; vc-rcs.el ends here