Mercurial > hg
changeset 51334: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 |
files | mercurial/revlogutils/deltas.py |
diffstat | 1 files changed, 32 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revlogutils/deltas.py Thu Nov 23 21:13:14 2023 +0100 +++ b/mercurial/revlogutils/deltas.py Fri Dec 29 13:35:08 2023 +0100 @@ -633,7 +633,31 @@ self.tested = {nullrev} - def candidate_groups(self): + self._candidates_iterator = self._candidate_groups() + self._last_good = None + self.current_group = self._candidates_iterator.send(self._last_good) + + @property + def done(self): + """True when all possible candidate have been tested""" + return self.current_group is None + + def next_group(self, good_delta=None): + """move to the next group to test + + The group of revision to test will be available in + `self.current_group`. If the previous group had any good delta, the + best one can be passed as the `good_delta` parameter to help selecting + the next group. + + If not revision remains to be, `self.done` will be True and + `self.current_group` will be None. + """ + if good_delta is not None: + self._last_good = good_delta.base + self.current_group = self._candidates_iterator.send(self._last_good) + + def _candidate_groups(self): """Provides group of revision to be tested as delta base This top level function focus on emitting groups with unique and @@ -1443,9 +1467,12 @@ snapshot_cache=self._snapshot_cache, ) - groups = search.candidate_groups() - candidaterevs = next(groups) - while candidaterevs is not None: + while not search.done: + current_group = search.current_group + # current_group can be `None`, but not is search.done is False + # We add this assert to help pytype + assert current_group is not None + candidaterevs = current_group dbg_try_rounds += 1 if self._debug_search: prev = None @@ -1537,10 +1564,7 @@ self._write_debug(msg) if nominateddeltas: deltainfo = min(nominateddeltas, key=lambda x: x.deltalen) - if deltainfo is not None: - candidaterevs = groups.send(deltainfo.base) - else: - candidaterevs = next(groups) + search.next_group(deltainfo) if deltainfo is None: dbg_type = b"full"