mirror of
https://github.com/git/git
synced 2024-08-28 12:09:19 +00:00
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>
This commit is contained in:
parent
543c5caa6c
commit
1a20dd49f8
|
@ -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
|
garbage: the number of files in object database that are not valid
|
||||||
loose objects nor valid packs
|
loose objects nor valid packs
|
||||||
|
+
|
||||||
|
size-garbage: disk space consumed by garbage files, in KiB
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
---
|
---
|
||||||
|
|
|
@ -10,9 +10,13 @@
|
||||||
#include "parse-options.h"
|
#include "parse-options.h"
|
||||||
|
|
||||||
static unsigned long garbage;
|
static unsigned long garbage;
|
||||||
|
static off_t size_garbage;
|
||||||
|
|
||||||
static void real_report_garbage(const char *desc, const char *path)
|
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);
|
warning("%s: %s", desc, path);
|
||||||
garbage++;
|
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,
|
static void count_objects(DIR *d, char *path, int len, int verbose,
|
||||||
unsigned long *loose,
|
unsigned long *loose,
|
||||||
off_t *loose_size,
|
off_t *loose_size,
|
||||||
unsigned long *packed_loose,
|
unsigned long *packed_loose)
|
||||||
unsigned long *garbage)
|
|
||||||
{
|
{
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
while ((ent = readdir(d)) != NULL) {
|
while ((ent = readdir(d)) != NULL) {
|
||||||
|
@ -54,9 +57,11 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
|
||||||
}
|
}
|
||||||
if (bad) {
|
if (bad) {
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
error("garbage found: %.*s/%s",
|
struct strbuf sb = STRBUF_INIT;
|
||||||
len + 2, path, ent->d_name);
|
strbuf_addf(&sb, "%.*s/%s",
|
||||||
(*garbage)++;
|
len + 2, path, ent->d_name);
|
||||||
|
report_garbage("garbage found", sb.buf);
|
||||||
|
strbuf_release(&sb);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -107,7 +112,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
|
||||||
if (!d)
|
if (!d)
|
||||||
continue;
|
continue;
|
||||||
count_objects(d, path, len, verbose,
|
count_objects(d, path, len, verbose,
|
||||||
&loose, &loose_size, &packed_loose, &garbage);
|
&loose, &loose_size, &packed_loose);
|
||||||
closedir(d);
|
closedir(d);
|
||||||
}
|
}
|
||||||
if (verbose) {
|
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("size-pack: %lu\n", (unsigned long) (size_pack / 1024));
|
||||||
printf("prune-packable: %lu\n", packed_loose);
|
printf("prune-packable: %lu\n", packed_loose);
|
||||||
printf("garbage: %lu\n", garbage);
|
printf("garbage: %lu\n", garbage);
|
||||||
|
printf("size-garbage: %lu\n", (unsigned long) (size_garbage / 1024));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
printf("%lu objects, %lu kilobytes\n",
|
printf("%lu objects, %lu kilobytes\n",
|
||||||
|
|
Loading…
Reference in a new issue