From b1e3fcdb9b087b4d69836dd5a228648008ff419a Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Mon, 11 May 2026 20:46:57 -0400 Subject: [PATCH] pack-bitmap: fix inverted binary search in `pseudo_merge_at()` The binary search in `pseudo_merge_at()` has its "lo" and "hi" updates swapped: when the midpoint's offset is less than the target, it sets `hi = mi` (searching left) instead of `lo = mi + 1` (searching right), and vice versa. This means that lookups for pseudo-merges whose offset is not near the midpoint of the pseudo-merge table are likely to fail. In practice, with a single pseudo-merge group this is masked because the lone entry is always at the midpoint. With multiple groups, the inverted comparisons cause lookups to search in the wrong direction, potentially missing entries. Swap the "lo" and "hi" assignments to search in the correct direction, making it possible to apply pseudo-merges during fill-in when more than one pseudo-merge exists in a group. Signed-off-by: Taylor Blau Signed-off-by: Junio C Hamano --- pseudo-merge.c | 4 ++-- t/t5333-pseudo-merge-bitmaps.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pseudo-merge.c b/pseudo-merge.c index ff18b6c364..fb71c76179 100644 --- a/pseudo-merge.c +++ b/pseudo-merge.c @@ -559,9 +559,9 @@ static struct pseudo_merge *pseudo_merge_at(const struct pseudo_merge_map *pm, if (got == want) return use_pseudo_merge(pm, &pm->v[mi]); else if (got < want) - hi = mi; - else lo = mi + 1; + else + hi = mi; } warning(_("could not find pseudo-merge for commit %s at offset %"PRIuMAX), diff --git a/t/t5333-pseudo-merge-bitmaps.sh b/t/t5333-pseudo-merge-bitmaps.sh index 3d7a766812..5411fbf1e0 100755 --- a/t/t5333-pseudo-merge-bitmaps.sh +++ b/t/t5333-pseudo-merge-bitmaps.sh @@ -496,7 +496,7 @@ test_expect_success 'apply pseudo-merges during fill-in traversal' ' ) ' -test_expect_failure 'apply pseudo-merges from multiple groups during fill-in' ' +test_expect_success 'apply pseudo-merges from multiple groups during fill-in' ' test_when_finished "rm -fr pseudo-merge-fill-in-multi" && git init pseudo-merge-fill-in-multi && (