git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Shumkin <alex.crezoff@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: "brian m. carlson" <sandals@crustytoothpaste.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Ramsay Jones" <ramsay@ramsay1.demon.co.uk>,
	"Alexey Shumkin" <Alex.Crezoff@gmail.com>,
	git@vger.kernel.org
Subject: [PATCH v4 5/5] pretty.c: format string with truncate respects logOutputEncoding
Date: Wed, 21 May 2014 17:20:07 +0400	[thread overview]
Message-ID: <ee7b2aa742a2fd287a57a38239d5eb71b9f50ef9.1400678003.git.Alex.Crezoff@gmail.com> (raw)
In-Reply-To: <cover.1400678003.git.Alex.Crezoff@gmail.com>
In-Reply-To: <cover.1400678003.git.Alex.Crezoff@gmail.com>

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.

Signed-off-by: Alexey Shumkin <Alex.Crezoff@gmail.com>
Reviewed-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 pretty.c                      | 7 ++++++-
 t/t4205-log-pretty-formats.sh | 8 ++++----
 t/t6006-rev-list-format.sh    | 6 +++---
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/pretty.c b/pretty.c
index 6e266dd..25e8825 100644
--- a/pretty.c
+++ b/pretty.c
@@ -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;
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index 74babce..c84ec9a 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -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
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index 42bdefe..19434ad 100755
--- a/t/t6006-rev-list-format.sh
+++ b/t/t6006-rev-list-format.sh
@@ -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
-- 
1.9.2-15

  parent reply	other threads:[~2014-05-21 13:21 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-16 13:06 [PATCH 0/2] Pretty print truncate does not work Alexey Shumkin
2014-05-16 13:06 ` [PATCH 1/2] t4205 (log-pretty-formats): Add failing tests for the case when i18n.logOutputEncoding is set Alexey Shumkin
2014-05-16 13:06 ` [PATCH 2/2] pretty.c: format string with truncate respects logOutputEncoding Alexey Shumkin
2014-05-16 13:44   ` Duy Nguyen
2014-05-16 15:40     ` [PATCH v2 0/2] Reroll patch series. Pretty print truncate does not work Alexey Shumkin
2014-05-16 15:40     ` [PATCH v2 1/2] t4205, t6006: Add failing tests for the case when i18n.logOutputEncoding is set Alexey Shumkin
2014-05-16 18:49       ` Junio C Hamano
2014-05-17  8:52         ` Alexey Shumkin
2014-05-19 15:28         ` [PATCH v3 0/5] Reroll patches. Pretty print truncate does not work Alexey Shumkin
2014-05-21 13:20           ` [PATCH v4 " Alexey Shumkin
2014-05-21 13:20           ` [PATCH v4 1/5] t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs Alexey Shumkin
2014-05-21 13:20           ` [PATCH v4 2/5] t4041, t4205, t6006, t7102: Don't hardcode tested encoding value Alexey Shumkin
2014-05-21 13:20           ` [PATCH v4 3/5] t4205 (log-pretty-format): Use `tformat` rather than `format` Alexey Shumkin
2014-05-21 13:20           ` [PATCH v4 4/5] t4205, t6006: Add failing tests for the case when i18n.logOutputEncoding is set Alexey Shumkin
2014-05-21 15:38             ` Ramsay Jones
2014-05-21 18:11               ` Junio C Hamano
2014-05-21 13:20           ` Alexey Shumkin [this message]
2014-05-19 15:28         ` [PATCH v3 1/5] t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs Alexey Shumkin
2014-05-19 15:28         ` [PATCH v3 2/5] t4041, t4205, t6006, t7102: Don't hardcode tested encoding value Alexey Shumkin
2014-05-20  1:49           ` brian m. carlson
2014-05-20  6:41             ` Alexey Shumkin
2014-05-19 15:28         ` [PATCH v3 3/5] t4205 (log-pretty-format): Use `tformat` rather than `format` Alexey Shumkin
2014-05-19 15:28         ` [PATCH v3 4/5] t4205, t6006: Add failing tests for the case when i18n.logOutputEncoding is set Alexey Shumkin
2014-05-19 15:28         ` [PATCH v3 5/5] pretty.c: format string with truncate respects logOutputEncoding Alexey Shumkin
2014-05-16 15:40     ` [PATCH v2 2/2] " Alexey Shumkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee7b2aa742a2fd287a57a38239d5eb71b9f50ef9.1400678003.git.Alex.Crezoff@gmail.com \
    --to=alex.crezoff@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    --cc=ramsay@ramsay1.demon.co.uk \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).