git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 4/4] count-objects: report how much disk space taken by garbage files

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Feb 12, 2013, 09:27 UTC
Message-ID
<1360661277-17273-5-git-send-email-pclouds@gmail.com>
In-Reply-To
<1360661277-17273-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             | 21 +++++++++++++--------
 2 files changed, 15 insertions(+), 8 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 639c9a5..75feee5 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -10,12 +10,15 @@
 #include "parse-options.h"
 
 static unsigned long garbage;
+static off_t size_garbage;
 
 static void real_report_garbage(const char *desc,
 				const char *path, int len,
 				const char *name)
 {
 	struct strbuf sb = STRBUF_INIT;
+	struct stat st;
+
 	if (len && name)
 		strbuf_addf(&sb, "%.*s/%s", len, path, name);
 	else if (!len && name)
@@ -23,6 +26,10 @@ static void real_report_garbage(const char *desc,
 	else
 		strbuf_addf(&sb, "%s", path);
 	warning("%s: %s", desc, sb.buf);
+
+	if (!stat(sb.buf, &st))
+		size_garbage += st.st_size;
+
 	garbage++;
 	strbuf_release(&sb);
 }
@@ -30,8 +37,7 @@ static void real_report_garbage(const char *desc,
 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) {
@@ -63,11 +69,9 @@ static void count_objects(DIR *d, char *path, int len, int verbose,
 				(*loose_size) += xsize_t(on_disk_bytes(st));
 		}
 		if (bad) {
-			if (verbose) {
-				error("garbage found: %.*s/%s",
-				      len + 2, path, ent->d_name);
-				(*garbage)++;
-			}
+			if (verbose)
+				report_garbage("garbage found",
+					       path, len + 2, ent->d_name);
 			continue;
 		}
 		(*loose)++;
@@ -117,7 +121,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) {
@@ -142,6 +146,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
Previous: Nguyễn Thái Ngọc Duy
Message 17 of 17 in “count-objects improvements”
  1. 0/4 count-objects improvementsNguyễn Thái Ngọc Duy, Feb 12, 2013
  2. 1/4 git-count-objects.txt: describe each line in -v outputNguyễn Thái Ngọc Duy, Feb 12, 2013
  3. 2/4 sha1_file: reorder code in prepare_packed_git_one()Nguyễn Thái Ngọc Duy, Feb 12, 2013
  4. 3/4 count-objects: report garbage files in pack directory tooNguyễn Thái Ngọc Duy, Feb 12, 2013
  5. Junio C HamanoFeb 12, 2013
  6. 0/4 count-objects improvementsNguyễn Thái Ngọc Duy, Feb 13, 2013
  7. 1/4 git-count-objects.txt: describe each line in -v outputNguyễn Thái Ngọc Duy, Feb 13, 2013
  8. 2/4 sha1_file: reorder code in prepare_packed_git_one()Nguyễn Thái Ngọc Duy, Feb 13, 2013
  9. 3/4 count-objects: report garbage files in pack directory tooNguyễn Thái Ngọc Duy, Feb 13, 2013
  10. Junio C HamanoFeb 13, 2013
  11. Junio C HamanoFeb 13, 2013
  12. Duy NguyenFeb 14, 2013
  13. Junio C HamanoFeb 14, 2013
  14. 3/4 count-objects: report garbage files in pack directory tooNguyễn Thái Ngọc Duy, Feb 15, 2013
  15. Junio C HamanoFeb 15, 2013
  16. 4/4 count-objects: report how much disk space taken by garbage filesNguyễn Thái Ngọc Duy, Feb 13, 2013
  17. 4/4 count-objects: report how much disk space taken by garbage filesNguyễn Thái Ngọc Duy, Feb 12, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.