Patchwork [1,of,4] bundle2: feed a unbundle20 to the `processbundle` function

login
register
mail settings
Submitter Pierre-Yves David
Date April 3, 2014, 10:57 p.m.
Message ID <71c310363488940c4519.1396565868@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4211/
State Superseded
Commit c33d7bf53812e963cea5fa9fe54caae7adbe8d99
Headers show

Comments

Pierre-Yves David - April 3, 2014, 10:57 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1396471857 25200
#      Wed Apr 02 13:50:57 2014 -0700
# Node ID 71c310363488940c451912d3d68492e2d5fb7eea
# Parent  d3775db748a06450b69e4fd5beb52cb5e9ef07b0
bundle2: feed a unbundle20 to the `processbundle` function

The unbundle can comes from multiple sources. (on disk file, peer, etc) and
(ultimately) of multiple type (bundle10, bundle20). The `processbundle` is no
longer in charge of creating the bundle.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -181,31 +181,22 @@  def parthandler(parttype):
         assert lparttype not in parthandlermapping
         parthandlermapping[lparttype] = func
         return func
     return _decorator
 
-def processbundle(repo, stream):
+def processbundle(repo, unbundler):
     """This function process a bundle, apply effect to/from a repo
 
-    Currently it:
-    - parse a stream into an unbundle20 object
-    - iterate over each parts then search and use the proper handling code to
-      process the part.
-
-    Parts are processes in order.
+    It iterate over each parts then search and use the proper handling code to
+    process the part. Parts are processes in order.
 
     This is very early version of this function that will be strongly reworked
     before final usage.
 
     Unknown Mandatory part will abort the process.
     """
     ui = repo.ui
-    # Extraction of the unbundler object will most likely change. It may be
-    # done outside of this function, the unbundler would be passed as argument.
-    # in all case the unbundler will eventually be created by a
-    # `changegroup.readbundle` style function.
-    unbundler = unbundle20(ui, stream)
     # todo:
     # - replace this is a init function soon.
     # - exception catching
     unbundler.params
     iterparts = iter(unbundler)
diff --git a/tests/test-bundle2.t b/tests/test-bundle2.t
--- a/tests/test-bundle2.t
+++ b/tests/test-bundle2.t
@@ -71,11 +71,12 @@  Create an extension to test bundle2 API
   > @command('unbundle2', [], '')
   > def cmdunbundle2(ui, repo):
   >     """process a bundle2 stream from stdin on the current repo"""
   >     try:
   >         try:
-  >             bundle2.processbundle(repo, sys.stdin)
+  >             unbundler = bundle2.unbundle20(ui, sys.stdin)
+  >             bundle2.processbundle(repo, unbundler)
   >         except KeyError, exc:
   >             raise util.Abort('missing support for %s' % exc)
   >     finally:
   >         remains = sys.stdin.read()
   >         ui.write('%i unread bytes\n' % len(remains))