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

Yuya Nishihara yuya at tcha.org
Mon Nov 13 10:43:46 EST 2017


# HG changeset patch
# User Yuya Nishihara <yuya at 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.

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:


More information about the Mercurial-devel mailing list