changeset 35029:e16f68c4abe3 stable

dispatch: stop parsing of early boolean option at "--"
author Yuya Nishihara <yuya@tcha.org>
date Fri, 10 Nov 2017 22:27:26 +0900
parents 7f8f9f0369ca
children d9aba3730d30
files mercurial/dispatch.py tests/test-dispatch.t
diffstat 2 files changed, 31 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dispatch.py	Fri Nov 10 22:22:39 2017 +0900
+++ b/mercurial/dispatch.py	Fri Nov 10 22:27:26 2017 +0900
@@ -699,8 +699,28 @@
     return values
 
 def _earlyreqoptbool(req, name, aliases):
-    assert len(aliases) == 1
-    return aliases[0] in req.args
+    """Peek a boolean option without using a full options table
+
+    >>> req = request([b'x', b'--debugger'])
+    >>> _earlyreqoptbool(req, b'debugger', [b'--debugger'])
+    True
+
+    >>> 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
+    pos = 0
+    while pos < argcount:
+        arg = req.args[pos]
+        if arg in aliases:
+            value = True
+        pos += 1
+    return value
 
 def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions):
     # run pre-hook, and abort if it fails
--- a/tests/test-dispatch.t	Fri Nov 10 22:22:39 2017 +0900
+++ b/tests/test-dispatch.t	Fri Nov 10 22:27:26 2017 +0900
@@ -42,6 +42,15 @@
   hg log [OPTION]... [FILE]
   (use 'hg log -h' to show more help)
 
+Parsing of early options should stop at "--":
+
+  $ hg cat -- --config=hooks.pre-cat=false
+  --config=hooks.pre-cat=false: no such file in rev cb9a9f314b8b
+  [1]
+  $ hg cat -- --debugger
+  --debugger: no such file in rev cb9a9f314b8b
+  [1]
+
 [defaults]
 
   $ hg cat a