diff options
| author | Junio C Hamano <gitster@pobox.com> | 2013-04-19 13:31:26 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2013-04-19 13:31:27 -0700 |
| commit | d7bffe9fb63185fbac6f4f41e9fb760b4f230a7d (patch) | |
| tree | 6353306a475ac8f5eba346055207e6378607241a /strbuf.c | |
| parent | 4059da335240ab35da6ee9d6f73346eba28fdfc7 (diff) | |
| parent | 1918225d2fce49c830b41b8c7907229638ae2825 (diff) | |
Merge branch 'ap/strbuf-humanize'
Teach "--human-readable" aka "-H" option to "git count-objects" to
show various large numbers in Ki/Mi/GiB scaled as necessary.
* ap/strbuf-humanize:
count-objects: add -H option to humanize sizes
strbuf: create strbuf_humanise_bytes() to show byte sizes
Diffstat (limited to 'strbuf.c')
| -rw-r--r-- | strbuf.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -528,6 +528,25 @@ void strbuf_addstr_urlencode(struct strbuf *sb, const char *s, strbuf_add_urlencode(sb, s, strlen(s), reserved); } +void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes) +{ + if (bytes > 1 << 30) { + strbuf_addf(buf, "%u.%2.2u GiB", + (int)(bytes >> 30), + (int)(bytes & ((1 << 30) - 1)) / 10737419); + } else if (bytes > 1 << 20) { + int x = bytes + 5243; /* for rounding */ + strbuf_addf(buf, "%u.%2.2u MiB", + x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20); + } else if (bytes > 1 << 10) { + int x = bytes + 5; /* for rounding */ + strbuf_addf(buf, "%u.%2.2u KiB", + x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10); + } else { + strbuf_addf(buf, "%u bytes", (int)bytes); + } +} + int printf_ln(const char *fmt, ...) { int ret; |
