diff options
author | Thomas Rast <trast@inf.ethz.ch> | 2013-04-05 16:34:47 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-04-05 10:39:08 -0700 |
commit | 4596f190d384872305e502ebece2e38358ba463e (patch) | |
tree | 0aaa6642d1841e38779c30ab6f9a3d63ae87860b | |
parent | 39410bf0bf81cb3f76fb9bfa8308cd672bc1442c (diff) | |
download | git-4596f190d384872305e502ebece2e38358ba463e.tar.gz |
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>
-rw-r--r-- | line-log.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/line-log.c b/line-log.c index 30edef4bec..5a12ceb012 100644 --- a/line-log.c +++ b/line-log.c @@ -80,6 +80,25 @@ static int range_cmp(const void *_r, const void *_s) } /* + * Check that the ranges are non-empty, sorted and non-overlapping + */ +static void range_set_check_invariants(struct range_set *rs) +{ + int i; + + if (!rs) + return; + + if (rs->nr) + assert(rs->ranges[0].start < rs->ranges[0].end); + + for (i = 1; i < rs->nr; i++) { + assert(rs->ranges[i-1].end < rs->ranges[i].start); + assert(rs->ranges[i].start < rs->ranges[i].end); + } +} + +/* * Helper: In-place pass of sorting and merging the ranges in the * 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) } assert(o <= rs->nr); rs->nr = o; + + range_set_check_invariants(rs); } /* @@ -687,8 +708,13 @@ static struct line_log_data *lookup_line_range(struct rev_info *revs, struct commit *commit) { struct line_log_data *ret = NULL; + struct line_log_data *d; ret = lookup_decoration(&revs->line_log_data, &commit->object); + + for (d = ret; d; d = d->next) + range_set_check_invariants(&d->ranges); + return ret; } |