Patchwork [10,of,19] snapshot: use None as a stop value when looking for a good delta

login
register
mail settings
Submitter Boris Feld
Date Sept. 8, 2018, 10:57 a.m.
Message ID <256a998ee3bf645cc6ee.1536404224@localhost.localdomain>
Download mbox | patch
Permalink /patch/34433/
State Accepted
Headers show

Comments

Boris Feld - Sept. 8, 2018, 10:57 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1536333452 14400
#      Fri Sep 07 11:17:32 2018 -0400
# Node ID 256a998ee3bf645cc6eee3a144e6825d61406a7c
# Parent  9ea2ef9abc22291b021b80c8f88320026ae79618
# EXP-Topic sparse-snapshot
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 256a998ee3bf
snapshot: use None as a stop value when looking for a good delta

Having clear stop value should help keep clear logic around the co-routine.
The alternative of using a StopIteration exception give a messier result.

This is one small step toward turning `_refinegroups` into a co-routine.

Patch

diff --git a/mercurial/revlogutils/deltas.py b/mercurial/revlogutils/deltas.py
--- a/mercurial/revlogutils/deltas.py
+++ b/mercurial/revlogutils/deltas.py
@@ -577,6 +577,7 @@  def _candidategroups(revlog, textlen, p1
     """
     # should we try to build a delta?
     if not (len(revlog) and revlog._storedeltachains):
+        yield None
         return
 
     deltalength = revlog.length
@@ -612,6 +613,7 @@  def _candidategroups(revlog, textlen, p1
             #      impacting performances. Some bounding or slicing mecanism
             #      would help to reduce this impact.
             yield tuple(group)
+    yield None
 
 def _findsnapshots(revlog, cache, start_rev):
     """find snapshot from start_rev to tip"""
@@ -842,7 +844,8 @@  class deltacomputer(object):
         p1r, p2r = revlog.rev(p1), revlog.rev(p2)
         groups = _candidategroups(self.revlog, revinfo.textlen,
                                              p1r, p2r, cachedelta)
-        for candidaterevs in groups:
+        candidaterevs = next(groups)
+        while candidaterevs is not None:
             nominateddeltas = []
             for candidaterev in candidaterevs:
                 candidatedelta = self._builddeltainfo(revinfo, candidaterev, fh)
@@ -851,6 +854,7 @@  class deltacomputer(object):
             if nominateddeltas:
                 deltainfo = min(nominateddeltas, key=lambda x: x.deltalen)
                 break
+            candidaterevs = next(groups)
 
         if deltainfo is None:
             deltainfo = self._fullsnapshotinfo(fh, revinfo)