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

[PATCH 3/6] commit-graph.c: extract `verify_one_commit_graph()`

From
Taylor Blau <me@ttaylorr.com>
Date
Jul 8, 2023, 00:31 UTC
Message-ID
<8fa8871063018946e47515898c57377825ec95a8.1688776280.git.me@ttaylorr.com>
In-Reply-To
<cover.1688776280.git.me@ttaylorr.com>

When the `verify_commit_graph()` function was extended to support commit-graph chains via 3da4b609bb1 (commit-graph: verify chains with --shallow mode, 2019-06-18), it did so by recursively calling itself on each layer of the commit-graph chain.

In practice this poses no issues, since commit-graph chains do not loop, and there are few enough of them that adding additional frames to the stack is not a problem.

A future commit will consolidate the progress output from `git commit-graph verify` when verifying chained commit-graphs to print a single line instead of one progress meter per commit-graph layer. Prepare for this by extracting a routine to verify a single layer of a commit-graph.

Note that `verify_commit_graph()` is still recursive after this patch, but this will change in the subsequent patch.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 commit-graph.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/commit-graph.c b/commit-graph.c
index f70afccada4..3d7cc11927d 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -2542,18 +2542,14 @@ static int commit_graph_checksum_valid(struct commit_graph *g)
 	return hashfile_checksum_valid(g->data, g->data_len);
 }
 
-int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
+static int verify_one_commit_graph(struct repository *r,
+				   struct commit_graph *g,
+				   int flags)
 {
 	uint32_t i, cur_fanout_pos = 0;
 	struct object_id prev_oid, cur_oid;
 	int generation_zero = 0;
 	struct progress *progress = NULL;
-	int local_error = 0;
-
-	if (!g) {
-		graph_report("no commit-graph file loaded");
-		return 1;
-	}
 
 	verify_commit_graph_error = verify_commit_graph_lite(g);
 	if (verify_commit_graph_error)
@@ -2699,7 +2695,19 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
 	}
 	stop_progress(&progress);
 
-	local_error = verify_commit_graph_error;
+	return verify_commit_graph_error;
+}
+
+int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
+{
+	int local_error = 0;
+
+	if (!g) {
+		graph_report("no commit-graph file loaded");
+		return 1;
+	}
+
+	local_error = verify_one_commit_graph(r, g, flags);
 
 	if (!(flags & COMMIT_GRAPH_VERIFY_SHALLOW) && g->base_graph)
 		local_error |= verify_commit_graph(r, g->base_graph, flags);
-- 
2.41.0.242.g6eec849fa5a
Previous: Taylor BlauNext: Taylor Blau
Message 4 of 8 in “fsck: squelch progress output with `--no-progress`”
  1. 0/6 fsck: squelch progress output with `--no-progress`Taylor Blau, Jul 8, 2023
  2. 1/6 fsck: suppress commit-graph output with `--no-progress`Taylor Blau, Jul 8, 2023
  3. 2/6 fsck: suppress MIDX output with `--no-progress`Taylor Blau, Jul 8, 2023
  4. 3/6 commit-graph.c: extract `verify_one_commit_graph()`Taylor Blau, Jul 8, 2023
  5. 4/6 commit-graph.c: iteratively verify commit-graph chainsTaylor Blau, Jul 8, 2023
  6. 5/6 commit-graph.c: pass progress to `verify_one_commit_graph()`Taylor Blau, Jul 8, 2023
  7. 6/6 commit-graph.c: avoid duplicated progress output during `verify`Taylor Blau, Jul 8, 2023
  8. Derrick StoleeJul 10, 2023

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.