diff mbox series

[2/7] builtin/verify-commit.c: stop using `the_repository`

Message ID 20250214230210.1460111-3-usmanakinyemi202@gmail.com (mailing list archive)
State Superseded
Headers show
Series stop using the_repository global variable. | expand

Commit Message

Usman Akinyemi Feb. 14, 2025, 10:57 p.m. UTC
Remove the_repository global variable in favor of the repository
argument that gets passed in "builtin/verify-tag.c".

When `-h` is passed to the command outside a Git repository, the
`run_builtin()` will call the `cmd_verify_commit()` function with `repo`
set to NULL and then early in the function, `parse_options()` call will
give the options help and exit, without having to consult much of the
configuration file. So it is safe to omit reading the config when `repo`
argument the caller gave us is NULL.

Let's pass `repository` argument to `verify_commit()` function to remove
it's dependency on the global `the_repository` variable.

Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
---
 builtin/verify-commit.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

shejialuo Feb. 16, 2025, 5:32 a.m. UTC | #1
On Sat, Feb 15, 2025 at 04:27:18AM +0530, Usman Akinyemi wrote:
> Remove the_repository global variable in favor of the repository
> argument that gets passed in "builtin/verify-tag.c".
> 

I think this is a typo. "builtin/verify-tag.c" should be
"builtin/verify-commit.c".
Usman Akinyemi Feb. 17, 2025, 8:55 a.m. UTC | #2
On Sun, Feb 16, 2025 at 11:02 AM shejialuo <shejialuo@gmail.com> wrote:
>
> On Sat, Feb 15, 2025 at 04:27:18AM +0530, Usman Akinyemi wrote:
> > Remove the_repository global variable in favor of the repository
> > argument that gets passed in "builtin/verify-tag.c".
> >
>
> I think this is a typo. "builtin/verify-tag.c" should be
> "builtin/verify-commit.c".
Ohh, yeah, I will fix it in the next version. Thanks.
diff mbox series

Patch

diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 779b7988ca..50f56d296c 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -5,7 +5,6 @@ 
  *
  * Based on git-verify-tag
  */
-#define USE_THE_REPOSITORY_VARIABLE
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
@@ -33,15 +32,15 @@  static int run_gpg_verify(struct commit *commit, unsigned flags)
 	return ret;
 }
 
-static int verify_commit(const char *name, unsigned flags)
+static int verify_commit(struct repository *repo, const char *name, unsigned flags)
 {
 	struct object_id oid;
 	struct object *obj;
 
-	if (repo_get_oid(the_repository, name, &oid))
+	if (repo_get_oid(repo, name, &oid))
 		return error("commit '%s' not found.", name);
 
-	obj = parse_object(the_repository, &oid);
+	obj = parse_object(repo, &oid);
 	if (!obj)
 		return error("%s: unable to read file.", name);
 	if (obj->type != OBJ_COMMIT)
@@ -54,7 +53,7 @@  static int verify_commit(const char *name, unsigned flags)
 int cmd_verify_commit(int argc,
 		      const char **argv,
 		      const char *prefix,
-		      struct repository *repo UNUSED)
+		      struct repository *repo)
 {
 	int i = 1, verbose = 0, had_error = 0;
 	unsigned flags = 0;
@@ -64,7 +63,8 @@  int cmd_verify_commit(int argc,
 		OPT_END()
 	};
 
-	git_config(git_default_config, NULL);
+	if (repo)
+		repo_config(repo, git_default_config, NULL);
 
 	argc = parse_options(argc, argv, prefix, verify_commit_options,
 			     verify_commit_usage, PARSE_OPT_KEEP_ARGV0);
@@ -78,7 +78,7 @@  int cmd_verify_commit(int argc,
 	 * was received in the process of writing the gpg input: */
 	signal(SIGPIPE, SIG_IGN);
 	while (i < argc)
-		if (verify_commit(argv[i++], flags))
+		if (verify_commit(repo, argv[i++], flags))
 			had_error = 1;
 	return had_error;
 }