# HG changeset patch # User Gregory Szorc # Date 1510454090 28800 # Node ID 495fcff101249ac2e062655425f11ce90e0d65df # Parent df2a676a2e9ef1eeba3fe7ae3b79200e140c458b bundlerepo: assign bundle attributes in bundle type blocks It is a bit wonky to assign the same object to multiple attributes and then possibly overwrite them later. Refactor the code to use a local variable and defer attribute assignment until the final values are ready. This required passing the bundle instance to _handlebundle2part(). The only use of this method I could find is Facebook's treemanifest extension. Since it is a private method, I don't think it warrants an API callout. Differential Revision: https://phab.mercurial-scm.org/D1378 diff -r df2a676a2e9e -r 495fcff10124 mercurial/bundlerepo.py --- a/mercurial/bundlerepo.py Sat Nov 11 18:22:36 2017 -0800 +++ b/mercurial/bundlerepo.py Sat Nov 11 18:34:50 2017 -0800 @@ -281,30 +281,35 @@ self.tempfile = None f = util.posixfile(bundlepath, "rb") - self._bundlefile = self._bundle = exchange.readbundle(ui, f, bundlepath) + bundle = exchange.readbundle(ui, f, bundlepath) - if isinstance(self._bundle, bundle2.unbundle20): + if isinstance(bundle, bundle2.unbundle20): + self._bundlefile = bundle + self._bundle = None + hadchangegroup = False - for part in self._bundle.iterparts(): + for part in bundle.iterparts(): if part.type == 'changegroup': if hadchangegroup: raise NotImplementedError("can't process " "multiple changegroups") hadchangegroup = True - self._handlebundle2part(part) + self._handlebundle2part(bundle, part) if not hadchangegroup: raise error.Abort(_("No changegroups found")) - elif isinstance(self._bundle, changegroup.cg1unpacker): - if self._bundle.compressed(): - f = self._writetempbundle(self._bundle.read, '.hg10un', + elif isinstance(bundle, changegroup.cg1unpacker): + if bundle.compressed(): + f = self._writetempbundle(bundle.read, '.hg10un', header='HG10UN') - self._bundlefile = self._bundle = exchange.readbundle( - ui, f, bundlepath, self.vfs) + bundle = exchange.readbundle(ui, f, bundlepath, self.vfs) + + self._bundlefile = bundle + self._bundle = bundle else: raise error.Abort(_('bundle type %s cannot be read') % - type(self._bundle)) + type(bundle)) # dict with the mapping 'filename' -> position in the bundle self.bundlefilespos = {} @@ -313,7 +318,7 @@ phases.retractboundary(self, None, phases.draft, [ctx.node() for ctx in self[self.firstnewrev:]]) - def _handlebundle2part(self, part): + def _handlebundle2part(self, bundle, part): if part.type == 'changegroup': cgstream = part version = part.params.get('version', '01') @@ -321,7 +326,7 @@ if version not in legalcgvers: msg = _('Unsupported changegroup version: %s') raise error.Abort(msg % version) - if self._bundle.compressed(): + if bundle.compressed(): cgstream = self._writetempbundle(part.read, ".cg%sun" % version)