Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 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 |
comparison
equal
deleted
inserted
replaced
42995:73288e7abe9b | 42996:4f2315cce1db |
---|---|
2335 DELTAREUSEFULLADD = 'fulladd' | 2335 DELTAREUSEFULLADD = 'fulladd' |
2336 | 2336 |
2337 DELTAREUSEALL = {'always', 'samerevs', 'never', 'fulladd'} | 2337 DELTAREUSEALL = {'always', 'samerevs', 'never', 'fulladd'} |
2338 | 2338 |
2339 def clone(self, tr, destrevlog, addrevisioncb=None, | 2339 def clone(self, tr, destrevlog, addrevisioncb=None, |
2340 deltareuse=DELTAREUSESAMEREVS, forcedeltabothparents=None): | 2340 deltareuse=DELTAREUSESAMEREVS, forcedeltabothparents=None): |
2341 """Copy this revlog to another, possibly with format changes. | 2341 """Copy this revlog to another, possibly with format changes. |
2342 | 2342 |
2343 The destination revlog will contain the same revisions and nodes. | 2343 The destination revlog will contain the same revisions and nodes. |
2344 However, it may not be bit-for-bit identical due to e.g. delta encoding | 2344 However, it may not be bit-for-bit identical due to e.g. delta encoding |
2345 differences. | 2345 differences. |
2403 destrevlog._lazydeltabase = False | 2403 destrevlog._lazydeltabase = False |
2404 destrevlog._lazydelta = False | 2404 destrevlog._lazydelta = False |
2405 | 2405 |
2406 destrevlog._deltabothparents = forcedeltabothparents or oldamd | 2406 destrevlog._deltabothparents = forcedeltabothparents or oldamd |
2407 | 2407 |
2408 deltacomputer = deltautil.deltacomputer(destrevlog) | 2408 self._clone(tr, destrevlog, addrevisioncb, deltareuse, |
2409 index = self.index | 2409 forcedeltabothparents) |
2410 for rev in self: | 2410 |
2411 entry = index[rev] | |
2412 | |
2413 # Some classes override linkrev to take filtered revs into | |
2414 # account. Use raw entry from index. | |
2415 flags = entry[0] & 0xffff | |
2416 linkrev = entry[4] | |
2417 p1 = index[entry[5]][7] | |
2418 p2 = index[entry[6]][7] | |
2419 node = entry[7] | |
2420 | |
2421 # (Possibly) reuse the delta from the revlog if allowed and | |
2422 # the revlog chunk is a delta. | |
2423 cachedelta = None | |
2424 rawtext = None | |
2425 if (deltareuse != self.DELTAREUSEFULLADD | |
2426 and destrevlog._lazydelta): | |
2427 dp = self.deltaparent(rev) | |
2428 if dp != nullrev: | |
2429 cachedelta = (dp, bytes(self._chunk(rev))) | |
2430 | |
2431 if not cachedelta: | |
2432 rawtext = self.rawdata(rev) | |
2433 | |
2434 | |
2435 if deltareuse == self.DELTAREUSEFULLADD: | |
2436 destrevlog.addrevision(rawtext, tr, linkrev, p1, p2, | |
2437 cachedelta=cachedelta, | |
2438 node=node, flags=flags, | |
2439 deltacomputer=deltacomputer) | |
2440 else: | |
2441 ifh = destrevlog.opener(destrevlog.indexfile, 'a+', | |
2442 checkambig=False) | |
2443 dfh = None | |
2444 if not destrevlog._inline: | |
2445 dfh = destrevlog.opener(destrevlog.datafile, 'a+') | |
2446 try: | |
2447 destrevlog._addrevision(node, rawtext, tr, linkrev, p1, | |
2448 p2, flags, cachedelta, ifh, dfh, | |
2449 deltacomputer=deltacomputer) | |
2450 finally: | |
2451 if dfh: | |
2452 dfh.close() | |
2453 ifh.close() | |
2454 | |
2455 if addrevisioncb: | |
2456 addrevisioncb(self, rev, node) | |
2457 finally: | 2411 finally: |
2458 destrevlog._lazydelta = oldlazydelta | 2412 destrevlog._lazydelta = oldlazydelta |
2459 destrevlog._lazydeltabase = oldlazydeltabase | 2413 destrevlog._lazydeltabase = oldlazydeltabase |
2460 destrevlog._deltabothparents = oldamd | 2414 destrevlog._deltabothparents = oldamd |
2415 | |
2416 def _clone(self, tr, destrevlog, addrevisioncb, deltareuse, | |
2417 forcedeltabothparents): | |
2418 """perform the core duty of `revlog.clone` after parameter processing""" | |
2419 deltacomputer = deltautil.deltacomputer(destrevlog) | |
2420 index = self.index | |
2421 for rev in self: | |
2422 entry = index[rev] | |
2423 | |
2424 # Some classes override linkrev to take filtered revs into | |
2425 # account. Use raw entry from index. | |
2426 flags = entry[0] & 0xffff | |
2427 linkrev = entry[4] | |
2428 p1 = index[entry[5]][7] | |
2429 p2 = index[entry[6]][7] | |
2430 node = entry[7] | |
2431 | |
2432 # (Possibly) reuse the delta from the revlog if allowed and | |
2433 # the revlog chunk is a delta. | |
2434 cachedelta = None | |
2435 rawtext = None | |
2436 if (deltareuse != self.DELTAREUSEFULLADD and destrevlog._lazydelta): | |
2437 dp = self.deltaparent(rev) | |
2438 if dp != nullrev: | |
2439 cachedelta = (dp, bytes(self._chunk(rev))) | |
2440 | |
2441 if not cachedelta: | |
2442 rawtext = self.rawdata(rev) | |
2443 | |
2444 | |
2445 if deltareuse == self.DELTAREUSEFULLADD: | |
2446 destrevlog.addrevision(rawtext, tr, linkrev, p1, p2, | |
2447 cachedelta=cachedelta, | |
2448 node=node, flags=flags, | |
2449 deltacomputer=deltacomputer) | |
2450 else: | |
2451 ifh = destrevlog.opener(destrevlog.indexfile, 'a+', | |
2452 checkambig=False) | |
2453 dfh = None | |
2454 if not destrevlog._inline: | |
2455 dfh = destrevlog.opener(destrevlog.datafile, 'a+') | |
2456 try: | |
2457 destrevlog._addrevision(node, rawtext, tr, linkrev, p1, | |
2458 p2, flags, cachedelta, ifh, dfh, | |
2459 deltacomputer=deltacomputer) | |
2460 finally: | |
2461 if dfh: | |
2462 dfh.close() | |
2463 ifh.close() | |
2464 | |
2465 if addrevisioncb: | |
2466 addrevisioncb(self, rev, node) | |
2461 | 2467 |
2462 def censorrevision(self, tr, censornode, tombstone=b''): | 2468 def censorrevision(self, tr, censornode, tombstone=b''): |
2463 if (self.version & 0xFFFF) == REVLOGV0: | 2469 if (self.version & 0xFFFF) == REVLOGV0: |
2464 raise error.RevlogError(_('cannot censor with version %d revlogs') % | 2470 raise error.RevlogError(_('cannot censor with version %d revlogs') % |
2465 self.version) | 2471 self.version) |