Mercurial > public > mercurial-scm > hg
comparison mercurial/revlogutils/deltas.py @ 51331:d0d869fccd20
delta-find: move away from the generator API for _DeltaSearch
We use more explicit function call. This make operations more explicit and will
make future refactoring simpler.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 29 Dec 2023 13:35:08 +0100 |
parents | 0d92d62ecde0 |
children | 02cc19f4f091 |
comparison
equal
deleted
inserted
replaced
51330:0d92d62ecde0 | 51331:d0d869fccd20 |
---|---|
631 snapshot_cache = SnapshotCache() | 631 snapshot_cache = SnapshotCache() |
632 self.snapshot_cache = snapshot_cache | 632 self.snapshot_cache = snapshot_cache |
633 | 633 |
634 self.tested = {nullrev} | 634 self.tested = {nullrev} |
635 | 635 |
636 def candidate_groups(self): | 636 self._candidates_iterator = self._candidate_groups() |
637 self._last_good = None | |
638 self.current_group = self._candidates_iterator.send(self._last_good) | |
639 | |
640 @property | |
641 def done(self): | |
642 """True when all possible candidate have been tested""" | |
643 return self.current_group is None | |
644 | |
645 def next_group(self, good_delta=None): | |
646 """move to the next group to test | |
647 | |
648 The group of revision to test will be available in | |
649 `self.current_group`. If the previous group had any good delta, the | |
650 best one can be passed as the `good_delta` parameter to help selecting | |
651 the next group. | |
652 | |
653 If not revision remains to be, `self.done` will be True and | |
654 `self.current_group` will be None. | |
655 """ | |
656 if good_delta is not None: | |
657 self._last_good = good_delta.base | |
658 self.current_group = self._candidates_iterator.send(self._last_good) | |
659 | |
660 def _candidate_groups(self): | |
637 """Provides group of revision to be tested as delta base | 661 """Provides group of revision to be tested as delta base |
638 | 662 |
639 This top level function focus on emitting groups with unique and | 663 This top level function focus on emitting groups with unique and |
640 worthwhile content. See _raw_candidate_groups for details about the | 664 worthwhile content. See _raw_candidate_groups for details about the |
641 group order. | 665 group order. |
1441 excluded_bases, | 1465 excluded_bases, |
1442 target_rev, | 1466 target_rev, |
1443 snapshot_cache=self._snapshot_cache, | 1467 snapshot_cache=self._snapshot_cache, |
1444 ) | 1468 ) |
1445 | 1469 |
1446 groups = search.candidate_groups() | 1470 while not search.done: |
1447 candidaterevs = next(groups) | 1471 current_group = search.current_group |
1448 while candidaterevs is not None: | 1472 # current_group can be `None`, but not is search.done is False |
1473 # We add this assert to help pytype | |
1474 assert current_group is not None | |
1475 candidaterevs = current_group | |
1449 dbg_try_rounds += 1 | 1476 dbg_try_rounds += 1 |
1450 if self._debug_search: | 1477 if self._debug_search: |
1451 prev = None | 1478 prev = None |
1452 if deltainfo is not None: | 1479 if deltainfo is not None: |
1453 prev = deltainfo.base | 1480 prev = deltainfo.base |
1535 elif self._debug_search: | 1562 elif self._debug_search: |
1536 msg = b"DBG-DELTAS-SEARCH: NO-DELTA\n" | 1563 msg = b"DBG-DELTAS-SEARCH: NO-DELTA\n" |
1537 self._write_debug(msg) | 1564 self._write_debug(msg) |
1538 if nominateddeltas: | 1565 if nominateddeltas: |
1539 deltainfo = min(nominateddeltas, key=lambda x: x.deltalen) | 1566 deltainfo = min(nominateddeltas, key=lambda x: x.deltalen) |
1540 if deltainfo is not None: | 1567 search.next_group(deltainfo) |
1541 candidaterevs = groups.send(deltainfo.base) | |
1542 else: | |
1543 candidaterevs = next(groups) | |
1544 | 1568 |
1545 if deltainfo is None: | 1569 if deltainfo is None: |
1546 dbg_type = b"full" | 1570 dbg_type = b"full" |
1547 deltainfo = self._fullsnapshotinfo(revinfo, target_rev) | 1571 deltainfo = self._fullsnapshotinfo(revinfo, target_rev) |
1548 elif deltainfo.snapshotdepth: # pytype: disable=attribute-error | 1572 elif deltainfo.snapshotdepth: # pytype: disable=attribute-error |