Patchwork [5,of,4,STABLE] dispatch: fix early parsing of short option with value like -R=foo

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 13, 2017, 3:43 p.m.
Message ID <6bccada86df7f70c24f2.1510587826@mimosa>
Download mbox | patch
Permalink /patch/25530/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 13, 2017, 3:43 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1510586759 -32400
#      Tue Nov 14 00:25:59 2017 +0900
# Branch stable
# Node ID 6bccada86df7f70c24f2e62bedf9bfb5d796cbd1
# Parent  a8d8c3229692d77881a6242329160803cb5ab8c5
dispatch: fix early parsing of short option with value like -R=foo

Before, -R=foo was parsed as '-R' 'foo', which disagrees with the standard
getopt behavior.
Augie Fackler - Nov. 13, 2017, 11:12 p.m.
On Tue, Nov 14, 2017 at 12:43:46AM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1510586759 -32400
> #      Tue Nov 14 00:25:59 2017 +0900
> # Branch stable
> # Node ID 6bccada86df7f70c24f2e62bedf9bfb5d796cbd1
> # Parent  a8d8c3229692d77881a6242329160803cb5ab8c5
> dispatch: fix early parsing of short option with value like -R=foo

queued for stable, thanks

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -665,6 +665,10 @@  def _earlygetopt(aliases, args):
     >>> _earlygetopt([b'-R'], args), args
     (['bar'], ['x', 'y'])
 
+    >>> args = [b'x', b'-R=bar', b'y']
+    >>> _earlygetopt([b'-R'], args), args
+    (['=bar'], ['x', 'y'])
+
     >>> args = [b'x', b'-R', b'--', b'y']
     >>> _earlygetopt([b'-R'], args), args
     ([], ['x', '-R', '--', 'y'])
@@ -678,7 +682,9 @@  def _earlygetopt(aliases, args):
     pos = 0
     while pos < argcount:
         fullarg = arg = args[pos]
-        equals = arg.find('=')
+        equals = -1
+        if arg.startswith('--'):
+            equals = arg.find('=')
         if equals > -1:
             arg = arg[:equals]
         if arg in aliases: