diff options
author | Doug Kelly <dougk.ff7@gmail.com> | 2016-01-13 11:07:12 -0600 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-01-13 12:13:36 -0800 |
commit | b0a9d62a7471e58832a575a78d57f8fb26822125 (patch) | |
tree | 6d18983b916aefdfe3d59750f826cf0e37aed11f | |
parent | 8462ae4033b17537f997f188dc87ad5b5ee10f89 (diff) | |
download | git-dk/gc-more-wo-pack.tar.gz |
gc: clean garbage .bitmap files from pack dirdk/gc-more-wo-pack
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | builtin/gc.c | 35 | ||||
-rwxr-xr-x | t/t5304-prune.sh | 2 |
2 files changed, 35 insertions, 2 deletions
diff --git a/builtin/gc.c b/builtin/gc.c index c583aad6ec..79e9886cd9 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 f7c380c5cf..cbcc0c0e68 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 && |