push: make discovery extensible
authorPierre-Yves David <pierre-yves.david@fb.com>
Tue, 01 Jul 2014 17:06:02 +0200
changeset 22018 ddb56e7e1b92
parent 22017 7986e99bb69a
child 22019 9fcf772f15ff
push: make discovery extensible We need to gather all discovery before the unified bundle2 push. We use the same pattern as bundle2 parts generation.
mercurial/exchange.py
--- a/mercurial/exchange.py	Wed Jul 30 19:04:50 2014 -0700
+++ b/mercurial/exchange.py	Tue Jul 01 17:06:02 2014 +0200
@@ -191,8 +191,41 @@
     _pushbookmark(pushop)
     return pushop.ret
 
+# list of steps to perform discovery before push
+pushdiscoveryorder = []
+
+# Mapping between step name and function
+#
+# This exists to help extensions wrap steps if necessary
+pushdiscoverymapping = {}
+
+def pushdiscovery(stepname):
+    """decorator for function performing discovery before push
+
+    The function is added to the step -> function mapping and appended to the
+    list of steps.  Beware that decorated function will be added in order (this
+    may matter).
+
+    You can only use this decorator for a new step, if you want to wrap a step
+    from an extension, change the pushdiscovery dictionary directly."""
+    def dec(func):
+        assert stepname not in pushdiscoverymapping
+        pushdiscoverymapping[stepname] = func
+        pushdiscoveryorder.append(stepname)
+        return func
+    return dec
+
+
+
 def _pushdiscovery(pushop):
-    # discovery
+    """Run all discovery steps"""
+    for stepname in pushdiscoveryorder:
+        step = pushdiscoverymapping[stepname]
+        step(pushop)
+
+@pushdiscovery('changeset')
+def _pushdiscoverychangeset(pushop):
+    """discover the changeset that need to be pushed"""
     unfi = pushop.repo.unfiltered()
     fci = discovery.findcommonincoming
     commoninc = fci(unfi, pushop.remote, force=pushop.force)