[PATCH 2 of 2] dispatch: don't stack trace on commands like `hg .log`

Augie Fackler raf at durin42.com
Fri Sep 25 12:28:41 CDT 2015


On Fri, Sep 25, 2015 at 12:24:12PM -0400, Jordi GutiƩrrez Hermoso wrote:
> # HG changeset patch
> # User Jordi GutiƩrrez Hermoso <jordigh at octave.org>
> # Date 1443194180 14400
> #      Fri Sep 25 11:16:20 2015 -0400
> # Node ID de7f04300f2a853e1a9033cd4dc89cf54662af72
> # Parent  c14d27fbb5a6568a232843887a63660e90208cbe
> dispatch: don't stack trace on commands like `hg .log`

Queued these. I'm unsure of the localization risks of patch 1, but I'm
choosing to err on the side of nicer to humans.

>
> This used to stack trace because it raised a util.Abort which wasn't
> handled in this block. We now handle it. Additionally, we error out
> earlier instead of plodding on and showing the "log" entry of the
> plain `hg help` output.
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -3981,7 +3981,11 @@ def help_(ui, name=None, **opts):
>
>      formatted, pruned = minirst.format(text, textwidth, keep=keep,
>                                         section=section)
> -    if section and not formatted:
> +
> +    # We could have been given a weird ".foo" section without a name
> +    # to look for, or we could have simply failed to found "foo.bar"
> +    # because bar isn't a section of foo
> +    if section and not (formatted and name):
>          raise util.Abort(_("help section not found"))
>
>      if 'verbose' in pruned:
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -253,7 +253,7 @@ def _runcatch(req):
>              # check if the command is in a disabled extension
>              # (but don't check for extensions themselves)
>              commands.help_(ui, inst.args[0], unknowncmd=True)
> -        except error.UnknownCommand:
> +        except (error.UnknownCommand, util.Abort):
>              suggested = False
>              if len(inst.args) == 2:
>                  sim = _getsimilar(inst.args[1], inst.args[0])
> diff --git a/tests/test-help.t b/tests/test-help.t
> --- a/tests/test-help.t
> +++ b/tests/test-help.t
> @@ -626,6 +626,23 @@ Test command suggestion, both one or mul
>    (did you mean 'log'?)
>    [255]
>
> +Make sure that we don't run afoul of the help system thinking that
> +this is a section and erroring out weirdly.
> +
> +  $ hg .log
> +  hg: unknown command '.log'
> +  (did you mean 'log'?)
> +  [255]
> +
> +  $ hg log.
> +  hg: unknown command 'log.'
> +  (did you mean 'log'?)
> +  [255]
> +  $ hg pu.lh
> +  hg: unknown command 'pu.lh'
> +  (did you mean one of 'pull', 'push'?)
> +  [255]
> +
>    $ cat > helpext.py <<EOF
>    > import os
>    > from mercurial import cmdutil, commands
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list