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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Mar 13, 2010 at 11:25 UTC
00fb3d214cbb867f45de0084e6b844445e076dce
2 files changed
+20
-2
builtin-blame.c
+1
-1
@@ -1772,7 +1772,7 @@ static int lineno_width(int lines)
1772
{
1773
int i, width;
1774
1775
- for (width = 1, i = 10; i <= lines + 1; width++)
1775
+ for (width = 1, i = 10; i <= lines; width++)
1776
i *= 10;
1777
return width;
1778
}
t/t8003-blame.sh
+19
-1
@@ -11,7 +11,15 @@ test_expect_success setup '
11
echo B B B B B >two &&
12
echo C C C C C >tres &&
13
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 &&
23
test_tick &&
24
GIT_AUTHOR_NAME=Initial git commit -m Initial &&
25
@@ -167,4 +175,14 @@ test_expect_success 'blame -L with invalid end' '
175
grep "has only 2 lines" errors
176
'
177
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
+
188
test_done