524
strbuf_addch(sb, '\n');
525
}
526
527
-static char *get_header(const struct commit *commit, const char *key)
527
+static char *get_header(const struct commit *commit, const char *msg,
528
+ const char *key)
529
{
530
int key_len = strlen(key);
530
- const char *line = commit->buffer;
531
+ const char *line = msg;
532
533
while (line) {
534
const char *eol = strchr(line, '\n'), *next;
589
static const char *utf8 = "UTF-8";
590
const char *use_encoding;
591
char *encoding;
592
+ char *msg = commit->buffer;
593
char *out;
594
595
if (!output_encoding || !*output_encoding)
594
- return NULL;
595
- encoding = get_header(commit, "encoding");
596
+ return msg;
597
+ encoding = get_header(commit, msg, "encoding");
598
use_encoding = encoding ? encoding : utf8;
599
if (same_encoding(use_encoding, output_encoding))
600
if (encoding) /* we'll strip encoding header later */
601
out = xstrdup(commit->buffer);
602
else
601
- return NULL; /* nothing to do */
603
+ return msg; /* nothing to do */
604
else
605
out = reencode_string(commit->buffer,
606
output_encoding, use_encoding);
608
out = replace_encoding_header(out, output_encoding);
609
610
free(encoding);
609
- return out;
611
+ /*
612
+ * If the re-encoding failed, out might be NULL here; in that
613
+ * case we just return the commit message verbatim.
614
+ */
615
+ return out ? out : msg;
616
+}
617
+
618
+void logmsg_free(char *msg, const struct commit *commit)
619
+{
620
+ if (msg != commit->buffer)
621
+ free(msg);
622
}
623
624
static int mailmap_name(const char **email, size_t *email_len,
1290
context.pretty_ctx = pretty_ctx;
1291
context.wrap_start = sb->len;
1292
context.message = logmsg_reencode(commit, output_enc);
1281
- if (!context.message)
1282
- context.message = commit->buffer;
1293
1294
strbuf_expand(sb, format, format_commit_item, &context);
1295
rewrap_message_tail(sb, &context, 0, 0, 0);
1296
1287
- if (context.message != commit->buffer)
1288
- free(context.message);
1297
+ logmsg_free(context.message, commit);
1298
free(context.signature.gpg_output);
1299
free(context.signature.signer);
1300
}
1441
{
1442
unsigned long beginning_of_body;
1443
int indent = 4;
1435
- const char *msg = commit->buffer;
1444
+ const char *msg;
1445
char *reencoded;
1446
const char *encoding;
1447
int need_8bit_cte = pp->need_8bit_cte;
1452
}
1453
1454
encoding = get_log_output_encoding();
1446
- reencoded = logmsg_reencode(commit, encoding);
1447
- if (reencoded) {
1448
- msg = reencoded;
1449
- }
1455
+ msg = reencoded = logmsg_reencode(commit, encoding);
1456
1457
if (pp->fmt == CMIT_FMT_ONELINE || pp->fmt == CMIT_FMT_EMAIL)
1458
indent = 0;
1509
if (pp->fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
1510
strbuf_addch(sb, '\n');
1511
1506
- free(reencoded);
1512
+ logmsg_free(reencoded, commit);
1513
}
1514
1515
void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,