Skip to contentSkip to conversation

Pretty print truncate does not work

PATCH In review Alexey Shumkin 5 participants 25 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

cover Pretty print truncate does not work

Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given length with an appropriate padding. This works for non-ASCII texts when i18n.logOutputEncoding is UTF-8 only (independently of a printed commit message encoding) but does not work when i18n.logOutputEncoding is NOT UTF-8.

Following patches are:
1. failing tests
2. Fix patch

Alexey Shumkin (2):
t4205 (log-pretty-formats): Add failing tests for the case when
i18n.logOutputEncoding is set
pretty.c: format string with truncate respects logOutputEncoding

 pretty.c                      |   7 +-
 t/t4205-log-pretty-formats.sh | 169 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 174 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.2-15
#1 lore raw

PATCH 1/2 t4205 (log-pretty-formats): Add failing tests for the case when i18n.logOutputEncoding is set

Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given length with an appropriate padding. This works for non-ASCII texts when i18n.logOutputEncoding is UTF-8 only (independently of a printed commit message encoding) but does not work when i18n.logOutputEncoding is NOT UTF-8.

There were no breakages as far as were no tests for the case when both a commit message and logOutputEncoding are not UTF-8.

Add failing tests for that which will be fixed in the next patch.

---
 t/t4205-log-pretty-formats.sh | 169 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 169 insertions(+)
t/t4205-log-pretty-formats.sh +169 -0
index 2a6278b..6791e0d 100755
@@ -153,6 +153,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(40)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+message two                            Z
+message one                            Z
+add bar                                Z
+$(commit_msg)                    Z
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting at the nth column' '
 	git log --pretty="format:%h %<|(40)%s" >actual &&
 	# complete the incomplete line at the end
@@ -166,6 +179,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%h %<|(40)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+$head1 message two                    Z
+$head2 message one                    Z
+$head3 add bar                        Z
+$head4 $(commit_msg)            Z
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with no padding' '
 	git log --pretty="format:%<(1)%s" >actual &&
 	# complete the incomplete line at the end
@@ -179,6 +205,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting with no padding. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(1)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	cat <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+message two
+message one
+add bar
+$(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with trunc' '
 	git log --pretty="format:%<(10,trunc)%s" >actual &&
 	# complete the incomplete line at the end
@@ -192,6 +231,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_failure 'left alignment formatting with trunc. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,trunc)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+message ..
+message ..
+add bar  Z
+initial...
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with ltrunc' '
 	git log --pretty="format:%<(10,ltrunc)%s" >actual &&
 	# complete the incomplete line at the end
@@ -205,6 +257,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_failure 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,ltrunc)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+..sage two
+..sage one
+add bar  Z
+..${sample_utf8_part}lich
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with mtrunc' '
 	git log --pretty="format:%<(10,mtrunc)%s" >actual &&
 	# complete the incomplete line at the end
@@ -218,6 +283,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_failure 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,mtrunc)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+mess.. two
+mess.. one
+add bar  Z
+init..lich
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'right alignment formatting' '
 	git log --pretty="format:%>(40)%s" >actual &&
 	# complete the incomplete line at the end
@@ -231,6 +309,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'right alignment formatting. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%>(40)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+Z                            message two
+Z                            message one
+Z                                add bar
+Z                    $(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'right alignment formatting at the nth column' '
 	git log --pretty="format:%h %>|(40)%s" >actual &&
 	# complete the incomplete line at the end
@@ -244,6 +335,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%h %>|(40)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+$head1                      message two
+$head2                      message one
+$head3                          add bar
+$head4              $(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'right alignment formatting with no padding' '
 	git log --pretty="format:%>(1)%s" >actual &&
 	# complete the incomplete line at the end
@@ -257,6 +361,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'right alignment formatting with no padding. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%>(1)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	cat <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+message two
+message one
+add bar
+$(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'center alignment formatting' '
 	git log --pretty="format:%><(40)%s" >actual &&
 	# complete the incomplete line at the end
@@ -270,6 +387,18 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'center alignment formatting. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%><(40)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+Z             message two              Z
+Z             message one              Z
+Z               add bar                Z
+Z         $(commit_msg)          Z
+EOF
+	test_cmp expected actual
+'
 test_expect_success 'center alignment formatting at the nth column' '
 	git log --pretty="format:%h %><|(40)%s" >actual &&
 	# complete the incomplete line at the end
@@ -283,6 +412,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%h %><|(40)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+$head1           message two          Z
+$head2           message one          Z
+$head3             add bar            Z
+$head4       $(commit_msg)      Z
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'center alignment formatting with no padding' '
 	git log --pretty="format:%><(1)%s" >actual &&
 	# complete the incomplete line at the end
@@ -296,6 +438,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'center alignment formatting with no padding. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%><(1)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	cat <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+message two
+message one
+add bar
+$(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left/right alignment formatting with stealing' '
 	git commit --amend -m short --author "long long long <[email protected]>" &&
 	git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
@@ -310,6 +465,20 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_failure 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
+	git commit --amend -m short --author "long long long <[email protected]>" &&
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	cat <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+short long  long long
+message ..   A U Thor
+add bar      A U Thor
+initial...   A U Thor
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'log decoration properly follows tag chain' '
 	git tag -a tag1 -m tag1 &&
 	git tag -a tag2 -m tag2 tag1 &&
Signature · 1 line
1.9.2-15
#2 lore raw

PATCH 2/2 pretty.c: format string with truncate respects logOutputEncoding

In reply to Alexey Shumkin

Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given length with an appropriate padding. This works for non-ASCII texts when i18n.logOutputEncoding is UTF-8 only (independently of a printed commit message encoding) but does not work when i18n.logOutputEncoding is NOT UTF-8.

In 7e77df3 (pretty: two phase conversion for non utf-8 commits, 2013-04-19) 'format_commit_item' function assumes commit message to be in UTF-8. And that was so until ecaee80 (pretty: --format output should honor logOutputEncoding, 2013-06-26) where conversion to logOutputEncoding was added before calling 'format_commit_message'.

Correct this by converting a commit message to UTF-8 first (as it assumed in 7e77df3 (pretty: two phase conversion for non utf-8 commits, 2013-04-19)). Only after that set 'output_enc' variable to an actual logOutputEncoding.

---
 pretty.c                      | 7 +++++--
 t/t4205-log-pretty-formats.sh | 8 ++++----
 2 files changed, 9 insertions(+), 6 deletions(-)
pretty.c +5 -2
index 6e266dd..7eb43c1 100644
@@ -1500,16 +1500,19 @@ void format_commit_message(const struct commit *commit,
 			   const struct pretty_print_context *pretty_ctx)
 {
 	struct format_commit_context context;
-	const char *output_enc = pretty_ctx->output_encoding;
 	const char *utf8 = "UTF-8";
 
 	memset(&context, 0, sizeof(context));
 	context.commit = commit;
 	context.pretty_ctx = pretty_ctx;
 	context.wrap_start = sb->len;
+	// convert a commit message to UTF-8 first
+	// as far as 'format_commit_item' assumes it in UTF-8
 	context.message = logmsg_reencode(commit,
 					  &context.commit_encoding,
-					  output_enc);
+					  utf8);
+	// then convert to an actual output encoding
+	const char *output_enc = pretty_ctx->output_encoding;
 
 	strbuf_expand(sb, format, format_commit_item, &context);
 	rewrap_message_tail(sb, &context, 0, 0, 0);
t/t4205-log-pretty-formats.sh +4 -4
index 6791e0d..7426fe2 100755
@@ -231,7 +231,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with trunc. i18n.logOutputEncoding' '
+test_expect_success 'left alignment formatting with trunc. i18n.logOutputEncoding' '
 	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,trunc)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -257,7 +257,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
+test_expect_success 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
 	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,ltrunc)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -283,7 +283,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
+test_expect_success 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
 	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,mtrunc)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -465,7 +465,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
+test_expect_success 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
 	git commit --amend -m short --author "long long long <[email protected]>" &&
 	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
 	# complete the incomplete line at the end
Signature · 1 line
1.9.2-15
#3 lore raw

Re: [PATCH 2/2] pretty.c: format string with truncate respects logOutputEncoding

And I thought I was the only one using this :)

