[PATCH 4 of 7 main-line-of-works (28 more patches to go)]] bundle2: add debug output for part generation

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu May 28 11:53:15 CDT 2015


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1432713121 25200
#      Wed May 27 00:52:01 2015 -0700
# Node ID 5fef62c3e3e5a2b525fcb721084546931475b1b6
# Parent  7660759a9bdb444daaa104c30496f4eb0a350cb8
bundle2: add debug output for part generation

The part generation process was lacking a ui object and could not produce debug
output. It seems valuable to have some debug output on this part too, especially
now that we are planning to be able to hide it in the default --debug output.

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -481,11 +481,11 @@ class bundle20(object):
             yield param
 
         outdebug(self.ui, 'start of parts')
         for part in self._parts:
             outdebug(self.ui, 'bundle part: "%s"' % part.type)
-            for chunk in part.getchunks():
+            for chunk in part.getchunks(ui=self.ui):
                 yield chunk
         outdebug(self.ui, 'end of bundle')
         yield _pack(_fpartheadersize, 0)
 
     def _paramchunk(self):
@@ -724,19 +724,20 @@ class bundlepart(object):
         if mandatory:
             params = self._mandatoryparams
         params.append((name, value))
 
     # methods used to generates the bundle2 stream
-    def getchunks(self):
+    def getchunks(self, ui):
         if self._generated is not None:
             raise RuntimeError('part can only be consumed once')
         self._generated = False
         #### header
         if self.mandatory:
             parttype = self.type.upper()
         else:
             parttype = self.type.lower()
+        outdebug(ui, 'part %s: "%s"' % (self.id, parttype))
         ## parttype
         header = [_pack(_fparttypesize, len(parttype)),
                   parttype, _pack(_fpartid, self.id),
                  ]
         ## parameters
@@ -761,31 +762,35 @@ class bundlepart(object):
         for key, value in advpar:
             header.append(key)
             header.append(value)
         ## finalize header
         headerchunk = ''.join(header)
+        outdebug(ui, 'header chunk size: %i' % len(headerchunk))
         yield _pack(_fpartheadersize, len(headerchunk))
         yield headerchunk
         ## payload
         try:
             for chunk in self._payloadchunks():
+                outdebug(ui, 'payload chunk size: %i' % len(chunk))
                 yield _pack(_fpayloadsize, len(chunk))
                 yield chunk
         except BaseException, exc:
             # backup exception data for later
             exc_info = sys.exc_info()
             msg = 'unexpected error: %s' % exc
             interpart = bundlepart('error:abort', [('message', msg)],
                                    mandatory=False)
             interpart.id = 0
             yield _pack(_fpayloadsize, -1)
-            for chunk in interpart.getchunks():
+            for chunk in interpart.getchunks(ui=ui):
                 yield chunk
+            outdebug(ui, 'closing payload chunk')
             # abort current part payload
             yield _pack(_fpayloadsize, 0)
             raise exc_info[0], exc_info[1], exc_info[2]
         # end of payload
+        outdebug(ui, 'closing payload chunk')
         yield _pack(_fpayloadsize, 0)
         self._generated = True
 
     def _payloadchunks(self):
         """yield chunks of a the part payload
diff --git a/tests/test-bundle2-format.t b/tests/test-bundle2-format.t
--- a/tests/test-bundle2-format.t
+++ b/tests/test-bundle2-format.t
@@ -386,16 +386,39 @@ Test part
   $ hg bundle2 --parts ../parts.hg2 --debug --config progress.debug=true
   bundle2-output: start emission of HG20 stream
   bundle2-output: bundle parameter: 
   bundle2-output: start of parts
   bundle2-output: bundle part: "test:empty"
+  bundle2-output: part 0: "test:empty"
+  bundle2-output: header chunk size: 17
+  bundle2-output: closing payload chunk
   bundle2-output: bundle part: "test:empty"
+  bundle2-output: part 1: "test:empty"
+  bundle2-output: header chunk size: 17
+  bundle2-output: closing payload chunk
   bundle2-output: bundle part: "test:song"
+  bundle2-output: part 2: "test:song"
+  bundle2-output: header chunk size: 16
+  bundle2-output: payload chunk size: 178
+  bundle2-output: closing payload chunk
   bundle2-output: bundle part: "test:debugreply"
+  bundle2-output: part 3: "test:debugreply"
+  bundle2-output: header chunk size: 22
+  bundle2-output: closing payload chunk
   bundle2-output: bundle part: "test:math"
+  bundle2-output: part 4: "test:math"
+  bundle2-output: header chunk size: 43
+  bundle2-output: payload chunk size: 2
+  bundle2-output: closing payload chunk
   bundle2-output: bundle part: "test:song"
+  bundle2-output: part 5: "test:song"
+  bundle2-output: header chunk size: 29
+  bundle2-output: closing payload chunk
   bundle2-output: bundle part: "test:ping"
+  bundle2-output: part 6: "test:ping"
+  bundle2-output: header chunk size: 16
+  bundle2-output: closing payload chunk
   bundle2-output: end of bundle
 
   $ cat ../parts.hg2
   HG20\x00\x00\x00\x00\x00\x00\x00\x11 (esc)
   test:empty\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11 (esc)
@@ -713,10 +736,12 @@ Support for changegroup
   02de42196ebee42ef284b6780a87cdc96e8eaab6
   bundle2-output: start emission of HG20 stream
   bundle2-output: bundle parameter: 
   bundle2-output: start of parts
   bundle2-output: bundle part: "changegroup"
+  bundle2-output: part 0: "changegroup"
+  bundle2-output: header chunk size: 18
   bundling: 1/4 changesets (25.00%)
   bundling: 2/4 changesets (50.00%)
   bundling: 3/4 changesets (75.00%)
   bundling: 4/4 changesets (100.00%)
   bundling: 1/4 manifests (25.00%)
@@ -724,10 +749,12 @@ Support for changegroup
   bundling: 3/4 manifests (75.00%)
   bundling: 4/4 manifests (100.00%)
   bundling: D 1/3 files (33.33%)
   bundling: E 2/3 files (66.67%)
   bundling: H 3/3 files (100.00%)
+  bundle2-output: payload chunk size: 1555
+  bundle2-output: closing payload chunk
   bundle2-output: end of bundle
 
   $ cat ../rev.hg2
   HG20\x00\x00\x00\x00\x00\x00\x00\x12\x0bchangegroup\x00\x00\x00\x00\x00\x00\x00\x00\x06\x13\x00\x00\x00\xa42\xafv\x86\xd4\x03\xcfE\xb5\xd9_-p\xce\xbe\xa5\x87\xac\x80j_\xdd\xd9\x89W\xc8\xa5JMCm\xfe\x1d\xa9\xd8\x7f!\xa1\xb9{\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x002\xafv\x86\xd4\x03\xcfE\xb5\xd9_-p\xce\xbe\xa5\x87\xac\x80j\x00\x00\x00\x00\x00\x00\x00)\x00\x00\x00)6e1f4c47ecb533ffd0c8e52cdc88afb6cd39e20c (esc)
   \x00\x00\x00f\x00\x00\x00h\x00\x00\x00\x02D (esc)


More information about the Mercurial-devel mailing list