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

From: Junio C Hamano <[email-masked]>
Date: Fri, 25 Nov 2022 14:48:55 +0900

"Sean Allred via GitGitGadget" <[email-masked]> writes:

> From: Sean Allred <[email-masked]>
>
> 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.

> Signed-off-by: Sean Allred <[email-masked]>
> ---
>  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;