changeset 34259:07e4170f02f3

bundle2: move handler validation out of processpart As part of refactoring bundle part processing let's move handler validation to its own function. Differential Revision: https://phab.mercurial-scm.org/D707
author Durham Goode <durham@fb.com>
date Thu, 14 Sep 2017 10:20:05 -0700
parents e71890f27767
children cc7b37c90616
files mercurial/bundle2.py
diffstat 1 files changed, 43 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundle2.py	Thu Sep 14 10:20:05 2017 -0700
+++ b/mercurial/bundle2.py	Thu Sep 14 10:20:05 2017 -0700
@@ -460,48 +460,55 @@
     })
     return ret
 
+def _gethandler(op, part):
+    status = 'unknown' # used by debug output
+    try:
+        handler = parthandlermapping.get(part.type)
+        if handler is None:
+            status = 'unsupported-type'
+            raise error.BundleUnknownFeatureError(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.BundleUnknownFeatureError(parttype=part.type,
+                                                  params=unknownparams)
+        status = 'supported'
+    except error.BundleUnknownFeatureError as 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))
+
+    return handler
+
 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.BundleUnknownFeatureError(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.BundleUnknownFeatureError(parttype=part.type,
-                                                      params=unknownparams)
-            status = 'supported'
-        except error.BundleUnknownFeatureError as 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 = _gethandler(op, part)
+        if handler is None:
+            return
 
         # handler is called outside the above try block so that we don't
         # risk catching KeyErrors from anything other than the