Skip to content

Commit

Permalink
format_commit_message(): simplify calls to logmsg_reencode()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Dec 10, 2012
1 parent 0e18bcd commit ec00807
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions pretty.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ char *logmsg_reencode(const struct commit *commit,
char *encoding;
char *out;

if (!*output_encoding)
if (!output_encoding || !*output_encoding)
return NULL;
encoding = get_header(commit, "encoding");
use_encoding = encoding ? encoding : utf8;
Expand Down Expand Up @@ -1184,23 +1184,15 @@ void format_commit_message(const struct commit *commit,
const struct pretty_print_context *pretty_ctx)
{
struct format_commit_context context;
static const char utf8[] = "UTF-8";
const char *output_enc = pretty_ctx->output_encoding;

memset(&context, 0, sizeof(context));
context.commit = commit;
context.pretty_ctx = pretty_ctx;
context.wrap_start = sb->len;
context.message = commit->buffer;
if (output_enc) {
char *enc = get_header(commit, "encoding");
if (strcmp(enc ? enc : utf8, output_enc)) {
context.message = logmsg_reencode(commit, output_enc);
if (!context.message)
context.message = commit->buffer;
}
free(enc);
}
context.message = logmsg_reencode(commit, output_enc);
if (!context.message)
context.message = commit->buffer;

strbuf_expand(sb, format, format_commit_item, &context);
rewrap_message_tail(sb, &context, 0, 0, 0);
Expand Down

0 comments on commit ec00807

Please sign in to comment.