Patchwork [5,of,5,V2] bundle2: support for unbundling simple parameter

login
register
mail settings
Submitter Pierre-Yves David
Date March 20, 2014, 6:39 p.m.
Message ID <f2b99db4d1e73a287d12.1395340786@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4008/
State Accepted
Commit c5aaeca0cfbfaad91eaa9c1a40f04b424bce2bd9
Headers show

Comments

Pierre-Yves David - March 20, 2014, 6:39 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1395183384 25200
#      Tue Mar 18 15:56:24 2014 -0700
# Node ID f2b99db4d1e73a287d127d80c51bf655ffb56efe
# Parent  c2a786e379896935e355bb0d7ee0b89b08095513
bundle2: support for unbundling simple parameter

the unbundler now understand simple list of parameter.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -140,13 +140,16 @@  class unbundler(object):
         return changegroup.readexactly(self._fp, size)
 
     @util.propertycache
     def params(self):
         """dictionnary of stream level parameters"""
-        paramsize = self._readexact(2)
-        assert paramsize == '\0\0'
-        return {}
+        params = {}
+        paramssize = self._unpack(_fstreamparamsize)[0]
+        if paramssize:
+            for p in self._readexact(paramssize).split(' '):
+                params[p] = None
+        return params
 
     def __iter__(self):
         """yield all parts contained in the stream"""
         # make sure param have been loaded
         self.params
diff --git a/tests/test-bundle2.t b/tests/test-bundle2.t
--- a/tests/test-bundle2.t
+++ b/tests/test-bundle2.t
@@ -28,10 +28,12 @@  Create an extension to test bundle2 API
   > @command('unbundle2', [], '')
   > def cmdunbundle2(ui, repo):
   >     """read a bundle2 container from standard input"""
   >     unbundler = bundle2.unbundler(sys.stdin)
   >     ui.write('options count: %i\n' % len(unbundler.params))
+  >     for key in sorted(unbundler.params):
+  >         print '-', key
   >     parts = list(unbundler)
   >     ui.write('parts count:   %i\n' % len(parts))
   > EOF
   $ cat >> $HGRCPATH << EOF
   > [extensions]
@@ -81,14 +83,30 @@  Test parameters
 advisory parameters, no value
 -------------------------------
 
 Simplest possible parameters form
 
-Test generation
+Test generation simple option
 
   $ hg bundle2 --param 'caution'
   HG20\x00\x07caution\x00\x00 (no-eol) (esc)
 
+Test unbundling
+
+  $ hg bundle2 --param 'caution' | hg unbundle2
+  options count: 1
+  - caution
+  parts count:   0
+
 Test generation multiple option
 
   $ hg bundle2 --param 'caution' --param 'meal'
   HG20\x00\x0ccaution meal\x00\x00 (no-eol) (esc)
+
+Test unbundling
+
+  $ hg bundle2 --param 'caution' --param 'meal' | hg unbundle2
+  options count: 2
+  - caution
+  - meal
+  parts count:   0
+