Skip to content

Commit 41a5cf6

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dae4a6a commit 41a5cf6

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

builtin/commit-graph.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
101101
if (opts.progress)
102102
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
103103

104-
source = find_odb(the_repository, opts.obj_dir);
104+
source = odb_find_source(the_repository->objects, opts.obj_dir);
105105
graph_name = get_commit_graph_filename(source);
106106
chain_name = get_commit_graph_chain_filename(source);
107107
if (open_commit_graph(graph_name, &fd, &st))
@@ -289,7 +289,7 @@ static int graph_write(int argc, const char **argv, const char *prefix,
289289
git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
290290
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
291291

292-
source = find_odb(the_repository, opts.obj_dir);
292+
source = odb_find_source(the_repository->objects, opts.obj_dir);
293293

294294
if (opts.reachable) {
295295
if (write_commit_graph_reachable(source, flags, &write_opts))

midx-write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
922922
struct strbuf cur_path_real = STRBUF_INIT;
923923

924924
/* 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);
926926

927927
for (cur = get_multi_pack_index(r); cur; cur = cur->next) {
928928
strbuf_realpath(&cur_path_real, cur->object_dir, 1);

odb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,14 +448,14 @@ char *compute_alternate_path(const char *path, struct strbuf *err)
448448
return ref_git;
449449
}
450450

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)
452452
{
453453
struct odb_source *source;
454454
char *obj_dir_real = real_pathdup(obj_dir, 1);
455455
struct strbuf odb_path_real = STRBUF_INIT;
456456

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) {
459459
strbuf_realpath(&odb_path_real, source->path, 1);
460460
if (!strcmp(obj_dir_real, odb_path_real.buf))
461461
break;

odb.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ struct odb_source {
6868
void prepare_alt_odb(struct repository *r);
6969
int has_alt_odb(struct repository *r);
7070
char *compute_alternate_path(const char *path, struct strbuf *err);
71-
struct odb_source *find_odb(struct repository *r, const char *obj_dir);
7271
typedef int alt_odb_fn(struct odb_source *, void *);
7372
int foreach_alt_odb(alt_odb_fn, void*);
7473
typedef void alternate_ref_fn(const struct object_id *oid, void *);
@@ -195,6 +194,12 @@ struct object_database {
195194
struct object_database *odb_new(struct repository *repo);
196195
void odb_clear(struct object_database *o);
197196

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+
198203
/*
199204
* Create a temporary file rooted in the object database directory, or
200205
* die on failure. The filename is taken from "pattern", which should have the

0 commit comments

Comments
 (0)