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

Re: [PATCH 02/10] merge: remove always-the-same "verbose" arguments

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 14, 2022, 18:31 UTC
Message-ID
<xmqqzgdy8dfz.fsf@gitster.g>
In-Reply-To
<patch-02.10-543ccbb1ee1-20221014T153426Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 26 quoted lines
> Simplify the code that builds the arguments for the "read-tree"
> invocation in reset_hard() and read_empty() to remove the "verbose"
> parameter.
>
> Before 172b6428d06 (do not overwrite untracked during merge from
> unborn branch, 2010-11-14) there was a "reset_hard()" function that
> would be called in two places, one of those passed a "verbose=1", the
> other a "verbose=0".
>
> After 172b6428d06 when read_empty() was split off from reset_hard()
> both of these functions only had one caller. The "verbose" in
> read_empty() would always be false, and the one in reset_hard() would
> always be true.
>
> There was never a good reason for the code to act this way, it
> happened because the read_empty() function was a copy/pasted and
> adjusted version of reset_hard().
>
> Since we're no longer conditionally adding the "-v" parameter
> here (and we'd only add it for "reset_hard()" we'll be able to move to
> a simpler and safer run-command API in the subsequent commit.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  builtin/merge.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)

I haven't checked the topics in flight that touch the same file, but as these are file-scope static, it is easy to check the correctness, and the change of function signature will mean that compilers will notice after a merge if there is somebody else who still wants them to be conditionally verbose.

I wonder if these were always unused, or we lost different callers over time, though.

Show 56 quoted lines
>
> diff --git a/builtin/merge.c b/builtin/merge.c
> index 5900b81729d..3bb49d805b4 100644
> --- a/builtin/merge.c
> +++ b/builtin/merge.c
> @@ -345,14 +345,12 @@ static int save_state(struct object_id *stash)
>  	return rc;
>  }
>  
> -static void read_empty(const struct object_id *oid, int verbose)
> +static void read_empty(const struct object_id *oid)
>  {
>  	int i = 0;
>  	const char *args[7];
>  
>  	args[i++] = "read-tree";
> -	if (verbose)
> -		args[i++] = "-v";
>  	args[i++] = "-m";
>  	args[i++] = "-u";
>  	args[i++] = empty_tree_oid_hex();
> @@ -363,14 +361,13 @@ static void read_empty(const struct object_id *oid, int verbose)
>  		die(_("read-tree failed"));
>  }
>  
> -static void reset_hard(const struct object_id *oid, int verbose)
> +static void reset_hard(const struct object_id *oid)
>  {
>  	int i = 0;
>  	const char *args[6];
>  
>  	args[i++] = "read-tree";
> -	if (verbose)
> -		args[i++] = "-v";
> +	args[i++] = "-v";
>  	args[i++] = "--reset";
>  	args[i++] = "-u";
>  	args[i++] = oid_to_hex(oid);
> @@ -385,7 +382,7 @@ static void restore_state(const struct object_id *head,
>  {
>  	struct strvec args = STRVEC_INIT;
>  
> -	reset_hard(head, 1);
> +	reset_hard(head);
>  
>  	if (is_null_oid(stash))
>  		goto refresh_cache;
> @@ -1470,7 +1467,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
>  					       check_trust_level);
>  
>  		remote_head_oid = &remoteheads->item->object.oid;
> -		read_empty(remote_head_oid, 0);
> +		read_empty(remote_head_oid);
>  		update_ref("initial pull", "HEAD", remote_head_oid, NULL, 0,
>  			   UPDATE_REFS_DIE_ON_ERR);
>  		goto done;
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 5 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.