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>
maint
Patrick Steinhardt 2025-07-01 14:22:17 +02:00 committed by Junio C Hamano
parent 2f5181fce6
commit bd52ea343d
4 changed files with 12 additions and 7 deletions

View File

@ -101,7 +101,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
if (opts.progress) if (opts.progress)
flags |= COMMIT_GRAPH_WRITE_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); graph_name = get_commit_graph_filename(source);
chain_name = get_commit_graph_chain_filename(source); chain_name = get_commit_graph_chain_filename(source);
if (open_commit_graph(graph_name, &fd, &st)) 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)) git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS; 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 (opts.reachable) {
if (write_commit_graph_reachable(source, flags, &write_opts)) if (write_commit_graph_reachable(source, flags, &write_opts))

View File

@ -922,7 +922,7 @@ static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
struct strbuf cur_path_real = STRBUF_INIT; struct strbuf cur_path_real = STRBUF_INIT;


/* Ensure the given object_dir is local, or a known alternate. */ /* 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) { for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
strbuf_realpath(&cur_path_real, cur->object_dir, 1); strbuf_realpath(&cur_path_real, cur->object_dir, 1);

6
odb.c
View File

@ -448,14 +448,14 @@ out:
return ref_git; 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; struct odb_source *source;
char *obj_dir_real = real_pathdup(obj_dir, 1); char *obj_dir_real = real_pathdup(obj_dir, 1);
struct strbuf odb_path_real = STRBUF_INIT; struct strbuf odb_path_real = STRBUF_INIT;


prepare_alt_odb(r); prepare_alt_odb(odb->repo);
for (source = r->objects->sources; source; source = source->next) { for (source = odb->sources; source; source = source->next) {
strbuf_realpath(&odb_path_real, source->path, 1); strbuf_realpath(&odb_path_real, source->path, 1);
if (!strcmp(obj_dir_real, odb_path_real.buf)) if (!strcmp(obj_dir_real, odb_path_real.buf))
break; break;

7
odb.h
View File

@ -68,7 +68,6 @@ struct odb_source {
void prepare_alt_odb(struct repository *r); void prepare_alt_odb(struct repository *r);
int has_alt_odb(struct repository *r); int has_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err); 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 *); typedef int alt_odb_fn(struct odb_source *, void *);
int foreach_alt_odb(alt_odb_fn, void*); int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, 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); struct object_database *odb_new(struct repository *repo);
void odb_clear(struct object_database *o); 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 * Create a temporary file rooted in the object database directory, or
* die on failure. The filename is taken from "pattern", which should have the * die on failure. The filename is taken from "pattern", which should have the