Git development
 help / color / mirror / Atom feed
From: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
To: Christian Couder <christian.couder@gmail.com>, git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Patrick Steinhardt <ps@pks.im>, Elijah Newren <newren@gmail.com>,
	Jeff King <peff@peff.net>,
	"brian m . carlson" <sandals@crustytoothpaste.net>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Justin Tobler <jltobler@gmail.com>
Subject: Re: [PATCH v3 3/4] parse-options: add early_scan_options()
Date: Sat, 31 Oct 2026 02:57:27 +0530	[thread overview]
Message-ID: <6782fa63-1e46-4ae9-b129-a157986c2556@gmail.com> (raw)
In-Reply-To: <20261012074413.337183-4-christian.couder@gmail.com>

On 10/12/26 13:14, Christian Couder wrote:
> diff --git a/parse-options.c b/parse-options.c
> index a98b958423..c03c396aa6 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -726,6 +726,8 @@ static void parse_options_check(const struct option *opts)
>   		     opts->long_name))
>   			optbug(opts, "uses feature "
>   			       "not supported for dashless options");
> +		if ((opts->flags & PARSE_OPT_EARLY) && !opts->long_name)
> +			optbug(opts, "uses PARSE_OPT_EARLY, which needs a long name");
>   		if (opts->type == OPTION_SET_INT && !opts->defval &&
>   		    opts->long_name && !(opts->flags & PARSE_OPT_NONEG))
>   			optbug(opts, "OPTION_SET_INT 0 should not be negatable");
> @@ -763,6 +765,8 @@ static void parse_options_check(const struct option *opts)
>   		case OPTION_SUBCOMMAND:
>   			if (!opts->value || !opts->subcommand_fn)
>   				optbug(opts, "OPTION_SUBCOMMAND needs a value and a subcommand function");
> +			if (opts->flags & PARSE_OPT_EARLY)
> +				optbug(opts, "OPTION_SUBCOMMAND does not support PARSE_OPT_EARLY");
>   			if (!subcommand_value)
>   				subcommand_value = opts->value;
>   			else if (subcommand_value != opts->value)

Would it make sense to also have these validations within 
early_scan_options() just in case it is called before 
parse_options_start() is invoked?
   > diff --git a/parse-options.h b/parse-options.h
> index 589f8d9008..f39b9a779a 100644
> --- a/parse-options.h
> +++ b/parse-options.h
> @@ -51,6 +51,7 @@ enum parse_opt_option_flags {
>   	PARSE_OPT_NODASH = 1 << 5,
>   	PARSE_OPT_LITERAL_ARGHELP = 1 << 6,
>   	PARSE_OPT_FROM_ALIAS = 1 << 7,
> +	PARSE_OPT_EARLY = 1 << 8,	/* only for early_scan_options() */
>   	PARSE_OPT_NOCOMPLETE = 1 << 9,
>   	PARSE_OPT_COMP_ARG = 1 << 10,
>   	PARSE_OPT_CMDMODE = 1 << 11,
> @@ -502,6 +503,96 @@ static inline void die_for_incompatible_opt2(int opt1, const char *opt1_name,
>   		BUG("option callback expects an argument"); \
>   } while(0)
>   
> +/*----- Early scan: scanning argv before the actual option parsing -----*/
> +
> +/*
> + * Some commands need to look at a few options before they can parse
> + * their command line for real, for example because the result decides
> + * whether a repository is needed at all.
> + *
> + * Such an early scan has to know which options take their value as a
> + * separate argument, or it could mistake such a value for an
> + * option. The functions below allow performing such early scans
> + * without being fooled by option values.
> + */
> +
> +/*
> + * Called by early_scan_options() for each argument matching a
> + * `struct option` with PARSE_OPT_EARLY set.
> + *
> + * - `option` is the matching option,

Would it be helpful to also convey here that the caller is not expected 
to retain the pointer as the memory pointing to it would be freed once 
the scan completes?

Rest of the patch looks fine to me.

-- 
Sivaraam


  reply	other threads:[~2026-10-30 21:27 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 16:10 [PATCH 0/6] Standardize early option scanning to fix argument parsing bugs Christian Couder
2026-09-02 16:10 ` [PATCH 1/6] parse-options: add early_scan_options() Christian Couder
2026-09-02 22:11   ` Junio C Hamano
2026-09-23  8:10     ` Christian Couder
2026-09-23 17:25       ` Junio C Hamano
2026-09-02 16:10 ` [PATCH 2/6] bisect: fix "--" detection when a term name is "--" Christian Couder
2026-09-02 22:30   ` Junio C Hamano
2026-09-23  8:11     ` Christian Couder
2026-09-23 17:27       ` Junio C Hamano
2026-09-02 16:10 ` [PATCH 3/6] rev-parse: fix "--" detection when it is an option value Christian Couder
2026-09-02 16:10 ` [PATCH 4/6] parse-options: add parse_options_takes_argument() Christian Couder
2026-09-02 16:10 ` [PATCH 5/6] parse-options: build early scan options from a struct option array Christian Couder
2026-09-02 16:10 ` [PATCH 6/6] fast-import: use early_scan_options() for --allow-unsafe-features Christian Couder
2026-09-04  3:38   ` Junio C Hamano
2026-09-02 18:52 ` [PATCH 0/6] Standardize early option scanning to fix argument parsing bugs Junio C Hamano
2026-09-23  8:10   ` Christian Couder
2026-09-23  8:09 ` [PATCH v2 0/3] Standardize early option scanning Christian Couder
2026-09-23  8:09   ` [PATCH v2 1/3] parse-options: add parse_options_takes_argument() Christian Couder
2026-09-23  8:09   ` [PATCH v2 2/3] parse-options: add early_scan_options() Christian Couder
2026-09-30  7:13     ` Kaartic Sivaraam
2026-10-12  8:10       ` Christian Couder
2026-09-23  8:09   ` [PATCH v2 3/3] fast-import: use early_scan_options() for --allow-unsafe-features Christian Couder
2026-10-12  7:44   ` [PATCH v3 0/4] Standardize early option scanning Christian Couder
2026-10-12  7:44     ` [PATCH v3 1/4] parse-options: add parse_options_takes_argument() Christian Couder
2026-10-12  7:44     ` [PATCH v3 2/4] parse-options: extract lookup_long_opt() from parse_long_opt() Christian Couder
2026-10-30 21:08       ` Kaartic Sivaraam
2026-10-12  7:44     ` [PATCH v3 3/4] parse-options: add early_scan_options() Christian Couder
2026-10-30 21:27       ` Kaartic Sivaraam [this message]
2026-10-12  7:44     ` [PATCH v3 4/4] fast-import: use early_scan_options() for --allow-unsafe-features Christian Couder

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

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

  git send-email \
    --in-reply-to=6782fa63-1e46-4ae9-b129-a157986c2556@gmail.com \
    --to=kaartic.sivaraam@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jltobler@gmail.com \
    --cc=newren@gmail.com \
    --cc=peff@peff.net \
    --cc=ps@pks.im \
    --cc=sandals@crustytoothpaste.net \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox