use delete_refs when deleting tags or branches
authorPhil Hord <redacted>
Thu, 21 Jan 2021 03:23:32 +0000 (19:23 -0800)
committerJunio C Hamano <redacted>
Fri, 22 Jan 2021 00:05:05 +0000 (16:05 -0800)
commit8198907795500a5054ad04507b9189cfa5431737
tree72c6b5d84acb3f503b49dca7370a8a50d6cf9ccf
parent66e871b6647ffea61a77a0f82c7ef3415f1ee79c
use delete_refs when deleting tags or branches

'git tag -d' accepts one or more tag refs to delete, but each deletion
is done by calling `delete_ref` on each argv. This is very slow when
removing from packed refs. Use delete_refs instead so all the removals
can be done inside a single transaction with a single update.

Do the same for 'git branch -d'.

Since delete_refs performs all the packed-refs delete operations
inside a single transaction, if any of the deletes fail then all
them will be skipped. In practice, none of them should fail since
we verify the hash of each one before calling delete_refs, but some
network error or odd permissions problem could have different results
after this change.

Also, since the file-backed deletions are not performed in the same
transaction, those could succeed even when the packed-refs transaction
fails.

After deleting branches, remove the branch config only if the branch
ref was removed and was not subsequently added back in.

A manual test deleting 24,000 tags took about 30 minutes using
delete_ref.  It takes about 5 seconds using delete_refs.

Acked-by: Elijah Newren <redacted>
Signed-off-by: Phil Hord <redacted>
Signed-off-by: Junio C Hamano <redacted>
builtin/branch.c
builtin/tag.c
git clone https://git.99rst.org/PROJECT