mercurial/dispatch.py
branchstable
changeset 35034 02845f7441af
parent 35033 d3d35a55e03b
child 35163 ee64e677c3cf
child 35170 c9740b69b9b7
equal deleted inserted replaced
35033:d3d35a55e03b 35034:02845f7441af
   262                 'pdb': pdb.post_mortem
   262                 'pdb': pdb.post_mortem
   263             }
   263             }
   264 
   264 
   265             # read --config before doing anything else
   265             # read --config before doing anything else
   266             # (e.g. to change trust settings for reading .hg/hgrc)
   266             # (e.g. to change trust settings for reading .hg/hgrc)
   267             cfgs = _parseconfig(req.ui, _earlygetopt(['--config'], req.args))
   267             cfgs = _parseconfig(req.ui,
       
   268                                 _earlyreqopt(req, 'config', ['--config']))
   268 
   269 
   269             if req.repo:
   270             if req.repo:
   270                 # copy configs that were passed on the cmdline (--config) to
   271                 # copy configs that were passed on the cmdline (--config) to
   271                 # the repo ui
   272                 # the repo ui
   272                 for sec, name, val in cfgs:
   273                 for sec, name, val in cfgs:
   466                              % (self.name, inst))
   467                              % (self.name, inst))
   467             return
   468             return
   468         self.cmdname = cmd = args.pop(0)
   469         self.cmdname = cmd = args.pop(0)
   469         self.givenargs = args
   470         self.givenargs = args
   470 
   471 
   471         for invalidarg in ("--cwd", "-R", "--repository", "--repo", "--config"):
   472         for invalidarg in commands.earlyoptflags:
   472             if _earlygetopt([invalidarg], args):
   473             if _earlygetopt([invalidarg], args):
   473                 self.badalias = (_("error in definition for alias '%s': %s may "
   474                 self.badalias = (_("error in definition for alias '%s': %s may "
   474                                    "only be given on the command line")
   475                                    "only be given on the command line")
   475                                  % (self.name, invalidarg))
   476                                  % (self.name, invalidarg))
   476                 return
   477                 return
   727                 pos += 1
   728                 pos += 1
   728         else:
   729         else:
   729             pos += 1
   730             pos += 1
   730     return values
   731     return values
   731 
   732 
       
   733 def _earlyreqopt(req, name, aliases):
       
   734     """Peek a list option without using a full options table"""
       
   735     values = _earlygetopt(aliases, req.args, strip=False)
       
   736     req.earlyoptions[name] = values
       
   737     return values
       
   738 
       
   739 def _earlyreqoptstr(req, name, aliases):
       
   740     """Peek a string option without using a full options table"""
       
   741     value = (_earlygetopt(aliases, req.args, strip=False) or [''])[-1]
       
   742     req.earlyoptions[name] = value
       
   743     return value
       
   744 
   732 def _earlyreqoptbool(req, name, aliases):
   745 def _earlyreqoptbool(req, name, aliases):
   733     """Peek a boolean option without using a full options table
   746     """Peek a boolean option without using a full options table
   734 
   747 
   735     >>> req = request([b'x', b'--debugger'])
   748     >>> req = request([b'x', b'--debugger'])
   736     >>> _earlyreqoptbool(req, b'debugger', [b'--debugger'])
   749     >>> _earlyreqoptbool(req, b'debugger', [b'--debugger'])
   817 
   830 
   818     cmd = aliases[0]
   831     cmd = aliases[0]
   819     fn = entry[0]
   832     fn = entry[0]
   820 
   833 
   821     if cmd and util.safehasattr(fn, 'shell'):
   834     if cmd and util.safehasattr(fn, 'shell'):
       
   835         # shell alias shouldn't receive early options which are consumed by hg
       
   836         args = args[:]
       
   837         _earlygetopt(commands.earlyoptflags, args, strip=True)
   822         d = lambda: fn(ui, *args[1:])
   838         d = lambda: fn(ui, *args[1:])
   823         return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d,
   839         return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d,
   824                                   [], {})
   840                                   [], {})
   825 
   841 
   826 def _dispatch(req):
   842 def _dispatch(req):
   827     args = req.args
   843     args = req.args
   828     ui = req.ui
   844     ui = req.ui
   829 
   845 
   830     # check for cwd
   846     # check for cwd
   831     cwd = _earlygetopt(['--cwd'], args)
   847     cwd = _earlyreqoptstr(req, 'cwd', ['--cwd'])
   832     cwd = cwd and cwd[-1] or ''
       
   833     if cwd:
   848     if cwd:
   834         os.chdir(cwd)
   849         os.chdir(cwd)
   835 
   850 
   836     rpath = _earlygetopt(["-R", "--repository", "--repo"], args)
   851     rpath = _earlyreqoptstr(req, 'repository', ["-R", "--repository", "--repo"])
   837     rpath = rpath and rpath[-1] or ''
       
   838     path, lui = _getlocal(ui, rpath)
   852     path, lui = _getlocal(ui, rpath)
   839 
   853 
   840     uis = {ui, lui}
   854     uis = {ui, lui}
   841 
   855 
   842     if req.repo:
   856     if req.repo:
   872             encoding.fallbackencoding = fallback
   886             encoding.fallbackencoding = fallback
   873 
   887 
   874         fullargs = args
   888         fullargs = args
   875         cmd, func, args, options, cmdoptions = _parse(lui, args)
   889         cmd, func, args, options, cmdoptions = _parse(lui, args)
   876 
   890 
   877         if options["config"]:
   891         if options["config"] != req.earlyoptions["config"]:
   878             raise error.Abort(_("option --config may not be abbreviated!"))
   892             raise error.Abort(_("option --config may not be abbreviated!"))
   879         if options["cwd"]:
   893         if options["cwd"] != req.earlyoptions["cwd"]:
   880             raise error.Abort(_("option --cwd may not be abbreviated!"))
   894             raise error.Abort(_("option --cwd may not be abbreviated!"))
   881         if options["repository"]:
   895         if options["repository"] != req.earlyoptions["repository"]:
   882             raise error.Abort(_(
   896             raise error.Abort(_(
   883                 "option -R has to be separated from other options (e.g. not "
   897                 "option -R has to be separated from other options (e.g. not "
   884                 "-qR) and --repository may only be abbreviated as --repo!"))
   898                 "-qR) and --repository may only be abbreviated as --repo!"))
   885         if options["debugger"] != req.earlyoptions["debugger"]:
   899         if options["debugger"] != req.earlyoptions["debugger"]:
   886             raise error.Abort(_("option --debugger may not be abbreviated!"))
   900             raise error.Abort(_("option --debugger may not be abbreviated!"))