Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 0940a76

Browse files
pcloudsgitster
authored andcommitted
pretty: get the correct encoding for --pretty:format=%e
parse_commit_header() provides the commit encoding for '%e' and it reads it from the re-encoded message, which contains the new encoding, not the original one in the commit object. This never happens because --pretty=format:xxx never respects i18n.logoutputencoding. But that's a different story. Get the commit encoding from logmsg_reencode() instead. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5a10d23 commit 0940a76

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pretty.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,12 @@ struct format_commit_context {
776776
unsigned commit_message_parsed:1;
777777
struct signature_check signature_check;
778778
char *message;
779+
char *commit_encoding;
779780
size_t width, indent1, indent2;
780781

781782
/* These offsets are relative to the start of the commit message. */
782783
struct chunk author;
783784
struct chunk committer;
784-
struct chunk encoding;
785785
size_t message_off;
786786
size_t subject_off;
787787
size_t body_off;
@@ -828,9 +828,6 @@ static void parse_commit_header(struct format_commit_context *context)
828828
} else if (!prefixcmp(msg + i, "committer ")) {
829829
context->committer.off = i + 10;
830830
context->committer.len = eol - i - 10;
831-
} else if (!prefixcmp(msg + i, "encoding ")) {
832-
context->encoding.off = i + 9;
833-
context->encoding.len = eol - i - 9;
834831
}
835832
i = eol;
836833
}
@@ -1185,7 +1182,8 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
11851182
msg + c->committer.off, c->committer.len,
11861183
c->pretty_ctx->date_mode);
11871184
case 'e': /* encoding */
1188-
strbuf_add(sb, msg + c->encoding.off, c->encoding.len);
1185+
if (c->commit_encoding)
1186+
strbuf_addstr(sb, c->commit_encoding);
11891187
return 1;
11901188
case 'B': /* raw body */
11911189
/* message_off is always left at the initial newline */
@@ -1296,11 +1294,14 @@ void format_commit_message(const struct commit *commit,
12961294
context.commit = commit;
12971295
context.pretty_ctx = pretty_ctx;
12981296
context.wrap_start = sb->len;
1299-
context.message = logmsg_reencode(commit, NULL, output_enc);
1297+
context.message = logmsg_reencode(commit,
1298+
&context.commit_encoding,
1299+
output_enc);
13001300

13011301
strbuf_expand(sb, format, format_commit_item, &context);
13021302
rewrap_message_tail(sb, &context, 0, 0, 0);
13031303

1304+
free(context.commit_encoding);
13041305
logmsg_free(context.message, commit);
13051306
free(context.signature_check.gpg_output);
13061307
free(context.signature_check.signer);

0 commit comments

Comments
 (0)