Mercurial > hg
changeset 42996:4f2315cce1db
upgrade: move most of revlog.clone method into a _clone method
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.
Differential Revision: https://phab.mercurial-scm.org/D6899
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 27 Sep 2019 12:41:20 +0200 |
parents | 73288e7abe9b |
children | 6510c7830838 |
files | mercurial/revlog.py |
diffstat | 1 files changed, 56 insertions(+), 50 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revlog.py Sat Sep 07 00:34:20 2019 +0200 +++ b/mercurial/revlog.py Fri Sep 27 12:41:20 2019 +0200 @@ -2337,7 +2337,7 @@ DELTAREUSEALL = {'always', 'samerevs', 'never', 'fulladd'} def clone(self, tr, destrevlog, addrevisioncb=None, - deltareuse=DELTAREUSESAMEREVS, forcedeltabothparents=None): + deltareuse=DELTAREUSESAMEREVS, forcedeltabothparents=None): """Copy this revlog to another, possibly with format changes. The destination revlog will contain the same revisions and nodes. @@ -2405,60 +2405,66 @@ destrevlog._deltabothparents = forcedeltabothparents or oldamd - deltacomputer = deltautil.deltacomputer(destrevlog) - index = self.index - for rev in self: - entry = index[rev] - - # Some classes override linkrev to take filtered revs into - # account. Use raw entry from index. - flags = entry[0] & 0xffff - linkrev = entry[4] - p1 = index[entry[5]][7] - p2 = index[entry[6]][7] - node = entry[7] - - # (Possibly) reuse the delta from the revlog if allowed and - # the revlog chunk is a delta. - cachedelta = None - rawtext = None - if (deltareuse != self.DELTAREUSEFULLADD - and destrevlog._lazydelta): - dp = self.deltaparent(rev) - if dp != nullrev: - cachedelta = (dp, bytes(self._chunk(rev))) - - if not cachedelta: - rawtext = self.rawdata(rev) - - - if deltareuse == self.DELTAREUSEFULLADD: - destrevlog.addrevision(rawtext, tr, linkrev, p1, p2, - cachedelta=cachedelta, - node=node, flags=flags, - deltacomputer=deltacomputer) - else: - ifh = destrevlog.opener(destrevlog.indexfile, 'a+', - checkambig=False) - dfh = None - if not destrevlog._inline: - dfh = destrevlog.opener(destrevlog.datafile, 'a+') - try: - destrevlog._addrevision(node, rawtext, tr, linkrev, p1, - p2, flags, cachedelta, ifh, dfh, - deltacomputer=deltacomputer) - finally: - if dfh: - dfh.close() - ifh.close() - - if addrevisioncb: - addrevisioncb(self, rev, node) + 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) + index = self.index + for rev in self: + entry = index[rev] + + # Some classes override linkrev to take filtered revs into + # account. Use raw entry from index. + flags = entry[0] & 0xffff + linkrev = entry[4] + p1 = index[entry[5]][7] + p2 = index[entry[6]][7] + node = entry[7] + + # (Possibly) reuse the delta from the revlog if allowed and + # the revlog chunk is a delta. + cachedelta = None + rawtext = None + if (deltareuse != self.DELTAREUSEFULLADD and destrevlog._lazydelta): + dp = self.deltaparent(rev) + if dp != nullrev: + cachedelta = (dp, bytes(self._chunk(rev))) + + if not cachedelta: + rawtext = self.rawdata(rev) + + + if deltareuse == self.DELTAREUSEFULLADD: + destrevlog.addrevision(rawtext, tr, linkrev, p1, p2, + cachedelta=cachedelta, + node=node, flags=flags, + deltacomputer=deltacomputer) + else: + ifh = destrevlog.opener(destrevlog.indexfile, 'a+', + checkambig=False) + dfh = None + if not destrevlog._inline: + dfh = destrevlog.opener(destrevlog.datafile, 'a+') + try: + destrevlog._addrevision(node, rawtext, tr, linkrev, p1, + p2, flags, cachedelta, ifh, dfh, + deltacomputer=deltacomputer) + finally: + if dfh: + dfh.close() + ifh.close() + + if addrevisioncb: + addrevisioncb(self, rev, node) + def censorrevision(self, tr, censornode, tombstone=b''): if (self.version & 0xFFFF) == REVLOGV0: raise error.RevlogError(_('cannot censor with version %d revlogs') %