D4318: setdiscovery: pass heads into _updatesample()

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Fri Aug 17 21:30:57 UTC 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4318

AFFECTED FILES
  mercurial/setdiscovery.py

CHANGE DETAILS

diff --git a/mercurial/setdiscovery.py b/mercurial/setdiscovery.py
--- a/mercurial/setdiscovery.py
+++ b/mercurial/setdiscovery.py
@@ -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:



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list