Skip to content

Commit df6308e

Browse files
sunshinecogitster
authored andcommitted
line-log: fix "log -LN" crash when N is last line of file
range-set invariants are: ranges must be (1) non-empty, (2) disjoint, (3) sorted in ascending order. line_log_data_insert() breaks the non-empty invariant under the following conditions: the incoming range is empty and the pathname attached to the range has not yet been encountered. In this case, line_log_data_insert() assigns the empty range to a new line_log_data record without taking any action to ensure that the empty range is eventually folded out. Subsequent range-set functions crash or throw an assertion failure upon encountering such an anomaly. Fix this bug. Signed-off-by: Eric Sunshine <[email protected]> Acked-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f8395ed commit df6308e

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

line-log.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ static void line_log_data_insert(struct line_log_data **list,
299299
p = xcalloc(1, sizeof(struct line_log_data));
300300
p->path = path;
301301
range_set_append(&p->ranges, begin, end);
302+
sort_and_merge_range_set(&p->ranges);
302303
if (ip) {
303304
p->next = ip->next;
304305
ip->next = p;

t/t4211-line-log.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ test_expect_success '-L {empty-range} (any -L)' '
7373
git log -L1,1:b.c -L$n:b.c
7474
'
7575

76-
test_expect_failure '-L {empty-range} (first -L)' '
76+
test_expect_success '-L {empty-range} (first -L)' '
7777
n=$(expr $(wc -l <b.c) + 1) &&
7878
git log -L$n:b.c
7979
'

0 commit comments

Comments
 (0)