Patchwork pull: make discovery phase extensible

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 13, 2014, 7:52 p.m.
Message ID <f70d2e37b0cc8e09fd5a.1413229932@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6236/
State Accepted
Headers show

Comments

Pierre-Yves David - Oct. 13, 2014, 7:52 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1411802946 25200
#      Sat Sep 27 00:29:06 2014 -0700
# Node ID f70d2e37b0cc8e09fd5a50d0f38c68a4aaff2a5f
# Parent  1533e642262de32c5a2445789710f49237019fd6
pull: make discovery phase extensible

We apply the same approach as for push and make the discovery extensible. There
is only one user in core right now but we already know we'll need something
smarter for obsmarkers. In fact the evolve extension could use this to cleanly
extend discovery.

Main motivation for this change is consistency between push and pull.
Augie Fackler - Oct. 14, 2014, 7:50 p.m.
On Mon, Oct 13, 2014 at 12:52:12PM -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1411802946 25200
> #      Sat Sep 27 00:29:06 2014 -0700
> # Node ID f70d2e37b0cc8e09fd5a50d0f38c68a4aaff2a5f
> # Parent  1533e642262de32c5a2445789710f49237019fd6
> pull: make discovery phase extensible

queued, thanks

>
> We apply the same approach as for push and make the discovery extensible. There
> is only one user in core right now but we already know we'll need something
> smarter for obsmarkers. In fact the evolve extension could use this to cleanly
> extend discovery.
>
> Main motivation for this change is consistency between push and pull.
>
> diff --git a/mercurial/exchange.py b/mercurial/exchange.py
> --- a/mercurial/exchange.py
> +++ b/mercurial/exchange.py
> @@ -866,11 +866,42 @@ def pull(repo, remote, heads=None, force
>          pullop.releasetransaction()
>          lock.release()
>
>      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
>      at some point."""
>      tmp = discovery.findcommonincoming(pullop.repo.unfiltered(),
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -866,11 +866,42 @@  def pull(repo, remote, heads=None, force
         pullop.releasetransaction()
         lock.release()
 
     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
     at some point."""
     tmp = discovery.findcommonincoming(pullop.repo.unfiltered(),