# HG changeset patch # User Yuya Nishihara # Date 1510386401 -32400 # Node ID cd235d6f851be4d526fd6fc83410f1308c3688d3 # Parent e273b6671827197c07b0ac99d561bcc6dccf4219 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 @@ 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 @@ >>> _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 @@ 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