From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 3/3] count-objects: report how much disk space taken by garbage files
Date: Fri, 8 Feb 2013 10:48:27 +0700 [thread overview]
Message-ID: <1360295307-5469-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1360295307-5469-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
We may do some redundant stat() here, but I don't think it can slow
count-objects down much to worry about.
Documentation/git-count-objects.txt | 2 ++
builtin/count-objects.c | 29 ++++++++++++++++++-----------
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/Documentation/git-count-objects.txt b/Documentation/git-count-objects.txt
index 1611d7c..da6e72e 100644
--- a/Documentation/git-count-objects.txt
+++ b/Documentation/git-count-objects.txt
@@ -35,6 +35,8 @@ 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
GIT
---
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 118b2ae..90d476d 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -10,24 +10,33 @@
#include "parse-options.h"
static unsigned long garbage;
+static off_t size_garbage;
extern void (*report_pack_garbage)(const char *path, int len, const char *name);
static void real_report_pack_garbage(const char *path, int len, const char *name)
{
+ struct strbuf sb = STRBUF_INIT;
+ struct stat st;
+
if (len && name)
- error("garbage found: %.*s/%s", len, path, name);
+ strbuf_addf(&sb, "%.*s/%s", len, path, name);
else if (!len && name)
- error("garbage found: %s%s", path, name);
+ strbuf_addf(&sb, "%s%s", path, name);
else
- error("garbage found: %s", path);
+ strbuf_addf(&sb, "%s", path);
+ error(_("garbage found: %s"), sb.buf);
+
+ if (!stat(sb.buf, &st))
+ size_garbage += st.st_size;
+
garbage++;
+ strbuf_release(&sb);
}
static void count_objects(DIR *d, char *path, int len, int verbose,
unsigned long *loose,
off_t *loose_size,
- unsigned long *packed_loose,
- unsigned long *garbage)
+ unsigned long *packed_loose)
{
struct dirent *ent;
while ((ent = readdir(d)) != NULL) {
@@ -59,11 +68,8 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
(*loose_size) += xsize_t(on_disk_bytes(st));
}
if (bad) {
- if (verbose) {
- error("garbage found: %.*s/%s",
- len + 2, path, ent->d_name);
- (*garbage)++;
- }
+ if (verbose)
+ report_pack_garbage(path, len + 2, ent->d_name);
continue;
}
(*loose)++;
@@ -113,7 +119,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
if (!d)
continue;
count_objects(d, path, len, verbose,
- &loose, &loose_size, &packed_loose, &garbage);
+ &loose, &loose_size, &packed_loose);
closedir(d);
}
if (verbose) {
@@ -138,6 +144,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
printf("size-pack: %lu\n", (unsigned long) (size_pack / 1024));
printf("prune-packable: %lu\n", packed_loose);
printf("garbage: %lu\n", garbage);
+ printf("size-garbage: %lu\n", (unsigned long) (size_garbage / 1024));
}
else
printf("%lu objects, %lu kilobytes\n",
--
1.8.1.2.495.g3fdf5d5.dirty
next prev parent reply other threads:[~2013-02-08 3:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-04 12:49 [PATCH 1/2] git-count-objects.txt: describe each line in -v output Nguyễn Thái Ngọc Duy
2013-02-04 12:49 ` [PATCH 2/2] count-objects: report garbage files in .git/objects/pack directory too Nguyễn Thái Ngọc Duy
2013-02-04 17:06 ` Junio C Hamano
2013-02-04 18:16 ` Junio C Hamano
2013-02-07 7:37 ` Duy Nguyen
2013-02-07 18:12 ` Junio C Hamano
2013-02-07 23:58 ` Duy Nguyen
2013-02-08 3:48 ` [PATCH v2 0/3] count-objects improvements Nguyễn Thái Ngọc Duy
2013-02-08 3:48 ` [PATCH v2 1/3] git-count-objects.txt: describe each line in -v output Nguyễn Thái Ngọc Duy
2013-02-08 3:48 ` [PATCH v2 2/3] count-objects: report garbage files in pack directory too Nguyễn Thái Ngọc Duy
2013-02-08 18:44 ` Junio C Hamano
2013-02-09 1:58 ` Duy Nguyen
2013-02-08 3:48 ` Nguyễn Thái Ngọc Duy [this message]
2013-02-08 18:47 ` [PATCH v2 3/3] count-objects: report how much disk space taken by garbage files Junio C Hamano
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=1360295307-5469-4-git-send-email-pclouds@gmail.com \
--to=pclouds@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).