Patchwork [3,of,6,main-line-of-works,(22,more,patches,to,go)] ] bundle2: add generic debug output regarding processed part

login
register
mail settings
Submitter Pierre-Yves David
Date May 28, 2015, 7:54 p.m.
Message ID <89b06c85a41c31cf00a6.1432842860@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/9336/
State Superseded
Commit 5bfffdbdc9079cbdf6ba745ab12c15e5ce1032f3
Headers show

Comments

Pierre-Yves David - May 28, 2015, 7:54 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1432708591 25200
#      Tue May 26 23:36:31 2015 -0700
# Node ID 89b06c85a41c31cf00a68f784d03dadc2308d655
# Parent  7e90773b13a2e68fa30db6d7fcc61e86ecbb103e
bundle2: add generic debug output regarding processed part

If we are about to hide the detailed debug output, we need some generic debug
message to replace it.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -357,27 +357,47 @@  def processbundle(repo, unbundler, trans
 def _processpart(op, part):
     """process a single part from a bundle
 
     The part is guaranteed to have been fully consumed when the function exits
     (even if an exception is raised)."""
+    status = 'unknown' # used by debug output
     try:
         try:
             handler = parthandlermapping.get(part.type)
             if handler is None:
+                status = 'unsupported-type'
                 raise error.UnsupportedPartError(parttype=part.type)
             indebug(op.ui, 'found a handler for part %r' % part.type)
             unknownparams = part.mandatorykeys - handler.params
             if unknownparams:
                 unknownparams = list(unknownparams)
                 unknownparams.sort()
+                status = 'unsupported-params (%s)' % unknownparams
                 raise error.UnsupportedPartError(parttype=part.type,
                                                params=unknownparams)
+            status = 'supported'
         except error.UnsupportedPartError, exc:
             if part.mandatory: # mandatory parts
                 raise
             indebug(op.ui, 'ignoring unsupported advisory part %s' % exc)
             return # skip to part processing
+        finally:
+            if op.ui.debugflag:
+                msg = ['bundle2-input-part: "%s"' % part.type]
+                if not part.mandatory:
+                    msg.append(' (advisory)')
+                nbmp = len(part.mandatorykeys)
+                nbap = len(part.params) - nbmp
+                if nbmp or nbap:
+                    msg.append(' (params:')
+                    if nbmp:
+                        msg.append(' %i mandatory' % nbmp)
+                    if nbap:
+                        msg.append(' %i advisory' % nbmp)
+                    msg.append(')')
+                msg.append(' %s\n' % status)
+                op.ui.debug(''.join(msg))
 
         # handler is called outside the above try block so that we don't
         # risk catching KeyErrors from anything other than the
         # parthandlermapping lookup (any KeyError raised by handler()
         # itself represents a defect of a different variety).
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
@@ -555,22 +555,25 @@  Process the bundle
   bundle2-input: part header size: 17
   bundle2-input: part type: "test:empty"
   bundle2-input: part id: "0"
   bundle2-input: part parameters: 0
   bundle2-input: ignoring unsupported advisory part test:empty
+  bundle2-input-part: "test:empty" (advisory) unsupported-type
   bundle2-input: payload chunk size: 0
   bundle2-input: part header size: 17
   bundle2-input: part type: "test:empty"
   bundle2-input: part id: "1"
   bundle2-input: part parameters: 0
   bundle2-input: ignoring unsupported advisory part test:empty
+  bundle2-input-part: "test:empty" (advisory) unsupported-type
   bundle2-input: payload chunk size: 0
   bundle2-input: part header size: 16
   bundle2-input: part type: "test:song"
   bundle2-input: part id: "2"
   bundle2-input: part parameters: 0
   bundle2-input: found a handler for part 'test:song'
+  bundle2-input-part: "test:song" (advisory) supported
   The choir starts singing:
   bundle2-input: payload chunk size: 178
   bundle2-input: payload chunk size: 0
       Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko
       Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
@@ -578,31 +581,35 @@  Process the bundle
   bundle2-input: part header size: 22
   bundle2-input: part type: "test:debugreply"
   bundle2-input: part id: "3"
   bundle2-input: part parameters: 0
   bundle2-input: found a handler for part 'test:debugreply'
+  bundle2-input-part: "test:debugreply" (advisory) supported
   debugreply: no reply
   bundle2-input: payload chunk size: 0
   bundle2-input: part header size: 43
   bundle2-input: part type: "test:math"
   bundle2-input: part id: "4"
   bundle2-input: part parameters: 3
   bundle2-input: ignoring unsupported advisory part test:math
+  bundle2-input-part: "test:math" (advisory) (params: 2 mandatory 2 advisory) unsupported-type
   bundle2-input: payload chunk size: 2
   bundle2-input: payload chunk size: 0
   bundle2-input: part header size: 29
   bundle2-input: part type: "test:song"
   bundle2-input: part id: "5"
   bundle2-input: part parameters: 1
   bundle2-input: found a handler for part 'test:song'
   bundle2-input: ignoring unsupported advisory part test:song - randomparam
+  bundle2-input-part: "test:song" (advisory) (params: 1 mandatory) unsupported-params (['randomparam'])
   bundle2-input: payload chunk size: 0
   bundle2-input: part header size: 16
   bundle2-input: part type: "test:ping"
   bundle2-input: part id: "6"
   bundle2-input: part parameters: 0
   bundle2-input: found a handler for part 'test:ping'
+  bundle2-input-part: "test:ping" (advisory) supported
   received ping request (id 6)
   bundle2-input: payload chunk size: 0
   bundle2-input: part header size: 0
   bundle2-input: end of bundle2 stream
   bundle2-input-bundle: 6 parts total