public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks•im>
To: John Cai via GitGitGadget <gitgitgadget@gmail•com>
Cc: git@vger•kernel.org, John Cai <johncai86@gmail•com>
Subject: Re: [PATCH 1/3] builtin: add a repository parameter for builtin functions
Date: Fri, 6 Sep 2024 12:46:46 +0200	[thread overview]
Message-ID: <ZtrdljxBJtnaUEla@pks.im> (raw)
In-Reply-To: <3301a34f76303c43feaf4eb9d6913fbeec439e97.1725555468.git.gitgitgadget@gmail.com>

On Thu, Sep 05, 2024 at 04:57:45PM +0000, John Cai via GitGitGadget wrote:
> 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.

> 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.

> @@ -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?

> 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.

> @@ -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

  reply	other threads:[~2024-09-06 10:46 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-05 16:57 [PATCH 0/3] Add repository parameter to builtins John Cai via GitGitGadget
2024-09-05 16:57 ` [PATCH 1/3] builtin: add a repository parameter for builtin functions John Cai via GitGitGadget
2024-09-06 10:46   ` Patrick Steinhardt [this message]
2024-09-09 21:08     ` John Cai
2024-09-05 16:57 ` [PATCH 2/3] builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h John Cai via GitGitGadget
2024-09-05 17:50   ` Junio C Hamano
2024-09-06 10:46     ` Patrick Steinhardt
2024-09-06 15:43   ` Junio C Hamano
2024-09-05 16:57 ` [PATCH 3/3] add: pass in repo variable instead of global the_repository John Cai via GitGitGadget
2024-09-06 10:46   ` Patrick Steinhardt
2024-09-05 17:21 ` [PATCH 0/3] Add repository parameter to builtins Junio C Hamano
2024-09-10 20:59 ` [PATCH v2 " John Cai via GitGitGadget
2024-09-10 20:59   ` [PATCH v2 1/3] builtin: add a repository parameter for builtin functions John Cai via GitGitGadget
2024-09-10 21:40     ` Junio C Hamano
2024-09-11 21:08       ` Junio C Hamano
2024-09-12  9:45         ` Patrick Steinhardt
2024-09-12 10:43           ` Jeff King
2024-09-12 10:50             ` Jeff King
2024-09-12 10:55               ` Patrick Steinhardt
2024-09-13 17:54                 ` John Cai
2024-09-10 20:59   ` [PATCH v2 2/3] builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h John Cai via GitGitGadget
2024-09-11 18:15     ` Junio C Hamano
2024-09-13 18:00       ` John Cai
2024-09-10 20:59   ` [PATCH v2 3/3] add: pass in repo variable instead of global the_repository John Cai via GitGitGadget
2024-09-11 18:23     ` Junio C Hamano
2024-09-13 21:16   ` [PATCH v3 0/4] Add repository parameter to builtins John Cai via GitGitGadget
2024-09-13 21:16     ` [PATCH v3 1/4] builtin: add a repository parameter for builtin functions John Cai via GitGitGadget
2024-09-13 21:16     ` [PATCH v3 2/4] builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.h John Cai via GitGitGadget
2024-09-13 21:32       ` Junio C Hamano
2024-09-13 21:16     ` [PATCH v3 3/4] builtin: remove USE_THE_REPOSITORY for those without the_repository John Cai via GitGitGadget
2024-09-13 21:16     ` [PATCH v3 4/4] add: pass in repo variable instead of global the_repository John Cai via GitGitGadget
2024-09-13 21:35       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZtrdljxBJtnaUEla@pks.im \
    --to=ps@pks$(echo .)im \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitgitgadget@gmail$(echo .)com \
    --cc=johncai86@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox