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

From: shejialuo <[email-masked]>
Date: Tue, 1 Oct 2024 12:21:32 +0800

On Mon, Sep 30, 2024 at 05:40:27PM +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.
> 

We will parse the "repo" to the "run_builtin()" for "RUN_SETUP_GENTLY"
property only when we know we run the command in the repository. If we
run the command outside of the repository, we should pass the NULL.

However, the above commit message is not accurate. If a builtin has the
"RUN_SETUP_GENTLY" property. We may pass or not.

> Signed-off-by: John Cai <[email-masked]>
> ---
>  git.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/git.c b/git.c
> index 2fbea24ec92..f58f169f3c7 100644
> --- a/git.c
> +++ b/git.c
> @@ -443,7 +443,7 @@ static int handle_alias(int *argcp, const char ***argv)
>  
>  static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct repository *repo)
>  {
> -	int status, help;
> +	int status, help, repo_exists;

This is wrong. We should initialize the "repo_exists" variable here.
Because we never set this variable to 0 in the later code path. It will
always be true for the following code:

    repo_exists ? repo : NULL

It will always evaluate to the "repo". This may could answer the
question raised by Junio in [PATCH v2 3/4].

Thanks,
Jialuo