git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] refs/files: remove empty parent dirs when ref creation fails

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 8, 2025, 21:52 UTC
Message-ID
<xmqqzfdes63u.fsf@gitster.g>
In-Reply-To
<20250708-b4-pks-reffiles-prune-empty-dirs-on-abort-v1-1-3bae02e4f034@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 23 quoted lines
> 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>
> ---
> Hi,
>
> this issue is something we recently discovered in Gitaly. It's nothing
> world breaking, but I think it makes sense to try and keep the refdb in
> a as-clean-as-possible state anyway.

Would we lose an empty ".git/refs/tags/" directory if we fail to create the first tag?

	... goes and looks at the try_remove function ...
OK, we protect the leading two levels when doing so, so we are safe.
Will queue.  Thanks.
Previous: Patrick Steinhardt
Message 2 of 2 in “refs/files: remove empty parent dirs when ref creation fails”
  1. refs/files: remove empty parent dirs when ref creation failsPatrick Steinhardt, Jul 8, 2025
  2. Junio C HamanoJul 8, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.