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 <trast@inf.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Rast committed
Apr 5, 2013 at 16:34 UTC
4596f190d384872305e502ebece2e38358ba463e
1 file changed
+26
line-log.c
+26
@@ -79,6 +79,25 @@ static int range_cmp(const void *_r, const void *_s)
79
return 1;
80
}
81
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
+
101
/*
102
* Helper: In-place pass of sorting and merging the ranges in the
103
* 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)
122
}
123
assert(o <= rs->nr);
124
rs->nr = o;
125
+
126
+ range_set_check_invariants(rs);
127
}
128
129
/*
@@ -687,8 +708,13 @@ static struct line_log_data *lookup_line_range(struct rev_info *revs,
708
struct commit *commit)
709
{
710
struct line_log_data *ret = NULL;
711
+ struct line_log_data *d;
712
713
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
+
718
return ret;
719
}
720