Skip to content

Commit 1a20dd4

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent 543c5ca commit 1a20dd4

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Documentation/git-count-objects.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ the packs. These objects could be pruned using `git prune-packed`.
3535
+
3636
garbage: the number of files in object database that are not valid
3737
loose objects nor valid packs
38+
+
39+
size-garbage: disk space consumed by garbage files, in KiB
3840

3941
GIT
4042
---

builtin/count-objects.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@
1010
#include "parse-options.h"
1111

1212
static unsigned long garbage;
13+
static off_t size_garbage;
1314

1415
static void real_report_garbage(const char *desc, const char *path)
1516
{
17+
struct stat st;
18+
if (!stat(path, &st))
19+
size_garbage += st.st_size;
1620
warning("%s: %s", desc, path);
1721
garbage++;
1822
}
1923

2024
static void count_objects(DIR *d, char *path, int len, int verbose,
2125
unsigned long *loose,
2226
off_t *loose_size,
23-
unsigned long *packed_loose,
24-
unsigned long *garbage)
27+
unsigned long *packed_loose)
2528
{
2629
struct dirent *ent;
2730
while ((ent = readdir(d)) != NULL) {
@@ -54,9 +57,11 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
5457
}
5558
if (bad) {
5659
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);
6065
}
6166
continue;
6267
}
@@ -107,7 +112,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
107112
if (!d)
108113
continue;
109114
count_objects(d, path, len, verbose,
110-
&loose, &loose_size, &packed_loose, &garbage);
115+
&loose, &loose_size, &packed_loose);
111116
closedir(d);
112117
}
113118
if (verbose) {
@@ -132,6 +137,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
132137
printf("size-pack: %lu\n", (unsigned long) (size_pack / 1024));
133138
printf("prune-packable: %lu\n", packed_loose);
134139
printf("garbage: %lu\n", garbage);
140+
printf("size-garbage: %lu\n", (unsigned long) (size_garbage / 1024));
135141
}
136142
else
137143
printf("%lu objects, %lu kilobytes\n",

0 commit comments

Comments
 (0)