]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/pack-refs: stop using `the_repository`
authorUsman Akinyemi <usmanakinyemi202@gmail.com>
Fri, 7 Mar 2025 23:35:04 +0000 (05:05 +0530)
committerJunio C Hamano <gitster@pobox.com>
Sat, 8 Mar 2025 00:52:01 +0000 (16:52 -0800)
Remove the_repository global variable in favor of the repository
argument that gets passed in "builtin/pack-refs.c".

When `-h` is passed to the command outside a Git repository, the
`run_builtin()` will call the `cmd_pack_refs()` function with `repo` set
to NULL and then early in the function, `parse_options()` call will give
the options help and exit.

Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pack-refs.c
t/t0610-reftable-basics.sh

index 4fdd68880e0c6d30ca77df1e5f0f2e3f5117097e..e47bae1c803bc81e28910a30213a27dbbdef6a10 100644 (file)
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
@@ -15,7 +13,7 @@ static char const * const pack_refs_usage[] = {
 int cmd_pack_refs(int argc,
                  const char **argv,
                  const char *prefix,
-                 struct repository *repo UNUSED)
+                 struct repository *repo)
 {
        struct ref_exclusions excludes = REF_EXCLUSIONS_INIT;
        struct string_list included_refs = STRING_LIST_INIT_NODUP;
@@ -39,7 +37,7 @@ int cmd_pack_refs(int argc,
                        N_("references to exclude")),
                OPT_END(),
        };
-       git_config(git_default_config, NULL);
+       repo_config(repo, git_default_config, NULL);
        if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
                usage_with_options(pack_refs_usage, opts);
 
@@ -52,7 +50,7 @@ int cmd_pack_refs(int argc,
        if (!pack_refs_opts.includes->nr)
                string_list_append(pack_refs_opts.includes, "refs/tags/*");
 
-       ret = refs_pack_refs(get_main_ref_store(the_repository), &pack_refs_opts);
+       ret = refs_pack_refs(get_main_ref_store(repo), &pack_refs_opts);
 
        clear_ref_exclusions(&excludes);
        string_list_clear(&included_refs, 0);
index 4618ffc108edd8f523a7ffb0d7f9c61fd3ab3734..002a75dee85f55ec5b77fe371ab06def72fe5216 100755 (executable)
@@ -14,6 +14,13 @@ export GIT_TEST_DEFAULT_REF_FORMAT
 
 INVALID_OID=$(test_oid 001)
 
+test_expect_success 'pack-refs does not crash with -h' '
+       test_expect_code 129 git pack-refs -h >usage &&
+       test_grep "[Uu]sage: git pack-refs " usage &&
+       test_expect_code 129 nongit git pack-refs -h >usage &&
+       test_grep "[Uu]sage: git pack-refs " usage
+'
+
 test_expect_success 'init: creates basic reftable structures' '
        test_when_finished "rm -rf repo" &&
        git init repo &&