From patchwork Wed Aug 23 20:31:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D290: bundlerepo: move bundle2 part handling out to a function From: phabricator X-Patchwork-Id: 23279 Message-Id: <220cb1a21d3a3ee19378ddb7eda0aa9c@localhost.localdomain> To: mercurial-devel@mercurial-scm.org Date: Wed, 23 Aug 2017 20:31:25 +0000 This revision was automatically updated to reflect the committed changes. Closed by commit rHGf672d060a931: bundlerepo: move bundle2 part handling out to a function (authored by durham). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D290?vs=1217&id=1229 REVISION DETAIL https://phab.mercurial-scm.org/D290 AFFECTED FILES mercurial/bundlerepo.py CHANGE DETAILS To: durham, #hg-reviewers, indygreg Cc: mercurial-devel diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py --- a/mercurial/bundlerepo.py +++ b/mercurial/bundlerepo.py @@ -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 """