]> Kevux Git Server - rit/commit
refs/files: remove empty parent dirs when ref creation fails
authorPatrick Steinhardt <ps@pks.im>
Tue, 8 Jul 2025 10:19:54 +0000 (12:19 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Jul 2025 21:52:56 +0000 (14:52 -0700)
commita3a7f2051686e087cba80f3af1557107406205c9
treec46b4262dbe4605cf39b7df386fbef8dce6776b9
parent16bd9f20a403117f2e0d9bcda6c6e621d3763e77
refs/files: remove empty parent dirs when ref creation fails

When creating a new reference in the "files" backend we first create the
directory hierarchy for that reference, then create the lockfile for
that reference, and finally rename the lockfile into place. When the
transaction gets aborted we prune the lockfile, but we don't clean up
the directory hierarchy that we may have created for the lockfile.

In some egde cases this can lead to lots of empty directories being
cluttered in the ".git/refs" directory that really serve no purpose at
all. We know to prune such empty directories when packing refs, but that
only patches over the issue.

Improve this by removing empty parents when cleaning up still-locked
references in `files_transaction_cleanup()`. This function is also
called when preparing or committing the transaction, so this change also
helps when not explicitly aborting the transaction.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs/files-backend.c
t/t1400-update-ref.sh