git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/3] Revert "parse-options: allow keep-unknown + stop-at-non-opt combination"

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jan 22, 2019, 00:30 UTC
Message-ID
<20190122003020.9672-2-pclouds@gmail.com>
In-Reply-To
<20190122003020.9672-1-pclouds@gmail.com>

This reverts commit a85e5a01080e35da0f94bf98f5f334c64e214ce3, which is a revert of 0d260f9a09 (parseopt: prevent KEEP_UNKNOWN and STOP_AT_NON_OPTION from being used together - 2009-03-09).

As described in 0d260f9a09, this option combination is tricky to get right and should be prevented unless you know what you're doing. In the one-shot mode, the diff and revision parsers are very well aware of remaining arguments being potentially unknown options or revisions and should handle the combination safely.

Reinstate the check added by 0d260f9a09. Modify it a bit to let one-shot mode through.

Noticed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 parse-options.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/parse-options.c b/parse-options.c
index a0ff8ea225..cec74522e5 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -466,6 +466,10 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,
 	ctx->prefix = prefix;
 	ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0);
 	ctx->flags = flags;
+	if ((flags & PARSE_OPT_KEEP_UNKNOWN) &&
+	    (flags & PARSE_OPT_STOP_AT_NON_OPTION) &&
+	    !(flags & PARSE_OPT_ONE_SHOT))
+		BUG("STOP_AT_NON_OPTION and KEEP_UNKNOWN don't go together");
 	if ((flags & PARSE_OPT_ONE_SHOT) &&
 	    (flags & PARSE_OPT_KEEP_ARGV0))
 		BUG("Can't keep argv0 if you don't have it");
-- 
2.20.1.560.g70ca8b83ee
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 8 of 10 in “nd/diff-parseopt fixups”
  1. 0/3 nd/diff-parseopt fixupsNguyễn Thái Ngọc Duy, Jan 22, 2019
  2. 1/3 Revert "parse-options: allow keep-unknown + stop-at-non-opt combination"Nguyễn Thái Ngọc Duy, Jan 22, 2019
  3. 3/3 diff.c: simplify diff_opt_break_rewrites()Nguyễn Thái Ngọc Duy, Jan 22, 2019
  4. Junio C HamanoJan 22, 2019
  5. Junio C HamanoJan 22, 2019
  6. 2/3 diff.c: delete unused functionsNguyễn Thái Ngọc Duy, Jan 22, 2019
  7. 0/3 nd/diff-parseopt fixupsNguyễn Thái Ngọc Duy, Jan 22, 2019
  8. 1/3 Revert "parse-options: allow keep-unknown + stop-at-non-opt combination"Nguyễn Thái Ngọc Duy, Jan 22, 2019
  9. 2/3 diff.c: delete unused functionsNguyễn Thái Ngọc Duy, Jan 22, 2019
  10. 3/3 diff.c: simplify diff_opt_break_rewrites()Nguyễn Thái Ngọc Duy, Jan 22, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.