All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Edson <edsonwasswa54@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v6] builtin/diff-files: convert ad hoc option parsing to parse-options API
Date: Mon, 02 Nov 2026 02:01:14 -0800	[thread overview]
Message-ID: <xmqq8q3blfh1.fsf@gitster.g> (raw)
In-Reply-To: <20261101192502.1920-1-edsonwasswa54@gmail.com> (Edson's message of "Sun, 1 Nov 2026 22:25:01 +0300")

Edson <edsonwasswa54@gmail.com> writes:

> -static const char diff_files_usage[] =
> -"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]"
> -"\n"
> -COMMON_DIFF_OPTIONS_HELP;
> +static const char * const diff_files_usage[] = {
> +	"git diff-files [-q] [-0 | -1 | -2 | -3 | -c | --cc] [<common-diff-options>] [<path>...]",
> +	NULL
> +};

The loss of COMMON_DIFF_OPTIONS_HELP here gives us a regression in
the help output ("git diff-files -h").  By replacing the single string
with a string array and passing it to parse_options() or
show_usage_with_options_if_asked(), the COMMON_DIFF_OPTIONS_HELP
macro is omitted.

Since parse_options() or show_usage_with_options_if_asked() only
knows about the options explicitly defined in the diff_files_options[]
array (leaving standard diff options to be parsed by
setup_revisions()), the common diff options (like -p, --stat, and -z)
will no longer be documented when the user runs "git diff-files -h".

You probably could shove COMMON_DIFF_OPTIONS_HELP into OPT_GROUP()
or something that produces static text in the help output to avoid
the regression if you really wanted to, but given that "diff-files"
is plumbing meant for use by scripts, I am not sure how much value
we get by rewriting its command-line parsing.  Being able to say
"git diff-files --bas" and get it understood as "--base" is
something we may appreciate if it were a Porcelain command, but is
it worth the hassle for a plumbing?  I have to wonder.

Especially when the parsing loop the patch wants to replace ...

>  	argc = setup_revisions(argc, argv, &rev, NULL);
> -	while (1 < argc && argv[1][0] == '-') {
> -		if (!strcmp(argv[1], "--base"))
> -			rev.max_count = 1;
> -		else if (!strcmp(argv[1], "--ours"))
> -			rev.max_count = 2;
> -		else if (!strcmp(argv[1], "--theirs"))
> -			rev.max_count = 3;
> -		else if (!strcmp(argv[1], "-q"))
> -			options |= DIFF_SILENT_ON_REMOVED;
> -		else
> -			usage(diff_files_usage);
> -		argv++; argc--;
> -	}

... is not anything that is ugly or overly hard to understand.

I dunno.


> +	argc = parse_options(argc, argv, prefix, diff_files_options,
> +			     diff_files_usage, 0);
>  	if (!rev.diffopt.output_format)
>  		rev.diffopt.output_format = DIFF_FORMAT_RAW;
>  	rev.diffopt.rotate_to_strict = 1;
> @@ -73,7 +74,7 @@ int cmd_diff_files(int argc,
>  	if (rev.pending.nr ||
>  	    rev.min_age != -1 || rev.max_age != -1 ||
>  	    3 < rev.max_count)
> -		usage(diff_files_usage);
> +		usage_with_options(diff_files_usage, diff_files_options);
>  
>  	/*
>  	 * "diff-files --base -p" should not combine merges because it

  reply	other threads:[~2026-11-02 10:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261028170432.3524465-1-gitster@pobox.com>
2026-10-28 19:14 ` [PATCH v2] builtin/diff-files: convert ad hoc option parsing to parse-options API Edson
2026-10-28 19:26 ` [PATCH v3] " Edson
2026-10-28 22:24   ` Junio C Hamano
2026-10-29 20:39 ` [PATCH v4] " Edson
2026-10-29 21:40   ` Junio C Hamano
2026-11-01 19:25   ` [PATCH v6] " Edson
2026-11-02 10:01     ` Junio C Hamano [this message]
2026-11-02 14:16       ` Wasswa Edson

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=xmqq8q3blfh1.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=edsonwasswa54@gmail.com \
    --cc=git@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.