Mercurial > hg
changeset 22377:f98abe3146b2 stable
dispatch: check shell alias again after loading extensions (issue4355)
Before this patch, the shell alias causes failure when it takes its
specific (= unknown for "hg") options in the command line, because
"_parse()" can't accept them.
This is the regression introduced by 03d345da0579.
It fixed the issue that ambiguity between shell aliases and commands
defined by extensions was ignored. But it also caused that ambiguous
shell alias is handled in "_parse()" even if it takes specific options
in the command line.
To avoid such failure, this patch checks shell alias again after
loading extensions.
All aliases and commands (including ones defined by extensions) are
completely defined before the 2nd (= newly added in this patch)
"_checkshellalias()" invocation, and "cmdutil.findcmd(strict=False)"
can detect ambiguity between them correctly.
For efficiency, this patch does:
- omit the 2nd "_checkshellalias()" invocation if "[ui] strict= True"
it causes "cmdutil.findcmd(strict=True)", of which result should
be equal to one of the 1st invocation before adding aliases
- avoid removing the 1st "_checkshellalias()" invocation
it causes "cmdutil.findcmd(strict=True)" invocation preventing
shell alias execution from loading extensions uselessly
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Wed, 10 Sep 2014 00:41:44 +0900 |
parents | d821fff9b0b9 |
children | c828b61e0635 fd0f0b0d316d |
files | mercurial/dispatch.py tests/test-alias.t |
diffstat | 2 files changed, 14 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/dispatch.py Wed Sep 10 00:41:44 2014 +0900 +++ b/mercurial/dispatch.py Wed Sep 10 00:41:44 2014 +0900 @@ -644,6 +644,7 @@ return if precheck: + strict = True norepo = commands.norepo optionalrepo = commands.optionalrepo def restorecommands(): @@ -652,13 +653,14 @@ cmdtable = commands.table.copy() addaliases(lui, cmdtable) else: + strict = False def restorecommands(): pass cmdtable = commands.table cmd = args[0] try: - aliases, entry = cmdutil.findcmd(cmd, cmdtable) + aliases, entry = cmdutil.findcmd(cmd, cmdtable, strict) except (error.AmbiguousCommand, error.UnknownCommand): restorecommands() return @@ -715,6 +717,14 @@ addaliases(lui, commands.table) + if not lui.configbool("ui", "strict"): + # All aliases and commands are completely defined, now. + # Check abbreviation/ambiguity of shell alias again, because shell + # alias may cause failure of "_parse" (see issue4355) + shellaliasfn = _checkshellalias(lui, ui, args, precheck=False) + if shellaliasfn: + return shellaliasfn() + # check for fallback encoding fallback = lui.config('ui', 'fallbackencoding') if fallback:
--- a/tests/test-alias.t Wed Sep 10 00:41:44 2014 +0900 +++ b/tests/test-alias.t Wed Sep 10 00:41:44 2014 +0900 @@ -353,7 +353,7 @@ > [extensions] > hgext.rebase = > [alias] - > rebate = !echo this is rebate + > rebate = !echo this is \$HG_ARGS > EOF $ hg reba hg: command 'reba' is ambiguous: @@ -361,6 +361,8 @@ [255] $ hg rebat this is rebate + $ hg rebat --foo-bar + this is rebate --foo-bar invalid arguments