format_commit_message(): simplify calls to logmsg_reencode()
All the other callers of logmsg_reencode() pass return value of get_commit_output_encoding() or get_log_output_encoding(). Teach the function to optionally take NULL as a synonym to "" aka "no conversion requested" so that we can simplify the only remaining calling site. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Dec 10, 2012 at 12:50 UTC
ec008076dbe6acde42ce9ff796f72ca7c3edd5bf
1 file changed
+4
-12
pretty.c
+4
-12
@@ -500,7 +500,7 @@ char *logmsg_reencode(const struct commit *commit,
500
char *encoding;
501
char *out;
502
503
- if (!*output_encoding)
503
+ if (!output_encoding || !*output_encoding)
504
return NULL;
505
encoding = get_header(commit, "encoding");
506
use_encoding = encoding ? encoding : utf8;
@@ -1184,23 +1184,15 @@ void format_commit_message(const struct commit *commit,
1184
const struct pretty_print_context *pretty_ctx)
1185
{
1186
struct format_commit_context context;
1187
- static const char utf8[] = "UTF-8";
1187
const char *output_enc = pretty_ctx->output_encoding;
1188
1189
memset(&context, 0, sizeof(context));
1190
context.commit = commit;
1191
context.pretty_ctx = pretty_ctx;
1192
context.wrap_start = sb->len;
1194
- context.message = commit->buffer;
1195
- if (output_enc) {
1196
- char *enc = get_header(commit, "encoding");
1197
- if (strcmp(enc ? enc : utf8, output_enc)) {
1198
- context.message = logmsg_reencode(commit, output_enc);
1199
- if (!context.message)
1200
- context.message = commit->buffer;
1201
- }
1202
- free(enc);
1203
- }
1193
+ context.message = logmsg_reencode(commit, output_enc);
1194
+ if (!context.message)
1195
+ context.message = commit->buffer;
1196
1197
strbuf_expand(sb, format, format_commit_item, &context);
1198
rewrap_message_tail(sb, &context, 0, 0, 0);