summaryrefslogtreecommitdiff
path: root/progress.c
diff options
context:
space:
mode:
authorNicolas Pitre <nico@cam.org>2009-04-24 17:46:15 -0400
committerJunio C Hamano <gitster@pobox.com>2009-04-25 08:54:18 -0700
commit66913284f06da58e2243acfad951a57501b8d813 (patch)
treec6ba039d76ef1cc5318ff3b98e63fd2b9e057f85 /progress.c
parentf29ac4f1b04c9cf84509e4a80f27f10b4373a446 (diff)
downloadgit-66913284f06da58e2243acfad951a57501b8d813.tar.gz
progress bar: round to the nearest instead of truncating down
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>
Diffstat (limited to 'progress.c')
-rw-r--r--progress.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/progress.c b/progress.c
index 55a8687ad1..621c34edc2 100644
--- a/progress.c
+++ b/progress.c
@@ -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);
}