Patchwork [14,of,14,FIX-bundle2] bundlerepo: properly extra compressed changegroup from bundle2

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 20, 2015, 2:36 p.m.
Message ID <a8f783c1722b71b54b68.1445351790@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/11192/
State Accepted
Headers show

Comments

Pierre-Yves David - Oct. 20, 2015, 2:36 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1445263315 -7200
#      Mon Oct 19 16:01:55 2015 +0200
# Node ID a8f783c1722b71b54b68d0d5c68612854cc00340
# Parent  7ab1d8aeeba134c8152379b32ae466f0a38c5660
# EXP-Topic generaldelta
# Available At http://hg.netv6.net/marmoute-wip/mercurial/
#              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r a8f783c1722b
bundlerepo: properly extra compressed changegroup from bundle2

Before this bundle repository were unable to work with compressed bundle2. We
use the same approach as with bundle1, we extra the changegroup in uncompressed
form into a temporary file.

Patch

diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -275,26 +275,30 @@  class bundlerepository(localrepo.localre
         self.tempfile = None
         f = util.posixfile(bundlename, "rb")
         self.bundlefile = self.bundle = exchange.readbundle(ui, f, bundlename)
 
         if isinstance(self.bundle, bundle2.unbundle20):
-            cgparts = [part for part in self.bundle.iterparts()
-                       if (part.type == 'changegroup')
-                       and (part.params.get('version', '01')
-                            in changegroup.packermap)]
+            cgstream = None
+            for part in self.bundle.iterparts():
+                if part.type == 'changegroup':
+                    if cgstream is not None:
+                        raise NotImplementedError("Can't process "
+                                                  "multiple changegroups")
+                    cgstream = part
+                    version = part.params.get('version', '01')
+                    if version not in changegroup.packermap:
+                        msg = _('Unsupported changegroup version: %s')
+                        raise error.Abort(msg % version)
+                    if self.bundle.compressed():
+                        cgstream = _writetempbundle(part.read,
+                                                    ".cg%sun" % version)
 
-            if not cgparts:
+            if cgstream is None:
                 raise error.Abort('No changegroups found')
-            version = cgparts[0].params.get('version', '01')
-            cgparts = [p for p in cgparts
-                       if p.params.get('version', '01') == version]
-            if len(cgparts) > 1:
-                raise NotImplementedError("Can't process multiple changegroups")
-            part = cgparts[0]
+            cgstream.seek(0)
 
-            part.seek(0)
-            self.bundle = changegroup.packermap[version][1](part, 'UN')
+            self.bundle = changegroup.packermap[version][1](cgstream, 'UN')
 
         elif self.bundle.compressed():
             f = _writetempbundle(self.bundle.read, '.hg10un', header='HG10UN')
             self.bundlefile = self.bundle = exchange.readbundle(ui, f,
                                                                 bundlename,