[PATCH 2 of 3] branchpoint: remove useless intermediate set creation

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Mon Oct 15 10:46:16 CDT 2012

# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1350315785 -7200
# Node ID 69277501dded5fc462e7db857c8df09fd7edcd2d
# Parent  c3eb9666d9fb25fa7c23410075390923e587ba9d
branchpoint: remove useless intermediate set creation

We don't need to compute the set of all branchpoints. We can just check the
number of children that element of subset have. The extra work did not seems to
had particular performance impact but the code is simpler this way.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -931,13 +931,11 @@ def branchpoint(repo, subset, x):
     parentscount = [0]*(len(repo) - baserev)
     for r in cl.revs(start=baserev + 1):
         for p in cl.parentrevs(r):
             if p >= baserev:
                 parentscount[p - baserev] += 1
-    branchpoints = set((baserev + i) for i in xrange(len(parentscount))
-                       if parentscount[i] > 1)
-    return [r for r in subset if r in branchpoints]
+    return [r for r in subset if (parentscount[r - baserev] > 1)]
 def minrev(repo, subset, x):
     Changeset with lowest revision number in set.

More information about the Mercurial-devel mailing list