Skip to content

Commit 2a1e28b

Browse files
derrickstoleegitster
authored andcommitted
commit-graph: extract copy_oids_to_commits()
The write_commit_graph() method is too complex, so we are extracting methods one by one. Extract copy_oids_to_commits(), which fills the commits list with the distinct commits from the oids list. During this loop, it also counts the number of "extra" edges from octopus merges. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b012f3e commit 2a1e28b

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

commit-graph.c

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,37 @@ static uint32_t count_distinct_commits(struct write_commit_graph_context *ctx)
984984
return count_distinct;
985985
}
986986

987+
static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
988+
{
989+
uint32_t i;
990+
struct commit_list *parent;
991+
992+
ctx->num_extra_edges = 0;
993+
if (ctx->report_progress)
994+
ctx->progress = start_delayed_progress(
995+
_("Finding extra edges in commit graph"),
996+
ctx->oids.nr);
997+
for (i = 0; i < ctx->oids.nr; i++) {
998+
int num_parents = 0;
999+
display_progress(ctx->progress, i + 1);
1000+
if (i > 0 && oideq(&ctx->oids.list[i - 1], &ctx->oids.list[i]))
1001+
continue;
1002+
1003+
ctx->commits.list[ctx->commits.nr] = lookup_commit(ctx->r, &ctx->oids.list[i]);
1004+
parse_commit_no_graph(ctx->commits.list[ctx->commits.nr]);
1005+
1006+
for (parent = ctx->commits.list[ctx->commits.nr]->parents;
1007+
parent; parent = parent->next)
1008+
num_parents++;
1009+
1010+
if (num_parents > 2)
1011+
ctx->num_extra_edges += num_parents - 1;
1012+
1013+
ctx->commits.nr++;
1014+
}
1015+
stop_progress(&ctx->progress);
1016+
}
1017+
9871018
int write_commit_graph(const char *obj_dir,
9881019
struct string_list *pack_indexes,
9891020
struct string_list *commit_hex,
@@ -997,7 +1028,6 @@ int write_commit_graph(const char *obj_dir,
9971028
uint32_t chunk_ids[5];
9981029
uint64_t chunk_offsets[5];
9991030
int num_chunks;
1000-
struct commit_list *parent;
10011031
const unsigned hashsz = the_hash_algo->rawsz;
10021032
struct strbuf progress_title = STRBUF_INIT;
10031033
int res = 0;
@@ -1056,30 +1086,7 @@ int write_commit_graph(const char *obj_dir,
10561086
ctx->commits.alloc = count_distinct;
10571087
ALLOC_ARRAY(ctx->commits.list, ctx->commits.alloc);
10581088

1059-
ctx->num_extra_edges = 0;
1060-
if (ctx->report_progress)
1061-
ctx->progress = start_delayed_progress(
1062-
_("Finding extra edges in commit graph"),
1063-
ctx->oids.nr);
1064-
for (i = 0; i < ctx->oids.nr; i++) {
1065-
int num_parents = 0;
1066-
display_progress(ctx->progress, i + 1);
1067-
if (i > 0 && oideq(&ctx->oids.list[i - 1], &ctx->oids.list[i]))
1068-
continue;
1069-
1070-
ctx->commits.list[ctx->commits.nr] = lookup_commit(ctx->r, &ctx->oids.list[i]);
1071-
parse_commit_no_graph(ctx->commits.list[ctx->commits.nr]);
1072-
1073-
for (parent = ctx->commits.list[ctx->commits.nr]->parents;
1074-
parent; parent = parent->next)
1075-
num_parents++;
1076-
1077-
if (num_parents > 2)
1078-
ctx->num_extra_edges += num_parents - 1;
1079-
1080-
ctx->commits.nr++;
1081-
}
1082-
stop_progress(&ctx->progress);
1089+
copy_oids_to_commits(ctx);
10831090

10841091
if (ctx->commits.nr >= GRAPH_EDGE_LAST_MASK) {
10851092
error(_("too many commits to write graph"));

0 commit comments

Comments
 (0)