Patchwork [8,of,8] discovery: add a simple `addinfo` method

login
register
mail settings
Submitter Boris Feld
Date Dec. 31, 2018, 5:35 p.m.
Message ID <f1debafea4d5f9d70c37.1546277755@Laptop-Boris.lan>
Download mbox | patch
Permalink /patch/37412/
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 1545965978 -3600
#      Fri Dec 28 03:59:38 2018 +0100
# Node ID f1debafea4d5f9d70c37003d760c2ba68323a415
# Parent  c5c3e376d7afcb5972f72262d84b6d4b75645329
# EXP-Topic discovery-refactor
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r f1debafea4d5
discovery: add a simple `addinfo` method

The method can directly process a sample result. This makes the main code
simpler to follow.

Patch

diff --git a/mercurial/setdiscovery.py b/mercurial/setdiscovery.py
--- a/mercurial/setdiscovery.py
+++ b/mercurial/setdiscovery.py
@@ -196,6 +196,20 @@  class partialdiscovery(object):
 
         self.undecided.difference_update(self.missing)
 
+    def addinfo(self, sample):
+        """consume an iterable of (rev, known) tuples"""
+        common = set()
+        missing = set()
+        for rev, known in sample:
+            if known:
+                common.add(rev)
+            else:
+                missing.add(rev)
+        if common:
+            self.addcommons(common)
+        if missing:
+            self.addmissings(missing)
+
     def hasinfo(self):
         """return True is we have any clue about the remote state"""
         return self._common.hasbases()
@@ -286,21 +300,12 @@  def findcommonheads(ui, local, remote,
     # 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)
+    disco.addinfo(zip(sample, yesno))
 
     full = False
     progress = ui.makeprogress(_('searching'), unit=_('queries'))
     while not disco.iscomplete():
 
-        if sample:
-            missinginsample = [n for i, n in enumerate(sample) if not yesno[i]]
-            disco.addmissings(missinginsample)
-
-
-        if disco.iscomplete():
-            break
-
         if full or disco.hasinfo():
             if full:
                 ui.note(_("sampling from both directions\n"))
@@ -329,9 +334,7 @@  def findcommonheads(ui, local, remote,
 
         full = True
 
-        if sample:
-            commoninsample = set(n for i, n in enumerate(sample) if yesno[i])
-            disco.addcommons(commoninsample)
+        disco.addinfo(zip(sample, yesno))
 
     # heads(common) == heads(common.bases) since common represents common.bases
     # and all its ancestors