Patchwork [4,of,8] revlog: skip over empty revision when looking for delta base

login
register
mail settings
Submitter Boris Feld
Date Aug. 14, 2018, 4:39 p.m.
Message ID <84ce7b4af1682c683c4e.1534264754@FB-lair>
Download mbox | patch
Permalink /patch/33723/
State Accepted
Headers show

Comments

Boris Feld - Aug. 14, 2018, 4:39 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1532711381 -7200
#      Fri Jul 27 19:09:41 2018 +0200
# Node ID 84ce7b4af1682c683c4e834af92dc1c3aca581c5
# Parent  d83a28de86d58327c89ec3d87f22c784d6f8edcd
# EXP-Topic sparse-snapshot
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 84ce7b4af168
revlog: skip over empty revision when looking for delta base

There is no point in keeping an empty revision in the middle of a chain since
they won't contribute any data. So we filter them out when looking for a valid
base delta.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -743,10 +743,20 @@  class _deltacomputer(object):
         p2 = revinfo.p2
         revlog = self.revlog
 
+        deltalength = self.revlog.length
+        deltaparent = self.revlog.deltaparent
+
         deltainfo = None
         for candidaterevs in self._getcandidaterevs(p1, p2, cachedelta):
             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
diff --git a/tests/test-generaldelta.t b/tests/test-generaldelta.t
--- a/tests/test-generaldelta.t
+++ b/tests/test-generaldelta.t
@@ -267,7 +267,7 @@  test maxdeltachainspan
        51       4        3       50    prev        356        594        611   1.02862       611         0    0.00000
        52       4        4       51      p1         58        640        669   1.04531       669         0    0.00000
        53       5        1       -1    base          0          0          0   0.00000         0         0    0.00000
-       54       5        2       53      p1        376        640        376   0.58750       376         0    0.00000
+       54       6        1       -1    base        369        640        369   0.57656       369         0    0.00000
   $ hg clone --pull source-repo --config experimental.maxdeltachainspan=2800 relax-chain --config format.generaldelta=yes
   requesting all changes
   adding changesets
@@ -333,7 +333,7 @@  test maxdeltachainspan
        51       2       13       17      p1         58        594        739   1.24411      2781      2042    2.76319
        52       5        1       -1    base        369        640        369   0.57656       369         0    0.00000
        53       6        1       -1    base          0          0          0   0.00000         0         0    0.00000
-       54       6        2       53      p1        376        640        376   0.58750       376         0    0.00000
+       54       7        1       -1    base        369        640        369   0.57656       369         0    0.00000
   $ hg clone --pull source-repo --config experimental.maxdeltachainspan=0 noconst-chain --config format.generaldelta=yes
   requesting all changes
   adding changesets
@@ -399,4 +399,4 @@  test maxdeltachainspan
        51       2       13       17      p1         58        594        739   1.24411      2642      1903    2.57510
        52       2       14       51      p1         58        640        797   1.24531      2700      1903    2.38770
        53       4        1       -1    base          0          0          0   0.00000         0         0    0.00000
-       54       4        2       53      p1        376        640        376   0.58750       376         0    0.00000
+       54       5        1       -1    base        369        640        369   0.57656       369         0    0.00000