# HG changeset patch # User Yuya Nishihara # Date 1510376561 -32400 # Node ID d9aba3730d30ca8c174d8b8d2ed917e4577494d0 # Parent e16f68c4abe33751568bafc8239566edca31867b 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. diff -r e16f68c4abe3 -r d9aba3730d30 mercurial/dispatch.py --- a/mercurial/dispatch.py Fri Nov 10 22:27:26 2017 +0900 +++ b/mercurial/dispatch.py Sat Nov 11 14:02:41 2017 +0900 @@ -55,6 +55,9 @@ self.fout = fout self.ferr = ferr + # remember options pre-parsed by _earlyreqopt*() + self.earlyoptions = {} + # reposetups which run before extensions, useful for chg to pre-fill # low-level repo state (for example, changelog) before extensions. self.prereposetups = prereposetups or [] @@ -707,19 +710,19 @@ >>> req = request([b'x', b'--', b'--debugger']) >>> _earlyreqoptbool(req, b'debugger', [b'--debugger']) - False """ try: argcount = req.args.index("--") except ValueError: argcount = len(req.args) - value = False + value = None pos = 0 while pos < argcount: arg = req.args[pos] if arg in aliases: value = True pos += 1 + req.earlyoptions[name] = value return value def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions): @@ -849,6 +852,9 @@ raise error.Abort(_( "option -R has to be separated from other options (e.g. not " "-qR) and --repository may only be abbreviated as --repo!")) + if options["debugger"] != req.earlyoptions["debugger"]: + raise error.Abort(_("option --debugger may not be abbreviated!")) + # don't validate --profile/--traceback, which can be enabled from now if options["encoding"]: encoding.encoding = options["encoding"] diff -r e16f68c4abe3 -r d9aba3730d30 tests/test-dispatch.t --- a/tests/test-dispatch.t Fri Nov 10 22:27:26 2017 +0900 +++ b/tests/test-dispatch.t Sat Nov 11 14:02:41 2017 +0900 @@ -51,6 +51,12 @@ --debugger: no such file in rev cb9a9f314b8b [1] +Unparsable form of early options: + + $ hg cat --debugg + abort: option --debugger may not be abbreviated! + [255] + [defaults] $ hg cat a