Quoted 16 lines
pretty.c +1 -1
index 6e266dd..7eb43c1 100644
@@ -1500,16 +1500,19 @@ void format_commit_message(const struct commit *commit,
                           const struct pretty_print_context *pretty_ctx)
 {
        struct format_commit_context context;
-       const char *output_enc = pretty_ctx->output_encoding;
        const char *utf8 = "UTF-8";
 
        memset(&context, 0, sizeof(context));
        context.commit = commit;
        context.pretty_ctx = pretty_ctx;
        context.wrap_start = sb->len;
+       // convert a commit message to UTF-8 first

pretty.c void format_commit_message(const struct commit *commit, · line 1518

Quoted 10 lines
pretty.c +4 -1
+       // as far as 'format_commit_item' assumes it in UTF-8
        context.message = logmsg_reencode(commit,
                                          &context.commit_encoding,
-                                         output_enc);
+                                         utf8);
+       // then convert to an actual output encoding
+       const char *output_enc = pretty_ctx->output_encoding;
 
        strbuf_expand(sb, format, format_commit_item, &context);
        rewrap_message_tail(sb, &context, 0, 0, 0);

It looks ok except minor issues, use C comment syntax, not C++ and variable declaration not in the middle of the body.

Signature · 1 line
Duy
#4 lore raw

v2 cover Reroll patch series. Pretty print truncate does not work

In this reroll (against v1) remarks of Nguyễn are respected. Comments style changed from C++ to C. variable declaration moved back to the beginning of a function.
Also, added tests for the same case for git rev-list
(see t6006-rev-list-format.sh)

Alexey Shumkin (2):
t4205, t6006: Add failing tests for the case when
i18n.logOutputEncoding is set
pretty.c: format string with truncate respects logOutputEncoding

 pretty.c                      |   7 +-
 t/t4205-log-pretty-formats.sh | 169 ++++++++++++++++++++++++++++++++++++++++++
 t/t6006-rev-list-format.sh    |  75 ++++++++++++++++++-
 3 files changed, 248 insertions(+), 3 deletions(-)
Signature · 1 line
1.9.2-17
#5 lore raw

PATCH v2 1/2 t4205, t6006: Add failing tests for the case when i18n.logOutputEncoding is set

Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given length with an appropriate padding. This works for non-ASCII texts when i18n.logOutputEncoding is UTF-8 only (independently of a printed commit message encoding) but does not work when i18n.logOutputEncoding is NOT UTF-8.

There were no breakages as far as were no tests for the case when both a commit message and logOutputEncoding are not UTF-8.

Add failing tests for that which will be fixed in the next patch.

---
 t/t4205-log-pretty-formats.sh | 169 ++++++++++++++++++++++++++++++++++++++++++
 t/t6006-rev-list-format.sh    |  75 ++++++++++++++++++-
 2 files changed, 242 insertions(+), 2 deletions(-)
t/t4205-log-pretty-formats.sh +169 -0
index 2a6278b..6791e0d 100755
@@ -153,6 +153,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(40)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+message two                            Z
+message one                            Z
+add bar                                Z
+$(commit_msg)                    Z
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting at the nth column' '
 	git log --pretty="format:%h %<|(40)%s" >actual &&
 	# complete the incomplete line at the end
@@ -166,6 +179,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%h %<|(40)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+$head1 message two                    Z
+$head2 message one                    Z
+$head3 add bar                        Z
+$head4 $(commit_msg)            Z
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with no padding' '
 	git log --pretty="format:%<(1)%s" >actual &&
 	# complete the incomplete line at the end
@@ -179,6 +205,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting with no padding. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(1)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	cat <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+message two
+message one
+add bar
+$(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with trunc' '
 	git log --pretty="format:%<(10,trunc)%s" >actual &&
 	# complete the incomplete line at the end
@@ -192,6 +231,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_failure 'left alignment formatting with trunc. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,trunc)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+message ..
+message ..
+add bar  Z
+initial...
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with ltrunc' '
 	git log --pretty="format:%<(10,ltrunc)%s" >actual &&
 	# complete the incomplete line at the end
@@ -205,6 +257,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_failure 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,ltrunc)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+..sage two
+..sage one
+add bar  Z
+..${sample_utf8_part}lich
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with mtrunc' '
 	git log --pretty="format:%<(10,mtrunc)%s" >actual &&
 	# complete the incomplete line at the end
@@ -218,6 +283,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_failure 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,mtrunc)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+mess.. two
+mess.. one
+add bar  Z
+init..lich
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'right alignment formatting' '
 	git log --pretty="format:%>(40)%s" >actual &&
 	# complete the incomplete line at the end
