diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
index 02850baddaddab29b5f5a0851b6cb1c9b0eeb3ec_bWVyY3VyaWFsL2RlYnVnY29tbWFuZHMucHk=..93313f66b69b58b9537b08f236cc58b5671cb3d1_bWVyY3VyaWFsL2RlYnVnY29tbWFuZHMucHk= 100644
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -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 --git a/tests/test-generaldelta.t b/tests/test-generaldelta.t
index 02850baddaddab29b5f5a0851b6cb1c9b0eeb3ec_dGVzdHMvdGVzdC1nZW5lcmFsZGVsdGEudA==..93313f66b69b58b9537b08f236cc58b5671cb3d1_dGVzdHMvdGVzdC1nZW5lcmFsZGVsdGEudA== 100644
--- a/tests/test-generaldelta.t
+++ b/tests/test-generaldelta.t
@@ -172,6 +172,44 @@
   $ hg init source-repo
   $ cd source-repo
   $ hg debugbuilddag --new-file '.+5:brancha$.+11:branchb$.+30:branchc<brancha+2<branchb+2'
+# add an empty revision somewhere
+  $ hg up tip
+  14 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg rm .
+  removing nf10
+  removing nf11
+  removing nf12
+  removing nf13
+  removing nf14
+  removing nf15
+  removing nf16
+  removing nf17
+  removing nf51
+  removing nf52
+  removing nf6
+  removing nf7
+  removing nf8
+  removing nf9
+  $ hg commit -m 'empty all'
+  $ hg revert --all --rev 'p1(.)'
+  adding nf10
+  adding nf11
+  adding nf12
+  adding nf13
+  adding nf14
+  adding nf15
+  adding nf16
+  adding nf17
+  adding nf51
+  adding nf52
+  adding nf6
+  adding nf7
+  adding nf8
+  adding nf9
+  $ hg commit -m 'restore all'
+  $ hg up null
+  0 files updated, 0 files merged, 14 files removed, 0 files unresolved
+  $ 
   $ cd ..
   $ hg -R source-repo debugdeltachain -m
       rev  chain# chainlen     prev   delta       size    rawsize  chainsize     ratio   lindist extradist extraratio
@@ -228,8 +266,10 @@
        50       4        2       49      p1         58        362        255   0.70442       255         0    0.00000
        51       4        3       50    prev        356        594        611   1.02862       611         0    0.00000
        52       4        4       51      p1         58        640        669   1.04531       669         0    0.00000
+       53       5        1       -1    base          0          0          0   0.00000         0         0    0.00000
+       54       5        2       53      p1        376        640        376   0.58750       376         0    0.00000
   $ hg clone --pull source-repo --config experimental.maxdeltachainspan=2800 relax-chain --config format.generaldelta=yes
   requesting all changes
   adding changesets
   adding manifests
   adding file changes
@@ -231,10 +271,10 @@
   $ hg clone --pull source-repo --config experimental.maxdeltachainspan=2800 relax-chain --config format.generaldelta=yes
   requesting all changes
   adding changesets
   adding manifests
   adding file changes
-  added 53 changesets with 53 changes to 53 files (+2 heads)
-  new changesets 61246295ee1e:99cae3713489
+  added 55 changesets with 53 changes to 53 files (+2 heads)
+  new changesets 61246295ee1e:c930ac4a5b32
   updating to branch default
   14 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg -R relax-chain debugdeltachain -m
@@ -292,8 +332,10 @@
        50       4        2       49      p1         58        362        255   0.70442       255         0    0.00000
        51       2       13       17      p1         58        594        739   1.24411      2781      2042    2.76319
        52       5        1       -1    base        369        640        369   0.57656       369         0    0.00000
+       53       6        1       -1    base          0          0          0   0.00000         0         0    0.00000
+       54       6        2       53      p1        376        640        376   0.58750       376         0    0.00000
   $ hg clone --pull source-repo --config experimental.maxdeltachainspan=0 noconst-chain --config format.generaldelta=yes
   requesting all changes
   adding changesets
   adding manifests
   adding file changes
@@ -295,10 +337,10 @@
   $ hg clone --pull source-repo --config experimental.maxdeltachainspan=0 noconst-chain --config format.generaldelta=yes
   requesting all changes
   adding changesets
   adding manifests
   adding file changes
-  added 53 changesets with 53 changes to 53 files (+2 heads)
-  new changesets 61246295ee1e:99cae3713489
+  added 55 changesets with 53 changes to 53 files (+2 heads)
+  new changesets 61246295ee1e:c930ac4a5b32
   updating to branch default
   14 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg -R noconst-chain debugdeltachain -m
@@ -356,3 +398,5 @@
        50       1        8       49      p1         58        362        447   1.23481      2915      2468    5.52125
        51       2       13       17      p1         58        594        739   1.24411      2642      1903    2.57510
        52       2       14       51      p1         58        640        797   1.24531      2700      1903    2.38770
+       53       4        1       -1    base          0          0          0   0.00000         0         0    0.00000
+       54       4        2       53      p1        376        640        376   0.58750       376         0    0.00000