Subject: Re: [PATCH 1/4] git: pass in repo for RUN_SETUP_GENTLY

From: Patrick Steinhardt <[email-masked]>
Date: Thu, 26 Sep 2024 16:24:24 +0200

On Tue, Sep 24, 2024 at 01:42:41PM +0000, John Cai via GitGitGadget wrote:
> From: John Cai <[email-masked]>
> 
> commands that have RUN_SETUP_GENTLY potentially need a repository.
> Modify the logic in run_builtin() to pass the repository to the builtin
> if a builtin has the RUN_SETUP_GENTLY property.
> 
> Signed-off-by: John Cai <[email-masked]>
> ---
>  git.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/git.c b/git.c
> index 2fbea24ec92..e31b52dcc50 100644
> --- a/git.c
> +++ b/git.c
> @@ -480,7 +480,10 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
>  	trace2_cmd_name(p->cmd);
>  
>  	validate_cache_entries(repo->index);
> -	status = p->fn(argc, argv, prefix, (p->option & RUN_SETUP)? repo : NULL);
> +	status = p->fn(argc,
> +		       argv,
> +		       prefix,
> +		       ((p->option & RUN_SETUP) || (p->option & RUN_SETUP_GENTLY))? repo : NULL);
>  	validate_cache_entries(repo->index);

Should we really pass `repo` unconditionally when `RUN_SETUP_GENTLY` was
requested? I'd think that we should rather pass `NULL` if we didn't find
a repository in that case. So this condition should likely be made
conditional, shouldn't it?

There's also a missing space between the closing brace and the ternary
questionmark.

Patrick