mercurial/exchange.py
changeset 22017 7986e99bb69a
parent 22016 7d976d71684c
child 22018 ddb56e7e1b92
equal deleted inserted replaced
22016:7d976d71684c 22017:7986e99bb69a
   241                              pushop.newbranch,
   241                              pushop.newbranch,
   242                              bool(pushop.incoming),
   242                              bool(pushop.incoming),
   243                              newbm)
   243                              newbm)
   244     return True
   244     return True
   245 
   245 
       
   246 # List of names of steps to perform for an outgoing bundle2, order matters.
       
   247 b2partsgenorder = []
       
   248 
       
   249 # Mapping between step name and function
       
   250 #
       
   251 # This exists to help extensions wrap steps if necessary
       
   252 b2partsgenmapping = {}
       
   253 
       
   254 def b2partsgenerator(stepname):
       
   255     """decorator for function generating bundle2 part
       
   256 
       
   257     The function is added to the step -> function mapping and appended to the
       
   258     list of steps.  Beware that decorated functions will be added in order
       
   259     (this may matter).
       
   260 
       
   261     You can only use this decorator for new steps, if you want to wrap a step
       
   262     from an extension, attack the b2partsgenmapping dictionary directly."""
       
   263     def dec(func):
       
   264         assert stepname not in b2partsgenmapping
       
   265         b2partsgenmapping[stepname] = func
       
   266         b2partsgenorder.append(stepname)
       
   267         return func
       
   268     return dec
       
   269 
       
   270 @b2partsgenerator('changeset')
   246 def _pushb2ctx(pushop, bundler):
   271 def _pushb2ctx(pushop, bundler):
   247     """handle changegroup push through bundle2
   272     """handle changegroup push through bundle2
   248 
   273 
   249     addchangegroup result is stored in the ``pushop.ret`` attribute.
   274     addchangegroup result is stored in the ``pushop.ret`` attribute.
   250     """
   275     """
   267         cgreplies = op.records.getreplies(cgpart.id)
   292         cgreplies = op.records.getreplies(cgpart.id)
   268         assert len(cgreplies['changegroup']) == 1
   293         assert len(cgreplies['changegroup']) == 1
   269         pushop.ret = cgreplies['changegroup'][0]['return']
   294         pushop.ret = cgreplies['changegroup'][0]['return']
   270     return handlereply
   295     return handlereply
   271 
   296 
   272 # list of function that may decide to add parts to an outgoing bundle2
       
   273 bundle2partsgenerators = [_pushb2ctx]
       
   274 
   297 
   275 def _pushbundle2(pushop):
   298 def _pushbundle2(pushop):
   276     """push data to the remote using bundle2
   299     """push data to the remote using bundle2
   277 
   300 
   278     The only currently supported type of data is changegroup but this will
   301     The only currently supported type of data is changegroup but this will
   280     bundler = bundle2.bundle20(pushop.ui, bundle2.bundle2caps(pushop.remote))
   303     bundler = bundle2.bundle20(pushop.ui, bundle2.bundle2caps(pushop.remote))
   281     # create reply capability
   304     # create reply capability
   282     capsblob = bundle2.encodecaps(pushop.repo.bundle2caps)
   305     capsblob = bundle2.encodecaps(pushop.repo.bundle2caps)
   283     bundler.newpart('b2x:replycaps', data=capsblob)
   306     bundler.newpart('b2x:replycaps', data=capsblob)
   284     replyhandlers = []
   307     replyhandlers = []
   285     for partgen in bundle2partsgenerators:
   308     for partgenname in b2partsgenorder:
       
   309         partgen = b2partsgenmapping[partgenname]
   286         ret = partgen(pushop, bundler)
   310         ret = partgen(pushop, bundler)
   287         if callable(ret):
   311         if callable(ret):
   288             replyhandlers.append(ret)
   312             replyhandlers.append(ret)
   289     # do not push if nothing to push
   313     # do not push if nothing to push
   290     if bundler.nbparts <= 1:
   314     if bundler.nbparts <= 1: