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 /builtin | |
parent | 4059da335240ab35da6ee9d6f73346eba28fdfc7 (diff) | |
parent | 1918225d2fce49c830b41b8c7907229638ae2825 (diff) | |
download | git-d7bffe9fb63185fbac6f4f41e9fb760b4f230a7d.tar.gz |
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 'builtin')
-rw-r--r-- | builtin/count-objects.c | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/builtin/count-objects.c b/builtin/count-objects.c index 3a01a8d085..a7f70cb858 100644 --- a/builtin/count-objects.c +++ b/builtin/count-objects.c @@ -79,13 +79,13 @@ static void count_objects(DIR *d, char *path, int len, int verbose, } static char const * const count_objects_usage[] = { - N_("git count-objects [-v]"), + N_("git count-objects [-v] [-H | --human-readable]"), NULL }; int cmd_count_objects(int argc, const char **argv, const char *prefix) { - int i, verbose = 0; + int i, verbose = 0, human_readable = 0; const char *objdir = get_object_directory(); int len = strlen(objdir); char *path = xmalloc(len + 50); @@ -93,6 +93,8 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) off_t loose_size = 0; struct option opts[] = { OPT__VERBOSE(&verbose, N_("be verbose")), + OPT_BOOL('H', "human-readable", &human_readable, + N_("print sizes in human readable format")), OPT_END(), }; @@ -119,6 +121,9 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) struct packed_git *p; unsigned long num_pack = 0; off_t size_pack = 0; + struct strbuf loose_buf = STRBUF_INIT; + struct strbuf pack_buf = STRBUF_INIT; + struct strbuf garbage_buf = STRBUF_INIT; if (!packed_git) prepare_packed_git(); for (p = packed_git; p; p = p->next) { @@ -130,17 +135,40 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) size_pack += p->pack_size + p->index_size; num_pack++; } + + if (human_readable) { + strbuf_humanise_bytes(&loose_buf, loose_size); + strbuf_humanise_bytes(&pack_buf, size_pack); + strbuf_humanise_bytes(&garbage_buf, size_garbage); + } else { + strbuf_addf(&loose_buf, "%lu", + (unsigned long)(loose_size / 1024)); + strbuf_addf(&pack_buf, "%lu", + (unsigned long)(size_pack / 1024)); + strbuf_addf(&garbage_buf, "%lu", + (unsigned long)(size_garbage / 1024)); + } + printf("count: %lu\n", loose); - printf("size: %lu\n", (unsigned long) (loose_size / 1024)); + printf("size: %s\n", loose_buf.buf); printf("in-pack: %lu\n", packed); printf("packs: %lu\n", num_pack); - printf("size-pack: %lu\n", (unsigned long) (size_pack / 1024)); + printf("size-pack: %s\n", pack_buf.buf); printf("prune-packable: %lu\n", packed_loose); printf("garbage: %lu\n", garbage); - printf("size-garbage: %lu\n", (unsigned long) (size_garbage / 1024)); + printf("size-garbage: %s\n", garbage_buf.buf); + strbuf_release(&loose_buf); + strbuf_release(&pack_buf); + strbuf_release(&garbage_buf); + } else { + struct strbuf buf = STRBUF_INIT; + if (human_readable) + strbuf_humanise_bytes(&buf, loose_size); + else + strbuf_addf(&buf, "%lu kilobytes", + (unsigned long)(loose_size / 1024)); + printf("%lu objects, %s\n", loose, buf.buf); + strbuf_release(&buf); } - else - printf("%lu objects, %lu kilobytes\n", - loose, (unsigned long) (loose_size / 1024)); return 0; } |