Remove empty directories in refs/ when housekeeping
During investigating why rugged.tags.first
could be slow, I realized that it's iterating through a lot of empty directories in refs/heads/*
.
I just checked that gitlab-ce has 9010 empty directories, and the one we're profiling has 29435 empty directories. This could explain why the latter has less refs yet it's still slower.
I found https://git.kaarsemaker.net/git/commit/be7c6d467e8cc4104e1a15e8ff2d7b207624c685/ Quoting:
pack-refs: remove newly empty directories
In a large repository which uses directories to organize many refs, "git pack-refs --all --prune" does not improve performance so much as it should, unless we remove all the now-empty directories as well.
If I do git pack-refs --all --prune
, it would remove the empty directories only when trying to remove a ref. If the directories are empty to begin with, Git won't do anything there. For example, having:
- a/b/c/ (empty directory)
- d/e/f/ref (ref)
Git would remove d/e/f/ref
and d/e/f/
and d/e/
and all of them, but a/b/c/
would stay intact.
We should find some way to clean them up.