summaryrefslogtreecommitdiff
path: root/commit-graph.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2019-06-12 13:29:43 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-06-12 18:20:54 (GMT)
commit014e3440f524a620fd8aba92f1efeac737d9c23d (patch)
treea3b30fdee2caebf08d5560183336b06c6e50ce64 /commit-graph.c
parentb2c83060525e69f628fb32836e311978e3899e6e (diff)
downloadgit-014e3440f524a620fd8aba92f1efeac737d9c23d.zip
git-014e3440f524a620fd8aba92f1efeac737d9c23d.tar.gz
git-014e3440f524a620fd8aba92f1efeac737d9c23d.tar.bz2
commit-graph: extract count_distinct_commits()
The write_commit_graph() method is too complex, so we are extracting helper functions one by one. Extract count_distinct_commits(), which sorts the oids list, then iterates through to find duplicates. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit-graph.c')
-rw-r--r--commit-graph.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/commit-graph.c b/commit-graph.c
index 61cb43d..1a0a875 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -963,6 +963,27 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
stop_progress(&ctx->progress);
}
+static uint32_t count_distinct_commits(struct write_commit_graph_context *ctx)
+{
+ uint32_t i, count_distinct = 1;
+
+ if (ctx->report_progress)
+ ctx->progress = start_delayed_progress(
+ _("Counting distinct commits in commit graph"),
+ ctx->oids.nr);
+ display_progress(ctx->progress, 0); /* TODO: Measure QSORT() progress */
+ QSORT(ctx->oids.list, ctx->oids.nr, commit_compare);
+
+ for (i = 1; i < ctx->oids.nr; i++) {
+ display_progress(ctx->progress, i + 1);
+ if (!oideq(&ctx->oids.list[i - 1], &ctx->oids.list[i]))
+ count_distinct++;
+ }
+ stop_progress(&ctx->progress);
+
+ return count_distinct;
+}
+
int write_commit_graph(const char *obj_dir,
struct string_list *pack_indexes,
struct string_list *commit_hex,
@@ -1024,19 +1045,7 @@ int write_commit_graph(const char *obj_dir,
close_reachable(ctx);
- if (ctx->report_progress)
- ctx->progress = start_delayed_progress(
- _("Counting distinct commits in commit graph"),
- ctx->oids.nr);
- display_progress(ctx->progress, 0); /* TODO: Measure QSORT() progress */
- QSORT(ctx->oids.list, ctx->oids.nr, commit_compare);
- count_distinct = 1;
- for (i = 1; i < ctx->oids.nr; i++) {
- display_progress(ctx->progress, i + 1);
- if (!oideq(&ctx->oids.list[i - 1], &ctx->oids.list[i]))
- count_distinct++;
- }
- stop_progress(&ctx->progress);
+ count_distinct = count_distinct_commits(ctx);
if (count_distinct >= GRAPH_EDGE_LAST_MASK) {
error(_("the commit graph format cannot write %d commits"), count_distinct);