progress API: unify stop_progress{,_msg}(), fix trace2 bug

Fix a bug that's been with us ever since 98a13647408 (trace2: log progress time and throughput, 2020-05-12), when the stop_progress_msg() API was used we didn't log a "region_leave" for the "region_enter" we start in "start_progress_delay()". The only user of the "stop_progress_msg()" function is "index-pack". Let's add a previously failing test to check that we have the same number of "region_enter" and "region_leave" events, with "-v" we'll log progress even in the test environment. In addition to that we've had a submarine bug here introduced with 9d81ecb52b5 (progress: add sparse mode to force 100% complete message, 2019-03-21). The "start_sparse_progress()" API would only do the right thing if the progress was ended with "stop_progress()", not "stop_progress_msg()". The only user of that API uses "stop_progress()", but let's still fix that along with the trace2 issue by making "stop_progress()" a trivial wrapper for "stop_progress_msg()". We can also drop the "if (progress)" test from "finish_if_sparse()". It's now a helper for the small "stop_progress_msg()" function. We'll already have returned from it if "progress" is "NULL". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 3, 2022 at 22:40 UTC 74900a6b3513e0908b1d16df7855e9d478b20b91
3 files changed +13 -20
progress.c
+3 -18
@@ -311,8 +311,7 @@ struct progress *start_delayed_sparse_progress(const char *title,
311
312 static void finish_if_sparse(struct progress *progress)
313 {
314 - if (progress &&
315 - progress->sparse &&
314 + if (progress->sparse &&
315 progress->last_value != progress->total)
316 display_progress(progress, progress->total);
317 }
@@ -347,22 +346,6 @@ static void log_trace2(struct progress *progress)
346 trace2_region_leave("progress", progress->title, the_repository);
347 }
348
350 -void stop_progress(struct progress **p_progress)
351 -{
352 - struct progress *progress;
353 -
354 - if (!p_progress)
355 - BUG("don't provide NULL to stop_progress");
356 - progress = *p_progress;
357 -
358 - finish_if_sparse(progress);
359 -
360 - if (progress)
361 - log_trace2(*p_progress);
362 -
363 - stop_progress_msg(p_progress, _("done"));
364 -}
365 -
349 void stop_progress_msg(struct progress **p_progress, const char *msg)
350 {
351 struct progress *progress;
@@ -375,8 +358,10 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
358 return;
359 *p_progress = NULL;
360
361 + finish_if_sparse(progress);
362 if (progress->last_value != -1)
363 force_last_update(progress, msg);
364 + log_trace2(progress);
365
366 clear_progress_signal();
367 strbuf_release(&progress->counters_sb);
progress.h
+5 -1
@@ -1,5 +1,6 @@
1 #ifndef PROGRESS_H
2 #define PROGRESS_H
3 +#include "gettext.h"
4
5 struct progress;
6
@@ -19,5 +20,8 @@ struct progress *start_delayed_progress(const char *title, uint64_t total);
20 struct progress *start_delayed_sparse_progress(const char *title,
21 uint64_t total);
22 void stop_progress_msg(struct progress **p_progress, const char *msg);
22 -void stop_progress(struct progress **p_progress);
23 +static inline void stop_progress(struct progress **p_progress)
24 +{
25 + stop_progress_msg(p_progress, _("done"));
26 +}
27 #endif
t/t5316-pack-delta-depth.sh
+5 -1
@@ -61,7 +61,11 @@ test_expect_success 'create series of packs' '
61 echo $cur
62 echo "$(git rev-parse :file) file"
63 } | git pack-objects --stdout >tmp &&
64 - git index-pack --stdin --fix-thin <tmp || return 1
64 + GIT_TRACE2_EVENT=$PWD/trace \
65 + git index-pack -v --stdin --fix-thin <tmp || return 1 &&
66 + grep -c region_enter.*progress trace >enter &&
67 + grep -c region_leave.*progress trace >leave &&
68 + test_cmp enter leave &&
69 prev=$cur
70 done
71 '