[PATCH STABLE] alias: handle shlex error in command aliases

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri May 16 23:42:31 CDT 2014



On 05/16/2014 09:37 PM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1400299576 -32400
> #      Sat May 17 13:06:16 2014 +0900
> # Branch stable
> # Node ID 83696824c83f8a8a28ea02bf482c63d9d79a089d
> # Parent  54d7657d7d1e6a62315eea53f4498657e766bb60
> alias: handle shlex error in command aliases

A wild bug fix appear! Thanks!

> No command should fail with ValueError just because there is unparseable
> alias definition.

But no command command should pretend to succeed when there miserably 
failed:

Could we raise an Abort Error instead?

>
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -383,7 +383,16 @@ class cmdalias(object):
>               self.fn = fn
>               return
>
> -        args = shlex.split(self.definition)
> +        try:
> +            args = shlex.split(self.definition)
> +        except ValueError, inst:
> +            def fn(ui, *args):
> +                ui.warn(_("error in definition for alias '%s': %s\n")
> +                        % (self.name, inst))
> +                return 1
> +            self.fn = fn
> +            self.badalias = True
> +            return
>           self.cmdname = cmd = args.pop(0)
>           args = map(util.expandpath, args)
>
> diff --git a/tests/test-alias.t b/tests/test-alias.t
> --- a/tests/test-alias.t
> +++ b/tests/test-alias.t
> @@ -10,6 +10,7 @@
>     > ambiguous = s
>     > recursive = recursive
>     > nodefinition =
> +  > noclosingquotation = '
>     > no--cwd = status --cwd elsewhere
>     > no-R = status -R elsewhere
>     > no--repo = status --repo elsewhere
> @@ -86,6 +87,14 @@ no definition
>     no definition for alias 'nodefinition'
>
>
> +no closing quotation
> +
> +  $ hg noclosing
> +  error in definition for alias 'noclosingquotation': No closing quotation

Raising AbortError will turn this in:

   error in definition for alias 'noclosingquotation': No closing quotation
   [255] ← Something terrible happen return code.

> +  $ hg help noclosing
> +  error in definition for alias 'noclosingquotation': No closing quotation
> +
> +
>   invalid options
>
>     $ hg no--cwd

Please resend an updated version

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list