From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v4 4/4] count-objects: report how much disk space taken by garbage files
Date: Wed, 13 Feb 2013 16:13:19 +0700 [thread overview]
Message-ID: <1360746799-3668-5-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1360746799-3668-1-git-send-email-pclouds@gmail.com>
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>
---
Documentation/git-count-objects.txt | 2 ++
builtin/count-objects.c | 18 ++++++++++++------
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/Documentation/git-count-objects.txt b/Documentation/git-count-objects.txt
index 1611d7c..da6e72e 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 1706c8b..3a01a8d 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",
--
1.8.1.2.536.gf441e6d
next prev parent reply other threads:[~2013-02-13 9:13 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-12 9:27 [PATCH v3 0/4] count-objects improvements Nguyễn Thái Ngọc Duy
2013-02-12 9:27 ` [PATCH v3 1/4] git-count-objects.txt: describe each line in -v output Nguyễn Thái Ngọc Duy
2013-02-12 9:27 ` [PATCH v3 2/4] sha1_file: reorder code in prepare_packed_git_one() Nguyễn Thái Ngọc Duy
2013-02-12 9:27 ` [PATCH v3 3/4] count-objects: report garbage files in pack directory too Nguyễn Thái Ngọc Duy
2013-02-12 17:23 ` Junio C Hamano
2013-02-13 9:13 ` [PATCH v4 0/4] count-objects improvements Nguyễn Thái Ngọc Duy
2013-02-13 9:13 ` [PATCH v4 1/4] git-count-objects.txt: describe each line in -v output Nguyễn Thái Ngọc Duy
2013-02-13 9:13 ` [PATCH v4 2/4] sha1_file: reorder code in prepare_packed_git_one() Nguyễn Thái Ngọc Duy
2013-02-13 9:13 ` [PATCH v4 3/4] count-objects: report garbage files in pack directory too Nguyễn Thái Ngọc Duy
2013-02-13 15:55 ` Junio C Hamano
2013-02-13 16:54 ` Junio C Hamano
2013-02-14 9:24 ` Duy Nguyen
2013-02-14 17:02 ` Junio C Hamano
2013-02-15 12:07 ` [PATCH v4+ " Nguyễn Thái Ngọc Duy
2013-02-15 23:20 ` Junio C Hamano
2013-02-13 9:13 ` Nguyễn Thái Ngọc Duy [this message]
2013-02-12 9:27 ` [PATCH v3 4/4] count-objects: report how much disk space taken by garbage files Nguyễn Thái Ngọc Duy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1360746799-3668-5-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).