comparison mercurial/dispatch.py @ 35031:e273b6671827 stable

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.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 14 Nov 2017 00:25:59 +0900
parents d9aba3730d30
children cd235d6f851b
comparison
equal deleted inserted replaced
35030:d9aba3730d30 35031:e273b6671827
663 663
664 >>> args = [b'x', b'-Rbar', b'y'] 664 >>> args = [b'x', b'-Rbar', b'y']
665 >>> _earlygetopt([b'-R'], args), args 665 >>> _earlygetopt([b'-R'], args), args
666 (['bar'], ['x', 'y']) 666 (['bar'], ['x', 'y'])
667 667
668 >>> args = [b'x', b'-R=bar', b'y']
669 >>> _earlygetopt([b'-R'], args), args
670 (['=bar'], ['x', 'y'])
671
668 >>> args = [b'x', b'-R', b'--', b'y'] 672 >>> args = [b'x', b'-R', b'--', b'y']
669 >>> _earlygetopt([b'-R'], args), args 673 >>> _earlygetopt([b'-R'], args), args
670 ([], ['x', '-R', '--', 'y']) 674 ([], ['x', '-R', '--', 'y'])
671 """ 675 """
672 try: 676 try:
676 shortopts = [opt for opt in aliases if len(opt) == 2] 680 shortopts = [opt for opt in aliases if len(opt) == 2]
677 values = [] 681 values = []
678 pos = 0 682 pos = 0
679 while pos < argcount: 683 while pos < argcount:
680 fullarg = arg = args[pos] 684 fullarg = arg = args[pos]
681 equals = arg.find('=') 685 equals = -1
686 if arg.startswith('--'):
687 equals = arg.find('=')
682 if equals > -1: 688 if equals > -1:
683 arg = arg[:equals] 689 arg = arg[:equals]
684 if arg in aliases: 690 if arg in aliases:
685 if equals > -1: 691 if equals > -1:
686 del args[pos] 692 del args[pos]