log: fix -L bounds checking bug

When 12da1d1f added -L support to git-log, a broken bounds check was copied from git-blame -L which incorrectly allows -LX to extend one line past end of file without reporting an error. Instead, it generates an empty range. Fix this bug. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Jul 31, 2013 at 04:15 UTC 63828b844d17d66d18c19375c559ab8678693f97
2 files changed +3 -3
line-log.c
+2 -2
@@ -594,13 +594,13 @@ parse_lines(struct commit *commit, const char *prefix, struct string_list *args)
594 lines, &begin, &end,
595 full_name))
596 die("malformed -L argument '%s'", range_part);
597 + if (lines < end || ((lines || begin) && lines < begin))
598 + die("file %s has only %lu lines", name_part, lines);
599 if (begin < 1)
600 begin = 1;
601 if (end < 1)
602 end = lines;
603 begin--;
602 - if (lines < end || lines < begin)
603 - die("file %s has only %ld lines", name_part, lines);
604 line_log_data_insert(&ranges, full_name, begin, end);
605
606 free_filespec(spec);
t/t4211-line-log.sh
+1 -1
@@ -69,7 +69,7 @@ test_expect_success '-L X (X == nlines)' '
69 git log -L $n:b.c
70 '
71
72 -test_expect_failure '-L X (X == nlines + 1)' '
72 +test_expect_success '-L X (X == nlines + 1)' '
73 n=$(expr $(wc -l <b.c) + 1) &&
74 test_must_fail git log -L $n:b.c
75 '