From: "Pat Notz" <patnotz@gmail.com>
To: git@vger.kernel.org
Subject: [PATCHv7 2/6] pretty.c: teach format_commit_message() to reencode the output
Date: Tue, 2 Nov 2010 13:59:08 -0600 [thread overview]
Message-ID: <1288727952-57498-3-git-send-email-patnotz@gmail.com> (raw)
In-Reply-To: <1288727952-57498-1-git-send-email-patnotz@gmail.com>
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>
---
commit.h | 3 +++
pretty.c | 27 +++++++++++++++++++++------
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/commit.h b/commit.h
index a0b710f..3bfb31b 100644
--- a/commit.h
+++ b/commit.h
@@ -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 *);
diff --git a/pretty.c b/pretty.c
index c253172..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;
@@ -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,
--
1.7.3.2
next prev parent reply other threads:[~2010-11-02 19:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-02 19:59 [PATCHv7 0/6] Add commit message options for rebase --autosquash Pat Notz
2010-11-02 19:59 ` [PATCHv7 1/6] commit: helper methods to reduce redundant blocks of code Pat Notz
2010-11-02 20:42 ` Thiago Farina
2010-11-02 19:59 ` Pat Notz [this message]
2010-11-02 19:59 ` [PATCHv7 3/6] commit: --fixup option for use with rebase --autosquash Pat Notz
2010-11-02 19:59 ` [PATCHv7 4/6] add tests of commit --fixup Pat Notz
2010-11-02 19:59 ` [PATCHv7 5/6] commit: --squash option for use with rebase --autosquash Pat Notz
2010-11-03 9:20 ` Stephen Boyd
2010-11-02 19:59 ` [PATCHv7 6/6] add tests of commit --squash Pat Notz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1288727952-57498-3-git-send-email-patnotz@gmail.com \
--to=patnotz@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).