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

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 5, 2015, 2:44 p.m.
Message ID <32b8d5e5be5e93886878.1438785863@mimosa>
Download mbox | patch
Permalink /patch/10107/
State Superseded
Commit 289149111d46cf8d243e0290bf81949078032fd9
Headers show

Comments

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

As scmutil.revrange() was rewritten to not use _combinesets(), we no longer
need _combinesets().

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)
@@ -3098,20 +3103,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