[PATCH 3 of 4 STABLE] dispatch: stop parsing of early boolean option at "--"

Yuya Nishihara yuya at tcha.org
Sat Nov 11 10:02:48 EST 2017


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1510320446 -32400
#      Fri Nov 10 22:27:26 2017 +0900
# Branch stable
# Node ID ed13a7f6d26a28f73593a091a6a57c756678245b
# Parent  e8c581ae8e8835cf7fc83e749a84919aea11f63a
dispatch: stop parsing of early boolean option at "--"

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -699,8 +699,28 @@ def _earlygetopt(aliases, args):
     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
diff --git a/tests/test-dispatch.t b/tests/test-dispatch.t
--- a/tests/test-dispatch.t
+++ b/tests/test-dispatch.t
@@ -42,6 +42,15 @@ Missing parameter for early option:
   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


More information about the Mercurial-devel mailing list