mercurial/cmdutil.py
changeset 4716 36d23de02da1
parent 4714 a741293793f6
child 4717 97369f6a6bb6
equal deleted inserted replaced
4715:ad45209a7c7a 4716:36d23de02da1
   246         except (IndexError, ValueError):
   246         except (IndexError, ValueError):
   247             raise util.Abort(_('malformed --config option: %s') % cfg)
   247             raise util.Abort(_('malformed --config option: %s') % cfg)
   248     return parsed
   248     return parsed
   249 
   249 
   250 def earlygetopt(aliases, args):
   250 def earlygetopt(aliases, args):
   251     if "--" in args:
   251     """Return list of values for a option (with aliases) in given order"""
   252         args = args[:args.index("--")]
   252     try:
   253     for opt in aliases:
   253         argcount = args.index("--")
   254         if opt in args:
   254     except ValueError:
   255             return args[args.index(opt) + 1]
   255         argcount = len(args)
   256     return None
   256     values = []
       
   257     pos = 0
       
   258     while pos < argcount:
       
   259         valuepos = argcount
       
   260         for opt in aliases:
       
   261             # find next occurance of current alias
       
   262             try:
       
   263                 candidate = args.index(opt, pos, argcount) + 1
       
   264                 # ignore and let getopt report an error if there is no value
       
   265                 if candidate < valuepos:
       
   266                     valuepos = candidate
       
   267             except ValueError:
       
   268                 pass
       
   269         if valuepos < argcount:
       
   270             values.append(args[valuepos])
       
   271         pos = valuepos
       
   272     return values
   257 
   273 
   258 def dispatch(ui, args, argv0=None):
   274 def dispatch(ui, args, argv0=None):
   259     # remember how to call 'hg' before changing the working dir
   275     # remember how to call 'hg' before changing the working dir
   260     util.set_hgexecutable(argv0)
   276     util.set_hgexecutable(argv0)
   261 
   277 
   262     # check for cwd first
   278     # check for cwd first
   263     cwd = earlygetopt(['--cwd'], args)
   279     cwd = earlygetopt(['--cwd'], args)
   264     if cwd:
   280     if cwd:
   265         os.chdir(cwd)
   281         os.chdir(cwd[-1])
   266 
   282 
   267     # read the local repository .hgrc into a local ui object
   283     # read the local repository .hgrc into a local ui object
   268     path = findrepo() or ""
   284     path = findrepo() or ""
   269     if not path:
   285     if not path:
   270         lui = ui
   286         lui = ui
   276             pass
   292             pass
   277 
   293 
   278     # now we can expand paths, even ones in .hg/hgrc
   294     # now we can expand paths, even ones in .hg/hgrc
   279     rpath = earlygetopt(["-R", "--repository", "--repo"], args)
   295     rpath = earlygetopt(["-R", "--repository", "--repo"], args)
   280     if rpath:
   296     if rpath:
   281         path = lui.expandpath(rpath)
   297         path = lui.expandpath(rpath[-1])
   282         lui = commands.ui.ui(parentui=ui)
   298         lui = commands.ui.ui(parentui=ui)
   283         lui.readconfig(os.path.join(path, ".hg", "hgrc"))
   299         lui.readconfig(os.path.join(path, ".hg", "hgrc"))
   284 
   300 
   285     extensions.loadall(lui)
   301     extensions.loadall(lui)
   286     # check for fallback encoding
   302     # check for fallback encoding