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

[PATCH 4/4] gc: Clean garbage .bitmap files from pack dir

From
Doug Kelly <dougk.ff7@gmail.com>
Date
Jan 13, 2016, 17:07 UTC
Message-ID
<8277e5f62991fce9524ea3020636fc8dafe926b4.1452704305.git.dougk.ff7@gmail.com>
In-Reply-To
<cover.1452704305.git.dougk.ff7@gmail.com>

Similar to cleaning up excess .idx files, clean any garbage .bitmap files that are not otherwise associated with any .idx/.pack files.

Signed-off-by: Doug Kelly <dougk.ff7@gmail.com>
Suggested-by: Jeff King <peff@peff.net>
---
 builtin/gc.c     | 35 ++++++++++++++++++++++++++++++++++-
 t/t5304-prune.sh |  2 +-
 2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/builtin/gc.c b/builtin/gc.c
index c583aad..79e9886 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -58,8 +58,41 @@ static void clean_pack_garbage(void)
 
 static void report_pack_garbage(unsigned seen_bits, const char *path)
 {
-	if (seen_bits == PACKDIR_FILE_IDX)
+	/* We know these are useless without the matching .pack */
+	if (ends_with(path, ".bitmap") || ends_with(path, ".idx")) {
 		string_list_append(&pack_garbage, path);
+		return;
+	}
+
+	/*
+	 * A pack without other files cannot be used, but should be saved,
+	 * as this is a recoverable situation (we may even see it racily
+	 * as new packs come into existence).
+	 */
+	if (ends_with(path, ".pack"))
+		return;
+
+	/*
+	 * A .keep file is useless without the matching pack, but it
+	 * _could_ contain information generated by the user. Let's keep it.
+	 * In the future, we may expand this to look for obvious leftover
+	 * receive-pack locks and drop them.
+	 */
+	if (ends_with(path, ".keep"))
+		return;
+
+	/*
+	 * A totally unrelated garbage file should be kept, to err
+	 * on the conservative side.
+	 */
+	if (seen_bits & PACKDIR_FILE_GARBAGE)
+		return;
+
+	/*
+	 * We have a file type that the garbage-reporting functions
+	 * know about but we don't. This function needs updating.
+	 */
+	die("BUG: report_pack_garbage confused");
 }
 
 static void git_config_date_string(const char *key, const char **output)
diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh
index f7c380c..cbcc0c0 100755
--- a/t/t5304-prune.sh
+++ b/t/t5304-prune.sh
@@ -257,7 +257,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'clean pack garbage with gc' '
+test_expect_success 'clean pack garbage with gc' '
 	test_when_finished "rm -f .git/objects/pack/fake*" &&
 	test_when_finished "rm -f .git/objects/pack/foo*" &&
 	: >.git/objects/pack/foo.keep &&
-- 
2.6.1
Previous: Junio C HamanoNext: Doug Kelly
Message 28 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.