[PATCH 1 of 5 STABLE RFC] dispatch: add option to not strip command args parsed by _earlygetopt()
Yuya Nishihara
yuya at tcha.org
Wed Nov 15 12:54:20 UTC 2017
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1510386401 -32400
# Sat Nov 11 16:46:41 2017 +0900
# Branch stable
# Node ID 169d9434332be406ab1ba83af4a5f9a29cca3823
# Parent 6bccada86df7f70c24f2e62bedf9bfb5d796cbd1
dispatch: add option to not strip command args parsed by _earlygetopt()
This allows us to parse the original args later by full-blown getopt() in
order to verify the result of the faulty early parsing. Still we need the
'strip=True' behavior for shell aliases.
Note that this series is RFC because it seems to change too much to be
included in stable release.
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -643,11 +643,11 @@ def _parseconfig(ui, config):
return configs
-def _earlygetopt(aliases, args):
+def _earlygetopt(aliases, args, strip=True):
"""Return list of values for an option (or aliases).
The values are listed in the order they appear in args.
- The options and values are removed from args.
+ The options and values are removed from args if strip=True.
>>> args = [b'x', b'--cwd', b'foo', b'y']
>>> _earlygetopt([b'--cwd'], args), args
@@ -657,14 +657,26 @@ def _earlygetopt(aliases, args):
>>> _earlygetopt([b'--cwd'], args), args
(['bar'], ['x', 'y'])
+ >>> args = [b'x', b'--cwd=bar', b'y']
+ >>> _earlygetopt([b'--cwd'], args, strip=False), args
+ (['bar'], ['x', '--cwd=bar', 'y'])
+
>>> args = [b'x', b'-R', b'foo', b'y']
>>> _earlygetopt([b'-R'], args), args
(['foo'], ['x', 'y'])
+ >>> args = [b'x', b'-R', b'foo', b'y']
+ >>> _earlygetopt([b'-R'], args, strip=False), args
+ (['foo'], ['x', '-R', 'foo', 'y'])
+
>>> args = [b'x', b'-Rbar', b'y']
>>> _earlygetopt([b'-R'], args), args
(['bar'], ['x', 'y'])
+ >>> args = [b'x', b'-Rbar', b'y']
+ >>> _earlygetopt([b'-R'], args, strip=False), args
+ (['bar'], ['x', '-Rbar', 'y'])
+
>>> args = [b'x', b'-R=bar', b'y']
>>> _earlygetopt([b'-R'], args), args
(['=bar'], ['x', 'y'])
@@ -689,20 +701,30 @@ def _earlygetopt(aliases, args):
arg = arg[:equals]
if arg in aliases:
if equals > -1:
- del args[pos]
values.append(fullarg[equals + 1:])
- argcount -= 1
+ if strip:
+ del args[pos]
+ argcount -= 1
+ else:
+ pos += 1
else:
if pos + 1 >= argcount:
# ignore and let getopt report an error if there is no value
break
- del args[pos]
- values.append(args.pop(pos))
- argcount -= 2
+ values.append(args[pos + 1])
+ if strip:
+ del args[pos:pos + 2]
+ argcount -= 2
+ else:
+ pos += 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
+ values.append(args[pos][2:])
+ if strip:
+ del args[pos]
+ argcount -= 1
+ else:
+ pos += 1
else:
pos += 1
return values
More information about the Mercurial-devel
mailing list