changeset 94800:1f66528f35c3

(vc-dispatcher-browsing): Use derived-mode-p. (vc-dir-prepare-status-buffer): Use vc-dispatcher-browsing. (vc-dispatcher-in-fileset-p): New fun. (vc-dispatcher-selection-set): Use it to properly handle directories.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 09 May 2008 15:30:47 +0000
parents b80a6e243f4c
children 4a0c0906cc91
files lisp/ChangeLog lisp/vc-dispatcher.el
diffstat 2 files changed, 25 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Fri May 09 09:42:46 2008 +0000
+++ b/lisp/ChangeLog	Fri May 09 15:30:47 2008 +0000
@@ -1,3 +1,10 @@
+2008-05-09  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* vc-dispatcher.el (vc-dispatcher-browsing): Use derived-mode-p.
+	(vc-dir-prepare-status-buffer): Use vc-dispatcher-browsing.
+	(vc-dispatcher-in-fileset-p): New fun.
+	(vc-dispatcher-selection-set): Use it to properly handle directories.
+
 2008-05-09  Dan Nicolaescu  <dann@ics.uci.edu>
 
 	* vc.el (vc-version-diff, vc-print-log, vc-revert, vc-rollback)
--- a/lisp/vc-dispatcher.el	Fri May 09 09:42:46 2008 +0000
+++ b/lisp/vc-dispatcher.el	Fri May 09 15:30:47 2008 +0000
@@ -671,7 +671,7 @@
 		(unless create-new
 		  (dolist (buffer (buffer-list))
 		    (set-buffer buffer)
-		    (when (and (eq major-mode 'vc-dir-mode)
+		    (when (and (vc-dispatcher-browsing)
 			       (string= (expand-file-name default-directory) dir))
 		      (return buffer)))))))
     (or buf
@@ -1326,7 +1326,17 @@
 
 (defun vc-dispatcher-browsing ()
   "Are we in a directory browser buffer?"
-  (eq major-mode 'vc-dir-mode))
+  (derived-mode-p 'vc-dir-mode))
+
+(defun vc-dispatcher-in-fileset-p (fileset)
+  (let ((member nil))
+    (while (and (not member) fileset)
+      (let ((elem (pop fileset)))
+        (if (if (file-directory-p elem)
+                (eq t (compare-strings buffer-file-name nil (length elem)
+                                       elem nil nil))
+              (eq (current-buffer) (get-file-buffer elem)))
+            (setq member t))))))
 
 (defun vc-dispatcher-selection-set ()
   "Deduce a set of files to which to apply an operation. Return the fileset.
@@ -1350,31 +1360,13 @@
 			    (vc-dispatcher-selection-set)))
      ;; No good set here, throw error
      (t (error "No fileset is available here.")))))
-    ;; We assume, in order to avoid unpleasant surprises to the user, 
-    ;; that a fileset is not in good shape to be handed to the user if the  
+    ;; We assume, in order to avoid unpleasant surprises to the user,
+    ;; that a fileset is not in good shape to be handed to the user if the
     ;; buffers visiting the fileset don't match the on-disk contents.
-    (dolist (file files)
-      (let ((visited (get-file-buffer file)))
-	(when visited
-	  (if (vc-dispatcher-browsing)
-	      (switch-to-buffer-other-window visited)
-	    (set-buffer visited))
-	  ;; Check relation of buffer and file, and make sure
-	  ;; user knows what he's doing.  First, finding the file
-	  ;; will check whether the file on disk is newer.
-	  ;; Ignore buffer-read-only during this test, and
-	  ;; preserve find-file-literally.
-	  (let ((buffer-read-only (not (file-writable-p file))))
-	    (find-file-noselect file nil find-file-literally))
-	  (if (not (verify-visited-file-modtime (current-buffer)))
-	      (if (yes-or-no-p (format "Replace %s on disk with buffer contents? " file))
-		  (write-file buffer-file-name)
-		(error "Aborted"))
-	    ;; Now, check if we have unsaved changes.
-	    (vc-buffer-sync t)
-	    (when (buffer-modified-p)
-	      (or (y-or-n-p (message "Use %s on disk, keeping modified buffer? " file))
-		  (error "Aborted")))))))
+    ;; This is actually untrue for operations like `print-log' (or `diff'
+    ;; between two revisions), so maybe this should be moved elsewhere.
+    (save-some-buffers
+     nil (lambda () (vc-dispatcher-in-fileset-p fileset)))
     files))
 
 ;; arch-tag: 7d08b17f-5470-4799-914b-bfb9fcf6a246