Skip to content

Commit ec00807

Browse files
committed
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 <[email protected]>
1 parent 0e18bcd commit ec00807

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

pretty.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ char *logmsg_reencode(const struct commit *commit,
500500
char *encoding;
501501
char *out;
502502

503-
if (!*output_encoding)
503+
if (!output_encoding || !*output_encoding)
504504
return NULL;
505505
encoding = get_header(commit, "encoding");
506506
use_encoding = encoding ? encoding : utf8;
@@ -1184,23 +1184,15 @@ void format_commit_message(const struct commit *commit,
11841184
const struct pretty_print_context *pretty_ctx)
11851185
{
11861186
struct format_commit_context context;
1187-
static const char utf8[] = "UTF-8";
11881187
const char *output_enc = pretty_ctx->output_encoding;
11891188

11901189
memset(&context, 0, sizeof(context));
11911190
context.commit = commit;
11921191
context.pretty_ctx = pretty_ctx;
11931192
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;
12041196

12051197
strbuf_expand(sb, format, format_commit_item, &context);
12061198
rewrap_message_tail(sb, &context, 0, 0, 0);

0 commit comments

Comments
 (0)