(Input Focus): Add documentation for `select-frame-set-input-focus'.
[emacs.git] / lisp / vc-rcs.el
blobca2958756a40718f05a9d4a3e65078c3a785e59e
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.39 2004/03/21 15:46:23 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)
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 (let (result)
202 (when vc-consult-headers
203 (vc-file-setprop file 'vc-checkout-model nil)
204 (vc-rcs-consult-headers file)
205 (setq result (vc-file-getprop file 'vc-checkout-model)))
206 (or result
207 (progn (vc-rcs-fetch-master-state file)
208 (vc-file-getprop file 'vc-checkout-model)))))
210 (defun vc-rcs-workfile-unchanged-p (file)
211 "RCS-specific implementation of vc-workfile-unchanged-p."
212 ;; Try to use rcsdiff --brief. If rcsdiff does not understand that,
213 ;; do a double take and remember the fact for the future
214 (let* ((version (concat "-r" (vc-workfile-version file)))
215 (status (if (eq vc-rcsdiff-knows-brief 'no)
216 (vc-do-command nil 1 "rcsdiff" file version)
217 (vc-do-command nil 2 "rcsdiff" file "--brief" version))))
218 (if (eq status 2)
219 (if (not vc-rcsdiff-knows-brief)
220 (setq vc-rcsdiff-knows-brief 'no
221 status (vc-do-command nil 1 "rcsdiff" file version))
222 (error "rcsdiff failed"))
223 (if (not vc-rcsdiff-knows-brief) (setq vc-rcsdiff-knows-brief 'yes)))
224 ;; The workfile is unchanged if rcsdiff found no differences.
225 (zerop status)))
229 ;;; State-changing functions
232 (defun vc-rcs-register (file &optional rev comment)
233 "Register FILE into the RCS version-control system.
234 REV is the optional revision number for the file. COMMENT can be used
235 to provide an initial description of FILE.
237 `vc-register-switches' and `vc-rcs-register-switches' are passed to
238 the RCS command (in that order).
240 Automatically retrieve a read-only version of the file with keywords
241 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
242 (let ((subdir (expand-file-name "RCS" (file-name-directory file))))
243 (and (not (file-exists-p subdir))
244 (not (directory-files (file-name-directory file)
245 nil ".*,v$" t))
246 (yes-or-no-p "Create RCS subdirectory? ")
247 (make-directory subdir))
248 (apply 'vc-do-command nil 0 "ci" file
249 ;; if available, use the secure registering option
250 (and (vc-rcs-release-p "5.6.4") "-i")
251 (concat (if vc-keep-workfiles "-u" "-r") rev)
252 (and comment (concat "-t-" comment))
253 (vc-switches 'RCS 'register))
254 ;; parse output to find master file name and workfile version
255 (with-current-buffer "*vc*"
256 (goto-char (point-min))
257 (let ((name (if (looking-at (concat "^\\(.*\\) <-- "
258 (file-name-nondirectory file)))
259 (match-string 1))))
260 (if (not name)
261 ;; if we couldn't find the master name,
262 ;; run vc-rcs-registered to get it
263 ;; (will be stored into the vc-name property)
264 (vc-rcs-registered file)
265 (vc-file-setprop file 'vc-name
266 (if (file-name-absolute-p name)
267 name
268 (expand-file-name
269 name
270 (file-name-directory file))))))
271 (vc-file-setprop file 'vc-workfile-version
272 (if (re-search-forward
273 "^initial revision: \\([0-9.]+\\).*\n"
274 nil t)
275 (match-string 1))))))
277 (defun vc-rcs-responsible-p (file)
278 "Return non-nil if RCS thinks it would be responsible for registering FILE."
279 ;; TODO: check for all the patterns in vc-rcs-master-templates
280 (file-directory-p (expand-file-name "RCS" (file-name-directory file))))
282 (defun vc-rcs-receive-file (file rev)
283 "Implementation of receive-file for RCS."
284 (let ((checkout-model (vc-checkout-model file)))
285 (vc-rcs-register file rev "")
286 (when (eq checkout-model 'implicit)
287 (vc-rcs-set-non-strict-locking file))
288 (vc-rcs-set-default-branch file (concat rev ".1"))))
290 (defun vc-rcs-unregister (file)
291 "Unregister FILE from RCS.
292 If this leaves the RCS subdirectory empty, ask the user
293 whether to remove it."
294 (let* ((master (vc-name file))
295 (dir (file-name-directory master))
296 (backup-info (find-backup-file-name master)))
297 (if (not backup-info)
298 (delete-file master)
299 (rename-file master (car backup-info) 'ok-if-already-exists)
300 (dolist (f (cdr backup-info)) (ignore-errors (delete-file f))))
301 (and (string= (file-name-nondirectory (directory-file-name dir)) "RCS")
302 ;; check whether RCS dir is empty, i.e. it does not
303 ;; contain any files except "." and ".."
304 (not (directory-files dir nil
305 "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*"))
306 (yes-or-no-p (format "Directory %s is empty; remove it? " dir))
307 (delete-directory dir))))
309 (defun vc-rcs-checkin (file rev comment)
310 "RCS-specific version of `vc-backend-checkin'."
311 (let ((switches (vc-switches 'RCS 'checkin)))
312 (let ((old-version (vc-workfile-version file)) new-version
313 (default-branch (vc-file-getprop file 'vc-rcs-default-branch)))
314 ;; Force branch creation if an appropriate
315 ;; default branch has been set.
316 (and (not rev)
317 default-branch
318 (string-match (concat "^" (regexp-quote old-version) "\\.")
319 default-branch)
320 (setq rev default-branch)
321 (setq switches (cons "-f" switches)))
322 (if (and (not rev) old-version)
323 (setq rev (vc-branch-part old-version)))
324 (apply 'vc-do-command nil 0 "ci" (vc-name file)
325 ;; if available, use the secure check-in option
326 (and (vc-rcs-release-p "5.6.4") "-j")
327 (concat (if vc-keep-workfiles "-u" "-r") rev)
328 (concat "-m" comment)
329 switches)
330 (vc-file-setprop file 'vc-workfile-version nil)
332 ;; determine the new workfile version
333 (set-buffer "*vc*")
334 (goto-char (point-min))
335 (when (or (re-search-forward
336 "new revision: \\([0-9.]+\\);" nil t)
337 (re-search-forward
338 "reverting to previous revision \\([0-9.]+\\)" nil t))
339 (setq new-version (match-string 1))
340 (vc-file-setprop file 'vc-workfile-version new-version))
342 ;; if we got to a different branch, adjust the default
343 ;; branch accordingly
344 (cond
345 ((and old-version new-version
346 (not (string= (vc-branch-part old-version)
347 (vc-branch-part new-version))))
348 (vc-rcs-set-default-branch file
349 (if (vc-trunk-p new-version) nil
350 (vc-branch-part new-version)))
351 ;; If this is an old RCS release, we might have
352 ;; to remove a remaining lock.
353 (if (not (vc-rcs-release-p "5.6.2"))
354 ;; exit status of 1 is also accepted.
355 ;; It means that the lock was removed before.
356 (vc-do-command nil 1 "rcs" (vc-name file)
357 (concat "-u" old-version))))))))
359 (defun vc-rcs-find-version (file rev buffer)
360 (apply 'vc-do-command
361 buffer 0 "co" (vc-name file)
362 "-q" ;; suppress diagnostic output
363 (concat "-p" rev)
364 (vc-switches 'RCS 'checkout)))
366 (defun vc-rcs-checkout (file &optional editable rev)
367 "Retrieve a copy of a saved version of FILE."
368 (let ((file-buffer (get-file-buffer file))
369 switches)
370 (message "Checking out %s..." file)
371 (save-excursion
372 ;; Change buffers to get local value of vc-checkout-switches.
373 (if file-buffer (set-buffer file-buffer))
374 (setq switches (vc-switches 'RCS 'checkout))
375 ;; Save this buffer's default-directory
376 ;; and use save-excursion to make sure it is restored
377 ;; in the same buffer it was saved in.
378 (let ((default-directory default-directory))
379 (save-excursion
380 ;; Adjust the default-directory so that the check-out creates
381 ;; the file in the right place.
382 (setq default-directory (file-name-directory file))
383 (let (new-version)
384 ;; if we should go to the head of the trunk,
385 ;; clear the default branch first
386 (and rev (string= rev "")
387 (vc-rcs-set-default-branch file nil))
388 ;; now do the checkout
389 (apply 'vc-do-command
390 nil 0 "co" (vc-name file)
391 ;; If locking is not strict, force to overwrite
392 ;; the writable workfile.
393 (if (eq (vc-checkout-model file) 'implicit) "-f")
394 (if editable "-l")
395 (if (stringp rev)
396 ;; a literal revision was specified
397 (concat "-r" rev)
398 (let ((workrev (vc-workfile-version file)))
399 (if workrev
400 (concat "-r"
401 (if (not rev)
402 ;; no revision specified:
403 ;; use current workfile version
404 workrev
405 ;; REV is t ...
406 (if (not (vc-trunk-p workrev))
407 ;; ... go to head of current branch
408 (vc-branch-part workrev)
409 ;; ... go to head of trunk
410 (vc-rcs-set-default-branch file
411 nil)
412 ""))))))
413 switches)
414 ;; determine the new workfile version
415 (with-current-buffer "*vc*"
416 (setq new-version
417 (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1)))
418 (vc-file-setprop file 'vc-workfile-version new-version)
419 ;; if necessary, adjust the default branch
420 (and rev (not (string= rev ""))
421 (vc-rcs-set-default-branch
422 file
423 (if (vc-rcs-latest-on-branch-p file new-version)
424 (if (vc-trunk-p new-version) nil
425 (vc-branch-part new-version))
426 new-version)))))
427 (message "Checking out %s...done" file)))))
429 (defun vc-rcs-revert (file &optional contents-done)
430 "Revert FILE to the version it was based on."
431 (vc-do-command nil 0 "co" (vc-name file) "-f"
432 (concat (if (eq (vc-state file) 'edited) "-u" "-r")
433 (vc-workfile-version file))))
435 (defun vc-rcs-cancel-version (file editable)
436 "Undo the most recent checkin of FILE.
437 EDITABLE non-nil means previous version should be locked."
438 (let* ((target (vc-workfile-version file))
439 (previous (if (vc-trunk-p target) "" (vc-branch-part target)))
440 (config (current-window-configuration))
441 (done nil))
442 (vc-do-command nil 0 "rcs" (vc-name file) (concat "-o" target))
443 ;; Check out the most recent remaining version. If it fails, because
444 ;; the whole branch got deleted, do a double-take and check out the
445 ;; version where the branch started.
446 (while (not done)
447 (condition-case err
448 (progn
449 (vc-do-command nil 0 "co" (vc-name file) "-f"
450 (concat (if editable "-l" "-u") previous))
451 (setq done t))
452 (error (set-buffer "*vc*")
453 (goto-char (point-min))
454 (if (search-forward "no side branches present for" nil t)
455 (progn (setq previous (vc-branch-part previous))
456 (vc-rcs-set-default-branch file previous)
457 ;; vc-do-command popped up a window with
458 ;; the error message. Get rid of it, by
459 ;; restoring the old window configuration.
460 (set-window-configuration config))
461 ;; No, it was some other error: re-signal it.
462 (signal (car err) (cdr err))))))))
464 (defun vc-rcs-merge (file first-version &optional second-version)
465 "Merge changes into current working copy of FILE.
466 The changes are between FIRST-VERSION and SECOND-VERSION."
467 (vc-do-command nil 1 "rcsmerge" (vc-name file)
468 "-kk" ; ignore keyword conflicts
469 (concat "-r" first-version)
470 (if second-version (concat "-r" second-version))))
472 (defun vc-rcs-steal-lock (file &optional rev)
473 "Steal the lock on the current workfile for FILE and revision REV.
474 Needs RCS 5.6.2 or later for -M."
475 (vc-do-command nil 0 "rcs" (vc-name file) "-M" (concat "-u" rev))
476 ;; Do a real checkout after stealing the lock, so that we see
477 ;; expanded headers.
478 (vc-do-command nil 0 "co" (vc-name file) "-f" (concat "-l" rev)))
483 ;;; History functions
486 (defun vc-rcs-print-log (file &optional buffer)
487 "Get change log associated with FILE."
488 (vc-do-command buffer 0 "rlog" (vc-name file)))
490 (defun vc-rcs-diff (file &optional oldvers newvers buffer)
491 "Get a difference report using RCS between two versions of FILE."
492 (if (not oldvers) (setq oldvers (vc-workfile-version file)))
493 (apply 'vc-do-command (or buffer "*vc-diff*") 1 "rcsdiff" file
494 (append (list "-q"
495 (concat "-r" oldvers)
496 (and newvers (concat "-r" newvers)))
497 (vc-switches 'RCS 'diff))))
501 ;;; Snapshot system
504 (defun vc-rcs-assign-name (file name)
505 "Assign to FILE's latest version a given NAME."
506 (vc-do-command nil 0 "rcs" (vc-name file) (concat "-n" name ":")))
510 ;;; Miscellaneous
513 (defun vc-rcs-check-headers ()
514 "Check if the current file has any headers in it."
515 (save-excursion
516 (goto-char (point-min))
517 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
518 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
520 (defun vc-rcs-clear-headers ()
521 "Implementation of vc-clear-headers for RCS."
522 (let ((case-fold-search nil))
523 (goto-char (point-min))
524 (while (re-search-forward
525 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
526 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
527 nil t)
528 (replace-match "$\\1$"))))
530 (defun vc-rcs-rename-file (old new)
531 ;; Just move the master file (using vc-rcs-master-templates).
532 (vc-rename-master (vc-name old) new vc-rcs-master-templates))
536 ;;; Internal functions
539 (defun vc-rcs-workfile-is-newer (file)
540 "Return non-nil if FILE is newer than its RCS master.
541 This likely means that FILE has been changed with respect
542 to its master version."
543 (let ((file-time (nth 5 (file-attributes file)))
544 (master-time (nth 5 (file-attributes (vc-name file)))))
545 (or (> (nth 0 file-time) (nth 0 master-time))
546 (and (= (nth 0 file-time) (nth 0 master-time))
547 (> (nth 1 file-time) (nth 1 master-time))))))
549 (defun vc-rcs-find-most-recent-rev (branch)
550 "Find most recent revision on BRANCH."
551 (goto-char (point-min))
552 (let ((latest-rev -1) value)
553 (while (re-search-forward (concat "^\\(" (regexp-quote branch)
554 "\\.\\([0-9]+\\)\\)\ndate[ \t]+[0-9.]+;")
555 nil t)
556 (let ((rev (string-to-number (match-string 2))))
557 (when (< latest-rev rev)
558 (setq latest-rev rev)
559 (setq value (match-string 1)))))
560 (or value
561 (vc-branch-part branch))))
563 (defun vc-rcs-fetch-master-state (file &optional workfile-version)
564 "Compute the master file's idea of the state of FILE.
565 If a WORKFILE-VERSION is given, compute the state of that version,
566 otherwise determine the workfile version based on the master file.
567 This function sets the properties `vc-workfile-version' and
568 `vc-checkout-model' to their correct values, based on the master
569 file."
570 (with-temp-buffer
571 (if (or (not (vc-insert-file (vc-name file) "^[0-9]"))
572 (progn (goto-char (point-min))
573 (not (looking-at "^head[ \t\n]+[^;]+;$"))))
574 (error "File %s is not an RCS master file" (vc-name file)))
575 (let ((workfile-is-latest nil)
576 (default-branch (vc-parse-buffer "^branch[ \t\n]+\\([^;]*\\);" 1)))
577 (vc-file-setprop file 'vc-rcs-default-branch default-branch)
578 (unless workfile-version
579 ;; Workfile version not known yet. Determine that first. It
580 ;; is either the head of the trunk, the head of the default
581 ;; branch, or the "default branch" itself, if that is a full
582 ;; revision number.
583 (cond
584 ;; no default branch
585 ((or (not default-branch) (string= "" default-branch))
586 (setq workfile-version
587 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
588 (setq workfile-is-latest t))
589 ;; default branch is actually a revision
590 ((string-match "^[0-9]+\\.[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*$"
591 default-branch)
592 (setq workfile-version default-branch))
593 ;; else, search for the head of the default branch
594 (t (vc-insert-file (vc-name file) "^desc")
595 (setq workfile-version
596 (vc-rcs-find-most-recent-rev default-branch))
597 (setq workfile-is-latest t)))
598 (vc-file-setprop file 'vc-workfile-version workfile-version))
599 ;; Check strict locking
600 (goto-char (point-min))
601 (vc-file-setprop file 'vc-checkout-model
602 (if (re-search-forward ";[ \t\n]*strict;" nil t)
603 'locking 'implicit))
604 ;; Compute state of workfile version
605 (goto-char (point-min))
606 (let ((locking-user
607 (vc-parse-buffer (concat "^locks[ \t\n]+[^;]*[ \t\n]+\\([^:]+\\):"
608 (regexp-quote workfile-version)
609 "[^0-9.]")
610 1)))
611 (cond
612 ;; not locked
613 ((not locking-user)
614 (if (or workfile-is-latest
615 (vc-rcs-latest-on-branch-p file workfile-version))
616 ;; workfile version is latest on branch
617 'up-to-date
618 ;; workfile version is not latest on branch
619 'needs-patch))
620 ;; locked by the calling user
621 ((and (stringp locking-user)
622 (string= locking-user (vc-user-login-name)))
623 (if (or (eq (vc-checkout-model file) 'locking)
624 workfile-is-latest
625 (vc-rcs-latest-on-branch-p file workfile-version))
626 'edited
627 ;; Locking is not used for the file, but the owner does
628 ;; have a lock, and there is a higher version on the current
629 ;; branch. Not sure if this can occur, and if it is right
630 ;; to use `needs-merge' in this case.
631 'needs-merge))
632 ;; locked by somebody else
633 ((stringp locking-user)
634 locking-user)
636 (error "Error getting state of RCS file")))))))
638 (defun vc-rcs-consult-headers (file)
639 "Search for RCS headers in FILE, and set properties accordingly.
641 Returns: nil if no headers were found
642 'rev if a workfile revision was found
643 'rev-and-lock if revision and lock info was found"
644 (cond
645 ((not (get-file-buffer file)) nil)
646 ((let (status version locking-user)
647 (save-excursion
648 (set-buffer (get-file-buffer file))
649 (goto-char (point-min))
650 (cond
651 ;; search for $Id or $Header
652 ;; -------------------------
653 ;; The `\ 's below avoid an RCS 5.7 bug when checking in this file.
654 ((or (and (search-forward "$Id\ : " nil t)
655 (looking-at "[^ ]+ \\([0-9.]+\\) "))
656 (and (progn (goto-char (point-min))
657 (search-forward "$Header\ : " nil t))
658 (looking-at "[^ ]+ \\([0-9.]+\\) ")))
659 (goto-char (match-end 0))
660 ;; if found, store the revision number ...
661 (setq version (match-string-no-properties 1))
662 ;; ... and check for the locking state
663 (cond
664 ((looking-at
665 (concat "[0-9]+[/-][01][0-9][/-][0-3][0-9] " ; date
666 "[0-2][0-9]:[0-5][0-9]+:[0-6][0-9]+\\([+-][0-9:]+\\)? " ; time
667 "[^ ]+ [^ ]+ ")) ; author & state
668 (goto-char (match-end 0)) ; [0-6] in regexp handles leap seconds
669 (cond
670 ;; unlocked revision
671 ((looking-at "\\$")
672 (setq locking-user 'none)
673 (setq status 'rev-and-lock))
674 ;; revision is locked by some user
675 ((looking-at "\\([^ ]+\\) \\$")
676 (setq locking-user (match-string-no-properties 1))
677 (setq status 'rev-and-lock))
678 ;; everything else: false
679 (nil)))
680 ;; unexpected information in
681 ;; keyword string --> quit
682 (nil)))
683 ;; search for $Revision
684 ;; --------------------
685 ((re-search-forward (concat "\\$"
686 "Revision: \\([0-9.]+\\) \\$")
687 nil t)
688 ;; if found, store the revision number ...
689 (setq version (match-string-no-properties 1))
690 ;; and see if there's any lock information
691 (goto-char (point-min))
692 (if (re-search-forward (concat "\\$" "Locker:") nil t)
693 (cond ((looking-at " \\([^ ]+\\) \\$")
694 (setq locking-user (match-string-no-properties 1))
695 (setq status 'rev-and-lock))
696 ((looking-at " *\\$")
697 (setq locking-user 'none)
698 (setq status 'rev-and-lock))
700 (setq locking-user 'none)
701 (setq status 'rev-and-lock)))
702 (setq status 'rev)))
703 ;; else: nothing found
704 ;; -------------------
705 (t nil)))
706 (if status (vc-file-setprop file 'vc-workfile-version version))
707 (and (eq status 'rev-and-lock)
708 (vc-file-setprop file 'vc-state
709 (cond
710 ((eq locking-user 'none) 'up-to-date)
711 ((string= locking-user (vc-user-login-name)) 'edited)
712 (t locking-user)))
713 ;; If the file has headers, we don't want to query the
714 ;; master file, because that would eliminate all the
715 ;; performance gain the headers brought us. We therefore
716 ;; use a heuristic now to find out whether locking is used
717 ;; for this file. If we trust the file permissions, and the
718 ;; file is not locked, then if the file is read-only we
719 ;; assume that locking is used for the file, otherwise
720 ;; locking is not used.
721 (not (vc-mistrust-permissions file))
722 (vc-up-to-date-p file)
723 (if (string-match ".r-..-..-." (nth 8 (file-attributes file)))
724 (vc-file-setprop file 'vc-checkout-model 'locking)
725 (vc-file-setprop file 'vc-checkout-model 'implicit)))
726 status))))
728 (defun vc-release-greater-or-equal (r1 r2)
729 "Compare release numbers, represented as strings.
730 Release components are assumed cardinal numbers, not decimal fractions
731 \(5.10 is a higher release than 5.9\). Omitted fields are considered
732 lower \(5.6.7 is earlier than 5.6.7.1\). Comparison runs till the end
733 of the string is found, or a non-numeric component shows up \(5.6.7 is
734 earlier than \"5.6.7 beta\", which is probably not what you want in
735 some cases\). This code is suitable for existing RCS release numbers.
736 CVS releases are handled reasonably, too \(1.3 < 1.4* < 1.5\)."
737 (let (v1 v2 i1 i2)
738 (catch 'done
739 (or (and (string-match "^\\.?\\([0-9]+\\)" r1)
740 (setq i1 (match-end 0))
741 (setq v1 (string-to-number (match-string 1 r1)))
742 (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
743 (setq i2 (match-end 0))
744 (setq v2 (string-to-number (match-string 1 r2)))
745 (if (> v1 v2) (throw 'done t)
746 (if (< v1 v2) (throw 'done nil)
747 (throw 'done
748 (vc-release-greater-or-equal
749 (substring r1 i1)
750 (substring r2 i2)))))))
751 (throw 'done t)))
752 (or (and (string-match "^\\.?\\([0-9]+\\)" r2)
753 (throw 'done nil))
754 (throw 'done t)))))
756 (defun vc-rcs-release-p (release)
757 "Return t if we have RELEASE or better."
758 (let ((installation (vc-rcs-system-release)))
759 (if (and installation
760 (not (eq installation 'unknown)))
761 (vc-release-greater-or-equal installation release))))
764 (defun vc-rcs-system-release ()
765 "Return the RCS release installed on this system, as a string.
766 Return symbol UNKNOWN if the release cannot be deducted. The user can
767 override this using variable `vc-rcs-release'.
769 If the user has not set variable `vc-rcs-release' and it is nil,
770 variable `vc-rcs-release' is set to the returned value."
771 (or vc-rcs-release
772 (setq vc-rcs-release
773 (or (and (zerop (vc-do-command nil nil "rcs" nil "-V"))
774 (with-current-buffer (get-buffer "*vc*")
775 (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1)))
776 'unknown))))
778 (defun vc-rcs-set-non-strict-locking (file)
779 (vc-do-command nil 0 "rcs" file "-U")
780 (vc-file-setprop file 'vc-checkout-model 'implicit)
781 (set-file-modes file (logior (file-modes file) 128)))
783 (defun vc-rcs-set-default-branch (file branch)
784 (vc-do-command nil 0 "rcs" (vc-name file) (concat "-b" branch))
785 (vc-file-setprop file 'vc-rcs-default-branch branch))
787 (provide 'vc-rcs)
789 ;;; arch-tag: 759b4916-5b0d-431d-b647-b185b8c652cf
790 ;;; vc-rcs.el ends here