Skip to content

Commit 72fe8bf

Browse files
Unique-Usmangitster
authored andcommitted
builtin/pack-refs: stop using the_repository
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 <[email protected]> Signed-off-by: Usman Akinyemi <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1c14b1a commit 72fe8bf

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

builtin/pack-refs.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
2-
31
#include "builtin.h"
42
#include "config.h"
53
#include "gettext.h"
@@ -15,7 +13,7 @@ static char const * const pack_refs_usage[] = {
1513
int cmd_pack_refs(int argc,
1614
const char **argv,
1715
const char *prefix,
18-
struct repository *repo UNUSED)
16+
struct repository *repo)
1917
{
2018
struct ref_exclusions excludes = REF_EXCLUSIONS_INIT;
2119
struct string_list included_refs = STRING_LIST_INIT_NODUP;
@@ -39,7 +37,7 @@ int cmd_pack_refs(int argc,
3937
N_("references to exclude")),
4038
OPT_END(),
4139
};
42-
git_config(git_default_config, NULL);
40+
repo_config(repo, git_default_config, NULL);
4341
if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
4442
usage_with_options(pack_refs_usage, opts);
4543

@@ -52,7 +50,7 @@ int cmd_pack_refs(int argc,
5250
if (!pack_refs_opts.includes->nr)
5351
string_list_append(pack_refs_opts.includes, "refs/tags/*");
5452

55-
ret = refs_pack_refs(get_main_ref_store(the_repository), &pack_refs_opts);
53+
ret = refs_pack_refs(get_main_ref_store(repo), &pack_refs_opts);
5654

5755
clear_ref_exclusions(&excludes);
5856
string_list_clear(&included_refs, 0);

t/t0610-reftable-basics.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ export GIT_TEST_DEFAULT_REF_FORMAT
1414

1515
INVALID_OID=$(test_oid 001)
1616

17+
test_expect_success 'pack-refs does not crash with -h' '
18+
test_expect_code 129 git pack-refs -h >usage &&
19+
test_grep "[Uu]sage: git pack-refs " usage &&
20+
test_expect_code 129 nongit git pack-refs -h >usage &&
21+
test_grep "[Uu]sage: git pack-refs " usage
22+
'
23+
1724
test_expect_success 'init: creates basic reftable structures' '
1825
test_when_finished "rm -rf repo" &&
1926
git init repo &&

0 commit comments

Comments
 (0)