# HG changeset patch # User Boris Feld # Date 1545965978 -3600 # Node ID f46ffd23dae8de16b50040378e7958f51f4ef7eb # Parent 96201120cdf5f57352a9d240a0656ed57b1d8a69 discovery: add a simple `addinfo` method The method can directly process a sample result. This makes the main code simpler to follow. diff -r 96201120cdf5 -r f46ffd23dae8 mercurial/setdiscovery.py --- 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