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

Re: [PATCH 2/2] builtin/add: use die_for_required_opt() helper

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 8, 2026, 17:00 UTC
Message-ID
<xmqqecihvug6.fsf@gitster.g>
In-Reply-To
<20260603111044.39116-3-r.siddharth.shrimali@gmail.com>
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.

Show 20 quoted lines
>  	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) {
Previous: Christian CouderNext: Christian Couder
Message 8 of 10 in “parse-options: introduce die_for_required_opt() helper”
  1. 0/2 parse-options: introduce die_for_required_opt() helperSiddharth Shrimali, Jun 3, 2026
  2. 1/2 parse-options: introduce die_for_required_opt()Siddharth Shrimali, Jun 3, 2026
  3. Jean-Noël AVILAJun 3, 2026
  4. Christian CouderJun 4, 2026
  5. Christian CouderJun 4, 2026
  6. 2/2 builtin/add: use die_for_required_opt() helperSiddharth Shrimali, Jun 3, 2026
  7. Christian CouderJun 4, 2026
  8. Junio C HamanoJun 8, 2026
  9. Christian CouderJun 4, 2026
  10. parse-options: introduce die_for_missing_opt()Siddharth Shrimali, Jun 8, 2026

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.