# HG changeset patch # User Thomas Arendsen Hein # Date 1182802090 -7200 # Node ID 36d23de02da14936d24241839db7b81b553776e8 # Parent ad45209a7c7a0831ef32f45b66788c2147777609 Make earlygetopt return a list of all option values, use the last value. This fixes: "hg -R" showing a useful error instead of traceback "hg -R foo --repository bar" using bar instead of foo And provides a way for other users of earlygetopt to accept more than one value. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -248,12 +248,28 @@ def parseconfig(config): return parsed def earlygetopt(aliases, args): - if "--" in args: - args = args[:args.index("--")] - for opt in aliases: - if opt in args: - return args[args.index(opt) + 1] - return None + """Return list of values for a option (with aliases) in given order""" + try: + argcount = args.index("--") + except ValueError: + argcount = len(args) + values = [] + pos = 0 + while pos < argcount: + valuepos = argcount + for opt in aliases: + # find next occurance of current alias + try: + candidate = args.index(opt, pos, argcount) + 1 + # ignore and let getopt report an error if there is no value + if candidate < valuepos: + valuepos = candidate + except ValueError: + pass + if valuepos < argcount: + values.append(args[valuepos]) + pos = valuepos + return values def dispatch(ui, args, argv0=None): # remember how to call 'hg' before changing the working dir @@ -262,7 +278,7 @@ def dispatch(ui, args, argv0=None): # check for cwd first cwd = earlygetopt(['--cwd'], args) if cwd: - os.chdir(cwd) + os.chdir(cwd[-1]) # read the local repository .hgrc into a local ui object path = findrepo() or "" @@ -278,7 +294,7 @@ def dispatch(ui, args, argv0=None): # now we can expand paths, even ones in .hg/hgrc rpath = earlygetopt(["-R", "--repository", "--repo"], args) if rpath: - path = lui.expandpath(rpath) + path = lui.expandpath(rpath[-1]) lui = commands.ui.ui(parentui=ui) lui.readconfig(os.path.join(path, ".hg", "hgrc"))