Skip to content

Commit 4596f19

Browse files
Thomas Rastgitster
authored andcommitted
log -L: check range set invariants when we look it up
lookup_line_range() is a good place to check that the range sets satisfy the invariants: they have been computed and set in earlier iterations, and we now start working with them. Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 39410bf commit 4596f19

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

line-log.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@ static int range_cmp(const void *_r, const void *_s)
7979
return 1;
8080
}
8181

82+
/*
83+
* Check that the ranges are non-empty, sorted and non-overlapping
84+
*/
85+
static void range_set_check_invariants(struct range_set *rs)
86+
{
87+
int i;
88+
89+
if (!rs)
90+
return;
91+
92+
if (rs->nr)
93+
assert(rs->ranges[0].start < rs->ranges[0].end);
94+
95+
for (i = 1; i < rs->nr; i++) {
96+
assert(rs->ranges[i-1].end < rs->ranges[i].start);
97+
assert(rs->ranges[i].start < rs->ranges[i].end);
98+
}
99+
}
100+
82101
/*
83102
* Helper: In-place pass of sorting and merging the ranges in the
84103
* range set, to re-establish the invariants after another operation
@@ -103,6 +122,8 @@ static void sort_and_merge_range_set(struct range_set *rs)
103122
}
104123
assert(o <= rs->nr);
105124
rs->nr = o;
125+
126+
range_set_check_invariants(rs);
106127
}
107128

108129
/*
@@ -687,8 +708,13 @@ static struct line_log_data *lookup_line_range(struct rev_info *revs,
687708
struct commit *commit)
688709
{
689710
struct line_log_data *ret = NULL;
711+
struct line_log_data *d;
690712

691713
ret = lookup_decoration(&revs->line_log_data, &commit->object);
714+
715+
for (d = ret; d; d = d->next)
716+
range_set_check_invariants(&d->ranges);
717+
692718
return ret;
693719
}
694720

0 commit comments

Comments
 (0)