]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule: pass repo to check_has_commit()
authorJonathan Tan <jonathantanmy@google.com>
Fri, 8 Oct 2021 21:08:19 +0000 (14:08 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 8 Oct 2021 22:06:06 +0000 (15:06 -0700)
Pass the repo explicitly when calling check_has_commit() to avoid
relying on add_submodule_odb(). With this commit and the parent commit,
the last remaining tests no longer rely on add_submodule_odb(), so mark
these tests accordingly.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule.c
t/t5526-fetch-submodules.sh
t/t5531-deep-submodule-push.sh
t/t5545-push-options.sh
t/t5572-pull-submodule.sh
t/t7418-submodule-sparse-gitmodules.sh

index 62beb8fd5f381a6746a5824922c7acd7d14ca563..4bf552b0e5c1063b76b3235272720a9676551f9a 100644 (file)
@@ -928,23 +928,33 @@ struct has_commit_data {
 static int check_has_commit(const struct object_id *oid, void *data)
 {
        struct has_commit_data *cb = data;
+       struct repository subrepo;
+       enum object_type type;
 
-       enum object_type type = oid_object_info(cb->repo, oid, NULL);
+       if (repo_submodule_init(&subrepo, cb->repo, cb->path, null_oid())) {
+               cb->result = 0;
+               goto cleanup;
+       }
+
+       type = oid_object_info(&subrepo, oid, NULL);
 
        switch (type) {
        case OBJ_COMMIT:
-               return 0;
+               goto cleanup;
        case OBJ_BAD:
                /*
                 * Object is missing or invalid. If invalid, an error message
                 * has already been printed.
                 */
                cb->result = 0;
-               return 0;
+               goto cleanup;
        default:
                die(_("submodule entry '%s' (%s) is a %s, not a commit"),
                    cb->path, oid_to_hex(oid), type_name(type));
        }
+cleanup:
+       repo_clear(&subrepo);
+       return 0;
 }
 
 static int submodule_has_commits(struct repository *r,
index ed11569d8d7ec605198773351e75baeaa232cb1a..2dc75b80db80964a6bcdbc3977be98f815b40dd0 100755 (executable)
@@ -6,6 +6,9 @@ test_description='Recursive "git fetch" for submodules'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
+export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
+
 . ./test-lib.sh
 
 pwd=$(pwd)
index d573ca496ab2234e1c5b7a228b9291320bf358c2..3f58b515cee5d8f8ec72d22e363512b5a5a40c1f 100755 (executable)
@@ -5,6 +5,9 @@ test_description='test push with submodules'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
+export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
+
 . ./test-lib.sh
 
 test_expect_success setup '
index 58c7add7eefad8dc8280590975b71a0b04296633..214228349ad3995e49815850412e9c24bfc58065 100755 (executable)
@@ -5,6 +5,9 @@ test_description='pushing to a repository using push options'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
+export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
+
 . ./test-lib.sh
 
 mk_repo_pair () {
index 4f92a116e1f0ec48bdf79f1963da32c8ecdcd8dd..fa6b4cca65c8c687bf83f9eaf0ecb5568c9373f6 100755 (executable)
@@ -2,6 +2,9 @@
 
 test_description='pull can handle submodules'
 
+GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
+export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
+
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-submodule-update.sh
 
index 3f7f27188313fb97e9e69e5be8d6c0b005b59e59..f87e524d6d467fd723c083c105f092850051f566 100755 (executable)
@@ -12,6 +12,9 @@ The test setup uses a sparse checkout, however the same scenario can be set up
 also by committing .gitmodules and then just removing it from the filesystem.
 '
 
+GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
+export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
+
 . ./test-lib.sh
 
 test_expect_success 'sparse checkout setup which hides .gitmodules' '