Skip to content

Commit

Permalink
progress bar: round to the nearest instead of truncating down
Browse files Browse the repository at this point in the history
Often the throughput output is requested when the data read so far is
one smaller than multiple of 1024; because 1023/1024 is ~0.999, it often
shows up as 0.99 because the code currently truncates.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Nicolas Pitre authored and Junio C Hamano committed Apr 25, 2009
1 parent f29ac4f commit 6691328
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions progress.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ static void throughput_string(struct throughput *tp, off_t total,
(int)(total >> 30),
(int)(total & ((1 << 30) - 1)) / 10737419);
} else if (total > 1 << 20) {
int x = total + 5243; /* for rounding */
l -= snprintf(tp->display, l, ", %u.%2.2u MiB",
(int)(total >> 20),
((int)(total & ((1 << 20) - 1)) * 100) >> 20);
x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);
} else if (total > 1 << 10) {
int x = total + 5; /* for rounding */
l -= snprintf(tp->display, l, ", %u.%2.2u KiB",
(int)(total >> 10),
((int)(total & ((1 << 10) - 1)) * 100) >> 10);
x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
} else {
l -= snprintf(tp->display, l, ", %u bytes", (int)total);
}
Expand Down

0 comments on commit 6691328

Please sign in to comment.