From 543c5caa6c93bb3d42545aeef334c6a175384db8 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Fri, 15 Feb 2013 19:07:10 +0700 Subject: count-objects: report garbage files in pack directory too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit prepare_packed_git_one() is modified to allow count-objects to hook a report function to so we don't need to duplicate the pack searching logic in count-objects.c. When report_pack_garbage is NULL, the overhead is insignificant. The garbage is reported with warning() instead of error() in packed garbage case because it's not an error to have garbage. Loose garbage is still reported as errors and will be converted to warnings later. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/count-objects.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'builtin/count-objects.c') diff --git a/builtin/count-objects.c b/builtin/count-objects.c index 9afaa88f77..1706c8bd81 100644 --- a/builtin/count-objects.c +++ b/builtin/count-objects.c @@ -9,6 +9,14 @@ #include "builtin.h" #include "parse-options.h" +static unsigned long garbage; + +static void real_report_garbage(const char *desc, const char *path) +{ + warning("%s: %s", desc, path); + garbage++; +} + static void count_objects(DIR *d, char *path, int len, int verbose, unsigned long *loose, off_t *loose_size, @@ -76,7 +84,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) const char *objdir = get_object_directory(); int len = strlen(objdir); char *path = xmalloc(len + 50); - unsigned long loose = 0, packed = 0, packed_loose = 0, garbage = 0; + unsigned long loose = 0, packed = 0, packed_loose = 0; off_t loose_size = 0; struct option opts[] = { OPT__VERBOSE(&verbose, N_("be verbose")), @@ -87,6 +95,8 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) /* we do not take arguments other than flags for now */ if (argc) usage_with_options(count_objects_usage, opts); + if (verbose) + report_garbage = real_report_garbage; memcpy(path, objdir, len); if (len && objdir[len-1] != '/') path[len++] = '/'; -- cgit v1.2.3 From 1a20dd49f8c4e6c62080f267ca77b357cb61be8e Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Wed, 13 Feb 2013 16:13:19 +0700 Subject: count-objects: report how much disk space taken by garbage files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- Documentation/git-count-objects.txt | 2 ++ builtin/count-objects.c | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'builtin/count-objects.c') diff --git a/Documentation/git-count-objects.txt b/Documentation/git-count-objects.txt index 1611d7c768..da6e72e696 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 1706c8bd81..3a01a8d085 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", -- cgit v1.2.3