Mercurial > hg
comparison mercurial/dispatch.py @ 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 |
comparison
equal
deleted
inserted
replaced
22376:d821fff9b0b9 | 22377:f98abe3146b2 |
---|---|
642 | 642 |
643 if not args: | 643 if not args: |
644 return | 644 return |
645 | 645 |
646 if precheck: | 646 if precheck: |
647 strict = True | |
647 norepo = commands.norepo | 648 norepo = commands.norepo |
648 optionalrepo = commands.optionalrepo | 649 optionalrepo = commands.optionalrepo |
649 def restorecommands(): | 650 def restorecommands(): |
650 commands.norepo = norepo | 651 commands.norepo = norepo |
651 commands.optionalrepo = optionalrepo | 652 commands.optionalrepo = optionalrepo |
652 cmdtable = commands.table.copy() | 653 cmdtable = commands.table.copy() |
653 addaliases(lui, cmdtable) | 654 addaliases(lui, cmdtable) |
654 else: | 655 else: |
656 strict = False | |
655 def restorecommands(): | 657 def restorecommands(): |
656 pass | 658 pass |
657 cmdtable = commands.table | 659 cmdtable = commands.table |
658 | 660 |
659 cmd = args[0] | 661 cmd = args[0] |
660 try: | 662 try: |
661 aliases, entry = cmdutil.findcmd(cmd, cmdtable) | 663 aliases, entry = cmdutil.findcmd(cmd, cmdtable, strict) |
662 except (error.AmbiguousCommand, error.UnknownCommand): | 664 except (error.AmbiguousCommand, error.UnknownCommand): |
663 restorecommands() | 665 restorecommands() |
664 return | 666 return |
665 | 667 |
666 cmd = aliases[0] | 668 cmd = aliases[0] |
712 _loaded.add(name) | 714 _loaded.add(name) |
713 | 715 |
714 # (reposetup is handled in hg.repository) | 716 # (reposetup is handled in hg.repository) |
715 | 717 |
716 addaliases(lui, commands.table) | 718 addaliases(lui, commands.table) |
719 | |
720 if not lui.configbool("ui", "strict"): | |
721 # All aliases and commands are completely defined, now. | |
722 # Check abbreviation/ambiguity of shell alias again, because shell | |
723 # alias may cause failure of "_parse" (see issue4355) | |
724 shellaliasfn = _checkshellalias(lui, ui, args, precheck=False) | |
725 if shellaliasfn: | |
726 return shellaliasfn() | |
717 | 727 |
718 # check for fallback encoding | 728 # check for fallback encoding |
719 fallback = lui.config('ui', 'fallbackencoding') | 729 fallback = lui.config('ui', 'fallbackencoding') |
720 if fallback: | 730 if fallback: |
721 encoding.fallbackencoding = fallback | 731 encoding.fallbackencoding = fallback |