commit-graph.c: avoid duplicated progress output during `verify`

When `git commit-graph verify` was taught how to verify commit-graph chains in 3da4b609bb1 (commit-graph: verify chains with --shallow mode, 2019-06-18), it produced one line of progress per layer of the commit-graph chain. $ git.compile commit-graph verify Verifying commits in commit graph: 100% (4356/4356), done. Verifying commits in commit graph: 100% (131912/131912), done. This could be somewhat confusing to users, who may wonder why there are multiple occurrences of "Verifying commits in commit graph". There are likely good arguments on whether or not there should be one line of progress output per commit-graph layer. On the one hand, the existing output shows us verifying each individual layer of the chain. But on the other hand, the fact that a commit-graph may be stored among multiple layers is an implementation detail that the caller need not be aware of. Clarify this by showing a single progress meter regardless of the number of layers in the commit-graph chain. After this patch, the output reflects the logical contents of a commit-graph chain, instead of showing one line of output per commit-graph layer: $ git.compile commit-graph verify Verifying commits in commit graph: 100% (136268/136268), done. Signed-off-by: Taylor Blau <me@ttaylorr.com> Acked-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Jul 7, 2023 at 20:31 UTC 9281cd07f014263b5385f13b47ff8399282c7cdc
2 files changed +19 -11
commit-graph.c
+17 -10
@@ -2545,7 +2545,8 @@ static int commit_graph_checksum_valid(struct commit_graph *g)
2545
2546 static int verify_one_commit_graph(struct repository *r,
2547 struct commit_graph *g,
2548 - struct progress *progress)
2548 + struct progress *progress,
2549 + uint64_t *seen)
2550 {
2551 uint32_t i, cur_fanout_pos = 0;
2552 struct object_id prev_oid, cur_oid;
@@ -2606,7 +2607,7 @@ static int verify_one_commit_graph(struct repository *r,
2607 timestamp_t max_generation = 0;
2608 timestamp_t generation;
2609
2609 - display_progress(progress, i + 1);
2610 + display_progress(progress, ++(*seen));
2611 oidread(&cur_oid, g->chunk_oid_lookup + g->hash_len * i);
2612
2613 graph_commit = lookup_commit(r, &cur_oid);
@@ -2695,26 +2696,32 @@ static int verify_one_commit_graph(struct repository *r,
2696
2697 int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
2698 {
2699 + struct progress *progress = NULL;
2700 int local_error = 0;
2701 + uint64_t seen = 0;
2702
2703 if (!g) {
2704 graph_report("no commit-graph file loaded");
2705 return 1;
2706 }
2707
2705 - for (; g; g = g->base_graph) {
2706 - struct progress *progress = NULL;
2707 - if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
2708 - progress = start_progress(_("Verifying commits in commit graph"),
2709 - g->num_commits);
2708 + if (flags & COMMIT_GRAPH_WRITE_PROGRESS) {
2709 + uint64_t total = g->num_commits;
2710 + if (!(flags & COMMIT_GRAPH_VERIFY_SHALLOW))
2711 + total += g->num_commits_in_base;
2712 +
2713 + progress = start_progress(_("Verifying commits in commit graph"),
2714 + total);
2715 + }
2716
2711 - local_error |= verify_one_commit_graph(r, g, progress);
2717 + for (; g; g = g->base_graph) {
2718 + local_error |= verify_one_commit_graph(r, g, progress, &seen);
2719 if (flags & COMMIT_GRAPH_VERIFY_SHALLOW)
2720 break;
2714 -
2715 - stop_progress(&progress);
2721 }
2722
2723 + stop_progress(&progress);
2724 +
2725 return local_error;
2726 }
2727
t/t5324-split-commit-graph.sh
+2 -1
@@ -351,7 +351,8 @@ test_expect_success 'add octopus merge' '
351 git branch merge/octopus &&
352 git commit-graph write --reachable --split &&
353 git commit-graph verify --progress 2>err &&
354 - test_line_count = 3 err &&
354 + test_line_count = 1 err &&
355 + grep "Verifying commits in commit graph: 100% (18/18)" err &&
356 test_i18ngrep ! warning err &&
357 test_line_count = 3 $graphdir/commit-graph-chain
358 '