# HG changeset patch # User Pierre-Yves David # Date 2015-01-07 00:40:33 # Node ID 07d0f59e0ba7a9992d203868528c48694f826b19 # Parent e97e363a7000817dcad4d05caddfbbec44dfc897 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. diff --git a/mercurial/setdiscovery.py b/mercurial/setdiscovery.py --- a/mercurial/setdiscovery.py +++ b/mercurial/setdiscovery.py @@ -74,8 +74,6 @@ def _updatesample(dag, nodes, sample, al 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 @@ def findcommonheads(ui, local, remote, 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'))