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>
Patrick Steinhardt committed
Nov 19, 2025 at 08:50 UTC
eea83c010cf431325a05f06cc7c64029538c8495
1 file changed
+2
-14
t/helper/test-repository.c
+2
-14
index 63c37de33d..9ba94cdffa 100644
--- a/t/helper/test-repository.c
+++ b/t/helper/test-repository.c
@@ -17,10 +17,6 @@ static void test_parse_commit_in_graph(const char *gitdir, const char *worktree,
struct commit *c;
struct commit_list *parent;
- setup_git_env(gitdir);
-
- repo_clear(the_repository);
-
if (repo_init(&r, gitdir, worktree))
die("Couldn't init repo");
@@ -47,10 +43,6 @@ static void test_get_commit_tree_in_graph(const char *gitdir,
struct commit *c;
struct tree *tree;
- setup_git_env(gitdir);
-
- repo_clear(the_repository);
-
if (repo_init(&r, gitdir, worktree))
die("Couldn't init repo");
@@ -75,24 +67,20 @@ static void test_get_commit_tree_in_graph(const char *gitdir,
int cmd__repository(int argc, const char **argv)
{
- int nongit_ok = 0;
-
- setup_git_directory_gently(&nongit_ok);
-
if (argc < 2)
die("must have at least 2 arguments");
if (!strcmp(argv[1], "parse_commit_in_graph")) {
struct object_id oid;
if (argc < 5)
die("not enough arguments");
- if (parse_oid_hex(argv[4], &oid, &argv[4]))
+ if (parse_oid_hex_any(argv[4], &oid, &argv[4]) == GIT_HASH_UNKNOWN)
die("cannot parse oid '%s'", argv[4]);
test_parse_commit_in_graph(argv[2], argv[3], &oid);
} else if (!strcmp(argv[1], "get_commit_tree_in_graph")) {
struct object_id oid;
if (argc < 5)
die("not enough arguments");
- if (parse_oid_hex(argv[4], &oid, &argv[4]))
+ if (parse_oid_hex_any(argv[4], &oid, &argv[4]) == GIT_HASH_UNKNOWN)
die("cannot parse oid '%s'", argv[4]);
test_get_commit_tree_in_graph(argv[2], argv[3], &oid);
} else {