Merge branch 'wc/packed-ref-removal-cleanup'
When "git update-ref -d" removes a ref that is packed, it left empty directories under $GIT_DIR/refs/ for * wc/packed-ref-removal-cleanup: refs: cleanup directories when deleting packed ref
This commit is contained in:
commit
16f91451fa
@ -45,10 +45,10 @@
|
|||||||
#define REF_UPDATE_VIA_HEAD (1 << 8)
|
#define REF_UPDATE_VIA_HEAD (1 << 8)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Used as a flag in ref_update::flags when the loose reference has
|
* Used as a flag in ref_update::flags when a reference has been
|
||||||
* been deleted.
|
* 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 {
|
struct ref_lock {
|
||||||
char *ref_name;
|
char *ref_name;
|
||||||
@ -2852,6 +2852,7 @@ static int files_transaction_finish(struct ref_store *ref_store,
|
|||||||
|
|
||||||
if (update->flags & REF_DELETING &&
|
if (update->flags & REF_DELETING &&
|
||||||
!(update->flags & REF_LOG_ONLY)) {
|
!(update->flags & REF_LOG_ONLY)) {
|
||||||
|
update->flags |= REF_DELETED_RMDIR;
|
||||||
if (!(update->type & REF_ISPACKED) ||
|
if (!(update->type & REF_ISPACKED) ||
|
||||||
update->type & REF_ISSYMREF) {
|
update->type & REF_ISSYMREF) {
|
||||||
/* It is a loose reference. */
|
/* It is a loose reference. */
|
||||||
@ -2861,7 +2862,6 @@ static int files_transaction_finish(struct ref_store *ref_store,
|
|||||||
ret = TRANSACTION_GENERIC_ERROR;
|
ret = TRANSACTION_GENERIC_ERROR;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
update->flags |= REF_DELETED_LOOSE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2874,9 +2874,9 @@ cleanup:
|
|||||||
for (i = 0; i < transaction->nr; i++) {
|
for (i = 0; i < transaction->nr; i++) {
|
||||||
struct ref_update *update = transaction->updates[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
|
* empty parent directories. (Note that this
|
||||||
* can only work because we have already
|
* can only work because we have already
|
||||||
* removed the lockfile.)
|
* removed the lockfile.)
|
||||||
|
@ -1598,4 +1598,13 @@ test_expect_success 'transaction cannot restart ongoing transaction' '
|
|||||||
test_must_fail git show-ref --verify refs/heads/restart
|
test_must_fail git show-ref --verify refs/heads/restart
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'directory not created deleting packed ref' '
|
||||||
|
git branch d1/d2/r1 HEAD &&
|
||||||
|
git pack-refs --all &&
|
||||||
|
test_path_is_missing .git/refs/heads/d1/d2 &&
|
||||||
|
git update-ref -d refs/heads/d1/d2/r1 &&
|
||||||
|
test_path_is_missing .git/refs/heads/d1/d2 &&
|
||||||
|
test_path_is_missing .git/refs/heads/d1
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user