]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t/helper: stop setting up `the_repository` repeatedly
authorPatrick Steinhardt <ps@pks.im>
Wed, 19 Nov 2025 07:50:56 +0000 (08:50 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Nov 2025 20:16:00 +0000 (12:16 -0800)
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>
t/helper/test-repository.c

index 63c37de33d22f195bb15298527e013e98c778776..9ba94cdffa4c474ee9994198f8641df7975ece15 100644 (file)
@@ -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 {