Try using git-rev-list(1)'s "--count" option before falling back
to a less efficient algorithm.

Signed-off-by: Pieter Praet <[email protected]>
---
 magit-compat.el |  8 ++++++++
 magit.el        | 23 +++++++++++++++--------
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/magit-compat.el b/magit-compat.el
index 43854fc..481df22 100644
--- a/magit-compat.el
+++ b/magit-compat.el
@@ -175,11 +175,13 @@ (defvar-local magit-have-graph 'unset)
 (defvar-local magit-have-decorate 'unset)
 (defvar-local magit-have-abbrev 'unset)
 (defvar-local magit-have-grep-reflog 'unset)
+(defvar-local magit-have-revlist-count 'unset)
 
 (put 'magit-have-graph 'permanent-local t)
 (put 'magit-have-decorate 'permanent-local t)
 (put 'magit-have-abbrev 'permanent-local t)
 (put 'magit-have-grep-reflog 'permanent-local t)
+(put 'magit-have-revlist-count 'permanent-local t)
 
 (defun magit-configure-have-graph ()
   (when (eq magit-have-graph 'unset)
@@ -202,5 +204,11 @@ (defun magit-configure-have-grep-reflog ()
           (= 0 (magit-git-exit-code
                 "log" "--walk-reflogs" "--grep-reflog" "." "-n" "0")))))
 
+(defun magit-configure-have-revlist-count ()
+  (when (eq magit-have-revlist-count 'unset)
+    (setq magit-have-revlist-count
+          (= 0 (magit-git-exit-code
+                "rev-list" "--count" "--left-right" "HEAD")))))
+
 (provide 'magit-compat)
 ;;; magit-compat.el ends here
diff --git a/magit.el b/magit.el
index 482863a..e51fd26 100644
--- a/magit.el
+++ b/magit.el
@@ -1283,14 +1283,21 @@ (defun magit-ref-ambiguous-p (ref)
 (defun magit-rev-diff-count (a b)
   "Return the commits in A but not B and vice versa.
 Return a list of two integers: (A>B B>A)."
-  ;; Kludge.  git < 1.7.2 does not support git rev-list --count
-  (let ((ac 0) (bc 0))
-    (dolist (commit (magit-git-lines "rev-list" "--left-right"
-                                     (concat a "..." b)))
-      (cl-case (aref commit 0)
-        (?\< (cl-incf ac))
-        (?\> (cl-incf bc))))
-    (list ac bc)))
+  (magit-configure-have-revlist-count)
+  (if magit-have-revlist-count
+      (mapcar 'string-to-number
+              (split-string (magit-git-string "rev-list"
+                                              "--count" "--left-right"
+                                              (concat a "..." b))
+                            "\t"))
+    ;; Kludge.  git < 1.7.2 does not support git rev-list --count
+    (let ((ac 0) (bc 0))
+      (dolist (commit (magit-git-lines "rev-list" "--left-right"
+                                       (concat a "..." b)))
+        (cl-case (aref commit 0)
+                 (?\< (cl-incf ac))
+                 (?\> (cl-incf bc))))
+      (list ac bc))))
 
 (defun magit-name-rev (rev &optional no-trim)
   "Return a human-readable name for REV.
-- 
1.7.11.1

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"magit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to