comparison 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
comparison
equal deleted inserted replaced
38645:02850baddadd 38646:93313f66b69b
676 try: 676 try:
677 prevrev = chain[-2] 677 prevrev = chain[-2]
678 except IndexError: 678 except IndexError:
679 prevrev = -1 679 prevrev = -1
680 680
681 chainratio = float(chainsize) / float(uncomp) 681 if uncomp != 0:
682 extraratio = float(extradist) / float(chainsize) 682 chainratio = float(chainsize) / float(uncomp)
683 else:
684 chainratio = chainsize
685
686 if chainsize != 0:
687 extraratio = float(extradist) / float(chainsize)
688 else:
689 extraratio = extradist
683 690
684 fm.startitem() 691 fm.startitem()
685 fm.write('rev chainid chainlen prevrev deltatype compsize ' 692 fm.write('rev chainid chainlen prevrev deltatype compsize '
686 'uncompsize chainsize chainratio lindist extradist ' 693 'uncompsize chainsize chainratio lindist extradist '
687 'extraratio', 694 'extraratio',