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
@@ -17,10 +17,6 @@ static void test_parse_commit_in_graph(const char *gitdir, const char *worktree,
17 struct commit *c;
18 struct commit_list *parent;
19
20 - setup_git_env(gitdir);
21 -
22 - repo_clear(the_repository);
23 -
20 if (repo_init(&r, gitdir, worktree))
21 die("Couldn't init repo");
22
@@ -47,10 +43,6 @@ static void test_get_commit_tree_in_graph(const char *gitdir,
43 struct commit *c;
44 struct tree *tree;
45
50 - setup_git_env(gitdir);
51 -
52 - repo_clear(the_repository);
53 -
46 if (repo_init(&r, gitdir, worktree))
47 die("Couldn't init repo");
48
@@ -75,24 +67,20 @@ static void test_get_commit_tree_in_graph(const char *gitdir,
67
68 int cmd__repository(int argc, const char **argv)
69 {
78 - int nongit_ok = 0;
79 -
80 - setup_git_directory_gently(&nongit_ok);
81 -
70 if (argc < 2)
71 die("must have at least 2 arguments");
72 if (!strcmp(argv[1], "parse_commit_in_graph")) {
73 struct object_id oid;
74 if (argc < 5)
75 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)
77 die("cannot parse oid '%s'", argv[4]);
78 test_parse_commit_in_graph(argv[2], argv[3], &oid);
79 } else if (!strcmp(argv[1], "get_commit_tree_in_graph")) {
80 struct object_id oid;
81 if (argc < 5)
82 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)
84 die("cannot parse oid '%s'", argv[4]);
85 test_get_commit_tree_in_graph(argv[2], argv[3], &oid);
86 } else {