[PATCH 2 of 2] cmdutil: prevent "show" from matching "showconfig" (BC)

Yuya Nishihara yuya at tcha.org
Thu May 18 10:23:23 EDT 2017


On Wed, 17 May 2017 19:13:12 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1493334106 25200
> #      Thu Apr 27 16:01:46 2017 -0700
> # Node ID fc33b0dd5feecb4a51e6ef797ff4fffb145a8be7
> # Parent  706ff3761c606fe127bc4bc3fb5267039e6f9131
> cmdutil: prevent "show" from matching "showconfig" (BC)
> 
> cmdutil.findpossible() performs a string prefix match to determine
> if a user-provided command/string should map to a command. If there
> is an unambiguous match, the mapped command is used.
> 
> This causes problems with commands defined by extensions. These
> commands aren't in the commands table. So, the command names and
> aliases have no opportunity to create a prefix match and prevent
> an unambiguous match.
> 
> In the case of `hg show`, "show" was being mapped to "showconfig"
> because nothing else in core has a "show" prefix.
> 
> This commit adds an argument to the @command decorator to define
> strings that won't be allowed to partial match the command.
> findpossible() has been taught to consult this value. And
> `hg config` now doesn't match against "show."
> 
> The single test change demonstrates that an out-of-the-box
> `hg show` now properly indicates that the command is provided by
> an extension.
> 
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -318,8 +318,9 @@ def findpossible(cmd, table, strict=Fals
>          if cmd in aliases:
>              found = cmd
>          elif not strict:
> +            nomatch = table[e][0].nomatch
>              for a in aliases:
> -                if a.startswith(cmd):
> +                if a.startswith(cmd) and cmd not in nomatch:
>                      found = a
>                      break
>          if found is not None:
> @@ -3363,13 +3364,18 @@ def command(table):
>      command line arguments. If True, arguments will be examined for potential
>      repository locations. See ``findrepo()``. If a repository is found, it
>      will be used.
> +
> +    ``nomatch`` defines an iterable of command strings that should not result
> +    in an alias match. Without this, all string prefixes in ``name`` elements
> +    will map to this command.
>      """

The BC seems fine, but I don't think this is a property attached to each
command, but an inter-command thing. I we had "showblahblah" command for
example, it would also have to define the same notmatch list.

Given this is a temporary workaround until "show" gets into the core, I'd
rather make a simple ad-hoc change.


More information about the Mercurial-devel mailing list