Patchwork [1,of,5] bundle2.unbundlepart: decouple mandatory from parttype

login
register
mail settings
Submitter Eric Sumner
Date Dec. 16, 2014, 9:57 p.m.
Message ID <e28406020f46ee791c4c.1418767050@dev911.prn1.facebook.com>
Download mbox | patch
Permalink /patch/7126/
State Accepted
Commit 94b25d71dd0f32a408ec12264ea3fe6b9ca63ff1
Delegated to: Pierre-Yves David
Headers show

Comments

Eric Sumner - Dec. 16, 2014, 9:57 p.m.
# HG changeset patch
# User Eric Sumner <ericsumner@fb.com>
# Date 1418412416 28800
#      Fri Dec 12 11:26:56 2014 -0800
# Node ID e28406020f46ee791c4c7aa71915ce869c4a579d
# Parent  416c133145ee78c8e83865b7370e185eed69c1be
bundle2.unbundlepart: decouple mandatory from parttype

Encoding whether or not a part is mandatory in the capitalization of the
parttype is unintuitive and error-prone.  This sequence of patches separates
these concerns in the API to reduce programmer error and pave the way for
a potential change in how this information is transmitted over the wire.

This patch separates the two pieces of information when reading the part header
so that it's unnecessary to know how they were combined during transmission.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -334,7 +334,7 @@ 
                 raise error.UnsupportedPartError(parttype=key,
                                                params=unknownparams)
         except error.UnsupportedPartError, exc:
-            if key != parttype: # mandatory parts
+            if part.mandatory: # mandatory parts
                 raise
             op.ui.debug('ignoring unsupported advisory part %s\n' % exc)
             return # skip to part processing
@@ -786,6 +786,7 @@ 
         self.mandatorykeys = ()
         self._payloadstream = None
         self._readheader()
+        self._mandatory = None
 
     def _fromheader(self, size):
         """return the next <size> byte from the header"""
@@ -818,6 +819,9 @@ 
         self.ui.debug('part type: "%s"\n' % self.type)
         self.id = self._unpackheader(_fpartid)[0]
         self.ui.debug('part id: "%s"\n' % self.id)
+        # extract mandatory bit from type
+        self.mandatory = (self.type != self.type.lower())
+        self.type = self.type.lower()
         ## reading parameters
         # param count
         mancount, advcount = self._unpackheader(_fpartparamcount)