@@ -231,6 +309,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'right alignment formatting. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%>(40)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+Z                            message two
+Z                            message one
+Z                                add bar
+Z                    $(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'right alignment formatting at the nth column' '
 	git log --pretty="format:%h %>|(40)%s" >actual &&
 	# complete the incomplete line at the end
@@ -244,6 +335,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%h %>|(40)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+$head1                      message two
+$head2                      message one
+$head3                          add bar
+$head4              $(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'right alignment formatting with no padding' '
 	git log --pretty="format:%>(1)%s" >actual &&
 	# complete the incomplete line at the end
@@ -257,6 +361,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'right alignment formatting with no padding. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%>(1)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	cat <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+message two
+message one
+add bar
+$(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'center alignment formatting' '
 	git log --pretty="format:%><(40)%s" >actual &&
 	# complete the incomplete line at the end
@@ -270,6 +387,18 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'center alignment formatting. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%><(40)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+Z             message two              Z
+Z             message one              Z
+Z               add bar                Z
+Z         $(commit_msg)          Z
+EOF
+	test_cmp expected actual
+'
 test_expect_success 'center alignment formatting at the nth column' '
 	git log --pretty="format:%h %><|(40)%s" >actual &&
 	# complete the incomplete line at the end
@@ -283,6 +412,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%h %><|(40)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+$head1           message two          Z
+$head2           message one          Z
+$head3             add bar            Z
+$head4       $(commit_msg)      Z
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'center alignment formatting with no padding' '
 	git log --pretty="format:%><(1)%s" >actual &&
 	# complete the incomplete line at the end
@@ -296,6 +438,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'center alignment formatting with no padding. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%><(1)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	cat <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+message two
+message one
+add bar
+$(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left/right alignment formatting with stealing' '
 	git commit --amend -m short --author "long long long <[email protected]>" &&
 	git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
@@ -310,6 +465,20 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_failure 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
+	git commit --amend -m short --author "long long long <[email protected]>" &&
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&
+	cat <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&
+short long  long long
+message ..   A U Thor
+add bar      A U Thor
+initial...   A U Thor
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'log decoration properly follows tag chain' '
 	git tag -a tag1 -m tag1 &&
 	git tag -a tag2 -m tag2 tag1 &&
t/t6006-rev-list-format.sh +73 -2

103 lines not on this page · raw message

Signature · 1 line
1.9.2-17
#6 lore raw

Re: [PATCH v2 1/2] t4205, t6006: Add failing tests for the case when i18n.logOutputEncoding is set

Quoted 23 lines · Alexey Shumkin

Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given length with an appropriate padding. This works for non-ASCII texts when i18n.logOutputEncoding is UTF-8 only (independently of a printed commit message encoding) but does not work when i18n.logOutputEncoding is NOT UTF-8.

There were no breakages as far as were no tests for the case when both a commit message and logOutputEncoding are not UTF-8.

Add failing tests for that which will be fixed in the next patch.

---
 t/t4205-log-pretty-formats.sh | 169 ++++++++++++++++++++++++++++++++++++++++++
 t/t6006-rev-list-format.sh    |  75 ++++++++++++++++++-
 2 files changed, 242 insertions(+), 2 deletions(-)
t/t4205-log-pretty-formats.sh +0 -0
index 2a6278b..6791e0d 100755

t/t4205-log-pretty-formats.sh EOF · line 159

Quoted 7 lines
t/t4205-log-pretty-formats.sh +4 -0
@@ -153,6 +153,19 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(40)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&

Would it change the meaning of the test if you used tformat: instead of format: (or --format="%<(40)%s")? If it doesn't, it would make it unnecessary to append an extra LF and explain why you do so.

t/t4205-log-pretty-formats.sh EOF · line 160

Quoted 1 line
t/t4205-log-pretty-formats.sh +1 -0
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&

It is minor but many existing uses of iconv in our tests spell these as UTF-8 and ISO8859-1 in uppercase. I vaguely recall there was a portability concern to favor the ones that are used in existing tests, but probably it no longer matters (I see you added the lowercase one with de6029a2 mid last year), so I am fine if these stay lowercase.

t/t4205-log-pretty-formats.sh EOF · line 211

Quoted 3 lines
t/t4205-log-pretty-formats.sh +3 -0
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(1)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&

Likewise for all the other "--pretty=format:" followed by an echo.

Thanks.

#7 lore raw

Re: [PATCH v2 1/2] t4205, t6006: Add failing tests for the case when i18n.logOutputEncoding is set

Quoted 28 lines · Junio C Hamano
Quoted 26 lines · Alexey Shumkin

Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given length with an appropriate padding. This works for non-ASCII texts when i18n.logOutputEncoding is UTF-8 only (independently of a printed commit message encoding) but does not work when i18n.logOutputEncoding is NOT UTF-8.

There were no breakages as far as were no tests for the case when both a commit message and logOutputEncoding are not UTF-8.

Add failing tests for that which will be fixed in the next patch.

---
 t/t4205-log-pretty-formats.sh | 169 ++++++++++++++++++++++++++++++++++++++++++
 t/t6006-rev-list-format.sh    |  75 ++++++++++++++++++-
 2 files changed, 242 insertions(+), 2 deletions(-)
t/t4205-log-pretty-formats.sh +0 -0
index 2a6278b..6791e0d 100755
@@ -153,6 +153,19 @@ EOF
 	test_cmp expected actual
 '
 
Quoted 8 lines

t/t4205-log-pretty-formats.sh EOF · line 159

Quoted 4 lines
t/t4205-log-pretty-formats.sh +4 -0
+test_expect_success 'left alignment formatting. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(40)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&

Would it change the meaning of the test if you used tformat: instead of format: (or --format="%<(40)%s")? If it doesn't, it would make it unnecessary to append an extra LF and explain why you do so.

Well, actually, I just copied previous tests and added i18n.logOutputEncoding.

But as I can see in the code - no, tformat will not change the meaning. so, may be there is a reason to change that (initial) tests from format to tformat first? And then add mine new.

Quoted 9 lines

t/t4205-log-pretty-formats.sh EOF · line 160

Quoted 2 lines
t/t4205-log-pretty-formats.sh +1 -0
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t iso8859-1 >expected &&

It is minor but many existing uses of iconv in our tests spell these as UTF-8 and ISO8859-1 in uppercase. I vaguely recall there was a portability concern to favor the ones that are used in existing tests, but probably it no longer matters (I see you added the lowercase one with de6029a2 mid last year), so I am fine if these stay lowercase.

I've grep'ed for lowercase iso8859-1 in test, and found almost all of them is code added by me.
Grep for uppercase gives more results. I can refactor that first for uniformity.

Quoted 6 lines

t/t4205-log-pretty-formats.sh EOF · line 211

Quoted 4 lines
t/t4205-log-pretty-formats.sh +3 -0
+	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(1)%s" >actual &&
+	# complete the incomplete line at the end
+	echo >>actual &&

Likewise for all the other "--pretty=format:" followed by an echo.

the same copy-paste-modify.

Quoted 2 lines

Thanks.

Signature · 1 line
Alexey Shumkin
#8 lore raw

v3 cover Reroll patches. Pretty print truncate does not work

In reply to Junio C Hamano

This patch series differs from the previous (v2) version in the following:
t4205 refactored: hardcoded SHA-1 digests replaced with variabled Tested encoding iso8859-1 replaced with variable (and uppercased to be in line
in other tests)
Usage of format + echo replaced with tformat

brian m. carlson <[email protected]> CCed as he committed 5e1361c (log: properly handle decorations with chained tags, 2013-12-17)

Alexey Shumkin (5):
t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs t4041, t4205, t6006, t7102: Don't hardcode tested encoding value t4205 (log-pretty-format): Use tformat rather than format t4205, t6006: Add failing tests for the case when
i18n.logOutputEncoding is set
pretty.c: format string with truncate respects logOutputEncoding

 pretty.c                         |   7 +-
 t/t4041-diff-submodule-option.sh |   7 +-
 t/t4205-log-pretty-formats.sh    | 217 ++++++++++++++++++++++++++++++---------
 t/t6006-rev-list-format.sh       | 110 ++++++++++++++++----
 t/t7102-reset.sh                 |  13 ++-
 5 files changed, 282 insertions(+), 72 deletions(-)
Signature · 1 line
1.9.2-15
#9 lore raw

PATCH v3 1/5 t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

That was introduced in a742f2a (t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs, 2013-06-26) but unfortunately was not followed in 5e1361c (log: properly handle decorations with chained tags, 2013-12-17)

---
 t/t4205-log-pretty-formats.sh | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
t/t4205-log-pretty-formats.sh +11 -3
index 2a6278b..f9f33ae 100755
@@ -296,6 +296,10 @@ EOF
 	test_cmp expected actual
 '
 
+# save HEAD's SHA-1 digest (with no abbreviations) to use it below
+# as far as the next test amends HEAD
+old_head1=$(git rev-parse --verify HEAD~0)
+
 test_expect_success 'left/right alignment formatting with stealing' '
 	git commit --amend -m short --author "long long long <[email protected]>" &&
 	git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
@@ -310,6 +314,10 @@ EOF
 	test_cmp expected actual
 '
 
+# get new digests (with no abbreviations)
+head1=$(git rev-parse --verify HEAD~0) &&
+head2=$(git rev-parse --verify HEAD~1) &&
+
 test_expect_success 'log decoration properly follows tag chain' '
 	git tag -a tag1 -m tag1 &&
 	git tag -a tag2 -m tag2 tag1 &&
@@ -317,9 +325,9 @@ test_expect_success 'log decoration properly follows tag chain' '
 	git commit --amend -m shorter &&
 	git log --no-walk --tags --pretty="%H %d" --decorate=full >actual &&
 	cat <<EOF >expected &&
-6a908c10688b2503073c39c9ba26322c73902bb5  (tag: refs/tags/tag2)
-9f716384d92283fb915a4eee5073f030638e05f9  (tag: refs/tags/message-one)
-b87e4cccdb77336ea79d89224737be7ea8e95367  (tag: refs/tags/message-two)
+$head1  (tag: refs/tags/tag2)
+$head2  (tag: refs/tags/message-one)
+$old_head1  (tag: refs/tags/message-two)
 EOF
 	sort actual >actual1 &&
 	test_cmp expected actual1
Signature · 1 line
1.9.2-15
#10 lore raw

PATCH v3 2/5 t4041, t4205, t6006, t7102: Don't hardcode tested encoding value

In reply to Alexey Shumkin

The tested encoding is always available in a variable. Use it instead of hardcoding. Also, to be in line with other tests use ISO8859-1 (uppercase) rather then iso8895-1.

---
 t/t4041-diff-submodule-option.sh |  7 +++++--
 t/t4205-log-pretty-formats.sh    | 11 +++++++----
 t/t6006-rev-list-format.sh       | 35 +++++++++++++++++++----------------
 t/t7102-reset.sh                 | 13 ++++++++-----
 4 files changed, 39 insertions(+), 27 deletions(-)
t/t4041-diff-submodule-option.sh +5 -2
index 1751c83..463d63b 100755
@@ -11,6 +11,9 @@ This test tries to verify the sanity of the --submodule option of git diff.
 
 . ./test-lib.sh
 
+# Tested non-UTF-8 encoding
+test_encoding="ISO8859-1"
+
 # String "added" in German (translated with Google Translate), encoded in UTF-8,
 # used in sample commit log messages in add_file() function below.
 added=$(printf "hinzugef\303\274gt")
@@ -23,8 +26,8 @@ add_file () {
 			echo "$name" >"$name" &&
 			git add "$name" &&
 			test_tick &&
-			msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso8859-1) &&
-			git -c 'i18n.commitEncoding=iso8859-1' commit -m "$msg_added_iso88591"
+			msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding) &&
+			git -c "i18n.commitEncoding=$test_encoding" commit -m "$msg_added_iso88591"
 		done >/dev/null &&
 		git rev-parse --short --verify HEAD
 	)
t/t4205-log-pretty-formats.sh +7 -4
index f9f33ae..f5ea3f8 100755
@@ -7,6 +7,9 @@
 test_description='Test pretty formats'
 . ./test-lib.sh
 
+# Tested non-UTF-8 encoding
+test_encoding="ISO8859-1"
+
 sample_utf8_part=$(printf "f\303\244ng")
 
 commit_msg () {
@@ -27,8 +30,8 @@ test_expect_success 'set up basic repos' '
 	>bar &&
 	git add foo &&
 	test_tick &&
-	git config i18n.commitEncoding iso8859-1 &&
-	git commit -m "$(commit_msg iso8859-1)" &&
+	git config i18n.commitEncoding $test_encoding &&
+	git commit -m "$(commit_msg $test_encoding)" &&
 	git add bar &&
 	test_tick &&
 	git commit -m "add bar" &&
@@ -56,8 +59,8 @@ test_expect_success 'alias user-defined format' '
 	test_cmp expected actual
 '
 
-test_expect_success 'alias user-defined tformat with %s (iso8859-1 encoding)' '
-	git config i18n.logOutputEncoding iso8859-1 &&
+test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' '
+	git config i18n.logOutputEncoding $test_encoding &&
 	git log --oneline >expected-s &&
 	git log --pretty="tformat:%h %s" >actual-s &&
 	git config --unset i18n.logOutputEncoding &&
t/t6006-rev-list-format.sh +19 -16
index 9874403..9e4ba62 100755
@@ -9,19 +9,22 @@ test_description='git rev-list --pretty=format test'
 . "$TEST_DIRECTORY"/lib-terminal.sh
 
 test_tick
+# Tested non-UTF-8 encoding
+test_encoding="ISO8859-1"
+
 # String "added" in German
 # (translated with Google Translate),
 # encoded in UTF-8, used as a commit log message below.
 added=$(printf "added (hinzugef\303\274gt) foo")
-added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1)
+added_iso88591=$(echo "$added" | iconv -f utf-8 -t $test_encoding)
 # same but "changed"
 changed=$(printf "changed (ge\303\244ndert) foo")
-changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso8859-1)
+changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding)
 
 test_expect_success 'setup' '
 	: >foo &&
 	git add foo &&
-	git config i18n.commitEncoding iso8859-1 &&
+	git config i18n.commitEncoding $test_encoding &&
 	git commit -m "$added_iso88591" &&
 	head1=$(git rev-parse --verify HEAD) &&
 	head1_short=$(git rev-parse --verify --short $head1) &&
@@ -124,9 +127,9 @@ EOF
 
 test_format encoding %e <<EOF
 commit $head2
-iso8859-1
+$test_encoding
 commit $head1
-iso8859-1
+$test_encoding
 EOF
 
 test_format subject %s <<EOF
@@ -206,16 +209,16 @@ test_expect_success '%C(auto) respects --color=auto (stdout not tty)' '
 	)
 '
 
-iconv -f utf-8 -t iso8859-1 > commit-msg <<EOF
+iconv -f utf-8 -t $test_encoding > commit-msg <<EOF
 Test printing of complex bodies
 
 This commit message is much longer than the others,
