Patchwork [11,of,11,V2] revlogdeltas: move finddeltainfo filtering inside _candidategroups

login
register
mail settings
Submitter Boris Feld
Date Aug. 27, 2018, 10:06 a.m.
Message ID <b83d12dd69ab55e13996.1535364398@FB-lair>
Download mbox | patch
Permalink /patch/34075/
State Accepted
Headers show

Comments

Boris Feld - Aug. 27, 2018, 10:06 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1534574496 -7200
#      Sat Aug 18 08:41:36 2018 +0200
# Node ID b83d12dd69ab55e139967d9687f643a6bf46f511
# Parent  2bf35ed4bc3d31d07b4dc97cf6f90e34128ca0e6
# EXP-Topic sparse-snapshot
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r b83d12dd69ab
revlogdeltas: move finddeltainfo filtering inside _candidategroups

Now all "simple" filtering logic is gathered in one place. The `finddeltainfo`
method is more straightforward and the `_candidate_groups` function knows more
about filtering revisions before we compute a delta against them.

Patch

diff --git a/mercurial/revlogutils/deltas.py b/mercurial/revlogutils/deltas.py
--- a/mercurial/revlogutils/deltas.py
+++ b/mercurial/revlogutils/deltas.py
@@ -568,7 +568,7 @@  def isgooddeltainfo(revlog, deltainfo, r
 
     return True
 
-def _candidategroups(revlog, p1, p2, cachedelta):
+def _candidategroups(revlog, textlen, p1, p2, cachedelta):
     """Provides group of revision to be tested as delta base
 
     This top level function focus on emitting groups with unique and worthwhile
@@ -578,12 +578,36 @@  def _candidategroups(revlog, p1, p2, cac
     if not (len(revlog) and revlog._storedeltachains):
         return
 
+    deltalength = revlog.length
+    deltaparent = revlog.deltaparent
+
+    deltas_limit = textlen * LIMIT_DELTA2TEXT
+
     tested = set([nullrev])
-    for group in _rawgroups(revlog, p1, p2, cachedelta):
-        group = tuple(r for r in group if r not in tested)
-        tested.update(group)
+    for temptative in _rawgroups(revlog, p1, p2, cachedelta):
+        group = []
+        for rev in temptative:
+            # skip over empty delta (no need to include them in a chain)
+            while not (rev == nullrev or rev in tested or deltalength(rev)):
+                rev = deltaparent(rev)
+                tested.add(rev)
+            # filter out revision we tested already
+            if rev in tested:
+                continue
+            tested.add(rev)
+            # filter out delta base that will never produce good delta
+            if deltas_limit < revlog.length(rev):
+                continue
+            # no need to try a delta against nullrev, this will be done as a
+            # last resort.
+            if rev == nullrev:
+                continue
+            # no delta for rawtext-changing revs (see "candelta" for why)
+            if revlog.flags(rev) & REVIDX_RAWTEXT_CHANGING_FLAGS:
+                continue
+            group.append(rev)
         if group:
-            yield group
+            yield tuple(group)
 
 def _rawgroups(revlog, p1, p2, cachedelta):
     """Provides group of revision to be tested as delta base
@@ -752,29 +776,13 @@  class deltacomputer(object):
         p2 = revinfo.p2
         revlog = self.revlog
 
-        deltalength = self.revlog.length
-        deltaparent = self.revlog.deltaparent
-
         deltainfo = None
-        deltas_limit = revinfo.textlen * LIMIT_DELTA2TEXT
         p1r, p2r = revlog.rev(p1), revlog.rev(p2)
-        groups = _candidategroups(self.revlog, p1r, p2r, cachedelta)
+        groups = _candidategroups(self.revlog, revinfo.textlen,
+                                             p1r, p2r, cachedelta)
         for candidaterevs in groups:
-            # filter out delta base that will never produce good delta
-            candidaterevs = [r for r in candidaterevs
-                             if self.revlog.length(r) <= deltas_limit]
             nominateddeltas = []
             for candidaterev in candidaterevs:
-                # skip over empty delta (no need to include them in a chain)
-                while candidaterev != nullrev and not deltalength(candidaterev):
-                    candidaterev = deltaparent(candidaterev)
-                # no need to try a delta against nullid, this will be handled
-                # by fulltext later.
-                if candidaterev == nullrev:
-                    continue
-                # no delta for rawtext-changing revs (see "candelta" for why)
-                if revlog.flags(candidaterev) & REVIDX_RAWTEXT_CHANGING_FLAGS:
-                    continue
                 candidatedelta = self._builddeltainfo(revinfo, candidaterev, fh)
                 if isgooddeltainfo(self.revlog, candidatedelta, revinfo):
                     nominateddeltas.append(candidatedelta)