comparison lisp/vc.el @ 95326:23822423eb64

(vc-deduce-fileset): Replace implementation with one based on a working older version. (vc-next-action): Use the new form of vc-deduce-fileset. Fix dealing with unregistered files.
author Dan Nicolaescu <dann@ics.uci.edu>
date Tue, 27 May 2008 00:18:35 +0000
parents da0363084105
children 257f10afe123
comparison
equal deleted inserted replaced
95325:da0363084105 95326:23822423eb64
645 ;; vc will bombs out because it wants to see the file being in CVS. 645 ;; vc will bombs out because it wants to see the file being in CVS.
646 ;; Those logs should likely use a local variable to hardware the VC they 646 ;; Those logs should likely use a local variable to hardware the VC they
647 ;; are supposed to work with. 647 ;; are supposed to work with.
648 ;; 648 ;;
649 ;;;; Problems: 649 ;;;; Problems:
650 ;;
651 ;; - log-view-diff does not work anymore in the case when the log was
652 ;; created from more than one file. The error is:
653 ;; vc-derived-from-dir-mode: Lisp nesting exceeds `max-lisp-eval-depth'.
654 ;; 650 ;;
655 ;; - the *vc-dir* buffer is not updated correctly anymore after VC 651 ;; - the *vc-dir* buffer is not updated correctly anymore after VC
656 ;; operations that change the file state. 652 ;; operations that change the file state.
657 ;; 653 ;;
658 ;;; Code: 654 ;;; Code:
993 (let ((buffer (or buffer (current-buffer)))) 989 (let ((buffer (or buffer (current-buffer))))
994 (cond ((derived-mode-p 'vc-dir-mode) t) 990 (cond ((derived-mode-p 'vc-dir-mode) t)
995 (vc-parent-buffer (vc-derived-from-dir-mode vc-parent-buffer)) 991 (vc-parent-buffer (vc-derived-from-dir-mode vc-parent-buffer))
996 (t nil)))) 992 (t nil))))
997 993
998 (defun vc-deduce-fileset (&optional observer) 994 (defvar vc-dir-backend nil
999 "Deduce a set of files and a backend to which to apply an operation and 995 "The backend used by the current *vc-dir* buffer.")
1000 the common state of the fileset. Return (BACKEND . FILESET)." 996
1001 (let* ((selection (vc-dispatcher-selection-set observer)) 997 ;; FIXME: this is not functional, commented out.
1002 (raw (car selection)) ;; Selection as user made it 998 ;; (defun vc-deduce-fileset (&optional observer)
1003 (cooked (cdr selection)) ;; Files only 999 ;; "Deduce a set of files and a backend to which to apply an operation and
1004 ;; FIXME: Store the backend in a buffer-local variable. 1000 ;; the common state of the fileset. Return (BACKEND . FILESET)."
1005 (backend (if (vc-derived-from-dir-mode (current-buffer)) 1001 ;; (let* ((selection (vc-dispatcher-selection-set observer))
1006 ;; FIXME: this should use vc-dir-backend from 1002 ;; (raw (car selection)) ;; Selection as user made it
1007 ;; the *vc-dir* buffer. 1003 ;; (cooked (cdr selection)) ;; Files only
1008 (vc-responsible-backend default-directory) 1004 ;; ;; FIXME: Store the backend in a buffer-local variable.
1009 (assert (and (= 1 (length raw)) 1005 ;; (backend (if (vc-derived-from-dir-mode (current-buffer))
1010 (not (file-directory-p (car raw))))) 1006 ;; ;; FIXME: this should use vc-dir-backend from
1011 (vc-backend (car cooked))))) 1007 ;; ;; the *vc-dir* buffer.
1012 (cons backend selection))) 1008 ;; (vc-responsible-backend default-directory)
1009 ;; (assert (and (= 1 (length raw))
1010 ;; (not (file-directory-p (car raw)))))
1011 ;; (vc-backend (car cooked)))))
1012 ;; (cons backend selection)))
1013
1014 (defun vc-deduce-fileset (&optional observer allow-unregistered)
1015 "Deduce a set of files and a backend to which to apply an operation.
1016
1017 Return (BACKEND FILESET FILESET_ONLY_FILES).
1018 If we're in VC-dir mode, the fileset is the list of marked files.
1019 Otherwise, if we're looking at a buffer visiting a version-controlled file,
1020 the fileset is a singleton containing this file.
1021 If none of these conditions is met, but ALLOW_UNREGISTERED is on and the
1022 visited file is not registered, return a singleton fileset containing it.
1023 Otherwise, throw an error."
1024 ;; FIXME: OBSERVER is unused. The name is not intuitive and is not
1025 ;; documented.
1026 (let (backend)
1027 (cond
1028 ((derived-mode-p 'vc-dir-mode)
1029 (let ((marked (vc-dir-marked-files)))
1030 (if marked
1031 (list vc-dir-backend marked (vc-dir-marked-only-files))
1032 (let ((crt (vc-dir-current-file)))
1033 (list vc-dir-backend (list crt) (vc-dir-child-files))))))
1034 ((setq backend (vc-backend buffer-file-name))
1035 (list backend (list buffer-file-name) (list buffer-file-name)))
1036 ((and vc-parent-buffer (or (buffer-file-name vc-parent-buffer)
1037 (with-current-buffer vc-parent-buffer
1038 (eq major-mode 'vc-dir-mode))))
1039 (progn
1040 (set-buffer vc-parent-buffer)
1041 (vc-deduce-fileset)))
1042 ((and allow-unregistered (not (vc-registered buffer-file-name)))
1043 (list (vc-responsible-backend
1044 (file-name-directory (buffer-file-name)))
1045 (list buffer-file-name) (list buffer-file-name)))
1046 (t (error "No fileset is available here.")))))
1013 1047
1014 (defun vc-ensure-vc-buffer () 1048 (defun vc-ensure-vc-buffer ()
1015 "Make sure that the current buffer visits a version-controlled file." 1049 "Make sure that the current buffer visits a version-controlled file."
1016 (cond 1050 (cond
1017 ((vc-dispatcher-browsing) 1051 ((vc-dispatcher-browsing)
1077 message has been entered, it checks in the resulting changes along 1111 message has been entered, it checks in the resulting changes along
1078 with the logmessage as change commentary. A writable file is retained. 1112 with the logmessage as change commentary. A writable file is retained.
1079 If the repository file is changed, you are asked if you want to 1113 If the repository file is changed, you are asked if you want to
1080 merge in the changes into your working copy." 1114 merge in the changes into your working copy."
1081 (interactive "P") 1115 (interactive "P")
1082 (let* ((vc-fileset (vc-deduce-fileset)) 1116 (let* ((vc-fileset (vc-deduce-fileset nil t))
1083 (backend (car vc-fileset)) 1117 (backend (car vc-fileset))
1084 (files (cadr vc-fileset)) 1118 (files (nth 1 vc-fileset))
1085 (fileset-only-files (cddr vc-fileset)) 1119 (fileset-only-files (nth 2 vc-fileset))
1086 ;; FIXME: We used to call `vc-recompute-state' here. 1120 ;; FIXME: We used to call `vc-recompute-state' here.
1087 (state (vc-state (car fileset-only-files))) 1121 (state (vc-state (car fileset-only-files)))
1088 ;; The backend should check that the checkout-model is consistent 1122 ;; The backend should check that the checkout-model is consistent
1089 ;; among all the `files'. 1123 ;; among all the `files'.
1090 (model (vc-checkout-model backend files)) 1124 (model
1125 ;; FIXME: This is not very elegant...
1126 (when (and state (not (eq state 'unregistered)))
1127 (vc-checkout-model backend files)))
1091 revision) 1128 revision)
1092 1129
1093 ;; Check that all files are in a consistent state, since we use that 1130 ;; Check that all files are in a consistent state, since we use that
1094 ;; state to decide which operation to perform. 1131 ;; state to decide which operation to perform.
1095 (dolist (file (cdr fileset-only-files)) 1132 (dolist (file (cdr fileset-only-files))
1101 (cond 1138 (cond
1102 ((eq state 'missing) 1139 ((eq state 'missing)
1103 (error "Fileset files are missing, so cannot be operated on.")) 1140 (error "Fileset files are missing, so cannot be operated on."))
1104 ((eq state 'ignored) 1141 ((eq state 'ignored)
1105 (error "Fileset files are ignored by the version-control system.")) 1142 (error "Fileset files are ignored by the version-control system."))
1106 ((eq state 'unregistered) 1143 ((or (null state) (eq state 'unregistered))
1107 (mapc (lambda (arg) (vc-register nil arg)) files)) 1144 (mapc (lambda (arg) (vc-register nil arg)) files))
1108 ;; Files are up-to-date, or need a merge and user specified a revision 1145 ;; Files are up-to-date, or need a merge and user specified a revision
1109 ((or (eq state 'up-to-date) (and verbose (eq state 'needs-update))) 1146 ((or (eq state 'up-to-date) (and verbose (eq state 'needs-update)))
1110 (cond 1147 (cond
1111 (verbose 1148 (verbose