# HG changeset patch # User Yuya Nishihara # Date 2017-11-11 05:02:41 # 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 --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -55,6 +55,9 @@ class request(object): 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 @@ def _earlyreqoptbool(req, name, aliases) >>> 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 @@ def _dispatch(req): 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 --git a/tests/test-dispatch.t b/tests/test-dispatch.t --- a/tests/test-dispatch.t +++ b/tests/test-dispatch.t @@ -51,6 +51,12 @@ Parsing of early options should stop at --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