summaryrefslogtreecommitdiff
path: root/builtin/count-objects.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2013-02-13 09:13:19 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-02-15 17:02:34 (GMT)
commit1a20dd49f8c4e6c62080f267ca77b357cb61be8e (patch)
treef86f7ec4b3d0c7d8dfca1400b6f14bd4fa0e1340 /builtin/count-objects.c
parent543c5caa6c93bb3d42545aeef334c6a175384db8 (diff)
downloadgit-1a20dd49f8c4e6c62080f267ca77b357cb61be8e.zip
git-1a20dd49f8c4e6c62080f267ca77b357cb61be8e.tar.gz
git-1a20dd49f8c4e6c62080f267ca77b357cb61be8e.tar.bz2
count-objects: report how much disk space taken by garbage files
Also issue warnings on loose garbages instead of errors as a result of using report_garbage() function in count_objects() Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/count-objects.c')
-rw-r--r--builtin/count-objects.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 1706c8b..3a01a8d 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -10,9 +10,13 @@
#include "parse-options.h"
static unsigned long garbage;
+static off_t size_garbage;
static void real_report_garbage(const char *desc, const char *path)
{
+ struct stat st;
+ if (!stat(path, &st))
+ size_garbage += st.st_size;
warning("%s: %s", desc, path);
garbage++;
}
@@ -20,8 +24,7 @@ static void real_report_garbage(const char *desc, const char *path)
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) {
@@ -54,9 +57,11 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
}
if (bad) {
if (verbose) {
- error("garbage found: %.*s/%s",
- len + 2, path, ent->d_name);
- (*garbage)++;
+ struct strbuf sb = STRBUF_INIT;
+ strbuf_addf(&sb, "%.*s/%s",
+ len + 2, path, ent->d_name);
+ report_garbage("garbage found", sb.buf);
+ strbuf_release(&sb);
}
continue;
}
@@ -107,7 +112,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) {
@@ -132,6 +137,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",