Merge branch 'ps/refname-avail-check-optim'

Incorrect sorting of refs with bytes with high-bit set on platforms
with signed char led to a BUG, which has been corrected.

* ps/refname-avail-check-optim:
  refs/packed: fix BUG when seeking refs with UTF-8 characters
maint
Junio C Hamano 2025-04-17 10:28:19 -07:00
commit c81538ea6c
2 changed files with 17 additions and 2 deletions

View File

@ -980,9 +980,9 @@ static int packed_ref_iterator_advance(struct ref_iterator *ref_iterator)
continue;

while (prefix && *prefix) {
if (*refname < *prefix)
if ((unsigned char)*refname < (unsigned char)*prefix)
BUG("packed-refs backend yielded reference preceding its prefix");
else if (*refname > *prefix)
else if ((unsigned char)*refname > (unsigned char)*prefix)
return ITER_DONE;
prefix++;
refname++;

View File

@ -42,4 +42,19 @@ test_expect_success 'no error from stale entry in packed-refs' '
test_cmp expect actual
'

test_expect_success 'list packed refs with unicode characters' '
test_when_finished "rm -rf repo" &&
git init repo &&
(
cd repo &&
test_commit --no-tag A &&
git update-ref refs/heads/ HEAD &&
git update-ref refs/heads/z HEAD &&
git pack-refs --all &&
printf "%s commit\trefs/heads/z\n" $(git rev-parse HEAD) >expect &&
git for-each-ref refs/heads/z >actual &&
test_cmp expect actual
)
'

test_done