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

login
register
mail settings
Submitter timeless@mozdev.org
Date Jan. 25, 2016, 9:25 p.m.
Message ID <8b795807503533f955ee.1453757151@waste.org>
Download mbox | patch
Permalink /patch/12886/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show

Comments

timeless@mozdev.org - Jan. 25, 2016, 9:25 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1453754438 0
#      Mon Jan 25 20:40:38 2016 +0000
# Branch stable
# Node ID 8b795807503533f955ee3a90869bb2e772be763c
# Parent  1779ff7426c9ef1605e6e1fdb9994a4c836fc459
debugrevlog: improve handling of empty manifests/changelogs

issue5062
Yuya Nishihara - Jan. 27, 2016, 2:21 p.m.
On Mon, 25 Jan 2016 15:25:51 -0600, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1453754438 0
> #      Mon Jan 25 20:40:38 2016 +0000
> # Branch stable
> # Node ID 8b795807503533f955ee3a90869bb2e772be763c
> # Parent  1779ff7426c9ef1605e6e1fdb9994a4c836fc459
> 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,9 +507,12 @@
>              filelog = repo.file(file_)
>              if len(filelog):
>                  r = filelog
> +    # This is intentionally not checking `r is not None`
>      if not r:
> -        if not file_:
> -            raise error.CommandError(cmd, _('invalid arguments'))

Got exception:

$ hg debugindex
Traceback (most recent call last):
  File "./hg", line 43, in <module>
    mercurial.dispatch.run()
  File "mercurial/dispatch.py", line 54, in run
    sys.exit((dispatch(request(sys.argv[1:])) or 0) & 255)
  File "mercurial/dispatch.py", line 120, in dispatch
    ret = _runcatch(req)
  File "mercurial/dispatch.py", line 191, in _runcatch
    return _dispatch(req)
  File "mercurial/dispatch.py", line 924, in _dispatch
    cmdpats, cmdoptions)
  File "mercurial/dispatch.py", line 681, in runcommand
    ret = _runcommand(ui, options, cmd, d)
  File "mercurial/extensions.py", line 195, in closure
    return func(*(args + a), **kw)
  File "hgext/color.py", line 518, in colorcmd
    return orig(ui_, opts, cmd, cmdfunc)
  File "mercurial/dispatch.py", line 1055, in _runcommand
    return checkargs()
  File "mercurial/dispatch.py", line 1015, in checkargs
    return cmdfunc()
  File "mercurial/dispatch.py", line 921, in <lambda>
    d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
  File "mercurial/util.py", line 991, in check
    return func(*args, **kwargs)
  File "mercurial/extensions.py", line 195, in closure
    return func(*(args + a), **kw)
  File "mercurial/util.py", line 991, in check
    return func(*args, **kwargs)
  File "hgext/mq.py", line 3516, in mqcommand
    return orig(ui, repo, *args, **kwargs)
  File "mercurial/util.py", line 991, in check
    return func(*args, **kwargs)
  File "mercurial/commands.py", line 2491, in debugindex
    r = cmdutil.openrevlog(repo, 'debugindex', file_, opts)
  File "mercurial/cmdutil.py", line 516, in openrevlog
    if not os.path.isfile(file_):
  File "/usr/lib/python2.7/genericpath.py", line 37, in isfile
    st = os.stat(path)
TypeError: coercing to Unicode: need string or buffer, NoneType found

> +        if cl:
> +            raise error.Abort(_("repository changelog is empty"))
> +        if mf:
> +            raise error.Abort(_("repository manifest is empty"))
>          if not os.path.isfile(file_):
>              raise error.Abort(_("revlog '%s' not found") % file_)

IMHO, "hg debugindex -c" is valid even if changelog is empty. And if it is
an error, "hg debugindex .hg/store/00changelog.i" should be the same.

> --- 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 = float(chainsize) and float(chainsize) / float(uncomp)
> +        extraratio = float(extradist) and float(extradist) / float(chainsize)

Why checking numerator?

> @@ -3210,7 +3210,7 @@
>                       (rev, p1, p2, r.start(rev), r.end(rev),
>                        r.start(dbase), r.start(cbase),
>                        r.start(p1), r.start(p2),
> -                      rs, ts, ts / r.end(rev), len(heads), clen))
> +                      rs, ts, ts and ts / r.end(rev), len(heads), clen))

> 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@DG|&wI28@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@744C`emV
> Gb=iP~qL29i

You can make an empty commit by "--config ui.allowemptycommit=True" or
"hg branch foo && hg ci".

> diff --git a/tests/test-debugcommands.t b/tests/test-debugcommands.t
> --- a/tests/test-debugcommands.t
> +++ b/tests/test-debugcommands.t
> @@ -1,3 +1,5 @@
> +#require test-repo

The test seems to work without a repo.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -507,9 +507,12 @@ 
             filelog = repo.file(file_)
             if len(filelog):
                 r = filelog
+    # This is intentionally not checking `r is not None`
     if not r:
-        if not file_:
-            raise error.CommandError(cmd, _('invalid arguments'))
+        if cl:
+            raise error.Abort(_("repository changelog is empty"))
+        if mf:
+            raise error.Abort(_("repository manifest is empty"))
         if not os.path.isfile(file_):
             raise error.Abort(_("revlog '%s' not found") % file_)
         r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False),
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 = float(chainsize) and float(chainsize) / float(uncomp)
+        extraratio = float(extradist) and float(extradist) / float(chainsize)
 
         fm.startitem()
         fm.write('rev chainid chainlen prevrev deltatype compsize '
@@ -3210,7 +3210,7 @@ 
                      (rev, p1, p2, r.start(rev), r.end(rev),
                       r.start(dbase), r.start(cbase),
                       r.start(p1), r.start(p2),
-                      rs, ts, ts / r.end(rev), len(heads), clen))
+                      rs, ts, ts and ts / r.end(rev), len(heads), clen))
         return 0
 
     v = r.version
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@DG|&wI28@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@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
@@ -1,3 +1,5 @@ 
+#require test-repo
+
   $ cat << EOF >> $HGRCPATH
   > [format]
   > usegeneraldelta=yes
@@ -5,18 +7,54 @@ 
 
   $ hg init debugrevlog
   $ cd debugrevlog
-  $ echo a > a
-  $ hg ci -Am adda
-  adding a
+  $ hg debugrevlog -c
+  abort: repository changelog is empty
+  [255]
+  $ hg debugrevlog -m
+  abort: repository manifest is empty
+  [255]
+  $ hg pull "$TESTDIR/bundles/issue5062.hg" -r 0
+  pulling from *issue5062.hg (glob)
+  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
+  revisions     : 1
+      merges    : 0 ( 0.00%)
+      normal    : 1 (100.00%)
+  revisions     : 1
+      full      : 1 (100.00%)
+      deltas    : 0 ( 0.00%)
+  revision size : 0
+      full      : 0 (100.00%)
+      deltas    : 0 (100.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 +64,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.0,
+    "chainsize": 0,
+    "compsize": 0,
+    "deltatype": "base",
+    "extradist": 0,
+    "extraratio": 0.0,
+    "lindist": 0,
+    "prevrev": -1,
+    "rev": 0,
+    "uncompsize": 0
+   },
+   {
+    "chainid": 2,
+    "chainlen": 1,
     "chainratio": 1.02325581395,
     "chainsize": 44,
     "compsize": 44,
@@ -66,7 +120,7 @@ 
     "extraratio": 0.0,
     "lindist": 44,
     "prevrev": -1,
-    "rev": 0,
+    "rev": 1,
     "uncompsize": 43
    }
   ]