Volume XXII, number 279Tuesday, October 6, 2026Latest message 45 minutes ago

The Git List

News and archive of git@vger.kernel.org, since April 2005

patchrefs/files: avoid packed-refs lock for root ref deletion

5 messages between Sep 10, 2026 and Sep 12, 2026, from Ariel Keselman, Patrick Steinhardt.

Plain Markdown or JSON for tools and agents. Diffs are folded; open one to read it.

Ariel KeselmanSep 10, 2026, 06:45 UTC on lore
Hi,

Deleting root refs in the files backend unnecessarily locks packed-refs, even though root refs cannot be packed. This can cause post-commit cleanup to report an error after a successful commit in a linked worktree with read-only shared metadata.

The attached patch skips that lock for root-ref deletion and adds regression tests. All seven new tests fail without the fix and pass with it; broader ref, worktree, and sequencer tests also pass.

AI assistance was used to generate the patch, tests, and commit message.

Thanks, Ariel

From c5d12e97a78123965590553fddc0dd78af3e006e Mon Sep 17 00:00:00 2001
From: Ariel Keselman <skariel@gmail.com>
Date: Wed, 9 Sep 2026 22:16:50 -0700
To: git@vger.kernel.org
Subject: [PATCH] refs/files: avoid packed-refs lock for root ref deletion

Deleting a root ref queues a packed-ref transaction in the files backend, even though root refs cannot be packed. For example, holding .git/packed-refs.lock makes "git update-ref --no-deref -d AUTO_MERGE" fail, whether or not AUTO_MERGE exists.

This also affects post-commit cleanup, which deletes AUTO_MERGE after updating HEAD. In a linked worktree with read-only shared metadata, commit succeeds but cleanup reports a packed-refs.lock error. Deleting CHERRY_PICK_HEAD and REVERT_HEAD is affected as well.

Skip the packed transaction for root-ref deletions. Keep loose-ref locking and packed-ref deletion for other refs unchanged.

Test existing and absent root refs with packed-refs.lock held. Also check that root-ref deletion leaves packed refs intact, and that a packed branch still requires the lock and can be deleted once it is released.

Signed-off-by: Ariel Keselman <skariel@gmail.com>
---
AI assistance was used to generate the patch, tests, and commit message.
Based on maint at e9019fcafe (Git 2.55).
Validation:
- All seven new tests fail with packed-refs.lock errors without the fix.
- With the fix, t0600 and t0601 pass (one platform skip in t0600).
- Broader ref, worktree, rebase, cherry-pick, commit and merge tests pass:
  123 scripts, 4083 tests on the maint-based tree.
- After merging with master at b8242b093d, 128 scripts / 4178 tests and
  260 unit tests pass.
 refs/files-backend.c        |  9 +++++---
 t/t0600-reffiles-backend.sh | 46 +++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 3 deletions(-)
Show changes to 2 files +52 −3

refs/files-backend.c, t/t0600-reffiles-backend.sh

