Skip to content

Commit

Permalink
blame: fix indent of line numbers
Browse files Browse the repository at this point in the history
Correct the calculation of the number of digits for line counts of the
form 10^n-1 (9, 99, ...) in lineno_width().  This makes blame stop
printing an extra space before the line numbers of files with that many
total lines.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Mar 13, 2010
1 parent 4a2284b commit 00fb3d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion builtin-blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -1772,7 +1772,7 @@ static int lineno_width(int lines)
{
int i, width;

for (width = 1, i = 10; i <= lines + 1; width++)
for (width = 1, i = 10; i <= lines; width++)
i *= 10;
return width;
}
Expand Down
20 changes: 19 additions & 1 deletion t/t8003-blame.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ test_expect_success setup '
echo B B B B B >two &&
echo C C C C C >tres &&
echo ABC >mouse &&
git add one two tres mouse &&
for i in 1 2 3 4 5 6 7 8 9
do
echo $i
done >nine_lines &&
for i in 1 2 3 4 5 6 7 8 9 a
do
echo $i
done >ten_lines &&
git add one two tres mouse nine_lines ten_lines &&
test_tick &&
GIT_AUTHOR_NAME=Initial git commit -m Initial &&
Expand Down Expand Up @@ -167,4 +175,14 @@ test_expect_success 'blame -L with invalid end' '
grep "has only 2 lines" errors
'

test_expect_success 'indent of line numbers, nine lines' '
git blame nine_lines >actual &&
test $(grep -c " " actual) = 0
'

test_expect_success 'indent of line numbers, ten lines' '
git blame ten_lines >actual &&
test $(grep -c " " actual) = 9
'

test_done

0 comments on commit 00fb3d2

Please sign in to comment.