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

[PATCH 1/3] prepare_packed_git(): find more garbage

From
Doug Kelly <dougk.ff7@gmail.com>
Date
Nov 14, 2015, 00:10 UTC
Message-ID
<1447459853-28838-2-git-send-email-dougk.ff7@gmail.com>
In-Reply-To
<1447459853-28838-1-git-send-email-dougk.ff7@gmail.com>

.bitmap and .keep files without .idx/.pack don't make much sense, so make sure these are reported as garbage as well. At the same time, refactoring report_garbage to handle extra bits.

Signed-off-by: Doug Kelly <dougk.ff7@gmail.com>
---
 builtin/count-objects.c | 16 ++++++----------
 cache.h                 |  4 +++-
 sha1_file.c             | 17 +++++++++++++++--
 t/t5304-prune.sh        |  2 ++
 4 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index ba92919..1637037 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -17,19 +17,15 @@ static off_t loose_size;
 
 static const char *bits_to_msg(unsigned seen_bits)
 {
-	switch (seen_bits) {
-	case 0:
-		return "no corresponding .idx or .pack";
-	case PACKDIR_FILE_GARBAGE:
+	if (seen_bits ==  PACKDIR_FILE_GARBAGE)
 		return "garbage found";
-	case PACKDIR_FILE_PACK:
+	else if (seen_bits & PACKDIR_FILE_PACK && seen_bits ^ ~PACKDIR_FILE_IDX)
 		return "no corresponding .idx";
-	case PACKDIR_FILE_IDX:
+	else if (seen_bits & PACKDIR_FILE_IDX && seen_bits ^ ~PACKDIR_FILE_PACK)
 		return "no corresponding .pack";
-	case PACKDIR_FILE_PACK|PACKDIR_FILE_IDX:
-	default:
-		return NULL;
-	}
+	else if (seen_bits == 0 || seen_bits ^ ~(PACKDIR_FILE_IDX|PACKDIR_FILE_PACK))
+		return "no corresponding .idx or .pack";
+	return NULL;
 }
 
 static void real_report_garbage(unsigned seen_bits, const char *path)
diff --git a/cache.h b/cache.h
index 736abc0..5b9d791 100644
--- a/cache.h
+++ b/cache.h
@@ -1292,7 +1292,9 @@ extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_
 /* A hook to report invalid files in pack directory */
 #define PACKDIR_FILE_PACK 1
 #define PACKDIR_FILE_IDX 2
-#define PACKDIR_FILE_GARBAGE 4
+#define PACKDIR_FILE_BITMAP 4
+#define PACKDIR_FILE_KEEP 8
+#define PACKDIR_FILE_GARBAGE 16
 extern void (*report_garbage)(unsigned seen_bits, const char *path);
 
 extern void prepare_packed_git(void);
diff --git a/sha1_file.c b/sha1_file.c
index 3d56746..5f939e4 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1225,6 +1225,15 @@ static void report_helper(const struct string_list *list,
 	if (seen_bits == (PACKDIR_FILE_PACK|PACKDIR_FILE_IDX))
 		return;
 
+	if (seen_bits == (PACKDIR_FILE_PACK|PACKDIR_FILE_IDX|PACKDIR_FILE_BITMAP))
+		return;
+
+	if (seen_bits == (PACKDIR_FILE_PACK|PACKDIR_FILE_IDX|PACKDIR_FILE_KEEP))
+		return;
+
+	if (seen_bits == (PACKDIR_FILE_PACK|PACKDIR_FILE_IDX|PACKDIR_FILE_BITMAP|PACKDIR_FILE_KEEP))
+		return;
+
 	for (; first < last; first++)
 		report_garbage(seen_bits, list->items[first].string);
 }
@@ -1256,9 +1265,13 @@ static void report_pack_garbage(struct string_list *list)
 			first = i;
 		}
 		if (!strcmp(path + baselen, "pack"))
