Git Mailing List Archive mirror
 help / color / mirror / Atom feed
* [PATCH] t7701: make annotated tag unreachable
@ 2023-06-21 10:21 Taylor Blau
  2023-06-24  4:38 ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Taylor Blau @ 2023-06-21 10:21 UTC (permalink / raw
  To: git; +Cc: Jeff King, Junio C Hamano

In 4dc16e2cb0 (gc: introduce `gc.recentObjectsHook`, 2023-06-07), we
added tests to ensure that prune-able (i.e. unreachable and with mtime
older than the cutoff) objects which are marked as recent via the new
`gc.recentObjectsHook` configuration are unpacked as loose with
`--unpack-unreachable`.

In that test, we also ensure that objects which are reachable from other
unreachable objects which were *not* pruned are kept as well, regardless
of their mtimes. For this, we use an annotated tag pointing at a blob
($obj2) which would otherwise be pruned.

But after pruning, that object is kept around for two reasons. One, the
tag object's mtime wasn't adjusted to be beyond the 1-hour cutoff, so it
would be kept as due to its recency regardless. The other reason is
because the tag itself is reachable.

Use mktag to write the tag object directly without pointing a reference
at it, and adjust the mtime of the tag object to be older than the
cutoff to ensure that our `gc.recentObjectsHook` configuration is
working as intended.

Noticed-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
Peff pointed this out to me after the gc.recentObjectsHook stuff was in
'next', but this should go on top. This patch is based off of the tip of
"tb/gc-recent-object-hook".

 t/t7701-repack-unpack-unreachable.sh | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/t/t7701-repack-unpack-unreachable.sh b/t/t7701-repack-unpack-unreachable.sh
index ba428c18a8..ceb4e805d2 100755
--- a/t/t7701-repack-unpack-unreachable.sh
+++ b/t/t7701-repack-unpack-unreachable.sh
@@ -126,8 +126,19 @@ test_expect_success 'gc.recentObjectsHook' '
 	git cat-file -p $obj2 &&
 	git cat-file -p $obj3 &&

+	# make an unreachable annotated tag object to ensure we rescue objects
+	# which are reachable from non-pruned unreachable objects
 	git tag -a -m tag obj2-tag $obj2 &&
-	obj2_tag="$(git rev-parse obj2-tag)" &&
+	obj2_tag="$(git mktag <<-EOF
+	object $obj2
+	type blob
+	tag obj2-tag
+	tagger T A Gger <tagger@example.com> 1234567890 -0000
+	EOF
+	)" &&
+
+	obj2_tag_pack="$(echo $obj2_tag | git pack-objects .git/objects/pack/pack)" &&
+	git prune-packed &&

 	write_script precious-objects <<-EOF &&
 	echo $obj2_tag
@@ -136,6 +147,7 @@ test_expect_success 'gc.recentObjectsHook' '

 	test-tool chmtime =-86400 .git/objects/pack/pack-$pack2.pack &&
 	test-tool chmtime =-86400 .git/objects/pack/pack-$pack3.pack &&
+	test-tool chmtime =-86400 .git/objects/pack/pack-$obj2_tag_pack.pack &&
 	git repack -A -d --unpack-unreachable=1.hour.ago &&

 	git cat-file -p $obj1 &&
--
2.40.1.478.g4dc16e2cb0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] t7701: make annotated tag unreachable
  2023-06-21 10:21 [PATCH] t7701: make annotated tag unreachable Taylor Blau
