changeset 39170:754f389b87f2

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
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 17 Aug 2018 17:48:15 +0000
parents 140992750187
children abce899c985f
files mercurial/setdiscovery.py
diffstat 1 files changed, 8 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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: