Hi, this patch series fixes races around locking the "packed-refs" file when auto-maintenance decides to repack it. This issue has been reported e.g. via [1] and [2]. The root cause is that git-gc(1) used to know to detach _after_ having repacked references. As such, callers wouldn't continue with their thing until we have already packed refs, and thus the race does not exist there. git-maintenance(1) didn't have the same split though, so this patch series retrofits that logic. The series is structured as follows: - Patches 1 and 2 do some light refactorings. - Patches 3 to 5 refactor how we set up the list of tasks to not rely on globals anymore. Instead, we now have a single source of truth for which tasks exactly will be run. - The remaining patches introduce the split of before/after-detach tasks and wire them up for "pack-refs", "reflog-expire" and "gc" tasks. Thanks! Patrick [1]: <CAJR-fbZ4X1+gN75m2dUvocR6NkowLOZ9F26cjBy8w1qd181OoQ@xxxxxxxxxxxxxx> [2]: <CANi7bVAkNc+gY1NoXfJuDRjxjZLTgL8Lfn8_ZmWsvLAoiLPkNg@xxxxxxxxxxxxxx> --- Patrick Steinhardt (11): builtin/gc: use designated field initializers for maintenance tasks builtin/gc: drop redundant local variable builtin/maintenance: centralize configuration of explicit tasks builtin/maintenance: mark "--task=" and "--schedule=" as incompatible builtin/maintenance: stop modifying global array of tasks builtin/maintenance: extract function to run tasks builtin/maintenance: fix typedef for function pointers builtin/maintenance: let tasks do maintenance before and after detach builtin/maintenance: fix locking race when packing refs and reflogs builtin/gc: avoid global state in `gc_before_repack()` builtin/maintenance: fix locking race when handling "gc" task builtin/gc.c | 386 +++++++++++++++++++++++++++---------------------- t/t7900-maintenance.sh | 19 ++- 2 files changed, 229 insertions(+), 176 deletions(-) --- base-commit: 845c48a16a7f7b2c44d8cb137b16a4a1f0140229 change-id: 20250527-b4-pks-maintenance-ref-lock-race-11ae5d68e06f