mercurial/exchange.py
changeset 22936 dae236906fb2
parent 22693 68439b154063
child 22937 92bf9abc4deb
--- a/mercurial/exchange.py	Tue Oct 14 21:59:39 2014 +0900
+++ b/mercurial/exchange.py	Sat Sep 27 00:29:06 2014 -0700
@@ -868,7 +868,38 @@
 
     return pullop
 
+# list of steps to perform discovery before pull
+pulldiscoveryorder = []
+
+# Mapping between step name and function
+#
+# This exists to help extensions wrap steps if necessary
+pulldiscoverymapping = {}
+
+def pulldiscovery(stepname):
+    """decorator for function performing discovery before pull
+
+    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 pulldiscovery dictionary directly."""
+    def dec(func):
+        assert stepname not in pulldiscoverymapping
+        pulldiscoverymapping[stepname] = func
+        pulldiscoveryorder.append(stepname)
+        return func
+    return dec
+
 def _pulldiscovery(pullop):
+    """Run all discovery steps"""
+    for stepname in pulldiscoveryorder:
+        step = pulldiscoverymapping[stepname]
+        step(pullop)
+
+@pulldiscovery('changegroup')
+def _pulldiscoverychangegroup(pullop):
     """discovery phase for the pull
 
     Current handle changeset discovery only, will change handle all discovery