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>
Ævar Arnfjörð Bjarmason committed
Feb 3, 2022 at 22:40 UTC
accf1eb1d0f102c6b8f099fa6063216818e45c6b
1 file changed
+36
-28
progress.c
+36
-28
@@ -317,6 +317,36 @@ static void finish_if_sparse(struct progress *progress)
317
display_progress(progress, progress->total);
318
}
319
320
+static void force_last_update(struct progress *progress, const char *msg)
321
+{
322
+ char *buf;
323
+ struct throughput *tp = progress->throughput;
324
+
325
+ if (tp) {
326
+ uint64_t now_ns = progress_getnanotime(progress);
327
+ unsigned int misecs, rate;
328
+ misecs = ((now_ns - progress->start_ns) * 4398) >> 32;
329
+ rate = tp->curr_total / (misecs ? misecs : 1);
330
+ throughput_string(&tp->display, tp->curr_total, rate);
331
+ }
332
+ progress_update = 1;
333
+ buf = xstrfmt(", %s.\n", msg);
334
+ display(progress, progress->last_value, buf);
335
+ free(buf);
336
+}
337
+
338
+static void log_trace2(struct progress *progress)
339
+{
340
+ trace2_data_intmax("progress", the_repository, "total_objects",
341
+ progress->total);
342
+
343
+ if (progress->throughput)
344
+ trace2_data_intmax("progress", the_repository, "total_bytes",
345
+ progress->throughput->curr_total);
346
+
347
+ trace2_region_leave("progress", progress->title, the_repository);
348
+}
349
+
350
void stop_progress(struct progress **p_progress)
351
{
352
struct progress *progress;
@@ -327,17 +357,8 @@ void stop_progress(struct progress **p_progress)
357
358
finish_if_sparse(progress);
359
330
- if (progress) {
331
- trace2_data_intmax("progress", the_repository, "total_objects",
332
- progress->total);
333
-
334
- if (progress->throughput)
335
- trace2_data_intmax("progress", the_repository,
336
- "total_bytes",
337
- progress->throughput->curr_total);
338
-
339
- trace2_region_leave("progress", progress->title, the_repository);
340
- }
360
+ if (progress)
361
+ log_trace2(*p_progress);
362
363
stop_progress_msg(p_progress, _("done"));
364
}
@@ -353,23 +374,10 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
374
if (!progress)
375
return;
376
*p_progress = NULL;
356
- if (progress->last_value != -1) {
357
- /* Force the last update */
358
- char *buf;
359
- struct throughput *tp = progress->throughput;
360
-
361
- if (tp) {
362
- uint64_t now_ns = progress_getnanotime(progress);
363
- unsigned int misecs, rate;
364
- misecs = ((now_ns - progress->start_ns) * 4398) >> 32;
365
- rate = tp->curr_total / (misecs ? misecs : 1);
366
- throughput_string(&tp->display, tp->curr_total, rate);
367
- }
368
- progress_update = 1;
369
- buf = xstrfmt(", %s.\n", msg);
370
- display(progress, progress->last_value, buf);
371
- free(buf);
372
- }
377
+
378
+ if (progress->last_value != -1)
379
+ force_last_update(progress, msg);
380
+
381
clear_progress_signal();
382
strbuf_release(&progress->counters_sb);
383
if (progress->throughput)