-			seen_bits |= 1;
+			seen_bits |= PACKDIR_FILE_PACK;
 		else if (!strcmp(path + baselen, "idx"))
-			seen_bits |= 2;
+			seen_bits |= PACKDIR_FILE_IDX;
+		else if (!strcmp(path + baselen, "bitmap"))
+			seen_bits |= PACKDIR_FILE_BITMAP;
+		else if (!strcmp(path + baselen, "keep"))
+			seen_bits |= PACKDIR_FILE_KEEP;
 	}
 	report_helper(list, seen_bits, first, list->nr);
 }
diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh
index def203c..1ea8279 100755
--- a/t/t5304-prune.sh
+++ b/t/t5304-prune.sh
@@ -261,6 +261,8 @@ test_expect_success 'clean pack garbage with gc' '
 warning: no corresponding .idx or .pack: .git/objects/pack/fake3.keep
 warning: no corresponding .idx: .git/objects/pack/foo.keep
 warning: no corresponding .idx: .git/objects/pack/foo.pack
+warning: no corresponding .pack: .git/objects/pack/fake2.idx
+warning: no corresponding .pack: .git/objects/pack/fake2.keep
 EOF
 	test_cmp expected actual
 '
-- 
2.6.1
Previous: Doug KellyNext: Stefan Beller
Message 2 of 33 in “Add cleanup for garbage .bitmap files”
  1. 0/3 Add cleanup for garbage .bitmap filesDoug Kelly, Nov 14, 2015
  2. 1/3 prepare_packed_git(): find more garbageDoug Kelly, Nov 14, 2015
  3. Stefan BellerNov 14, 2015
  4. 1/3 prepare_packed_git(): find more garbageDoug Kelly, Nov 14, 2015
  5. 2/3 t5304: Add test for .bitmap garbage filesDoug Kelly, Nov 14, 2015
  6. 3/3 gc: Clean garbage .bitmap files from pack dirDoug Kelly, Nov 14, 2015
  7. Jeff KingDec 15, 2015
  8. Stefan BellerNov 25, 2015
  9. 1/3 prepare_packed_git(): find more garbageDoug Kelly, Nov 26, 2015
  10. Jeff KingDec 15, 2015
  11. Jeff KingDec 15, 2015
  12. 0/3 prepare_packed_git(): find more garbageDoug Kelly, Dec 19, 2015
  13. 1/3 prepare_packed_git(): find more garbageDoug Kelly, Dec 19, 2015
  14. 2/3 t5304: Add test for .bitmap garbage filesDoug Kelly, Dec 19, 2015
  15. 3/3 gc: Clean garbage .bitmap files from pack dirDoug Kelly, Dec 19, 2015
  16. Jeff KingDec 19, 2015
  17. Jeff KingDec 19, 2015
  18. Jeff KingDec 19, 2015
  19. Stefan BellerJan 11, 2016
  20. 0/4 gc: Clean garbage .bitmap files from pack dirDoug Kelly, Jan 13, 2016
  21. 1/4 prepare_packed_git(): find more garbageDoug Kelly, Jan 13, 2016
  22. 2/4 t5304: Add test for .bitmap garbage filesDoug Kelly, Jan 13, 2016
  23. Junio C HamanoJan 13, 2016
  24. 3/4 t5304: Ensure wanted files are not deletedDoug Kelly, Jan 13, 2016
  25. Junio C HamanoJan 13, 2016
  26. Doug KellyJan 18, 2016
  27. Junio C HamanoJan 19, 2016
  28. 4/4 gc: Clean garbage .bitmap files from pack dirDoug Kelly, Jan 13, 2016
  29. Doug KellyNov 26, 2015
  30. Doug KellyNov 14, 2015
  31. 2/3 t5304: Add test for .bitmap garbage filesDoug Kelly, Nov 14, 2015
  32. Stefan BellerNov 14, 2015
  33. 3/3 gc: Clean garbage .bitmap files from pack dirDoug Kelly, Nov 14, 2015

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.