Patchwork [4,of,4,V2] revset: make balanced addsets by orset() without using _combinesets()

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 7, 2015, 2:45 p.m.
Message ID <97c73a40e9dc09c49d73.1438958747@mimosa>
Download mbox | patch
Permalink /patch/10133/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 7, 2015, 2:45 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1436068209 -32400
#      Sun Jul 05 12:50:09 2015 +0900
# Node ID 97c73a40e9dc09c49d732fc79bffad38d520d01a
# Parent  fd7a0e50142b8d933be19414ac55b57dbd5e4612
revset: make balanced addsets by orset() without using _combinesets()

As scmutil.revrange() was rewritten to not use _combinesets(), we no longer
need _combinesets().
Pierre-Yves David - Aug. 10, 2015, 7 a.m.
On 08/07/2015 07:45 AM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1436068209 -32400
> #      Sun Jul 05 12:50:09 2015 +0900
> # Node ID 97c73a40e9dc09c49d732fc79bffad38d520d01a
> # Parent  fd7a0e50142b8d933be19414ac55b57dbd5e4612
> revset: make balanced addsets by orset() without using _combinesets()

I'm happy to see this code removed :)

Pushed to the clowncopter.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -406,8 +406,13 @@  def andset(repo, subset, x, y):
     return getset(repo, getset(repo, subset, x), y)
 
 def orset(repo, subset, *xs):
-    rs = [getset(repo, subset, x) for x in xs]
-    return _combinesets(rs)
+    assert xs
+    if len(xs) == 1:
+        return getset(repo, subset, xs[0])
+    p = len(xs) // 2
+    a = orset(repo, subset, *xs[:p])
+    b = orset(repo, subset, *xs[p:])
+    return a + b
 
 def notset(repo, subset, x):
     return subset - getset(repo, subset, x)
@@ -3107,20 +3112,6 @@  class filteredset(abstractsmartset):
     def __repr__(self):
         return '<%s %r>' % (type(self).__name__, self._subset)
 
-# this function will be removed, or merged to addset or orset, when
-# - scmutil.revrange() can be rewritten to not combine calculated smartsets
-# - or addset can handle more than two sets without balanced tree
-def _combinesets(subsets):
-    """Create balanced tree of addsets representing union of given sets"""
-    if not subsets:
-        return baseset()
-    if len(subsets) == 1:
-        return subsets[0]
-    p = len(subsets) // 2
-    xs = _combinesets(subsets[:p])
-    ys = _combinesets(subsets[p:])
-    return addset(xs, ys)
-
 def _iterordered(ascending, iter1, iter2):
     """produce an ordered iteration from two iterators with the same order