changeset 26826:39dbf495880b stable

debugrevlog: cope with empty revlog files I have no idea where it came from, but my clone of Mercurial has an empty filelog for `contrib/hgfixes/__init__.py` - it's *valid*, just contains no nodes. Without this change, debugrevlog crashes with a zero division error.
author Augie Fackler <augie@google.com>
date Fri, 23 Oct 2015 11:04:53 -0400
parents 78539633acf3
children a9ed5a8fc5e0
files mercurial/commands.py
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Fri Oct 23 21:27:29 2015 +0200
+++ b/mercurial/commands.py	Fri Oct 23 11:04:53 2015 -0400
@@ -3037,7 +3037,9 @@
     totalsize = fulltotal + deltatotal
     avgchainlen = sum(chainlengths) / numrevs
     maxchainlen = max(chainlengths)
-    compratio = totalrawsize / totalsize
+    compratio = 1
+    if totalsize:
+        compratio = totalrawsize / totalsize
 
     basedfmtstr = '%%%dd\n'
     basepcfmtstr = '%%%dd %s(%%5.2f%%%%)\n'
@@ -3048,7 +3050,10 @@
         return basepcfmtstr % (len(str(max)), ' ' * padding)
 
     def pcfmt(value, total):
-        return (value, 100 * float(value) / total)
+        if total:
+            return (value, 100 * float(value) / total)
+        else:
+            return value, 100.0
 
     ui.write(('format : %d\n') % format)
     ui.write(('flags  : %s\n') % ', '.join(flags))