[PATCH 1 of 5] revset: adds onlyroots argument to revsbetween

Laurent Charignon lcharignon at fb.com
Fri Aug 7 06:10:19 UTC 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1434770334 25200
#      Fri Jun 19 20:18:54 2015 -0700
# Branch stable
# Node ID dd83ca8e712cec7331a8418600da7c5a8b8cfed0
# Parent  79f0cb97d7537a7c2948f8f9b0a89148825a3a1d
revset: adds onlyroots argument to revsbetween

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.

This patch adds a new argument to revsbetween called onlyroots. This allows us
to compute grandparent with revsbetween and remove the code of grandparent in
the next patch.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -78,7 +78,7 @@
 
     return generatorset(iterate(), iterasc=True)
 
-def _revsbetween(repo, roots, heads):
+def _revsbetween(repo, roots, heads, onlyroots=False):
     """Return all paths between roots and heads, inclusive of both endpoint
     sets."""
     if not roots:
@@ -101,6 +101,8 @@
         rev = nextvisit()
         if rev in roots:
             reached(rev)
+            if onlyroots:
+                continue
         parents = parentrevs(rev)
         seen[rev] = parents
         for parent in parents:
@@ -108,6 +110,8 @@
                 dovisit(parent)
     if not reachable:
         return baseset()
+    if onlyroots:
+        return reachable
     for rev in sorted(seen):
         for parent in seen[rev]:
             if parent in reachable:


More information about the Mercurial-devel mailing list