summaryrefslogtreecommitdiff
path: root/refs
diff options
context:
space:
mode:
authorWill Chandler <wfc@wfchandler.org>2021-05-08 05:00:43 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-05-11 04:59:57 (GMT)
commit5f03e5126d895283e6d42093dd4f15cbc30011dd (patch)
treecf827a2550bace761752ff9f32440edce9ca039a /refs
parent48bf2fa8bad054d66bd79c6ba903c89c704201f7 (diff)
downloadgit-5f03e5126d895283e6d42093dd4f15cbc30011dd.zip
git-5f03e5126d895283e6d42093dd4f15cbc30011dd.tar.gz
git-5f03e5126d895283e6d42093dd4f15cbc30011dd.tar.bz2
refs: cleanup directories when deleting packed ref
When deleting a packed ref via 'update-ref -d', a lockfile is made in the directory that would contain the loose copy of that ref, creating any directories in the ref's path that do not exist. When the transaction completes, the lockfile is deleted, but any empty parent directories made when creating the lockfile are left in place. These empty directories are not removed by 'pack-refs' or other housekeeping tasks and will accumulate over time. When deleting a loose ref, we remove all empty parent directories at the end of the transaction. This commit applies the parent directory cleanup logic used when deleting loose refs to packed refs as well. Signed-off-by: Will Chandler <wfc@wfchandler.org> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs')
-rw-r--r--refs/files-backend.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 119972e..49e6ee0 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -45,10 +45,10 @@
#define REF_UPDATE_VIA_HEAD (1 << 8)
/*
- * Used as a flag in ref_update::flags when the loose reference has
- * been deleted.
+ * Used as a flag in ref_update::flags when a reference has been
+ * deleted and the ref's parent directories may need cleanup.
*/
-#define REF_DELETED_LOOSE (1 << 9)
+#define REF_DELETED_RMDIR (1 << 9)
struct ref_lock {
char *ref_name;
@@ -2852,6 +2852,7 @@ static int files_transaction_finish(struct ref_store *ref_store,
if (update->flags & REF_DELETING &&
!(update->flags & REF_LOG_ONLY)) {
+ update->flags |= REF_DELETED_RMDIR;
if (!(update->type & REF_ISPACKED) ||
update->type & REF_ISSYMREF) {
/* It is a loose reference. */
@@ -2861,7 +2862,6 @@ static int files_transaction_finish(struct ref_store *ref_store,
ret = TRANSACTION_GENERIC_ERROR;
goto cleanup;
}
- update->flags |= REF_DELETED_LOOSE;
}
}
}
@@ -2874,9 +2874,9 @@ cleanup:
for (i = 0; i < transaction->nr; i++) {
struct ref_update *update = transaction->updates[i];
- if (update->flags & REF_DELETED_LOOSE) {
+ if (update->flags & REF_DELETED_RMDIR) {
/*
- * The loose reference was deleted. Delete any
+ * The reference was deleted. Delete any
* empty parent directories. (Note that this
* can only work because we have already
* removed the lockfile.)