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>
Nguyễn Thái Ngọc Duy committed
Feb 13, 2013 at 16:13 UTC
1a20dd49f8c4e6c62080f267ca77b357cb61be8e
2 files changed
+14
-6
Documentation/git-count-objects.txt
+2
@@ -35,6 +35,8 @@ the packs. These objects could be pruned using `git prune-packed`.
35
+
36
garbage: the number of files in object database that are not valid
37
loose objects nor valid packs
38
++
39
+size-garbage: disk space consumed by garbage files, in KiB
40
41
GIT
42
---
builtin/count-objects.c
+12
-6
@@ -10,9 +10,13 @@
10
#include "parse-options.h"
11
12
static unsigned long garbage;
13
+static off_t size_garbage;
14
15
static void real_report_garbage(const char *desc, const char *path)
16
{
17
+ struct stat st;
18
+ if (!stat(path, &st))
19
+ size_garbage += st.st_size;
20
warning("%s: %s", desc, path);
21
garbage++;
22
}
@@ -20,8 +24,7 @@ static void real_report_garbage(const char *desc, const char *path)
24
static void count_objects(DIR *d, char *path, int len, int verbose,
25
unsigned long *loose,
26
off_t *loose_size,
23
- unsigned long *packed_loose,
24
- unsigned long *garbage)
27
+ unsigned long *packed_loose)
28
{
29
struct dirent *ent;
30
while ((ent = readdir(d)) != NULL) {
@@ -54,9 +57,11 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
57
}
58
if (bad) {
59
if (verbose) {
57
- error("garbage found: %.*s/%s",
58
- len + 2, path, ent->d_name);
59
- (*garbage)++;
60
+ struct strbuf sb = STRBUF_INIT;
61
+ strbuf_addf(&sb, "%.*s/%s",
62
+ len + 2, path, ent->d_name);
63
+ report_garbage("garbage found", sb.buf);
64
+ strbuf_release(&sb);
65
}
66
continue;
67
}
@@ -107,7 +112,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
112
if (!d)
113
continue;
114
count_objects(d, path, len, verbose,
110
- &loose, &loose_size, &packed_loose, &garbage);
115
+ &loose, &loose_size, &packed_loose);
116
closedir(d);
117
}
118
if (verbose) {
@@ -132,6 +137,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
137
printf("size-pack: %lu\n", (unsigned long) (size_pack / 1024));
138
printf("prune-packable: %lu\n", packed_loose);
139
printf("garbage: %lu\n", garbage);
140
+ printf("size-garbage: %lu\n", (unsigned long) (size_garbage / 1024));
141
}
142
else
143
printf("%lu objects, %lu kilobytes\n",