diff mbox series

[v2,03/12] builtin/verify-commit: refactor `cmd_verify_commit()`

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

Commit Message

Usman Akinyemi Feb. 19, 2025, 8:32 p.m. UTC
Move `git_config()` call after `usage_with_options()` to avoid NULL `repo`
check.

When "-h" is passed to builtins using the RUN_SETUP macro, `repo` passed
by `run_builtin()` will be NULL. If we use the `repo` instead of the
global `the_repository` variable. We will have to switch from `git_config()`
to `repo_config()` which takes in `repo`. We must check for NULL `repo`
if `repo_config()` comes before `usage_with_options()`. Moving `git_config()`
after `usage_with_options()` eliminates this need, as `usage_with_options()`
exit before calling `repo_config()`.

This will be useful in the following patch which remove `the_repository`
global variable in favor of the `repo` passed by `run_builtin()`.

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

Patch

diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 779b7988ca..ae0c625777 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -64,8 +64,6 @@  int cmd_verify_commit(int argc,
 		OPT_END()
 	};
 
-	git_config(git_default_config, NULL);
-
 	argc = parse_options(argc, argv, prefix, verify_commit_options,
 			     verify_commit_usage, PARSE_OPT_KEEP_ARGV0);
 	if (argc <= i)
@@ -74,6 +72,8 @@  int cmd_verify_commit(int argc,
 	if (verbose)
 		flags |= GPG_VERIFY_VERBOSE;
 
+	git_config(git_default_config, NULL);
+
 	/* sometimes the program was terminated because this signal
 	 * was received in the process of writing the gpg input: */
 	signal(SIGPIPE, SIG_IGN);