Patchwork [4,of,4] revlog: don't consider nullrev when choosing delta base

login
register
mail settings
Submitter Martin von Zweigbergk
Date Dec. 5, 2015, 5:57 a.m.
Message ID <b94cd7a1f543b3b80ad1.1449295061@waste.org>
Download mbox | patch
Permalink /patch/11843/
State Accepted
Headers show

Comments

Martin von Zweigbergk - Dec. 5, 2015, 5:57 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1449280016 28800
#      Fri Dec 04 17:46:56 2015 -0800
# Node ID b94cd7a1f543b3b80ad196e1f8731e44afefdb2a
# Parent  fd8f2cd725f35a189e01c2d89b19f2ea004276f1
revlog: don't consider nullrev when choosing delta base

In the most complex case, we try using the incoming delta base, then
we try both parents, and then we try the previous revlog entry. If
none of these result in a good delta, we natually use the null
revision as base. However, we sometimes consider the nullrev before we
have exhausted our other options. Specifically, when both parents are
null, we use the nullrev as delta base if it produces a good delta
(according to _isgooddelta()), and we fail to try the previous revlog
entry as delta base. After 20a9226bdc8a (addrevision: use general
delta when the incoming base delta is bad, 2015-12-01), it can also
happen for non-merge commits when the incoming delta is not good.

The Firefox repo (from many months back) shrinks a tiny bit with this
patch: from 1.855GB to 1.830GB (1.4%). The hg repo itself shrinks even
less: by less than 0.1%. There may be repos that get larger instead.

This undoes the unexplained test change in 20a9226bdc8a.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1432,9 +1432,9 @@ 
                 if self._isgooddelta(candidatedelta, textlen):
                     delta = candidatedelta
             if delta is None and self._generaldelta:
-                parents = [p1r, p2r]
                 # exclude already lazy tested base if any
-                parents = [p for p in parents if p not in tested]
+                parents = [p for p in (p1r, p2r)
+                           if p != nullrev and p not in tested]
                 if parents and not self._aggressivemergedeltas:
                     # Pick whichever parent is closer to us (to minimize the
                     # chance of having to build a fulltext).
diff --git a/tests/test-bundle.t b/tests/test-bundle.t
--- a/tests/test-bundle.t
+++ b/tests/test-bundle.t
@@ -266,13 +266,13 @@ 
 packed1 is produced properly
 
   $ hg -R test debugcreatestreamclonebundle packed.hg
-  writing 2667 bytes for 6 files
+  writing 2663 bytes for 6 files
   bundle requirements: generaldelta, revlogv1
 
   $ f -B 64 --size --sha1 --hexdump packed.hg
-  packed.hg: size=2830, sha1=c28255110a88ffa52ddc44985cad295b1ab349bc
+  packed.hg: size=2826, sha1=e139f97692a142b19cdcff64a69697d5307ce6d4
   0000: 48 47 53 31 55 4e 00 00 00 00 00 00 00 06 00 00 |HGS1UN..........|
-  0010: 00 00 00 00 0a 6b 00 16 67 65 6e 65 72 61 6c 64 |.....k..generald|
+  0010: 00 00 00 00 0a 67 00 16 67 65 6e 65 72 61 6c 64 |.....g..generald|
   0020: 65 6c 74 61 2c 72 65 76 6c 6f 67 76 31 00 64 61 |elta,revlogv1.da|
   0030: 74 61 2f 61 64 69 66 66 65 72 65 6e 74 66 69 6c |ta/adifferentfil|
 
diff --git a/tests/test-generaldelta.t b/tests/test-generaldelta.t
--- a/tests/test-generaldelta.t
+++ b/tests/test-generaldelta.t
@@ -133,8 +133,8 @@ 
   $ hg debugindex -m
      rev    offset  length  delta linkrev nodeid       p1           p2
        0         0      59     -1       0 8dde941edb6e 000000000000 000000000000
-       1        59      59     -1       1 315c023f341d 000000000000 000000000000
-       2       118      65      1       2 2ab389a983eb 315c023f341d 8dde941edb6e
+       1        59      61      0       1 315c023f341d 000000000000 000000000000
+       2       120      65      1       2 2ab389a983eb 315c023f341d 8dde941edb6e
 
   $ hg strip -q -r . --config extensions.strip=
 
@@ -145,8 +145,8 @@ 
   $ hg debugindex -m
      rev    offset  length  delta linkrev nodeid       p1           p2
        0         0      59     -1       0 8dde941edb6e 000000000000 000000000000
-       1        59      59     -1       1 315c023f341d 000000000000 000000000000
-       2       118      62      0       2 2ab389a983eb 315c023f341d 8dde941edb6e
+       1        59      61      0       1 315c023f341d 000000000000 000000000000
+       2       120      62      0       2 2ab389a983eb 315c023f341d 8dde941edb6e
 
 Test that strip bundle use bundle2
   $ hg --config extensions.strip= strip .
diff --git a/tests/test-treemanifest.t b/tests/test-treemanifest.t
--- a/tests/test-treemanifest.t
+++ b/tests/test-treemanifest.t
@@ -276,14 +276,14 @@ 
   $ hg debugindex .hg/store/meta/dir1/00manifest.i
      rev    offset  length  delta linkrev nodeid       p1           p2
        0         0     125     -1       4 63c9c0557d24 000000000000 000000000000
-       1       125     131     -1       5 23d12a1f6e0e 000000000000 000000000000
+       1       125     109      0       5 23d12a1f6e0e 000000000000 000000000000
   $ echo 2 > dir1/a
   $ hg --config experimental.treemanifest=False ci -qm 'modify dir1/a'
   $ hg debugindex .hg/store/meta/dir1/00manifest.i
      rev    offset  length  delta linkrev nodeid       p1           p2
        0         0     125     -1       4 63c9c0557d24 000000000000 000000000000
-       1       125     131     -1       5 23d12a1f6e0e 000000000000 000000000000
-       2       256      55      1       6 3cb2d87b4250 23d12a1f6e0e 000000000000
+       1       125     109      0       5 23d12a1f6e0e 000000000000 000000000000
+       2       234      55      1       6 3cb2d87b4250 23d12a1f6e0e 000000000000
 
 Create deeper repo with tree manifests.