git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Alexey Shumkin <alex.crezoff@gmail.com>
Date
May 19, 2014, 15:28 UTC
Message-ID
<8dbe3506315942709627102c133d555139ac68af.1400513063.git.Alex.Crezoff@gmail.com>
In-Reply-To
<cover.1400513063.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 a932f34..c6e9a73 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
Previous: Alexey ShumkinNext: Alexey Shumkin
Message 16 of 25 in “Pretty print truncate does not work”
  1. 0/2 Pretty print truncate does not workAlexey Shumkin, May 16, 2014
  2. 1/2 t4205 (log-pretty-formats): Add failing tests for the case when i18n.logOutputEncoding is setAlexey Shumkin, May 16, 2014
  3. 2/2 pretty.c: format string with truncate respects logOutputEncodingAlexey Shumkin, May 16, 2014
  4. Duy NguyenMay 16, 2014
  5. 0/2 Reroll patch series. Pretty print truncate does not workAlexey Shumkin, May 16, 2014
  6. 1/2 t4205, t6006: Add failing tests for the case when i18n.logOutputEncoding is setAlexey Shumkin, May 16, 2014
  7. Junio C HamanoMay 16, 2014
  8. Alexey ShumkinMay 17, 2014
  9. 0/5 Reroll patches. Pretty print truncate does not workAlexey Shumkin, May 19, 2014
  10. 1/5 t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputsAlexey Shumkin, May 19, 2014
  11. 2/5 t4041, t4205, t6006, t7102: Don't hardcode tested encoding valueAlexey Shumkin, May 19, 2014
  12. brian m. carlsonMay 20, 2014
  13. Alexey ShumkinMay 20, 2014
  14. 3/5 t4205 (log-pretty-format): Use `tformat` rather than `format`Alexey Shumkin, May 19, 2014
  15. 4/5 t4205, t6006: Add failing tests for the case when i18n.logOutputEncoding is setAlexey Shumkin, May 19, 2014
  16. 5/5 pretty.c: format string with truncate respects logOutputEncodingAlexey Shumkin, May 19, 2014
  17. 0/5 Reroll patches. Pretty print truncate does not workAlexey Shumkin, May 21, 2014
  18. 1/5 t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputsAlexey Shumkin, May 21, 2014
  19. 2/5 t4041, t4205, t6006, t7102: Don't hardcode tested encoding valueAlexey Shumkin, May 21, 2014
  20. 3/5 t4205 (log-pretty-format): Use `tformat` rather than `format`Alexey Shumkin, May 21, 2014
  21. 4/5 t4205, t6006: Add failing tests for the case when i18n.logOutputEncoding is setAlexey Shumkin, May 21, 2014
  22. Ramsay JonesMay 21, 2014
  23. Junio C HamanoMay 21, 2014
  24. 5/5 pretty.c: format string with truncate respects logOutputEncodingAlexey Shumkin, May 21, 2014
  25. 2/2 pretty.c: format string with truncate respects logOutputEncodingAlexey Shumkin, May 16, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.