{"thread":{"id":"24100","subject":"[PATCH v2 1/2] add --recode-patch option to git-mailinfo","startedAt":"2010-06-13T18:50:39Z","lastAt":"2010-06-14T05:49:41Z","messageCount":4,"participants":["Zhang Le","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"143619","messageId":"1276455040-14726-1-git-send-email-r0bertz@gentoo.org","threadId":"24100","inReplyTo":null,"subject":"[PATCH v2 1/2] add --recode-patch option to git-mailinfo","fromName":"Zhang Le","fromEmail":"r0bertz@gentoo.org","sentAt":"2010-06-13T18:50:39Z","receivedAt":"2010-06-13T18:50:39Z","isPatch":true,"sender":{"key":"r0bertz@gentoo.org","avatar":"https://avatars.githubusercontent.com/u/29025?v=4"},"body":"I have a translation project which uses UTF-8 as charset.\nSo the patch must be encoded in UTF-8, not just the commit msg etc.\nAnd we use google group as our mailing list.\n\nRecently, mails saved from gmail are encoded using local charset based on\ngoogle group's setting. This seems smart but it caused inconvinience for\nour project.\n\nSince we can't no control on what google will do, so I took another way,\ni.e. add this option to git-mailinfo. I hope this could benefit others as\nwell.\n\nSigned-off-by: Zhang Le <r0bertz@gentoo.org>\n---\n Documentation/git-mailinfo.txt |    6 +++++-\n builtin/mailinfo.c             |    8 +++++++-\n 2 files changed, 12 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-mailinfo.txt b/Documentation/git-mailinfo.txt\nindex 3ea5aad..24d5bd7 100644\n--- a/Documentation/git-mailinfo.txt\n+++ b/Documentation/git-mailinfo.txt\n@@ -45,7 +45,7 @@ OPTIONS\n \tthem.  This used to be optional but now it is the default.\n +\n Note that the patch is always used as-is without charset\n-conversion, even with this flag.\n+conversion, even with this flag.  Unless --recode-patch is used.\n \n --encoding=<encoding>::\n \tSimilar to -u.  But when re-coding, the charset specified here is\n@@ -54,6 +54,10 @@ conversion, even with this flag.\n -n::\n \tDisable all charset re-coding of the metadata.\n \n+--recode-patch::\n+\tSimilar to -u.  But what is re-coded is the patch instead of the\n+\tmetainfo.  The default is off.\n+\n --scissors::\n \tRemove everything in body before a scissors line.  A line that\n \tmainly consists of scissors (either \">8\" or \"8<\") and perforation\ndiff --git a/builtin/mailinfo.c b/builtin/mailinfo.c\nindex 4a9729b..73f51f3 100644\n--- a/builtin/mailinfo.c\n+++ b/builtin/mailinfo.c\n@@ -12,6 +12,7 @@ static FILE *cmitmsg, *patchfile, *fin, *fout;\n static int keep_subject;\n static int keep_non_patch_brackets_in_subject;\n static const char *metainfo_charset;\n+static int recode_patch;\n static struct strbuf line = STRBUF_INIT;\n static struct strbuf name = STRBUF_INIT;\n static struct strbuf email = STRBUF_INIT;\n@@ -830,6 +831,8 @@ static int handle_commit_msg(struct strbuf *line)\n \n static void handle_patch(const struct strbuf *line)\n {\n+\tif (recode_patch)\n+\t\tconvert_to_utf8(line, charset.buf);\n \tfwrite(line->buf, 1, line->len, patchfile);\n \tpatch_lines++;\n }\n@@ -1021,7 +1024,7 @@ static int git_mailinfo_config(const char *var, const char *value, void *unused)\n }\n \n static const char mailinfo_usage[] =\n-\t\"git mailinfo [-k|-b] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] msg patch < mail >info\";\n+\t\"git mailinfo [-k|-b] [-u | --encoding=<encoding> | -n] [--recode-patch] [--scissors | --no-scissors] msg patch < mail >info\";\n \n int cmd_mailinfo(int argc, const char **argv, const char *prefix)\n {\n@@ -1034,6 +1037,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)\n \n \tdef_charset = (git_commit_encoding ? git_commit_encoding : \"UTF-8\");\n \tmetainfo_charset = def_charset;\n+\trecode_patch = 0;\n \n \twhile (1 < argc && argv[1][0] == '-') {\n \t\tif (!strcmp(argv[1], \"-k\"))\n@@ -1046,6 +1050,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)\n \t\t\tmetainfo_charset = NULL;\n \t\telse if (!prefixcmp(argv[1], \"--encoding=\"))\n \t\t\tmetainfo_charset = argv[1] + 11;\n+\t\telse if (!strcmp(argv[1], \"--recode-patch\"))\n+\t\t\trecode_patch = 1;\n \t\telse if (!strcmp(argv[1], \"--scissors\"))\n \t\t\tuse_scissors = 1;\n \t\telse if (!strcmp(argv[1], \"--no-scissors\"))\n-- \n1.7.1\n"},{"id":"143620","messageId":"1276455040-14726-2-git-send-email-r0bertz@gentoo.org","threadId":"24100","inReplyTo":"1276455040-14726-1-git-send-email-r0bertz@gentoo.org","subject":"[PATCH v2 2/2] add --recode-patch option to git-am","fromName":"Zhang Le","fromEmail":"r0bertz@gentoo.org","sentAt":"2010-06-13T18:50:40Z","receivedAt":"2010-06-13T18:50:40Z","isPatch":true,"sender":{"key":"r0bertz@gentoo.org","avatar":"https://avatars.githubusercontent.com/u/29025?v=4"},"body":"The reason has been explained in the \"add --recode-patch to git-mailinfo\" patch\n\nSigned-off-by: Zhang Le <r0bertz@gentoo.org>\n---\n Documentation/git-am.txt |    4 ++++\n git-am.sh                |   13 +++++++++++--\n 2 files changed, 15 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-am.txt b/Documentation/git-am.txt\nindex 9e62f87..38c1442 100644\n--- a/Documentation/git-am.txt\n+++ b/Documentation/git-am.txt\n@@ -73,6 +73,10 @@ default.   You can use `--no-utf8` to override this.\n \tPass `-n` flag to 'git mailinfo' (see\n \tlinkgit:git-mailinfo[1]).\n \n+--recode-patch::\n+\tPass `--recode-patch` flag to 'git mailinfo' (see\n+\tlinkgit:git-mailinfo[1]).\n+\n -3::\n --3way::\n \tWhen the patch does not apply cleanly, fall back on\ndiff --git a/git-am.sh b/git-am.sh\nindex 1056075..62e7870 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -14,6 +14,7 @@ b,binary*       (historical option -- no-op)\n q,quiet         be quiet\n s,signoff       add a Signed-off-by line to the commit message\n u,utf8          recode into utf8 (default)\n+recode-patch    pass --recode-patch flag to git-mailinfo\n k,keep          pass -k flag to git-mailinfo\n keep-cr         pass --keep-cr flag to git-mailsplit for mbox format\n no-keep-cr      do not pass --keep-cr flag to git-mailsplit independent of am.keepcr\n@@ -294,7 +295,7 @@ split_patches () {\n prec=4\n dotest=\"$GIT_DIR/rebase-apply\"\n sign= utf8=t keep= keepcr= skip= interactive= resolved= rebasing= abort=\n-resolvemsg= resume= scissors= no_inbody_headers=\n+resolvemsg= resume= scissors= no_inbody_headers= recode_patch=\n git_apply_opt=\n committer_date_is_author_date=\n ignore_date=\n@@ -320,6 +321,8 @@ do\n \t\tutf8=t ;; # this is now default\n \t--no-utf8)\n \t\tutf8= ;;\n+\t--recode-patch)\n+\t\trecode_patch=t ;;\n \t-k|--keep)\n \t\tkeep=t ;;\n \t-c|--scissors)\n@@ -463,6 +466,7 @@ else\n \techo \"$threeway\" >\"$dotest/threeway\"\n \techo \"$sign\" >\"$dotest/sign\"\n \techo \"$utf8\" >\"$dotest/utf8\"\n+\techo \"$recode_patch\" >\"$dotest/recode_patch\"\n \techo \"$keep\" >\"$dotest/keep\"\n \techo \"$keepcr\" >\"$dotest/keepcr\"\n \techo \"$scissors\" >\"$dotest/scissors\"\n@@ -504,6 +508,10 @@ then\n else\n \tutf8=-n\n fi\n+if test \"$(cat \"$dotest/recode_patch\")\" = t\n+then\n+\trecodepatch=--recode-patch\n+fi\n if test \"$(cat \"$dotest/keep\")\" = t\n then\n \tkeep=-k\n@@ -580,7 +588,8 @@ do\n \t# by the user, or the user can tell us to do so by --resolved flag.\n \tcase \"$resume\" in\n \t'')\n-\t\tgit mailinfo $keep $no_inbody_headers $scissors $utf8 \"$dotest/msg\" \"$dotest/patch\" \\\n+\t\tgit mailinfo $keep $no_inbody_headers $scissors $utf8 \\\n+\t\t$recodepatch \"$dotest/msg\" \"$dotest/patch\" \\\n \t\t\t<\"$dotest/$msgnum\" >\"$dotest/info\" ||\n \t\t\tstop_here $this\n \n-- \n1.7.1\n"},{"id":"143635","messageId":"7vvd9mb2kc.fsf@alter.siamese.dyndns.org","threadId":"24100","inReplyTo":"1276455040-14726-1-git-send-email-r0bertz@gentoo.org","subject":"Re: [PATCH v2 1/2] add --recode-patch option to git-mailinfo","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-06-14T05:33:55Z","receivedAt":"2010-06-14T05:33:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Zhang Le <r0bertz@gentoo.org> writes:\n\n> diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c\n> index 4a9729b..73f51f3 100644\n> --- a/builtin/mailinfo.c\n> +++ b/builtin/mailinfo.c\n> @@ -830,6 +831,8 @@ static int handle_commit_msg(struct strbuf *line)\n>  \n>  static void handle_patch(const struct strbuf *line)\n>  {\n> +\tif (recode_patch)\n> +\t\tconvert_to_utf8(line, charset.buf);\n\nbuiltin/mailinfo.c: In function 'handle_patch':\nbuiltin/mailinfo.c:835: error: passing argument 1 of 'convert_to_utf8' discards qualifiers from pointer target type\n\nI do not think there is a reason for \"line\" to be const anymore; it used\nto make sense back when handle_patch() was only about writing the patch\nout, but that no longer is the case.\n"},{"id":"143636","messageId":"20100614054941.GA28218@adriano","threadId":"24100","inReplyTo":"7vvd9mb2kc.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2 1/2] add --recode-patch option to git-mailinfo","fromName":"Zhang Le","fromEmail":"r0bertz@gentoo.org","sentAt":"2010-06-14T05:49:41Z","receivedAt":"2010-06-14T05:49:41Z","isPatch":true,"sender":{"key":"r0bertz@gentoo.org","avatar":"https://avatars.githubusercontent.com/u/29025?v=4"},"body":"On 22:33 Sun 13 Jun     , Junio C Hamano wrote:\n> Zhang Le <r0bertz@gentoo.org> writes:\n> \n> > diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c\n> > index 4a9729b..73f51f3 100644\n> > --- a/builtin/mailinfo.c\n> > +++ b/builtin/mailinfo.c\n> > @@ -830,6 +831,8 @@ static int handle_commit_msg(struct strbuf *line)\n> >  \n> >  static void handle_patch(const struct strbuf *line)\n> >  {\n> > +\tif (recode_patch)\n> > +\t\tconvert_to_utf8(line, charset.buf);\n> \n> builtin/mailinfo.c: In function 'handle_patch':\n> builtin/mailinfo.c:835: error: passing argument 1 of 'convert_to_utf8' discards qualifiers from pointer target type\n> \n> I do not think there is a reason for \"line\" to be const anymore; it used\n> to make sense back when handle_patch() was only about writing the patch\n> out, but that no longer is the case.\n\nSo you have used -Werror, right?\nBecause my gcc (4.4.3) only shows a warning.\n\nWill fix it.\n\nMy gcc also shows another warning:\nbuiltin/mailinfo.c:836: warning: ignoring return value of 'fwrite', declared\nwith attribute warn_unused_result\n\nDoes it occur to you as well?\n\n-- \nZhang, Le\nGentoo/Loongson Developer\nhttp://zhangle.is-a-geek.org\n0260 C902 B8F8 6506 6586 2B90 BC51 C808 1E4E 2973\n"}]}