Mercurial > public > mercurial-scm > hg
comparison mercurial/bundlerepo.py @ 35053:495fcff10124
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
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 11 Nov 2017 18:34:50 -0800 |
parents | df2a676a2e9e |
children | 3f393e4593f2 |
comparison
equal
deleted
inserted
replaced
35052:df2a676a2e9e | 35053:495fcff10124 |
---|---|
279 else: | 279 else: |
280 self._url = 'bundle:' + bundlepath | 280 self._url = 'bundle:' + bundlepath |
281 | 281 |
282 self.tempfile = None | 282 self.tempfile = None |
283 f = util.posixfile(bundlepath, "rb") | 283 f = util.posixfile(bundlepath, "rb") |
284 self._bundlefile = self._bundle = exchange.readbundle(ui, f, bundlepath) | 284 bundle = exchange.readbundle(ui, f, bundlepath) |
285 | 285 |
286 if isinstance(self._bundle, bundle2.unbundle20): | 286 if isinstance(bundle, bundle2.unbundle20): |
287 self._bundlefile = bundle | |
288 self._bundle = None | |
289 | |
287 hadchangegroup = False | 290 hadchangegroup = False |
288 for part in self._bundle.iterparts(): | 291 for part in bundle.iterparts(): |
289 if part.type == 'changegroup': | 292 if part.type == 'changegroup': |
290 if hadchangegroup: | 293 if hadchangegroup: |
291 raise NotImplementedError("can't process " | 294 raise NotImplementedError("can't process " |
292 "multiple changegroups") | 295 "multiple changegroups") |
293 hadchangegroup = True | 296 hadchangegroup = True |
294 | 297 |
295 self._handlebundle2part(part) | 298 self._handlebundle2part(bundle, part) |
296 | 299 |
297 if not hadchangegroup: | 300 if not hadchangegroup: |
298 raise error.Abort(_("No changegroups found")) | 301 raise error.Abort(_("No changegroups found")) |
299 elif isinstance(self._bundle, changegroup.cg1unpacker): | 302 elif isinstance(bundle, changegroup.cg1unpacker): |
300 if self._bundle.compressed(): | 303 if bundle.compressed(): |
301 f = self._writetempbundle(self._bundle.read, '.hg10un', | 304 f = self._writetempbundle(bundle.read, '.hg10un', |
302 header='HG10UN') | 305 header='HG10UN') |
303 self._bundlefile = self._bundle = exchange.readbundle( | 306 bundle = exchange.readbundle(ui, f, bundlepath, self.vfs) |
304 ui, f, bundlepath, self.vfs) | 307 |
308 self._bundlefile = bundle | |
309 self._bundle = bundle | |
305 else: | 310 else: |
306 raise error.Abort(_('bundle type %s cannot be read') % | 311 raise error.Abort(_('bundle type %s cannot be read') % |
307 type(self._bundle)) | 312 type(bundle)) |
308 | 313 |
309 # dict with the mapping 'filename' -> position in the bundle | 314 # dict with the mapping 'filename' -> position in the bundle |
310 self.bundlefilespos = {} | 315 self.bundlefilespos = {} |
311 | 316 |
312 self.firstnewrev = self.changelog.repotiprev + 1 | 317 self.firstnewrev = self.changelog.repotiprev + 1 |
313 phases.retractboundary(self, None, phases.draft, | 318 phases.retractboundary(self, None, phases.draft, |
314 [ctx.node() for ctx in self[self.firstnewrev:]]) | 319 [ctx.node() for ctx in self[self.firstnewrev:]]) |
315 | 320 |
316 def _handlebundle2part(self, part): | 321 def _handlebundle2part(self, bundle, part): |
317 if part.type == 'changegroup': | 322 if part.type == 'changegroup': |
318 cgstream = part | 323 cgstream = part |
319 version = part.params.get('version', '01') | 324 version = part.params.get('version', '01') |
320 legalcgvers = changegroup.supportedincomingversions(self) | 325 legalcgvers = changegroup.supportedincomingversions(self) |
321 if version not in legalcgvers: | 326 if version not in legalcgvers: |
322 msg = _('Unsupported changegroup version: %s') | 327 msg = _('Unsupported changegroup version: %s') |
323 raise error.Abort(msg % version) | 328 raise error.Abort(msg % version) |
324 if self._bundle.compressed(): | 329 if bundle.compressed(): |
325 cgstream = self._writetempbundle(part.read, | 330 cgstream = self._writetempbundle(part.read, |
326 ".cg%sun" % version) | 331 ".cg%sun" % version) |
327 | 332 |
328 self._bundle = changegroup.getunbundler(version, cgstream, 'UN') | 333 self._bundle = changegroup.getunbundler(version, cgstream, 'UN') |
329 | 334 |