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

login
register
mail settings
Submitter Bryan O'Sullivan
Date April 29, 2013, 9:15 p.m.
Message ID <8e74ab770b1460e5d2cd.1367270101@australite.local>
Download mbox | patch
Permalink /patch/1500/
State Accepted
Commit fc081623f4bd918e384b47231707a4ee71dc1ccf
Headers show

Comments

Bryan O'Sullivan - April 29, 2013, 9:15 p.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@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!
Matt Mackall - April 30, 2013, 7:54 p.m.
On Mon, 2013-04-29 at 14:15 -0700, Bryan O'Sullivan wrote:
> # HG changeset patch
> # User Bryan O'Sullivan <bryano@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

These are queue for stable, thanks.

Patch

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