@@ -135,7 +135,11 @@ static void display(struct progress *progress, uint64_t n, const char *done)
}
} else if (progress_update) {
strbuf_reset(counters_sb);
- strbuf_addf(counters_sb, "%"PRIuMAX"%s", (uintmax_t)n, tp);
+ if (n > 0)
+ strbuf_addf(counters_sb, "%" PRIuMAX "%s",
+ (uintmax_t)n, tp);
+ else
+ strbuf_addstr(counters_sb, tp);
show_update = 1;
}
@@ -170,11 +174,12 @@ static void display(struct progress *progress, uint64_t n, const char *done)
}
}
-static void throughput_string(struct strbuf *buf, uint64_t total,
- unsigned int rate)
+static void throughput_string(struct progress *progress, struct strbuf *buf,
+ uint64_t total, unsigned int rate)
{
strbuf_reset(buf);
- strbuf_addstr(buf, ", ");
+ if (progress->total || progress->last_value > 0)
+ strbuf_addstr(buf, ", ");
strbuf_humanise_bytes(buf, total);
strbuf_addstr(buf, " | ");
strbuf_humanise_rate(buf, rate * 1024);
@@ -243,7 +248,7 @@ void display_throughput(struct progress *progress, uint64_t total)
tp->last_misecs[tp->idx] = misecs;
tp->idx = (tp->idx + 1) % TP_IDX_MAX;
- throughput_string(&tp->display, total, rate);
+ throughput_string(progress, &tp->display, total, rate);
if (progress->last_value != -1 && progress_update)
display(progress, progress->last_value, NULL);
}
@@ -343,7 +348,7 @@ static void force_last_update(struct progress *progress, const char *msg)
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);
+ throughput_string(progress, &tp->display, tp->curr_total, rate);
}
progress_update = 1;
buf = xstrfmt(", %s.\n", msg);
@@ -263,6 +263,37 @@ test_expect_success 'progress display with throughput and total' '
test_cmp expect out
'
+test_expect_success 'progress display throughput without total' '
+ cat >expect <<-\EOF &&
+ Working hard: <CR>
+ Working hard: 200.00 KiB | 100.00 KiB/s<CR>
+ Working hard: 300.00 KiB | 100.00 KiB/s<CR>
+ Working hard: 400.00 KiB | 100.00 KiB/s<CR>
+ Working hard: 400.00 KiB | 100.00 KiB/s, done.
+ EOF
+
+ cat >in <<-\EOF &&
+ start 0
+ throughput 102400 1000
+ update
+ progress 0
+ throughput 204800 2000
+ update
+ progress 0
+ throughput 307200 3000
+ update
+ progress 0
+ throughput 409600 4000
+ update
+ progress 0
+ stop
+ EOF
+ test-tool progress <in 2>stderr &&
+
+ show_cr <stderr >out &&
+ test_cmp expect out
+'
+
test_expect_success 'cover up after throughput shortens' '
cat >expect <<-\EOF &&
Working hard: 1<CR>