summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-03-21 21:02:34 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-03-21 21:02:34 (GMT)
commitf5715de54a2237025a74704cb41f5404c743a2c3 (patch)
tree38f7021336ab39c6dfdc9a46880939482f5489c5 /builtin
parente4e1c5499056de58f7df207cf41274a321857c77 (diff)
parent1a20dd49f8c4e6c62080f267ca77b357cb61be8e (diff)
downloadgit-f5715de54a2237025a74704cb41f5404c743a2c3.zip
git-f5715de54a2237025a74704cb41f5404c743a2c3.tar.gz
git-f5715de54a2237025a74704cb41f5404c743a2c3.tar.bz2
Merge branch 'nd/count-garbage'
"git count-objects -v" did not count leftover temporary packfiles and other kinds of garbage. * nd/count-garbage: count-objects: report how much disk space taken by garbage files count-objects: report garbage files in pack directory too sha1_file: reorder code in prepare_packed_git_one() git-count-objects.txt: describe each line in -v output
Diffstat (limited to 'builtin')
-rw-r--r--builtin/count-objects.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 9afaa88..3a01a8d 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -9,11 +9,22 @@
#include "builtin.h"
#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++;
+}
+
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) {
@@ -46,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;
}
@@ -76,7 +89,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 +100,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++] = '/';
@@ -97,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) {
@@ -122,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",