git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 16 of 22 in “commit-graph: several refactorings for writing commit graphs”
  1. 00/10 commit-graph: several refactorings for writing commit graphsPatrick Steinhardt, Nov 4, 2026
  2. 01/10 commit-graph: rename `struct commit_graph_opts`Patrick Steinhardt, Nov 4, 2026
  3. 02/10 commit-graph: pass writer flags via optionsPatrick Steinhardt, Nov 4, 2026
  4. 03/10 commit-graph: drop `NULL` checks for write optionsPatrick Steinhardt, Nov 4, 2026
  5. 04/10 commit-graph: drop redundant flags in write contextPatrick Steinhardt, Nov 4, 2026
  6. Junio C HamanoNov 4, 2026
  7. 05/10 commit-graph: merge the two commit graph writersPatrick Steinhardt, Nov 4, 2026
  8. Derrick StoleeNov 4, 2026
  9. 06/10 commit-graph: move remaining write parameters into optionsPatrick Steinhardt, Nov 4, 2026
  10. Derrick StoleeNov 4, 2026
  11. Kristofer KarlssonNov 4, 2026
  12. Patrick SteinhardtNov 5, 2026
  13. Kristofer KarlssonNov 5, 2026
  14. 07/10 commit-graph: fix mixup of write/verify flagsPatrick Steinhardt, Nov 4, 2026
  15. 08/10 builtin/commit-graph: set flags directlyPatrick Steinhardt, Nov 4, 2026
  16. 09/10 odb/source-files: verify commit-graphs as part of fsckPatrick Steinhardt, Nov 4, 2026
  17. 10/10 commit-graph: modernize function namesPatrick Steinhardt, Nov 4, 2026
  18. Derrick StoleeNov 4, 2026
  19. Patrick SteinhardtNov 5, 2026
  20. Patrick SteinhardtNov 5, 2026
  21. Derrick StoleeNov 5, 2026
  22. Patrick SteinhardtNov 5, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.