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

login
register
mail settings
Submitter Pierre-Yves David
Date April 12, 2014, 10:08 p.m.
Message ID <372163682f8801aaf198.1397340523@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4306/
State Accepted
Headers show

Comments

Pierre-Yves David - April 12, 2014, 10:08 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.

Patch

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:]