Skip to content

Commit bea37f1

Browse files
pks-tgitster
authored andcommitted
ref-filter: fix stale parsed objects
In 054f5f4 (ref-filter: parse objects on demand, 2025-10-23) we have started to skip parsing some objects in case we don't need to access their values in the first place. This was done by introducing a new member `struct expand_data::maybe_object` that gets populated on demand via `get_or_parse_object()`. This has led to a regression though where the object now gets reused because we don't reset it properly. The `oi` structure is declared in global scope, and there is no single place where we reset it before invoking `get_object()`. The consequence is that the `maybe_object` member doesn't get reset across calls, so subsequent calls will end up reusing the same object. This is only an issue for a subset of retrieved values, as not all of the infrastructure ends up calling `get_or_parse_object()`. So the effect is limited, which is probably why the issue wasn't detected earlier. Fix the issue by resetting `maybe_object` in `get_object()`. Reported-by: Junio C Hamano <gitster@pobox.com> Based-on-patch-by: Jeff King <peff@peff.net> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent a29e2e8 commit bea37f1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

ref-filter.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,6 +2367,8 @@ static int get_object(struct ref_array_item *ref, int deref,
23672367
int eaten = 0;
23682368
int ret;
23692369

2370+
oi->maybe_object = NULL;
2371+
23702372
if (oi->info.contentp) {
23712373
/* We need to know that to use parse_object_buffer properly */
23722374
oi->info.sizep = &oi->size;

t/t7004-tag.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,4 +2332,24 @@ test_expect_success 'If tag cannot be created then tag message file is not unlin
23322332
test_path_exists .git/TAG_EDITMSG
23332333
'
23342334

2335+
test_expect_success 'annotated tag version sort' '
2336+
git tag -a -m "sample 1.0" vsample-1.0 &&
2337+
git tag -a -m "sample 2.0" vsample-2.0 &&
2338+
git tag -a -m "sample 10.0" vsample-10.0 &&
2339+
cat >expect <<-EOF &&
2340+
vsample-1.0
2341+
vsample-2.0
2342+
vsample-10.0
2343+
EOF
2344+
2345+
git tag --list --sort=version:tag vsample-\* >actual &&
2346+
test_cmp expect actual &&
2347+
2348+
# Ensure that we also handle this case alright in the case we have the
2349+
# peeled values cached e.g. via the packed-refs file.
2350+
git pack-refs --all &&
2351+
git tag --list --sort=version:tag vsample-\* &&
2352+
test_cmp expect actual
2353+
'
2354+
23352355
test_done

0 commit comments

Comments
 (0)