[PATCH 09/12] commit-graph: mark incomplete commit graph chains
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Nov 16, 2026, 13:07 UTC
- Message-ID
- <20261116-pks-odb-pluggable-commit-graphs-v1-9-a83fc1ff0808@pks.im>
- In-Reply-To
- <20261116-pks-odb-pluggable-commit-graphs-v1-0-a83fc1ff0808@pks.im>
When loading a commit graph chain it may happen that we only find a subset of its layers. Such a commit graph is still usable though in the case where we have the base and layers building on top of it, so we still return such an incomplete commit graph to the caller.
While valid and usable, we of course want to warn about such commit graphs in `git commit-graph verify`, which is why there is an `incomplete` out-parameter in `load_commit_graph_chain_fd_st()`. In a subsequent commit though we want to hide this function in favor of a pluggable interface, but carrying such a flag there feels wrong.
Instead, have the function set a new `incomplete` field in the commit graph structure itself.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- builtin/commit-graph.c | 9 ++++----- commit-graph.c | 9 ++++----- commit-graph.h | 4 ++-- 3 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 2a5a75dc22f..5ecce4b6caa 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -66,7 +66,6 @@ static int cmd_commit_graph_verify(int argc, enum commit_graph_verify_flags flags = isatty(2) ? COMMIT_GRAPH_VERIFY_PROGRESS : 0; int fd; struct stat st; - int incomplete_chain = 0; int ret; struct option options[] = { OPT_BIT(0, "shallow", &flags, @@ -113,20 +112,20 @@ static int cmd_commit_graph_verify(int argc, else if (opened == OPENED_GRAPH) graph = commit_graph_read(repo, fd, &st); else - graph = load_commit_graph_chain_fd_st(repo->objects, fd, &st, - &incomplete_chain); + graph = load_commit_graph_chain_fd_st(repo->objects, fd, &st); if (!graph) return 1; ret = commit_graph_verify(graph, flags); - commit_graph_free(graph); - if (incomplete_chain) { + if (graph->incomplete) { error("one or more commit-graph chain files could not be loaded"); ret |= 1; } + commit_graph_free(graph); + return ret; } diff --git a/commit-graph.c b/commit-graph.c index 7bb6b112b2e..0ae9f586f21 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -651,8 +651,7 @@ int open_commit_graph_chain(const char *chain_file, } struct commit_graph *load_commit_graph_chain_fd_st(struct object_database *odb, - int fd, struct stat *st, - int *incomplete_chain) + int fd, struct stat *st) { struct commit_graph *graph_chain = NULL; struct strbuf line = STRBUF_INIT; @@ -703,11 +702,12 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct object_database *odb, } commit_graph_validate_chain(graph_chain); + if (graph_chain) + graph_chain->incomplete = !valid; fclose(fp); strbuf_release(&line); - *incomplete_chain = !valid; return graph_chain; } @@ -720,9 +720,8 @@ static struct commit_graph *load_commit_graph_chain(struct repository *repo, struct commit_graph *g = NULL; if (open_commit_graph_chain(chain_file, &fd, &st, repo->hash_algo)) { - int incomplete; /* ownership of fd is taken over by load function */ - g = load_commit_graph_chain_fd_st(repo->objects, fd, &st, &incomplete); + g = load_commit_graph_chain_fd_st(repo->objects, fd, &st); } free(chain_file); diff --git a/commit-graph.h b/commit-graph.h index 1cc0d097321..3b5e0eb2d73 100644 --- a/commit-graph.h +++ b/commit-graph.h @@ -93,6 +93,7 @@ struct commit_graph { struct object_id oid; char *dir; char *filename; + bool incomplete; uint32_t num_commits_in_base; unsigned int read_generation_data; @@ -124,8 +125,7 @@ struct commit_graph { struct commit_graph *commit_graph_read(struct repository *repo, int fd, struct stat *st); struct commit_graph *load_commit_graph_chain_fd_st(struct object_database *odb, - int fd, struct stat *st, - int *incomplete_chain); + int fd, struct stat *st); /* * Link the commit graph layer `g` on top of the chain `base`. `base` may be
-- 2.56.1.763.g16177fe143.dirty