[PATCH 6 of 8] changegroup: give a way to includes header in getchunks

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Fri Apr 11 17:06:03 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1397224885 25200
#      Fri Apr 11 07:01:25 2014 -0700
# Node ID 95eaf9fabeb354ac0dc6f924ce1482e9a8bf1537
# Parent  6eef726e8e85dd6011fc61951c6dc7e4984df721
changegroup: give a way to includes header in getchunks

For bundle2 we want a simple way to stream a full changegroup. We need a header
for that. We add the option for `unbundle10` to do this. This stay optional
because `writebundle` may use compression and need to write its own header.

When we use an header, we use "HG10UN", as `getchunks` yield uncompressed chunk.
We rely on compression of the container for now.

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -89,11 +89,11 @@ def writebundle(cg, filename, bundletype
         # in case of sshrepo because we don't know the end of the stream
 
         # an empty chunkgroup is the end of the changegroup
         # a changegroup has at least 2 chunkgroups (changelog and manifest).
         # after that, an empty chunkgroup is the end of the changegroup
-        for chunk in cg.getchunks():
+        for chunk in cg.getchunks(includeheader=False):
             fh.write(z.compress(chunk))
         fh.write(z.flush())
         cleanup = None
         return filename
     finally:
@@ -185,20 +185,23 @@ class unbundle10(object):
         delta = readexactly(self._stream, l - self.deltaheadersize)
         node, p1, p2, deltabase, cs = self._deltaheader(header, prevnode)
         return {'node': node, 'p1': p1, 'p2': p2, 'cs': cs,
                 'deltabase': deltabase, 'delta': delta}
 
-    def getchunks(self):
+    def getchunks(self, includeheader=True):
         """returns all the chunks contains in the bundle
 
         Used when you need to forward the binary stream to a file or another
         network API. To do so, it parse the changegroup data, otherwise it will
         block in case of sshrepo because it don't know the end of the stream.
         """
         # an empty chunkgroup is the end of the changegroup
         # a changegroup has at least 2 chunkgroups (changelog and manifest).
         # after that, an empty chunkgroup is the end of the changegroup
+        if includeheader:
+            # do not use self._type as yielded chunk are not compressed
+            yield 'HG10UN'
         empty = False
         count = 0
         while not empty or count <= 2:
             empty = True
             count += 1


More information about the Mercurial-devel mailing list