Skip to content

Commit 9ca8305

Browse files
ttaylorrgitster
authored andcommitted
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 <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 79f261d commit 9ca8305

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

pseudo-merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,9 @@ static struct pseudo_merge *pseudo_merge_at(const struct pseudo_merge_map *pm,
559559
if (got == want)
560560
return use_pseudo_merge(pm, &pm->v[mi]);
561561
else if (got < want)
562-
hi = mi;
563-
else
564562
lo = mi + 1;
563+
else
564+
hi = mi;
565565
}
566566

567567
warning(_("could not find pseudo-merge for commit %s at offset %"PRIuMAX),

t/t5333-pseudo-merge-bitmaps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ test_expect_success 'apply pseudo-merges during fill-in traversal' '
496496
)
497497
'
498498

499-
test_expect_failure 'apply pseudo-merges from multiple groups during fill-in' '
499+
test_expect_success 'apply pseudo-merges from multiple groups during fill-in' '
500500
git init pseudo-merge-fill-in-multi &&
501501
test_when_finished "rm -fr pseudo-merge-fill-in-multi" &&
502502
(

0 commit comments

Comments
 (0)