[PATCH 3 of 4] bundle2: print debug information during unbundling

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Fri Mar 21 17:12:55 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1395274309 25200
#      Wed Mar 19 17:11:49 2014 -0700
# Node ID 8d47c765129239116a52caffbdc61e21171cdf9c
# Parent  d59b5c916f3be745fd19fab9dacc02f2352eeea0
bundle2: print debug information during unbundling

The unbundler class is now feed with an ui object and use it to transmit data
about the unbundling process.

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -139,18 +139,20 @@ class bundle20(object):
 class unbundle20(object):
     """interpret a bundle2 stream
 
     (this will eventually yield parts)"""
 
-    def __init__(self, fp):
+    def __init__(self, ui, fp):
+        self.ui = ui
         self._fp = fp
         header = self._readexact(4)
         magic, version = header[0:2], header[2:4]
         if magic != 'HG':
             raise util.Abort(_('not a Mercurial bundle'))
         if version != '20':
             raise util.Abort(_('unknown bundle version %s') % version)
+        self.ui.debug('start processing of %s stream\n' % header)
 
     def _unpack(self, format):
         """unpack this struct format from the stream"""
         data = self._readexact(struct.calcsize(format))
         return _unpack(format, data)
@@ -160,10 +162,11 @@ class unbundle20(object):
         return changegroup.readexactly(self._fp, size)
 
     @util.propertycache
     def params(self):
         """dictionnary of stream level parameters"""
+        self.ui.debug('reading bundle2 stream parameters\n')
         params = {}
         paramssize = self._unpack(_fstreamparamsize)[0]
         if paramssize:
             for p in self._readexact(paramssize).split(' '):
                 p = p.split('=', 1)
@@ -175,14 +178,16 @@ class unbundle20(object):
 
     def __iter__(self):
         """yield all parts contained in the stream"""
         # make sure param have been loaded
         self.params
+        self.ui.debug('start extraction of bundle2 parts\n')
         part = self._readpart()
         while part is not None:
             yield part
             part = self._readpart()
+        self.ui.debug('end of bundle2 stream\n')
 
     def _readpart(self):
         """return None when an end of stream markers is reach"""
         headersize = self._readexact(2)
         assert headersize == '\0\0'
diff --git a/tests/test-bundle2.t b/tests/test-bundle2.t
--- a/tests/test-bundle2.t
+++ b/tests/test-bundle2.t
@@ -37,11 +37,11 @@ Create an extension to test bundle2 API
   >         file.write(chunk)
   > 
   > @command('unbundle2', [], '')
   > def cmdunbundle2(ui, repo):
   >     """read a bundle2 container from standard input"""
-  >     unbundler = bundle2.unbundle20(sys.stdin)
+  >     unbundler = bundle2.unbundle20(ui, sys.stdin)
   >     ui.write('options count: %i\n' % len(unbundler.params))
   >     for key in sorted(unbundler.params):
   >         ui.write('- %s\n' % key)
   >         value = unbundler.params[key]
   >         if value is not None:
@@ -160,20 +160,36 @@ Test unbundling
   parts count:   0
 
 Test debug output
 ---------------------------------------------------
 
+bundling debug
+
   $ hg bundle2 --debug --param 'e|! 7/=babar%#==tutu' --param simple ../out.hg2
   start emission of HG20 stream
   bundle parameter: e%7C%21%207/=babar%25%23%3D%3Dtutu simple
   end of bundle
 
 file content is ok
 
   $ cat ../out.hg2
   HG20\x00)e%7C%21%207/=babar%25%23%3D%3Dtutu simple\x00\x00 (no-eol) (esc)
 
+unbundling debug
+
+  $ hg unbundle2 --debug < ../out.hg2
+  start processing of HG20 stream
+  reading bundle2 stream parameters
+  options count: 2
+  - e|! 7/
+      babar%#==tutu
+  - simple
+  start extraction of bundle2 parts
+  end of bundle2 stream
+  parts count:   0
+
+
 Test buggy input
 ---------------------------------------------------
 
 empty parameter name
 


More information about the Mercurial-devel mailing list