1422 else: |
1422 else: |
1423 textlen = len(text) |
1423 textlen = len(text) |
1424 |
1424 |
1425 # should we try to build a delta? |
1425 # should we try to build a delta? |
1426 if prev != nullrev: |
1426 if prev != nullrev: |
|
1427 tested = set() |
1427 if cachedelta and self._generaldelta and self._lazydeltabase: |
1428 if cachedelta and self._generaldelta and self._lazydeltabase: |
1428 # Assume what we received from the server is a good choice |
1429 # Assume what we received from the server is a good choice |
1429 # build delta will reuse the cache |
1430 # build delta will reuse the cache |
1430 candidatedelta = builddelta(cachedelta[0]) |
1431 candidatedelta = builddelta(cachedelta[0]) |
|
1432 tested.add(candidatedelta[3]) |
1431 if self._isgooddelta(candidatedelta, textlen): |
1433 if self._isgooddelta(candidatedelta, textlen): |
1432 delta = candidatedelta |
1434 delta = candidatedelta |
1433 elif prev != candidatedelta[3]: |
1435 if delta is None and self._generaldelta: |
1434 # Try against prev to hopefully save us a fulltext. |
|
1435 delta = builddelta(prev) |
|
1436 elif self._generaldelta: |
|
1437 parents = [p1r, p2r] |
1436 parents = [p1r, p2r] |
1438 if not self._aggressivemergedeltas: |
1437 # exclude already lazy tested base if any |
|
1438 parents = [p for p in parents if p not in tested] |
|
1439 if parents and not self._aggressivemergedeltas: |
1439 # Pick whichever parent is closer to us (to minimize the |
1440 # Pick whichever parent is closer to us (to minimize the |
1440 # chance of having to build a fulltext). Since |
1441 # chance of having to build a fulltext). |
1441 # nullrev == -1, any non-merge commit will always pick p1r. |
|
1442 parents = [max(parents)] |
1442 parents = [max(parents)] |
|
1443 tested.update(parents) |
1443 pdeltas = [] |
1444 pdeltas = [] |
1444 for p in parents: |
1445 for p in parents: |
1445 pd = builddelta(p) |
1446 pd = builddelta(p) |
1446 if self._isgooddelta(pd, textlen): |
1447 if self._isgooddelta(pd, textlen): |
1447 pdeltas.append(pd) |
1448 pdeltas.append(pd) |
1448 if pdeltas: |
1449 if pdeltas: |
1449 delta = min(pdeltas, key=lambda x: x[1]) |
1450 delta = min(pdeltas, key=lambda x: x[1]) |
1450 elif prev not in parents: |
1451 if delta is None and prev not in tested: |
1451 # Neither is good, try against prev to hopefully save us |
1452 # other approach failed try against prev to hopefully save us a |
1452 # a fulltext. |
1453 # fulltext. |
1453 delta = builddelta(prev) |
|
1454 else: |
|
1455 delta = builddelta(prev) |
1454 delta = builddelta(prev) |
1456 if delta is not None: |
1455 if delta is not None: |
1457 dist, l, data, base, chainbase, chainlen, compresseddeltalen = delta |
1456 dist, l, data, base, chainbase, chainlen, compresseddeltalen = delta |
1458 |
1457 |
1459 if not self._isgooddelta(delta, textlen): |
1458 if not self._isgooddelta(delta, textlen): |