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

Re: [PATCH 1/3] builtin: add a repository parameter for builtin functions

From
Patrick Steinhardt <ps@pks.im>
Date
Sep 6, 2024, 10:46 UTC
Message-ID
<ZtrdljxBJtnaUEla@pks.im>
In-Reply-To
<3301a34f76303c43feaf4eb9d6913fbeec439e97.1725555468.git.gitgitgadget@gmail.com>
On Thu, Sep 05, 2024 at 04:57:45PM +0000, John Cai via GitGitGadget wrote:
Show 14 quoted lines
> From: John Cai <johncai86@gmail.com>
> diff --git a/builtin/add.c b/builtin/add.c
> index 40b61ef90d9..3b9bc93ed9a 100644
> --- a/builtin/add.c
> +++ b/builtin/add.c
> @@ -358,7 +358,7 @@ static int add_files(struct dir_struct *dir, int flags)
>  	return exit_status;
>  }
>  
> -int cmd_add(int argc, const char **argv, const char *prefix)
> +int cmd_add(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
>  {
>  	int exit_status = 0;
>  	struct pathspec pathspec;
Nit: all of these are now overly long as we typically wrap at 80
characters.
Show 37 quoted lines
> diff --git a/git.c b/git.c
> index 9a618a2740f..0ea6e351dfd 100644
> --- a/git.c
> +++ b/git.c
> @@ -31,7 +31,7 @@
>  
>  struct cmd_struct {
>  	const char *cmd;
> -	int (*fn)(int, const char **, const char *);
> +	int (*fn)(int, const char **, const char *, struct repository *);
>  	unsigned int option;
>  };
>  
> @@ -441,7 +441,7 @@ static int handle_alias(int *argcp, const char ***argv)
>  	return ret;
>  }
>  
> -static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
> +static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct repository *repo)
>  {
>  	int status, help;
>  	struct stat st;
> @@ -479,9 +479,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
>  	trace_argv_printf(argv, "trace: built-in: git");
>  	trace2_cmd_name(p->cmd);
>  
> -	validate_cache_entries(the_repository->index);
> -	status = p->fn(argc, argv, prefix);
> -	validate_cache_entries(the_repository->index);
> +	validate_cache_entries(repo->index);
> +
> +	status = p->fn(argc, argv, prefix, startup_info->have_repository? repo: NULL) ;
> +
> +	validate_cache_entries(repo->index);
>  
>  	if (status)
>  		return status;
Looks sensible.
Show 9 quoted lines
> @@ -736,7 +738,7 @@ static void handle_builtin(int argc, const char **argv)
>  
>  	builtin = get_builtin(cmd);
>  	if (builtin)
> -		exit(run_builtin(builtin, argc, argv));
> +		exit(run_builtin(builtin, argc, argv, the_repository));
>  	strvec_clear(&args);
>  }
>  
Why don't we need a check for `startup_info->have_repository` here?
Show 12 quoted lines
> diff --git a/help.c b/help.c
> index c03863f2265..e7cdfab6432 100644
> --- a/help.c
> +++ b/help.c
> @@ -16,6 +16,7 @@
>  #include "parse-options.h"
>  #include "prompt.h"
>  #include "fsmonitor-ipc.h"
> +#include "repository.h"
>  
>  #ifndef NO_CURL
>  #include "git-curl-compat.h" /* For LIBCURL_VERSION only */
The include shouldn't be necessary. You can instead add a forward declaration.
Show 9 quoted lines
> @@ -775,7 +776,7 @@ void get_version_info(struct strbuf *buf, int show_build_options)
>  	}
>  }
>  
> -int cmd_version(int argc, const char **argv, const char *prefix)
> +int cmd_version(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
>  {
>  	struct strbuf buf = STRBUF_INIT;
>  	int build_options = 0;
Patrick
Previous: John Cai via GitGitGadgetNext: John Cai
Message 7 of 32 in “Add repository parameter to builtins”
  1. 0/3 Add repository parameter to builtinsJohn Cai via GitGitGadget, Sep 5, 2024
  2. 2/3 builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.hJohn Cai via GitGitGadget, Sep 5, 2024
  3. Junio C HamanoSep 5, 2024
  4. Patrick SteinhardtSep 6, 2024
  5. Junio C HamanoSep 6, 2024
  6. 1/3 builtin: add a repository parameter for builtin functionsJohn Cai via GitGitGadget, Sep 5, 2024
  7. Patrick SteinhardtSep 6, 2024
  8. John CaiSep 9, 2024
  9. 3/3 add: pass in repo variable instead of global the_repositoryJohn Cai via GitGitGadget, Sep 5, 2024
  10. Patrick SteinhardtSep 6, 2024
  11. Junio C HamanoSep 5, 2024
  12. 0/3 Add repository parameter to builtinsJohn Cai via GitGitGadget, Sep 10, 2024
  13. 3/3 add: pass in repo variable instead of global the_repositoryJohn Cai via GitGitGadget, Sep 10, 2024
  14. Junio C HamanoSep 11, 2024
  15. 2/3 builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.hJohn Cai via GitGitGadget, Sep 10, 2024
  16. Junio C HamanoSep 11, 2024
  17. John CaiSep 13, 2024
  18. 1/3 builtin: add a repository parameter for builtin functionsJohn Cai via GitGitGadget, Sep 10, 2024
  19. Junio C HamanoSep 10, 2024
  20. Junio C HamanoSep 11, 2024
  21. Patrick SteinhardtSep 12, 2024
  22. Jeff KingSep 12, 2024
  23. Jeff KingSep 12, 2024
  24. Patrick SteinhardtSep 12, 2024
  25. John CaiSep 13, 2024
  26. 0/4 Add repository parameter to builtinsJohn Cai via GitGitGadget, Sep 13, 2024
  27. 1/4 builtin: add a repository parameter for builtin functionsJohn Cai via GitGitGadget, Sep 13, 2024
  28. 3/4 builtin: remove USE_THE_REPOSITORY for those without the_repositoryJohn Cai via GitGitGadget, Sep 13, 2024
  29. 2/4 builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.hJohn Cai via GitGitGadget, Sep 13, 2024
  30. Junio C HamanoSep 13, 2024
  31. 4/4 add: pass in repo variable instead of global the_repositoryJohn Cai via GitGitGadget, Sep 13, 2024
  32. Junio C HamanoSep 13, 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.