commit-graph: extract copy_oids_to_commits()
The write_commit_graph() method is too complex, so we are extracting helper functions 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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Jun 12, 2019 at 06:29 UTC
f998d542260ec643875e7f0fa860dbb43c2388ca
1 file changed
+32
-25
commit-graph.c
+32
-25
@@ -984,6 +984,37 @@ static uint32_t count_distinct_commits(struct write_commit_graph_context *ctx)
984
return count_distinct;
985
}
986
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
+
1018
int write_commit_graph(const char *obj_dir,
1019
struct string_list *pack_indexes,
1020
struct string_list *commit_hex,
@@ -997,7 +1028,6 @@ int write_commit_graph(const char *obj_dir,
1028
uint32_t chunk_ids[5];
1029
uint64_t chunk_offsets[5];
1030
int num_chunks;
1000
- struct commit_list *parent;
1031
const unsigned hashsz = the_hash_algo->rawsz;
1032
struct strbuf progress_title = STRBUF_INIT;
1033
int res = 0;
@@ -1056,30 +1086,7 @@ int write_commit_graph(const char *obj_dir,
1086
ctx->commits.alloc = count_distinct;
1087
ALLOC_ARRAY(ctx->commits.list, ctx->commits.alloc);
1088
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);
1090
1091
if (ctx->commits.nr >= GRAPH_EDGE_LAST_MASK) {
1092
error(_("too many commits to write graph"));