Skip to content

Commit f8395ed

Browse files
sunshinecogitster
authored andcommitted
range-set: satisfy non-empty ranges invariant
range-set invariants are: ranges must be (1) non-empty, (2) disjoint, (3) sorted in ascending order. During processing, various range-set utility functions break the invariants (for instance, by adding empty ranges), with the expectation that a finalizing sort_and_merge_range_set() will restore sanity. sort_and_merge_range_set(), however, neglects to fold out empty ranges, thus it fails to satisfy the non-empty constraint. Subsequent range-set functions crash or throw an assertion failure upon encountering such an anomaly. Rectify the situation by having sort_and_merge_range_set() fold out empty ranges. Signed-off-by: Eric Sunshine <[email protected]> Acked-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 99780b0 commit f8395ed

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

line-log.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ static void sort_and_merge_range_set(struct range_set *rs)
115115
qsort(rs->ranges, rs->nr, sizeof(struct range), range_cmp);
116116

117117
for (i = 0; i < rs->nr; i++) {
118+
if (rs->ranges[i].start == rs->ranges[i].end)
119+
continue;
118120
if (o > 0 && rs->ranges[i].start <= rs->ranges[o-1].end) {
119121
if (rs->ranges[o-1].end < rs->ranges[i].end)
120122
rs->ranges[o-1].end = rs->ranges[i].end;

t/t4211-line-log.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ test_bad_opts "-L :foo:b.c" "no match"
6767
# There is a separate bug when an empty -L range is the first -L encountered,
6868
# thus to demonstrate this particular bug, the empty -L range must follow a
6969
# non-empty -L range.
70-
test_expect_failure '-L {empty-range} (any -L)' '
70+
test_expect_success '-L {empty-range} (any -L)' '
71+
n=$(expr $(cat b.c | wc -l) + 1) &&
7172
n=$(expr $(wc -l <b.c) + 1) &&
7273
git log -L1,1:b.c -L$n:b.c
7374
'

0 commit comments

Comments
 (0)