discovery: move handling of sampling special case inside sampling function
authorBoris Feld <boris.feld@octobus.net>
Fri, 14 Dec 2018 12:01:15 +0100
changeset 41111 3c85a62d7462
parent 41110 71b0db4fa027
child 41112 3023bc4b3da0
discovery: move handling of sampling special case inside sampling function The handling of cases where the number of revisions to sample is smaller than the sample size can be moved with the sample function themselves. This simplifies main logic, preparing a coming refactoring.
mercurial/setdiscovery.py
--- a/mercurial/setdiscovery.py	Fri Jan 04 17:49:59 2019 +0100
+++ b/mercurial/setdiscovery.py	Fri Dec 14 12:01:15 2018 +0100
@@ -102,6 +102,8 @@
     :headrevs: set of head revisions in local DAG to consider
     :revs: set of revs to discover
     :size: the maximum size of the sample"""
+    if len(revs) <= size:
+        return list(revs)
     sample = set(repo.revs('heads(%ld)', revs))
 
     if len(sample) >= size:
@@ -112,6 +114,8 @@
     return sample
 
 def _takefullsample(repo, headrevs, revs, size):
+    if len(revs) <= size:
+        return list(revs)
     sample = set(repo.revs('heads(%ld)', revs))
 
     # update from heads
@@ -264,10 +268,7 @@
             ui.debug("taking quick initial sample\n")
             samplefunc = _takequicksample
             targetsize = initialsamplesize
-        if len(undecided) <= targetsize:
-            sample = list(undecided)
-        else:
-            sample = samplefunc(local, ownheads, undecided, targetsize)
+        sample = samplefunc(local, ownheads, undecided, targetsize)
 
         roundtrips += 1
         progress.update(roundtrips)