Skip to content

Commit 00fb3d2

Browse files
René Scharfegitster
authored andcommitted
blame: fix indent of line numbers
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4a2284b commit 00fb3d2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

builtin-blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ static int lineno_width(int lines)
17721772
{
17731773
int i, width;
17741774

1775-
for (width = 1, i = 10; i <= lines + 1; width++)
1775+
for (width = 1, i = 10; i <= lines; width++)
17761776
i *= 10;
17771777
return width;
17781778
}

t/t8003-blame.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ test_expect_success setup '
1111
echo B B B B B >two &&
1212
echo C C C C C >tres &&
1313
echo ABC >mouse &&
14-
git add one two tres mouse &&
14+
for i in 1 2 3 4 5 6 7 8 9
15+
do
16+
echo $i
17+
done >nine_lines &&
18+
for i in 1 2 3 4 5 6 7 8 9 a
19+
do
20+
echo $i
21+
done >ten_lines &&
22+
git add one two tres mouse nine_lines ten_lines &&
1523
test_tick &&
1624
GIT_AUTHOR_NAME=Initial git commit -m Initial &&
1725
@@ -167,4 +175,14 @@ test_expect_success 'blame -L with invalid end' '
167175
grep "has only 2 lines" errors
168176
'
169177

178+
test_expect_success 'indent of line numbers, nine lines' '
179+
git blame nine_lines >actual &&
180+
test $(grep -c " " actual) = 0
181+
'
182+
183+
test_expect_success 'indent of line numbers, ten lines' '
184+
git blame ten_lines >actual &&
185+
test $(grep -c " " actual) = 9
186+
'
187+
170188
test_done

0 commit comments

Comments
 (0)