[PATCH 6 of 6 V2] revsbetween: default to the C implementation

Laurent Charignon lcharignon at fb.com
Fri Aug 7 04:28:23 CDT 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1438924280 25200
#      Thu Aug 06 22:11:20 2015 -0700
# Branch stable
# Node ID a66356f153c7362060de0c13b5a06f2f76082a00
# Parent  25bd9ea0726e9f9f56d105f136a0bcd07631d24a
revsbetween: default to the C implementation

This patch is part of a series of patches to speed up the computation of
revset.revsbetween by introducing a C implementation. The main motivation is to
speed up smartlog on big repositories. At the end of the series, on our big
repositories the computation of revsbetween is 10-50x faster and smartlog on is
2x-5x faster.

Before this patch, revsbetween was computed in pure Python by default. This
patch makes the C implementation the default and provides a speedup for
revsbetween.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -78,19 +78,13 @@
 
     return generatorset(iterate(), iterasc=True)
 
-def revsbetween(repo, roots, heads, includepath=True):
-    """Return all paths between roots and heads, inclusive of both endpoint
-    sets."""
-    if not roots:
-        return baseset()
+def revsbetweenpure(repo, minroot, roots, heads, includepath):
     parentrevs = repo.changelog.parentrevs
     visit = list(heads)
     reachable = set()
     seen = {}
     # XXX this should be 'parentset.min()' assuming 'parentset' is a smartset
     # (and if it is not, it should.)
-    minroot = min(roots)
-    roots = set(roots)
     # prefetch all the things! (because python is slow)
     reached = reachable.add
     dovisit = visit.append
@@ -118,6 +112,19 @@
                 reached(rev)
     return baseset(sorted(reachable))
 
+def revsbetween(repo, roots, heads, includepath=True):
+    """Return all paths between roots and heads, inclusive of both endpoint
+    sets."""
+    if not roots:
+        return baseset()
+    minroot = min(roots)
+    roots = set(roots)
+    heads = list(heads)
+    try:
+        return repo.changelog.revsbetween(minroot, heads, roots, includepath)
+    except AttributeError:
+        return revsbetweenpure(repo, minroot, roots, heads, includepath)
+
 elements = {
     # token-type: binding-strength, primary, prefix, infix, suffix
     "(": (21, None, ("group", 1, ")"), ("func", 1, ")"), None),


More information about the Mercurial-devel mailing list