changeset 41171:f46ffd23dae8

discovery: add a simple `addinfo` method The method can directly process a sample result. This makes the main code simpler to follow.
author Boris Feld <boris.feld@octobus.net>
date Fri, 28 Dec 2018 03:59:38 +0100
parents 96201120cdf5
children 3dcc96582627
files mercurial/setdiscovery.py
diffstat 1 files changed, 16 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/setdiscovery.py	Fri Dec 28 03:48:00 2018 +0100
+++ b/mercurial/setdiscovery.py	Fri Dec 28 03:59:38 2018 +0100
@@ -195,6 +195,20 @@
 
         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()
@@ -288,21 +302,12 @@
     # 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"))
@@ -331,9 +336,7 @@
 
         full = True
 
-        if sample:
-            commoninsample = set(n for i, n in enumerate(sample) if yesno[i])
-            disco.addcommons(commoninsample)
+        disco.addinfo(zip(sample, yesno))
 
     result = disco.commonheads()
     elapsed = util.timer() - start