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

Re: [PATCH v3 1/3] git: pass in repo to builtin based on setup_git_directory_gently

From
shejialuo <shejialuo@gmail.com>
Date
Oct 5, 2024, 06:51 UTC
Message-ID
<ZwDh6XAKIhUF_Lu6@ArchLinux>
In-Reply-To
<8009fdb38b0b4c3880588119b99ac5387d398540.1728099043.git.gitgitgadget@gmail.com>
On Sat, Oct 05, 2024 at 03:30:41AM +0000, John Cai via GitGitGadget wrote:
Show 35 quoted lines
> From: John Cai <johncai86@gmail.com>
> 
> The current code in run_builtin() passes in a repository to the builtin
> based on whether cmd_struct's option flag has RUN_SETUP.
> 
> This is incorrect, however, since some builtins that only have
> RUN_SETUP_GENTLY can potentially take a repository.
> setup_git_directory_gently() tells us whether or not a command is being
> run inside of a repository.
> 
> Use the output of setup_git_directory_gently() to help determine whether
> or not there is a repository to pass to the builtin. If not, then we
> just pass NULL.
> 
> As part of this patch, we need to modify add to check for a NULL repo
> before calling repo_git_config(), since add -h can be run outside of a
> repository.
> 
> Signed-off-by: John Cai <johncai86@gmail.com>
> ---
>  builtin/add.c | 3 ++-
>  git.c         | 7 ++++---
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/builtin/add.c b/builtin/add.c
> index 773b7224a49..7d353077921 100644
> --- a/builtin/add.c
> +++ b/builtin/add.c
> @@ -385,7 +385,8 @@ int cmd_add(int argc,
>  	char *ps_matched = NULL;
>  	struct lock_file lock_file = LOCK_INIT;
>  
> -	repo_config(repo, add_config, NULL);
> +	if (repo)
> +		repo_config(repo, add_config, NULL);

The reason why we need to check whether the `repo` is NULL is that when using "git add -h", the RUN_SETUP flag would be converted to RUN_SETUP_GENTLY.

I think this change is OK. But I wonder whether we should encapsulate the logic into the "repo_config" function. It's a little cumbersome to check whether the "repo" exists. I also feel it's a bad idea to check in the "repo_config" function because in the most time, we run commands inside the repository. So, in my view, at current, this is enough.

Thanks, Jialuo

Previous: John Cai via GitGitGadgetNext: John Cai via GitGitGadget
Message 35 of 44 in “Remove the_repository global for am, annotate, apply, archive builtins”
  1. 0/4 Remove the_repository global for am, annotate, apply, archive builtinsJohn Cai via GitGitGadget, Sep 24, 2024
  2. 1/4 git: pass in repo for RUN_SETUP_GENTLYJohn Cai via GitGitGadget, Sep 24, 2024
  3. shejialuoSep 24, 2024
  4. Junio C HamanoSep 24, 2024
  5. Junio C HamanoSep 24, 2024
  6. Patrick SteinhardtSep 26, 2024
  7. Junio C HamanoSep 26, 2024
  8. 2/4 annotate: remove usage of the_repository globalJohn Cai via GitGitGadget, Sep 24, 2024
  9. 3/4 apply: remove the_repository global variableJohn Cai via GitGitGadget, Sep 24, 2024
  10. Junio C HamanoSep 24, 2024
  11. Junio C HamanoSep 24, 2024
  12. John CaiSep 26, 2024
  13. Junio C HamanoSep 26, 2024
  14. 4/4 archive: remove the_repository global variableJohn Cai via GitGitGadget, Sep 24, 2024
  15. Junio C HamanoSep 24, 2024
  16. 0/4 Remove the_repository global for am, annotate, apply, archive builtinsJohn Cai via GitGitGadget, Sep 30, 2024
  17. 1/4 git: pass in repo for RUN_SETUP_GENTLYJohn Cai via GitGitGadget, Sep 30, 2024
  18. Junio C HamanoSep 30, 2024
  19. shejialuoOct 1, 2024
  20. 2/4 annotate: remove usage of the_repository globalJohn Cai via GitGitGadget, Sep 30, 2024
  21. Junio C HamanoSep 30, 2024
  22. 4/4 archive: remove the_repository global variableJohn Cai via GitGitGadget, Sep 30, 2024
  23. Junio C HamanoSep 30, 2024
  24. johncai86@gmail.comOct 4, 2024
  25. 3/4 apply: remove the_repository global variableJohn Cai via GitGitGadget, Sep 30, 2024
  26. Junio C HamanoSep 30, 2024
  27. shejialuoOct 1, 2024
  28. Patrick SteinhardtOct 1, 2024
  29. shejialuoOct 1, 2024
  30. Patrick SteinhardtOct 1, 2024
  31. Junio C HamanoOct 1, 2024
  32. johncai86@gmail.comOct 3, 2024
  33. 0/3 Remove the_repository global for am, annotate, apply, archive builtinsJohn Cai via GitGitGadget, Oct 5, 2024
  34. 1/3 git: pass in repo to builtin based on setup_git_directory_gentlyJohn Cai via GitGitGadget, Oct 5, 2024
  35. shejialuoOct 5, 2024
  36. 2/3 annotate: remove usage of the_repository globalJohn Cai via GitGitGadget, Oct 5, 2024
  37. 3/3 archive: remove the_repository global variableJohn Cai via GitGitGadget, Oct 5, 2024
  38. shejialuoOct 5, 2024
  39. johncai86@gmail.comOct 10, 2024
  40. 0/3 Remove the_repository global for am, annotate, apply, archive builtinsJohn Cai via GitGitGadget, Oct 10, 2024
  41. 1/3 git: pass in repo to builtin based on setup_git_directory_gentlyJohn Cai via GitGitGadget, Oct 10, 2024
  42. 2/3 annotate: remove usage of the_repository globalJohn Cai via GitGitGadget, Oct 10, 2024
  43. 3/3 archive: remove the_repository global variableJohn Cai via GitGitGadget, Oct 10, 2024
  44. Junio C HamanoOct 11, 2024

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.