diff options
author | Pat Notz <patnotz@gmail.com> | 2010-11-02 13:59:08 -0600 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-11-04 13:53:34 -0700 |
commit | 177b29dcab4c6a1b291b718c1fb192d151356f3f (patch) | |
tree | 07605c8b609f51cf9ad21ba1bd4f78893f8bcbe9 | |
parent | commit: helper methods to reduce redundant blocks of code (diff) | |
download | tgif-177b29dcab4c6a1b291b718c1fb192d151356f3f.tar.xz |
pretty.c: teach format_commit_message() to reencode the output
format_commit_message() will now reencode the content if the desired
output encoding is different from the encoding in the passed in
commit. Callers wanting to specify the output encoding do so via the
pretty_print_context struct.
Signed-off-by: Pat Notz <patnotz@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | commit.h | 3 | ||||
-rw-r--r-- | pretty.c | 27 |
2 files changed, 24 insertions, 6 deletions
@@ -77,6 +77,7 @@ struct pretty_print_context int need_8bit_cte; int show_notes; struct reflog_walk_info *reflog_info; + const char *output_encoding; }; struct userformat_want { @@ -85,6 +86,8 @@ struct userformat_want { extern int has_non_ascii(const char *text); struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */ +extern char *logmsg_reencode(const struct commit *commit, + const char *output_encoding); extern char *reencode_commit_message(const struct commit *commit, const char **encoding_p); extern void get_commit_format(const char *arg, struct rev_info *); @@ -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; @@ -1011,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, |