changeset 87844:3bd7c8c8bbe7

* vc.el: Make vc-status asynchronous. (vc-update-vc-status-buffer): New function broken out of ... (vc-status-refresh): ... here. Pass vc-update-vc-status-buffer to the dir-status backend function. * vc-hg.el (vc-hg-dir-status): Compute the status asynchronously. Move the output processing to ... (vc-hg-after-dir-status): ... here. Call the function passed as an argument with the results.
author Dan Nicolaescu <dann@ics.uci.edu>
date Fri, 18 Jan 2008 23:32:58 +0000
parents e1d6c4e34d2c
children 800f4ac6c848
files lisp/ChangeLog lisp/vc-hg.el lisp/vc.el
diffstat 3 files changed, 51 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Fri Jan 18 22:50:17 2008 +0000
+++ b/lisp/ChangeLog	Fri Jan 18 23:32:58 2008 +0000
@@ -1,3 +1,15 @@
+2008-01-18  Dan Nicolaescu  <dann@ics.uci.edu>
+
+	* vc.el: Make vc-status asynchronous.
+	(vc-update-vc-status-buffer): New function broken out of ...
+	(vc-status-refresh): ... here. Pass vc-update-vc-status-buffer to
+	the dir-status backend function.
+
+	* vc-hg.el (vc-hg-dir-status): Compute the status asynchronously.
+	Move the output processing to ...
+	(vc-hg-after-dir-status): ... here.  Call the function passed as
+	an argument with the results.
+
 2008-01-18  Stefan Monnier  <monnier@iro.umontreal.ca>
 
 	* doc-view.el (doc-view-pdf/ps->png): Make sure we a have a valid cwd.
--- a/lisp/vc-hg.el	Fri Jan 18 22:50:17 2008 +0000
+++ b/lisp/vc-hg.el	Fri Jan 18 23:32:58 2008 +0000
@@ -480,35 +480,41 @@
 
 (define-derived-mode vc-hg-incoming-mode vc-hg-log-view-mode "Hg-Incoming")
 
-
 ;; XXX Experimental function for the vc-dired replacement.
-(defun vc-hg-dir-status (dir)
-  "Return a list of conses (file . state) for DIR."
-  (with-temp-buffer
-    (vc-hg-command (current-buffer) nil dir "status")
-    (goto-char (point-min))
-    (let ((status-char nil)
-	  (file nil)
-	  (translation '((?= . up-to-date)
-			 (?C . up-to-date)
-			 (?A . added)
-			 (?R . removed)
-			 (?M . edited)
-			 (?I . ignored)
-			 (?! . deleted)
-			 (?? . unregistered)))
-	  (translated nil)
+(defun vc-hg-after-dir-status (update-function buff)
+  (let ((status-char nil)
+	(file nil)
+	(translation '((?= . up-to-date)
+		       (?C . up-to-date)
+		       (?A . added)
+		       (?R . removed)
+		       (?M . edited)
+		       (?I . ignored)
+		       (?! . deleted)
+		       (?? . unregistered)))
+	(translated nil)
 	  (result nil))
+      (goto-char (point-min))
       (while (not (eobp))
 	(setq status-char (char-after))
 	(setq file 
 	      (buffer-substring-no-properties (+ (point) 2) 
-					       (line-end-position)))
+					      (line-end-position)))
 	(setq translated (assoc status-char translation))
 	(when (and translated (not (eq (cdr translated) 'up-to-date)))
 	  (push (cons file (cdr translated)) result))
 	(forward-line))
-      result)))
+      (funcall update-function result buff)))
+
+;; XXX Experimental function for the vc-dired replacement.
+(defun vc-hg-dir-status (dir update-function status-buffer)
+  "Return a list of conses (file . state) for DIR."
+  (with-current-buffer
+      (get-buffer-create
+       (expand-file-name " *VC-hg* tmp status" dir))
+    (vc-hg-command (current-buffer) 'async dir "status")
+    (vc-exec-after 
+     `(vc-hg-after-dir-status (quote ,update-function) ,status-buffer))))
 
 ;; XXX this adds another top level menu, instead figure out how to
 ;; replace the Log-View menu.
--- a/lisp/vc.el	Fri Jan 18 22:50:17 2008 +0000
+++ b/lisp/vc.el	Fri Jan 18 23:32:58 2008 +0000
@@ -544,8 +544,6 @@
 ;;
 ;; - decide if vc-status should replace vc-dired.
 ;;
-;; - vc-status should be made asynchronous.
-;;
 ;; - vc-status needs a menu, mouse bindings and some color bling.
 
 ;;; Code:
@@ -2622,16 +2620,26 @@
 
 (put 'vc-status-mode 'mode-class 'special)
 
+(defun vc-update-vc-status-buffer (entries buffer)
+  (with-current-buffer buffer
+    (dolist (entry entries)
+      (ewoc-enter-last vc-status
+		       (vc-status-create-fileinfo (cdr entry) (car entry))))
+    (ewoc-goto-node vc-status (ewoc-nth vc-status 0))))
+
 (defun vc-status-refresh ()
   "Refresh the contents of the VC status buffer."
   (interactive)
   ;; This is not very efficient; ewoc could use a new function here.
   (ewoc-filter vc-status (lambda (node) nil))
   (let ((backend (vc-responsible-backend default-directory)))
-    (dolist (entry (vc-call-backend backend 'dir-status default-directory))
-      (ewoc-enter-last vc-status
-		       (vc-status-create-fileinfo (cdr entry) (car entry)))))
-  (ewoc-goto-node vc-status (ewoc-nth vc-status 0)))
+    ;; Call the dir-status backend function. dir-status is supposed to
+    ;; be asynchronous.  It should compute the results and call the
+    ;; function passed as a an arg to update the vc-status buffer with
+    ;; the results.
+    (vc-call-backend 
+     backend 'dir-status default-directory 
+     #'vc-update-vc-status-buffer (current-buffer))))
 
 (defun vc-status-next-line (arg)
   "Go to the next line.