@ 2023-06-24  4:38 ` Jeff King
  2023-06-24 14:33   ` [PATCH v2] " Taylor Blau
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff King @ 2023-06-24  4:38 UTC (permalink / raw
  To: Taylor Blau; +Cc: git, Junio C Hamano

On Wed, Jun 21, 2023 at 06:21:10AM -0400, Taylor Blau wrote:

> But after pruning, that object is kept around for two reasons. One, the
> tag object's mtime wasn't adjusted to be beyond the 1-hour cutoff, so it
> would be kept as due to its recency regardless. The other reason is
> because the tag itself is reachable.
> 
> Use mktag to write the tag object directly without pointing a reference
> at it, and adjust the mtime of the tag object to be older than the
> cutoff to ensure that our `gc.recentObjectsHook` configuration is
> working as intended.

Thanks, this should fix the problem (which you can notice by making the
recentObjectsHook in the test a noop and seeing that it still passes).

But there's one more thing...

> diff --git a/t/t7701-repack-unpack-unreachable.sh b/t/t7701-repack-unpack-unreachable.sh
> index ba428c18a8..ceb4e805d2 100755
> --- a/t/t7701-repack-unpack-unreachable.sh
> +++ b/t/t7701-repack-unpack-unreachable.sh
> @@ -126,8 +126,19 @@ test_expect_success 'gc.recentObjectsHook' '
>  	git cat-file -p $obj2 &&
>  	git cat-file -p $obj3 &&
> 
> +	# make an unreachable annotated tag object to ensure we rescue objects
> +	# which are reachable from non-pruned unreachable objects
>  	git tag -a -m tag obj2-tag $obj2 &&
> -	obj2_tag="$(git rev-parse obj2-tag)" &&
> +	obj2_tag="$(git mktag <<-EOF
> +	object $obj2
> +	type blob
> +	tag obj2-tag
> +	tagger T A Gger <tagger@example.com> 1234567890 -0000
> +	EOF
> +	)" &&

Since we are using "mktag" here, the call to "git tag" can go away
entirely. It's not only redundant, but it erroneously keeps reachability
to $obj2. The test still does something useful (it makes sure that
$obj2_tag was saved), but it is failing to test what it wanted to about
$obj2, namely that it is kept because the hook mentioned an object that
points to it.

So we'd want to squash in:

diff --git a/t/t7701-repack-unpack-unreachable.sh b/t/t7701-repack-unpack-unreachable.sh
index ceb4e805d2..fe6c3e77a3 100755
--- a/t/t7701-repack-unpack-unreachable.sh
+++ b/t/t7701-repack-unpack-unreachable.sh
@@ -128,7 +128,6 @@ test_expect_success 'gc.recentObjectsHook' '
 
 	# make an unreachable annotated tag object to ensure we rescue objects
 	# which are reachable from non-pruned unreachable objects
-	git tag -a -m tag obj2-tag $obj2 &&
 	obj2_tag="$(git mktag <<-EOF
 	object $obj2
 	type blob

-Peff

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2] t7701: make annotated tag unreachable
  2023-06-24  4:38 ` Jeff King
@ 2023-06-24 14:33   ` Taylor Blau
  2023-06-27  7:09     ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Taylor Blau @ 2023-06-24 14:33 UTC (permalink / raw
  To: git; +Cc: Jeff King, Junio C Hamano

In 4dc16e2cb0 (gc: introduce `gc.recentObjectsHook`, 2023-06-07), we
added tests to ensure that prune-able (i.e. unreachable and with mtime
older than the cutoff) objects which are marked as recent via the new
`gc.recentObjectsHook` configuration are unpacked as loose with
`--unpack-unreachable`.

In that test, we also ensure that objects which are reachable from other
unreachable objects which were *not* pruned are kept as well, regardless
of their mtimes. For this, we use an annotated tag pointing at a blob
($obj2) which would otherwise be pruned.

But after pruning, that object is kept around for two reasons. One, the
tag object's mtime wasn't adjusted to be beyond the 1-hour cutoff, so it
would be kept as due to its recency regardless. The other reason is
because the tag itself is reachable.

Use mktag to write the tag object directly without pointing a reference
at it, and adjust the mtime of the tag object to be older than the
cutoff to ensure that our `gc.recentObjectsHook` configuration is
working as intended.

Noticed-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
Fixes a trivial oversight from an earlier version of this patch noticed
by Peff.

Range-diff against v1:
1:  48d3c2c187 ! 1:  259b1b5591 t7701: make annotated tag unreachable
    @@ t/t7701-repack-unpack-unreachable.sh: test_expect_success 'gc.recentObjectsHook'
      	git cat-file -p $obj2 &&
      	git cat-file -p $obj3 &&

    +-	git tag -a -m tag obj2-tag $obj2 &&
    +-	obj2_tag="$(git rev-parse obj2-tag)" &&
     +	# make an unreachable annotated tag object to ensure we rescue objects
     +	# which are reachable from non-pruned unreachable objects
    - 	git tag -a -m tag obj2-tag $obj2 &&
    --	obj2_tag="$(git rev-parse obj2-tag)" &&
     +	obj2_tag="$(git mktag <<-EOF
     +	object $obj2
     +	type blob

 t/t7701-repack-unpack-unreachable.sh | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/t/t7701-repack-unpack-unreachable.sh b/t/t7701-repack-unpack-unreachable.sh
index ba428c18a8..fe6c3e77a3 100755
--- a/t/t7701-repack-unpack-unreachable.sh
+++ b/t/t7701-repack-unpack-unreachable.sh
@@ -126,8 +126,18 @@ test_expect_success 'gc.recentObjectsHook' '
 	git cat-file -p $obj2 &&
 	git cat-file -p $obj3 &&

-	git tag -a -m tag obj2-tag $obj2 &&
-	obj2_tag="$(git rev-parse obj2-tag)" &&
+	# make an unreachable annotated tag object to ensure we rescue objects
+	# which are reachable from non-pruned unreachable objects
+	obj2_tag="$(git mktag <<-EOF
+	object $obj2
+	type blob
+	tag obj2-tag
+	tagger T A Gger <tagger@example.com> 1234567890 -0000
+	EOF
+	)" &&
+
+	obj2_tag_pack="$(echo $obj2_tag | git pack-objects .git/objects/pack/pack)" &&
+	git prune-packed &&

 	write_script precious-objects <<-EOF &&
 	echo $obj2_tag
