Mercurial > public > mercurial-scm > hg
comparison mercurial/dispatch.py @ 35030:d9aba3730d30 stable
dispatch: abort if early boolean options can't be parsed
Perhaps we'll need to restrict the parsing rules of --debugger and --profile,
where this patch will help us know why the --debugger option doesn't work.
I have another series to extend this feature to --config/--cwd/-R, but even
with that, shell aliases can be used to get around the restriction.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 11 Nov 2017 14:02:41 +0900 |
parents | e16f68c4abe3 |
children | e273b6671827 |
comparison
equal
deleted
inserted
replaced
35029:e16f68c4abe3 | 35030:d9aba3730d30 |
---|---|
52 | 52 |
53 # input/output/error streams | 53 # input/output/error streams |
54 self.fin = fin | 54 self.fin = fin |
55 self.fout = fout | 55 self.fout = fout |
56 self.ferr = ferr | 56 self.ferr = ferr |
57 | |
58 # remember options pre-parsed by _earlyreqopt*() | |
59 self.earlyoptions = {} | |
57 | 60 |
58 # reposetups which run before extensions, useful for chg to pre-fill | 61 # reposetups which run before extensions, useful for chg to pre-fill |
59 # low-level repo state (for example, changelog) before extensions. | 62 # low-level repo state (for example, changelog) before extensions. |
60 self.prereposetups = prereposetups or [] | 63 self.prereposetups = prereposetups or [] |
61 | 64 |
705 >>> _earlyreqoptbool(req, b'debugger', [b'--debugger']) | 708 >>> _earlyreqoptbool(req, b'debugger', [b'--debugger']) |
706 True | 709 True |
707 | 710 |
708 >>> req = request([b'x', b'--', b'--debugger']) | 711 >>> req = request([b'x', b'--', b'--debugger']) |
709 >>> _earlyreqoptbool(req, b'debugger', [b'--debugger']) | 712 >>> _earlyreqoptbool(req, b'debugger', [b'--debugger']) |
710 False | |
711 """ | 713 """ |
712 try: | 714 try: |
713 argcount = req.args.index("--") | 715 argcount = req.args.index("--") |
714 except ValueError: | 716 except ValueError: |
715 argcount = len(req.args) | 717 argcount = len(req.args) |
716 value = False | 718 value = None |
717 pos = 0 | 719 pos = 0 |
718 while pos < argcount: | 720 while pos < argcount: |
719 arg = req.args[pos] | 721 arg = req.args[pos] |
720 if arg in aliases: | 722 if arg in aliases: |
721 value = True | 723 value = True |
722 pos += 1 | 724 pos += 1 |
725 req.earlyoptions[name] = value | |
723 return value | 726 return value |
724 | 727 |
725 def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions): | 728 def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions): |
726 # run pre-hook, and abort if it fails | 729 # run pre-hook, and abort if it fails |
727 hook.hook(lui, repo, "pre-%s" % cmd, True, args=" ".join(fullargs), | 730 hook.hook(lui, repo, "pre-%s" % cmd, True, args=" ".join(fullargs), |
847 raise error.Abort(_("option --cwd may not be abbreviated!")) | 850 raise error.Abort(_("option --cwd may not be abbreviated!")) |
848 if options["repository"]: | 851 if options["repository"]: |
849 raise error.Abort(_( | 852 raise error.Abort(_( |
850 "option -R has to be separated from other options (e.g. not " | 853 "option -R has to be separated from other options (e.g. not " |
851 "-qR) and --repository may only be abbreviated as --repo!")) | 854 "-qR) and --repository may only be abbreviated as --repo!")) |
855 if options["debugger"] != req.earlyoptions["debugger"]: | |
856 raise error.Abort(_("option --debugger may not be abbreviated!")) | |
857 # don't validate --profile/--traceback, which can be enabled from now | |
852 | 858 |
853 if options["encoding"]: | 859 if options["encoding"]: |
854 encoding.encoding = options["encoding"] | 860 encoding.encoding = options["encoding"] |
855 if options["encodingmode"]: | 861 if options["encodingmode"]: |
856 encoding.encodingmode = options["encodingmode"] | 862 encoding.encodingmode = options["encodingmode"] |