[PATCH STABLE v2] debugrevlog: improve handling of empty manifests/changelogs

timeless timeless at mozdev.org
Fri Jan 29 12:04:53 CST 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1453754438 0
#      Mon Jan 25 20:40:38 2016 +0000
# Branch stable
# Node ID 8811fe5c3ab8808191f1eddbb2467718285f7b14
# Parent  7cb7264cfd52d2672644db4bc16a0bd50aa093ca
debugrevlog: improve handling of empty manifests/changelogs

issue5062

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -507,8 +507,8 @@
             filelog = repo.file(file_)
             if len(filelog):
                 r = filelog
-    if not r:
-        if not file_:
+    if r is None:
+        if not any([cl, dir, mf, file_]):
             raise error.CommandError(cmd, _('invalid arguments'))
         if not os.path.isfile(file_):
             raise error.Abort(_("revlog '%s' not found") % file_)
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2634,8 +2634,8 @@
         except IndexError:
             prevrev = -1
 
-        chainratio = float(chainsize) / float(uncomp)
-        extraratio = float(extradist) / float(chainsize)
+        chainratio = uncomp and float(chainsize) / float(uncomp)
+        extraratio = chainsize and float(extradist) / float(chainsize)
 
         fm.startitem()
         fm.write('rev chainid chainlen prevrev deltatype compsize '
@@ -3283,18 +3283,19 @@
     numdeltas = numrevs - numfull
     numoprev = numprev - nump1prev - nump2prev
     totalrawsize = datasize[2]
-    datasize[2] /= numrevs
-    fulltotal = fullsize[2]
-    fullsize[2] /= numfull
-    deltatotal = deltasize[2]
-    if numrevs - numfull > 0:
-        deltasize[2] /= numrevs - numfull
-    totalsize = fulltotal + deltatotal
-    avgchainlen = sum(chainlengths) / numrevs
-    maxchainlen = max(chainlengths)
-    compratio = 1
-    if totalsize:
-        compratio = totalrawsize / totalsize
+    if numrevs:
+        datasize[2] /= numrevs
+        fulltotal = fullsize[2]
+        fullsize[2] /= numfull
+        deltatotal = deltasize[2]
+        if numdeltas > 0:
+            deltasize[2] /= numdeltas
+        totalsize = fulltotal + deltatotal
+        avgchainlen = sum(chainlengths) / numrevs
+        maxchainlen = max(chainlengths)
+        compratio = 1
+        if totalsize:
+            compratio = totalrawsize / totalsize
 
     basedfmtstr = '%%%dd\n'
     basepcfmtstr = '%%%dd %s(%%5.2f%%%%)\n'
@@ -3313,24 +3314,32 @@
     ui.write(('format : %d\n') % format)
     ui.write(('flags  : %s\n') % ', '.join(flags))
 
-    ui.write('\n')
-    fmt = pcfmtstr(totalsize)
-    fmt2 = dfmtstr(totalsize)
-    ui.write(('revisions     : ') + fmt2 % numrevs)
-    ui.write(('    merges    : ') + fmt % pcfmt(nummerges, numrevs))
-    ui.write(('    normal    : ') + fmt % pcfmt(numrevs - nummerges, numrevs))
-    ui.write(('revisions     : ') + fmt2 % numrevs)
-    ui.write(('    full      : ') + fmt % pcfmt(numfull, numrevs))
-    ui.write(('    deltas    : ') + fmt % pcfmt(numdeltas, numrevs))
-    ui.write(('revision size : ') + fmt2 % totalsize)
-    ui.write(('    full      : ') + fmt % pcfmt(fulltotal, totalsize))
-    ui.write(('    deltas    : ') + fmt % pcfmt(deltatotal, totalsize))
-
-    ui.write('\n')
-    fmt = dfmtstr(max(avgchainlen, compratio))
-    ui.write(('avg chain length  : ') + fmt % avgchainlen)
-    ui.write(('max chain length  : ') + fmt % maxchainlen)
-    ui.write(('compression ratio : ') + fmt % compratio)
+    if numrevs:
+        ui.write('\n')
+        if totalrawsize:
+            fmt = pcfmtstr(totalsize)
+            fmt2 = dfmtstr(totalsize)
+        else:
+            fmt = pcfmtstr(numrevs)
+            fmt2 = dfmtstr(numrevs)
+        ui.write(('revisions     : ') + fmt2 % numrevs)
+        ui.write(('    merges    : ') + fmt % pcfmt(nummerges, numrevs))
+        ui.write(('    normal    : ') + fmt %
+                 pcfmt(numrevs - nummerges, numrevs))
+        ui.write(('revisions     : ') + fmt2 % numrevs)
+        ui.write(('    full      : ') + fmt % pcfmt(numfull, numrevs))
+        ui.write(('    deltas    : ') + fmt % pcfmt(numdeltas, numrevs))
+    if totalrawsize:
+        ui.write(('revision size : ') + fmt2 % totalsize)
+        ui.write(('    full      : ') + fmt % pcfmt(fulltotal, totalsize))
+        ui.write(('    deltas    : ') + fmt % pcfmt(deltatotal, totalsize))
+
+    if chainlengths:
+        ui.write('\n')
+        fmt = dfmtstr(max(avgchainlen, compratio))
+        ui.write(('avg chain length  : ') + fmt % avgchainlen)
+        ui.write(('max chain length  : ') + fmt % maxchainlen)
+        ui.write(('compression ratio : ') + fmt % compratio)
 
     if format > 0:
         ui.write('\n')
diff --git a/tests/bundles/issue5062.hg b/tests/bundles/issue5062.hg
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..4ab60c676af49435fd7f8761d7e91f8bd2e8de9b
GIT binary patch
literal 360
zc$@)f0hj(rM=~$~000g{Z*6dLWpi_BZ*Dz8T0&ZAIWa+5CR16qrt7l+00sZw_?`p;
zL<j%yYTMEPzwQ5^3jh%U0CWN%A_xK?Kv6IN`(}hGJrU at DG|&wI28 at Fs00Yth4^XOm
zN`9hb$OeD_X`!G7gVX~c13&{%nvY1)qd?GlfB*mh00w{nqF1wt;XoECH?m+rsXz-9
ziNd{??V4!P;wMS3_9j!!eKAw!jP%q%m9#Lq!8mZGK{S(*BBJ?3Y>1RZ!~i-00W=G3
zK^00yR9Q6>c>If$A7*R9;EJ!1kP}>WoH;RKZ}6CRjW2_nR=6K_8r2D8+F)bNCUh}a
zD57hSOLe45!BgK}JV>t_=mvEq<3$7sMOC*S0A14o3Nj8=2QXumaOE(|)SpRgH|VH9
zK!jnfgk&;cf)j`t9a%{qMIfkglY3ubPM>po936!J9**x`#O?{i=M_MIi at 744C`emV
Gb=iP~qL29i

