gc: remove garbage .idx files from pack dir
Add a custom report_garbage handler to collect and remove garbage .idx files from the pack directory. Signed-off-by: Doug Kelly <dougk.ff7@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Doug Kelly committed
Nov 3, 2015 at 21:05 UTC
478f34d2b6ea13d5f56ecec04de7ca7ce18367c0
2 files changed
+22
-1
builtin/gc.c
+21
@@ -57,6 +57,22 @@ static void remove_pidfile_on_signal(int signo)
57
raise(signo);
58
}
59
60
+static struct string_list pack_garbage = STRING_LIST_INIT_DUP;
61
+
62
+static void clean_pack_garbage(void)
63
+{
64
+ int i;
65
+ for (i = 0; i < pack_garbage.nr; i++)
66
+ unlink_or_warn(pack_garbage.items[i].string);
67
+ string_list_clear(&pack_garbage, 0);
68
+}
69
+
70
+static void report_pack_garbage(unsigned seen_bits, const char *path)
71
+{
72
+ if (seen_bits == PACKDIR_FILE_IDX)
73
+ string_list_append(&pack_garbage, path);
74
+}
75
+
76
static void git_config_date_string(const char *key, const char **output)
77
{
78
if (git_config_get_string_const(key, output))
@@ -372,6 +388,11 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
388
if (run_command_v_opt(rerere.argv, RUN_GIT_CMD))
389
return error(FAILED_RUN, rerere.argv[0]);
390
391
+ report_garbage = report_pack_garbage;
392
+ reprepare_packed_git();
393
+ if (pack_garbage.nr > 0)
394
+ clean_pack_garbage();
395
+
396
if (auto_gc && too_many_loose_objects())
397
warning(_("There are too many unreachable loose objects; "
398
"run 'git prune' to remove them."));
t/t5304-prune.sh
+1
-1
@@ -245,7 +245,7 @@ EOF
245
test_cmp expected actual
246
'
247
248
-test_expect_failure 'clean pack garbage with gc' '
248
+test_expect_success 'clean pack garbage with gc' '
249
test_when_finished "rm -f .git/objects/pack/fake*" &&
250
test_when_finished "rm -f .git/objects/pack/foo*" &&
251
: >.git/objects/pack/foo.keep &&