Skip to content

Commit 5ce922a

Browse files
sunshinecogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9527604 commit 5ce922a

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

line-range.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line,
5454
}
5555
num = strtol(spec, &term, 10);
5656
if (term != spec) {
57-
if (ret)
57+
if (ret) {
58+
if (num <= 0)
59+
die("-L invalid line number: %ld", num);
5860
*ret = num;
61+
}
5962
return term;
6063
}
6164

t/annotate-tests.sh

+9-9
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ test_expect_success 'blame -L Y,X (undocumented)' '
185185
check_count -L6,3 B 1 B1 1 B2 1 D 1
186186
'
187187

188-
test_expect_failure 'blame -L -X' '
188+
test_expect_success 'blame -L -X' '
189189
test_must_fail $PROG -L-1 file
190190
'
191191

192-
test_expect_failure 'blame -L 0' '
192+
test_expect_success 'blame -L 0' '
193193
test_must_fail $PROG -L0 file
194194
'
195195

196-
test_expect_failure 'blame -L ,0' '
196+
test_expect_success 'blame -L ,0' '
197197
test_must_fail $PROG -L,0 file
198198
'
199199

@@ -447,8 +447,8 @@ test_expect_success 'blame empty' '
447447
check_count -h HEAD^^ -f incremental
448448
'
449449

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^^
452452
'
453453

454454
test_expect_success 'blame -L 1 empty' '
@@ -463,8 +463,8 @@ test_expect_success 'blame half' '
463463
check_count -h HEAD^ -f incremental I 1
464464
'
465465

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^
468468
'
469469

470470
test_expect_success 'blame -L 1 half' '
@@ -483,8 +483,8 @@ test_expect_success 'blame full' '
483483
check_count -f incremental I 1
484484
'
485485

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
488488
'
489489

490490
test_expect_success 'blame -L 1 full' '

0 commit comments

Comments
 (0)