Skip to content

Commit 74900a6

Browse files
avargitster
authored andcommitted
progress API: unify stop_progress{,_msg}(), fix trace2 bug
Fix a bug that's been with us ever since 98a1364 (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 9d81ecb (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent accf1eb commit 74900a6

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

progress.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ struct progress *start_delayed_sparse_progress(const char *title,
311311

312312
static void finish_if_sparse(struct progress *progress)
313313
{
314-
if (progress &&
315-
progress->sparse &&
314+
if (progress->sparse &&
316315
progress->last_value != progress->total)
317316
display_progress(progress, progress->total);
318317
}
@@ -347,22 +346,6 @@ static void log_trace2(struct progress *progress)
347346
trace2_region_leave("progress", progress->title, the_repository);
348347
}
349348

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-
366349
void stop_progress_msg(struct progress **p_progress, const char *msg)
367350
{
368351
struct progress *progress;
@@ -375,8 +358,10 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
375358
return;
376359
*p_progress = NULL;
377360

361+
finish_if_sparse(progress);
378362
if (progress->last_value != -1)
379363
force_last_update(progress, msg);
364+
log_trace2(progress);
380365

381366
clear_progress_signal();
382367
strbuf_release(&progress->counters_sb);

progress.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#ifndef PROGRESS_H
22
#define PROGRESS_H
3+
#include "gettext.h"
34

45
struct progress;
56

@@ -19,5 +20,8 @@ struct progress *start_delayed_progress(const char *title, uint64_t total);
1920
struct progress *start_delayed_sparse_progress(const char *title,
2021
uint64_t total);
2122
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+
}
2327
#endif

t/t5316-pack-delta-depth.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ test_expect_success 'create series of packs' '
6161
echo $cur
6262
echo "$(git rev-parse :file) file"
6363
} | 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 &&
6569
prev=$cur
6670
done
6771
'

0 commit comments

Comments
 (0)