[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Patch to make VC annotate async
From: |
Tom Tromey |
Subject: |
Patch to make VC annotate async |
Date: |
Sat, 23 Jun 2007 20:32:11 -0600 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.990 (gnu/linux) |
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 <address@hidden>
* 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.
- Patch to make VC annotate async,
Tom Tromey <=