[PATCH 2 of 2 stable] dispatch: add support for --option=value to _earlygetopt

Bryan O'Sullivan bos at serpentine.com
Mon Apr 29 16:15:01 CDT 2013


# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1367270082 25200
#      Mon Apr 29 14:14:42 2013 -0700
# Branch stable
# Node ID 8e74ab770b1460e5d2cdc69b837d06a988e3c220
# Parent  1050604e2c9d34112d3fe4eff58321af0d72e816
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!

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -490,6 +490,10 @@ def _earlygetopt(aliases, args):
     >>> _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 @@ def _earlygetopt(aliases, args):
     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


More information about the Mercurial-devel mailing list