submodule: pass repo to check_has_commit()

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>

Jonathan Tan committed Oct 8, 2021 at 14:08 UTC 13a2f620b27c0fa29de026de5d74a2434c565ece
6 files changed +28 -3
submodule.c
+13 -3
@@ -928,23 +928,33 @@ struct has_commit_data {
928 static int check_has_commit(const struct object_id *oid, void *data)
929 {
930 struct has_commit_data *cb = data;
931 + struct repository subrepo;
932 + enum object_type type;
933
932 - enum object_type type = oid_object_info(cb->repo, oid, NULL);
934 + if (repo_submodule_init(&subrepo, cb->repo, cb->path, null_oid())) {
935 + cb->result = 0;
936 + goto cleanup;
937 + }
938 +
939 + type = oid_object_info(&subrepo, oid, NULL);
940
941 switch (type) {
942 case OBJ_COMMIT:
936 - return 0;
943 + goto cleanup;
944 case OBJ_BAD:
945 /*
946 * Object is missing or invalid. If invalid, an error message
947 * has already been printed.
948 */
949 cb->result = 0;
943 - return 0;
950 + goto cleanup;
951 default:
952 die(_("submodule entry '%s' (%s) is a %s, not a commit"),
953 cb->path, oid_to_hex(oid), type_name(type));
954 }
955 +cleanup:
956 + repo_clear(&subrepo);
957 + return 0;
958 }
959
960 static int submodule_has_commits(struct repository *r,
t/t5526-fetch-submodules.sh
+3
@@ -6,6 +6,9 @@ test_description='Recursive "git fetch" for submodules'
6 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
7 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8
9 +GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
10 +export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
11 +
12 . ./test-lib.sh
13
14 pwd=$(pwd)
t/t5531-deep-submodule-push.sh
+3
@@ -5,6 +5,9 @@ test_description='test push with submodules'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 +GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
9 +export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
10 +
11 . ./test-lib.sh
12
13 test_expect_success setup '
t/t5545-push-options.sh
+3
@@ -5,6 +5,9 @@ test_description='pushing to a repository using push options'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 +GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
9 +export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
10 +
11 . ./test-lib.sh
12
13 mk_repo_pair () {
t/t5572-pull-submodule.sh
+3
@@ -2,6 +2,9 @@
2
3 test_description='pull can handle submodules'
4
5 +GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
6 +export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
7 +
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/lib-submodule-update.sh
10
t/t7418-submodule-sparse-gitmodules.sh
+3
@@ -12,6 +12,9 @@ The test setup uses a sparse checkout, however the same scenario can be set up
12 also by committing .gitmodules and then just removing it from the filesystem.
13 '
14
15 +GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
16 +export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
17 +
18 . ./test-lib.sh
19
20 test_expect_success 'sparse checkout setup which hides .gitmodules' '