Mercurial > hg
diff mercurial/debugcommands.py @ 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 | 760cc5dc01e8 |
children | 0f4c2c70e26e |
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 '