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

[PATCH] commit-graph: use commit_list_count()

From
René Scharfe <l.s.r@web.de>
Date
Sep 15, 2019, 17:07 UTC
Message-ID
<1d28fb89-6ed6-b70f-762c-b65cffeb6705@web.de>

Let commit_list_count() count the number of parents instead of duplicating it. Also store the result in an unsigned int, as that's what the function returns, and the count is never negative.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 commit-graph.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/commit-graph.c b/commit-graph.c
index 9b02d2c426..5b0d6b5adc 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1279,7 +1279,6 @@ static uint32_t count_distinct_commits(struct write_commit_graph_context *ctx)
 static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
 {
 	uint32_t i;
-	struct commit_list *parent;

 	ctx->num_extra_edges = 0;
 	if (ctx->report_progress)
@@ -1287,7 +1286,8 @@ static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
 			_("Finding extra edges in commit graph"),
 			ctx->oids.nr);
 	for (i = 0; i < ctx->oids.nr; i++) {
-		int num_parents = 0;
+		unsigned int num_parents;
+
 		display_progress(ctx->progress, i + 1);
 		if (i > 0 && oideq(&ctx->oids.list[i - 1], &ctx->oids.list[i]))
 			continue;
@@ -1301,10 +1301,7 @@ static void copy_oids_to_commits(struct write_commit_graph_context *ctx)

 		parse_commit_no_graph(ctx->commits.list[ctx->commits.nr]);

-		for (parent = ctx->commits.list[ctx->commits.nr]->parents;
-		     parent; parent = parent->next)
-			num_parents++;
-
+		num_parents = commit_list_count(ctx->commits.list[ctx->commits.nr]->parents);
 		if (num_parents > 2)
 			ctx->num_extra_edges += num_parents - 1;

@@ -1616,8 +1613,7 @@ static int commit_compare(const void *_a, const void *_b)

 static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
 {
-	uint32_t i, num_parents;
-	struct commit_list *parent;
+	uint32_t i;

 	if (ctx->report_progress)
 		ctx->progress = start_delayed_progress(
@@ -1635,10 +1631,9 @@ static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
 			die(_("unexpected duplicate commit id %s"),
 			    oid_to_hex(&ctx->commits.list[i]->object.oid));
 		} else {
-			num_parents = 0;
-			for (parent = ctx->commits.list[i]->parents; parent; parent = parent->next)
-				num_parents++;
+			unsigned int num_parents;

+			num_parents = commit_list_count(ctx->commits.list[i]->parents);
 			if (num_parents > 2)
 				ctx->num_extra_edges += num_parents - 1;
 		}
--
2.23.0
Next: Derrick Stolee
Message 1 of 2 in “commit-graph: use commit_list_count()”
  1. commit-graph: use commit_list_count()René Scharfe, Sep 15, 2019
  2. Derrick StoleeSep 16, 2019

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.