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 <sunshine@sunshineco.com> Acked-by: Thomas Rast <trast@inf.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Jul 23, 2013 at 10:28 UTC f8395edc6f5c59a92adcf42ea20a01872ec22700
2 files changed +4 -1
line-log.c
+2
@@ -115,6 +115,8 @@ static void sort_and_merge_range_set(struct range_set *rs)
115 qsort(rs->ranges, rs->nr, sizeof(struct range), range_cmp);
116
117 for (i = 0; i < rs->nr; i++) {
118 + if (rs->ranges[i].start == rs->ranges[i].end)
119 + continue;
120 if (o > 0 && rs->ranges[i].start <= rs->ranges[o-1].end) {
121 if (rs->ranges[o-1].end < rs->ranges[i].end)
122 rs->ranges[o-1].end = rs->ranges[i].end;
t/t4211-line-log.sh
+2 -1
@@ -67,7 +67,8 @@ test_bad_opts "-L :foo:b.c" "no match"
67 # There is a separate bug when an empty -L range is the first -L encountered,
68 # thus to demonstrate this particular bug, the empty -L range must follow a
69 # 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) &&
72 n=$(expr $(wc -l <b.c) + 1) &&
73 git log -L1,1:b.c -L$n:b.c
74 '