Patchwork [05,of,10,V3] discovery: move undecided set on the partialdiscovery

login
register
mail settings
Submitter Boris Feld
Date Jan. 4, 2019, 10:45 p.m.
Message ID <944c2173a32073584a22.1546641924@localhost.localdomain>
Download mbox | patch
Permalink /patch/37473/
State Accepted
Headers show

Comments

Boris Feld - Jan. 4, 2019, 10:45 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1545963817 -3600
#      Fri Dec 28 03:23:37 2018 +0100
# Node ID 944c2173a32073584a22f8de8c0e348245065c1e
# Parent  f3c439000eb772272745c344f5257f3ecce369c0
# EXP-Topic discovery-refactor
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 944c2173a320
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.
via Mercurial-devel - Jan. 10, 2019, 7:12 p.m.
On Fri, Jan 4, 2019 at 2:54 PM Boris Feld <boris.feld@octobus.net> wrote:

> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1545963817 -3600
> #      Fri Dec 28 03:23:37 2018 +0100
> # Node ID 944c2173a32073584a22f8de8c0e348245065c1e
> # Parent  f3c439000eb772272745c344f5257f3ecce369c0
> # EXP-Topic discovery-refactor
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r
> 944c2173a320
> 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
> @@ -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
>

Why is this is a @property? It seems confusing to me to use a property for
something that changes over time and this does change over time, right?

Patch

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