Skip to content

Commit 870ed81

Browse files
pks-tgitster
authored andcommitted
odb: allow odb_find_source() to fail
When trying to locate a source for an unknown object directory we will die right away. In subsequent patches we will add new callsites though that want to handle this situation gracefully instead. Refactor the function to return a `NULL` pointer if the source could not be found and adapt the callsites to die instead. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4a67e25 commit 870ed81

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

builtin/commit-graph.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
102102
flags |= COMMIT_GRAPH_WRITE_PROGRESS;
103103

104104
source = odb_find_source(the_repository->objects, opts.obj_dir);
105+
if (!source)
106+
die(_("could not find object directory matching %s"), opts.obj_dir);
105107
graph_name = get_commit_graph_filename(source);
106108
chain_name = get_commit_graph_chain_filename(source);
107109
if (open_commit_graph(graph_name, &fd, &st))
@@ -290,6 +292,8 @@ static int graph_write(int argc, const char **argv, const char *prefix,
290292
flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
291293

292294
source = odb_find_source(the_repository->objects, opts.obj_dir);
295+
if (!source)
296+
die(_("could not find object directory matching %s"), opts.obj_dir);
293297

294298
if (opts.reachable) {
295299
if (write_commit_graph_reachable(source, flags, &write_opts))

midx-write.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,8 @@ static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
917917
const char *object_dir)
918918
{
919919
struct odb_source *source = odb_find_source(r->objects, object_dir);
920+
if (!source)
921+
die(_("could not find object directory matching %s"), object_dir);
920922
return get_multi_pack_index(source);
921923
}
922924

odb.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,6 @@ struct odb_source *odb_find_source(struct object_database *odb, const char *obj_
464464
free(obj_dir_real);
465465
strbuf_release(&odb_path_real);
466466

467-
if (!source)
468-
die(_("could not find object directory matching %s"), obj_dir);
469467
return source;
470468
}
471469

odb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ struct object_database *odb_new(struct repository *repo);
186186
void odb_clear(struct object_database *o);
187187

188188
/*
189-
* Find source by its object directory path. Dies in case the source couldn't
190-
* be found.
189+
* Find source by its object directory path. Returns a `NULL` pointer in case
190+
* the source could not be found.
191191
*/
192192
struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
193193

0 commit comments

Comments
 (0)