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

Re: [PATCH 03/10] run-command API: add and use a run_command_l_opt()

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 14, 2022, 18:40 UTC
Message-ID
<xmqqtu468d0k.fsf@gitster.g>
In-Reply-To
<patch-03.10-fd81d44f221-20221014T153426Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 13 quoted lines
>  bisect.c                 | 19 +++++++++----------
>  builtin/clone.c          | 16 ++++++----------
>  builtin/difftool.c       | 14 ++++++--------
>  builtin/gc.c             | 22 ++++++++--------------
>  builtin/merge.c          | 35 ++++++-----------------------------
>  builtin/remote.c         | 10 ++++------
>  compat/mingw.c           |  8 +++-----
>  ll-merge.c               |  4 +---
>  run-command.c            | 15 +++++++++++++++
>  run-command.h            | 13 +++++++++++--
>  sequencer.c              |  4 +---
>  t/helper/test-fake-ssh.c |  4 +---
>  12 files changed, 71 insertions(+), 93 deletions(-)
Nice.
Show 5 quoted lines
> @@ -862,11 +858,11 @@ static void write_refspec_config(const char *src_ref_prefix,
>  
>  static void dissociate_from_references(void)
>  {
> -	static const char* argv[] = { "repack", "-a", "-d", NULL };
Good to see that this one in a wrong scope can now go away.
Show 7 quoted lines
>  	char *alternates = git_pathdup("objects/info/alternates");
>  
>  	if (!access(alternates, F_OK)) {
> -		if (run_command_v_opt(argv, RUN_GIT_CMD|RUN_COMMAND_NO_STDIN))
> +		if (run_command_l_opt(RUN_GIT_CMD|RUN_COMMAND_NO_STDIN,
> +				      "repack",  "-a", "-d", NULL))
>  			die(_("cannot repack to clean up"));
Show 22 quoted lines
> diff --git a/builtin/remote.c b/builtin/remote.c
> index 910f7b9316a..1d86c14297b 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -92,13 +92,11 @@ static int verbose;
>  
>  static int fetch_remote(const char *name)
>  {
> -	const char *argv[] = { "fetch", name, NULL, NULL };
> -	if (verbose) {
> -		argv[1] = "-v";
> -		argv[2] = name;
> -	}
>  	printf_ln(_("Updating %s"), name);
> -	if (run_command_v_opt(argv, RUN_GIT_CMD))
> +	if (verbose && run_command_l_opt(RUN_GIT_CMD, "-v", "fetch", name,
> +					 NULL))
> +		return error(_("Could not fetch %s"), name);
> +	else if (run_command_l_opt(RUN_GIT_CMD, "fetch", name, NULL))
>  		return error(_("Could not fetch %s"), name);
>  	return 0;
>  }

This, together with the "merge" one that used to be conditional (which I take as a sign that new callers can legitimately wish it to be conditional again), is where the new l_opt() variant is weak.

And the above is wrong. If verbose option is given and run command succeeds in running "fetch -v" (another bug is that the updated code is running "git -v fetch <name>"), we will try running "fetch" without "-v" option after that.

So, for simplest things (i.e. the majority of places this patch touches), addition of l_opt() is great. Use of it for nontrivial things like this is not. We need to repeat ourselves, and the use of API is error prone.

Show 9 quoted lines
> diff --git a/compat/mingw.c b/compat/mingw.c
> index 901375d5841..4f5392c5796 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -196,17 +196,15 @@ static int read_yes_no_answer(void)
>  static int ask_yes_no_if_possible(const char *format, ...)
>  {
>  	char question[4096];
> -	const char *retry_hook[] = { NULL, NULL, NULL };
Good to see that this one in a wrong scope can now go away.
Show 16 quoted lines
> +	char *retry_hook;
>  	va_list args;
>  
>  	va_start(args, format);
>  	vsnprintf(question, sizeof(question), format, args);
>  	va_end(args);
>  
> -	if ((retry_hook[0] = mingw_getenv("GIT_ASK_YESNO"))) {
> -		retry_hook[1] = question;
> -		return !run_command_v_opt(retry_hook, 0);
> -	}
> +	if ((retry_hook = mingw_getenv("GIT_ASK_YESNO")))
> +		return !run_command_l_opt(0, retry_hook, question, NULL);
>  
>  	if (!isatty(_fileno(stdin)) || !isatty(_fileno(stderr)))
>  		return 0;
Previous: Ævar Arnfjörð BjarmasonNext: Jeff King
Message 7 of 39 in “run-command API: add run_command_{l,sv}_opt()”
  1. 00/10 run-command API: add run_command_{l,sv}_opt()Ævar Arnfjörð Bjarmason, Oct 14, 2022
  2. 01/10 run-command.c: refactor run_command_*_tr2() to internal helpersÆvar Arnfjörð Bjarmason, Oct 14, 2022
  3. Junio C HamanoOct 14, 2022
  4. 02/10 merge: remove always-the-same "verbose" argumentsÆvar Arnfjörð Bjarmason, Oct 14, 2022
  5. Junio C HamanoOct 14, 2022
  6. 03/10 run-command API: add and use a run_command_l_opt()Ævar Arnfjörð Bjarmason, Oct 14, 2022
  7. Junio C HamanoOct 14, 2022
  8. Jeff KingOct 14, 2022
  9. Junio C HamanoOct 14, 2022
  10. 04/10 am: use run_command_l_opt() for show_patch()Ævar Arnfjörð Bjarmason, Oct 14, 2022
  11. Junio C HamanoOct 14, 2022
  12. 05/10 run-command API docs: clarify & fleshen out run_command_v_opt*() docsÆvar Arnfjörð Bjarmason, Oct 14, 2022
  13. 06/10 run-command API: remove RUN_COMMAND_STDOUT_TO_STDERR flagÆvar Arnfjörð Bjarmason, Oct 14, 2022
  14. 08/10 run-command API & users: remove run_command_v_opt_tr2()Ævar Arnfjörð Bjarmason, Oct 14, 2022
  15. 07/10 run-command API & diff.c: remove run_command_v_opt_cd_env()Ævar Arnfjörð Bjarmason, Oct 14, 2022
  16. 09/10 gc: use strvec_pushf(), avoid redundant strbuf_detach()Ævar Arnfjörð Bjarmason, Oct 14, 2022
  17. 10/10 run-command API: add and use a run_command_sv_opt()Ævar Arnfjörð Bjarmason, Oct 14, 2022
  18. René ScharfeOct 14, 2022
  19. 00/10 run-command API: add run_command_{l,sv}_opt()Ævar Arnfjörð Bjarmason, Oct 17, 2022
  20. 01/10 run-command.c: refactor run_command_*_tr2() to internal helpersÆvar Arnfjörð Bjarmason, Oct 17, 2022
  21. 02/10 merge: remove always-the-same "verbose" argumentsÆvar Arnfjörð Bjarmason, Oct 17, 2022
  22. 04/10 am: use run_command_l_opt() for show_patch()Ævar Arnfjörð Bjarmason, Oct 17, 2022
  23. 03/10 run-command API: add and use a run_command_l_opt()Ævar Arnfjörð Bjarmason, Oct 17, 2022
  24. 05/10 run-command API docs: clarify & fleshen out run_command_v_opt*() docsÆvar Arnfjörð Bjarmason, Oct 17, 2022
  25. 06/10 run-command API: remove RUN_COMMAND_STDOUT_TO_STDERR flagÆvar Arnfjörð Bjarmason, Oct 17, 2022
  26. 07/10 run-command API & diff.c: remove run_command_v_opt_cd_env()Ævar Arnfjörð Bjarmason, Oct 17, 2022
  27. 08/10 run-command API & users: remove run_command_v_opt_tr2()Ævar Arnfjörð Bjarmason, Oct 17, 2022
  28. 10/10 run-command API: add and use a run_command_sv_opt()Ævar Arnfjörð Bjarmason, Oct 17, 2022
  29. 09/10 gc: use strvec_pushf(), avoid redundant strbuf_detach()Ævar Arnfjörð Bjarmason, Oct 17, 2022
  30. Junio C HamanoOct 18, 2022
  31. Ævar Arnfjörð BjarmasonOct 18, 2022
  32. Jeff KingOct 18, 2022
  33. Junio C HamanoOct 19, 2022
  34. Jeff KingOct 19, 2022
  35. Junio C HamanoOct 19, 2022
  36. Jeff KingOct 19, 2022
  37. Junio C HamanoOct 19, 2022
  38. René ScharfeOct 20, 2022
  39. Junio C HamanoOct 20, 2022

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.