Patchwork [7,of,8] bundle2: extract a _payloadchunks method for part

login
register
mail settings
Submitter Pierre-Yves David
Date April 11, 2014, 10:06 p.m.
Message ID <e6261a31c9a819d972f4.1397253964@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4290/
State Accepted
Headers show

Comments

Pierre-Yves David - April 11, 2014, 10:06 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1397158400 25200
#      Thu Apr 10 12:33:20 2014 -0700
# Node ID e6261a31c9a819d972f404f5c3301d6e5f5ff3f3
# Parent  95eaf9fabeb354ac0dc6f924ce1482e9a8bf1537
bundle2: extract a _payloadchunks method for part

We are preparing streaming capability for part. So the generation of payload
chunk will becomes more complex. We extract this part in its own function before
any changes.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -547,17 +547,24 @@  class part(object):
         ## finalize header
         headerchunk = ''.join(header)
         yield _pack(_fpartheadersize, len(headerchunk))
         yield headerchunk
         ## payload
+        for chunk in self._payloadchunks():
+            yield _pack(_fpayloadsize, len(chunk))
+            yield chunk
+        # end of payload
+        yield _pack(_fpayloadsize, 0)
+
+    def _payloadchunks(self):
+        """yield chunks of a the part payload
+
+        Exists to handle the different methods to provide data to a part."""
         # we only support fixed size data now.
         # This will be improved in the future.
         if len(self.data):
-            yield _pack(_fpayloadsize, len(self.data))
             yield self.data
-        # end of payload
-        yield _pack(_fpayloadsize, 0)
 
 @parthandler('changegroup')
 def handlechangegroup(op, inpart):
     """apply a changegroup part on the repo