# HG changeset patch # User Thomas Arendsen Hein # Date 1182875731 -7200 # Node ID 79cc512a34edb3fdc6f39183ddb800c2a42bd5a3 # Parent f6e961c0155b759b658bf547ed81117d0a8651a2 Fix earlygetop for short options with unnecessary spaces removed Examples: hg log -qR foo hg log -Rfoo hg log -qRfoo diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -248,7 +248,12 @@ def parseconfig(config): return parsed def earlygetopt(aliases, args): - """Return list of values for a option (with aliases) in given order""" + """Return list of values for a option (with aliases) in given order + + Short option aliases have to occur before long aliases, e.g.: + earlygetopt(["-R", "--repository", "--repo"], args) + (this is not checked!) + """ try: argcount = args.index("--") except ValueError: @@ -258,6 +263,22 @@ def earlygetopt(aliases, args): while pos < argcount: valuepos = argcount for opt in aliases: + # short option can have no spaces, e.g. hg log -qRfoo: + if len(opt) == 2: + i = argcount + while i > 0: + i -= 1 + arg = args[i] + if len(arg) > 2 and arg[0] == '-' and arg[1] != '-': + optpos = arg.find(opt[1]) + # split Rfoo -> R foo + if 0 < optpos < len(arg)-1: + args[i:i+1] = [arg[:optpos+1], arg[optpos+1:]] + argcount += 1 + # split -qR -> -q -R + if optpos > 1: + args[i:i+1] = [arg[:optpos], opt] + argcount += 1 # find next occurance of current alias try: candidate = args.index(opt, pos, argcount) + 1