Skip to content

Commit eea83c0

Browse files
pks-tgitster
authored andcommitted
t/helper: stop setting up the_repository repeatedly
The "repository" test helper sets up `the_repository` twice. In fact though, we don't even have to set it up even once: all we need is to set up its hash algorithm, because we still depend on some subsystems that aren't free of `the_repository`. Refactor the code accordingly. This prepares for a subsequent change, where setting up the repository repeatedly will lead to a `BUG()`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8dc22e8 commit eea83c0

1 file changed

Lines changed: 2 additions & 14 deletions

File tree

t/helper/test-repository.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ static void test_parse_commit_in_graph(const char *gitdir, const char *worktree,
1717
struct commit *c;
1818
struct commit_list *parent;
1919

20-
setup_git_env(gitdir);
21-
22-
repo_clear(the_repository);
23-
2420
if (repo_init(&r, gitdir, worktree))
2521
die("Couldn't init repo");
2622

@@ -47,10 +43,6 @@ static void test_get_commit_tree_in_graph(const char *gitdir,
4743
struct commit *c;
4844
struct tree *tree;
4945

50-
setup_git_env(gitdir);
51-
52-
repo_clear(the_repository);
53-
5446
if (repo_init(&r, gitdir, worktree))
5547
die("Couldn't init repo");
5648

@@ -75,24 +67,20 @@ static void test_get_commit_tree_in_graph(const char *gitdir,
7567

7668
int cmd__repository(int argc, const char **argv)
7769
{
78-
int nongit_ok = 0;
79-
80-
setup_git_directory_gently(&nongit_ok);
81-
8270
if (argc < 2)
8371
die("must have at least 2 arguments");
8472
if (!strcmp(argv[1], "parse_commit_in_graph")) {
8573
struct object_id oid;
8674
if (argc < 5)
8775
die("not enough arguments");
88-
if (parse_oid_hex(argv[4], &oid, &argv[4]))
76+
if (parse_oid_hex_any(argv[4], &oid, &argv[4]) == GIT_HASH_UNKNOWN)
8977
die("cannot parse oid '%s'", argv[4]);
9078
test_parse_commit_in_graph(argv[2], argv[3], &oid);
9179
} else if (!strcmp(argv[1], "get_commit_tree_in_graph")) {
9280
struct object_id oid;
9381
if (argc < 5)
9482
die("not enough arguments");
95-
if (parse_oid_hex(argv[4], &oid, &argv[4]))
83+
if (parse_oid_hex_any(argv[4], &oid, &argv[4]) == GIT_HASH_UNKNOWN)
9684
die("cannot parse oid '%s'", argv[4]);
9785
test_get_commit_tree_in_graph(argv[2], argv[3], &oid);
9886
} else {

0 commit comments

Comments
 (0)