The following patches in this series want to handle the progress bar's
title and changing parts (i.e. the counter and the optional percentage
and throughput combined) differently, and need to know the length
of the changing parts of the previously displayed progress bar.
To prepare for those changes assemble the changing parts in a separate
strbuf kept in 'struct progress' before printing.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
unsigned delay;
struct throughput *throughput;
uint64_t start_ns;
unsigned delay;
struct throughput *throughput;
uint64_t start_ns;
+ struct strbuf counters_sb;
};
static volatile sig_atomic_t progress_update;
};
static volatile sig_atomic_t progress_update;
static void display(struct progress *progress, uint64_t n, const char *done)
{
static void display(struct progress *progress, uint64_t n, const char *done)
{
+ const char *tp;
+ struct strbuf *counters_sb = &progress->counters_sb;
+ int show_update = 0;
if (progress->delay && (!progress_update || --progress->delay))
return;
progress->last_value = n;
tp = (progress->throughput) ? progress->throughput->display.buf : "";
if (progress->delay && (!progress_update || --progress->delay))
return;
progress->last_value = n;
tp = (progress->throughput) ? progress->throughput->display.buf : "";
- eol = done ? done : " \r";
if (progress->total) {
unsigned percent = n * 100 / progress->total;
if (percent != progress->last_percent || progress_update) {
progress->last_percent = percent;
if (progress->total) {
unsigned percent = n * 100 / progress->total;
if (percent != progress->last_percent || progress_update) {
progress->last_percent = percent;
- if (is_foreground_fd(fileno(stderr)) || done) {
- fprintf(stderr, "%s: %3u%% (%"PRIuMAX"/%"PRIuMAX")%s%s",
- progress->title, percent,
- (uintmax_t)n, (uintmax_t)progress->total,
- tp, eol);
- fflush(stderr);
- }
- progress_update = 0;
+
+ strbuf_reset(counters_sb);
+ strbuf_addf(counters_sb,
+ "%3u%% (%"PRIuMAX"/%"PRIuMAX")%s", percent,
+ (uintmax_t)n, (uintmax_t)progress->total,
+ tp);
+ show_update = 1;
}
} else if (progress_update) {
}
} else if (progress_update) {
+ strbuf_reset(counters_sb);
+ strbuf_addf(counters_sb, "%"PRIuMAX"%s", (uintmax_t)n, tp);
+ show_update = 1;
+ }
+
+ if (show_update) {
if (is_foreground_fd(fileno(stderr)) || done) {
if (is_foreground_fd(fileno(stderr)) || done) {
- fprintf(stderr, "%s: %"PRIuMAX"%s%s",
- progress->title, (uintmax_t)n, tp, eol);
+ const char *eol = done ? done : " \r";
+
+ fprintf(stderr, "%s: %s%s", progress->title,
+ counters_sb->buf, eol);
fflush(stderr);
}
progress_update = 0;
fflush(stderr);
}
progress_update = 0;
progress->delay = delay;
progress->throughput = NULL;
progress->start_ns = getnanotime();
progress->delay = delay;
progress->throughput = NULL;
progress->start_ns = getnanotime();
+ strbuf_init(&progress->counters_sb, 0);
set_progress_signal();
return progress;
}
set_progress_signal();
return progress;
}
free(buf);
}
clear_progress_signal();
free(buf);
}
clear_progress_signal();
+ strbuf_release(&progress->counters_sb);
if (progress->throughput)
strbuf_release(&progress->throughput->display);
free(progress->throughput);
if (progress->throughput)
strbuf_release(&progress->throughput->display);
free(progress->throughput);