Specifically: number of kept packs, size of kept packs (and indexes),
and number of objects in kept packs.

Add documentation of resulting fields.  While here, correct the omission
from ae72f68541 ("count-objects -v: show number of packs as well.",
2006-12-27) of the "packs" field.

Signed-off-by: Nathaniel Filardo <nw...@cl.cam.ac.uk>
---
 Documentation/git-count-objects.txt |  8 ++++++++
 builtin/count-objects.c             | 17 +++++++++++++++--
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-count-objects.txt 
b/Documentation/git-count-objects.txt
index cb9b4d2e46..8d88f87856 100644
--- a/Documentation/git-count-objects.txt
+++ b/Documentation/git-count-objects.txt
@@ -26,10 +26,18 @@ count: the number of loose objects
 +
 size: disk space consumed by loose objects, in KiB (unless -H is specified)
 +
+packs: the number of pack files
++
+packs-keep: the number of pack files marked kept
++
 in-pack: the number of in-pack objects
 +
+in-pack-keep: the number of objects in packs marked kept
++
 size-pack: disk space consumed by the packs, in KiB (unless -H is specified)
 +
+size-pack-keep: disk space consumed by kept 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`.
 +
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 3fae474f6f..0309c7907f 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -117,17 +117,24 @@ int cmd_count_objects(int argc, const char **argv, const 
char *prefix)
 
        if (verbose) {
                struct packed_git *p;
-               unsigned long num_pack = 0;
-               off_t size_pack = 0;
+               unsigned long num_pack = 0, num_pack_keep = 0;
+               unsigned long packed_keep = 0;
+               off_t size_pack = 0, size_pack_keep = 0;
                struct strbuf loose_buf = STRBUF_INIT;
                struct strbuf pack_buf = STRBUF_INIT;
                struct strbuf garbage_buf = STRBUF_INIT;
+               struct strbuf pack_keep_buf = STRBUF_INIT;
 
                for (p = get_all_packs(the_repository); p; p = p->next) {
                        if (!p->pack_local)
                                continue;
                        if (open_pack_index(p))
                                continue;
+                       if (p->pack_keep || p->pack_keep_in_core) {
+                               packed_keep += p->num_objects;
+                               size_pack_keep += p->pack_size + p->index_size;
+                               num_pack_keep++;
+                       }
                        packed += p->num_objects;
                        size_pack += p->pack_size + p->index_size;
                        num_pack++;
@@ -136,12 +143,15 @@ int cmd_count_objects(int argc, const char **argv, const 
char *prefix)
                if (human_readable) {
                        strbuf_humanise_bytes(&loose_buf, loose_size);
                        strbuf_humanise_bytes(&pack_buf, size_pack);
+                       strbuf_humanise_bytes(&pack_keep_buf, size_pack_keep);
                        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(&pack_keep_buf, "%lu",
+                                   (unsigned long)(size_pack_keep / 1024));
                        strbuf_addf(&garbage_buf, "%lu",
                                    (unsigned long)(size_garbage / 1024));
                }
@@ -149,8 +159,11 @@ int cmd_count_objects(int argc, const char **argv, const 
char *prefix)
                printf("count: %lu\n", loose);
                printf("size: %s\n", loose_buf.buf);
                printf("in-pack: %lu\n", packed);
+               printf("in-pack-keep: %lu\n", packed_keep);
                printf("packs: %lu\n", num_pack);
+               printf("packs-keep: %lu\n", num_pack_keep);
                printf("size-pack: %s\n", pack_buf.buf);
+               printf("size-pack-keep: %s\n", pack_keep_buf.buf);
                printf("prune-packable: %lu\n", packed_loose);
                printf("garbage: %lu\n", garbage);
                printf("size-garbage: %s\n", garbage_buf.buf);
-- 
2.17.1

Reply via email to