diff --git a/tests/test-debugcommands.t b/tests/test-debugcommands.t
--- a/tests/test-debugcommands.t
+++ b/tests/test-debugcommands.t
@@ -5,18 +5,69 @@
 
   $ hg init debugrevlog
   $ cd debugrevlog
-  $ echo a > a
-  $ hg ci -Am adda
-  adding a
+  $ hg debugrevlog -c
+  format : 1
+  flags  : inline
+  
+  uncompressed data size (min/max/avg) : 0 / 0 / 0
+  full revision size (min/max/avg)     : 0 / 0 / 0
+  delta size (min/max/avg)             : 0 / 0 / 0
   $ hg debugrevlog -m
   format : 1
   flags  : inline, generaldelta
   
-  revisions     :  1
+  uncompressed data size (min/max/avg) : 0 / 0 / 0
+  full revision size (min/max/avg)     : 0 / 0 / 0
+  delta size (min/max/avg)             : 0 / 0 / 0
+  $ hg commit --config ui.allowemptycommit=True -m 'empty'
+  $ hg debugrevlog -m
+  format : 1
+  flags  : inline, generaldelta
+  
+  uncompressed data size (min/max/avg) : 0 / 0 / 0
+  full revision size (min/max/avg)     : 0 / 0 / 0
+  delta size (min/max/avg)             : 0 / 0 / 0
+  $ hg rollback
+  repository tip rolled back to revision -1 (undo commit)
+  working directory now based on revision -1
+  $ hg pull "$TESTDIR/bundles/issue5062.hg" -r 0
+  pulling from /home/timeless/hg/crew/tests/bundles/issue5062.hg
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 0 changes to 0 files
+  (run 'hg update' to get a working copy)
+  $ hg debugrevlog -m
+  format : 1
+  flags  : inline, generaldelta
+  
+  revisions     : 1
+      merges    : 0 ( 0.00%)
+      normal    : 1 (100.00%)
+  revisions     : 1
+      full      : 1 (100.00%)
+      deltas    : 0 ( 0.00%)
+  
+  avg chain length  : 0
+  max chain length  : 0
+  compression ratio : 1
+  
+  uncompressed data size (min/max/avg) : 0 / 0 / 0
+  full revision size (min/max/avg)     : 0 / 0 / 0
+  delta size (min/max/avg)             : 0 / 0 / 0
+  $ echo a > a
+  $ hg ci -Am adda
+  adding a
+  created new head
+  $ hg debugrevlog -m
+  format : 1
+  flags  : inline, generaldelta
+  
+  revisions     :  2
       merges    :  0 ( 0.00%)
