[PATCH 4 of 8] bundle2: move unpackheader closure on the class

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Sat Apr 12 17:08:43 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1397245658 14400
#      Fri Apr 11 15:47:38 2014 -0400
# Node ID 372163682f8801aaf1986c819da6a5bb03bdec76
# Parent  e214c047eeb7227e987558dc97961fac08942c18
bundle2: move unpackheader closure on the class

With the same argument than the other one, we move this closure on the
unbundlepart class.

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -557,31 +557,33 @@ class unbundlepart(unpackermixing):
         offset = self._headeroffset
         data = self._headerdata[offset:(offset + size)]
         self._headeroffset += size
         return data
 
+    def _unpackheader(self, format):
+        """read given format from header
+
+        This automatically compute the size of the format to read."""
+        data = self._fromheader(struct.calcsize(format))
+        return _unpack(format, data)
+
     def _readdata(self):
         """read the header and setup the object"""
         # some utility to help reading from the header block
-        def unpackheader(format):
-            """read given format from header
 
-            This automatically compute the size of the format to read."""
-            data = self._fromheader(struct.calcsize(format))
-            return _unpack(format, data)
-
-        typesize = unpackheader(_fparttypesize)[0]
+        typesize = self._unpackheader(_fparttypesize)[0]
         self.type = self._fromheader(typesize)
         self.ui.debug('part type: "%s"\n' % self.type)
-        self.id = unpackheader(_fpartid)[0]
+        self.id = self._unpackheader(_fpartid)[0]
         self.ui.debug('part id: "%s"\n' % self.id)
         ## reading parameters
         # param count
-        mancount, advcount = unpackheader(_fpartparamcount)
+        mancount, advcount = self._unpackheader(_fpartparamcount)
         self.ui.debug('part parameters: %i\n' % (mancount + advcount))
         # param size
-        paramsizes = unpackheader(_makefpartparamsizes(mancount + advcount))
+        fparamsizes = _makefpartparamsizes(mancount + advcount)
+        paramsizes = self._unpackheader(fparamsizes)
         # make it a list of couple again
         paramsizes = zip(paramsizes[::2], paramsizes[1::2])
         # split mandatory from advisory
         mansizes = paramsizes[:mancount]
         advsizes = paramsizes[mancount:]


More information about the Mercurial-devel mailing list