setdiscovery: pass heads into _updatesample()
authorGregory Szorc <gregory.szorc@gmail.com>
Fri, 17 Aug 2018 17:48:15 +0000
changeset 39170 754f389b87f2
parent 39169 140992750187
child 39171 abce899c985f
setdiscovery: pass heads into _updatesample() In preparation for eliminating the use of dagutil. Since _takefullsample() operates on the inverted DAG, it is easier to have the caller pass in the relevant set instead of teaching _updatesample() about when to invert the DAG. We keep the logic identical for now: future commits will remove dagutil. Differential Revision: https://phab.mercurial-scm.org/D4318
mercurial/setdiscovery.py
--- a/mercurial/setdiscovery.py	Fri Aug 17 17:26:07 2018 +0000
+++ b/mercurial/setdiscovery.py	Fri Aug 17 17:48:15 2018 +0000
@@ -56,7 +56,7 @@
     util,
 )
 
-def _updatesample(dag, revs, sample, quicksamplesize=0):
+def _updatesample(dag, revs, heads, sample, quicksamplesize=0):
     """update an existing sample to match the expected size
 
     The sample is updated with revs exponentially distant from each head of the
@@ -68,13 +68,9 @@
 
     :dag: a dag object from dagutil
     :revs:  set of revs we want to discover (if None, assume the whole dag)
+    :heads: set of DAG head revs
     :sample: a sample to update
     :quicksamplesize: optional target size of the sample"""
-    # if revs is empty we scan the entire graph
-    if revs:
-        heads = dag.headsetofconnecteds(revs)
-    else:
-        heads = dag.heads()
     dist = {}
     visit = collections.deque(heads)
     seen = set()
@@ -109,16 +105,19 @@
 
     if len(sample) >= size:
         return _limitsample(sample, size)
-    _updatesample(dag, None, sample, quicksamplesize=size)
+
+    _updatesample(dag, None, dag.heads(), sample, quicksamplesize=size)
     return sample
 
 def _takefullsample(repo, dag, revs, size):
     sample = set(repo.revs('heads(%ld)', revs))
 
     # update from heads
-    _updatesample(dag, revs, sample)
+    _updatesample(dag, revs, dag.headsetofconnecteds(revs), sample)
     # update from roots
-    _updatesample(dag.inverse(), revs, sample)
+    inverteddag = dag.inverse()
+    _updatesample(inverteddag, revs, inverteddag.headsetofconnecteds(revs),
+                  sample)
     assert sample
     sample = _limitsample(sample, size)
     if len(sample) < size: