range-set: satisfy non-empty ranges invariant
authorEric Sunshine <sunshine@sunshineco.com>
Tue, 23 Jul 2013 14:28:06 +0000 (10:28 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 23 Jul 2013 19:09:14 +0000 (12:09 -0700)
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>
line-log.c
t/t4211-line-log.sh
index 52348796c1b482c06f8944999603a5b92dcfdf04..6f94d56063aa6d9544be4fdb41241a968f5aa347 100644 (file)
@@ -115,6 +115,8 @@ static void sort_and_merge_range_set(struct range_set *rs)
        qsort(rs->ranges, rs->nr, sizeof(struct range), range_cmp);
 
        for (i = 0; i < rs->nr; i++) {
+               if (rs->ranges[i].start == rs->ranges[i].end)
+                       continue;
                if (o > 0 && rs->ranges[i].start <= rs->ranges[o-1].end) {
                        if (rs->ranges[o-1].end < rs->ranges[i].end)
                                rs->ranges[o-1].end = rs->ranges[i].end;
index d98efb3c4e96570566a08e7b373d892d16ffa5ad..e7a6e499654d436e898f03f68316bc50fb76cc42 100755 (executable)
@@ -67,7 +67,8 @@ test_bad_opts "-L :foo:b.c" "no match"
 # There is a separate bug when an empty -L range is the first -L encountered,
 # thus to demonstrate this particular bug, the empty -L range must follow a
 # non-empty -L range.
-test_expect_failure '-L {empty-range} (any -L)' '
+test_expect_success '-L {empty-range} (any -L)' '
+       n=$(expr $(cat b.c | wc -l) + 1) &&
        n=$(expr $(wc -l <b.c) + 1) &&
        git log -L1,1:b.c -L$n:b.c
 '