@@ -136,6 +146,7 @@ test_expect_success 'gc.recentObjectsHook' '

 	test-tool chmtime =-86400 .git/objects/pack/pack-$pack2.pack &&
 	test-tool chmtime =-86400 .git/objects/pack/pack-$pack3.pack &&
+	test-tool chmtime =-86400 .git/objects/pack/pack-$obj2_tag_pack.pack &&
 	git repack -A -d --unpack-unreachable=1.hour.ago &&

 	git cat-file -p $obj1 &&
--
2.40.1.479.g48d3c2c187.dirty

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] t7701: make annotated tag unreachable
  2023-06-24 14:33   ` [PATCH v2] " Taylor Blau
@ 2023-06-27  7:09     ` Jeff King
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff King @ 2023-06-27  7:09 UTC (permalink / raw
  To: Taylor Blau; +Cc: git, Junio C Hamano

On Sat, Jun 24, 2023 at 10:33:47AM -0400, Taylor Blau wrote:

> In 4dc16e2cb0 (gc: introduce `gc.recentObjectsHook`, 2023-06-07), we
> added tests to ensure that prune-able (i.e. unreachable and with mtime
> older than the cutoff) objects which are marked as recent via the new
> `gc.recentObjectsHook` configuration are unpacked as loose with
> `--unpack-unreachable`.
> 
> In that test, we also ensure that objects which are reachable from other
> unreachable objects which were *not* pruned are kept as well, regardless
> of their mtimes. For this, we use an annotated tag pointing at a blob
> ($obj2) which would otherwise be pruned.
> 
> But after pruning, that object is kept around for two reasons. One, the
> tag object's mtime wasn't adjusted to be beyond the 1-hour cutoff, so it
> would be kept as due to its recency regardless. The other reason is
> because the tag itself is reachable.
> 
> Use mktag to write the tag object directly without pointing a reference
> at it, and adjust the mtime of the tag object to be older than the
> cutoff to ensure that our `gc.recentObjectsHook` configuration is
> working as intended.
> 
> Noticed-by: Jeff King <peff@peff.net>
> Signed-off-by: Taylor Blau <me@ttaylorr.com>
> ---
> Fixes a trivial oversight from an earlier version of this patch noticed
> by Peff.

Thanks, this looks great to me.

-Peff

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-27  7:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-21 10:21 [PATCH] t7701: make annotated tag unreachable Taylor Blau
2023-06-24  4:38 ` Jeff King
2023-06-24 14:33   ` [PATCH v2] " Taylor Blau
2023-06-27  7:09     ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).