The content of the clone method now focus on parameters validation and
processing. The _clone method focus on the actual cloning logic.
Splitting the method out save some indentation and clarify each method code
since it a focussed on one goal.
indygreg |
hg-reviewers |
The content of the clone method now focus on parameters validation and
processing. The _clone method focus on the actual cloning logic.
Splitting the method out save some indentation and clarify each method code
since it a focussed on one goal.
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/revlog.py (106 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
8a1692d92cc4 | 73288e7abe9b | Pierre-Yves David | Sep 27 2019, 6:41 AM |
DELTAREUSESAMEREVS = 'samerevs' | DELTAREUSESAMEREVS = 'samerevs' | ||||
DELTAREUSENEVER = 'never' | DELTAREUSENEVER = 'never' | ||||
DELTAREUSEFULLADD = 'fulladd' | DELTAREUSEFULLADD = 'fulladd' | ||||
DELTAREUSEALL = {'always', 'samerevs', 'never', 'fulladd'} | DELTAREUSEALL = {'always', 'samerevs', 'never', 'fulladd'} | ||||
def clone(self, tr, destrevlog, addrevisioncb=None, | def clone(self, tr, destrevlog, addrevisioncb=None, | ||||
deltareuse=DELTAREUSESAMEREVS, forcedeltabothparents=None): | deltareuse=DELTAREUSESAMEREVS, forcedeltabothparents=None): | ||||
"""Copy this revlog to another, possibly with format changes. | """Copy this revlog to another, possibly with format changes. | ||||
The destination revlog will contain the same revisions and nodes. | The destination revlog will contain the same revisions and nodes. | ||||
However, it may not be bit-for-bit identical due to e.g. delta encoding | However, it may not be bit-for-bit identical due to e.g. delta encoding | ||||
differences. | differences. | ||||
The ``deltareuse`` argument control how deltas from the existing revlog | The ``deltareuse`` argument control how deltas from the existing revlog | ||||
are preserved in the destination revlog. The argument can have the | are preserved in the destination revlog. The argument can have the | ||||
destrevlog._lazydeltabase = False | destrevlog._lazydeltabase = False | ||||
destrevlog._lazydelta = True | destrevlog._lazydelta = True | ||||
elif deltareuse == self.DELTAREUSENEVER: | elif deltareuse == self.DELTAREUSENEVER: | ||||
destrevlog._lazydeltabase = False | destrevlog._lazydeltabase = False | ||||
destrevlog._lazydelta = False | destrevlog._lazydelta = False | ||||
destrevlog._deltabothparents = forcedeltabothparents or oldamd | destrevlog._deltabothparents = forcedeltabothparents or oldamd | ||||
self._clone(tr, destrevlog, addrevisioncb, deltareuse, | |||||
forcedeltabothparents) | |||||
finally: | |||||
destrevlog._lazydelta = oldlazydelta | |||||
destrevlog._lazydeltabase = oldlazydeltabase | |||||
destrevlog._deltabothparents = oldamd | |||||
def _clone(self, tr, destrevlog, addrevisioncb, deltareuse, | |||||
forcedeltabothparents): | |||||
"""perform the core duty of `revlog.clone` after parameter processing""" | |||||
deltacomputer = deltautil.deltacomputer(destrevlog) | deltacomputer = deltautil.deltacomputer(destrevlog) | ||||
index = self.index | index = self.index | ||||
for rev in self: | for rev in self: | ||||
entry = index[rev] | entry = index[rev] | ||||
# Some classes override linkrev to take filtered revs into | # Some classes override linkrev to take filtered revs into | ||||
# account. Use raw entry from index. | # account. Use raw entry from index. | ||||
flags = entry[0] & 0xffff | flags = entry[0] & 0xffff | ||||
linkrev = entry[4] | linkrev = entry[4] | ||||
p1 = index[entry[5]][7] | p1 = index[entry[5]][7] | ||||
p2 = index[entry[6]][7] | p2 = index[entry[6]][7] | ||||
node = entry[7] | node = entry[7] | ||||
# (Possibly) reuse the delta from the revlog if allowed and | # (Possibly) reuse the delta from the revlog if allowed and | ||||
# the revlog chunk is a delta. | # the revlog chunk is a delta. | ||||
cachedelta = None | cachedelta = None | ||||
rawtext = None | rawtext = None | ||||
if (deltareuse != self.DELTAREUSEFULLADD | if (deltareuse != self.DELTAREUSEFULLADD and destrevlog._lazydelta): | ||||
and destrevlog._lazydelta): | |||||
dp = self.deltaparent(rev) | dp = self.deltaparent(rev) | ||||
if dp != nullrev: | if dp != nullrev: | ||||
cachedelta = (dp, bytes(self._chunk(rev))) | cachedelta = (dp, bytes(self._chunk(rev))) | ||||
if not cachedelta: | if not cachedelta: | ||||
rawtext = self.rawdata(rev) | rawtext = self.rawdata(rev) | ||||
if deltareuse == self.DELTAREUSEFULLADD: | if deltareuse == self.DELTAREUSEFULLADD: | ||||
destrevlog.addrevision(rawtext, tr, linkrev, p1, p2, | destrevlog.addrevision(rawtext, tr, linkrev, p1, p2, | ||||
cachedelta=cachedelta, | cachedelta=cachedelta, | ||||
node=node, flags=flags, | node=node, flags=flags, | ||||
deltacomputer=deltacomputer) | deltacomputer=deltacomputer) | ||||
else: | else: | ||||
ifh = destrevlog.opener(destrevlog.indexfile, 'a+', | ifh = destrevlog.opener(destrevlog.indexfile, 'a+', | ||||
checkambig=False) | checkambig=False) | ||||
dfh = None | dfh = None | ||||
if not destrevlog._inline: | if not destrevlog._inline: | ||||
dfh = destrevlog.opener(destrevlog.datafile, 'a+') | dfh = destrevlog.opener(destrevlog.datafile, 'a+') | ||||
try: | try: | ||||
destrevlog._addrevision(node, rawtext, tr, linkrev, p1, | destrevlog._addrevision(node, rawtext, tr, linkrev, p1, | ||||
p2, flags, cachedelta, ifh, dfh, | p2, flags, cachedelta, ifh, dfh, | ||||
deltacomputer=deltacomputer) | deltacomputer=deltacomputer) | ||||
finally: | finally: | ||||
if dfh: | if dfh: | ||||
dfh.close() | dfh.close() | ||||
ifh.close() | ifh.close() | ||||
if addrevisioncb: | if addrevisioncb: | ||||
addrevisioncb(self, rev, node) | addrevisioncb(self, rev, node) | ||||
finally: | |||||
destrevlog._lazydelta = oldlazydelta | |||||
destrevlog._lazydeltabase = oldlazydeltabase | |||||
destrevlog._deltabothparents = oldamd | |||||
def censorrevision(self, tr, censornode, tombstone=b''): | def censorrevision(self, tr, censornode, tombstone=b''): | ||||
if (self.version & 0xFFFF) == REVLOGV0: | if (self.version & 0xFFFF) == REVLOGV0: | ||||
raise error.RevlogError(_('cannot censor with version %d revlogs') % | raise error.RevlogError(_('cannot censor with version %d revlogs') % | ||||
self.version) | self.version) | ||||
censorrev = self.rev(censornode) | censorrev = self.rev(censornode) | ||||
tombstone = storageutil.packmeta({b'censored': tombstone}, b'') | tombstone = storageutil.packmeta({b'censored': tombstone}, b'') |