summaryrefslogtreecommitdiff
path: root/line-log.c
diff options
context:
space:
mode:
authorThomas Rast <trast@inf.ethz.ch>2013-04-05 16:34:48 +0200
committerJunio C Hamano <gitster@pobox.com>2013-04-05 10:39:09 -0700
commit209618860c2627a4e134a15472587c574b328b40 (patch)
treec0c33f379053fb4150b1dbfc1fd506a925c948a4 /line-log.c
parent4596f190d384872305e502ebece2e38358ba463e (diff)
downloadgit-209618860c2627a4e134a15472587c574b328b40.tar.gz
log -L: fix overlapping input ranges
The existing code was too defensive, and would trigger the assert in range_set_append() if the user gave overlapping ranges. The intent was always to define overlapping ranges as just the union of all of them, as evidenced by the call to sort_and_merge_range_set(). (Which was already used, unlike what the comment said.) Fix by splitting out the meat of range_set_append() to a new _unsafe() function that lacks the paranoia. sort_and_merge_range_set will fix up the ranges, so we don't need the checks there. Signed-off-by: Thomas Rast <trast@inf.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'line-log.c')
-rw-r--r--line-log.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/line-log.c b/line-log.c
index 5a12ceb012..85c7c249f4 100644
--- a/line-log.c
+++ b/line-log.c
@@ -56,16 +56,21 @@ static void range_set_move(struct range_set *dst, struct range_set *src)
}
/* tack on a _new_ range _at the end_ */
-static void range_set_append(struct range_set *rs, long a, long b)
+static void range_set_append_unsafe(struct range_set *rs, long a, long b)
{
assert(a <= b);
- assert(rs->nr == 0 || rs->ranges[rs->nr-1].end <= a);
range_set_grow(rs, 1);
rs->ranges[rs->nr].start = a;
rs->ranges[rs->nr].end = b;
rs->nr++;
}
+static void range_set_append(struct range_set *rs, long a, long b)
+{
+ assert(rs->nr == 0 || rs->ranges[rs->nr-1].end <= a);
+ range_set_append_unsafe(rs, a, b);
+}
+
static int range_cmp(const void *_r, const void *_s)
{
const struct range *r = _r;
@@ -99,10 +104,8 @@ static void range_set_check_invariants(struct range_set *rs)
}
/*
- * Helper: In-place pass of sorting and merging the ranges in the
- * range set, to re-establish the invariants after another operation
- *
- * NEEDSWORK currently not needed
+ * In-place pass of sorting and merging the ranges in the range set,
+ * to establish the invariants when we get the ranges from the user
*/
static void sort_and_merge_range_set(struct range_set *rs)
{
@@ -280,7 +283,7 @@ static void line_log_data_insert(struct line_log_data **list,
struct line_log_data *p = search_line_log_data(*list, spec->path, &ip);
if (p) {
- range_set_append(&p->ranges, begin, end);
+ range_set_append_unsafe(&p->ranges, begin, end);
sort_and_merge_range_set(&p->ranges);
free_filespec(spec);
return;