obsdiscovery: move code inserting discovery at the end of the file
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 30 May 2017 12:26:57 +0200
changeset 2509 6da129b2b440
parent 2508 45abd0586c73
child 2510 b99b83728ea3
obsdiscovery: move code inserting discovery at the end of the file This makes it easier to reuser function defined earlier in the file.
hgext3rd/evolve/obsdiscovery.py
--- a/hgext3rd/evolve/obsdiscovery.py	Tue May 30 12:15:52 2017 +0200
+++ b/hgext3rd/evolve/obsdiscovery.py	Tue May 30 12:26:57 2017 +0200
@@ -72,92 +72,6 @@
 eh.merge(stablerange.eh)
 obsexcmsg = utility.obsexcmsg
 
-##########################################
-###  trigger discovery during exchange ###
-##########################################
-
-def _dopushmarkers(pushop):
-    return (# we have any markers to push
-            pushop.repo.obsstore
-            # exchange of obsmarkers is enabled locally
-            and obsolete.isenabled(pushop.repo, obsolete.exchangeopt)
-            # remote server accept markers
-            and 'obsolete' in pushop.remote.listkeys('namespaces'))
-
-@eh.wrapfunction(exchange, '_pushdiscoveryobsmarkers')
-def _pushdiscoveryobsmarkers(orig, pushop):
-    if _dopushmarkers(pushop):
-        repo = pushop.repo
-        obsexcmsg(repo.ui, "computing relevant nodes\n")
-        revs = list(repo.revs('::%ln', pushop.futureheads))
-        unfi = repo.unfiltered()
-        cl = unfi.changelog
-        if not pushop.remote.capable('_evoext_obshash_0'):
-            return orig(pushop)
-
-        common = []
-        missing = None
-        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):
-            missing = findmissingrange(pushop.ui, unfi, pushop.remote,
-                                       commonrevs)
-        else:
-            common = findcommonobsmarkers(pushop.ui, unfi, pushop.remote,
-                                          commonrevs)
-        if missing is None:
-            revs = list(unfi.revs('%ld - (::%ln)', revs, common))
-            nodes = [cl.node(r) for r in revs]
-        else:
-            revs = list(repo.revs('only(%ln, %ln)', pushop.futureheads,
-                        pushop.outgoing.commonheads))
-            nodes = [cl.node(r) for r in revs]
-            nodes += missing
-
-        if nodes:
-            obsexcmsg(repo.ui, "computing markers relevant to %i nodes\n"
-                               % len(nodes))
-            pushop.outobsmarkers = repo.obsstore.relevantmarkers(nodes)
-        else:
-            obsexcmsg(repo.ui, "markers already in sync\n")
-            pushop.outobsmarkers = []
-
-@eh.extsetup
-def _installobsmarkersdiscovery(ui):
-    olddisco = exchange.pushdiscoverymapping['obsmarker']
-
-    def newdisco(pushop):
-        _pushdiscoveryobsmarkers(olddisco, pushop)
-    exchange.pushdiscoverymapping['obsmarker'] = newdisco
-
-def buildpullobsmarkersboundaries(pullop, bundle2=True):
-    """small function returning the argument for pull markers call
-    may to contains 'heads' and 'common'. skip the key for None.
-
-    It is a separed function to play around with strategy for that."""
-    repo = pullop.repo
-    remote = pullop.remote
-    unfi = repo.unfiltered()
-    revs = unfi.revs('::(%ln - null)', pullop.common)
-    boundaries = {'heads': pullop.pulledsubset}
-    if not revs: # nothing common
-        boundaries['common'] = [node.nullid]
-        return boundaries
-
-    if bundle2 and _canobshashrange(repo, remote):
-        obsexcmsg(repo.ui, "looking for common markers in %i nodes\n"
-                  % len(revs))
-        boundaries['missing'] = findmissingrange(repo.ui, repo, pullop.remote,
-                                                 revs)
-    elif remote.capable('_evoext_obshash_0'):
-        obsexcmsg(repo.ui, "looking for common markers in %i nodes\n"
-                           % len(revs))
-        boundaries['common'] = findcommonobsmarkers(repo.ui, repo, remote, revs)
-    else:
-        boundaries['common'] = [node.nullid]
-    return boundaries
-
 ##################################
 ###  Code performing discovery ###
 ##################################
