all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Patch to make VC annotate async
@ 2007-06-24  2:32 Tom Tromey
  2007-06-24 17:35 ` Richard Stallman
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Tom Tromey @ 2007-06-24  2:32 UTC (permalink / raw)
  To: Emacs Hackers

This patch changes the VC annotate command to allow back ends to run
annotation in the background.  It also changes the CVS back end to do
this.

I was initially inspired to write this patch because "svn annotate"
can be rather slow, and I didn't want to wait for it to complete.
However, it turns out that changing vc-svn.el to annotate in the
background does not work -- in my test case (a file in GCC), the
annotation is truncated before the end of the file.  I'm not sure what
is going on here.

A couple other back ends (hg and mcvs) could be changed to use code
similar to the CVS code below.  I didn't attempt this.

Tom


2007-06-24  Tom Tromey  <tromey@redhat.com>

	* vc.el (vc-annotate-display-select): Don't pop to buffer if one
	is specified.
	(vc-annotate): Run vc-annotate-display-select via vc-exec-after.
	* vc-cvs.el (vc-cvs-annotate-output): New variable.
	(vc-cvs-annotate-process-filter): New function.
	(vc-cvs-annotate-command): Run command async.  Use
	vc-cvs-annotate-process-filter.

Index: vc-cvs.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/vc-cvs.el,v
retrieving revision 1.80
diff -u -r1.80 vc-cvs.el
--- vc-cvs.el	21 Jan 2007 03:53:10 -0000	1.80
+++ vc-cvs.el	24 Jun 2007 02:23:00 -0000
@@ -153,6 +153,8 @@
 ;;; Internal variables
 ;;;
 
+;; Collects initial 'cvs annotate' output.
+(defvar vc-cvs-annotate-output nil)
 
 ;;;
 ;;; State-querying functions
@@ -588,14 +590,33 @@
                (and rev2 (concat "-r" rev2))
                (vc-switches 'CVS 'diff))))))
 
+(defun vc-cvs-annotate-process-filter (process string)
+  (setq vc-cvs-annotate-output (concat vc-cvs-annotate-output string))
+  (let ((list (split-string vc-cvs-annotate-output "\n")))
+    (if (equal (substring vc-cvs-annotate-output -1) "\n")
+	(setq vc-cvs-annotate-output "")
+      ;; If input doesn't end with \n, don't use the last list
+      ;; element.
+      (setq vc-cvs-annotate-output (car (last list)))
+      (setq list (nreverse (cdr (nreverse list)))))
+    (while (and list
+		(not (string-match "^[0-9]" (car list))))
+      (setq list (cdr list)))
+    ;; If there is a list element remaining, it means we saw the first
+    ;; line we want to insert.  Reset the process filter and continue.
+    (when list
+      (set-process-filter process 'vc-process-filter)
+      (mapc (lambda (line) (vc-process-filter process (concat line "\n"))) list)
+      (vc-process-filter process vc-cvs-annotate-output))))
+
 (defun vc-cvs-annotate-command (file buffer &optional version)
   "Execute \"cvs annotate\" on FILE, inserting the contents in BUFFER.
 Optional arg VERSION is a version to annotate from."
-  (vc-cvs-command buffer 0 file "annotate" (if version (concat "-r" version)))
-  (with-current-buffer buffer
-    (goto-char (point-min))
-    (re-search-forward "^[0-9]")
-    (delete-region (point-min) (1- (point)))))
+  (vc-cvs-command buffer 'async file "annotate"
+		  (if version (concat "-r" version)))
+  (set (make-local-variable 'vc-cvs-annotate-output) "")
+  (set-process-filter (get-buffer-process buffer)
+		      'vc-cvs-annotate-process-filter))
 
 (defun vc-cvs-annotate-current-time ()
   "Return the current time, based at midnight of the current day, and
Index: vc.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/vc.el,v
retrieving revision 1.428
diff -u -r1.428 vc.el
--- vc.el	20 Jun 2007 16:32:09 -0000	1.428
+++ vc.el	24 Jun 2007 02:23:04 -0000
@@ -3099,7 +3099,8 @@
 use; you may override this using the second optional arg MODE."
   (interactive)
   (if mode (setq vc-annotate-display-mode mode))
-  (pop-to-buffer (or buffer (current-buffer)))
+  ;; If BUFFER is set then we've already popped to it.
+  (unless buffer (pop-to-buffer (current-buffer)))
   (cond ((null vc-annotate-display-mode)
          ;; The ratio is global, thus relative to the global color-map.
          (kill-local-variable 'vc-annotate-color-map)
@@ -3159,7 +3160,6 @@
   (vc-ensure-vc-buffer)
   (setq vc-annotate-display-mode display-mode) ;Not sure why.  --Stef
   (let* ((temp-buffer-name (format "*Annotate %s (rev %s)*" (buffer-name) rev))
-         (temp-buffer-show-function 'vc-annotate-display-select)
          ;; If BUF is specified, we presume the caller maintains current line,
          ;; so we don't need to do it here.  This implementation may give
          ;; strange results occasionally in the case of REV != WORKFILE-REV.
@@ -3184,10 +3184,15 @@
         (set (make-local-variable 'vc-annotate-parent-file) file)
         (set (make-local-variable 'vc-annotate-parent-rev) rev)
         (set (make-local-variable 'vc-annotate-parent-display-mode)
-             display-mode)))
-    (when current-line
-      (goto-line current-line temp-buffer-name))
-    (message "Annotating... done")))
+             display-mode)
+
+	(vc-exec-after
+	 `(progn
+	    (vc-annotate-display-select ,(current-buffer))
+	    (when ,current-line
+	      (goto-line ,current-line ,temp-buffer-name))
+	    (unless (active-minibuffer-window)
+	      (message "Annotating... done"))))))))
 
 (defun vc-annotate-prev-version (prefix)
   "Visit the annotation of the version previous to this one.

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2007-07-12  3:15 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-24  2:32 Patch to make VC annotate async Tom Tromey
2007-06-24 17:35 ` Richard Stallman
2007-06-24 18:05   ` Tom Tromey
2007-06-24 23:47     ` Richard Stallman
2007-06-24 19:33 ` Stefan Monnier
2007-06-24 21:32   ` Tom Tromey
2007-06-25  1:34     ` Stefan Monnier
2007-06-25 15:24       ` Tom Tromey
2007-06-25 16:54         ` Stefan Monnier
2007-06-25 17:53           ` Tom Tromey
2007-06-26 17:48       ` Stefan Monnier
2007-07-07 21:06 ` Stefan Monnier
2007-07-09 15:12   ` Tom Tromey
2007-07-09 19:09     ` David Kastrup
2007-07-11 16:02       ` Tom Tromey
2007-07-12  3:15         ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.