[PATCH 1/2] [RFC] add --recode-patch option to git-mailinfo

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a translation project which uses UTF-8 as charset.
So the patch must be encoded in UTF-8, not just the commit msg etc.
And we use google group as our mailing list.

Recently, due to unknown reason, mails saved from gmail are encoded using GB2312.
This never happened before. I guess google has did something.
But I haven't found how to change this behavior.

So I took another way, i.e. add this option to git-mailinfo.
I hope this could benefit others as well.

Signed-off-by: Zhang Le <r0bertz@xxxxxxxxxx>
---
 builtin/mailinfo.c  |    8 +++++++-
 man1/git-mailinfo.1 |    7 ++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
index 4a9729b..73f51f3 100644
--- a/builtin/mailinfo.c
+++ b/builtin/mailinfo.c
@@ -12,6 +12,7 @@ static FILE *cmitmsg, *patchfile, *fin, *fout;
 static int keep_subject;
 static int keep_non_patch_brackets_in_subject;
 static const char *metainfo_charset;
+static int recode_patch;
 static struct strbuf line = STRBUF_INIT;
 static struct strbuf name = STRBUF_INIT;
 static struct strbuf email = STRBUF_INIT;
@@ -830,6 +831,8 @@ static int handle_commit_msg(struct strbuf *line)
 
 static void handle_patch(const struct strbuf *line)
 {
+	if (recode_patch)
+		convert_to_utf8(line, charset.buf);
 	fwrite(line->buf, 1, line->len, patchfile);
 	patch_lines++;
 }
@@ -1021,7 +1024,7 @@ static int git_mailinfo_config(const char *var, const char *value, void *unused)
 }
 
 static const char mailinfo_usage[] =
-	"git mailinfo [-k|-b] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] msg patch < mail >info";
+	"git mailinfo [-k|-b] [-u | --encoding=<encoding> | -n] [--recode-patch] [--scissors | --no-scissors] msg patch < mail >info";
 
 int cmd_mailinfo(int argc, const char **argv, const char *prefix)
 {
@@ -1034,6 +1037,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
 
 	def_charset = (git_commit_encoding ? git_commit_encoding : "UTF-8");
 	metainfo_charset = def_charset;
+	recode_patch = 0;
 
 	while (1 < argc && argv[1][0] == '-') {
 		if (!strcmp(argv[1], "-k"))
@@ -1046,6 +1050,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
 			metainfo_charset = NULL;
 		else if (!prefixcmp(argv[1], "--encoding="))
 			metainfo_charset = argv[1] + 11;
+		else if (!strcmp(argv[1], "--recode-patch"))
+			recode_patch = 1;
 		else if (!strcmp(argv[1], "--scissors"))
 			use_scissors = 1;
 		else if (!strcmp(argv[1], "--no-scissors"))
diff --git a/man1/git-mailinfo.1 b/man1/git-mailinfo.1
index 4d0e929..d52457f 100644
--- a/man1/git-mailinfo.1
+++ b/man1/git-mailinfo.1
@@ -22,7 +22,7 @@
 git-mailinfo \- Extracts patch and authorship from a single e\-mail message
 .SH "SYNOPSIS"
 .sp
-\fIgit mailinfo\fR [\-k|\-b] [\-u | \-\-encoding=<encoding> | \-n] [\-\-scissors] <msg> <patch>
+\fIgit mailinfo\fR [\-k|\-b] [\-u | \-\-encoding=<encoding> | \-n] [\-\-recode\-patch] [\-\-scissors] <msg> <patch>
 .SH "DESCRIPTION"
 .sp
 Reads a single e\-mail message from the standard input, and writes the commit log message in <msg> file, and the patches in <patch> file\&. The author name, e\-mail and e\-mail subject are written out to the standard output to be used by \fIgit am\fR to create a commit\&. It is usually not necessary to use this command directly\&. See \fBgit-am\fR(1) instead\&.
@@ -70,6 +70,11 @@ Similar to \-u but if the local convention is different from what is specified b
 Disable all charset re\-coding of the metadata\&.
 .RE
 .PP
+\-\-recode\-patch
+.RS 4
+Re\-code patch as well, using the same encoding as metadata\&. The default is off\&.
+.RE
+.PP
 \-\-scissors
 .RS 4
 Remove everything in body before a scissors line\&. A line that mainly consists of scissors (either ">8" or "8<") and perforation (dash "\-") marks is called a scissors line, and is used to request the reader to cut the message at that line\&. If such a line appears in the body of the message before the patch, everything before it (including the scissors line itself) is ignored when this option is used\&.
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]