Merge branch 'ak/refs-files-root-ref-lock' into next

The files backend has been updated to avoid unconditionally locking
the 'packed-refs' file when deleting a root ref (which are never
packed).

* ak/refs-files-root-ref-lock:
  refs/files: avoid packed-refs lock for root ref deletion
next
Junio C Hamano 2026-09-16 09:22:56 -07:00
commit c8568ea3e1
2 changed files with 45 additions and 3 deletions

View File

@ -3034,10 +3034,12 @@ static int files_transaction_prepare(struct ref_store *ref_store,

if (update->flags & REF_DELETING &&
!(update->flags & REF_LOG_ONLY) &&
!(update->flags & REF_IS_PRUNING)) {
!(update->flags & REF_IS_PRUNING) &&
!is_root_ref(update->refname)) {
/*
* This reference has to be deleted from
* packed-refs if it exists there.
* This reference has to be deleted from packed-refs if it
* exists there. Root refs are never packed, so we do not
* have to delete them from packed-refs.
*/
if (!packed_transaction) {
packed_transaction = ref_store_transaction_begin(

View File

@ -540,4 +540,44 @@ test_expect_success SYMLINKS,!MINGW,!WITH_BREAKING_CHANGES 'core.preferSymlinkRe
test "$(test_readlink .git/TEST_SYMREF_HEAD)" = refs/heads/new
'

test_expect_success 'deleting a root ref does not lock packed-refs' '
test_when_finished "rm -rf root-ref" &&
git init root-ref &&
(
cd root-ref &&
test_commit initial &&
git update-ref AUTO_MERGE HEAD &&
git pack-refs --all &&
test_path_is_file .git/AUTO_MERGE &&
cp .git/packed-refs expect &&
: >.git/packed-refs.lock &&
git update-ref --no-deref -d AUTO_MERGE &&
test_path_is_missing .git/AUTO_MERGE &&
test_path_is_file .git/packed-refs.lock &&
test_cmp expect .git/packed-refs
)
'

test_expect_success 'deleting root and packed refs in one transaction requires packed-refs lock' '
test_when_finished "rm -rf root-ref" &&
git init root-ref &&
(
cd root-ref &&
test_commit initial &&
git update-ref refs/heads/packed-branch HEAD &&
git pack-refs --all &&
test_path_is_missing .git/refs/heads/packed-branch &&
git update-ref AUTO_MERGE HEAD &&
git refs list --include-root-refs >expect &&
: >.git/packed-refs.lock &&
test_must_fail git update-ref --no-deref --stdin 2>err <<-EOF &&
delete AUTO_MERGE
delete refs/heads/packed-branch
EOF
test_grep "Unable to create .*packed-refs.lock" err &&
git refs list --include-root-refs >actual &&
test_cmp expect actual
)
'

test_done