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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Apr 19, 2013 at 09:08 UTC 0940a76db621e87fe7bf569e7e2e7d703d4be592
1 file changed +7 -6
pretty.c
+7 -6
@@ -776,12 +776,12 @@ struct format_commit_context {
776 unsigned commit_message_parsed:1;
777 struct signature_check signature_check;
778 char *message;
779 + char *commit_encoding;
780 size_t width, indent1, indent2;
781
782 /* These offsets are relative to the start of the commit message. */
783 struct chunk author;
784 struct chunk committer;
784 - struct chunk encoding;
785 size_t message_off;
786 size_t subject_off;
787 size_t body_off;
@@ -828,9 +828,6 @@ static void parse_commit_header(struct format_commit_context *context)
828 } else if (!prefixcmp(msg + i, "committer ")) {
829 context->committer.off = i + 10;
830 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;
831 }
832 i = eol;
833 }
@@ -1185,7 +1182,8 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
1182 msg + c->committer.off, c->committer.len,
1183 c->pretty_ctx->date_mode);
1184 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);
1187 return 1;
1188 case 'B': /* raw body */
1189 /* message_off is always left at the initial newline */
@@ -1296,11 +1294,14 @@ void format_commit_message(const struct commit *commit,
1294 context.commit = commit;
1295 context.pretty_ctx = pretty_ctx;
1296 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);
1300
1301 strbuf_expand(sb, format, format_commit_item, &context);
1302 rewrap_message_tail(sb, &context, 0, 0, 0);
1303
1304 + free(context.commit_encoding);
1305 logmsg_free(context.message, commit);
1306 free(context.signature_check.gpg_output);
1307 free(context.signature_check.signer);