diff --git a/refs/files-backend.c b/refs/files-backend.c
index a4c7858787..41887f180f 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2981,10 +2981,13 @@ 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.
+			 * Root refs cannot be packed. Do not acquire the shared
+			 * packed-refs lock when deleting a per-worktree root ref.
+			 * Other references have to be deleted from
+			 * packed-refs if they exist there.
 			 */
 			if (!packed_transaction) {
 				packed_transaction = ref_store_transaction_begin(
diff --git a/t/t0600-reffiles-backend.sh b/t/t0600-reffiles-backend.sh
index 74bfa2e9ba..b7f3287841 100755
--- a/t/t0600-reffiles-backend.sh
+++ b/t/t0600-reffiles-backend.sh
@@ -519,4 +519,50 @@ test_expect_success 'symref transaction supports false symlink config' '
 	test_cmp expect actual
 '
 
+for ref in AUTO_MERGE CHERRY_PICK_HEAD REVERT_HEAD
+do
+	for state in existing missing
+	do
+		test_expect_success "deleting $state $ref does not lock packed-refs" '
+			test_when_finished "rm -rf root-ref" &&
+			git init root-ref &&
+			(
+				cd root-ref &&
+				test_commit initial &&
+				if test "$state" = existing
+				then
+					git update-ref "$ref" HEAD
+				fi &&
+				: >.git/packed-refs.lock &&
+				git -c core.packedRefsTimeout=0 update-ref --no-deref -d "$ref" &&
+				test_path_is_missing ".git/$ref" &&
+				test_path_is_file .git/packed-refs.lock
+			)
+		'
+	done
+done
+
+test_expect_success 'root ref deletion preserves packed refs and their locking' '
+	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 &&
+		cp .git/packed-refs expect &&
+		git update-ref AUTO_MERGE HEAD &&
+		: >.git/packed-refs.lock &&
+		git -c core.packedRefsTimeout=0 update-ref --no-deref -d AUTO_MERGE &&
+		test_cmp expect .git/packed-refs &&
+		test_must_fail git -c core.packedRefsTimeout=0 update-ref -d refs/heads/packed-branch 2>err &&
+		test_grep "Unable to create .*packed-refs.lock" err &&
+		test_cmp expect .git/packed-refs &&
+		rm .git/packed-refs.lock &&
+		git update-ref -d refs/heads/packed-branch &&
+		test_must_fail git rev-parse --verify refs/heads/packed-branch
+	)
+'
+
 test_done
-- 
2.55.0
Patrick SteinhardtSep 10, 2026, 08:35 UTC in reply to Ariel Keselman on lore

Re: [PATCH] refs/files: avoid packed-refs lock for root ref deletion

Hi,
On Wed, Sep 09, 2026 at 11:45:46PM -0700, Ariel Keselman wrote:
Show 12 quoted lines
> Hi,
> 
> Deleting root refs in the files backend unnecessarily locks
> packed-refs, even though root refs cannot be packed. This can cause
> post-commit cleanup to report an error after a successful commit in a
> linked worktree with read-only shared metadata.
> 
> The attached patch skips that lock for root-ref deletion and adds
> regression tests. All seven new tests fail without the fix and pass
> with it; broader ref, worktree, and sequencer tests also pass.
> 
> AI assistance was used to generate the patch, tests, and commit message.

Please consult Documentation/SubmittingPatches. The expectation is that patches will not be sent as attachments. I'd recommend using a tool like b4 to send your patches, which handles a lot of the nuisances for you.

Show 18 quoted lines
> From c5d12e97a78123965590553fddc0dd78af3e006e Mon Sep 17 00:00:00 2001
> From: Ariel Keselman <skariel@gmail.com>
> Date: Wed, 9 Sep 2026 22:16:50 -0700
> To: git@vger.kernel.org
> Subject: [PATCH] refs/files: avoid packed-refs lock for root ref deletion
> 
> Deleting a root ref queues a packed-ref transaction in the files
> backend, even though root refs cannot be packed. For example, holding
> .git/packed-refs.lock makes "git update-ref --no-deref -d AUTO_MERGE"
> fail, whether or not AUTO_MERGE exists.
> 
> This also affects post-commit cleanup, which deletes AUTO_MERGE after
> updating HEAD. In a linked worktree with read-only shared metadata,
> commit succeeds but cleanup reports a packed-refs.lock error. Deleting
> CHERRY_PICK_HEAD and REVERT_HEAD is affected as well.
> 
> Skip the packed transaction for root-ref deletions. Keep loose-ref
> locking and packed-ref deletion for other refs unchanged.

Makes sense indeed. Root refs are never packed, and consequently it does not make any sense for us to try to evict them from packed-refs, either.

Show 19 quoted lines
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index a4c7858787..41887f180f 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -2981,10 +2981,13 @@ 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.
> +			 * Root refs cannot be packed. Do not acquire the shared
> +			 * packed-refs lock when deleting a per-worktree root ref.
> +			 * Other references have to be deleted from
> +			 * packed-refs if they exist there.
>  			 */
Nit: I feel like this comment is a bit too focussed on the root refs
now. A small, incremental change could've been:
	/*
     * This reference has to be deleted from packed-refs if it exists
     * there. Note that root refs are never packed, so we don't have to
     * deltee those from packed-refs.
	 */
Show 11 quoted lines
>  			if (!packed_transaction) {
>  				packed_transaction = ref_store_transaction_begin(
> diff --git a/t/t0600-reffiles-backend.sh b/t/t0600-reffiles-backend.sh
> index 74bfa2e9ba..b7f3287841 100755
> --- a/t/t0600-reffiles-backend.sh
> +++ b/t/t0600-reffiles-backend.sh
> @@ -519,4 +519,50 @@ test_expect_success 'symref transaction supports false symlink config' '
>  	test_cmp expect actual
>  '
>  
> +for ref in AUTO_MERGE CHERRY_PICK_HEAD REVERT_HEAD

Isn't it a bit excessive to test for all these different root refs? I don't see much value in doing that.

> +do
> +	for state in existing missing

Likewise, I'm not quite sure what we prove here. Should be fine to just test with an existing root ref.

Show 13 quoted lines
> +	do
> +		test_expect_success "deleting $state $ref does not lock packed-refs" '
> +			test_when_finished "rm -rf root-ref" &&
> +			git init root-ref &&
> +			(
> +				cd root-ref &&
> +				test_commit initial &&
> +				if test "$state" = existing
> +				then
> +					git update-ref "$ref" HEAD
> +				fi &&
> +				: >.git/packed-refs.lock &&
> +				git -c core.packedRefsTimeout=0 update-ref --no-deref -d "$ref" &&

Setting the timeout shouldn't really have any impact on the test result, should it?

Show 29 quoted lines
> +				test_path_is_missing ".git/$ref" &&
> +				test_path_is_file .git/packed-refs.lock
> +			)
> +		'
> +	done
> +done
> +
> +test_expect_success 'root ref deletion preserves packed refs and their locking' '
> +	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 &&
> +		cp .git/packed-refs expect &&
> +		git update-ref AUTO_MERGE HEAD &&
> +		: >.git/packed-refs.lock &&
> +		git -c core.packedRefsTimeout=0 update-ref --no-deref -d AUTO_MERGE &&
> +		test_cmp expect .git/packed-refs &&
> +		test_must_fail git -c core.packedRefsTimeout=0 update-ref -d refs/heads/packed-branch 2>err &&
> +		test_grep "Unable to create .*packed-refs.lock" err &&
> +		test_cmp expect .git/packed-refs &&
> +		rm .git/packed-refs.lock &&
> +		git update-ref -d refs/heads/packed-branch &&
> +		test_must_fail git rev-parse --verify refs/heads/packed-branch
> +	)
> +'

And this test feels like it's testing almost exactly what the other test does. The only difference is that we have an actual packed-refs file, but that can easily be squashed into the other test, too.

That being said, what we're missing is a test that creates a single transaction that updates both a root ref and a non-root-ref with a preexisting lockfile. Such a transaction should fail even though we skip the packed transaction for the roof ref itself.

Thanks!
Patrick
Ariel KeselmanSep 10, 2026, 14:55 UTC in reply to Patrick Steinhardt on lore

[PATCH v2] refs/files: avoid packed-refs lock for root ref deletion

Deleting a root ref queues a packed-ref transaction in the files backend, even though root refs cannot be packed. For example, holding .git/packed-refs.lock makes "git update-ref --no-deref -d AUTO_MERGE" fail, whether or not AUTO_MERGE exists.

This also affects post-commit cleanup, which deletes AUTO_MERGE after updating HEAD. In a linked worktree with read-only shared metadata, commit succeeds but cleanup reports a packed-refs.lock error. Deleting CHERRY_PICK_HEAD and REVERT_HEAD is affected as well.

Skip the packed transaction for root-ref deletions. Keep loose-ref locking and packed-ref deletion for other refs unchanged.

Test deleting a root ref with packed-refs.lock held, and check that a transaction deleting both a root ref and a packed branch still fails without changing either ref.

Signed-off-by: Ariel Keselman <skariel@gmail.com>
---
Thanks for the review, Patrick.
Changes since v1:
- Keep the packed-ref deletion comment focused on its original purpose.
- Use one existing root ref and include a packed-refs file in the test.
- Drop the timeout overrides and redundant individual-ref cases.
- Add a transaction deleting a root ref and a packed branch together;
  check that a held packed-ref lock causes failure and preserves both refs.

AI assistance was used to generate the patch, tests, and commit message, including this revision.

The root-ref deletion regression fails without the fix. With the fix, 123 test scripts / 4078 tests pass, along with 249 unit tests and t0600 with SHA-256 (one platform skip in t0600).

 refs/files-backend.c        |  8 ++++---
 t/t0600-reffiles-backend.sh | 43 +++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 3 deletions(-)
Show changes to 2 files +48 −3

refs/files-backend.c, t/t0600-reffiles-backend.sh

diff --git a/refs/files-backend.c b/refs/files-backend.c
index a4c7858787..0333d5d355 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2981,10 +2981,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(
diff --git a/t/t0600-reffiles-backend.sh b/t/t0600-reffiles-backend.sh
index 74bfa2e9ba..65ca19e84b 100755
--- a/t/t0600-reffiles-backend.sh
+++ b/t/t0600-reffiles-backend.sh
@@ -519,4 +519,47 @@ test_expect_success 'symref transaction supports false symlink config' '
 	test_cmp expect actual
 '
 
+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 pack-refs --all &&
+		cp .git/packed-refs expect &&
+		git update-ref AUTO_MERGE HEAD &&
+		: >.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 rev-parse AUTO_MERGE refs/heads/packed-branch >expect &&
+		cat >stdin <<-EOF &&
+		start
+		delete AUTO_MERGE
+		delete refs/heads/packed-branch
+		prepare
+		commit
+		EOF
+		: >.git/packed-refs.lock &&
+		test_must_fail git update-ref --no-deref --stdin <stdin 2>err &&
+		test_grep "Unable to create .*packed-refs.lock" err &&
+		git rev-parse AUTO_MERGE refs/heads/packed-branch >actual &&
+		test_cmp expect actual
+	)
+'
+
 test_done
-- 
2.55.0
Patrick SteinhardtSep 11, 2026, 08:13 UTC in reply to Ariel Keselman on lore

Re: [PATCH v2] refs/files: avoid packed-refs lock for root ref deletion

On Thu, Sep 10, 2026 at 07:55:28AM -0700, Ariel Keselman wrote:
Show 16 quoted lines
> Deleting a root ref queues a packed-ref transaction in the files
> backend, even though root refs cannot be packed. For example, holding
> .git/packed-refs.lock makes "git update-ref --no-deref -d AUTO_MERGE"
> fail, whether or not AUTO_MERGE exists.
> 
> This also affects post-commit cleanup, which deletes AUTO_MERGE after
> updating HEAD. In a linked worktree with read-only shared metadata,
> commit succeeds but cleanup reports a packed-refs.lock error. Deleting
> CHERRY_PICK_HEAD and REVERT_HEAD is affected as well.
> 
> Skip the packed transaction for root-ref deletions. Keep loose-ref
> locking and packed-ref deletion for other refs unchanged.
> 
> Test deleting a root ref with packed-refs.lock held, and check that a
> transaction deleting both a root ref and a packed branch still fails
> without changing either ref.
Nit: this last paragraph doesn't really add any value, as it's trivially
visible from the patch that we add tests.
Show 17 quoted lines
> Signed-off-by: Ariel Keselman <skariel@gmail.com>
> ---
> Thanks for the review, Patrick.
> 
> Changes since v1:
> - Keep the packed-ref deletion comment focused on its original purpose.
> - Use one existing root ref and include a packed-refs file in the test.
> - Drop the timeout overrides and redundant individual-ref cases.
> - Add a transaction deleting a root ref and a packed branch together;
>   check that a held packed-ref lock causes failure and preserves both refs.
> 
> AI assistance was used to generate the patch, tests, and commit message,
> including this revision.
> 
> The root-ref deletion regression fails without the fix. With the fix,
> 123 test scripts / 4078 tests pass, along with 249 unit tests and t0600
> with SHA-256 (one platform skip in t0600).

Huh? I hope that _all_ tests pass with this, not only 4078, and I would assume that you verified that this is the case at least on your machine.

Show 17 quoted lines
> diff --git a/t/t0600-reffiles-backend.sh b/t/t0600-reffiles-backend.sh
> index 74bfa2e9ba..65ca19e84b 100755
> --- a/t/t0600-reffiles-backend.sh
> +++ b/t/t0600-reffiles-backend.sh
> @@ -519,4 +519,47 @@ test_expect_success 'symref transaction supports false symlink config' '
>  	test_cmp expect actual
>  '
>  
> +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 pack-refs --all &&
> +		cp .git/packed-refs expect &&
> +		git update-ref AUTO_MERGE HEAD &&

For added benefit we could even execute git-pack-refs(1) after having created AUTO_MERGE and then execute `test_path_is_file` for it just to prove that it really doesn't get packed. But other than that the tests look good to me.

Show 19 quoted lines
> +		: >.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 rev-parse AUTO_MERGE refs/heads/packed-branch >expect &&
We could strengthen this a bit by listing the state of all refs:
    git refs list --include-root-refs >expect
Show 6 quoted lines
> +		cat >stdin <<-EOF &&
> +		start
> +		delete AUTO_MERGE
> +		delete refs/heads/packed-branch
> +		prepare
> +		commit

We can drop start/prepare/commit here, those are optional. We can also drop the extra file and just write the data into git-update-ref(1) directly via the heredoc.

Show 8 quoted lines
> +		EOF
> +		: >.git/packed-refs.lock &&
> +		test_must_fail git update-ref --no-deref --stdin <stdin 2>err &&
> +		test_grep "Unable to create .*packed-refs.lock" err &&
> +		git rev-parse AUTO_MERGE refs/heads/packed-branch >actual &&
> +		test_cmp expect actual
> +	)
> +'
Thanks!
Patrick
Ariel KeselmanSep 12, 2026, 02:12 UTC in reply to Patrick Steinhardt on lore

Re: [PATCH v2] refs/files: avoid packed-refs lock for root ref deletion

Sorry, I accidentally sent v3 as a new thread. It is available here:
https://lore.kernel.org/git/20260912014609.535922-1-skariel@gmail.com/
On Fri, Sep 11, 2026 at 1:13 AM Patrick Steinhardt <ps@pks.im> wrote:
Show 113 quoted lines
>
> On Thu, Sep 10, 2026 at 07:55:28AM -0700, Ariel Keselman wrote:
> > Deleting a root ref queues a packed-ref transaction in the files
> > backend, even though root refs cannot be packed. For example, holding
> > .git/packed-refs.lock makes "git update-ref --no-deref -d AUTO_MERGE"
> > fail, whether or not AUTO_MERGE exists.
> >
> > This also affects post-commit cleanup, which deletes AUTO_MERGE after
> > updating HEAD. In a linked worktree with read-only shared metadata,
> > commit succeeds but cleanup reports a packed-refs.lock error. Deleting
> > CHERRY_PICK_HEAD and REVERT_HEAD is affected as well.
> >
> > Skip the packed transaction for root-ref deletions. Keep loose-ref
> > locking and packed-ref deletion for other refs unchanged.
> >
> > Test deleting a root ref with packed-refs.lock held, and check that a
> > transaction deleting both a root ref and a packed branch still fails
> > without changing either ref.
>
> Nit: this last paragraph doesn't really add any value, as it's trivially
> visible from the patch that we add tests.
>
> > Signed-off-by: Ariel Keselman <skariel@gmail.com>
> > ---
> > Thanks for the review, Patrick.
> >
> > Changes since v1:
> > - Keep the packed-ref deletion comment focused on its original purpose.
> > - Use one existing root ref and include a packed-refs file in the test.
> > - Drop the timeout overrides and redundant individual-ref cases.
> > - Add a transaction deleting a root ref and a packed branch together;
> >   check that a held packed-ref lock causes failure and preserves both refs.
> >
> > AI assistance was used to generate the patch, tests, and commit message,
> > including this revision.
> >
> > The root-ref deletion regression fails without the fix. With the fix,
> > 123 test scripts / 4078 tests pass, along with 249 unit tests and t0600
> > with SHA-256 (one platform skip in t0600).
>
> Huh? I hope that _all_ tests pass with this, not only 4078, and I would
> assume that you verified that this is the case at least on your machine.
>
> > diff --git a/t/t0600-reffiles-backend.sh b/t/t0600-reffiles-backend.sh
> > index 74bfa2e9ba..65ca19e84b 100755
> > --- a/t/t0600-reffiles-backend.sh
> > +++ b/t/t0600-reffiles-backend.sh
> > @@ -519,4 +519,47 @@ test_expect_success 'symref transaction supports false symlink config' '
> >       test_cmp expect actual
> >  '
> >
> > +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 pack-refs --all &&
> > +             cp .git/packed-refs expect &&
> > +             git update-ref AUTO_MERGE HEAD &&
>
> For added benefit we could even execute git-pack-refs(1) after having
> created AUTO_MERGE and then execute `test_path_is_file` for it just to
> prove that it really doesn't get packed. But other than that the tests
> look good to me.
>
> > +             : >.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 rev-parse AUTO_MERGE refs/heads/packed-branch >expect &&
>
> We could strengthen this a bit by listing the state of all refs:
>
>     git refs list --include-root-refs >expect
>
> > +             cat >stdin <<-EOF &&
> > +             start
> > +             delete AUTO_MERGE
> > +             delete refs/heads/packed-branch
> > +             prepare
> > +             commit
>
> We can drop start/prepare/commit here, those are optional. We can also
> drop the extra file and just write the data into git-update-ref(1)
> directly via the heredoc.
>
> > +             EOF
> > +             : >.git/packed-refs.lock &&
> > +             test_must_fail git update-ref --no-deref --stdin <stdin 2>err &&
> > +             test_grep "Unable to create .*packed-refs.lock" err &&
> > +             git rev-parse AUTO_MERGE refs/heads/packed-branch >actual &&
> > +             test_cmp expect actual
> > +     )
> > +'
>
> Thanks!
>
> Patrick

Back to recent threads

[PATCH] refs/files: avoid packed-refs lock for root ref deletion | The Git List