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 alternate and adjusting all callers. Rename the function to `odb_find_alternate()`. Signed-off-by: Patrick Steinhardt <ps@xxxxxx> --- 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 ae8ac52a975..90c767797e2 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; - alternate = find_odb(the_repository, opts.obj_dir); + alternate = odb_find_alternate(the_repository->objects, opts.obj_dir); graph_name = get_commit_graph_filename(alternate); chain_name = get_commit_graph_chain_filename(alternate); 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; - alternate = find_odb(the_repository, opts.obj_dir); + alternate = odb_find_alternate(the_repository->objects, opts.obj_dir); if (opts.reachable) { if (write_commit_graph_reachable(alternate, flags, &write_opts)) diff --git a/midx-write.c b/midx-write.c index dd3b3070e55..dd65800e8b3 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_alternate(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 2b36735087e..621a16b35ea 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_alternate *find_odb(struct repository *r, const char *obj_dir) +struct odb_alternate *odb_find_alternate(struct object_database *odb, const char *obj_dir) { struct odb_alternate *alternate; char *obj_dir_real = real_pathdup(obj_dir, 1); struct strbuf odb_path_real = STRBUF_INIT; - prepare_alt_odb(r); - for (alternate = r->objects->alternates; alternate; alternate = alternate->next) { + prepare_alt_odb(odb->repo); + for (alternate = odb->alternates; alternate; alternate = alternate->next) { strbuf_realpath(&odb_path_real, alternate->path, 1); if (!strcmp(obj_dir_real, odb_path_real.buf)) break; diff --git a/odb.h b/odb.h index 745e38c1931..60d6358c2c6 100644 --- a/odb.h +++ b/odb.h @@ -58,7 +58,6 @@ struct odb_alternate { 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_alternate *find_odb(struct repository *r, const char *obj_dir); typedef int alt_odb_fn(struct odb_alternate *, void *); int foreach_alt_odb(alt_odb_fn, void*); typedef void alternate_ref_fn(const struct object_id *oid, void *); @@ -185,6 +184,12 @@ struct object_database { struct object_database *odb_new(struct repository *repo); void odb_clear(struct object_database *o); +/* + * Find backend by its object directory path. Dies in case the object directory + * couldn't be found. + */ +struct odb_alternate *odb_find_alternate(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.49.0.1077.gc0e912fd4c.dirty