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

Re: [PATCH 2/3] var: remove read_var

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 25, 2022, 05:48 UTC
Message-ID
<xmqqo7sveg8o.fsf@gitster.g>
In-Reply-To
<905b109b458e291da04d9879cbc6b032bbd9a302.1669321369.git.gitgitgadget@gmail.com>
"Sean Allred via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 6 quoted lines
> From: Sean Allred <allred.sean@gmail.com>
>
> With our target git_var value now available, we no longer need to call
> into read_var() to find its read() function again. This does avoid a
> second loop through git_vars, but mostly it just removes a lot of
> duplicated logic.

If I were doing this series, I would probably have written a single patch for the steps 1 & 2 from the beginning. That way, reviewers can clearly see what the differences in behaviour between get_git_var() and read_var() in that patch to see that the single step is a strict improvement.

Other than that, both patches 1 & 2 look good.
Thanks.
Show 38 quoted lines
> Signed-off-by: Sean Allred <allred.sean@gmail.com>
> ---
>  builtin/var.c | 16 +---------------
>  1 file changed, 1 insertion(+), 15 deletions(-)
>
> diff --git a/builtin/var.c b/builtin/var.c
> index 776f1778ae1..e215cd3b0c0 100644
> --- a/builtin/var.c
> +++ b/builtin/var.c
> @@ -67,20 +67,6 @@ static const struct git_var *get_git_var(const char *var)
>  	return NULL;
>  }
>  
> -static const char *read_var(const char *var)
> -{
> -	struct git_var *ptr;
> -	const char *val;
> -	val = NULL;
> -	for (ptr = git_vars; ptr->read; ptr++) {
> -		if (strcmp(var, ptr->name) == 0) {
> -			val = ptr->read(IDENT_STRICT);
> -			break;
> -		}
> -	}
> -	return val;
> -}
> -
>  static int show_config(const char *var, const char *value, void *cb)
>  {
>  	if (value)
> @@ -108,7 +94,7 @@ int cmd_var(int argc, const char **argv, const char *prefix)
>  	if (!git_var)
>  		usage(var_usage);
>  
> -	val = read_var(argv[1]);
> +	val = git_var->read(IDENT_STRICT);
>  	if (!val)
>  		return 1;
Previous: Sean Allred via GitGitGadgetNext: Sean Allred via GitGitGadget
Message 4 of 15 in “Improve consistency of git-var”
  1. 0/3 Improve consistency of git-varSean Allred via GitGitGadget, Nov 24, 2022
  2. 1/3 var: do not print usage() with a correct invocationSean Allred via GitGitGadget, Nov 24, 2022
  3. 2/3 var: remove read_varSean Allred via GitGitGadget, Nov 24, 2022
  4. Junio C HamanoNov 25, 2022
  5. 3/3 var: allow GIT_EDITOR to return nullSean Allred via GitGitGadget, Nov 24, 2022
  6. 0/2 Improve consistency of git-varSean Allred via GitGitGadget, Nov 25, 2022
  7. 1/2 var: do not print usage() with a correct invocationSean Allred via GitGitGadget, Nov 25, 2022
  8. Ævar Arnfjörð BjarmasonNov 25, 2022
  9. Sean AllredNov 26, 2022
  10. 2/2 var: allow GIT_EDITOR to return nullSean Allred via GitGitGadget, Nov 25, 2022
  11. Ævar Arnfjörð BjarmasonNov 25, 2022
  12. Sean AllredNov 26, 2022
  13. 0/2 Improve consistency of git-varSean Allred via GitGitGadget, Nov 26, 2022
  14. 1/2 var: do not print usage() with a correct invocationSean Allred via GitGitGadget, Nov 26, 2022
  15. 2/2 var: allow GIT_EDITOR to return nullSean Allred via GitGitGadget, Nov 26, 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.