Patchwork [1,of,2] bundle2: add an 'idx' argument to the 'b2partsgenerator'

login
register
mail settings
Submitter Pierre-Yves David
Date April 14, 2015, 7:06 p.m.
Message ID <2ec934ad3f7fdcdf389f.1429038396@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/8664/
State Accepted
Headers show

Comments

Pierre-Yves David - April 14, 2015, 7:06 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1429034855 14400
#      Tue Apr 14 14:07:35 2015 -0400
# Node ID 2ec934ad3f7fdcdf389f99cceeac2bf59a80f705
# Parent  c560d8c687916cb70a6d54c2c9ddcb5c9e457be2
bundle2: add an 'idx' argument to the 'b2partsgenerator'

This argument let extensions control in what order bundle2 part are generated
client side during a push. This is useful to ensure the transaction is in a
proper state before some actions or hooks happens.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -425,11 +425,11 @@  b2partsgenorder = []
 # Mapping between step name and function
 #
 # This exists to help extensions wrap steps if necessary
 b2partsgenmapping = {}
 
-def b2partsgenerator(stepname):
+def b2partsgenerator(stepname, idx=None):
     """decorator for function generating bundle2 part
 
     The function is added to the step -> function mapping and appended to the
     list of steps.  Beware that decorated functions will be added in order
     (this may matter).
@@ -437,11 +437,14 @@  def b2partsgenerator(stepname):
     You can only use this decorator for new steps, if you want to wrap a step
     from an extension, attack the b2partsgenmapping dictionary directly."""
     def dec(func):
         assert stepname not in b2partsgenmapping
         b2partsgenmapping[stepname] = func
-        b2partsgenorder.append(stepname)
+        if idx is None:
+            b2partsgenorder.append(stepname)
+        else:
+            b2partsgenorder.insert(idx, stepname)
         return func
     return dec
 
 @b2partsgenerator('changeset')
 def _pushb2ctx(pushop, bundler):