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 backend and adjusting all callers. Rename the function to `odb_find_backend()`. Signed-off-by: Patrick Steinhardt <ps@xxxxxx> --- builtin/commit-graph.c | 18 +++++++++--------- midx-write.c | 2 +- odb.c | 14 +++++++------- odb.h | 7 ++++++- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 0a184d39720..28550d3bcc9 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -66,7 +66,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) { struct commit_graph *graph = NULL; - struct odb_backend *odb = NULL; + struct odb_backend *backend = NULL; char *graph_name; char *chain_name; enum { OPENED_NONE, OPENED_GRAPH, OPENED_CHAIN } opened = OPENED_NONE; @@ -101,9 +101,9 @@ static int graph_verify(int argc, const char **argv, const char *prefix, if (opts.progress) flags |= COMMIT_GRAPH_WRITE_PROGRESS; - odb = find_odb(the_repository, opts.obj_dir); - graph_name = get_commit_graph_filename(odb); - chain_name = get_commit_graph_chain_filename(odb); + backend = odb_find_backend(the_repository->objects, opts.obj_dir); + graph_name = get_commit_graph_filename(backend); + chain_name = get_commit_graph_chain_filename(backend); if (open_commit_graph(graph_name, &fd, &st)) opened = OPENED_GRAPH; else if (errno != ENOENT) @@ -120,7 +120,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix, if (opened == OPENED_NONE) return 0; else if (opened == OPENED_GRAPH) - graph = load_commit_graph_one_fd_st(the_repository, fd, &st, odb); + graph = load_commit_graph_one_fd_st(the_repository, fd, &st, backend); else graph = load_commit_graph_chain_fd_st(the_repository, fd, &st, &incomplete_chain); @@ -221,7 +221,7 @@ static int graph_write(int argc, const char **argv, const char *prefix, struct string_list pack_indexes = STRING_LIST_INIT_DUP; struct strbuf buf = STRBUF_INIT; struct oidset commits = OIDSET_INIT; - struct odb_backend *odb = NULL; + struct odb_backend *backend = NULL; int result = 0; enum commit_graph_write_flags flags = 0; struct progress *progress = NULL; @@ -289,10 +289,10 @@ 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; - odb = find_odb(the_repository, opts.obj_dir); + backend = odb_find_backend(the_repository->objects, opts.obj_dir); if (opts.reachable) { - if (write_commit_graph_reachable(odb, flags, &write_opts)) + if (write_commit_graph_reachable(backend, flags, &write_opts)) result = 1; goto cleanup; } @@ -318,7 +318,7 @@ static int graph_write(int argc, const char **argv, const char *prefix, stop_progress(&progress); } - if (write_commit_graph(odb, + if (write_commit_graph(backend, opts.stdin_packs ? &pack_indexes : NULL, opts.stdin_commits ? &commits : NULL, flags, diff --git a/midx-write.c b/midx-write.c index dd3b3070e55..e8371a84a14 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_backend(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 67207ce636d..6359c541d78 100644 --- a/odb.c +++ b/odb.c @@ -448,15 +448,15 @@ char *compute_alternate_path(const char *path, struct strbuf *err) return ref_git; } -struct odb_backend *find_odb(struct repository *r, const char *obj_dir) +struct odb_backend *odb_find_backend(struct object_database *odb, const char *obj_dir) { - struct odb_backend *odb; + struct odb_backend *backend; char *obj_dir_real = real_pathdup(obj_dir, 1); struct strbuf odb_path_real = STRBUF_INIT; - prepare_alt_odb(r); - for (odb = r->objects->backends; odb; odb = odb->next) { - strbuf_realpath(&odb_path_real, odb->path, 1); + prepare_alt_odb(odb->repo); + for (backend = odb->backends; backend; backend = backend->next) { + strbuf_realpath(&odb_path_real, backend->path, 1); if (!strcmp(obj_dir_real, odb_path_real.buf)) break; } @@ -464,9 +464,9 @@ struct odb_backend *find_odb(struct repository *r, const char *obj_dir) free(obj_dir_real); strbuf_release(&odb_path_real); - if (!odb) + if (!backend) die(_("could not find object directory matching %s"), obj_dir); - return odb; + return backend; } static void fill_alternate_refs_command(struct child_process *cmd, diff --git a/odb.h b/odb.h index 1617a9bac2c..a8c0f788969 100644 --- a/odb.h +++ b/odb.h @@ -56,7 +56,6 @@ struct odb_backend { 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_backend *find_odb(struct repository *r, const char *obj_dir); typedef int alt_odb_fn(struct odb_backend *, void *); int foreach_alt_odb(alt_odb_fn, void*); typedef void alternate_ref_fn(const struct object_id *oid, void *); @@ -183,6 +182,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_backend *odb_find_backend(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.1045.g170613ef41.dirty