blame: prevent error if range ends past end of file

If the -L option is used to specify a line range in git blame, and the
end of the range is past the end of the file, git will fail with a fatal
error. This commit prevents such behavior - instead we display the blame
for existing lines within the specified range. Tests are amended
accordingly.

This commit also fixes two corner cases. Blaming -L n,-(n+1) now blames
the first n lines of a file rather than from n to the end of the file.
Blaming -L ,-n will be treated as -L 1,-n and blame the first line of
the file, rather than blaming the whole file.

Signed-off-by: Isabella Stephens <istephens@atlassian.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Isabella Stephens
2018-06-15 16:29:27 +10:00
committed by Junio C Hamano
parent fc54c1af3e
commit 96cfa94e68
4 changed files with 13 additions and 9 deletions

View File

@ -47,7 +47,7 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line,
else if (!num)
*ret = begin;
else
*ret = begin + num;
*ret = begin + num > 0 ? begin + num : 1;
return term;
}
return spec;