Skip to content

Commit 8a64822

Browse files
committed
Merge branch 'as/log-output-encoding-in-user-format'
"log --format=" did not honor i18n.logoutputencoding configuration and this attempts to fix it. * as/log-output-encoding-in-user-format: t4205 (log-pretty-formats): avoid using `sed` t6006 (rev-list-format): add tests for "%b" and "%s" for the case i18n.commitEncoding is not set t4205, t6006, t7102: make functions better readable t4205 (log-pretty-formats): revert back single quotes t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1 t4205: replace .\+ with ..* in sed commands pretty: --format output should honor logOutputEncoding pretty: Add failing tests: --format output should honor logOutputEncoding t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs t7102 (reset): don't hardcode SHA-1 in expected outputs t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs
2 parents dacd2bc + 37eb772 commit 8a64822

File tree

9 files changed

+265
-136
lines changed

9 files changed

+265
-136
lines changed

builtin/reset.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ static int reset_index(const unsigned char *sha1, int reset_type, int quiet)
9393
static void print_new_head_line(struct commit *commit)
9494
{
9595
const char *hex, *body;
96+
char *msg;
9697

9798
hex = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
9899
printf(_("HEAD is now at %s"), hex);
99-
body = strstr(commit->buffer, "\n\n");
100+
msg = logmsg_reencode(commit, NULL, get_log_output_encoding());
101+
body = strstr(msg, "\n\n");
100102
if (body) {
101103
const char *eol;
102104
size_t len;
@@ -107,6 +109,7 @@ static void print_new_head_line(struct commit *commit)
107109
}
108110
else
109111
printf("\n");
112+
logmsg_free(msg, commit);
110113
}
111114

112115
static void update_index_from_diff(struct diff_queue_struct *q,

builtin/rev-list.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ static void show_commit(struct commit *commit, void *data)
111111
ctx.date_mode = revs->date_mode;
112112
ctx.date_mode_explicit = revs->date_mode_explicit;
113113
ctx.fmt = revs->commit_format;
114+
ctx.output_encoding = get_log_output_encoding();
114115
pretty_print_commit(&ctx, commit, &buf);
115116
if (revs->graph) {
116117
if (buf.len) {

builtin/shortlog.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
137137
ctx.subject = "";
138138
ctx.after_subject = "";
139139
ctx.date_mode = DATE_NORMAL;
140+
ctx.output_encoding = get_log_output_encoding();
140141
pretty_print_commit(&ctx, commit, &ufbuf);
141142
buffer = ufbuf.buf;
142143
} else if (*buffer) {

log-tree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ void show_log(struct rev_info *opt)
617617
ctx.fmt = opt->commit_format;
618618
ctx.mailmap = opt->mailmap;
619619
ctx.color = opt->diffopt.use_color;
620+
ctx.output_encoding = get_log_output_encoding();
620621
pretty_print_commit(&ctx, commit, &msgbuf);
621622

622623
if (opt->add_signoff)

submodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
226226
while ((commit = get_revision(rev))) {
227227
struct pretty_print_context ctx = {0};
228228
ctx.date_mode = rev->date_mode;
229+
ctx.output_encoding = get_log_output_encoding();
229230
strbuf_setlen(&sb, 0);
230231
strbuf_addstr(&sb, line_prefix);
231232
if (commit->object.flags & SYMMETRIC_LEFT) {

t/t4041-diff-submodule-option.sh

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/sh
22
#
33
# Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
4+
# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
45
#
56

67
test_description='Support for verbose submodule differences in git diff
@@ -10,6 +11,9 @@ This test tries to verify the sanity of the --submodule option of git diff.
1011

1112
. ./test-lib.sh
1213

14+
# String "added" in German (translated with Google Translate), encoded in UTF-8,
15+
# used in sample commit log messages in add_file() function below.
16+
added=$(printf "hinzugef\303\274gt")
1317
add_file () {
1418
(
1519
cd "$1" &&
@@ -19,7 +23,8 @@ add_file () {
1923
echo "$name" >"$name" &&
2024
git add "$name" &&
2125
test_tick &&
22-
git commit -m "Add $name" || exit
26+
msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso8859-1) &&
27+
git -c 'i18n.commitEncoding=iso8859-1' commit -m "$msg_added_iso88591"
2328
done >/dev/null &&
2429
git rev-parse --short --verify HEAD
2530
)
@@ -93,7 +98,7 @@ test_expect_success 'modified submodule(forward)' '
9398
git diff-index -p --submodule=log HEAD >actual &&
9499
cat >expected <<-EOF &&
95100
Submodule sm1 $head1..$head2:
96-
> Add foo3
101+
> Add foo3 ($added foo3)
97102
EOF
98103
test_cmp expected actual
99104
'
@@ -102,7 +107,7 @@ test_expect_success 'modified submodule(forward)' '
102107
git diff --submodule=log >actual &&
103108
cat >expected <<-EOF &&
104109
Submodule sm1 $head1..$head2:
105-
> Add foo3
110+
> Add foo3 ($added foo3)
106111
EOF
107112
test_cmp expected actual
108113
'
@@ -111,7 +116,7 @@ test_expect_success 'modified submodule(forward) --submodule' '
111116
git diff --submodule >actual &&
112117
cat >expected <<-EOF &&
113118
Submodule sm1 $head1..$head2:
114-
> Add foo3
119+
> Add foo3 ($added foo3)
115120
EOF
116121
test_cmp expected actual
117122
'
@@ -142,8 +147,8 @@ test_expect_success 'modified submodule(backward)' '
142147
git diff-index -p --submodule=log HEAD >actual &&
143148
cat >expected <<-EOF &&
144149
Submodule sm1 $head2..$head3 (rewind):
145-
< Add foo3
146-
< Add foo2
150+
< Add foo3 ($added foo3)
151+
< Add foo2 ($added foo2)
147152
EOF
148153
test_cmp expected actual
149154
'
@@ -153,10 +158,10 @@ test_expect_success 'modified submodule(backward and forward)' '
153158
git diff-index -p --submodule=log HEAD >actual &&
154159
cat >expected <<-EOF &&
155160
Submodule sm1 $head2...$head4:
156-
> Add foo5
157-
> Add foo4
158-
< Add foo3
159-
< Add foo2
161+
> Add foo5 ($added foo5)
162+
> Add foo4 ($added foo4)
163+
< Add foo3 ($added foo3)
164+
< Add foo2 ($added foo2)
160165
EOF
161166
test_cmp expected actual
162167
'

0 commit comments

Comments
 (0)