@@ -920,3 +834,89 @@
     def newcap(repo, proto):
         return _obshash_capabilities(oldcap, repo, proto)
     wireproto.commands['capabilities'] = (newcap, args)
+
+##########################################
+###  trigger discovery during exchange ###
+##########################################
+
+def _dopushmarkers(pushop):
+    return (# we have any markers to push
+            pushop.repo.obsstore
+            # exchange of obsmarkers is enabled locally
+            and obsolete.isenabled(pushop.repo, obsolete.exchangeopt)
+            # remote server accept markers
+            and 'obsolete' in pushop.remote.listkeys('namespaces'))
+
+@eh.wrapfunction(exchange, '_pushdiscoveryobsmarkers')
+def _pushdiscoveryobsmarkers(orig, pushop):
+    if _dopushmarkers(pushop):
+        repo = pushop.repo
+        obsexcmsg(repo.ui, "computing relevant nodes\n")
+        revs = list(repo.revs('::%ln', pushop.futureheads))
+        unfi = repo.unfiltered()
+        cl = unfi.changelog
+        if not pushop.remote.capable('_evoext_obshash_0'):
+            return orig(pushop)
+
+        common = []
+        missing = None
+        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):
+            missing = findmissingrange(pushop.ui, unfi, pushop.remote,
+                                       commonrevs)
+        else:
+            common = findcommonobsmarkers(pushop.ui, unfi, pushop.remote,
+                                          commonrevs)
+        if missing is None:
+            revs = list(unfi.revs('%ld - (::%ln)', revs, common))
+            nodes = [cl.node(r) for r in revs]
+        else:
+            revs = list(repo.revs('only(%ln, %ln)', pushop.futureheads,
+                        pushop.outgoing.commonheads))
+            nodes = [cl.node(r) for r in revs]
+            nodes += missing
+
+        if nodes:
+            obsexcmsg(repo.ui, "computing markers relevant to %i nodes\n"
+                               % len(nodes))
+            pushop.outobsmarkers = repo.obsstore.relevantmarkers(nodes)
+        else:
+            obsexcmsg(repo.ui, "markers already in sync\n")
+            pushop.outobsmarkers = []
+
+@eh.extsetup
+def _installobsmarkersdiscovery(ui):
+    olddisco = exchange.pushdiscoverymapping['obsmarker']
+
+    def newdisco(pushop):
+        _pushdiscoveryobsmarkers(olddisco, pushop)
+    exchange.pushdiscoverymapping['obsmarker'] = newdisco
+
+def buildpullobsmarkersboundaries(pullop, bundle2=True):
+    """small function returning the argument for pull markers call
+    may to contains 'heads' and 'common'. skip the key for None.
+
+    It is a separed function to play around with strategy for that."""
+    repo = pullop.repo
+    remote = pullop.remote
+    unfi = repo.unfiltered()
+    revs = unfi.revs('::(%ln - null)', pullop.common)
+    boundaries = {'heads': pullop.pulledsubset}
+    if not revs: # nothing common
+        boundaries['common'] = [node.nullid]
+        return boundaries
+
+    if bundle2 and _canobshashrange(repo, remote):
+        obsexcmsg(repo.ui, "looking for common markers in %i nodes\n"
+                  % len(revs))
+        boundaries['missing'] = findmissingrange(repo.ui, repo, pullop.remote,
+                                                 revs)
+    elif remote.capable('_evoext_obshash_0'):
+        obsexcmsg(repo.ui, "looking for common markers in %i nodes\n"
+                           % len(revs))
+        boundaries['common'] = findcommonobsmarkers(repo.ui, repo, remote, revs)
+    else:
+        boundaries['common'] = [node.nullid]
+    return boundaries