Skip to content

Commit b0a9d62

Browse files
vangdfanggitster
authored andcommitted
gc: clean garbage .bitmap files from pack dir
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 <[email protected]> Suggested-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8462ae4 commit b0a9d62

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

builtin/gc.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,41 @@ static void clean_pack_garbage(void)
5858

5959
static void report_pack_garbage(unsigned seen_bits, const char *path)
6060
{
61-
if (seen_bits == PACKDIR_FILE_IDX)
61+
/* We know these are useless without the matching .pack */
62+
if (ends_with(path, ".bitmap") || ends_with(path, ".idx")) {
6263
string_list_append(&pack_garbage, path);
64+
return;
65+
}
66+
67+
/*
68+
* A pack without other files cannot be used, but should be saved,
69+
* as this is a recoverable situation (we may even see it racily
70+
* as new packs come into existence).
71+
*/
72+
if (ends_with(path, ".pack"))
73+
return;
74+
75+
/*
76+
* A .keep file is useless without the matching pack, but it
77+
* _could_ contain information generated by the user. Let's keep it.
78+
* In the future, we may expand this to look for obvious leftover
79+
* receive-pack locks and drop them.
80+
*/
81+
if (ends_with(path, ".keep"))
82+
return;
83+
84+
/*
85+
* A totally unrelated garbage file should be kept, to err
86+
* on the conservative side.
87+
*/
88+
if (seen_bits & PACKDIR_FILE_GARBAGE)
89+
return;
90+
91+
/*
92+
* We have a file type that the garbage-reporting functions
93+
* know about but we don't. This function needs updating.
94+
*/
95+
die("BUG: report_pack_garbage confused");
6396
}
6497

6598
static void git_config_date_string(const char *key, const char **output)

t/t5304-prune.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ EOF
257257
test_cmp expected actual
258258
'
259259

260-
test_expect_failure 'clean pack garbage with gc' '
260+
test_expect_success 'clean pack garbage with gc' '
261261
test_when_finished "rm -f .git/objects/pack/fake*" &&
262262
test_when_finished "rm -f .git/objects/pack/foo*" &&
263263
: >.git/objects/pack/foo.keep &&

0 commit comments

Comments
 (0)