git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 06/17] odb: get rid of `the_repository` in `assert_oid_type()`

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 2, 2025, 10:27 UTC
Message-ID
<20250602-pks-object-store-wo-the-repository-v4-6-e986804a7c62@pks.im>
In-Reply-To
<20250602-pks-object-store-wo-the-repository-v4-0-e986804a7c62@pks.im>

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>
---
 builtin/commit-tree.c | 2 +-
 commit.c              | 2 +-
 odb.c                 | 5 +++--
 odb.h                 | 3 ++-
 4 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index 546069f8682..31cfd9bd15d 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -48,7 +48,7 @@ static int parse_parent_arg_callback(const struct option *opt,
 	if (repo_get_oid_commit(the_repository, arg, &oid))
 		die(_("not a valid object name %s"), arg);
 
-	assert_oid_type(&oid, OBJ_COMMIT);
+	odb_assert_oid_type(the_repository->objects, &oid, OBJ_COMMIT);
 	new_parent(lookup_commit(the_repository, &oid), parents);
 	return 0;
 }
diff --git a/commit.c b/commit.c
index 1d30f8ce15a..aa65183d8b6 100644
--- a/commit.c
+++ b/commit.c
@@ -1706,7 +1706,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
 	/* Not having i18n.commitencoding is the same as having utf-8 */
 	encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
 
-	assert_oid_type(tree, OBJ_TREE);
+	odb_assert_oid_type(the_repository->objects, tree, OBJ_TREE);
 
 	if (memchr(msg, '\0', msg_len))
 		return error("a NUL byte in commit log message not allowed.");
diff --git a/odb.c b/odb.c
index 483b9b38414..3a3ceed5508 100644
--- a/odb.c
+++ b/odb.c
@@ -946,9 +946,10 @@ int has_object(struct repository *r, const struct object_id *oid,
 	return oid_object_info_extended(r, oid, NULL, object_info_flags) >= 0;
 }
 
-void assert_oid_type(const struct object_id *oid, enum object_type expect)
+void odb_assert_oid_type(struct object_database *odb,
+			 const struct object_id *oid, enum object_type expect)
 {
-	enum object_type type = oid_object_info(the_repository, oid, NULL);
+	enum object_type type = oid_object_info(odb->repo, oid, NULL);
 	if (type < 0)
 		die(_("%s is not a valid object"), oid_to_hex(oid));
 	if (type != expect)
diff --git a/odb.h b/odb.h
index a9e802f5831..7b64358d678 100644
--- a/odb.h
+++ b/odb.h
@@ -302,7 +302,8 @@ enum {
 int has_object(struct repository *r, const struct object_id *oid,
 	       unsigned flags);
 
-void assert_oid_type(const struct object_id *oid, enum object_type expect);
+void odb_assert_oid_type(struct object_database *odb,
+			 const struct object_id *oid, enum object_type expect);
 
 /*
  * Enabling the object read lock allows multiple threads to safely call the
-- 
2.50.0.rc0.629.g846fc57c9e.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 12 of 23 in “object-store: carve out the object database subsystem”
  1. 00/17 object-store: carve out the object database subsystemPatrick Steinhardt, Jun 2, 2025
  2. 01/17 object-store: rename `raw_object_store` to `object_database`Patrick Steinhardt, Jun 2, 2025
  3. Toon ClaesJun 4, 2025
  4. Patrick SteinhardtJun 4, 2025
  5. 03/17 object-store: rename files to "odb.{c,h}"Patrick Steinhardt, Jun 2, 2025
  6. 02/17 object-store: rename `object_directory` to `odb_source`Patrick Steinhardt, Jun 2, 2025
  7. Toon ClaesJun 4, 2025
  8. Patrick SteinhardtJun 4, 2025
  9. 04/17 odb: introduce parent pointersPatrick Steinhardt, Jun 2, 2025
  10. 05/17 odb: get rid of `the_repository` in `find_odb()`Patrick Steinhardt, Jun 2, 2025
  11. 07/17 odb: get rid of `the_repository` in `odb_mkstemp()`Patrick Steinhardt, Jun 2, 2025
  12. 06/17 odb: get rid of `the_repository` in `assert_oid_type()`Patrick Steinhardt, Jun 2, 2025
  13. 09/17 odb: get rid of `the_repository` in `for_each()` functionsPatrick Steinhardt, Jun 2, 2025
  14. 08/17 odb: get rid of `the_repository` when handling alternatesPatrick Steinhardt, Jun 2, 2025
  15. 11/17 odb: get rid of `the_repository` when handling submodule sourcesPatrick Steinhardt, Jun 2, 2025
  16. 10/17 odb: get rid of `the_repository` when handling the primary sourcePatrick Steinhardt, Jun 2, 2025
  17. 12/17 odb: trivial refactorings to get rid of `the_repository`Patrick Steinhardt, Jun 2, 2025
  18. 13/17 odb: rename `oid_object_info()`Patrick Steinhardt, Jun 2, 2025
  19. 15/17 odb: rename `has_object()`Patrick Steinhardt, Jun 2, 2025
  20. 14/17 odb: rename `repo_read_object_file()`Patrick Steinhardt, Jun 2, 2025
  21. 17/17 odb: rename `read_object_with_reference()`Patrick Steinhardt, Jun 2, 2025
  22. 16/17 odb: rename `pretend_object_file()`Patrick Steinhardt, Jun 2, 2025
  23. Junio C HamanoJun 2, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.