Patchwork [2,of,2,V2] debugdeltachain: protect against 0 readsize

login
register
mail settings
Submitter Boris Feld
Date July 11, 2018, 12:48 p.m.
Message ID <38562bbb26c9fc08648a.1531313315@FB-lair>
Download mbox | patch
Permalink /patch/32769/
State Accepted
Headers show

Comments

Boris Feld - July 11, 2018, 12:48 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1531309724 -7200
#      Wed Jul 11 13:48:44 2018 +0200
# Node ID 38562bbb26c9fc08648a7c548d9b23b6f048716d
# Parent  0be6256636d19c196111d2445b3d6bd8aff5e445
# EXP-Topic debugdeltachain-divbyzero
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 38562bbb26c9
debugdeltachain: protect against 0 readsize

If you don't read any data, read density should be 1.

Patch

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -715,7 +715,10 @@  def debugdeltachain(ui, repo, file_=None
                 if largestblock < blksize:
                     largestblock = blksize
 
-            readdensity = float(chainsize) / float(readsize)
+            if readsize:
+                readdensity = float(chainsize) / float(readsize)
+            else:
+                readdensity = 1
 
             fm.write('readsize largestblock readdensity srchunks',
                      ' %10d %10d %9.5f %8d',
diff --git a/tests/test-debugcommands.t b/tests/test-debugcommands.t
--- a/tests/test-debugcommands.t
+++ b/tests/test-debugcommands.t
@@ -8,33 +8,41 @@ 
   $ echo a > a
   $ hg ci -Am adda
   adding a
+  $ hg rm .
+  removing a
+  $ hg ci -Am make-it-empty
+  $ hg revert --all -r 0
+  adding a
+  $ hg ci -Am make-it-full
 #if reporevlogstore
   $ hg debugrevlog -m
   format : 1
   flags  : inline, generaldelta
   
-  revisions     :  1
+  revisions     :  3
       merges    :  0 ( 0.00%)
-      normal    :  1 (100.00%)
-  revisions     :  1
-      full      :  1 (100.00%)
+      normal    :  3 (100.00%)
+  revisions     :  3
+      full      :  3 (100.00%)
       deltas    :  0 ( 0.00%)
-  revision size : 44
-      full      : 44 (100.00%)
+  revision size : 88
+      full      : 88 (100.00%)
       deltas    :  0 ( 0.00%)
   
-  chunks        :  1
-      0x75 (u)  :  1 (100.00%)
-  chunks size   : 44
-      0x75 (u)  : 44 (100.00%)
+  chunks        :  3
+      empty     :  1 (33.33%)
+      0x75 (u)  :  2 (66.67%)
+  chunks size   : 88
+      empty     :  0 ( 0.00%)
+      0x75 (u)  : 88 (100.00%)
   
   avg chain length  :  0
   max chain length  :  0
   max chain reach   : 44
   compression ratio :  0
   
-  uncompressed data size (min/max/avg) : 43 / 43 / 43
-  full revision size (min/max/avg)     : 44 / 44 / 44
+  uncompressed data size (min/max/avg) : 0 / 43 / 28
+  full revision size (min/max/avg)     : 0 / 44 / 29
   delta size (min/max/avg)             : 0 / 0 / 0
 #endif
 
@@ -73,9 +81,13 @@  debugdelta chain basic output
   $ hg debugdeltachain -m
       rev  chain# chainlen     prev   delta       size    rawsize  chainsize     ratio   lindist extradist extraratio
         0       1        1       -1    base         44         43         44   1.02326        44         0    0.00000
+        1       2        1       -1    base          0          0          0   0.00000         0         0    0.00000
+        2       3        1       -1    base         44         43         44   1.02326        44         0    0.00000
 
   $ hg debugdeltachain -m -T '{rev} {chainid} {chainlen}\n'
   0 1 1
+  1 2 1
+  2 3 1
 
   $ hg debugdeltachain -m -Tjson
   [
@@ -92,6 +104,34 @@  debugdelta chain basic output
     "prevrev": -1,
     "rev": 0,
     "uncompsize": 43
+   },
+   {
+    "chainid": 2,
+    "chainlen": 1,
+    "chainratio": 0,
+    "chainsize": 0,
+    "compsize": 0,
+    "deltatype": "base",
+    "extradist": 0,
+    "extraratio": 0,
+    "lindist": 0,
+    "prevrev": -1,
+    "rev": 1,
+    "uncompsize": 0
+   },
+   {
+    "chainid": 3,
+    "chainlen": 1,
+    "chainratio": 1.02325581395,
+    "chainsize": 44,
+    "compsize": 44,
+    "deltatype": "base",
+    "extradist": 0,
+    "extraratio": 0.0,
+    "lindist": 44,
+    "prevrev": -1,
+    "rev": 2,
+    "uncompsize": 43
    }
   ]
 
@@ -104,9 +144,13 @@  debugdelta chain with sparse read enable
   $ hg debugdeltachain -m
       rev  chain# chainlen     prev   delta       size    rawsize  chainsize     ratio   lindist extradist extraratio   readsize largestblk rddensity srchunks
         0       1        1       -1    base         44         43         44   1.02326        44         0    0.00000         44         44   1.00000        1
+        1       2        1       -1    base          0          0          0   0.00000         0         0    0.00000          0          0   1.00000        1
+        2       3        1       -1    base         44         43         44   1.02326        44         0    0.00000         44         44   1.00000        1
 
   $ hg debugdeltachain -m -T '{rev} {chainid} {chainlen} {readsize} {largestblock} {readdensity}\n'
   0 1 1 44 44 1.0
+  1 2 1 0 0 1
+  2 3 1 44 44 1.0
 
   $ hg debugdeltachain -m -Tjson
   [
@@ -127,6 +171,42 @@  debugdelta chain with sparse read enable
     "rev": 0,
     "srchunks": 1,
     "uncompsize": 43
+   },
+   {
+    "chainid": 2,
+    "chainlen": 1,
+    "chainratio": 0,
+    "chainsize": 0,
+    "compsize": 0,
+    "deltatype": "base",
+    "extradist": 0,
+    "extraratio": 0,
+    "largestblock": 0,
+    "lindist": 0,
+    "prevrev": -1,
+    "readdensity": 1,
+    "readsize": 0,
+    "rev": 1,
+    "srchunks": 1,
+    "uncompsize": 0
+   },
+   {
+    "chainid": 3,
+    "chainlen": 1,
+    "chainratio": 1.02325581395,
+    "chainsize": 44,
+    "compsize": 44,
+    "deltatype": "base",
+    "extradist": 0,
+    "extraratio": 0.0,
+    "largestblock": 44,
+    "lindist": 44,
+    "prevrev": -1,
+    "readdensity": 1.0,
+    "readsize": 44,
+    "rev": 2,
+    "srchunks": 1,
+    "uncompsize": 43
    }
   ]