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

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 1, 2025 at 14:22 UTC bd52ea343d2af91574fedcf765250f44f3d624d4
4 files changed +12 -7
builtin/commit-graph.c
+2 -2
@@ -101,7 +101,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
101 if (opts.progress)
102 flags |= COMMIT_GRAPH_WRITE_PROGRESS;
103
104 - source = find_odb(the_repository, opts.obj_dir);
104 + source = odb_find_source(the_repository->objects, opts.obj_dir);
105 graph_name = get_commit_graph_filename(source);
106 chain_name = get_commit_graph_chain_filename(source);
107 if (open_commit_graph(graph_name, &fd, &st))
@@ -289,7 +289,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
289 git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
290 flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
291
292 - source = find_odb(the_repository, opts.obj_dir);
292 + source = odb_find_source(the_repository->objects, opts.obj_dir);
293
294 if (opts.reachable) {
295 if (write_commit_graph_reachable(source, flags, &write_opts))
midx-write.c
+1 -1
@@ -922,7 +922,7 @@ static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
922 struct strbuf cur_path_real = STRBUF_INIT;
923
924 /* Ensure the given object_dir is local, or a known alternate. */
925 - find_odb(r, obj_dir_real);
925 + odb_find_source(r->objects, obj_dir_real);
926
927 for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
928 strbuf_realpath(&cur_path_real, cur->object_dir, 1);
odb.c
+3 -3
@@ -448,14 +448,14 @@ out:
448 return ref_git;
449 }
450
451 -struct odb_source *find_odb(struct repository *r, const char *obj_dir)
451 +struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir)
452 {
453 struct odb_source *source;
454 char *obj_dir_real = real_pathdup(obj_dir, 1);
455 struct strbuf odb_path_real = STRBUF_INIT;
456
457 - prepare_alt_odb(r);
458 - for (source = r->objects->sources; source; source = source->next) {
457 + prepare_alt_odb(odb->repo);
458 + for (source = odb->sources; source; source = source->next) {
459 strbuf_realpath(&odb_path_real, source->path, 1);
460 if (!strcmp(obj_dir_real, odb_path_real.buf))
461 break;
odb.h
+6 -1
@@ -68,7 +68,6 @@ struct odb_source {
68 void prepare_alt_odb(struct repository *r);
69 int has_alt_odb(struct repository *r);
70 char *compute_alternate_path(const char *path, struct strbuf *err);
71 -struct odb_source *find_odb(struct repository *r, const char *obj_dir);
71 typedef int alt_odb_fn(struct odb_source *, void *);
72 int foreach_alt_odb(alt_odb_fn, void*);
73 typedef void alternate_ref_fn(const struct object_id *oid, void *);
@@ -195,6 +194,12 @@ struct object_database {
194 struct object_database *odb_new(struct repository *repo);
195 void odb_clear(struct object_database *o);
196
197 +/*
198 + * Find source by its object directory path. Dies in case the source couldn't
199 + * be found.
200 + */
201 +struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
202 +
203 /*
204 * Create a temporary file rooted in the object database directory, or
205 * die on failure. The filename is taken from "pattern", which should have the