line-range: reject -L line numbers less than 1

Since inception, git-blame -L has been documented as accepting 1-based line numbers. When handed a line number less than 1, -L's behavior is undocumented and undefined; it's also nonsensical and should be diagnosed as an error. Do so. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Aug 6, 2013 at 09:59 UTC 5ce922a014f78684a96c3d03a51decf0d21fa58d
2 files changed +13 -10
line-range.c
+4 -1
@@ -54,8 +54,11 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line,
54 }
55 num = strtol(spec, &term, 10);
56 if (term != spec) {
57 - if (ret)
57 + if (ret) {
58 + if (num <= 0)
59 + die("-L invalid line number: %ld", num);
60 *ret = num;
61 + }
62 return term;
63 }
64
t/annotate-tests.sh
+9 -9
@@ -185,15 +185,15 @@ test_expect_success 'blame -L Y,X (undocumented)' '
185 check_count -L6,3 B 1 B1 1 B2 1 D 1
186 '
187
188 -test_expect_failure 'blame -L -X' '
188 +test_expect_success 'blame -L -X' '
189 test_must_fail $PROG -L-1 file
190 '
191
192 -test_expect_failure 'blame -L 0' '
192 +test_expect_success 'blame -L 0' '
193 test_must_fail $PROG -L0 file
194 '
195
196 -test_expect_failure 'blame -L ,0' '
196 +test_expect_success 'blame -L ,0' '
197 test_must_fail $PROG -L,0 file
198 '
199
@@ -447,8 +447,8 @@ test_expect_success 'blame empty' '
447 check_count -h HEAD^^ -f incremental
448 '
449
450 -test_expect_success 'blame -L 0 empty (undocumented)' '
451 - check_count -h HEAD^^ -f incremental -L0
450 +test_expect_success 'blame -L 0 empty' '
451 + test_must_fail $PROG -L0 incremental HEAD^^
452 '
453
454 test_expect_success 'blame -L 1 empty' '
@@ -463,8 +463,8 @@ test_expect_success 'blame half' '
463 check_count -h HEAD^ -f incremental I 1
464 '
465
466 -test_expect_success 'blame -L 0 half (undocumented)' '
467 - check_count -h HEAD^ -f incremental -L0 I 1
466 +test_expect_success 'blame -L 0 half' '
467 + test_must_fail $PROG -L0 incremental HEAD^
468 '
469
470 test_expect_success 'blame -L 1 half' '
@@ -483,8 +483,8 @@ test_expect_success 'blame full' '
483 check_count -f incremental I 1
484 '
485
486 -test_expect_success 'blame -L 0 full (undocumented)' '
487 - check_count -f incremental -L0 I 1
486 +test_expect_success 'blame -L 0 full' '
487 + test_must_fail $PROG -L0 incremental
488 '
489
490 test_expect_success 'blame -L 1 full' '