Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
Cc: git@vger.kernel.org,  christian.couder@gmail.com,
	 toon@iotcl.com, jn.avila@free.fr
Subject: Re: [PATCH 2/2] builtin/add: use die_for_required_opt() helper
Date: Mon, 08 Jun 2026 10:00:09 -0700	[thread overview]
Message-ID: <xmqqecihvug6.fsf@gitster.g> (raw)
In-Reply-To: <20260603111044.39116-3-r.siddharth.shrimali@gmail.com> (Siddharth Shrimali's message of "Wed, 3 Jun 2026 16:40:44 +0530")

Siddharth Shrimali <r.siddharth.shrimali@gmail.com> writes:

> -	if (!show_only && ignore_missing)
> -		die(_("the option '%s' requires '%s'"), "--ignore-missing", "--dry-run");
> +	die_for_required_opt(ignore_missing, "--ignore-missing", show_only, "--dry-run");

As builtin_add_options[] knows that ignore_missing (variable) comes
from the use of "--ignore-missing" (option), and similarly the value
of show_only (variable) is tightly linked to "--dry-run" (option),
it feels quite wasteful having to pass both.

I wonder if we can do this more declaratively, perhaps by
introducing extra types of elements in struct option[] that tells
"--ignore-missing" requires "--dry-run", so that the client code
does not have to do anything more than calling parse_options() to
implement this?

A possible counter-argument may be that the value of, say,
ignore_missing may be different at this point in the code from what
was set by parse_options() when the command line was processed, but
then it means that the message (with or without your patch) is
misleading, so I am not sure if that counter-argument is valid.

>  	if (chmod_arg && ((chmod_arg[0] != '-' && chmod_arg[0] != '+') ||
>  			  chmod_arg[1] != 'x' || chmod_arg[2]))
> @@ -462,6 +461,8 @@ int cmd_add(int argc,
>  		       PATHSPEC_SYMLINK_LEADING_PATH,
>  		       prefix, argv);
>  
> +	die_for_required_opt(pathspec_file_nul, "--pathspec-file-nul",
> +				!!pathspec_from_file, "--pathspec-from-file");
>  	if (pathspec_from_file) {
>  		if (pathspec.nr)
>  			die(_("'%s' and pathspec arguments cannot be used together"), "--pathspec-from-file");
> @@ -470,8 +471,6 @@ int cmd_add(int argc,
>  				    PATHSPEC_PREFER_FULL |
>  				    PATHSPEC_SYMLINK_LEADING_PATH,
>  				    prefix, pathspec_from_file, pathspec_file_nul);
> -	} else if (pathspec_file_nul) {
> -		die(_("the option '%s' requires '%s'"), "--pathspec-file-nul", "--pathspec-from-file");
>  	}
>  
>  	if (require_pathspec && pathspec.nr == 0) {

  parent reply	other threads:[~2026-06-08 17:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03 11:10 [PATCH 0/2] parse-options: introduce die_for_required_opt() helper Siddharth Shrimali
2026-06-03 11:10 ` [PATCH 1/2] parse-options: introduce die_for_required_opt() Siddharth Shrimali
2026-06-03 19:48   ` Jean-Noël AVILA
2026-06-04  8:00     ` Christian Couder
2026-06-04  8:10   ` Christian Couder
2026-06-03 11:10 ` [PATCH 2/2] builtin/add: use die_for_required_opt() helper Siddharth Shrimali
2026-06-04  8:27   ` Christian Couder
2026-06-08 17:00   ` Junio C Hamano [this message]
2026-06-04  7:45 ` [PATCH 0/2] parse-options: introduce " Christian Couder
2026-06-08 12:44 ` [PATCH v2] parse-options: introduce die_for_missing_opt() Siddharth Shrimali

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=xmqqecihvug6.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jn.avila@free.fr \
    --cc=r.siddharth.shrimali@gmail.com \
    --cc=toon@iotcl.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox