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

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

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 2, 2025, 10:27 UTC
Message-ID
<20250602-pks-object-store-wo-the-repository-v4-5-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 `find_odb()` by passing in the object database in which we want to search for the source and adjusting all callers.

Rename the function to `odb_find_source()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/commit-graph.c | 4 ++--
 midx-write.c           | 2 +-
 odb.c                  | 6 +++---
 odb.h                  | 7 ++++++-
 4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index f04eaba5259..77d7e88a98c 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -101,7 +101,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
 	if (opts.progress)
 		flags |= COMMIT_GRAPH_WRITE_PROGRESS;
 
-	source = find_odb(the_repository, opts.obj_dir);
+	source = odb_find_source(the_repository->objects, opts.obj_dir);
 	graph_name = get_commit_graph_filename(source);
 	chain_name = get_commit_graph_chain_filename(source);
 	if (open_commit_graph(graph_name, &fd, &st))
@@ -289,7 +289,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
 	    git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
 		flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
 
-	source = find_odb(the_repository, opts.obj_dir);
+	source = odb_find_source(the_repository->objects, opts.obj_dir);
 
 	if (opts.reachable) {
 		if (write_commit_graph_reachable(source, flags, &write_opts))
diff --git a/midx-write.c b/midx-write.c
index ba4a94950a8..f2cfb85476e 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -922,7 +922,7 @@ static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
 	struct strbuf cur_path_real = STRBUF_INIT;
 
 	/* Ensure the given object_dir is local, or a known alternate. */
-	find_odb(r, obj_dir_real);
+	odb_find_source(r->objects, obj_dir_real);
 
 	for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
 		strbuf_realpath(&cur_path_real, cur->object_dir, 1);
diff --git a/odb.c b/odb.c
index afb16f4c693..483b9b38414 100644
--- a/odb.c
+++ b/odb.c
@@ -448,14 +448,14 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
 	return ref_git;
 }
 
-struct odb_source *find_odb(struct repository *r, const char *obj_dir)
+struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir)
 {
 	struct odb_source *source;
 	char *obj_dir_real = real_pathdup(obj_dir, 1);
 	struct strbuf odb_path_real = STRBUF_INIT;
 
-	prepare_alt_odb(r);
-	for (source = r->objects->sources; source; source = source->next) {
+	prepare_alt_odb(odb->repo);
+	for (source = odb->sources; source; source = source->next) {
 		strbuf_realpath(&odb_path_real, source->path, 1);
 		if (!strcmp(obj_dir_real, odb_path_real.buf))
 			break;
diff --git a/odb.h b/odb.h
index f1c903d103c..a9e802f5831 100644
--- a/odb.h
+++ b/odb.h
@@ -68,7 +68,6 @@ struct odb_source {
 void prepare_alt_odb(struct repository *r);
 int has_alt_odb(struct repository *r);
 char *compute_alternate_path(const char *path, struct strbuf *err);
-struct odb_source *find_odb(struct repository *r, const char *obj_dir);
 typedef int alt_odb_fn(struct odb_source *, void *);
 int foreach_alt_odb(alt_odb_fn, void*);
 typedef void alternate_ref_fn(const struct object_id *oid, void *);
@@ -195,6 +194,12 @@ struct object_database {
 struct object_database *odb_new(struct repository *repo);
 void odb_clear(struct object_database *o);
 
+/*
+ * Find source by its object directory path. Dies in case the source couldn't
+ * be found.
+ */
+struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
+
 /*
  * Create a temporary file rooted in the object database directory, or
  * die on failure. The filename is taken from "pattern", which should have the
-- 
2.50.0.rc0.629.g846fc57c9e.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 10 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.