Strictly speaking, this variable tracks offsets within the
changegroup, not the bundle.
While we're here, mark a class attribute as private because
it is.
.. api::
Rename bundlerepo.bundlerepository.bundlefilespos to _cgfilespos.
Strictly speaking, this variable tracks offsets within the
changegroup, not the bundle.
While we're here, mark a class attribute as private because
it is.
.. api::
Rename bundlerepo.bundlerepository.bundlefilespos to _cgfilespos.
Lint Skipped |
Unit Tests Skipped |
def _write(self, fp): | def _write(self, fp): | ||||
raise NotImplementedError | raise NotImplementedError | ||||
def _updateroots(self, phase, newroots, tr): | def _updateroots(self, phase, newroots, tr): | ||||
self.phaseroots[phase] = newroots | self.phaseroots[phase] = newroots | ||||
self.invalidate() | self.invalidate() | ||||
self.dirty = True | self.dirty = True | ||||
bundlefilespos = {} | |||||
def _getfilestarts(cgunpacker): | def _getfilestarts(cgunpacker): | ||||
filespos = {} | |||||
for chunkdata in iter(cgunpacker.filelogheader, {}): | for chunkdata in iter(cgunpacker.filelogheader, {}): | ||||
fname = chunkdata['filename'] | fname = chunkdata['filename'] | ||||
bundlefilespos[fname] = bundle.tell() | filespos[fname] = cgunpacker.tell() | ||||
for chunk in iter(lambda: cgunpacker.deltachunk(None), {}): | for chunk in iter(lambda: cgunpacker.deltachunk(None), {}): | ||||
pass | pass | ||||
return bundlefilespos | return filespos | ||||
class bundlerepository(localrepo.localrepository): | class bundlerepository(localrepo.localrepository): | ||||
"""A repository instance that is a union of a local repo and a bundle. | """A repository instance that is a union of a local repo and a bundle. | ||||
Instances represent a read-only repository composed of a local repository | Instances represent a read-only repository composed of a local repository | ||||
with the contents of a bundle file applied. The repository instance is | with the contents of a bundle file applied. The repository instance is | ||||
conceptually similar to the state of a repository after an | conceptually similar to the state of a repository after an | ||||
``hg unbundle`` operation. However, the contents of the bundle are never | ``hg unbundle`` operation. However, the contents of the bundle are never | ||||
bundle = exchange.readbundle(ui, f, bundlepath, self.vfs) | bundle = exchange.readbundle(ui, f, bundlepath, self.vfs) | ||||
self._bundlefile = bundle | self._bundlefile = bundle | ||||
self._cgunpacker = bundle | self._cgunpacker = bundle | ||||
else: | else: | ||||
raise error.Abort(_('bundle type %s cannot be read') % | raise error.Abort(_('bundle type %s cannot be read') % | ||||
type(bundle)) | type(bundle)) | ||||
# dict with the mapping 'filename' -> position in the bundle | # dict with the mapping 'filename' -> position in the changegroup. | ||||
self.bundlefilespos = {} | self._cgfilespos = {} | ||||
self.firstnewrev = self.changelog.repotiprev + 1 | self.firstnewrev = self.changelog.repotiprev + 1 | ||||
phases.retractboundary(self, None, phases.draft, | phases.retractboundary(self, None, phases.draft, | ||||
[ctx.node() for ctx in self[self.firstnewrev:]]) | [ctx.node() for ctx in self[self.firstnewrev:]]) | ||||
def _handlebundle2part(self, bundle, part): | def _handlebundle2part(self, bundle, part): | ||||
if part.type != 'changegroup': | if part.type != 'changegroup': | ||||
return | return | ||||
self._consumemanifest() | self._consumemanifest() | ||||
return self.filestart | return self.filestart | ||||
def url(self): | def url(self): | ||||
return self._url | return self._url | ||||
def file(self, f): | def file(self, f): | ||||
if not self.bundlefilespos: | if not self._cgfilespos: | ||||
self._cgunpacker.seek(self.filestart) | self._cgunpacker.seek(self.filestart) | ||||
self.bundlefilespos = _getfilestarts(self._cgunpacker) | self._cgfilespos = _getfilestarts(self._cgunpacker) | ||||
if f in self.bundlefilespos: | if f in self._cgfilespos: | ||||
self._cgunpacker.seek(self.bundlefilespos[f]) | self._cgunpacker.seek(self._cgfilespos[f]) | ||||
linkmapper = self.unfiltered().changelog.rev | linkmapper = self.unfiltered().changelog.rev | ||||
return bundlefilelog(self.svfs, f, self._cgunpacker, linkmapper) | return bundlefilelog(self.svfs, f, self._cgunpacker, linkmapper) | ||||
else: | else: | ||||
return filelog.filelog(self.svfs, f) | return filelog.filelog(self.svfs, f) | ||||
def close(self): | def close(self): | ||||
"""Close assigned bundle file immediately.""" | """Close assigned bundle file immediately.""" | ||||
self._bundlefile.close() | self._bundlefile.close() |