-and it will be encoded in iso8859-1. We should therefore
-include an iso8859 character: ¡bueno!
+and it will be encoded in $test_encoding. We should therefore
+include an ISO8859 character: ¡bueno!
 EOF
 
 test_expect_success 'setup complex body' '
-	git config i18n.commitencoding iso8859-1 &&
+	git config i18n.commitencoding $test_encoding &&
 	echo change2 >foo && git commit -a -F commit-msg &&
 	head3=$(git rev-parse --verify HEAD) &&
 	head3_short=$(git rev-parse --short $head3)
@@ -223,11 +226,11 @@ test_expect_success 'setup complex body' '
 
 test_format complex-encoding %e <<EOF
 commit $head3
-iso8859-1
+$test_encoding
 commit $head2
-iso8859-1
+$test_encoding
 commit $head1
-iso8859-1
+$test_encoding
 EOF
 
 test_format complex-subject %s <<EOF
@@ -243,16 +246,16 @@ test_expect_success 'prepare expected messages (for test %b)' '
 	cat <<-EOF >expected.utf-8 &&
 	commit $head3
 	This commit message is much longer than the others,
-	and it will be encoded in iso8859-1. We should therefore
-	include an iso8859 character: ¡bueno!
+	and it will be encoded in $test_encoding. We should therefore
+	include an ISO8859 character: ¡bueno!
 
 	commit $head2
 	commit $head1
 	EOF
-	iconv -f utf-8 -t iso8859-1 expected.utf-8 >expected.iso8859-1
+	iconv -f utf-8 -t $test_encoding expected.utf-8 >expected.ISO8859-1
 '
 
-test_format complex-body %b <expected.iso8859-1
+test_format complex-body %b <expected.ISO8859-1
 
 # Git uses i18n.commitEncoding if no i18n.logOutputEncoding set
 # so unset i18n.commitEncoding to test encoding conversion
t/t7102-reset.sh +8 -5
index ee117e2..8a56756 100755
@@ -22,6 +22,9 @@ commit_msg () {
 	fi
 }
 
+# Tested non-UTF-8 encoding
+test_encoding="ISO8859-1"
+
 test_expect_success 'creating initial files and commits' '
 	test_tick &&
 	echo "1st file" >first &&
@@ -41,7 +44,7 @@ test_expect_success 'creating initial files and commits' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" &&
+	git -c "i18n.commitEncoding=$test_encoding" commit -a -m "$(commit_msg $test_encoding)" &&
 	head5=$(git rev-parse --verify HEAD)
 '
 # git log --pretty=oneline # to see those SHA1 involved
@@ -64,10 +67,10 @@ test_expect_success 'reset --hard message' '
 	test_cmp .expected .actual
 '
 
-test_expect_success 'reset --hard message (iso8859-1 logoutputencoding)' '
+test_expect_success 'reset --hard message (ISO8859-1 logoutputencoding)' '
 	hex=$(git log -1 --format="%h") &&
-	git -c "i18n.logOutputEncoding=iso8859-1" reset --hard > .actual &&
-	echo HEAD is now at $hex $(commit_msg iso8859-1) > .expected &&
+	git -c "i18n.logOutputEncoding=$test_encoding" reset --hard > .actual &&
+	echo HEAD is now at $hex $(commit_msg $test_encoding) > .expected &&
 	test_cmp .expected .actual
 '
 
@@ -331,7 +334,7 @@ test_expect_success 'redoing the last two commits should succeed' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" &&
+	git -c "i18n.commitEncoding=$test_encoding" commit -a -m "$(commit_msg $test_encoding)" &&
 	check_changes $head5
 '
 
Signature · 1 line
1.9.2-15
#11 lore raw

Re: [PATCH v3 2/5] t4041, t4205, t6006, t7102: Don't hardcode tested encoding value

Quoted 3 lines · Alexey Shumkin

The tested encoding is always available in a variable. Use it instead of hardcoding. Also, to be in line with other tests use ISO8859-1 (uppercase) rather then iso8895-1.

You wrote "iso8895" when I think you meant "iso8859".

Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
#12 lore raw

Re: [PATCH v3 2/5] t4041, t4205, t6006, t7102: Don't hardcode tested encoding value

Quoted 6 lines · brian m. carlson
Quoted 3 lines · Alexey Shumkin

The tested encoding is always available in a variable. Use it instead of hardcoding. Also, to be in line with other tests use ISO8859-1 (uppercase) rather then iso8895-1.

You wrote "iso8895" when I think you meant "iso8859".

Oops!
Yes, you're right, I've meant iso8859.

Quoted 5 lines
Signature · 4 lines
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
Signature · 5 lines
Alexey Shumkin
E-mail: [email protected]
ICQ: 118001447
Jabber (GoogleTalk): [email protected]
Skype: crezoff
#13 lore raw

PATCH v3 3/5 t4205 (log-pretty-format): Use `tformat` rather than `format`

In reply to Alexey Shumkin

Use tformat to avoid using of echo to complete end of line.

---
 t/t4205-log-pretty-formats.sh | 52 +++++++++++--------------------------------
 1 file changed, 13 insertions(+), 39 deletions(-)
t/t4205-log-pretty-formats.sh +13 -39
index f5ea3f8..c03a65e 100755
@@ -144,9 +144,7 @@ test_expect_success 'setup more commits' '
 '
 
 test_expect_success 'left alignment formatting' '
-	git log --pretty="format:%<(40)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%<(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 message two                            Z
 message one                            Z
@@ -157,9 +155,7 @@ EOF
 '
 
 test_expect_success 'left alignment formatting at the nth column' '
-	git log --pretty="format:%h %<|(40)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%h %<|(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 $head1 message two                    Z
 $head2 message one                    Z
@@ -170,9 +166,7 @@ EOF
 '
 
 test_expect_success 'left alignment formatting with no padding' '
-	git log --pretty="format:%<(1)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%<(1)%s" >actual &&
 	cat <<EOF >expected &&
 message two
 message one
@@ -183,9 +177,7 @@ EOF
 '
 
 test_expect_success 'left alignment formatting with trunc' '
-	git log --pretty="format:%<(10,trunc)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%<(10,trunc)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 message ..
 message ..
@@ -196,9 +188,7 @@ EOF
 '
 
 test_expect_success 'left alignment formatting with ltrunc' '
-	git log --pretty="format:%<(10,ltrunc)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 ..sage two
 ..sage one
@@ -209,9 +199,7 @@ EOF
 '
 
 test_expect_success 'left alignment formatting with mtrunc' '
-	git log --pretty="format:%<(10,mtrunc)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 mess.. two
 mess.. one
@@ -222,9 +210,7 @@ EOF
 '
 
 test_expect_success 'right alignment formatting' '
-	git log --pretty="format:%>(40)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%>(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 Z                            message two
 Z                            message one
@@ -235,9 +221,7 @@ EOF
 '
 
 test_expect_success 'right alignment formatting at the nth column' '
-	git log --pretty="format:%h %>|(40)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%h %>|(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 $head1                      message two
 $head2                      message one
@@ -248,9 +232,7 @@ EOF
 '
 
 test_expect_success 'right alignment formatting with no padding' '
-	git log --pretty="format:%>(1)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%>(1)%s" >actual &&
 	cat <<EOF >expected &&
 message two
 message one
@@ -261,9 +243,7 @@ EOF
 '
 
 test_expect_success 'center alignment formatting' '
-	git log --pretty="format:%><(40)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%><(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 Z             message two              Z
 Z             message one              Z
@@ -274,9 +254,7 @@ EOF
 '
 
 test_expect_success 'center alignment formatting at the nth column' '
-	git log --pretty="format:%h %><|(40)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%h %><|(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 $head1           message two          Z
 $head2           message one          Z
@@ -287,9 +265,7 @@ EOF
 '
 
 test_expect_success 'center alignment formatting with no padding' '
-	git log --pretty="format:%><(1)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%><(1)%s" >actual &&
 	cat <<EOF >expected &&
 message two
 message one
@@ -305,9 +281,7 @@ old_head1=$(git rev-parse --verify HEAD~0)
 
 test_expect_success 'left/right alignment formatting with stealing' '
 	git commit --amend -m short --author "long long long <[email protected]>" &&
-	git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
 	cat <<EOF >expected &&
 short long  long long
 message ..   A U Thor
Signature · 1 line
1.9.2-15
#14 lore raw

PATCH v3 4/5 t4205, t6006: Add failing tests for the case when i18n.logOutputEncoding is set

In reply to Alexey Shumkin

Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given length with an appropriate padding. This works for non-ASCII texts when i18n.logOutputEncoding is UTF-8 only (independently of a printed commit message encoding) but does not work when i18n.logOutputEncoding is NOT UTF-8.

There were no breakages as far as were no tests for the case when both a commit message and logOutputEncoding are not UTF-8.

Add failing tests for that which will be fixed in the next patch.

---
 t/t4205-log-pretty-formats.sh | 140 ++++++++++++++++++++++++++++++++++++++++++
 t/t6006-rev-list-format.sh    |  75 +++++++++++++++++++++-
 2 files changed, 213 insertions(+), 2 deletions(-)
