From: "Pat Notz" <patnotz@gmail.com>
To: git@vger.kernel.org
Subject: [PATCHv5 4/8] pretty.c: teach format_commit_message() to reencode the output
Date: Thu, 7 Oct 2010 13:10:53 -0600 [thread overview]
Message-ID: <1286478657-61581-5-git-send-email-patnotz@gmail.com> (raw)
In-Reply-To: <1286478657-61581-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.
Signed-off-by: Pat Notz <patnotz@gmail.com>
---
archive.c | 2 +-
builtin/commit.c | 6 +++---
builtin/fmt-merge-msg.c | 2 +-
commit.h | 3 ++-
log-tree.c | 2 +-
notes-cache.c | 2 +-
pretty.c | 39 +++++++++++++++++++++++++++++++++++----
submodule.c | 4 ++--
8 files changed, 46 insertions(+), 14 deletions(-)
diff --git a/archive.c b/archive.c
index edd6853..42b7ab1 100644
--- a/archive.c
+++ b/archive.c
@@ -51,7 +51,7 @@ static void format_subst(const struct commit *commit,
strbuf_add(&fmt, b + 8, c - b - 8);
strbuf_add(buf, src, b - src);
- format_commit_message(commit, fmt.buf, buf, &ctx);
+ format_commit_message(commit, fmt.buf, buf, &ctx, NULL);
len -= c + 1 - src;
src = c + 1;
}
diff --git a/builtin/commit.c b/builtin/commit.c
index ea3801d..e66f10c 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -826,7 +826,7 @@ static const char *find_author_by_nickname(const char *name)
struct pretty_print_context ctx = {0};
ctx.date_mode = DATE_NORMAL;
strbuf_release(&buf);
- format_commit_message(commit, "%an <%ae>", &buf, &ctx);
+ format_commit_message(commit, "%an <%ae>", &buf, &ctx, NULL);
return strbuf_detach(&buf, NULL);
}
die("No existing author found with '%s'", name);
@@ -1135,8 +1135,8 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
strbuf_addstr(&format, "format:%h] %s");
- format_commit_message(commit, "%an <%ae>", &author_ident, &pctx);
- format_commit_message(commit, "%cn <%ce>", &committer_ident, &pctx);
+ format_commit_message(commit, "%an <%ae>", &author_ident, &pctx, NULL);
+ format_commit_message(commit, "%cn <%ce>", &committer_ident, &pctx, NULL);
if (strbuf_cmp(&author_ident, &committer_ident)) {
strbuf_addstr(&format, "\n Author: ");
strbuf_addbuf_percentquote(&format, &author_ident);
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 78c7774..7619f4f 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -173,7 +173,7 @@ static void shortlog(const char *name, unsigned char *sha1,
if (subjects.nr > limit)
continue;
- format_commit_message(commit, "%s", &sb, &ctx);
+ format_commit_message(commit, "%s", &sb, &ctx, NULL);
strbuf_ltrim(&sb);
if (!sb.len)
diff --git a/commit.h b/commit.h
index 6f4b586..51c7110 100644
--- a/commit.h
+++ b/commit.h
@@ -92,7 +92,8 @@ extern char *get_header(const struct commit *commit, const char *key);
extern void userformat_find_requirements(const char *fmt, struct userformat_want *w);
extern void format_commit_message(const struct commit *commit,
const char *format, struct strbuf *sb,
- const struct pretty_print_context *context);
+ const struct pretty_print_context *context,
+ const char *output_encoding);
extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
struct strbuf *sb,
const struct pretty_print_context *context);
diff --git a/log-tree.c b/log-tree.c
index b46ed3b..af3200d 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -274,7 +274,7 @@ void get_patch_filename(struct commit *commit, int nr, const char *suffix,
struct pretty_print_context ctx = {0};
ctx.date_mode = DATE_NORMAL;
- format_commit_message(commit, "%f", buf, &ctx);
+ format_commit_message(commit, "%f", buf, &ctx, NULL);
if (max_len < buf->len)
strbuf_setlen(buf, max_len);
strbuf_addstr(buf, suffix);
diff --git a/notes-cache.c b/notes-cache.c
index dee6d62..461c474 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -19,7 +19,7 @@ static int notes_cache_match_validity(const char *ref, const char *validity)
return 0;
memset(&pretty_ctx, 0, sizeof(pretty_ctx));
- format_commit_message(commit, "%s", &msg, &pretty_ctx);
+ format_commit_message(commit, "%s", &msg, &pretty_ctx, NULL);
strbuf_trim(&msg);
ret = !strcmp(msg.buf, validity);
diff --git a/pretty.c b/pretty.c
index a607fd6..e5ce7fb 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1009,16 +1009,47 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *w)
void format_commit_message(const struct commit *commit,
const char *format, struct strbuf *sb,
- const struct pretty_print_context *pretty_ctx)
+ const struct pretty_print_context *pretty_ctx,
+ const char *output_encoding)
{
struct format_commit_context context;
+ static char utf8[] = "UTF-8";
+ char *enc;
+ char *buffer;
+ char *enc_buffer;
+ struct strbuf scratch_sb = STRBUF_INIT;
+ struct strbuf *sb_ptr;
+
+ enc = get_header(commit, "encoding");
+ enc = enc ? enc : utf8;
+ if(output_encoding && strcmp(enc,output_encoding)) {
+ sb_ptr = &scratch_sb;
+ } else {
+ sb_ptr = sb;
+ }
memset(&context, 0, sizeof(context));
context.commit = commit;
context.pretty_ctx = pretty_ctx;
context.wrap_start = sb->len;
- strbuf_expand(sb, format, format_commit_item, &context);
- rewrap_message_tail(sb, &context, 0, 0, 0);
+ strbuf_expand(sb_ptr, format, format_commit_item, &context);
+ rewrap_message_tail(sb_ptr, &context, 0, 0, 0);
+
+ if(sb_ptr != sb) {
+ /* if re-encoding fails, take the content byte-for-byte */
+ buffer = strbuf_detach(sb_ptr, 0);
+ enc_buffer = reencode_string(buffer, output_encoding, enc);
+ enc_buffer = enc_buffer ? enc_buffer : buffer;
+
+ strbuf_addstr(sb,enc_buffer);
+
+ if(enc_buffer != buffer)
+ free(enc_buffer);
+ free(buffer);
+ }
+
+ if(enc != utf8)
+ free(enc);
}
static void pp_header(enum cmit_fmt fmt,
@@ -1177,7 +1208,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
int need_8bit_cte = context->need_8bit_cte;
if (fmt == CMIT_FMT_USERFORMAT) {
- format_commit_message(commit, user_format, sb, context);
+ format_commit_message(commit, user_format, sb, context, NULL);
return;
}
diff --git a/submodule.c b/submodule.c
index 91a4758..c108ff6 100644
--- a/submodule.c
+++ b/submodule.c
@@ -217,7 +217,7 @@ void show_submodule_summary(FILE *f, const char *path,
}
else if (add)
strbuf_addstr(&sb, add);
- format_commit_message(commit, format, &sb, &ctx);
+ format_commit_message(commit, format, &sb, &ctx, NULL);
if (reset)
strbuf_addstr(&sb, reset);
strbuf_addch(&sb, '\n');
@@ -362,7 +362,7 @@ static void print_commit(struct commit *commit)
struct strbuf sb = STRBUF_INIT;
struct pretty_print_context ctx = {0};
ctx.date_mode = DATE_NORMAL;
- format_commit_message(commit, " %h: %m %s", &sb, &ctx);
+ format_commit_message(commit, " %h: %m %s", &sb, &ctx, NULL);
fprintf(stderr, "%s\n", sb.buf);
strbuf_release(&sb);
}
--
1.7.3.1
next prev parent reply other threads:[~2010-10-07 19:12 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-07 19:10 [PATCHv5 0/8] Add commit message options for rebase --autosquash Pat Notz
2010-10-07 19:10 ` [PATCHv5 1/8] commit.c: prefer get_header() to manual searching Pat Notz
2010-10-07 21:11 ` Sverre Rabbelier
2010-10-07 21:12 ` Sverre Rabbelier
2010-10-13 21:59 ` Junio C Hamano
2010-10-07 19:10 ` [PATCHv5 2/8] commit.c: new function for looking up a comit by name Pat Notz
2010-10-13 21:59 ` Junio C Hamano
2010-10-07 19:10 ` [PATCHv5 3/8] pretty.c: helper methods for getting output encodings Pat Notz
2010-10-07 19:10 ` Pat Notz [this message]
2010-10-13 21:59 ` [PATCHv5 4/8] pretty.c: teach format_commit_message() to reencode the output Junio C Hamano
2010-10-13 22:44 ` Pat Notz
2010-10-07 19:10 ` [PATCHv5 5/8] commit: --fixup option for use with rebase --autosquash Pat Notz
2010-10-07 19:10 ` [PATCHv5 6/8] add tests of commit --fixup Pat Notz
2010-10-07 19:10 ` [PATCHv5 7/8] commit: --squash option for use with rebase --autosquash Pat Notz
2010-10-07 19:10 ` [PATCHv5 8/8] add tests of commit --squash Pat Notz
2010-10-11 21:06 ` [PATCHv5 0/8] Add commit message options for rebase --autosquash Pat Notz
2010-10-12 9:36 ` Sverre Rabbelier
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=1286478657-61581-5-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).