Skip to content

Commit 9201261

Browse files
KarthikNayakgitster
authored andcommitted
ref-cache: set prefix_state when seeking
In 090eb5336c (refs: selectively set prefix in the seek functions, 2025-07-15) we separated the seeking functionality of reference iterators from the functionality to set prefix to an iterator. This allows users of ref iterators to seek to a particular reference to provide pagination support. The files-backend, uses the ref-cache iterator to iterate over loose refs. The iterator tracks directories and entries already processed via a stack of levels. Each level corresponds to a directory under the files backend. New levels are added to the stack, and when all entries from a level is yielded, the corresponding level is popped from the stack. To accommodate seeking, we need to populate and traverse the levels to stop the requested seek marker at the appropriate level and its entry index. Each level also contains a 'prefix_state' which is used for prefix matching, this allows the iterator to skip levels/entries which don't match a prefix. The default value of 'prefix_state' is PREFIX_CONTAINS_DIR, which yields all entries within a level. When purely seeking without prefix matching, we want to yield all entries. The commit however, skips setting the value explicitly. This causes the MemorySanitizer to issue a 'use-of-uninitialized-value' error when running 't/t6302-for-each-ref-filter'. Set the value explicitly to avoid to fix the issue. Reported-by: Kyle Lippincott <[email protected]> Helped-by: Kyle Lippincott <[email protected]> Helped-by: Jeff King <[email protected]> Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dabecb9 commit 9201261

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

refs/ref-cache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ static int cache_ref_iterator_seek(struct ref_iterator *ref_iterator,
527527
level = &iter->levels[iter->levels_nr++];
528528
level->dir = dir;
529529
level->index = -1;
530+
level->prefix_state = PREFIX_CONTAINS_DIR;
530531
} else {
531532
/* reduce the index so the leaf node is iterated over */
532533
if (cmp <= 0 && !slash)

0 commit comments

Comments
 (0)