Mercurial > hg-stable
changeset 38646:93313f66b69b
debugdeltachain: avoid division by zero when a chain is empty
The two ratios chainratio and extraratio are computed using dividers
that may be zero when the file is empty.
As the denominators are integers, the limit of the ratio "just before zero" is
the numerator value itself.
If the numerator itself is zero, the ratio value is still meaningful: in both
cases, a "good" value is a low ratio, and a size of zero is the optimal case.
author | Paul Morelle <paul.morelle@octobus.net> |
---|---|
date | Thu, 21 Jun 2018 18:19:57 +0200 |
parents | 02850baddadd |
children | 0f4c2c70e26e |
files | mercurial/debugcommands.py tests/test-generaldelta.t |
diffstat | 2 files changed, 57 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/debugcommands.py Mon Jul 09 15:33:49 2018 -0700 +++ b/mercurial/debugcommands.py Thu Jun 21 18:19:57 2018 +0200 @@ -678,8 +678,15 @@ except IndexError: prevrev = -1 - chainratio = float(chainsize) / float(uncomp) - extraratio = float(extradist) / float(chainsize) + if uncomp != 0: + chainratio = float(chainsize) / float(uncomp) + else: + chainratio = chainsize + + if chainsize != 0: + extraratio = float(extradist) / float(chainsize) + else: + extraratio = extradist fm.startitem() fm.write('rev chainid chainlen prevrev deltatype compsize '
--- a/tests/test-generaldelta.t Mon Jul 09 15:33:49 2018 -0700 +++ b/tests/test-generaldelta.t Thu Jun 21 18:19:57 2018 +0200 @@ -172,6 +172,44 @@ $ hg init source-repo $ cd source-repo $ hg debugbuilddag --new-file '.+5:brancha$.+11:branchb$.+30:branchc<brancha+2<branchb+2' +# add an empty revision somewhere + $ hg up tip + 14 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg rm . + removing nf10 + removing nf11 + removing nf12 + removing nf13 + removing nf14 + removing nf15 + removing nf16 + removing nf17 + removing nf51 + removing nf52 + removing nf6 + removing nf7 + removing nf8 + removing nf9 + $ hg commit -m 'empty all' + $ hg revert --all --rev 'p1(.)' + adding nf10 + adding nf11 + adding nf12 + adding nf13 + adding nf14 + adding nf15 + adding nf16 + adding nf17 + adding nf51 + adding nf52 + adding nf6 + adding nf7 + adding nf8 + adding nf9 + $ hg commit -m 'restore all' + $ hg up null + 0 files updated, 0 files merged, 14 files removed, 0 files unresolved + $ $ cd .. $ hg -R source-repo debugdeltachain -m rev chain# chainlen prev delta size rawsize chainsize ratio lindist extradist extraratio @@ -228,13 +266,15 @@ 50 4 2 49 p1 58 362 255 0.70442 255 0 0.00000 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 $ hg clone --pull source-repo --config experimental.maxdeltachainspan=2800 relax-chain --config format.generaldelta=yes requesting all changes adding changesets adding manifests adding file changes - added 53 changesets with 53 changes to 53 files (+2 heads) - new changesets 61246295ee1e:99cae3713489 + added 55 changesets with 53 changes to 53 files (+2 heads) + new changesets 61246295ee1e:c930ac4a5b32 updating to branch default 14 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg -R relax-chain debugdeltachain -m @@ -292,13 +332,15 @@ 50 4 2 49 p1 58 362 255 0.70442 255 0 0.00000 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 $ hg clone --pull source-repo --config experimental.maxdeltachainspan=0 noconst-chain --config format.generaldelta=yes requesting all changes adding changesets adding manifests adding file changes - added 53 changesets with 53 changes to 53 files (+2 heads) - new changesets 61246295ee1e:99cae3713489 + added 55 changesets with 53 changes to 53 files (+2 heads) + new changesets 61246295ee1e:c930ac4a5b32 updating to branch default 14 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg -R noconst-chain debugdeltachain -m @@ -356,3 +398,5 @@ 50 1 8 49 p1 58 362 447 1.23481 2915 2468 5.52125 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