comparison mercurial/revlog.py @ 27189:7b6cb7c15109

addrevision: rework generaldelta computation The old code have multiple explicit tests and code duplications. This makes it hard to improve the code. We rewrite the logic in a more generic way, not changing anything of the computed result. The final goal here is to eventually be able to: - factor out the default fallback case "try against 'prev'" in a single place - allow 'lazydeltabase' case to use the smarter general delta code path when the incoming base does not provide us with a good delta.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 01 Dec 2015 18:45:16 -0800
parents 8e7db961535a
children 20a9226bdc8a
comparison
equal deleted inserted replaced
27188:6a1301e22bd7 27189:7b6cb7c15109
1432 delta = candidatedelta 1432 delta = candidatedelta
1433 elif prev != candidatedelta[3]: 1433 elif prev != candidatedelta[3]:
1434 # Try against prev to hopefully save us a fulltext. 1434 # Try against prev to hopefully save us a fulltext.
1435 delta = builddelta(prev) 1435 delta = builddelta(prev)
1436 elif self._generaldelta: 1436 elif self._generaldelta:
1437 if p2r != nullrev and self._aggressivemergedeltas: 1437 parents = [p1r, p2r]
1438 delta = builddelta(p1r) 1438 if not self._aggressivemergedeltas:
1439 delta2 = builddelta(p2r)
1440 p1good = self._isgooddelta(delta, textlen)
1441 p2good = self._isgooddelta(delta2, textlen)
1442 if p1good and p2good:
1443 # If both are good deltas, choose the smallest
1444 if delta2[1] < delta[1]:
1445 delta = delta2
1446 elif p2good:
1447 # If only p2 is good, use it
1448 delta = delta2
1449 elif p1good:
1450 pass
1451 else:
1452 # Neither is good, try against prev to hopefully save us
1453 # a fulltext.
1454 delta = builddelta(prev)
1455 else:
1456 # Pick whichever parent is closer to us (to minimize the 1439 # Pick whichever parent is closer to us (to minimize the
1457 # chance of having to build a fulltext). Since 1440 # chance of having to build a fulltext). Since
1458 # nullrev == -1, any non-merge commit will always pick p1r. 1441 # nullrev == -1, any non-merge commit will always pick p1r.
1459 drev = p2r if p2r > p1r else p1r 1442 parents = [max(parents)]
1460 delta = builddelta(drev) 1443 pdeltas = []
1461 # If the chosen delta will result in us making a full text, 1444 for p in parents:
1462 # give it one last try against prev. 1445 pd = builddelta(p)
1463 if drev != prev and not self._isgooddelta(delta, textlen): 1446 if self._isgooddelta(pd, textlen):
1464 delta = builddelta(prev) 1447 pdeltas.append(pd)
1448 if pdeltas:
1449 delta = min(pdeltas, key=lambda x: x[1])
1450 elif prev not in parents:
1451 # Neither is good, try against prev to hopefully save us
1452 # a fulltext.
1453 delta = builddelta(prev)
1465 else: 1454 else:
1466 delta = builddelta(prev) 1455 delta = builddelta(prev)
1467 if delta is not None: 1456 if delta is not None:
1468 dist, l, data, base, chainbase, chainlen, compresseddeltalen = delta 1457 dist, l, data, base, chainbase, chainlen, compresseddeltalen = delta
1469 1458