Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
line-log: optimize ranges by joining them when possible
Technically, it is okay to have line ranges that touch (i.e. the end of
the first range ends just before the next range begins). However, it is
inefficient, and when the user provides such touching ranges via
multiple `-L` options, we already join them.

When we traverse the history, though, we never join ranges, even they
become "touchy-feely" due to added lines (which are "removed" from
line-log's point of view because it traverses the commit history into
the past).

Let's optimize also this case.

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Aug 4, 2018
commit d5d9db3c1124d29e26864596a8c36f0dc4de8a7e
4 changes: 4 additions & 0 deletions line-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ void range_set_append_unsafe(struct range_set *rs, long a, long b)

void range_set_append(struct range_set *rs, long a, long b)
{
if (rs->nr > 0 && rs->ranges[rs->nr-1].end + 1 == a) {
rs->ranges[rs->nr-1].end = b;
return;
}
assert(rs->nr == 0 || rs->ranges[rs->nr-1].end <= a);
range_set_append_unsafe(rs, a, b);
}
Expand Down
2 changes: 1 addition & 1 deletion t/t4211-line-log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ q_to_lf () {
tr Q '\012'
}

test_expect_failure 'close to overlapping ranges' '
test_expect_success 'close to overlapping ranges' '
test_seq 5 >a1.c &&
git add a1.c &&
git commit -m "5 lines" a1.c &&
Expand Down