odb: get rid of `the_repository` in `assert_oid_type()`

Get rid of our dependency on `the_repository` in `assert_oid_type()` by passing in the object database as a parameter and adjusting all callers. Rename the function to `odb_assert_oid_type()`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 1, 2025 at 14:22 UTC 961038856bcd319289a226e29503358123c0a1ba
4 files changed +7 -5
builtin/commit-tree.c
+1 -1
@@ -48,7 +48,7 @@ static int parse_parent_arg_callback(const struct option *opt,
48 if (repo_get_oid_commit(the_repository, arg, &oid))
49 die(_("not a valid object name %s"), arg);
50
51 - assert_oid_type(&oid, OBJ_COMMIT);
51 + odb_assert_oid_type(the_repository->objects, &oid, OBJ_COMMIT);
52 new_parent(lookup_commit(the_repository, &oid), parents);
53 return 0;
54 }
commit.c
+1 -1
@@ -1706,7 +1706,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
1706 /* Not having i18n.commitencoding is the same as having utf-8 */
1707 encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
1708
1709 - assert_oid_type(tree, OBJ_TREE);
1709 + odb_assert_oid_type(the_repository->objects, tree, OBJ_TREE);
1710
1711 if (memchr(msg, '\0', msg_len))
1712 return error("a NUL byte in commit log message not allowed.");
odb.c
+3 -2
@@ -946,9 +946,10 @@ int has_object(struct repository *r, const struct object_id *oid,
946 return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
947 }
948
949 -void assert_oid_type(const struct object_id *oid, enum object_type expect)
949 +void odb_assert_oid_type(struct object_database *odb,
950 + const struct object_id *oid, enum object_type expect)
951 {
951 - enum object_type type = oid_object_info(the_repository, oid, NULL);
952 + enum object_type type = oid_object_info(odb->repo, oid, NULL);
953 if (type < 0)
954 die(_("%s is not a valid object"), oid_to_hex(oid));
955 if (type != expect)
odb.h
+2 -1
@@ -302,7 +302,8 @@ enum {
302 int has_object(struct repository *r, const struct object_id *oid,
303 unsigned flags);
304
305 -void assert_oid_type(const struct object_id *oid, enum object_type expect);
305 +void odb_assert_oid_type(struct object_database *odb,
306 + const struct object_id *oid, enum object_type expect);
307
308 /*
309 * Enabling the object read lock allows multiple threads to safely call the