setdiscovery: avoid calling any sample building if the undecided set is small
authorPierre-Yves David <pierre-yves.david@fb.com>
Tue, 06 Jan 2015 16:40:33 -0800
changeset 23808 07d0f59e0ba7
parent 23807 e97e363a7000
child 23809 9ca2eb881b53
setdiscovery: avoid calling any sample building if the undecided set is small If the length of undecided is smaller than the sample size, we can just request information for all of them. This conditional was previously handled by '_setupsample'. But '_setupsample' is in my opinion a problematic function with blurry semantics. Having this conditional explicitly earlier makes the code more explicit and moves us closer to removing this '_setupsample' function.
mercurial/setdiscovery.py
--- a/mercurial/setdiscovery.py	Wed Jan 07 09:30:06 2015 -0800
+++ b/mercurial/setdiscovery.py	Tue Jan 06 16:40:33 2015 -0800
@@ -74,8 +74,6 @@
                 visit.append(p)
 
 def _setupsample(dag, nodes, size):
-    if len(nodes) <= size:
-        return set(nodes), None, 0
     always = dag.headsetofconnecteds(nodes)
     desiredlen = size - len(always)
     if desiredlen <= 0:
@@ -205,8 +203,11 @@
             ui.debug("taking quick initial sample\n")
             samplefunc = _takequicksample
             targetsize = initialsamplesize
-        sample = samplefunc(dag, undecided, targetsize)
-        sample = _limitsample(sample, targetsize)
+        if len(undecided) < targetsize:
+            sample = list(undecided)
+        else:
+            sample = samplefunc(dag, undecided, targetsize)
+            sample = _limitsample(sample, targetsize)
 
         roundtrips += 1
         ui.progress(_('searching'), roundtrips, unit=_('queries'))