[PATCH 3 of 5 V2] bundle2: introduce a bundleoperation object

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Fri Apr 4 13:11:50 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1396502684 25200
#      Wed Apr 02 22:24:44 2014 -0700
# Node ID 10cf49dd923a8522df571f3619a0e2dfdeeeeb28
# Parent  70bb6695fbc36bd98025d1858112846170a68d4b
bundle2: introduce a bundleoperation object

This object is responsible of store sta

This object will hold all data and state gathered through the processing of a
bundle. This will allow:

- each handler to be aware of the thing unbundled so far
- the caller to retrieve data about the execution
- bear useful object and logic (like repo, transaction)
- bear possible bundle2 reply triggered by the unbundling.

For now the object is very simple but it will grow at the same time than the
bundle2 implementation.

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -181,10 +181,31 @@ def parthandler(parttype):
         assert lparttype not in parthandlermapping
         parthandlermapping[lparttype] = func
         return func
     return _decorator
 
+class bundleoperation(object):
+    """an object that represent a single bundle processing
+
+    It purpose is to carry unbundle related objects and states.
+
+    A new should be created at the begining of each bundle processing. the
+    object is to be return by the processing function.
+
+    The object have very little content now it will ultimatly contains:
+    * an access to the repo the bundle is applied to,
+    * an ui object,
+    * a way to retrieve a transaction to add changes to the repo,
+    * a way to record the result the processing of each part,
+    * a way to forge a bundle response when applicable.
+    """
+
+    def __init__(self, repo):
+        self.repo = repo
+        self.ui = repo.ui
+
+
 def processbundle(repo, unbundler):
     """This function process a bundle, apply effect to/from a repo
 
     It iterate over each parts then search and use the proper handling code to
     process the part. Parts are processes in order.
@@ -192,11 +213,11 @@ def processbundle(repo, unbundler):
     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
+    op = bundleoperation(repo)
     # todo:
     # - replace this is a init function soon.
     # - exception catching
     unbundler.params
     iterparts = iter(unbundler)
@@ -205,21 +226,21 @@ def processbundle(repo, unbundler):
             parttype = part.type
             # part key are matched lower case
             key = parttype.lower()
             try:
                 handler = parthandlermapping[key]
-                ui.debug('found an handler for part %r\n' % parttype)
+                op.ui.debug('found an handler for part %r\n' % parttype)
             except KeyError:
                 if key != parttype: # mandatory parts
                     # todo:
                     # - use a more precise exception
                     raise
-                ui.debug('ignoring unknown advisory part %r\n' % key)
+                op.ui.debug('ignoring unknown advisory part %r\n' % key)
                 # todo:
                 # - consume the part once we use streaming
                 continue
-            handler(repo, part)
+            handler(op, part)
     except Exception:
         for part in iterparts:
             pass # consume the bundle content
         raise
 
diff --git a/tests/test-bundle2.t b/tests/test-bundle2.t
--- a/tests/test-bundle2.t
+++ b/tests/test-bundle2.t
@@ -19,15 +19,15 @@ Create an extension to test bundle2 API
   > Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
   > Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko."""
   > assert len(ELEPHANTSSONG) == 178 # future test say 178 bytes, trust it.
   > 
   > @bundle2.parthandler('test:song')
-  > def songhandler(repo, part):
+  > def songhandler(op, part):
   >     """handle a "test:song" bundle2 part, printing the lyrics on stdin"""
-  >     repo.ui.write('The choir start singing:\n')
+  >     op.ui.write('The choir start singing:\n')
   >     for line in part.data.split('\n'):
-  >         repo.ui.write('    %s\n' % line)
+  >         op.ui.write('    %s\n' % line)
   > 
   > @command('bundle2',
   >          [('', 'param', [], 'stream level parameter'),
   >           ('', 'unknown', False, 'include an unknown mandatory part in the bundle'),
   >           ('', 'parts', False, 'include some arbitrary parts to the bundle'),],


More information about the Mercurial-devel mailing list