Skip to content

Commit b012f3e

Browse files
derrickstoleegitster
authored andcommitted
commit-graph: extract count_distinct_commits()
The write_commit_graph() method is too complex, so we are extracting methods one by one. Extract count_distinct_commits(), which sorts the oids list, then iterates through to find duplicates. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 93ba186 commit b012f3e

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

commit-graph.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,27 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
963963
stop_progress(&ctx->progress);
964964
}
965965

966+
static uint32_t count_distinct_commits(struct write_commit_graph_context *ctx)
967+
{
968+
uint32_t i, count_distinct = 1;
969+
970+
if (ctx->report_progress)
971+
ctx->progress = start_delayed_progress(
972+
_("Counting distinct commits in commit graph"),
973+
ctx->oids.nr);
974+
display_progress(ctx->progress, 0); /* TODO: Measure QSORT() progress */
975+
QSORT(ctx->oids.list, ctx->oids.nr, commit_compare);
976+
977+
for (i = 1; i < ctx->oids.nr; i++) {
978+
display_progress(ctx->progress, i + 1);
979+
if (!oideq(&ctx->oids.list[i - 1], &ctx->oids.list[i]))
980+
count_distinct++;
981+
}
982+
stop_progress(&ctx->progress);
983+
984+
return count_distinct;
985+
}
986+
966987
int write_commit_graph(const char *obj_dir,
967988
struct string_list *pack_indexes,
968989
struct string_list *commit_hex,
@@ -1024,19 +1045,7 @@ int write_commit_graph(const char *obj_dir,
10241045

10251046
close_reachable(ctx);
10261047

1027-
if (ctx->report_progress)
1028-
ctx->progress = start_delayed_progress(
1029-
_("Counting distinct commits in commit graph"),
1030-
ctx->oids.nr);
1031-
display_progress(ctx->progress, 0); /* TODO: Measure QSORT() progress */
1032-
QSORT(ctx->oids.list, ctx->oids.nr, commit_compare);
1033-
count_distinct = 1;
1034-
for (i = 1; i < ctx->oids.nr; i++) {
1035-
display_progress(ctx->progress, i + 1);
1036-
if (!oideq(&ctx->oids.list[i - 1], &ctx->oids.list[i]))
1037-
count_distinct++;
1038-
}
1039-
stop_progress(&ctx->progress);
1048+
count_distinct = count_distinct_commits(ctx);
10401049

10411050
if (count_distinct >= GRAPH_EDGE_LAST_MASK) {
10421051
error(_("the commit graph format cannot write %d commits"), count_distinct);

0 commit comments

Comments
 (0)