comparison lisp/vc-rcs.el @ 33560:da206bbad86b

Functions reordered.
author André Spiegel <spiegel@gnu.org>
date Thu, 16 Nov 2000 18:14:41 +0000
parents e7f273d850bf
children 32bcc6e27e02
comparison
equal deleted inserted replaced
33559:c6a08bfab7fd 33560:da206bbad86b
3 ;; Copyright (C) 1992,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc. 3 ;; Copyright (C) 1992,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc.
4 4
5 ;; Author: FSF (see vc.el for full credits) 5 ;; Author: FSF (see vc.el for full credits)
6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org> 6 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
7 7
8 ;; $Id: vc-rcs.el,v 1.10 2000/10/03 11:33:59 spiegel Exp $ 8 ;; $Id: vc-rcs.el,v 1.11 2000/10/03 12:08:40 spiegel Exp $
9 9
10 ;; This file is part of GNU Emacs. 10 ;; This file is part of GNU Emacs.
11 11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify 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 13 ;; it under the terms of the GNU General Public License as published by
25 ;; Boston, MA 02111-1307, USA. 25 ;; Boston, MA 02111-1307, USA.
26 26
27 ;;; Commentary: see vc.el 27 ;;; Commentary: see vc.el
28 28
29 ;;; Code: 29 ;;; Code:
30
31 ;;;
32 ;;; Customization options
33 ;;;
30 34
31 (eval-when-compile 35 (eval-when-compile
32 (require 'cl)) 36 (require 'cl))
33 37
34 (defcustom vc-rcs-release nil 38 (defcustom vc-rcs-release nil
96 (repeat :tag "User-specified" 100 (repeat :tag "User-specified"
97 (choice string 101 (choice string
98 function))) 102 function)))
99 :version "21.1" 103 :version "21.1"
100 :group 'vc) 104 :group 'vc)
105
106
107 ;;;
108 ;;; State-querying functions
109 ;;;
101 110
102 ;;;###autoload 111 ;;;###autoload
103 (progn (defun vc-rcs-registered (f) (vc-default-registered 'RCS f))) 112 (progn (defun vc-rcs-registered (f) (vc-default-registered 'RCS f)))
104 113
105 (defun vc-rcs-state (file) 114 (defun vc-rcs-state (file)
162 ;; Strange permissions. Fall through to 171 ;; Strange permissions. Fall through to
163 ;; expensive state computation. 172 ;; expensive state computation.
164 (vc-rcs-state file)))) 173 (vc-rcs-state file))))
165 (vc-rcs-state file))))) 174 (vc-rcs-state file)))))
166 175
176 (defun vc-rcs-workfile-version (file)
177 "RCS-specific version of `vc-workfile-version'."
178 (or (and vc-consult-headers
179 (vc-rcs-consult-headers file)
180 (vc-file-getprop file 'vc-workfile-version))
181 (progn
182 (vc-rcs-fetch-master-state file)
183 (vc-file-getprop file 'vc-workfile-version))))
184
185 (defun vc-rcs-latest-on-branch-p (file &optional version)
186 "Return non-nil if workfile version of FILE is the latest on its branch.
187 When VERSION is given, perform check for that version."
188 (unless version (setq version (vc-workfile-version file)))
189 (with-temp-buffer
190 (string= version
191 (if (vc-rcs-trunk-p version)
192 (progn
193 ;; Compare VERSION to the head version number.
194 (vc-insert-file (vc-name file) "^[0-9]")
195 (vc-parse-buffer "^head[ \t\n]+\\([^;]+\\);" 1))
196 ;; If we are not on the trunk, we need to examine the
197 ;; whole current branch.
198 (vc-insert-file (vc-name file) "^desc")
199 (vc-rcs-find-most-recent-rev (vc-rcs-branch-part version))))))
200
201 (defun vc-rcs-checkout-model (file)
202 "RCS-specific version of `vc-checkout-model'."
203 (vc-rcs-consult-headers file)
204 (or (vc-file-getprop file 'vc-checkout-model)
205 (progn (vc-rcs-fetch-master-state file)
206 (vc-file-getprop file 'vc-checkout-model))))
207
208 (defun vc-rcs-workfile-unchanged-p (file)
209 "RCS-specific implementation of vc-workfile-unchanged-p."
210 ;; Try to use rcsdiff --brief. If rcsdiff does not understand that,
211 ;; do a double take and remember the fact for the future
212 (let* ((version (concat "-r" (vc-workfile-version file)))
213 (status (if (eq vc-rcsdiff-knows-brief 'no)
214 (vc-do-command nil 1 "rcsdiff" file version)
215 (vc-do-command nil 2 "rcsdiff" file "--brief" version))))
216 (if (eq status 2)
217 (if (not vc-rcsdiff-knows-brief)
218 (setq vc-rcsdiff-knows-brief 'no
219 status (vc-do-command nil 1 "rcsdiff" file version))
220 (error "rcsdiff failed"))
221 (if (not vc-rcsdiff-knows-brief) (setq vc-rcsdiff-knows-brief 'yes)))
222 ;; The workfile is unchanged if rcsdiff found no differences.
223 (zerop status)))
224
225
226 ;;;
227 ;;; State-changing functions
228 ;;;
229
230 (defun vc-rcs-register (file &optional rev comment)
231 "Register FILE into the RCS version-control system.
232 REV is the optional revision number for the file. COMMENT can be used
233 to provide an initial description of FILE.
234
235 `vc-register-switches' and `vc-rcs-register-switches' are passed to
236 the RCS command (in that order).
237
238 Automatically retrieve a read-only version of the file with keywords
239 expanded if `vc-keep-workfiles' is non-nil, otherwise, delete the workfile."
240 (let ((subdir (expand-file-name "RCS" (file-name-directory file)))
241 (switches (list
242 (if (stringp vc-register-switches)
243 (list vc-register-switches)
244 vc-register-switches)
245 (if (stringp vc-rcs-register-switches)
246 (list vc-rcs-register-switches)
247 vc-rcs-register-switches))))
248
249 (and (not (file-exists-p subdir))
250 (not (directory-files (file-name-directory file)
251 nil ".*,v$" t))
252 (yes-or-no-p "Create RCS subdirectory? ")
253 (make-directory subdir))
254 (apply 'vc-do-command nil 0 "ci" file
255 ;; if available, use the secure registering option
256 (and (vc-rcs-release-p "5.6.4") "-i")
257 (concat (if vc-keep-workfiles "-u" "-r") rev)
258 (and comment (concat "-t-" comment))
259 switches)
260 ;; parse output to find master file name and workfile version
261 (with-current-buffer "*vc*"
262 (goto-char (point-min))
263 (let ((name (if (looking-at (concat "^\\(.*\\) <-- "
264 (file-name-nondirectory file)))
265 (match-string 1))))
266 (if (not name)
267 ;; if we couldn't find the master name,
268 ;; run vc-rcs-registered to get it
269 ;; (will be stored into the vc-name property)
270 (vc-rcs-registered file)
271 (vc-file-setprop file 'vc-name
272 (if (file-name-absolute-p name)
273 name
274 (expand-file-name
275 name
276 (file-name-directory file))))))
277 (vc-file-setprop file 'vc-workfile-version
278 (if (re-search-forward
279 "^initial revision: \\([0-9.]+\\).*\n"
280 nil t)
281 (match-string 1))))))
282
283 (defun vc-rcs-responsible-p (file)
284 "Return non-nil if RCS thinks it would be responsible for registering FILE."
285 ;; TODO: check for all the patterns in vc-rcs-master-templates
286 (file-directory-p (expand-file-name "RCS" (file-name-directory file))))
287
288 (defun vc-rcs-receive-file (file rev)
289 "Implementation of receive-file for RCS."
290 (let ((checkout-model (vc-checkout-model file)))
291 (vc-rcs-register file rev "")
292 (when (eq checkout-model 'implicit)
293 (vc-rcs-set-non-strict-locking file))
294 (vc-rcs-set-default-branch file (concat rev ".1"))))
295
296 (defun vc-rcs-unregister (file)
297 "Unregister FILE from RCS.
298 If this leaves the RCS subdirectory empty, ask the user
299 whether to remove it."
300 (let* ((master (vc-name file))
301 (dir (file-name-directory master))
302 (backup-info (find-backup-file-name master)))
303 (if (not backup-info)
304 (delete-file master)
305 (rename-file master (car backup-info) 'ok-if-already-exists)
306 (dolist (f (cdr backup-info)) (ignore-errors (delete-file f))))
307 (and (string= (file-name-nondirectory (directory-file-name dir)) "RCS")
308 ;; check whether RCS dir is empty, i.e. it does not
309 ;; contain any files except "." and ".."
310 (not (directory-files dir nil
311 "^\\([^.]\\|\\.[^.]\\|\\.\\.[^.]\\).*"))
312 (yes-or-no-p (format "Directory %s is empty; remove it? " dir))
313 (delete-directory dir))))
314
315 (defun vc-rcs-checkin (file rev comment)
316 "RCS-specific version of `vc-backend-checkin'."
317 (let ((switches (if (stringp vc-checkin-switches)
318 (list vc-checkin-switches)
319 vc-checkin-switches)))
320 (let ((old-version (vc-workfile-version file)) new-version
321 (default-branch (vc-file-getprop file 'vc-rcs-default-branch)))
322 ;; Force branch creation if an appropriate
323 ;; default branch has been set.
324 (and (not rev)
325 default-branch
326 (string-match (concat "^" (regexp-quote old-version) "\\.")
327 default-branch)
328 (setq rev default-branch)
329 (setq switches (cons "-f" switches)))
330 (apply 'vc-do-command nil 0 "ci" (vc-name file)
331 ;; if available, use the secure check-in option
332 (and (vc-rcs-release-p "5.6.4") "-j")
333 (concat (if vc-keep-workfiles "-u" "-r") rev)
334 (concat "-m" comment)
335 switches)
336 (vc-file-setprop file 'vc-workfile-version nil)
337
338 ;; determine the new workfile version
339 (set-buffer "*vc*")
340 (goto-char (point-min))
341 (when (or (re-search-forward
342 "new revision: \\([0-9.]+\\);" nil t)
343 (re-search-forward
344 "reverting to previous revision \\([0-9.]+\\)" nil t))
345 (setq new-version (match-string 1))
346 (vc-file-setprop file 'vc-workfile-version new-version))
347
348 ;; if we got to a different branch, adjust the default
349 ;; branch accordingly
350 (cond
351 ((and old-version new-version
352 (not (string= (vc-rcs-branch-part old-version)
353 (vc-rcs-branch-part new-version))))
354 (vc-rcs-set-default-branch file
355 (if (vc-rcs-trunk-p new-version) nil
356 (vc-rcs-branch-part new-version)))
357 ;; If this is an old RCS release, we might have
358 ;; to remove a remaining lock.
359 (if (not (vc-rcs-release-p "5.6.2"))
360 ;; exit status of 1 is also accepted.
361 ;; It means that the lock was removed before.
362 (vc-do-command nil 1 "rcs" (vc-name file)
363 (concat "-u" old-version))))))))
364
365 (defun vc-rcs-checkout (file &optional writable rev workfile)
366 "Retrieve a copy of a saved version of FILE into a workfile."
367 (let ((filename (or workfile file))
368 (file-buffer (get-file-buffer file))
369 switches)
370 (message "Checking out %s..." filename)
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 (if (stringp vc-checkout-switches)
375 (list vc-checkout-switches)
376 vc-checkout-switches))
377 ;; Save this buffer's default-directory
378 ;; and use save-excursion to make sure it is restored
379 ;; in the same buffer it was saved in.
380 (let ((default-directory default-directory))
381 (save-excursion
382 ;; Adjust the default-directory so that the check-out creates
383 ;; the file in the right place.
384 (setq default-directory (file-name-directory filename))
385 (if workfile ;; RCS
386 ;; RCS can't check out into arbitrary file names directly.
387 ;; Use `co -p' and make stdout point to the correct file.
388 (let ((vc-modes (logior (file-modes (vc-name file))
389 (if writable 128 0)))
390 (failed t))
391 (unwind-protect
392 (progn
393 (let ((coding-system-for-read 'no-conversion)
394 (coding-system-for-write 'no-conversion))
395 (with-temp-file filename
396 (apply 'vc-do-command
397 (current-buffer) 0 "co" (vc-name file)
398 "-q" ;; suppress diagnostic output
399 (if writable "-l")
400 (concat "-p" rev)
401 switches)))
402 (set-file-modes filename
403 (logior (file-modes (vc-name file))
404 (if writable 128 0)))
405 (setq failed nil))
406 (and failed (file-exists-p filename)
407 (delete-file filename))))
408 (let (new-version)
409 ;; if we should go to the head of the trunk,
410 ;; clear the default branch first
411 (and rev (string= rev "")
412 (vc-rcs-set-default-branch file nil))
413 ;; now do the checkout
414 (apply 'vc-do-command
415 nil 0 "co" (vc-name file)
416 ;; If locking is not strict, force to overwrite
417 ;; the writable workfile.
418 (if (eq (vc-checkout-model file) 'implicit) "-f")
419 (if writable "-l")
420 (if rev (concat "-r" rev)
421 ;; if no explicit revision was specified,
422 ;; check out that of the working file
423 (let ((workrev (vc-workfile-version file)))
424 (if workrev (concat "-r" workrev)
425 nil)))
426 switches)
427 ;; determine the new workfile version
428 (with-current-buffer "*vc*"
429 (setq new-version
430 (vc-parse-buffer "^revision \\([0-9.]+\\).*\n" 1)))
431 (vc-file-setprop file 'vc-workfile-version new-version)
432 ;; if necessary, adjust the default branch
433 (and rev (not (string= rev ""))
434 (vc-rcs-set-default-branch
435 file
436 (if (vc-rcs-latest-on-branch-p file new-version)
437 (if (vc-rcs-trunk-p new-version) nil
438 (vc-rcs-branch-part new-version))
439 new-version))))))
440 (message "Checking out %s...done" filename)))))
441
442 (defun vc-rcs-revert (file)
443 "Revert FILE to the version it was based on."
444 (vc-do-command nil 0 "co" (vc-name file) "-f"
445 (concat "-u" (vc-workfile-version file))))
446
447 (defun vc-rcs-cancel-version (file writable)
448 "Undo the most recent checkin of FILE.
449 WRITABLE non-nil means previous version should be locked."
450 (let* ((target (vc-workfile-version file))
451 (previous (if (vc-trunk-p target) "" (vc-branch-part target)))
452 (config (current-window-configuration))
453 (done nil))
454 (vc-do-command nil 0 "rcs" (vc-name file) (concat "-o" target))
455 ;; Check out the most recent remaining version. If it fails, because
456 ;; the whole branch got deleted, do a double-take and check out the
457 ;; version where the branch started.
458 (while (not done)
459 (condition-case err
460 (progn
461 (vc-do-command nil 0 "co" (vc-name file) "-f"
462 (concat (if writable "-l" "-u") previous))
463 (setq done t))
464 (error (set-buffer "*vc*")
465 (goto-char (point-min))
466 (if (search-forward "no side branches present for" nil t)
467 (progn (setq previous (vc-branch-part previous))
468 (vc-rcs-set-default-branch file previous)
469 ;; vc-do-command popped up a window with
470 ;; the error message. Get rid of it, by
471 ;; restoring the old window configuration.
472 (set-window-configuration config))
473 ;; No, it was some other error: re-signal it.
474 (signal (car err) (cdr err))))))))
475
476 (defun vc-rcs-merge (file first-version &optional second-version)
477 "Merge changes into current working copy of FILE.
478 The changes are between FIRST-VERSION and SECOND-VERSION."
479 (vc-do-command nil 1 "rcsmerge" (vc-name file)
480 "-kk" ; ignore keyword conflicts
481 (concat "-r" first-version)
482 (if second-version (concat "-r" second-version))))
483
484 (defun vc-rcs-steal-lock (file &optional rev)
485 "Steal the lock on the current workfile for FILE and revision REV.
486 Needs RCS 5.6.2 or later for -M."
487 (vc-do-command nil 0 "rcs" (vc-name file) "-M"
488 (concat "-u" rev) (concat "-l" rev)))
489
490
491
492 ;;;
493 ;;; History functions
494 ;;;
495
496 (defun vc-rcs-print-log (file)
497 "Get change log associated with FILE."
498 (vc-do-command t 0 "rlog" (vc-name file)))
499
500 (defun vc-rcs-show-log-entry (version)
501 (when (re-search-forward
502 ;; also match some context, for safety
503 (concat "----\nrevision " version
504 "\\(\tlocked by:.*\n\\|\n\\)date: ") nil t)
505 ;; set the display window so that
506 ;; the whole log entry is displayed
507 (let (start end lines)
508 (beginning-of-line) (forward-line -1) (setq start (point))
509 (if (not (re-search-forward "^----*\nrevision" nil t))
510 (setq end (point-max))
511 (beginning-of-line) (forward-line -1) (setq end (point)))
512 (setq lines (count-lines start end))
513 (cond
514 ;; if the global information and this log entry fit
515 ;; into the window, display from the beginning
516 ((< (count-lines (point-min) end) (window-height))
517 (goto-char (point-min))
518 (recenter 0)
519 (goto-char start))
520 ;; if the whole entry fits into the window,
521 ;; display it centered
522 ((< (1+ lines) (window-height))
523 (goto-char start)
524 (recenter (1- (- (/ (window-height) 2) (/ lines 2)))))
525 ;; otherwise (the entry is too large for the window),
526 ;; display from the start
527 (t
528 (goto-char start)
529 (recenter 0))))))
530
531 (defun vc-rcs-diff (file &optional oldvers newvers)
532 "Get a difference report using RCS between two versions of FILE."
533 (if (not oldvers) (setq oldvers (vc-workfile-version file)))
534 ;; If we know that --brief is not supported, don't try it.
535 (let* ((diff-switches-list (if (listp diff-switches)
536 diff-switches
537 (list diff-switches)))
538 (options (append (list "-q"
539 (concat "-r" oldvers)
540 (and newvers (concat "-r" newvers)))
541 diff-switches-list)))
542 (apply 'vc-do-command t 1 "rcsdiff" file options)))
543
544
545 ;;;
546 ;;; Snapshot system
547 ;;;
548
549 (defun vc-rcs-assign-name (file name)
550 "Assign to FILE's latest version a given NAME."
551 (vc-do-command nil 0 "rcs" (vc-name file) (concat "-n" name ":")))
552
553
554 ;;;
555 ;;; Miscellaneous
556 ;;;
557
558 (defun vc-rcs-check-headers ()
559 "Check if the current file has any headers in it."
560 (save-excursion
561 (goto-char (point-min))
562 (re-search-forward "\\$[A-Za-z\300-\326\330-\366\370-\377]+\
563 \\(: [\t -#%-\176\240-\377]*\\)?\\$" nil t)))
564
565 (defun vc-rcs-clear-headers ()
566 "Implementation of vc-clear-headers for RCS."
567 (let ((case-fold-search nil))
568 (goto-char (point-min))
569 (while (re-search-forward
570 (concat "\\$\\(Author\\|Date\\|Header\\|Id\\|Locker\\|Name\\|"
571 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
572 nil t)
573 (replace-match "$\\1$"))))
574
575 (defun vc-rcs-rename-file (old new)
576 ;; Just move the master file (using vc-rcs-master-templates).
577 (vc-rename-master (vc-name old) new vc-rcs-master-templates))
578
579
580 ;;;
581 ;;; Internal functions
582 ;;;
583
584 (defun vc-rcs-trunk-p (rev)
585 "Return t if REV is an RCS revision on the trunk."
586 (not (eq nil (string-match "\\`[0-9]+\\.[0-9]+\\'" rev))))
587
588 (defun vc-rcs-branch-part (rev)
589 "Return the branch part of an RCS revision number REV"
590 (substring rev 0 (string-match "\\.[0-9]+\\'" rev)))
591
592 (defun vc-rcs-branch-p (rev)
593 "Return t if REV is an RCS branch revision"
594 (not (eq nil (string-match "\\`[0-9]+\\(\\.[0-9]+\\.[0-9]+\\)*\\'" rev))))
595
596 (defun vc-rcs-minor-part (rev)
597 "Return the minor version number of an RCS revision number REV."
598 (string-match "[0-9]+\\'" rev)
599 (substring rev (match-beginning 0) (match-end 0)))
600
601 (defun vc-rcs-previous-version (rev)
602 "Guess the previous RCS version number"
603 (let ((branch (vc-rcs-branch-part rev))
604 (minor-num (string-to-number (vc-rcs-minor-part rev))))
605 (if (> minor-num 1)
606 ;; version does probably not start a branch or release
607 (concat branch "." (number-to-string (1- minor-num)))
608 (if (vc-rcs-trunk-p rev)
609 ;; we are at the beginning of the trunk --
610 ;; don't know anything to return here
611 ""
612 ;; we are at the beginning of a branch --
613 ;; return version of starting point
614 (vc-rcs-branch-part branch)))))
615
167 (defun vc-rcs-workfile-is-newer (file) 616 (defun vc-rcs-workfile-is-newer (file)
168 "Return non-nil if FILE is newer than its RCS master. 617 "Return non-nil if FILE is newer than its RCS master.
169 This likely means that FILE has been changed with respect 618 This likely means that FILE has been changed with respect
170 to its master version." 619 to its master version."
171 (let ((file-time (nth 5 (file-attributes file))) 620 (let ((file-time (nth 5 (file-attributes file)))
172 (master-time (nth 5 (file-attributes (vc-name file))))) 621 (master-time (nth 5 (file-attributes (vc-name file)))))
173 (or (> (nth 0 file-time) (nth 0 master-time)) 622 (or (> (nth 0 file-time) (nth 0 master-time))
174 (and (= (nth 0 file-time) (nth 0 master-time)) 623 (and (= (nth 0 file-time) (nth 0 master-time))
175 (> (nth 1 file-time) (nth 1 master-time)))))) 624 (> (nth 1 file-time) (nth 1 master-time))))))
176
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))
182 (progn
183 (vc-rcs-fetch-master-state file)
184 (vc-file-getprop file 'vc-workfile-version))))
185
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))))
192
193 ;;; internal code
194 625
195 (defun vc-rcs-find-most-recent-rev (branch) 626 (defun vc-rcs-find-most-recent-rev (branch)
196 "Find most recent revision on BRANCH." 627 "Find most recent revision on BRANCH."
197 (goto-char (point-min)) 628 (goto-char (point-min))
198 (let ((latest-rev -1) value) 629 (let ((latest-rev -1) value)
371 (if (string-match ".r-..-..-." (nth 8 (file-attributes file))) 802 (if (string-match ".r-..-..-." (nth 8 (file-attributes file)))
372 (vc-file-setprop file 'vc-checkout-model 'locking) 803 (vc-file-setprop file 'vc-checkout-model 'locking)
373 (vc-file-setprop file 'vc-checkout-model 'implicit))) 804 (vc-file-setprop file 'vc-checkout-model 'implicit)))
374 status)))) 805 status))))
375 806
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))))
384 (if (eq status 2)
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.
391 (zerop status)))
392
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))))
396
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)))
400
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)))
405 (with-temp-buffer
406 (string= version
407 (if (vc-rcs-trunk-p version)
408 (progn
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))))))
416
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))))
420
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)))
425
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))))
430 (if (> minor-num 1)
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
436 ""
437 ;; we are at the beginning of a branch --
438 ;; return version of starting point
439 (vc-rcs-branch-part branch)))))
440
441 (defun vc-rcs-print-log (file)
442 "Get change log associated with FILE."
443 (vc-do-command t 0 "rlog" (vc-name file)))
444
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))
458 (cond
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))
463 (recenter 0)
464 (goto-char start))
465 ;; if the whole entry fits into the window,
466 ;; display it centered
467 ((< (1+ lines) (window-height))
468 (goto-char start)
469 (recenter (1- (- (/ (window-height) 2) (/ lines 2)))))
470 ;; otherwise (the entry is too large for the window),
471 ;; display from the start
472 (t
473 (goto-char start)
474 (recenter 0))))))
475
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 ":")))
479
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))))
487
488 (defun vc-rcs-check-headers ()
489 "Check if the current file has any headers in it."
490 (save-excursion
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)))
494
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]+\\$")
502 nil t)
503 (replace-match "$\\1$"))))
504
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)))
510
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))
517 (done nil))
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.
522 (while (not done)
523 (condition-case err
524 (progn
525 (vc-do-command nil 0 "co" (vc-name file) "-f"
526 (concat (if writable "-l" "-u") previous))
527 (setq done t))
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))))))))
539
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))))
544
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))
548
549 (defun vc-release-greater-or-equal (r1 r2) 807 (defun vc-release-greater-or-equal (r1 r2)
550 "Compare release numbers, represented as strings. 808 "Compare release numbers, represented as strings.
551 Release components are assumed cardinal numbers, not decimal fractions 809 Release components are assumed cardinal numbers, not decimal fractions
552 \(5.10 is a higher release than 5.9\). Omitted fields are considered 810 \(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 811 lower \(5.6.7 is earlier than 5.6.7.1\). Comparison runs till the end
579 (let ((installation (vc-rcs-system-release))) 837 (let ((installation (vc-rcs-system-release)))
580 (if (and installation 838 (if (and installation
581 (not (eq installation 'unknown))) 839 (not (eq installation 'unknown)))
582 (vc-release-greater-or-equal installation release)))) 840 (vc-release-greater-or-equal installation release))))
583 841
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.
593 (and (not rev)
594 default-branch
595 (string-match (concat "^" (regexp-quote old-version) "\\.")
596 default-branch)
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)
604 switches)
605 (vc-file-setprop file 'vc-workfile-version nil)
606
607 ;; determine the new workfile version
608 (set-buffer "*vc*")
609 (goto-char (point-min))
610 (when (or (re-search-forward
611 "new revision: \\([0-9.]+\\);" nil t)
612 (re-search-forward
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))
616
617 ;; if we got to a different branch, adjust the default
618 ;; branch accordingly
619 (cond
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))))))))
633 842
634 (defun vc-rcs-system-release () 843 (defun vc-rcs-system-release ()
635 "Return the RCS release installed on this system, as a string. 844 "Return the RCS release installed on this system, as a string.
636 Return symbol UNKNOWN if the release cannot be deducted. The user can 845 Return symbol UNKNOWN if the release cannot be deducted. The user can
637 override this using variable `vc-rcs-release'. 846 override this using variable `vc-rcs-release'.
643 (or (and (zerop (vc-do-command nil nil "rcs" nil "-V")) 852 (or (and (zerop (vc-do-command nil nil "rcs" nil "-V"))
644 (with-current-buffer (get-buffer "*vc*") 853 (with-current-buffer (get-buffer "*vc*")
645 (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1))) 854 (vc-parse-buffer "^RCS version \\([0-9.]+ *.*\\)" 1)))
646 'unknown)))) 855 'unknown))))
647 856
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)
653 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)))
660
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))))
665
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.
670
671 `vc-register-switches' and `vc-rcs-register-switches' are passed to
672 the RCS command (in that order).
673
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)))
677 (switches (list
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))))
684
685 (and (not (file-exists-p subdir))
686 (not (directory-files (file-name-directory file)
687 nil ".*,v$" t))
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))
695 switches)
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)))
701 (match-string 1))))
702 (if (not name)
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)
709 name
710 (expand-file-name
711 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"
716 nil t)
717 (match-string 1))))))
718
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)
727 (delete-file master)
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))))
737
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"))))
745
746 (defun vc-rcs-set-non-strict-locking (file) 857 (defun vc-rcs-set-non-strict-locking (file)
747 (vc-do-command nil 0 "rcs" file "-U") 858 (vc-do-command nil 0 "rcs" file "-U")
748 (vc-file-setprop file 'vc-checkout-model 'implicit) 859 (vc-file-setprop file 'vc-checkout-model 'implicit)
749 (set-file-modes file (logior (file-modes file) 128))) 860 (set-file-modes file (logior (file-modes file) 128)))
750 861
751 (defun vc-rcs-set-default-branch (file branch) 862 (defun vc-rcs-set-default-branch (file branch)
752 (vc-do-command nil 0 "rcs" (vc-name file) (concat "-b" branch)) 863 (vc-do-command nil 0 "rcs" (vc-name file) (concat "-b" branch))
753 (vc-file-setprop file 'vc-rcs-default-branch branch)) 864 (vc-file-setprop file 'vc-rcs-default-branch branch))
754 865
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))
759 switches)
760 (message "Checking out %s..." filename)
761 (save-excursion
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))
771 (save-excursion
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))
775 (if workfile ;; RCS
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)))
780 (failed t))
781 (unwind-protect
782 (progn
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
789 (if writable "-l")
790 (concat "-p" rev)
791 switches)))
792 (set-file-modes filename
793 (logior (file-modes (vc-name file))
794 (if writable 128 0)))
795 (setq failed nil))
796 (and failed (file-exists-p filename)
797 (delete-file filename))))
798 (let (new-version)
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")
809 (if writable "-l")
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)
815 nil)))
816 switches)
817 ;; determine the new workfile version
818 (with-current-buffer "*vc*"
819 (setq new-version
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
825 file
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))
829 new-version))))))
830 (message "Checking out %s...done" filename)))))
831
832 (provide 'vc-rcs) 866 (provide 'vc-rcs)
833 867
834 ;;; vc-rcs.el ends here 868 ;;; vc-rcs.el ends here