changeset 20843:0641b41b0b49

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.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Wed, 19 Mar 2014 17:11:49 -0700
parents 938718d72624
children 2631204d7305
files mercurial/bundle2.py tests/test-bundle2.t
diffstat 2 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundle2.py	Tue Mar 18 19:07:10 2014 -0700
+++ b/mercurial/bundle2.py	Wed Mar 19 17:11:49 2014 -0700
@@ -141,7 +141,8 @@
 
     (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]
@@ -149,6 +150,7 @@
             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"""
@@ -162,6 +164,7 @@
     @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:
@@ -177,10 +180,12 @@
         """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"""
--- a/tests/test-bundle2.t	Tue Mar 18 19:07:10 2014 -0700
+++ b/tests/test-bundle2.t	Wed Mar 19 17:11:49 2014 -0700
@@ -39,7 +39,7 @@
   > @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)
@@ -162,6 +162,8 @@
 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
@@ -172,6 +174,20 @@
   $ 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
 ---------------------------------------------------