Skip to content

Commit 051e2dc

Browse files
committed
gc/repack: release packs when needed
On Windows, files cannot be removed nor renamed if there are still handles held by a process. To remedy that, we introduced the close_all_packs() function. Earlier, we made sure that the packs are released just before `git gc` is spawned, in case that gc wants to remove no-longer needed packs. But this developer forgot that gc itself also needs to let go of packs, e.g. when consolidating all packs via the --aggressive option. Likewise, `git repack -d` wants to delete obsolete packs and therefore needs to close all pack handles, too. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent a364543 commit 051e2dc

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

builtin/gc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,10 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
434434

435435
report_garbage = report_pack_garbage;
436436
reprepare_packed_git();
437-
if (pack_garbage.nr > 0)
437+
if (pack_garbage.nr > 0) {
438+
close_all_packs();
438439
clean_pack_garbage();
440+
}
439441

440442
if (auto_gc && too_many_loose_objects())
441443
warning(_("There are too many unreachable loose objects; "

builtin/repack.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
289289
if (!names.nr && !quiet)
290290
printf("Nothing new to pack.\n");
291291

292+
close_all_packs();
293+
292294
/*
293295
* Ok we have prepared all new packfiles.
294296
* First see if there are packs of the same name and if so

0 commit comments

Comments
 (0)