613
static const char *utf8 = "UTF-8";
614
const char *use_encoding;
615
char *encoding;
616
- char *msg = commit->buffer;
616
+ const char *msg = get_commit_buffer(commit);
617
char *out;
618
619
- if (!msg) {
620
- enum object_type type;
621
- unsigned long size;
622
-
623
- msg = read_sha1_file(commit->object.sha1, &type, &size);
624
- if (!msg)
625
- die("Cannot read commit object %s",
626
- sha1_to_hex(commit->object.sha1));
627
- if (type != OBJ_COMMIT)
628
- die("Expected commit for '%s', got %s",
629
- sha1_to_hex(commit->object.sha1), typename(type));
630
- }
631
-
619
if (!output_encoding || !*output_encoding) {
620
if (commit_encoding)
621
*commit_encoding =
639
* Otherwise, we still want to munge the encoding header in the
640
* result, which will be done by modifying the buffer. If we
641
* are using a fresh copy, we can reuse it. But if we are using
655
- * the cached copy from commit->buffer, we need to duplicate it
656
- * to avoid munging commit->buffer.
642
+ * the cached copy from get_commit_buffer, we need to duplicate it
643
+ * to avoid munging the cached copy.
644
*/
658
- out = msg;
659
- if (out == commit->buffer)
660
- out = xstrdup(out);
645
+ if (msg == get_cached_commit_buffer(commit))
646
+ out = xstrdup(msg);
647
+ else
648
+ out = (char *)msg;
649
}
650
else {
651
/*
655
* copy, we can free it.
656
*/
657
out = reencode_string(msg, output_encoding, use_encoding);
670
- if (out && msg != commit->buffer)
671
- free(msg);
658
+ if (out)
659
+ unuse_commit_buffer(commit, msg);
660
}
661
662
/*
675
return out ? out : msg;
676
}
677
690
-void logmsg_free(const char *msg, const struct commit *commit)
691
-{
692
- if (msg != commit->buffer)
693
- free((void *)msg);
694
-}
695
-
678
static int mailmap_name(const char **email, size_t *email_len,
679
const char **name, size_t *name_len)
680
{
1513
}
1514
1515
free(context.commit_encoding);
1534
- logmsg_free(context.message, commit);
1516
+ unuse_commit_buffer(commit, context.message);
1517
free(context.signature_check.gpg_output);
1518
free(context.signature_check.signer);
1519
}
1749
if (pp->fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
1750
strbuf_addch(sb, '\n');
1751
1770
- logmsg_free(reencoded, commit);
1752
+ unuse_commit_buffer(commit, reencoded);
1753
}
1754
1755
void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit,