diff mbox series

[v2,07/12] builtin/pack-refs: refactor `cmd_pack_refs()`

Message ID 20250219203349.787173-8-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/pack-refs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/builtin/pack-refs.c b/builtin/pack-refs.c
index 4fdd68880e..bd09366738 100644
--- a/builtin/pack-refs.c
+++ b/builtin/pack-refs.c
@@ -39,10 +39,11 @@  int cmd_pack_refs(int argc,
 			N_("references to exclude")),
 		OPT_END(),
 	};
-	git_config(git_default_config, NULL);
+
 	if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
 		usage_with_options(pack_refs_usage, opts);
 
+	git_config(git_default_config, NULL);
 	for_each_string_list_item(item, &option_excluded_refs)
 		add_ref_exclusion(pack_refs_opts.exclusions, item->string);