changeset 2515:cd8aa99d4f20

obsdiscovery: automatically pick protocol in a list This makes the code cleaner, clearer and more flexible. This also prepare the ability to disable obsmarkers discover entirely.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 30 May 2017 13:01:11 +0200
parents b9f03002f214
children d0a78e8b6434
files hgext3rd/evolve/obsdiscovery.py
diffstat 1 files changed, 21 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/obsdiscovery.py	Tue May 30 14:35:40 2017 +0200
+++ b/hgext3rd/evolve/obsdiscovery.py	Tue May 30 13:01:11 2017 +0200
@@ -865,23 +865,39 @@
     revs = list(repo.revs('only(%ln, %ln)', pushop.futureheads, common))
     return [node(r) for r in revs]
 
+# available discovery method, first valid is used
+# tuple (canuse, perform discovery))
+obsdiscoveries = [
+    (_canobshashrange, _pushobshashrange),
+    (_canobshashtree, _pushobshashtree),
+]
+
 @eh.wrapfunction(exchange, '_pushdiscoveryobsmarkers')
 def _pushdiscoveryobsmarkers(orig, pushop):
     if _dopushmarkers(pushop):
         repo = pushop.repo
+        remote = pushop.remote
         obsexcmsg(repo.ui, "computing relevant nodes\n")
         revs = list(repo.revs('::%ln', pushop.futureheads))
         unfi = repo.unfiltered()
-        if not _canobshashtree(repo, pushop.remote):
+
+        # look for an obs-discovery protocol we can use
+        discovery = None
+        for candidate in obsdiscoveries:
+            if candidate[0](repo, remote):
+                discovery = candidate[1]
+                break
+
+        if discovery is None:
+            # no discovery available, rely on core to push all relevants
+            # obs markers.
             return orig(pushop)
 
         obsexcmsg(repo.ui, "looking for common markers in %i nodes\n"
                            % len(revs))
         commonrevs = list(unfi.revs('::%ln', pushop.outgoing.commonheads))
-        if _canobshashrange(repo, pushop.remote):
-            nodes = _pushobshashrange(pushop, commonrevs)
-        else:
-            nodes = _pushobshashtree(pushop, commonrevs)
+        # find the nodes where the relevant obsmarkers mismatches
+        nodes = discovery(pushop, commonrevs)
 
         if nodes:
             obsexcmsg(repo.ui, "computing markers relevant to %i nodes\n"