mercurial/dispatch.py
changeset 29132 12769703d4ba
parent 29129 e6dfb0e4eeef
child 29761 39149b6036e6
equal deleted inserted replaced
29131:8a66eda46c98 29132:12769703d4ba
   668         lui = ui.copy()
   668         lui = ui.copy()
   669         lui.readconfig(os.path.join(path, ".hg", "hgrc"), path)
   669         lui.readconfig(os.path.join(path, ".hg", "hgrc"), path)
   670 
   670 
   671     return path, lui
   671     return path, lui
   672 
   672 
   673 def _checkshellalias(lui, ui, args, precheck=True):
   673 def _checkshellalias(lui, ui, args):
   674     """Return the function to run the shell alias, if it is required
   674     """Return the function to run the shell alias, if it is required"""
   675 
       
   676     'precheck' is whether this function is invoked before adding
       
   677     aliases or not.
       
   678     """
       
   679     options = {}
   675     options = {}
   680 
   676 
   681     try:
   677     try:
   682         args = fancyopts.fancyopts(args, commands.globalopts, options)
   678         args = fancyopts.fancyopts(args, commands.globalopts, options)
   683     except fancyopts.getopt.GetoptError:
   679     except fancyopts.getopt.GetoptError:
   684         return
   680         return
   685 
   681 
   686     if not args:
   682     if not args:
   687         return
   683         return
   688 
   684 
   689     if precheck:
   685     cmdtable = commands.table
   690         strict = True
       
   691         cmdtable = commands.table.copy()
       
   692         addaliases(lui, cmdtable)
       
   693     else:
       
   694         strict = False
       
   695         cmdtable = commands.table
       
   696 
   686 
   697     cmd = args[0]
   687     cmd = args[0]
   698     try:
   688     try:
       
   689         strict = ui.configbool("ui", "strict")
   699         aliases, entry = cmdutil.findcmd(cmd, cmdtable, strict)
   690         aliases, entry = cmdutil.findcmd(cmd, cmdtable, strict)
   700     except (error.AmbiguousCommand, error.UnknownCommand):
   691     except (error.AmbiguousCommand, error.UnknownCommand):
   701         return
   692         return
   702 
   693 
   703     cmd = aliases[0]
   694     cmd = aliases[0]
   743         os.chdir(cwd[-1])
   734         os.chdir(cwd[-1])
   744 
   735 
   745     rpath = _earlygetopt(["-R", "--repository", "--repo"], args)
   736     rpath = _earlygetopt(["-R", "--repository", "--repo"], args)
   746     path, lui = _getlocal(ui, rpath)
   737     path, lui = _getlocal(ui, rpath)
   747 
   738 
   748     # Now that we're operating in the right directory/repository with
       
   749     # the right config settings, check for shell aliases
       
   750     shellaliasfn = _checkshellalias(lui, ui, args)
       
   751     if shellaliasfn:
       
   752         return shellaliasfn()
       
   753 
       
   754     # Configure extensions in phases: uisetup, extsetup, cmdtable, and
   739     # Configure extensions in phases: uisetup, extsetup, cmdtable, and
   755     # reposetup. Programs like TortoiseHg will call _dispatch several
   740     # reposetup. Programs like TortoiseHg will call _dispatch several
   756     # times so we keep track of configured extensions in _loaded.
   741     # times so we keep track of configured extensions in _loaded.
   757     extensions.loadall(lui)
   742     extensions.loadall(lui)
   758     exts = [ext for ext in extensions.extensions() if ext[0] not in _loaded]
   743     exts = [ext for ext in extensions.extensions() if ext[0] not in _loaded]
   770 
   755 
   771     # (reposetup is handled in hg.repository)
   756     # (reposetup is handled in hg.repository)
   772 
   757 
   773     addaliases(lui, commands.table)
   758     addaliases(lui, commands.table)
   774 
   759 
   775     if not lui.configbool("ui", "strict"):
   760     # All aliases and commands are completely defined, now.
   776         # All aliases and commands are completely defined, now.
   761     # Check abbreviation/ambiguity of shell alias.
   777         # Check abbreviation/ambiguity of shell alias again, because shell
   762     shellaliasfn = _checkshellalias(lui, ui, args)
   778         # alias may cause failure of "_parse" (see issue4355)
   763     if shellaliasfn:
   779         shellaliasfn = _checkshellalias(lui, ui, args, precheck=False)
   764         return shellaliasfn()
   780         if shellaliasfn:
       
   781             return shellaliasfn()
       
   782 
   765 
   783     # check for fallback encoding
   766     # check for fallback encoding
   784     fallback = lui.config('ui', 'fallbackencoding')
   767     fallback = lui.config('ui', 'fallbackencoding')
   785     if fallback:
   768     if fallback:
   786         encoding.fallbackencoding = fallback
   769         encoding.fallbackencoding = fallback