]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/maintenance: fix locking race when handling "gc" task
authorPatrick Steinhardt <ps@pks.im>
Tue, 3 Jun 2025 14:01:20 +0000 (16:01 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Jun 2025 15:30:52 +0000 (08:30 -0700)
commit1b5074e614d9b32bd760d2583e7435685ca4faab
tree71ba44b7a1eb408f54b04921ecfeaa1a981bc414
parentd2b084c66037f1a77b3e061ae7e4d96cbdbf6c05
builtin/maintenance: fix locking race when handling "gc" task

The "gc" task has a similar locking race as the one that we have fixed
for the "pack-refs" and "reflog-expire" tasks in preceding commits. Fix
this by splitting up the logic of the "gc" task:

  - We execute `gc_before_repack()` in the foreground, which contains
    the logic that git-gc(1) itself would execute in the foreground, as
    well.

  - We spawn git-gc(1) after detaching, but with a new hidden flag that
    suppresses calling `gc_before_repack()`.

Like this we have roughly the same logic as git-gc(1) itself and know to
repack refs and reflogs before detaching, thus fixing the race.

Note that `gc_before_repack()` is renamed to `gc_foreground_tasks()` to
better reflect what this function does.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/gc.c
t/t7900-maintenance.sh