Skip to content

Commit e4c8180

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 41a5cf6 commit e4c8180

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

builtin/commit-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static int parse_parent_arg_callback(const struct option *opt,
4848
if (repo_get_oid_commit(the_repository, arg, &oid))
4949
die(_("not a valid object name %s"), arg);
5050

51-
assert_oid_type(&oid, OBJ_COMMIT);
51+
odb_assert_oid_type(the_repository->objects, &oid, OBJ_COMMIT);
5252
new_parent(lookup_commit(the_repository, &oid), parents);
5353
return 0;
5454
}

commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
17061706
/* Not having i18n.commitencoding is the same as having utf-8 */
17071707
encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
17081708

1709-
assert_oid_type(tree, OBJ_TREE);
1709+
odb_assert_oid_type(the_repository->objects, tree, OBJ_TREE);
17101710

17111711
if (memchr(msg, '\0', msg_len))
17121712
return error("a NUL byte in commit log message not allowed.");

odb.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,9 +946,10 @@ int has_object(struct repository *r, const struct object_id *oid,
946946
return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
947947
}
948948

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)
950951
{
951-
enum object_type type = oid_object_info(the_repository, oid, NULL);
952+
enum object_type type = oid_object_info(odb->repo, oid, NULL);
952953
if (type < 0)
953954
die(_("%s is not a valid object"), oid_to_hex(oid));
954955
if (type != expect)

odb.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ enum {
302302
int has_object(struct repository *r, const struct object_id *oid,
303303
unsigned flags);
304304

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);
306307

307308
/*
308309
* Enabling the object read lock allows multiple threads to safely call the

0 commit comments

Comments
 (0)