From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 4/4] Only re-encode certain parts in commit object, not the whole
Date: Tue, 21 Feb 2012 21:24:52 +0700 [thread overview]
Message-ID: <1329834292-2511-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1329834292-2511-1-git-send-email-pclouds@gmail.com>
Commit object has its own format, which happens to be in ascii, but
not really subject to re-encoding.
There are only four areas that may be re-encoded: author line,
committer line, mergetag lines and commit body. Encoding of tags
embedded in mergetag lines is not decided by commit encoding, so leave
it out and consider it binary.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
pretty.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 57 insertions(+), 1 deletions(-)
diff --git a/pretty.c b/pretty.c
index 5c433a2..6ccc091 100644
--- a/pretty.c
+++ b/pretty.c
@@ -489,6 +489,62 @@ static char *replace_encoding_header(char *buf, const char *encoding)
return strbuf_detach(&tmp, NULL);
}
+/*
+ * Re-encode author, committer and commit body only, leaving the rest
+ * in ascii (or whatever the encoding it is in mergetag lines)
+ * regardless output encoding. We assume the commit is good, so no
+ * validation.
+ */
+static char *reencode_commit(const char *buffer,
+ const char *out_enc, const char *in_enc)
+{
+ struct strbuf out = STRBUF_INIT;
+ struct strbuf buf = STRBUF_INIT;
+ char *reencoded, *s, *e;
+
+ strbuf_addstr(&buf, buffer);
+
+ s = strstr(buf.buf, "\nauthor ");
+ assert(s != NULL);
+ s += 8; /* "\nauthor " */
+ strbuf_add(&out, buf.buf, s - buf.buf);
+ e = strchr(s, '\n');
+ *e = '\0';
+ reencoded = reencode_string(s, out_enc, in_enc);
+ if (reencoded && strchr(reencoded, '\n'))
+ die("your chosen encoding produces \\n out of nowhere?");
+ strbuf_addstr(&out, reencoded ? reencoded : s);
+ free(reencoded);
+
+ strbuf_addstr(&out, "\ncommitter ");
+ assert(!strncmp(e + 1, "committer ", 10));
+ s = e + 11; /* "\ncommitter " */
+ e = strchr(s, '\n');
+ *e = '\0';
+ reencoded = reencode_string(s, out_enc, in_enc);
+ if (reencoded && strchr(reencoded, '\n'))
+ die("your chosen encoding produces \\n out of nowhere?");
+ strbuf_addstr(&out, reencoded ? reencoded : s);
+ free(reencoded);
+ *e = '\n';
+
+ s = e;
+ e = strstr(s, "\n\n");
+ if (e) {
+ e += 2; /* "\n\n" */
+ strbuf_add(&out, s, e - s);
+
+ s = e;
+ reencoded = reencode_string(s, out_enc, in_enc);
+ strbuf_addstr(&out, reencoded ? reencoded : s);
+ free(reencoded);
+ } else
+ strbuf_addstr(&out, s);
+
+ strbuf_release(&buf);
+ return strbuf_detach(&out, NULL);
+}
+
char *logmsg_reencode(const struct commit *commit,
const char *output_encoding)
{
@@ -514,7 +570,7 @@ char *logmsg_reencode(const struct commit *commit,
else
return NULL; /* nothing to do */
else
- out = reencode_string(commit->buffer,
+ out = reencode_commit(commit->buffer,
output_encoding, use_encoding);
if (out)
out = replace_encoding_header(out, output_encoding);
--
1.7.8.36.g69ee2
next prev parent reply other threads:[~2012-02-21 14:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-21 14:24 [PATCH 1/4] t3900: add missing UTF-16.txt and mark the test successful Nguyễn Thái Ngọc Duy
2012-02-21 14:24 ` [PATCH 2/4] Do attempt pretty print in ASCII-incompatible encodings Nguyễn Thái Ngọc Duy
2012-02-21 14:53 ` Nguyen Thai Ngoc Duy
2012-02-21 18:21 ` Jeff King
2012-02-22 2:17 ` Nguyen Thai Ngoc Duy
2012-02-23 11:25 ` Peter Krefting
2012-02-21 14:24 ` [PATCH 3/4] utf8: die if failed to re-encoding Nguyễn Thái Ngọc Duy
2012-02-21 17:36 ` Junio C Hamano
2012-02-21 14:24 ` Nguyễn Thái Ngọc Duy [this message]
2012-02-21 18:25 ` [PATCH 4/4] Only re-encode certain parts in commit object, not the whole Jeff King
2012-02-22 2:01 ` Nguyen Thai Ngoc Duy
2012-02-22 3:14 ` Junio C Hamano
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=1329834292-2511-4-git-send-email-pclouds@gmail.com \
--to=pclouds@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).