Patchwork [4,of,8] discovery: move undecided set on the partialdiscovery

login
register
mail settings
Submitter Boris Feld
Date Dec. 31, 2018, 5:35 p.m.
Message ID <6eb53e3f1bc514d4cb37.1546277751@Laptop-Boris.lan>
Download mbox | patch
Permalink /patch/37407/
State Superseded
Headers show

Comments

Boris Feld - Dec. 31, 2018, 5:35 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 6eb53e3f1bc514d4cb376d84b2bdd1302d27f8e2
# Parent  d4896a8672cb719ac2cf43f1a7035a335e43665c
# EXP-Topic discovery-refactor
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 6eb53e3f1bc5
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.
Pulkit Goyal - Jan. 4, 2019, 4:03 p.m.
On Mon, Dec 31, 2018 at 11:11 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 6eb53e3f1bc514d4cb376d84b2bdd1302d27f8e2
> # Parent  d4896a8672cb719ac2cf43f1a7035a335e43665c
> # EXP-Topic discovery-refactor
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r
> 6eb53e3f1bc5
> 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,16 @@ 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: exist both locally and remotely
> +    - common:    own nodes I know we both know
> +    - undecided: own nodes where I don't know if remote knows them
>      """
>

the above documentation too.
Boris Feld - Jan. 4, 2019, 5:28 p.m.
On 04/01/2019 17:03, Pulkit Goyal wrote:
>
>
> On Mon, Dec 31, 2018 at 11:11 PM Boris Feld <boris.feld@octobus.net
> <mailto:boris.feld@octobus.net>> wrote:
>
>     # HG changeset patch
>     # User Boris Feld <boris.feld@octobus.net
>     <mailto:boris.feld@octobus.net>>
>     # Date 1545963817 -3600
>     #      Fri Dec 28 03:23:37 2018 +0100
>     # Node ID 6eb53e3f1bc514d4cb376d84b2bdd1302d27f8e2
>     # Parent  d4896a8672cb719ac2cf43f1a7035a335e43665c
>     # EXP-Topic discovery-refactor
>     # Available At https://bitbucket.org/octobus/mercurial-devel/
>     #              hg pull
>     https://bitbucket.org/octobus/mercurial-devel/ -r 6eb53e3f1bc5
>     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,16 @@ 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: exist both locally and remotely
>     +    - common:    own nodes I know we both know
>     +    - undecided: own nodes where I don't know if remote knows them
>          """
>
>
> the above documentation too.
Same here, reusing the existing doc (with an extra typo, one of the
common, should be missing).
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/setdiscovery.py b/mercurial/setdiscovery.py
--- a/mercurial/setdiscovery.py
+++ b/mercurial/setdiscovery.py
@@ -167,12 +167,16 @@  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: exist both locally and remotely
+    - 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 +186,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 +264,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 +286,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 +303,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 +322,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