Patchwork [4,of,4,STABLE] dispatch: abort if early boolean options can't be parsed

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 11, 2017, 3:02 p.m.
Message ID <a8d8c3229692d77881a6.1510412569@mimosa>
Download mbox | patch
Permalink /patch/25486/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 11, 2017, 3:02 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1510376561 -32400
#      Sat Nov 11 14:02:41 2017 +0900
# Branch stable
# Node ID a8d8c3229692d77881a6242329160803cb5ab8c5
# Parent  ed13a7f6d26a28f73593a091a6a57c756678245b
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.
Augie Fackler - Nov. 13, 2017, 11:12 p.m.
On Sun, Nov 12, 2017 at 12:02:49AM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1510376561 -32400
> #      Sat Nov 11 14:02:41 2017 +0900
> # Branch stable
> # Node ID a8d8c3229692d77881a6242329160803cb5ab8c5
> # Parent  ed13a7f6d26a28f73593a091a6a57c756678245b
> dispatch: abort if early boolean options can't be parsed

queued for stable, thanks

Patch

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