From: Antoine Pelisse <apelisse@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Antoine Pelisse <apelisse@gmail.com>
Subject: [PATCH 2/2] count-objects: add -H option to humanize sizes
Date: Wed, 10 Apr 2013 21:03:24 +0200 [thread overview]
Message-ID: <1365620604-17851-2-git-send-email-apelisse@gmail.com> (raw)
In-Reply-To: <1365620604-17851-1-git-send-email-apelisse@gmail.com>
Use the new humanize() function to print loose objects size, pack size,
and garbage size in verbose mode, or loose objects size in regular mode.
This patch doesn't change the way anything is displayed when the option
is not used.
Also update the documentation.
Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
---
Documentation/git-count-objects.txt | 14 ++++++++---
builtin/count-objects.c | 46 +++++++++++++++++++++++++++++------
2 files changed, 48 insertions(+), 12 deletions(-)
diff --git a/Documentation/git-count-objects.txt b/Documentation/git-count-objects.txt
index da6e72e..b300e84 100644
--- a/Documentation/git-count-objects.txt
+++ b/Documentation/git-count-objects.txt
@@ -8,7 +8,7 @@ git-count-objects - Count unpacked number of objects and their disk consumption
SYNOPSIS
--------
[verse]
-'git count-objects' [-v]
+'git count-objects' [-v] [-H | --human-readable]
DESCRIPTION
-----------
@@ -24,11 +24,11 @@ OPTIONS
+
count: the number of loose objects
+
-size: disk space consumed by loose objects, in KiB
+size: disk space consumed by loose objects, in KiB (unless -H is specified)
+
in-pack: the number of in-pack objects
+
-size-pack: disk space consumed by the packs, in KiB
+size-pack: disk space consumed by the packs, in KiB (unless -H is specified)
+
prune-packable: the number of loose objects that are also present in
the packs. These objects could be pruned using `git prune-packed`.
@@ -36,7 +36,13 @@ the packs. These objects could be pruned using `git prune-packed`.
garbage: the number of files in object database that are not valid
loose objects nor valid packs
+
-size-garbage: disk space consumed by garbage files, in KiB
+size-garbage: disk space consumed by garbage files, in KiB (unless -H is
+specified)
+
+-H::
+--human-readable::
+
+Print sizes in human readable format
GIT
---
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 0343e35..935ad9e 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_BOOLEAN('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,42 @@ 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_humanize(&loose_buf, loose_size);
+ strbuf_humanize(&pack_buf, size_pack);
+ strbuf_humanize(&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_humanize(&buf, loose_size);
+ else
+ strbuf_addf(&buf, "%lu KiB",
+ (unsigned long)(loose_size / 1024));
+ printf("%lu objects, %s\n", loose, buf.buf);
+ strbuf_release(&buf);
}
- else
- printf("%lu objects, %lu KiB\n",
- loose, (unsigned long) (loose_size / 1024));
return 0;
}
--
1.7.9.5
next prev parent reply other threads:[~2013-04-10 19:04 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-02 11:43 [PATCH] count-objects: output "KiB" instead of "kilobytes" Mihai Capotă
2013-04-02 17:41 ` Junio C Hamano
2013-04-02 22:01 ` Junio C Hamano
2013-04-03 6:27 ` Mihai Capotă
2013-04-03 12:48 ` [PATCH v2] " Mihai Capotă
2013-04-03 14:38 ` Junio C Hamano
2013-04-04 13:18 ` Mihai Capotă
2013-04-04 16:27 ` Junio C Hamano
2013-04-05 9:38 ` Mihai Capotă
2013-04-05 9:39 ` [PATCH] count-objects doc: document use of kibibytes Mihai Capotă
2013-04-05 20:31 ` [PATCH v2] count-objects: output "KiB" instead of "kilobytes" Antoine Pelisse
2013-04-08 18:18 ` [PATCH 1/2] progress: create public humanize() to show sizes Antoine Pelisse
2013-04-08 18:18 ` [PATCH 2/2] count-objects: add -H option to humanize sizes Antoine Pelisse
2013-04-08 21:40 ` [PATCH 1/2] progress: create public humanize() to show sizes Junio C Hamano
2013-04-10 19:03 ` [PATCH 1/2] strbuf: create strbuf_humanize() to show byte sizes Antoine Pelisse
2013-04-10 19:03 ` Antoine Pelisse [this message]
2013-04-10 19:43 ` Jonathan Nieder
2013-04-10 20:00 ` Antoine Pelisse
2013-04-10 19:57 ` Junio C Hamano
2013-04-10 20:12 ` Antoine Pelisse
2013-04-08 21:55 ` [PATCH 1/2] progress: create public humanize() to show sizes Eric Sunshine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1365620604-17851-2-git-send-email-apelisse@gmail.com \
--to=apelisse@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).