Skip to content

Commit 689a146

Browse files
rscharfegitster
authored andcommitted
commit-graph: use commit_list_count()
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 <[email protected]> Acked-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5fa0f52 commit 689a146

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

commit-graph.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,15 +1276,15 @@ static uint32_t count_distinct_commits(struct write_commit_graph_context *ctx)
12761276
static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
12771277
{
12781278
uint32_t i;
1279-
struct commit_list *parent;
12801279

12811280
ctx->num_extra_edges = 0;
12821281
if (ctx->report_progress)
12831282
ctx->progress = start_delayed_progress(
12841283
_("Finding extra edges in commit graph"),
12851284
ctx->oids.nr);
12861285
for (i = 0; i < ctx->oids.nr; i++) {
1287-
int num_parents = 0;
1286+
unsigned int num_parents;
1287+
12881288
display_progress(ctx->progress, i + 1);
12891289
if (i > 0 && oideq(&ctx->oids.list[i - 1], &ctx->oids.list[i]))
12901290
continue;
@@ -1298,10 +1298,7 @@ static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
12981298

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

1301-
for (parent = ctx->commits.list[ctx->commits.nr]->parents;
1302-
parent; parent = parent->next)
1303-
num_parents++;
1304-
1301+
num_parents = commit_list_count(ctx->commits.list[ctx->commits.nr]->parents);
13051302
if (num_parents > 2)
13061303
ctx->num_extra_edges += num_parents - 1;
13071304

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

16141611
static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
16151612
{
1616-
uint32_t i, num_parents;
1617-
struct commit_list *parent;
1613+
uint32_t i;
16181614

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

1633+
num_parents = commit_list_count(ctx->commits.list[i]->parents);
16391634
if (num_parents > 2)
16401635
ctx->num_extra_edges += num_parents - 1;
16411636
}

0 commit comments

Comments
 (0)