t7701: make annotated tag unreachable

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Jun 24, 2023 at 10:33 UTC 25d59524bbc79b4f4560fca1b9b22c8c36780636
1 file changed +13 -2
t/t7701-repack-unpack-unreachable.sh
+13 -2
@@ -126,8 +126,18 @@ test_expect_success 'gc.recentObjectsHook' '
126 git cat-file -p $obj2 &&
127 git cat-file -p $obj3 &&
128
129 - git tag -a -m tag obj2-tag $obj2 &&
130 - obj2_tag="$(git rev-parse obj2-tag)" &&
129 + # make an unreachable annotated tag object to ensure we rescue objects
130 + # which are reachable from non-pruned unreachable objects
131 + obj2_tag="$(git mktag <<-EOF
132 + object $obj2
133 + type blob
134 + tag obj2-tag
135 + tagger T A Gger <tagger@example.com> 1234567890 -0000
136 + EOF
137 + )" &&
138 +
139 + obj2_tag_pack="$(echo $obj2_tag | git pack-objects .git/objects/pack/pack)" &&
140 + git prune-packed &&
141
142 write_script precious-objects <<-EOF &&
143 echo $obj2_tag
@@ -136,6 +146,7 @@ test_expect_success 'gc.recentObjectsHook' '
146
147 test-tool chmtime =-86400 .git/objects/pack/pack-$pack2.pack &&
148 test-tool chmtime =-86400 .git/objects/pack/pack-$pack3.pack &&
149 + test-tool chmtime =-86400 .git/objects/pack/pack-$obj2_tag_pack.pack &&
150 git repack -A -d --unpack-unreachable=1.hour.ago &&
151
152 git cat-file -p $obj1 &&