git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Stefan Beller" <sbeller@google.com>,
	"SZEDER Gábor" <szeder.dev@gmail.com>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 1/3] Revert "parse-options: allow keep-unknown + stop-at-non-opt combination"
Date: Tue, 22 Jan 2019 07:30:18 +0700	[thread overview]
Message-ID: <20190122003020.9672-2-pclouds@gmail.com> (raw)
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


  reply	other threads:[~2019-01-22  0:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-22  0:26 [PATCH 0/3] nd/diff-parseopt fixups Nguyễn Thái Ngọc Duy
2019-01-22  0:26 ` [PATCH 1/3] Revert "parse-options: allow keep-unknown + stop-at-non-opt combination" Nguyễn Thái Ngọc Duy
2019-01-22  0:26 ` [PATCH 2/3] diff.c: delete unused functions Nguyễn Thái Ngọc Duy
2019-01-22  0:26 ` [PATCH 3/3] diff.c: simplify diff_opt_break_rewrites() Nguyễn Thái Ngọc Duy
2019-01-22 20:50   ` Junio C Hamano
2019-01-22 23:18     ` Junio C Hamano
2019-01-22  0:30 ` [PATCH v2 0/3] nd/diff-parseopt fixups Nguyễn Thái Ngọc Duy
2019-01-22  0:30   ` Nguyễn Thái Ngọc Duy [this message]
2019-01-22  0:30   ` [PATCH v2 2/3] diff.c: delete unused functions Nguyễn Thái Ngọc Duy
2019-01-22  0:30   ` [PATCH v2 3/3] diff.c: simplify diff_opt_break_rewrites() Nguyễn Thái Ngọc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190122003020.9672-2-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sbeller@google.com \
    --cc=szeder.dev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).