[PATCH 05 of 10 V2] discovery: move undecided set on the partialdiscovery

Boris Feld boris.feld at octobus.net
Fri Jan 4 17:29:26 UTC 2019


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1545963817 -3600
#      Fri Dec 28 03:23:37 2018 +0100
# Node ID fca60f8ccc4333b0afd959e45a0febb64126ec7f
# Parent  b70041eb7b51f23c10732138c7254468f8232f55
# EXP-Topic discovery-refactor
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r fca60f8ccc43
discovery: move undecided set on the partialdiscovery

To initialize it, we need to know the discovery target. This commit only move
the set on the `partialdiscovery` object, later changeset will take advantage of
it.

diff --git a/mercurial/setdiscovery.py b/mercurial/setdiscovery.py
--- a/mercurial/setdiscovery.py
+++ b/mercurial/setdiscovery.py
@@ -167,12 +167,15 @@ class partialdiscovery(object):
     Feed with data from the remote repository, this object keep track of the
     current set of changeset in various states:
 
-    - common: own nodes I know we both know
+    - common:    own nodes I know we both know
+    - undecided: own nodes where I don't know if remote knows them
     """
 
-    def __init__(self, repo):
+    def __init__(self, repo, targetheads):
         self._repo = repo
+        self._targetheads = targetheads
         self._common = repo.changelog.incrementalmissingrevs()
+        self._undecided = None
 
     def addcommons(self, commons):
         """registrer nodes known as common"""
@@ -182,6 +185,13 @@ class partialdiscovery(object):
         """return True is we have any clue about the remote state"""
         return self._common.hasbases()
 
+    @property
+    def undecided(self):
+        if self._undecided is not None:
+            return self._undecided
+        self._undecided = set(self._common.missingancestors(self._targetheads))
+        return self._undecided
+
     def commonheads(self):
         """the heads of the known common set"""
         return set(self._repo.revs('heads(%ld)',
@@ -253,20 +263,18 @@ def findcommonheads(ui, local, remote,
 
     # full blown discovery
 
-    disco = partialdiscovery(local)
+    disco = partialdiscovery(local, ownheads)
     # treat remote heads (and maybe own heads) as a first implicit sample
     # response
     disco.addcommons(srvheads)
     commoninsample = set(n for i, n in enumerate(sample) if yesno[i])
     disco.addcommons(commoninsample)
-    # own nodes where I don't know if remote knows them
-    undecided = set(disco._common.missingancestors(ownheads))
     # own nodes I know remote lacks
     missing = set()
 
     full = False
     progress = ui.makeprogress(_('searching'), unit=_('queries'))
-    while undecided:
+    while disco.undecided:
 
         if sample:
             missinginsample = [n for i, n in enumerate(sample) if not yesno[i]]
@@ -277,9 +285,9 @@ def findcommonheads(ui, local, remote,
             else:
                 missing.update(local.revs('descendants(%ld)', missinginsample))
 
-            undecided.difference_update(missing)
+            disco.undecided.difference_update(missing)
 
-        if not undecided:
+        if not disco.undecided:
             break
 
         if full or disco.hasinfo():
@@ -294,12 +302,12 @@ def findcommonheads(ui, local, remote,
             ui.debug("taking quick initial sample\n")
             samplefunc = _takequicksample
             targetsize = initialsamplesize
-        sample = samplefunc(local, ownheads, undecided, targetsize)
+        sample = samplefunc(local, ownheads, disco.undecided, targetsize)
 
         roundtrips += 1
         progress.update(roundtrips)
         ui.debug("query %i; still undecided: %i, sample size is: %i\n"
-                 % (roundtrips, len(undecided), len(sample)))
+                 % (roundtrips, len(disco.undecided), len(sample)))
         # indices between sample and externalized version must match
         sample = list(sample)
 
@@ -313,7 +321,7 @@ def findcommonheads(ui, local, remote,
         if sample:
             commoninsample = set(n for i, n in enumerate(sample) if yesno[i])
             disco.addcommons(commoninsample)
-            disco._common.removeancestorsfrom(undecided)
+            disco._common.removeancestorsfrom(disco.undecided)
 
     # heads(common) == heads(common.bases) since common represents common.bases
     # and all its ancestors



More information about the Mercurial-devel mailing list