mercurial/dispatch.py
changeset 28313 aa73d6a5d9ea
parent 28263 59509c6724c7
child 28391 73905484ef70
equal deleted inserted replaced
28312:24f1d3c70c41 28313:aa73d6a5d9ea
   494                 self.fn, self.opts, self.help = tableentry
   494                 self.fn, self.opts, self.help = tableentry
   495             else:
   495             else:
   496                 self.fn, self.opts = tableentry
   496                 self.fn, self.opts = tableentry
   497 
   497 
   498             self.args = aliasargs(self.fn, args)
   498             self.args = aliasargs(self.fn, args)
   499             if cmd not in commands.norepo.split(' '):
   499             if not self.fn.norepo:
   500                 self.norepo = False
   500                 self.norepo = False
   501             if cmd in commands.optionalrepo.split(' '):
   501             if self.fn.optionalrepo:
   502                 self.optionalrepo = True
   502                 self.optionalrepo = True
   503             if cmd in commands.inferrepo.split(' '):
   503             if self.fn.inferrepo:
   504                 self.inferrepo = True
   504                 self.inferrepo = True
   505             if self.help.startswith("hg " + cmd):
   505             if self.help.startswith("hg " + cmd):
   506                 # drop prefix in old-style help lines so hg shows the alias
   506                 # drop prefix in old-style help lines so hg shows the alias
   507                 self.help = self.help[4 + len(cmd):]
   507                 self.help = self.help[4 + len(cmd):]
   508             self.__doc__ = self.fn.__doc__
   508             self.__doc__ = self.fn.__doc__
   554         except (KeyError, AttributeError):
   554         except (KeyError, AttributeError):
   555             # definition might not exist or it might not be a cmdalias
   555             # definition might not exist or it might not be a cmdalias
   556             pass
   556             pass
   557 
   557 
   558         cmdtable[aliasdef.name] = (aliasdef, aliasdef.opts, aliasdef.help)
   558         cmdtable[aliasdef.name] = (aliasdef, aliasdef.opts, aliasdef.help)
   559         if aliasdef.norepo:
       
   560             commands.norepo += ' %s' % alias
       
   561         if aliasdef.optionalrepo:
       
   562             commands.optionalrepo += ' %s' % alias
       
   563         if aliasdef.inferrepo:
       
   564             commands.inferrepo += ' %s' % alias
       
   565 
   559 
   566 def _parse(ui, args):
   560 def _parse(ui, args):
   567     options = {}
   561     options = {}
   568     cmdoptions = {}
   562     cmdoptions = {}
   569 
   563 
   726     if not args:
   720     if not args:
   727         return
   721         return
   728 
   722 
   729     if precheck:
   723     if precheck:
   730         strict = True
   724         strict = True
   731         norepo = commands.norepo
       
   732         optionalrepo = commands.optionalrepo
       
   733         inferrepo = commands.inferrepo
       
   734         def restorecommands():
       
   735             commands.norepo = norepo
       
   736             commands.optionalrepo = optionalrepo
       
   737             commands.inferrepo = inferrepo
       
   738         cmdtable = commands.table.copy()
   725         cmdtable = commands.table.copy()
   739         addaliases(lui, cmdtable)
   726         addaliases(lui, cmdtable)
   740     else:
   727     else:
   741         strict = False
   728         strict = False
   742         def restorecommands():
       
   743             pass
       
   744         cmdtable = commands.table
   729         cmdtable = commands.table
   745 
   730 
   746     cmd = args[0]
   731     cmd = args[0]
   747     try:
   732     try:
   748         aliases, entry = cmdutil.findcmd(cmd, cmdtable, strict)
   733         aliases, entry = cmdutil.findcmd(cmd, cmdtable, strict)
   749     except (error.AmbiguousCommand, error.UnknownCommand):
   734     except (error.AmbiguousCommand, error.UnknownCommand):
   750         restorecommands()
       
   751         return
   735         return
   752 
   736 
   753     cmd = aliases[0]
   737     cmd = aliases[0]
   754     fn = entry[0]
   738     fn = entry[0]
   755 
   739 
   756     if cmd and util.safehasattr(fn, 'shell'):
   740     if cmd and util.safehasattr(fn, 'shell'):
   757         d = lambda: fn(ui, *args[1:])
   741         d = lambda: fn(ui, *args[1:])
   758         return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d,
   742         return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d,
   759                                   [], {})
   743                                   [], {})
   760 
       
   761     restorecommands()
       
   762 
   744 
   763 _loaded = set()
   745 _loaded = set()
   764 def _dispatch(req):
   746 def _dispatch(req):
   765     args = req.args
   747     args = req.args
   766     ui = req.ui
   748     ui = req.ui
   874     elif not cmd:
   856     elif not cmd:
   875         return commands.help_(ui, 'shortlist')
   857         return commands.help_(ui, 'shortlist')
   876 
   858 
   877     repo = None
   859     repo = None
   878     cmdpats = args[:]
   860     cmdpats = args[:]
   879     if cmd not in commands.norepo.split():
   861     if not func.norepo:
   880         # use the repo from the request only if we don't have -R
   862         # use the repo from the request only if we don't have -R
   881         if not rpath and not cwd:
   863         if not rpath and not cwd:
   882             repo = req.repo
   864             repo = req.repo
   883 
   865 
   884         if repo:
   866         if repo:
   895             except error.RequirementError:
   877             except error.RequirementError:
   896                 raise
   878                 raise
   897             except error.RepoError:
   879             except error.RepoError:
   898                 if rpath and rpath[-1]: # invalid -R path
   880                 if rpath and rpath[-1]: # invalid -R path
   899                     raise
   881                     raise
   900                 if cmd not in commands.optionalrepo.split():
   882                 if not func.optionalrepo:
   901                     if (cmd in commands.inferrepo.split() and
   883                     if func.inferrepo and args and not path:
   902                         args and not path): # try to infer -R from command args
   884                         # try to infer -R from command args
   903                         repos = map(cmdutil.findrepo, args)
   885                         repos = map(cmdutil.findrepo, args)
   904                         guess = repos[0]
   886                         guess = repos[0]
   905                         if guess and repos.count(guess) == len(repos):
   887                         if guess and repos.count(guess) == len(repos):
   906                             req.args = ['--repository', guess] + fullargs
   888                             req.args = ['--repository', guess] + fullargs
   907                             return _dispatch(req)
   889                             return _dispatch(req)