t/t4205-log-pretty-formats.sh +140 -0
index c03a65e..74babce 100755
@@ -154,6 +154,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(40)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+message two                            Z
+message one                            Z
+add bar                                Z
+$(commit_msg)                    Z
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting at the nth column' '
 	git log --pretty="tformat:%h %<|(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -165,6 +176,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+$head1 message two                    Z
+$head2 message one                    Z
+$head3 add bar                        Z
+$head4 $(commit_msg)            Z
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with no padding' '
 	git log --pretty="tformat:%<(1)%s" >actual &&
 	cat <<EOF >expected &&
@@ -176,6 +198,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting with no padding. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(1)%s" >actual &&
+	cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+message two
+message one
+add bar
+$(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with trunc' '
 	git log --pretty="tformat:%<(10,trunc)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -187,6 +220,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_failure 'left alignment formatting with trunc. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+message ..
+message ..
+add bar  Z
+initial...
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with ltrunc' '
 	git log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -198,6 +242,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_failure 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+..sage two
+..sage one
+add bar  Z
+..${sample_utf8_part}lich
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with mtrunc' '
 	git log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -209,6 +264,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_failure 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+mess.. two
+mess.. one
+add bar  Z
+init..lich
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'right alignment formatting' '
 	git log --pretty="tformat:%>(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -220,6 +286,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'right alignment formatting. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(40)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+Z                            message two
+Z                            message one
+Z                                add bar
+Z                    $(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'right alignment formatting at the nth column' '
 	git log --pretty="tformat:%h %>|(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -231,6 +308,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+$head1                      message two
+$head2                      message one
+$head3                          add bar
+$head4              $(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'right alignment formatting with no padding' '
 	git log --pretty="tformat:%>(1)%s" >actual &&
 	cat <<EOF >expected &&
@@ -242,6 +330,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'right alignment formatting with no padding. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual &&
+	cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+message two
+message one
+add bar
+$(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'center alignment formatting' '
 	git log --pretty="tformat:%><(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -253,6 +352,16 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'center alignment formatting. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(40)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+Z             message two              Z
+Z             message one              Z
+Z               add bar                Z
+Z         $(commit_msg)          Z
+EOF
+	test_cmp expected actual
+'
 test_expect_success 'center alignment formatting at the nth column' '
 	git log --pretty="tformat:%h %><|(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -264,6 +373,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+$head1           message two          Z
+$head2           message one          Z
+$head3             add bar            Z
+$head4       $(commit_msg)      Z
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'center alignment formatting with no padding' '
 	git log --pretty="tformat:%><(1)%s" >actual &&
 	cat <<EOF >expected &&
@@ -278,6 +398,16 @@ EOF
 # save HEAD's SHA-1 digest (with no abbreviations) to use it below
 # as far as the next test amends HEAD
 old_head1=$(git rev-parse --verify HEAD~0)
+test_expect_success 'center alignment formatting with no padding. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(1)%s" >actual &&
+	cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+message two
+message one
+add bar
+$(commit_msg)
+EOF
+	test_cmp expected actual
+'
 
 test_expect_success 'left/right alignment formatting with stealing' '
 	git commit --amend -m short --author "long long long <[email protected]>" &&
@@ -290,6 +420,16 @@ initial...   A U Thor
 EOF
 	test_cmp expected actual
 '
+test_expect_failure 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
+	cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+short long  long long
+message ..   A U Thor
+add bar      A U Thor
+initial...   A U Thor
+EOF
+	test_cmp expected actual
+'
 
 # get new digests (with no abbreviations)
 head1=$(git rev-parse --verify HEAD~0) &&
t/t6006-rev-list-format.sh +73 -2

103 lines not on this page · raw message

Signature · 1 line
1.9.2-15
#15 lore raw

PATCH v3 5/5 pretty.c: format string with truncate respects logOutputEncoding

In reply to Alexey Shumkin

Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given length with an appropriate padding. This works for non-ASCII texts when i18n.logOutputEncoding is UTF-8 only (independently of a printed commit message encoding) but does not work when i18n.logOutputEncoding is NOT UTF-8.

In 7e77df3 (pretty: two phase conversion for non utf-8 commits, 2013-04-19) 'format_commit_item' function assumes commit message to be in UTF-8. And that was so until ecaee80 (pretty: --format output should honor logOutputEncoding, 2013-06-26) where conversion to logOutputEncoding was added before calling 'format_commit_message'.

Correct this by converting a commit message to UTF-8 first (as it assumed in 7e77df3 (pretty: two phase conversion for non utf-8 commits, 2013-04-19)). Only after that convert a commit message to an actual logOutputEncoding.

---
 pretty.c                      | 7 ++++++-
 t/t4205-log-pretty-formats.sh | 8 ++++----
 t/t6006-rev-list-format.sh    | 6 +++---
 3 files changed, 13 insertions(+), 8 deletions(-)
pretty.c +6 -1
index 6e266dd..25e8825 100644
@@ -1507,13 +1507,18 @@ void format_commit_message(const struct commit *commit,
 	context.commit = commit;
 	context.pretty_ctx = pretty_ctx;
 	context.wrap_start = sb->len;
+	/*
+	 * convert a commit message to UTF-8 first
+	 * as far as 'format_commit_item' assumes it in UTF-8
+	 */
 	context.message = logmsg_reencode(commit,
 					  &context.commit_encoding,
-					  output_enc);
+					  utf8);
 
 	strbuf_expand(sb, format, format_commit_item, &context);
 	rewrap_message_tail(sb, &context, 0, 0, 0);
 
+	/* then convert a commit message to an actual output encoding */
 	if (output_enc) {
 		if (same_encoding(utf8, output_enc))
 			output_enc = NULL;
t/t4205-log-pretty-formats.sh +4 -4
index 74babce..c84ec9a 100755
@@ -220,7 +220,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with trunc. i18n.logOutputEncoding' '
+test_expect_success 'left alignment formatting with trunc. i18n.logOutputEncoding' '
 	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual &&
 	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
 message ..
@@ -242,7 +242,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
+test_expect_success 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
 	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
 	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
 ..sage two
@@ -264,7 +264,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
+test_expect_success 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
 	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
 	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
 mess.. two
@@ -420,7 +420,7 @@ initial...   A U Thor
 EOF
 	test_cmp expected actual
 '
-test_expect_failure 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
+test_expect_success 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
 	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
 	cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
 short long  long long
t/t6006-rev-list-format.sh +3 -3
index a932f34..c6e9a73 100755
@@ -259,7 +259,7 @@ commit $head1
 $added_iso88591
 EOF
 
-test_format complex-subject-trunc %<($truncate_count,trunc)%s failure <<EOF
+test_format complex-subject-trunc %<($truncate_count,trunc)%s <<EOF
 commit $head3
 Test printing of c..
 commit $head2
@@ -268,7 +268,7 @@ commit $head1
 added (hinzugef${added_utf8_part_iso88591}gt..
 EOF
 
-test_format complex-subject-mtrunc %<($truncate_count,mtrunc)%s failure <<EOF
+test_format complex-subject-mtrunc %<($truncate_count,mtrunc)%s <<EOF
 commit $head3
 Test prin..ex bodies
 commit $head2
@@ -277,7 +277,7 @@ commit $head1
 added (hi..f${added_utf8_part_iso88591}gt) foo
 EOF
 
-test_format complex-subject-ltrunc %<($truncate_count,ltrunc)%s failure <<EOF
+test_format complex-subject-ltrunc %<($truncate_count,ltrunc)%s <<EOF
 commit $head3
 .. of complex bodies
 commit $head2
Signature · 1 line
1.9.2-15
#16 lore raw

v4 cover Reroll patches. Pretty print truncate does not work

In reply to Alexey Shumkin

This version (v4) differs from the previuos (v3):
1. Fixed typo ISO8895-1 (vs ISO8859-1)
2. Fixed t4205 test: tested format strings are double-quoted

Alexey Shumkin (5):
t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs t4041, t4205, t6006, t7102: Don't hardcode tested encoding value t4205 (log-pretty-format): Use tformat rather than format t4205, t6006: Add failing tests for the case when
i18n.logOutputEncoding is set
pretty.c: format string with truncate respects logOutputEncoding

 pretty.c                         |   7 +-
 t/t4041-diff-submodule-option.sh |   7 +-
 t/t4205-log-pretty-formats.sh    | 217 ++++++++++++++++++++++++++++++---------
 t/t6006-rev-list-format.sh       | 110 ++++++++++++++++----
 t/t7102-reset.sh                 |  13 ++-
 5 files changed, 282 insertions(+), 72 deletions(-)
Signature · 1 line
1.9.2-15
#17 lore raw

PATCH v4 1/5 t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs

The expected SHA-1 digests are always available in variables. Use them instead of hardcoding.

That was introduced in a742f2a (t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs, 2013-06-26) but unfortunately was not followed in 5e1361c (log: properly handle decorations with chained tags, 2013-12-17)

---
 t/t4205-log-pretty-formats.sh | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
t/t4205-log-pretty-formats.sh +11 -3
index 2a6278b..f9f33ae 100755
@@ -296,6 +296,10 @@ EOF
 	test_cmp expected actual
 '
 
+# save HEAD's SHA-1 digest (with no abbreviations) to use it below
+# as far as the next test amends HEAD
+old_head1=$(git rev-parse --verify HEAD~0)
+
 test_expect_success 'left/right alignment formatting with stealing' '
 	git commit --amend -m short --author "long long long <[email protected]>" &&
 	git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
@@ -310,6 +314,10 @@ EOF
 	test_cmp expected actual
 '
 
+# get new digests (with no abbreviations)
+head1=$(git rev-parse --verify HEAD~0) &&
+head2=$(git rev-parse --verify HEAD~1) &&
+
 test_expect_success 'log decoration properly follows tag chain' '
 	git tag -a tag1 -m tag1 &&
 	git tag -a tag2 -m tag2 tag1 &&
@@ -317,9 +325,9 @@ test_expect_success 'log decoration properly follows tag chain' '
 	git commit --amend -m shorter &&
 	git log --no-walk --tags --pretty="%H %d" --decorate=full >actual &&
 	cat <<EOF >expected &&
-6a908c10688b2503073c39c9ba26322c73902bb5  (tag: refs/tags/tag2)
-9f716384d92283fb915a4eee5073f030638e05f9  (tag: refs/tags/message-one)
-b87e4cccdb77336ea79d89224737be7ea8e95367  (tag: refs/tags/message-two)
+$head1  (tag: refs/tags/tag2)
+$head2  (tag: refs/tags/message-one)
+$old_head1  (tag: refs/tags/message-two)
 EOF
 	sort actual >actual1 &&
 	test_cmp expected actual1
Signature · 1 line
1.9.2-15
#18 lore raw

PATCH v4 2/5 t4041, t4205, t6006, t7102: Don't hardcode tested encoding value

In reply to Alexey Shumkin

The tested encoding is always available in a variable. Use it instead of hardcoding. Also, to be in line with other tests use ISO8859-1 (uppercase) rather then iso8859-1.

---
 t/t4041-diff-submodule-option.sh |  7 +++++--
 t/t4205-log-pretty-formats.sh    | 11 +++++++----
 t/t6006-rev-list-format.sh       | 35 +++++++++++++++++++----------------
 t/t7102-reset.sh                 | 13 ++++++++-----
 4 files changed, 39 insertions(+), 27 deletions(-)
t/t4041-diff-submodule-option.sh +5 -2
index 1751c83..463d63b 100755
@@ -11,6 +11,9 @@ This test tries to verify the sanity of the --submodule option of git diff.
 
 . ./test-lib.sh
 
+# Tested non-UTF-8 encoding
+test_encoding="ISO8859-1"
+
 # String "added" in German (translated with Google Translate), encoded in UTF-8,
 # used in sample commit log messages in add_file() function below.
 added=$(printf "hinzugef\303\274gt")
@@ -23,8 +26,8 @@ add_file () {
 			echo "$name" >"$name" &&
 			git add "$name" &&
 			test_tick &&
-			msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso8859-1) &&
-			git -c 'i18n.commitEncoding=iso8859-1' commit -m "$msg_added_iso88591"
+			msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding) &&
+			git -c "i18n.commitEncoding=$test_encoding" commit -m "$msg_added_iso88591"
 		done >/dev/null &&
 		git rev-parse --short --verify HEAD
 	)
t/t4205-log-pretty-formats.sh +7 -4
index f9f33ae..f5ea3f8 100755
@@ -7,6 +7,9 @@
 test_description='Test pretty formats'
 . ./test-lib.sh
 
+# Tested non-UTF-8 encoding
+test_encoding="ISO8859-1"
+
 sample_utf8_part=$(printf "f\303\244ng")
 
 commit_msg () {
@@ -27,8 +30,8 @@ test_expect_success 'set up basic repos' '
 	>bar &&
 	git add foo &&
 	test_tick &&
-	git config i18n.commitEncoding iso8859-1 &&
-	git commit -m "$(commit_msg iso8859-1)" &&
+	git config i18n.commitEncoding $test_encoding &&
+	git commit -m "$(commit_msg $test_encoding)" &&
 	git add bar &&
 	test_tick &&
 	git commit -m "add bar" &&
@@ -56,8 +59,8 @@ test_expect_success 'alias user-defined format' '
 	test_cmp expected actual
 '
 
-test_expect_success 'alias user-defined tformat with %s (iso8859-1 encoding)' '
-	git config i18n.logOutputEncoding iso8859-1 &&
+test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' '
+	git config i18n.logOutputEncoding $test_encoding &&
 	git log --oneline >expected-s &&
 	git log --pretty="tformat:%h %s" >actual-s &&
 	git config --unset i18n.logOutputEncoding &&
t/t6006-rev-list-format.sh +19 -16
index 9874403..9e4ba62 100755
@@ -9,19 +9,22 @@ test_description='git rev-list --pretty=format test'
 . "$TEST_DIRECTORY"/lib-terminal.sh
 
 test_tick
+# Tested non-UTF-8 encoding
+test_encoding="ISO8859-1"
+
 # String "added" in German
 # (translated with Google Translate),
 # encoded in UTF-8, used as a commit log message below.
 added=$(printf "added (hinzugef\303\274gt) foo")
-added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1)
+added_iso88591=$(echo "$added" | iconv -f utf-8 -t $test_encoding)
 # same but "changed"
 changed=$(printf "changed (ge\303\244ndert) foo")
-changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso8859-1)
+changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding)
 
 test_expect_success 'setup' '
 	: >foo &&
 	git add foo &&
-	git config i18n.commitEncoding iso8859-1 &&
+	git config i18n.commitEncoding $test_encoding &&
 	git commit -m "$added_iso88591" &&
 	head1=$(git rev-parse --verify HEAD) &&
 	head1_short=$(git rev-parse --verify --short $head1) &&
@@ -124,9 +127,9 @@ EOF
 
 test_format encoding %e <<EOF
 commit $head2
-iso8859-1
+$test_encoding
 commit $head1
-iso8859-1
+$test_encoding
 EOF
 
 test_format subject %s <<EOF
@@ -206,16 +209,16 @@ test_expect_success '%C(auto) respects --color=auto (stdout not tty)' '
 	)
 '
 
-iconv -f utf-8 -t iso8859-1 > commit-msg <<EOF
+iconv -f utf-8 -t $test_encoding > commit-msg <<EOF
 Test printing of complex bodies
 
 This commit message is much longer than the others,
-and it will be encoded in iso8859-1. We should therefore
-include an iso8859 character: ¡bueno!
+and it will be encoded in $test_encoding. We should therefore
+include an ISO8859 character: ¡bueno!
 EOF
 
 test_expect_success 'setup complex body' '
-	git config i18n.commitencoding iso8859-1 &&
+	git config i18n.commitencoding $test_encoding &&
 	echo change2 >foo && git commit -a -F commit-msg &&
 	head3=$(git rev-parse --verify HEAD) &&
 	head3_short=$(git rev-parse --short $head3)
@@ -223,11 +226,11 @@ test_expect_success 'setup complex body' '
 
 test_format complex-encoding %e <<EOF
 commit $head3
-iso8859-1
+$test_encoding
 commit $head2
-iso8859-1
+$test_encoding
 commit $head1
-iso8859-1
+$test_encoding
 EOF
 
 test_format complex-subject %s <<EOF
@@ -243,16 +246,16 @@ test_expect_success 'prepare expected messages (for test %b)' '
 	cat <<-EOF >expected.utf-8 &&
 	commit $head3
 	This commit message is much longer than the others,
-	and it will be encoded in iso8859-1. We should therefore
-	include an iso8859 character: ¡bueno!
+	and it will be encoded in $test_encoding. We should therefore
+	include an ISO8859 character: ¡bueno!
 
 	commit $head2
 	commit $head1
 	EOF
-	iconv -f utf-8 -t iso8859-1 expected.utf-8 >expected.iso8859-1
+	iconv -f utf-8 -t $test_encoding expected.utf-8 >expected.ISO8859-1
 '
 
-test_format complex-body %b <expected.iso8859-1
+test_format complex-body %b <expected.ISO8859-1
 
 # Git uses i18n.commitEncoding if no i18n.logOutputEncoding set
 # so unset i18n.commitEncoding to test encoding conversion
t/t7102-reset.sh +8 -5
index ee117e2..8a56756 100755
@@ -22,6 +22,9 @@ commit_msg () {
 	fi
 }
 
+# Tested non-UTF-8 encoding
+test_encoding="ISO8859-1"
+
 test_expect_success 'creating initial files and commits' '
 	test_tick &&
 	echo "1st file" >first &&
@@ -41,7 +44,7 @@ test_expect_success 'creating initial files and commits' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" &&
+	git -c "i18n.commitEncoding=$test_encoding" commit -a -m "$(commit_msg $test_encoding)" &&
 	head5=$(git rev-parse --verify HEAD)
 '
 # git log --pretty=oneline # to see those SHA1 involved
@@ -64,10 +67,10 @@ test_expect_success 'reset --hard message' '
 	test_cmp .expected .actual
 '
 
-test_expect_success 'reset --hard message (iso8859-1 logoutputencoding)' '
+test_expect_success 'reset --hard message (ISO8859-1 logoutputencoding)' '
 	hex=$(git log -1 --format="%h") &&
-	git -c "i18n.logOutputEncoding=iso8859-1" reset --hard > .actual &&
-	echo HEAD is now at $hex $(commit_msg iso8859-1) > .expected &&
+	git -c "i18n.logOutputEncoding=$test_encoding" reset --hard > .actual &&
+	echo HEAD is now at $hex $(commit_msg $test_encoding) > .expected &&
 	test_cmp .expected .actual
 '
 
@@ -331,7 +334,7 @@ test_expect_success 'redoing the last two commits should succeed' '
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" &&
+	git -c "i18n.commitEncoding=$test_encoding" commit -a -m "$(commit_msg $test_encoding)" &&
 	check_changes $head5
 '
 
Signature · 1 line
1.9.2-15
#19 lore raw

PATCH v4 3/5 t4205 (log-pretty-format): Use `tformat` rather than `format`

In reply to Alexey Shumkin

Use tformat to avoid using of echo to complete end of line.

---
 t/t4205-log-pretty-formats.sh | 52 +++++++++++--------------------------------
 1 file changed, 13 insertions(+), 39 deletions(-)
t/t4205-log-pretty-formats.sh +13 -39
index f5ea3f8..c03a65e 100755
@@ -144,9 +144,7 @@ test_expect_success 'setup more commits' '
 '
 
 test_expect_success 'left alignment formatting' '
-	git log --pretty="format:%<(40)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%<(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 message two                            Z
 message one                            Z
@@ -157,9 +155,7 @@ EOF
 '
 
 test_expect_success 'left alignment formatting at the nth column' '
-	git log --pretty="format:%h %<|(40)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%h %<|(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 $head1 message two                    Z
 $head2 message one                    Z
@@ -170,9 +166,7 @@ EOF
 '
 
 test_expect_success 'left alignment formatting with no padding' '
-	git log --pretty="format:%<(1)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%<(1)%s" >actual &&
 	cat <<EOF >expected &&
 message two
 message one
@@ -183,9 +177,7 @@ EOF
 '
 
 test_expect_success 'left alignment formatting with trunc' '
-	git log --pretty="format:%<(10,trunc)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%<(10,trunc)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 message ..
 message ..
@@ -196,9 +188,7 @@ EOF
 '
 
 test_expect_success 'left alignment formatting with ltrunc' '
-	git log --pretty="format:%<(10,ltrunc)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 ..sage two
 ..sage one
@@ -209,9 +199,7 @@ EOF
 '
 
 test_expect_success 'left alignment formatting with mtrunc' '
-	git log --pretty="format:%<(10,mtrunc)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 mess.. two
 mess.. one
@@ -222,9 +210,7 @@ EOF
 '
 
 test_expect_success 'right alignment formatting' '
-	git log --pretty="format:%>(40)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%>(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 Z                            message two
 Z                            message one
@@ -235,9 +221,7 @@ EOF
 '
 
 test_expect_success 'right alignment formatting at the nth column' '
-	git log --pretty="format:%h %>|(40)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%h %>|(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 $head1                      message two
 $head2                      message one
@@ -248,9 +232,7 @@ EOF
 '
 
 test_expect_success 'right alignment formatting with no padding' '
-	git log --pretty="format:%>(1)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%>(1)%s" >actual &&
 	cat <<EOF >expected &&
 message two
 message one
@@ -261,9 +243,7 @@ EOF
 '
 
 test_expect_success 'center alignment formatting' '
-	git log --pretty="format:%><(40)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%><(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 Z             message two              Z
 Z             message one              Z
@@ -274,9 +254,7 @@ EOF
 '
 
 test_expect_success 'center alignment formatting at the nth column' '
-	git log --pretty="format:%h %><|(40)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%h %><|(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
 $head1           message two          Z
 $head2           message one          Z
@@ -287,9 +265,7 @@ EOF
 '
 
 test_expect_success 'center alignment formatting with no padding' '
-	git log --pretty="format:%><(1)%s" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%><(1)%s" >actual &&
 	cat <<EOF >expected &&
 message two
 message one
@@ -305,9 +281,7 @@ old_head1=$(git rev-parse --verify HEAD~0)
 
 test_expect_success 'left/right alignment formatting with stealing' '
 	git commit --amend -m short --author "long long long <[email protected]>" &&
-	git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
-	# complete the incomplete line at the end
-	echo >>actual &&
+	git log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
 	cat <<EOF >expected &&
 short long  long long
 message ..   A U Thor
Signature · 1 line
1.9.2-15
#20 lore raw

PATCH v4 4/5 t4205, t6006: Add failing tests for the case when i18n.logOutputEncoding is set

In reply to Alexey Shumkin

Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given length with an appropriate padding. This works for non-ASCII texts when i18n.logOutputEncoding is UTF-8 only (independently of a printed commit message encoding) but does not work when i18n.logOutputEncoding is NOT UTF-8.

There were no breakages as far as were no tests for the case when both a commit message and logOutputEncoding are not UTF-8.

Add failing tests for that which will be fixed in the next patch.

---
 t/t4205-log-pretty-formats.sh | 140 ++++++++++++++++++++++++++++++++++++++++++
 t/t6006-rev-list-format.sh    |  75 +++++++++++++++++++++-
 2 files changed, 213 insertions(+), 2 deletions(-)
t/t4205-log-pretty-formats.sh +140 -0
index c03a65e..74babce 100755
@@ -154,6 +154,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(40)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+message two                            Z
+message one                            Z
+add bar                                Z
+$(commit_msg)                    Z
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting at the nth column' '
 	git log --pretty="tformat:%h %<|(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -165,6 +176,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+$head1 message two                    Z
+$head2 message one                    Z
+$head3 add bar                        Z
+$head4 $(commit_msg)            Z
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with no padding' '
 	git log --pretty="tformat:%<(1)%s" >actual &&
 	cat <<EOF >expected &&
@@ -176,6 +198,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'left alignment formatting with no padding. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(1)%s" >actual &&
+	cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+message two
+message one
+add bar
+$(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with trunc' '
 	git log --pretty="tformat:%<(10,trunc)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -187,6 +220,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_failure 'left alignment formatting with trunc. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+message ..
+message ..
+add bar  Z
+initial...
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with ltrunc' '
 	git log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -198,6 +242,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_failure 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+..sage two
+..sage one
+add bar  Z
+..${sample_utf8_part}lich
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'left alignment formatting with mtrunc' '
 	git log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -209,6 +264,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_failure 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+mess.. two
+mess.. one
+add bar  Z
+init..lich
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'right alignment formatting' '
 	git log --pretty="tformat:%>(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -220,6 +286,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'right alignment formatting. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(40)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+Z                            message two
+Z                            message one
+Z                                add bar
+Z                    $(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'right alignment formatting at the nth column' '
 	git log --pretty="tformat:%h %>|(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -231,6 +308,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+$head1                      message two
+$head2                      message one
+$head3                          add bar
+$head4              $(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'right alignment formatting with no padding' '
 	git log --pretty="tformat:%>(1)%s" >actual &&
 	cat <<EOF >expected &&
@@ -242,6 +330,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'right alignment formatting with no padding. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual &&
+	cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+message two
+message one
+add bar
+$(commit_msg)
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'center alignment formatting' '
 	git log --pretty="tformat:%><(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -253,6 +352,16 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'center alignment formatting. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(40)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+Z             message two              Z
+Z             message one              Z
+Z               add bar                Z
+Z         $(commit_msg)          Z
+EOF
+	test_cmp expected actual
+'
 test_expect_success 'center alignment formatting at the nth column' '
 	git log --pretty="tformat:%h %><|(40)%s" >actual &&
 	qz_to_tab_space <<EOF >expected &&
@@ -264,6 +373,17 @@ EOF
 	test_cmp expected actual
 '
 
+test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual &&
+	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+$head1           message two          Z
+$head2           message one          Z
+$head3             add bar            Z
+$head4       $(commit_msg)      Z
+EOF
+	test_cmp expected actual
+'
+
 test_expect_success 'center alignment formatting with no padding' '
 	git log --pretty="tformat:%><(1)%s" >actual &&
 	cat <<EOF >expected &&
@@ -278,6 +398,16 @@ EOF
 # save HEAD's SHA-1 digest (with no abbreviations) to use it below
 # as far as the next test amends HEAD
 old_head1=$(git rev-parse --verify HEAD~0)
+test_expect_success 'center alignment formatting with no padding. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(1)%s" >actual &&
+	cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+message two
+message one
+add bar
+$(commit_msg)
+EOF
+	test_cmp expected actual
+'
 
 test_expect_success 'left/right alignment formatting with stealing' '
 	git commit --amend -m short --author "long long long <[email protected]>" &&
@@ -290,6 +420,16 @@ initial...   A U Thor
 EOF
 	test_cmp expected actual
 '
+test_expect_failure 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
+	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
+	cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
+short long  long long
+message ..   A U Thor
+add bar      A U Thor
+initial...   A U Thor
+EOF
+	test_cmp expected actual
+'
 
 # get new digests (with no abbreviations)
 head1=$(git rev-parse --verify HEAD~0) &&
t/t6006-rev-list-format.sh +73 -2

103 lines not on this page · raw message

Signature · 1 line
1.9.2-15
#21 lore raw

Re: [PATCH v4 4/5] t4205, t6006: Add failing tests for the case when i18n.logOutputEncoding is set

Quoted 6 lines · Alexey Shumkin

Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given length with an appropriate padding. This works for non-ASCII texts when i18n.logOutputEncoding is UTF-8 only (independently of a printed commit message encoding) but does not work when i18n.logOutputEncoding is NOT UTF-8.

Quoted 8 lines

There were no breakages as far as were no tests for the case when both a commit message and logOutputEncoding are not UTF-8.

Add failing tests for that which will be fixed in the next patch.

Hmm, I didn't really review these patches. I simply noted a problem on my system and provided you with an extended bug-report and assisted you in fixing it up. So, if it even warrants a mention in the commit message, then 'Helped-by:' would be nearer the mark.

Thanks!

ATB,
Ramsay Jones

#22 lore raw

Re: [PATCH v4 4/5] t4205, t6006: Add failing tests for the case when i18n.logOutputEncoding is set

Quoted 12 lines · Ramsay Jones
Quoted 11 lines · Alexey Shumkin

Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given length with an appropriate padding. This works for non-ASCII texts when i18n.logOutputEncoding is UTF-8 only (independently of a printed commit message encoding) but does not work when i18n.logOutputEncoding is NOT UTF-8.

There were no breakages as far as were no tests for the case when both a commit message and logOutputEncoding are not UTF-8.

Add failing tests for that which will be fixed in the next patch.

Quoted 8 lines
Quoted 3 lines

Hmm, I didn't really review these patches. I simply noted a problem on my system and provided you with an extended bug-report and assisted you in fixing it up. So, if it even warrants a mention in the commit message, then 'Helped-by:' would be nearer the mark.

I had the same impression. The same for Duy's.

#23 lore raw

PATCH v4 5/5 pretty.c: format string with truncate respects logOutputEncoding

In reply to Alexey Shumkin

Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given length with an appropriate padding. This works for non-ASCII texts when i18n.logOutputEncoding is UTF-8 only (independently of a printed commit message encoding) but does not work when i18n.logOutputEncoding is NOT UTF-8.

In 7e77df3 (pretty: two phase conversion for non utf-8 commits, 2013-04-19) 'format_commit_item' function assumes commit message to be in UTF-8. And that was so until ecaee80 (pretty: --format output should honor logOutputEncoding, 2013-06-26) where conversion to logOutputEncoding was added before calling 'format_commit_message'.

Correct this by converting a commit message to UTF-8 first (as it assumed in 7e77df3 (pretty: two phase conversion for non utf-8 commits, 2013-04-19)). Only after that convert a commit message to an actual logOutputEncoding.

---
 pretty.c                      | 7 ++++++-
 t/t4205-log-pretty-formats.sh | 8 ++++----
 t/t6006-rev-list-format.sh    | 6 +++---
 3 files changed, 13 insertions(+), 8 deletions(-)
pretty.c +6 -1
index 6e266dd..25e8825 100644
@@ -1507,13 +1507,18 @@ void format_commit_message(const struct commit *commit,
 	context.commit = commit;
 	context.pretty_ctx = pretty_ctx;
 	context.wrap_start = sb->len;
+	/*
+	 * convert a commit message to UTF-8 first
+	 * as far as 'format_commit_item' assumes it in UTF-8
+	 */
 	context.message = logmsg_reencode(commit,
 					  &context.commit_encoding,
-					  output_enc);
+					  utf8);
 
 	strbuf_expand(sb, format, format_commit_item, &context);
 	rewrap_message_tail(sb, &context, 0, 0, 0);
 
+	/* then convert a commit message to an actual output encoding */
 	if (output_enc) {
 		if (same_encoding(utf8, output_enc))
 			output_enc = NULL;
t/t4205-log-pretty-formats.sh +4 -4
index 74babce..c84ec9a 100755
@@ -220,7 +220,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with trunc. i18n.logOutputEncoding' '
+test_expect_success 'left alignment formatting with trunc. i18n.logOutputEncoding' '
 	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual &&
 	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
 message ..
@@ -242,7 +242,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
+test_expect_success 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
 	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
 	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
 ..sage two
@@ -264,7 +264,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
+test_expect_success 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
 	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
 	qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
 mess.. two
@@ -420,7 +420,7 @@ initial...   A U Thor
 EOF
 	test_cmp expected actual
 '
-test_expect_failure 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
+test_expect_success 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
 	git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
 	cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
 short long  long long
t/t6006-rev-list-format.sh +3 -3
index 42bdefe..19434ad 100755
@@ -259,7 +259,7 @@ commit $head1
 $added_iso88591
 EOF
 
-test_format complex-subject-trunc "%<($truncate_count,trunc)%s" failure <<EOF
+test_format complex-subject-trunc "%<($truncate_count,trunc)%s" <<EOF
 commit $head3
 Test printing of c..
 commit $head2
@@ -268,7 +268,7 @@ commit $head1
 added (hinzugef${added_utf8_part_iso88591}gt..
 EOF
 
-test_format complex-subject-mtrunc "%<($truncate_count,mtrunc)%s" failure <<EOF
+test_format complex-subject-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF
 commit $head3
 Test prin..ex bodies
 commit $head2
@@ -277,7 +277,7 @@ commit $head1
 added (hi..f${added_utf8_part_iso88591}gt) foo
 EOF
 
-test_format complex-subject-ltrunc "%<($truncate_count,ltrunc)%s" failure <<EOF
+test_format complex-subject-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF
 commit $head3
 .. of complex bodies
 commit $head2
Signature · 1 line
1.9.2-15
#24 lore raw

PATCH v2 2/2 pretty.c: format string with truncate respects logOutputEncoding

In reply to Alexey Shumkin

Pretty format string %<(N,[ml]trunc)>%s truncates subject to a given length with an appropriate padding. This works for non-ASCII texts when i18n.logOutputEncoding is UTF-8 only (independently of a printed commit message encoding) but does not work when i18n.logOutputEncoding is NOT UTF-8.

In 7e77df3 (pretty: two phase conversion for non utf-8 commits, 2013-04-19) 'format_commit_item' function assumes commit message to be in UTF-8. And that was so until ecaee80 (pretty: --format output should honor logOutputEncoding, 2013-06-26) where conversion to logOutputEncoding was added before calling 'format_commit_message'.

Correct this by converting a commit message to UTF-8 first (as it assumed in 7e77df3 (pretty: two phase conversion for non utf-8 commits, 2013-04-19)). Only after that convert a commit message to an actual logOutputEncoding.

---
 pretty.c                      | 7 ++++++-
 t/t4205-log-pretty-formats.sh | 8 ++++----
 t/t6006-rev-list-format.sh    | 6 +++---
 3 files changed, 13 insertions(+), 8 deletions(-)
pretty.c +6 -1
index 6e266dd..25e8825 100644
@@ -1507,13 +1507,18 @@ void format_commit_message(const struct commit *commit,
 	context.commit = commit;
 	context.pretty_ctx = pretty_ctx;
 	context.wrap_start = sb->len;
+	/*
+	 * convert a commit message to UTF-8 first
+	 * as far as 'format_commit_item' assumes it in UTF-8
+	 */
 	context.message = logmsg_reencode(commit,
 					  &context.commit_encoding,
-					  output_enc);
+					  utf8);
 
 	strbuf_expand(sb, format, format_commit_item, &context);
 	rewrap_message_tail(sb, &context, 0, 0, 0);
 
+	/* then convert a commit message to an actual output encoding */
 	if (output_enc) {
 		if (same_encoding(utf8, output_enc))
 			output_enc = NULL;
t/t4205-log-pretty-formats.sh +4 -4
index 6791e0d..7426fe2 100755
@@ -231,7 +231,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with trunc. i18n.logOutputEncoding' '
+test_expect_success 'left alignment formatting with trunc. i18n.logOutputEncoding' '
 	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,trunc)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -257,7 +257,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
+test_expect_success 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
 	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,ltrunc)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -283,7 +283,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
+test_expect_success 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
 	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,mtrunc)%s" >actual &&
 	# complete the incomplete line at the end
 	echo >>actual &&
@@ -465,7 +465,7 @@ EOF
 	test_cmp expected actual
 '
 
-test_expect_failure 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
+test_expect_success 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
 	git commit --amend -m short --author "long long long <[email protected]>" &&
 	git -c i18n.logOutputEncoding=iso8859-1 log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
 	# complete the incomplete line at the end
t/t6006-rev-list-format.sh +3 -3
index 09cdf24..04811fd 100755
@@ -256,7 +256,7 @@ commit $head1
 $added_iso88591
 EOF
 
-test_format complex-subject-trunc %<($truncate_count,trunc)%s failure <<EOF
+test_format complex-subject-trunc %<($truncate_count,trunc)%s <<EOF
 commit $head3
 Test printing of c..
 commit $head2
@@ -265,7 +265,7 @@ commit $head1
 added (hinzugef${added_utf8_part_iso88591}gt..
 EOF
 
-test_format complex-subject-mtrunc %<($truncate_count,mtrunc)%s failure <<EOF
+test_format complex-subject-mtrunc %<($truncate_count,mtrunc)%s <<EOF
 commit $head3
 Test prin..ex bodies
 commit $head2
@@ -274,7 +274,7 @@ commit $head1
 added (hi..f${added_utf8_part_iso88591}gt) foo
 EOF
 
-test_format complex-subject-ltrunc %<($truncate_count,ltrunc)%s failure <<EOF
+test_format complex-subject-ltrunc %<($truncate_count,ltrunc)%s <<EOF
 commit $head3
 .. of complex bodies
 commit $head2
Signature · 1 line
1.9.2-17