Patchwork [1,of,4] bundle2.unbundlepart: raise payloadchunks from a closure to a method

login
register
mail settings
Submitter Eric Sumner
Date Feb. 4, 2015, 7:29 p.m.
Message ID <3403436c7237eb359bdf.1423078175@waste.org>
Download mbox | patch
Permalink /patch/7668/
State Accepted
Commit 9881a1437799cbef382670ff6900c948c8992257
Headers show

Comments

Eric Sumner - Feb. 4, 2015, 7:29 p.m.
# HG changeset patch
# User Eric Sumner <ericsumner@fb.com>
# Date 1421274742 28800
#      Wed Jan 14 14:32:22 2015 -0800
# Node ID 3403436c7237eb359bdf69f1ba438eb4c6a3db12
# Parent  e1dbe0b215ae137eec53ceb12440536d570a83d2
bundle2.unbundlepart: raise payloadchunks from a closure to a method

In a future patch, seek() will need to make a new chunk iterator for the stream;
this places it somewhere it can be called multiple times.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -852,6 +852,22 @@ 
         self.params.update(dict(self.advisoryparams))
         self.mandatorykeys = frozenset(p[0] for p in mandatoryparams)
 
+    def _payloadchunks(self):
+        payloadsize = self._unpack(_fpayloadsize)[0]
+        self.ui.debug('payload chunk size: %i\n' % payloadsize)
+        while payloadsize:
+            if payloadsize == flaginterrupt:
+                # interruption detection, the handler will now read a
+                # single part and process it.
+                interrupthandler(self.ui, self._fp)()
+            elif payloadsize < 0:
+                msg = 'negative payload chunk size: %i' %  payloadsize
+                raise error.BundleValueError(msg)
+            else:
+                yield self._readexact(payloadsize)
+            payloadsize = self._unpack(_fpayloadsize)[0]
+            self.ui.debug('payload chunk size: %i\n' % payloadsize)
+
     def _readheader(self):
         """read the header and setup the object"""
         typesize = self._unpackheader(_fparttypesize)[0]
@@ -883,22 +899,7 @@ 
             advparams.append((self._fromheader(key), self._fromheader(value)))
         self._initparams(manparams, advparams)
         ## part payload
-        def payloadchunks():
-            payloadsize = self._unpack(_fpayloadsize)[0]
-            self.ui.debug('payload chunk size: %i\n' % payloadsize)
-            while payloadsize:
-                if payloadsize == flaginterrupt:
-                    # interruption detection, the handler will now read a
-                    # single part and process it.
-                    interrupthandler(self.ui, self._fp)()
-                elif payloadsize < 0:
-                    msg = 'negative payload chunk size: %i' %  payloadsize
-                    raise error.BundleValueError(msg)
-                else:
-                    yield self._readexact(payloadsize)
-                payloadsize = self._unpack(_fpayloadsize)[0]
-                self.ui.debug('payload chunk size: %i\n' % payloadsize)
-        self._payloadstream = util.chunkbuffer(payloadchunks())
+        self._payloadstream = util.chunkbuffer(self._payloadchunks())
         # we read the data, tell it
         self._initialized = True