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

[PATCH 07/10] commit-graph: fix mixup of write/verify flags

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 4, 2026, 15:57 UTC
Message-ID
<20261104-pks-commit-graph-write-refactorings-v1-7-d013d9401a59@pks.im>
In-Reply-To
<20261104-pks-commit-graph-write-refactorings-v1-0-d013d9401a59@pks.im>

While we already have flags specific to `verify_commit_graph()`, the function also uses `COMMIT_GRAPH_WRITE_PROGRESS`. This mixup is a bit of a footgun though, as it may easily happen that the value of that flag is the exact same value as a future `COMMIT_GRAPH_VERIFY_*` flag.

Fix this mixup by introducing a new `COMMIT_GRAPH_VERIFY_PROGRESS` flag. While at it, convert the verify flags into an enum.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/commit-graph.c | 4 ++--
 commit-graph.c         | 5 +++--
 commit-graph.h         | 8 ++++++--
 3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index f2c374d0176..09b09d6ac5c 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -70,9 +70,9 @@ static int cmd_commit_graph_verify(int argc,
 	char *graph_name;
 	char *chain_name;
 	enum { OPENED_NONE, OPENED_GRAPH, OPENED_CHAIN } opened = OPENED_NONE;
+	enum commit_graph_verify_flags flags = 0;
 	int fd;
 	struct stat st;
-	int flags = 0;
 	int incomplete_chain = 0;
 	int ret;
 	struct option options[] = {
@@ -97,7 +97,7 @@ static int cmd_commit_graph_verify(int argc,
 	if (opts.shallow)
 		flags |= COMMIT_GRAPH_VERIFY_SHALLOW;
 	if (opts.progress)
-		flags |= COMMIT_GRAPH_WRITE_PROGRESS;
+		flags |= COMMIT_GRAPH_VERIFY_PROGRESS;
 
 	dir = odb_source_files_find_dir(repo->objects, opts.obj_dir);
 	if (!dir)
diff --git a/commit-graph.c b/commit-graph.c
index 077213b5336..c82776b0667 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -2904,7 +2904,8 @@ static int verify_one_commit_graph(struct commit_graph *g,
 	return verify_commit_graph_error;
 }
 
-int verify_commit_graph(struct commit_graph *g, int flags)
+int verify_commit_graph(struct commit_graph *g,
+			enum commit_graph_verify_flags flags)
 {
 	struct progress *progress = NULL;
 	int local_error = 0;
@@ -2915,7 +2916,7 @@ int verify_commit_graph(struct commit_graph *g, int flags)
 		return 1;
 	}
 
-	if (flags & COMMIT_GRAPH_WRITE_PROGRESS) {
+	if (flags & COMMIT_GRAPH_VERIFY_PROGRESS) {
 		uint64_t total = g->num_commits;
 		if (!(flags & COMMIT_GRAPH_VERIFY_SHALLOW))
 			total += g->num_commits_in_base;
diff --git a/commit-graph.h b/commit-graph.h
index 0e03e82a04a..80d59bd23bd 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -199,9 +199,13 @@ int write_commit_graph(struct repository *r,
 		       const char *dir,
 		       const struct commit_graph_write_options *opts);
 
-#define COMMIT_GRAPH_VERIFY_SHALLOW	(1 << 0)
+enum commit_graph_verify_flags {
+	COMMIT_GRAPH_VERIFY_SHALLOW = (1 << 0),
+	COMMIT_GRAPH_VERIFY_PROGRESS = (1 << 1),
+};
 
-int verify_commit_graph(struct commit_graph *g, int flags);
+int verify_commit_graph(struct commit_graph *g,
+			enum commit_graph_verify_flags flags);
 
 void close_commit_graph(struct object_database *);
 void free_commit_graph(struct commit_graph *);
-- 
2.56.0.500.g5d06dc02cd.dirty
Previous: Kristofer KarlssonNext: Patrick Steinhardt
Message 14 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.