blame: reject empty ranges -L,+0 and -L,-0

Empty ranges -L,+0 and -L,-0 are nonsensical in the context of blame yet they are accepted (in fact, both are interpreted as -L1,Y where Y is end-of-file). Report them as invalid. 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 5d57cac6ae7c661d430dcc7dd2e44c994bf797be
2 files changed +3 -3
line-range.c
+1 -1
@@ -21,7 +21,7 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line,
21 * for 20 lines, or "-L <something>,-5" for 5 lines ending at
22 * <something>.
23 */
24 - if (1 < begin && (spec[0] == '+' || spec[0] == '-')) {
24 + if (1 <= begin && (spec[0] == '+' || spec[0] == '-')) {
25 num = strtol(spec + 1, &term, 10);
26 if (term != spec + 1) {
27 if (!ret)
t/annotate-tests.sh
+2 -2
@@ -185,7 +185,7 @@ 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 ,+0' '
188 +test_expect_success 'blame -L ,+0' '
189 test_must_fail $PROG -L,+0 file
190 '
191
@@ -201,7 +201,7 @@ test_expect_success 'blame -L X,+N' '
201 check_count -L3,+4 B 1 B1 1 B2 1 D 1
202 '
203
204 -test_expect_failure 'blame -L ,-0' '
204 +test_expect_success 'blame -L ,-0' '
205 test_must_fail $PROG -L,-0 file
206 '
207