dispatch: add support for --option=value to _earlygetopt stable
authorBryan O'Sullivan <bryano@fb.com>
Mon, 29 Apr 2013 14:14:42 -0700
branchstable
changeset 19099 fc081623f4bd
parent 19098 f01ae031f84c
child 19101 da4175159dac
dispatch: add support for --option=value to _earlygetopt This fixes a very confusing error message: $ hg --config=pager.enabled=off st abort: option --config may not be abbreviated!
mercurial/dispatch.py
--- a/mercurial/dispatch.py	Mon Apr 29 14:14:41 2013 -0700
+++ b/mercurial/dispatch.py	Mon Apr 29 14:14:42 2013 -0700
@@ -490,6 +490,10 @@
     >>> _earlygetopt(['--cwd'], args), args
     (['foo'], ['x', 'y'])
 
+    >>> args = ['x', '--cwd=bar', 'y']
+    >>> _earlygetopt(['--cwd'], args), args
+    (['bar'], ['x', 'y'])
+
     >>> args = ['x', '-R', 'foo', 'y']
     >>> _earlygetopt(['-R'], args), args
     (['foo'], ['x', 'y'])
@@ -506,14 +510,22 @@
     values = []
     pos = 0
     while pos < argcount:
-        if args[pos] in aliases:
-            if pos + 1 >= argcount:
-                # ignore and let getopt report an error if there is no value
-                break
+        fullarg = arg = args[pos]
+        equals = arg.find('=')
+        if equals > -1:
+            arg = arg[:equals]
+        if arg in aliases:
             del args[pos]
-            values.append(args.pop(pos))
-            argcount -= 2
-        elif args[pos][:2] in shortopts:
+            if equals > -1:
+                values.append(fullarg[equals + 1:])
+                argcount -= 1
+            else:
+                if pos + 1 >= argcount:
+                    # ignore and let getopt report an error if there is no value
+                    break
+                values.append(args.pop(pos))
+                argcount -= 2
+        elif arg[:2] in shortopts:
             # short option can have no following space, e.g. hg log -Rfoo
             values.append(args.pop(pos)[2:])
             argcount -= 1