changeset 33889:f672d060a931

bundlerepo: move bundle2 part handling out to a function This moves the bundle2 part handling for bundlerepo out to a separate function so extensions can participate in bundlerepo setup when using bundle2 bundles. Differential Revision: https://phab.mercurial-scm.org/D290
author Durham Goode <durham@fb.com>
date Wed, 23 Aug 2017 12:35:03 -0700
parents 891118dcd279
children 3de9a2df6411
files mercurial/bundlerepo.py
diffstat 1 files changed, 20 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundlerepo.py	Wed Aug 23 12:35:03 2017 -0700
+++ b/mercurial/bundlerepo.py	Wed Aug 23 12:35:03 2017 -0700
@@ -283,26 +283,18 @@
         self.bundlefile = self.bundle = exchange.readbundle(ui, f, bundlename)
 
         if isinstance(self.bundle, bundle2.unbundle20):
-            cgstream = None
+            hadchangegroup = False
             for part in self.bundle.iterparts():
                 if part.type == 'changegroup':
-                    if cgstream is not None:
+                    if hadchangegroup:
                         raise NotImplementedError("can't process "
                                                   "multiple changegroups")
-                    cgstream = part
-                    version = part.params.get('version', '01')
-                    legalcgvers = changegroup.supportedincomingversions(self)
-                    if version not in legalcgvers:
-                        msg = _('Unsupported changegroup version: %s')
-                        raise error.Abort(msg % version)
-                    if self.bundle.compressed():
-                        cgstream = self._writetempbundle(part.read,
-                                                         ".cg%sun" % version)
+                    hadchangegroup = True
 
-            if cgstream is None:
-                raise error.Abort(_('No changegroups found'))
+                self._handlebundle2part(part)
 
-            self.bundle = changegroup.getunbundler(version, cgstream, 'UN')
+            if not hadchangegroup:
+                raise error.Abort(_("No changegroups found"))
 
         elif self.bundle.compressed():
             f = self._writetempbundle(self.bundle.read, '.hg10un',
@@ -318,6 +310,20 @@
         phases.retractboundary(self, None, phases.draft,
                                [ctx.node() for ctx in self[self.firstnewrev:]])
 
+    def _handlebundle2part(self, part):
+        if part.type == 'changegroup':
+            cgstream = part
+            version = part.params.get('version', '01')
+            legalcgvers = changegroup.supportedincomingversions(self)
+            if version not in legalcgvers:
+                msg = _('Unsupported changegroup version: %s')
+                raise error.Abort(msg % version)
+            if self.bundle.compressed():
+                cgstream = self._writetempbundle(part.read,
+                                                 ".cg%sun" % version)
+
+            self.bundle = changegroup.getunbundler(version, cgstream, 'UN')
+
     def _writetempbundle(self, readfn, suffix, header=''):
         """Write a temporary file to disk
         """