summaryrefslogtreecommitdiff
path: root/progress.c
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-02-03 21:40:17 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-02-03 23:39:55 (GMT)
commitaccf1eb1d0f102c6b8f099fa6063216818e45c6b (patch)
treefdc8adec03a7ef6d0f64dcccae32c7b4df1e2c61 /progress.c
parent1ccad6a1f175080c3896a70501dcd6c9e0a0af0a (diff)
downloadgit-accf1eb1d0f102c6b8f099fa6063216818e45c6b.zip
git-accf1eb1d0f102c6b8f099fa6063216818e45c6b.tar.gz
git-accf1eb1d0f102c6b8f099fa6063216818e45c6b.tar.bz2
progress.c: refactor stop_progress{,_msg}() to use helpers
Create two new static helpers for the stop_progress() and stop_progress_msg() functions. As we'll see in the subsequent commit having those two split up doesn't make much sense, and results in a bug in how we log to trace2. This narrow preparatory change makes the diff for that subsequent change smaller. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'progress.c')
-rw-r--r--progress.c64
1 files changed, 36 insertions, 28 deletions
diff --git a/progress.c b/progress.c
index 6e7daa3..6cc7f90 100644
--- a/progress.c
+++ b/progress.c
@@ -317,6 +317,36 @@ static void finish_if_sparse(struct progress *progress)
display_progress(progress, progress->total);
}
+static void force_last_update(struct progress *progress, const char *msg)
+{
+ char *buf;
+ struct throughput *tp = progress->throughput;
+
+ if (tp) {
+ uint64_t now_ns = progress_getnanotime(progress);
+ unsigned int misecs, rate;
+ misecs = ((now_ns - progress->start_ns) * 4398) >> 32;
+ rate = tp->curr_total / (misecs ? misecs : 1);
+ throughput_string(&tp->display, tp->curr_total, rate);
+ }
+ progress_update = 1;
+ buf = xstrfmt(", %s.\n", msg);
+ display(progress, progress->last_value, buf);
+ free(buf);
+}
+
+static void log_trace2(struct progress *progress)
+{
+ trace2_data_intmax("progress", the_repository, "total_objects",
+ progress->total);
+
+ if (progress->throughput)
+ trace2_data_intmax("progress", the_repository, "total_bytes",
+ progress->throughput->curr_total);
+
+ trace2_region_leave("progress", progress->title, the_repository);
+}
+
void stop_progress(struct progress **p_progress)
{
struct progress *progress;
@@ -327,17 +357,8 @@ void stop_progress(struct progress **p_progress)
finish_if_sparse(progress);
- if (progress) {
- trace2_data_intmax("progress", the_repository, "total_objects",
- progress->total);
-
- if (progress->throughput)
- trace2_data_intmax("progress", the_repository,
- "total_bytes",
- progress->throughput->curr_total);
-
- trace2_region_leave("progress", progress->title, the_repository);
- }
+ if (progress)
+ log_trace2(*p_progress);
stop_progress_msg(p_progress, _("done"));
}
@@ -353,23 +374,10 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
if (!progress)
return;
*p_progress = NULL;
- if (progress->last_value != -1) {
- /* Force the last update */
- char *buf;
- struct throughput *tp = progress->throughput;
-
- if (tp) {
- uint64_t now_ns = progress_getnanotime(progress);
- unsigned int misecs, rate;
- misecs = ((now_ns - progress->start_ns) * 4398) >> 32;
- rate = tp->curr_total / (misecs ? misecs : 1);
- throughput_string(&tp->display, tp->curr_total, rate);
- }
- progress_update = 1;
- buf = xstrfmt(", %s.\n", msg);
- display(progress, progress->last_value, buf);
- free(buf);
- }
+
+ if (progress->last_value != -1)
+ force_last_update(progress, msg);
+
clear_progress_signal();
strbuf_release(&progress->counters_sb);
if (progress->throughput)