[PATCH 09/10] odb/source-files: verify commit-graphs as part of fsck
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Nov 4, 2026, 15:57 UTC
- Message-ID
- <20261104-pks-commit-graph-write-refactorings-v1-9-d013d9401a59@pks.im>
- In-Reply-To
- <20261104-pks-commit-graph-write-refactorings-v1-0-d013d9401a59@pks.im>
git-fsck(1) verifies commit-graphs by downcasting the object database's source to the "files" backend and spawning `git commit-graph verify --object-dir` for each of its object directories. But starting with 14bf3a43f8b (Merge branch 'ps/odb-pluggable-fsck', 2026-09-15) we have adapted git-fsck(1) so that the verification of the object database is pluggable.
In a subsequent patch series we're also about to make commit graphs themselves pluggable so that a backend can choose where exactly a commit graph is stored. As part of that, we'll also have to make verification of commit graphs pluggable in the same way.
Move the verification into `odb_source_files_fsck()`, same as we did for multi-pack indices, bitmaps and all the other auxiliary data structures. Same as when we adapted consistency checks for those, there are a couple of consequences here:
- Commit graphs stored in alternates are only verified when
`ODB_FSCK_FULL` is set, which is the default for git-fsck(1). - Commit-graphs are not verified with `--connectivity-only` anymore,
as that mode skips the object database checks altogether. - Failures are reported via `ERROR_OBJECT` instead of a dedicated
exit code bit, same as we have dropped `ERROR_MIDX` et al. Those
error codes were never documented or exercised anywhere.Signed-off-by: Patrick Steinhardt <ps@pks.im> --- builtin/fsck.c | 20 -------------------- odb/source-files.c | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c index 710780e35a8..c4558efcf18 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -46,7 +46,6 @@ static timestamp_t now; #define ERROR_OBJECT 01 #define ERROR_REACHABLE 02 #define ERROR_REFS 010 -#define ERROR_COMMIT_GRAPH 020 static const char *describe_object(const struct object_id *oid) { @@ -913,7 +912,6 @@ int cmd_fsck(int argc, fsck_enable_object_names(&fsck_walk_options); repo_config(repo, git_fsck_config, &fsck_obj_options); - prepare_repo_settings(repo); if (check_references) fsck_refs(repo); @@ -984,24 +982,6 @@ int cmd_fsck(int argc, check_connectivity(repo); - if (repo->settings.core_commit_graph) { - struct odb_source_files *files = odb_source_files_downcast(repo->objects->source); - struct child_process commit_graph_verify = CHILD_PROCESS_INIT; - - for (struct odb_files_dir *dir = files->dirs; dir; dir = dir->next) { - child_process_init(&commit_graph_verify); - commit_graph_verify.git_cmd = 1; - strvec_pushl(&commit_graph_verify.args, "commit-graph", - "verify", "--object-dir", dir->abspath, NULL); - if (show_progress) - strvec_push(&commit_graph_verify.args, "--progress"); - else - strvec_push(&commit_graph_verify.args, "--no-progress"); - if (run_command(&commit_graph_verify)) - errors_found |= ERROR_COMMIT_GRAPH; - } - } - free_snapshot_refs(&snap); return errors_found; } diff --git a/odb/source-files.c b/odb/source-files.c index 5b4277fbfd3..224b47e38b1 100644 --- a/odb/source-files.c +++ b/odb/source-files.c @@ -1215,6 +1215,30 @@ static int odb_source_files_generate_pack(struct odb_source *source UNUSED, return 0; } +static int fsck_commit_graph(struct odb_source_files *files, + struct odb_files_dir *dir, + struct odb_fsck_options *opts) +{ + struct repository *repo = files->base.odb->repo; + struct child_process commit_graph_verify = CHILD_PROCESS_INIT; + + prepare_repo_settings(repo); + if (!repo->settings.core_commit_graph) + return 0; + + commit_graph_verify.git_cmd = 1; + strvec_pushl(&commit_graph_verify.args, "commit-graph", "verify", + "--object-dir", dir->abspath, NULL); + if (opts->flags & ODB_FSCK_PROGRESS) + strvec_push(&commit_graph_verify.args, "--progress"); + else + strvec_push(&commit_graph_verify.args, "--no-progress"); + if (run_command(&commit_graph_verify)) + return -1; + + return 0; +} + static int odb_source_files_fsck(struct odb_source *source, struct odb_fsck_options *opts) { @@ -1227,6 +1251,7 @@ static int odb_source_files_fsck(struct odb_source *source, ret |= odb_source_fsck(&dir->loose->base, opts); ret |= odb_source_fsck(&dir->packed->base, opts); + ret |= fsck_commit_graph(files, dir, opts); } return ret;
-- 2.56.0.500.g5d06dc02cd.dirty