[PATCH STABLE] debugrevlog: improve handling of empty manifests/changelogs
Yuya Nishihara
yuya at tcha.org
Wed Jan 27 08:21:03 CST 2016
On Mon, 25 Jan 2016 15:25:51 -0600, timeless wrote:
> # HG changeset patch
> # User timeless <timeless at 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 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
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.
More information about the Mercurial-devel
mailing list