Skip to content

Commit accf1eb

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1ccad6a commit accf1eb

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

progress.c

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,36 @@ static void finish_if_sparse(struct progress *progress)
317317
display_progress(progress, progress->total);
318318
}
319319

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+
320350
void stop_progress(struct progress **p_progress)
321351
{
322352
struct progress *progress;
@@ -327,17 +357,8 @@ void stop_progress(struct progress **p_progress)
327357

328358
finish_if_sparse(progress);
329359

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);
341362

342363
stop_progress_msg(p_progress, _("done"));
343364
}
@@ -353,23 +374,10 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
353374
if (!progress)
354375
return;
355376
*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+
373381
clear_progress_signal();
374382
strbuf_release(&progress->counters_sb);
375383
if (progress->throughput)

0 commit comments

Comments
 (0)