From 7d509878b845a2a895cc880b833a016a06199981 Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Wed, 21 May 2014 17:20:07 +0400 Subject: [PATCH] pretty.c: format string with truncate respects logOutputEncoding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- 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 3c43db558a..c9cf67ea7c 100644 --- a/pretty.c +++ b/pretty.c @@ -1506,13 +1506,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 74babced70..c84ec9ae61 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 <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 <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 <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 <expected && short long long long diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 680b960152..c277db64f7 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -256,7 +256,7 @@ commit $head1 $added_iso88591 EOF -test_format complex-subject-trunc "%<($truncate_count,trunc)%s" failure <