# HG changeset patch # User Yuya Nishihara # Date 1511598650 -32400 # Node ID 98a5aa5575e73c7b13507ed8210c5ce654b688ec # Parent 5b569d512fbd7422de3f53f3a8a4acfd70ab2a30 fancyopts: fix handling of "--" value in earlygetopt() diff -r 5b569d512fbd -r 98a5aa5575e7 mercurial/fancyopts.py --- a/mercurial/fancyopts.py Fri Nov 24 01:09:00 2017 +0900 +++ b/mercurial/fancyopts.py Sat Nov 25 17:30:50 2017 +0900 @@ -119,7 +119,7 @@ >>> get([b'--cwd=foo', b'x', b'y', b'-R', b'bar', b'--debugger'], gnu=False) ([('--cwd', 'foo')], ['x', 'y', '-R', 'bar', '--debugger']) >>> get([b'--unknown', b'--cwd=foo', b'--', '--debugger'], gnu=False) - ([], ['--unknown', '--cwd=foo', '--debugger']) + ([], ['--unknown', '--cwd=foo', '--', '--debugger']) stripping early options (without loosing '--'): @@ -141,6 +141,13 @@ >>> get([b'-q', b'--']) ([('-q', '')], []) + '--' may be a value: + + >>> get([b'-R', b'--', b'x']) + ([('-R', '--')], ['x']) + >>> get([b'--cwd', b'--', b'x']) + ([('--cwd', '--')], ['x']) + value passed to bool options: >>> get([b'--debugger=foo', b'x']) @@ -163,20 +170,16 @@ >>> get([b'-', b'y']) ([], ['-', 'y']) """ - # ignoring everything just after '--' isn't correct as '--' may be an - # option value (e.g. ['-R', '--']), but we do that consistently. - try: - argcount = args.index('--') - except ValueError: - argcount = len(args) - parsedopts = [] parsedargs = [] pos = 0 - while pos < argcount: + while pos < len(args): arg = args[pos] + if arg == '--': + pos += not keepsep + break flag, hasval, val, takeval = _earlyoptarg(arg, shortlist, namelist) - if not hasval and takeval and pos + 1 >= argcount: + if not hasval and takeval and pos + 1 >= len(args): # missing last argument break if not flag or hasval and not takeval: @@ -195,8 +198,7 @@ parsedopts.append((flag, args[pos + 1])) pos += 2 - parsedargs.extend(args[pos:argcount]) - parsedargs.extend(args[argcount + (not keepsep):]) + parsedargs.extend(args[pos:]) return parsedopts, parsedargs def fancyopts(args, options, state, gnu=False, early=False, optaliases=None): diff -r 5b569d512fbd -r 98a5aa5575e7 tests/test-dispatch.t --- a/tests/test-dispatch.t Fri Nov 24 01:09:00 2017 +0900 +++ b/tests/test-dispatch.t Sat Nov 25 17:30:50 2017 +0900 @@ -40,10 +40,10 @@ "--" may be an option value: $ hg -R -- log - abort: option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo! + abort: repository -- not found! [255] $ hg log -R -- - abort: option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo! + abort: repository -- not found! [255] $ hg log -T -- -- (no-eol)