Patchwork [5,of,7] push: make discovery extensible

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 4, 2014, 10:32 p.m.
Message ID <52603c1d28853d4332a0.1407191527@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5253/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 4, 2014, 10:32 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1404227162 -7200
#      Tue Jul 01 17:06:02 2014 +0200
# Node ID 52603c1d28853d4332a0c9821939047fbd387b6d
# Parent  ef23af55a08a21a479254a769dd0ccc94075be71
push: make discovery extensible

We need to gather all discovery before the unified bundle2 push. We use the same
pattern than for bundle2 parts generation.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -189,12 +189,45 @@  def push(repo, remote, force=False, revs
             locallock.release()
 
     _pushbookmark(pushop)
     return pushop.ret
 
+# list of steps to perform discovery before push
+pushdiscoveryorder = []
+
+# Mapping between step name and function
+#
+# This exists to help extension to wrap step if necessary
+pushdiscoverymapping = {}
+
+def pushdiscovery(stepname):
+    """decorator for function performing discovery before push
+
+    The function is added to the step -> function mapping and append to the
+    list of steps.  Beware that decorated function will be added in order This
+    may matters.
+
+    You can only use this decorator for new step, if you want to wrap a step
+    from an extension, change the pushdiscovery dictionnary 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)
     common, inc, remoteheads = commoninc
     fco = discovery.findcommonoutgoing