-      normal    :  1 (100.00%)
-  revisions     :  1
-      full      :  1 (100.00%)
+      normal    :  2 (100.00%)
+  revisions     :  2
+      full      :  2 (100.00%)
       deltas    :  0 ( 0.00%)
   revision size : 44
       full      : 44 (100.00%)
@@ -26,38 +77,54 @@
   max chain length  : 0
   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 / 21
+  full revision size (min/max/avg)     : 0 / 44 / 22
   delta size (min/max/avg)             : 0 / 0 / 0
 
 Test debugindex, with and without the --debug flag
   $ hg debugindex a
      rev    offset  length  ..... linkrev nodeid       p1           p2 (re)
-       0         0       3   ....       0 b789fdd96dc2 000000000000 000000000000 (re)
+       0         0       3   ....       1 b789fdd96dc2 000000000000 000000000000 (re)
   $ hg --debug debugindex a
      rev    offset  length  ..... linkrev nodeid                                   p1                                       p2 (re)
-       0         0       3   ....       0 b789fdd96dc2f3bd229c1dd8eedf0fc60e2b68e3 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 (re)
+       0         0       3   ....       1 b789fdd96dc2f3bd229c1dd8eedf0fc60e2b68e3 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 (re)
   $ hg debugindex -f 1 a
      rev flag   offset   length     size  .....   link     p1     p2       nodeid (re)
-       0 0000        0        3        2   ....      0     -1     -1 b789fdd96dc2 (re)
+       0 0000        0        3        2   ....      1     -1     -1 b789fdd96dc2 (re)
   $ hg --debug debugindex -f 1 a
      rev flag   offset   length     size  .....   link     p1     p2                                   nodeid (re)
-       0 0000        0        3        2   ....      0     -1     -1 b789fdd96dc2f3bd229c1dd8eedf0fc60e2b68e3 (re)
+       0 0000        0        3        2   ....      1     -1     -1 b789fdd96dc2f3bd229c1dd8eedf0fc60e2b68e3 (re)
 
 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
+        0       1        1       -1    base          0          0          0   0.00000         0         0    0.00000
+        1       2        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
 
   $ hg debugdeltachain -m -Tjson
   [
    {
     "chainid": 1,
     "chainlen": 1,
+    "chainratio": 0,
+    "chainsize": 0,
+    "compsize": 0,
+    "deltatype": "base",
+    "extradist": 0,
+    "extraratio": 0,
+    "lindist": 0,
+    "prevrev": -1,
+    "rev": 0,
+    "uncompsize": 0
+   },
+   {
+    "chainid": 2,
+    "chainlen": 1,
     "chainratio": 1.02325581395,
     "chainsize": 44,
     "compsize": 44,
@@ -66,7 +133,7 @@
     "extraratio": 0.0,
     "lindist": 44,
     "prevrev": -1,
-    "rev": 0,
+    "rev": 1,
     "uncompsize": 43
    }
   ]


More information about the Mercurial-devel mailing list