Skip to content

Commit 7d50987

Browse files
ashumkingitster
authored andcommitted
pretty.c: format string with truncate respects logOutputEncoding
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 <[email protected]> Reviewed-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d928d81 commit 7d50987

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

pretty.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,13 +1506,18 @@ void format_commit_message(const struct commit *commit,
15061506
context.commit = commit;
15071507
context.pretty_ctx = pretty_ctx;
15081508
context.wrap_start = sb->len;
1509+
/*
1510+
* convert a commit message to UTF-8 first
1511+
* as far as 'format_commit_item' assumes it in UTF-8
1512+
*/
15091513
context.message = logmsg_reencode(commit,
15101514
&context.commit_encoding,
1511-
output_enc);
1515+
utf8);
15121516

15131517
strbuf_expand(sb, format, format_commit_item, &context);
15141518
rewrap_message_tail(sb, &context, 0, 0, 0);
15151519

1520+
/* then convert a commit message to an actual output encoding */
15161521
if (output_enc) {
15171522
if (same_encoding(utf8, output_enc))
15181523
output_enc = NULL;

t/t4205-log-pretty-formats.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ EOF
220220
test_cmp expected actual
221221
'
222222

223-
test_expect_failure 'left alignment formatting with trunc. i18n.logOutputEncoding' '
223+
test_expect_success 'left alignment formatting with trunc. i18n.logOutputEncoding' '
224224
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual &&
225225
qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
226226
message ..
@@ -242,7 +242,7 @@ EOF
242242
test_cmp expected actual
243243
'
244244

245-
test_expect_failure 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
245+
test_expect_success 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
246246
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
247247
qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
248248
..sage two
@@ -264,7 +264,7 @@ EOF
264264
test_cmp expected actual
265265
'
266266

267-
test_expect_failure 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
267+
test_expect_success 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
268268
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
269269
qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
270270
mess.. two
@@ -420,7 +420,7 @@ initial... A U Thor
420420
EOF
421421
test_cmp expected actual
422422
'
423-
test_expect_failure 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
423+
test_expect_success 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
424424
git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
425425
cat <<EOF | iconv -f utf-8 -t $test_encoding >expected &&
426426
short long long long

t/t6006-rev-list-format.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ commit $head1
256256
$added_iso88591
257257
EOF
258258

259-
test_format complex-subject-trunc "%<($truncate_count,trunc)%s" failure <<EOF
259+
test_format complex-subject-trunc "%<($truncate_count,trunc)%s" <<EOF
260260
commit $head3
261261
Test printing of c..
262262
commit $head2
@@ -265,7 +265,7 @@ commit $head1
265265
added (hinzugef${added_utf8_part_iso88591}gt..
266266
EOF
267267

268-
test_format complex-subject-mtrunc "%<($truncate_count,mtrunc)%s" failure <<EOF
268+
test_format complex-subject-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF
269269
commit $head3
270270
Test prin..ex bodies
271271
commit $head2
@@ -274,7 +274,7 @@ commit $head1
274274
added (hi..f${added_utf8_part_iso88591}gt) foo
275275
EOF
276276

277-
test_format complex-subject-ltrunc "%<($truncate_count,ltrunc)%s" failure <<EOF
277+
test_format complex-subject-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF
278278
commit $head3
279279
.. of complex bodies
280280
commit $head2

0 commit comments

Comments
 (0)