All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] blame: fix indent of line numbers
@ 2010-03-13 10:25 René Scharfe
  2010-03-13 20:53 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2010-03-13 10:25 UTC (permalink / raw
  To: Junio C Hamano; +Cc: Git Mailing List

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>
---
 builtin/blame.c  |    2 +-
 t/t8003-blame.sh |   20 +++++++++++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index 10f7eac..fc15863 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -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;
 }
diff --git a/t/t8003-blame.sh b/t/t8003-blame.sh
index 3bbddd0..230143c 100755
--- a/t/t8003-blame.sh
+++ b/t/t8003-blame.sh
@@ -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 &&
 
@@ -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
-- 
1.7.0.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] blame: fix indent of line numbers
  2010-03-13 10:25 [PATCH] blame: fix indent of line numbers René Scharfe
@ 2010-03-13 20:53 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2010-03-13 20:53 UTC (permalink / raw
  To: René Scharfe; +Cc: Git Mailing List

Thanks; embarrassed ;-)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-03-13 20:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-13 10:25 [PATCH] blame: fix indent of line numbers René Scharfe
2010-03-13 20:53 ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.