comparison lisp/vc.el @ 21324:b0abfde79536

* vc.el (vc-resolve-conflicts): New function. (vc-next-action-on-file): Use it. (vc-backend-revert): For CVS, revert to the version the buffer was based on, not the latest on the current branch (same behavior as for RCS). For SCCS, forget vc-workfile-version so that it gets recomputed. (vc-revert-buffer): Rewrote doc string to explain the above. (vc-finish-logentry): Don't add extra newline.
author André Spiegel <spiegel@gnu.org>
date Tue, 31 Mar 1998 17:19:32 +0000
parents 8972762c8ca6
children 8b4db8ce1da3
comparison
equal deleted inserted replaced
21323:6fe4f59fab8c 21324:b0abfde79536
3 ;; Copyright (C) 1992, 93, 94, 95, 96, 97 Free Software Foundation, Inc. 3 ;; Copyright (C) 1992, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
4 4
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com> 5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
6 ;; Maintainer: Andre Spiegel <spiegel@inf.fu-berlin.de> 6 ;; Maintainer: Andre Spiegel <spiegel@inf.fu-berlin.de>
7 7
8 ;; $Id: vc.el,v 1.211 1998/03/18 13:25:00 spiegel Exp spiegel $ 8 ;; $Id: vc.el,v 1.212 1998/03/20 15:40:24 spiegel Exp spiegel $
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
779 (not (yes-or-no-p 779 (not (yes-or-no-p
780 (format 780 (format
781 "Buffer %s modified; merge file on disc anyhow? " 781 "Buffer %s modified; merge file on disc anyhow? "
782 (buffer-name buffer))))) 782 (buffer-name buffer)))))
783 (error "Merge aborted")) 783 (error "Merge aborted"))
784 (if (not (zerop (vc-backend-merge-news file))) 784 (let ((status (vc-backend-merge-news file)))
785 ;; Overlaps detected - what now? Should use some 785 (and buffer
786 ;; fancy RCS conflict resolving package, or maybe 786 (vc-resynch-buffer file t
787 ;; emerge, but for now, simply warn the user with a 787 (not (buffer-modified-p buffer))))
788 ;; message. 788 (if (not (zerop status))
789 (message "Conflicts detected!")) 789 (if (y-or-n-p "Conflicts detected. Resolve them now? ")
790 (and buffer 790 (vc-resolve-conflicts)))))
791 (vc-resynch-buffer file t (not (buffer-modified-p buffer)))))
792 (error "%s needs update" (buffer-name)))) 791 (error "%s needs update" (buffer-name))))
793 792
794 ;; For CVS files with implicit checkout: if unmodified, don't do anything 793 ;; For CVS files with implicit checkout: if unmodified, don't do anything
795 ((and (eq vc-type 'CVS) 794 ((and (eq vc-type 'CVS)
796 (eq (vc-checkout-model file) 'implicit) 795 (eq (vc-checkout-model file) 'implicit)
865 ;; that in. 864 ;; that in.
866 (if (not (verify-visited-file-modtime (current-buffer))) 865 (if (not (verify-visited-file-modtime (current-buffer)))
867 (if (yes-or-no-p "Replace file on disk with buffer contents? ") 866 (if (yes-or-no-p "Replace file on disk with buffer contents? ")
868 (write-file (buffer-file-name)) 867 (write-file (buffer-file-name))
869 (error "Aborted")) 868 (error "Aborted"))
870 ;; give luser a chance to save before checking in. 869 ;; if buffer is not saved, give user a chance to do it
871 (vc-buffer-sync)) 870 (vc-buffer-sync))
872 871
873 ;; Revert if file is unchanged and buffer is too. 872 ;; Revert if file is unchanged and buffer is too.
874 ;; If buffer is modified, that means the user just said no 873 ;; If buffer is modified, that means the user just said no
875 ;; to saving it; in that case, don't revert, 874 ;; to saving it; in that case, don't revert,
1202 "Complete the operation implied by the current log entry." 1201 "Complete the operation implied by the current log entry."
1203 (interactive) 1202 (interactive)
1204 ;; Check and record the comment, if any. 1203 ;; Check and record the comment, if any.
1205 (if (not nocomment) 1204 (if (not nocomment)
1206 (progn 1205 (progn
1207 (goto-char (point-max))
1208 (if (not (bolp))
1209 (newline))
1210 ;; Comment too long? 1206 ;; Comment too long?
1211 (vc-backend-logentry-check vc-log-file) 1207 (vc-backend-logentry-check vc-log-file)
1212 ;; Record the comment in the comment ring 1208 ;; Record the comment in the comment ring
1213 (ring-insert vc-comment-ring (buffer-string)) 1209 (ring-insert vc-comment-ring (buffer-string))
1214 )) 1210 ))
1486 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$") 1482 "RCSfile\\|Revision\\|Source\\|State\\): [^$\n]+\\$")
1487 nil t) 1483 nil t)
1488 (replace-match "$\\1$"))) 1484 (replace-match "$\\1$")))
1489 (vc-restore-buffer-context context))) 1485 (vc-restore-buffer-context context)))
1490 1486
1487 (defun vc-resolve-conflicts ()
1488 "Invoke ediff to resolve conflicts in the current buffer.
1489 The conflicts must be marked with rcsmerge conflict markers."
1490 (interactive)
1491 (let* ((found nil)
1492 (file-name (file-name-nondirectory buffer-file-name))
1493 (your-buffer (generate-new-buffer
1494 (concat "*" file-name " WORKFILE*")))
1495 (other-buffer (generate-new-buffer
1496 (concat "*" file-name " CHECKED-IN*")))
1497 (result-buffer (current-buffer)))
1498 (save-excursion
1499 (set-buffer your-buffer)
1500 (erase-buffer)
1501 (insert-buffer result-buffer)
1502 (goto-char (point-min))
1503 (while (re-search-forward (concat "^<<<<<<< "
1504 (regexp-quote file-name) "\n") nil t)
1505 (setq found t)
1506 (replace-match "")
1507 (if (not (re-search-forward "^=======\n" nil t))
1508 (error "Malformed conflict marker"))
1509 (replace-match "")
1510 (let ((start (point)))
1511 (if (not (re-search-forward "^>>>>>>> [0-9.]+\n" nil t))
1512 (error "Malformed conflict marker"))
1513 (delete-region start (point))))
1514 (if (not found)
1515 (progn
1516 (kill-buffer your-buffer)
1517 (kill-buffer other-buffer)
1518 (error "No conflict markers found")))
1519 (set-buffer other-buffer)
1520 (erase-buffer)
1521 (insert-buffer result-buffer)
1522 (goto-char (point-min))
1523 (while (re-search-forward (concat "^<<<<<<< "
1524 (regexp-quote file-name) "\n") nil t)
1525 (let ((start (match-beginning 0)))
1526 (if (not (re-search-forward "^=======\n" nil t))
1527 (error "Malformed conflict marker"))
1528 (delete-region start (point))
1529 (if (not (re-search-forward "^>>>>>>> [0-9.]+\n" nil t))
1530 (error "Malformed conflict marker"))
1531 (replace-match "")))
1532 (let ((config (current-window-configuration))
1533 (ediff-default-variant 'default-B))
1534
1535 ;; Fire up ediff.
1536
1537 (set-buffer (ediff-merge-buffers your-buffer other-buffer))
1538
1539 ;; Ediff is now set up, and we are in the control buffer.
1540 ;; Do a few further adjustments and take precautions for exit.
1541
1542 (make-local-variable 'vc-ediff-windows)
1543 (setq vc-ediff-windows config)
1544 (make-local-variable 'vc-ediff-result)
1545 (setq vc-ediff-result result-buffer)
1546 (make-local-variable 'ediff-quit-hook)
1547 (setq ediff-quit-hook
1548 (function
1549 (lambda ()
1550 (let ((buffer-A ediff-buffer-A)
1551 (buffer-B ediff-buffer-B)
1552 (buffer-C ediff-buffer-C)
1553 (result vc-ediff-result)
1554 (windows vc-ediff-windows))
1555 (ediff-cleanup-mess)
1556 (set-buffer result)
1557 (erase-buffer)
1558 (insert-buffer buffer-C)
1559 (kill-buffer buffer-A)
1560 (kill-buffer buffer-B)
1561 (kill-buffer buffer-C)
1562 (set-window-configuration windows)
1563 (message "Conflict resolution finished; you may save the buffer")))))
1564 (message "Please resolve conflicts now; exit ediff when done")
1565 nil))))
1566
1491 ;; The VC directory major mode. Coopt Dired for this. 1567 ;; The VC directory major mode. Coopt Dired for this.
1492 ;; All VC commands get mapped into logical equivalents. 1568 ;; All VC commands get mapped into logical equivalents.
1493 1569
1494 (define-derived-mode vc-dired-mode dired-mode "Dired under VC" 1570 (define-derived-mode vc-dired-mode dired-mode "Dired under VC"
1495 "The major mode used in VC directory buffers. It is derived from Dired. 1571 "The major mode used in VC directory buffers. It is derived from Dired.
1848 ) 1924 )
1849 ) 1925 )
1850 1926
1851 ;;;###autoload 1927 ;;;###autoload
1852 (defun vc-revert-buffer () 1928 (defun vc-revert-buffer ()
1853 "Revert the current buffer's file back to the latest checked-in version. 1929 "Revert the current buffer's file back to the version it was based on.
1854 This asks for confirmation if the buffer contents are not identical 1930 This asks for confirmation if the buffer contents are not identical
1855 to that version. 1931 to that version. Note that for RCS and CVS, this function does not
1856 If the back-end is CVS, this will give you the most recent revision of 1932 automatically pick up newer changes found in the master file;
1857 the file on the branch you are editing." 1933 use C-u \\[vc-next-action] RET to do so."
1858 (interactive) 1934 (interactive)
1859 (if vc-dired-mode 1935 (if vc-dired-mode
1860 (find-file-other-window (dired-get-filename))) 1936 (find-file-other-window (dired-get-filename)))
1861 (while vc-parent-buffer 1937 (while vc-parent-buffer
1862 (pop-to-buffer vc-parent-buffer)) 1938 (pop-to-buffer vc-parent-buffer))
2634 (vc-file-setprop file 'vc-checkout-time 2710 (vc-file-setprop file 'vc-checkout-time
2635 (nth 5 (file-attributes file))))))) 2711 (nth 5 (file-attributes file)))))))
2636 (message "Checking in %s...done" file)) 2712 (message "Checking in %s...done" file))
2637 2713
2638 (defun vc-backend-revert (file) 2714 (defun vc-backend-revert (file)
2639 ;; Revert file to latest checked-in version. 2715 ;; Revert file to the version it was based on.
2640 ;; (for RCS, to workfile version)
2641 (message "Reverting %s..." file) 2716 (message "Reverting %s..." file)
2642 (vc-file-clear-masterprops file) 2717 (vc-file-clear-masterprops file)
2643 (vc-backend-dispatch 2718 (vc-backend-dispatch
2644 file 2719 file
2645 ;; SCCS 2720 ;; SCCS
2646 (progn 2721 (progn
2647 (vc-do-command nil 0 "unget" file 'MASTER nil) 2722 (vc-do-command nil 0 "unget" file 'MASTER nil)
2648 (vc-do-command nil 0 "get" file 'MASTER nil)) 2723 (vc-do-command nil 0 "get" file 'MASTER nil)
2724 ;; Checking out explicit versions is not supported under SCCS, yet.
2725 ;; We always "revert" to the latest version; therefore
2726 ;; vc-workfile-version is cleared here so that it gets recomputed.
2727 (vc-file-setprop 'vc-workfile-version nil))
2649 ;; RCS 2728 ;; RCS
2650 (vc-do-command nil 0 "co" file 'MASTER 2729 (vc-do-command nil 0 "co" file 'MASTER
2651 "-f" (concat "-u" (vc-workfile-version file))) 2730 "-f" (concat "-u" (vc-workfile-version file)))
2652 ;; CVS 2731 ;; CVS
2653 (progn 2732 (progn
2654 (delete-file file) 2733 (delete-file file)
2655 (vc-do-command nil 0 "cvs" file 'WORKFILE "update"))) 2734 (vc-do-command nil 0 "cvs" file 'WORKFILE "update"
2735 (concat "-r" (vc-workfile-version file)))))
2656 (vc-file-setprop file 'vc-locking-user 'none) 2736 (vc-file-setprop file 'vc-locking-user 'none)
2657 (vc-file-setprop file 'vc-checkout-time (nth 5 (file-attributes file))) 2737 (vc-file-setprop file 'vc-checkout-time (nth 5 (file-attributes file)))
2658 (message "Reverting %s...done" file) 2738 (message "Reverting %s...done" file)
2659 ) 2739 )
2660 2740