# HG changeset patch # User Paul Morelle # Date 1529597997 -7200 # Node ID 93313f66b69b58b9537b08f236cc58b5671cb3d1 # Parent 02850baddaddab29b5f5a0851b6cb1c9b0eeb3ec 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. diff -r 02850baddadd -r 93313f66b69b mercurial/debugcommands.py --- 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 ' diff -r 02850baddadd -r 93313f66b69b tests/test-generaldelta.t --- 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