summaryrefslogtreecommitdiff
path: root/pretty.c
diff options
context:
space:
mode:
Diffstat (limited to 'pretty.c')
-rw-r--r--pretty.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/pretty.c b/pretty.c
index f85444b..8549934 100644
--- a/pretty.c
+++ b/pretty.c
@@ -403,8 +403,8 @@ static char *replace_encoding_header(char *buf, const char *encoding)
return strbuf_detach(&tmp, NULL);
}
-static char *logmsg_reencode(const struct commit *commit,
- const char *output_encoding)
+char *logmsg_reencode(const struct commit *commit,
+ const char *output_encoding)
{
static const char *utf8 = "UTF-8";
const char *use_encoding;
@@ -555,6 +555,7 @@ struct format_commit_context {
const struct pretty_print_context *pretty_ctx;
unsigned commit_header_parsed:1;
unsigned commit_message_parsed:1;
+ char *message;
size_t width, indent1, indent2;
/* These offsets are relative to the start of the commit message. */
@@ -591,7 +592,7 @@ static int add_again(struct strbuf *sb, struct chunk *chunk)
static void parse_commit_header(struct format_commit_context *context)
{
- const char *msg = context->commit->buffer;
+ const char *msg = context->message;
int i;
for (i = 0; msg[i]; i++) {
@@ -677,8 +678,8 @@ const char *format_subject(struct strbuf *sb, const char *msg,
static void parse_commit_message(struct format_commit_context *c)
{
- const char *msg = c->commit->buffer + c->message_off;
- const char *start = c->commit->buffer;
+ const char *msg = c->message + c->message_off;
+ const char *start = c->message;
msg = skip_empty_lines(msg);
c->subject_off = msg - start;
@@ -741,7 +742,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
{
struct format_commit_context *c = context;
const struct commit *commit = c->commit;
- const char *msg = commit->buffer;
+ const char *msg = c->message;
struct commit_list *p;
int h1, h2;
@@ -886,8 +887,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
case 'N':
if (c->pretty_ctx->show_notes) {
format_display_notes(commit->object.sha1, sb,
- git_log_output_encoding ? git_log_output_encoding
- : git_commit_encoding, 0);
+ get_log_output_encoding(), 0);
return 1;
}
return 0;
@@ -1012,13 +1012,27 @@ 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 *enc;
+ 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) {
+ enc = get_header(commit, "encoding");
+ enc = enc ? enc : utf8;
+ if (strcmp(enc, output_enc))
+ context.message = logmsg_reencode(commit, output_enc);
+ }
+
strbuf_expand(sb, format, format_commit_item, &context);
rewrap_message_tail(sb, &context, 0, 0, 0);
+
+ if (context.message != commit->buffer)
+ free(context.message);
}
static void pp_header(enum cmit_fmt fmt,
@@ -1159,11 +1173,7 @@ char *reencode_commit_message(const struct commit *commit, const char **encoding
{
const char *encoding;
- encoding = (git_log_output_encoding
- ? git_log_output_encoding
- : git_commit_encoding);
- if (!encoding)
- encoding = "UTF-8";
+ encoding = get_log_output_encoding();
if (encoding_p)
*encoding_p = encoding;
return logmsg_reencode(commit, encoding);