{"thread":{"id":"24128","subject":"[PATCH v3 1/2] add --recode-patch option to git-mailinfo","startedAt":"2010-06-16T05:09:42Z","lastAt":"2010-06-17T01:39:18Z","messageCount":4,"participants":["Zhang Le","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":2},"messages":[{"id":"143806","messageId":"1276664983-5693-1-git-send-email-r0bertz@gentoo.org","threadId":"24128","inReplyTo":null,"subject":"[PATCH v3 1/2] add --recode-patch option to git-mailinfo","fromName":"Zhang Le","fromEmail":"r0bertz@gentoo.org","sentAt":"2010-06-16T05:09:42Z","receivedAt":"2010-06-16T05:09:42Z","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 inconvenience for\nour project.\n\nSince we have 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\nChangelog:\n\nv2 -> v3:\nRemoved 'const' type qualifier from handle_patch()'s parameter\nFixed typos in commit msg\n\nv1 -> v2:\nClarified how -u/--encoding is handled in git-mailinfo's documentation\n\nSigned-off-by: Zhang Le <r0bertz@gentoo.org>\n---\n Documentation/git-mailinfo.txt |    6 +++++-\n builtin/mailinfo.c             |   10 ++++++++--\n 2 files changed, 13 insertions(+), 3 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..bb87b32 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@@ -828,8 +829,10 @@ static int handle_commit_msg(struct strbuf *line)\n \treturn 0;\n }\n \n-static void handle_patch(const struct strbuf *line)\n+static void handle_patch(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":"143807","messageId":"1276664983-5693-2-git-send-email-r0bertz@gentoo.org","threadId":"24128","inReplyTo":"1276664983-5693-1-git-send-email-r0bertz@gentoo.org","subject":"[PATCH v3 2/2] add --recode-patch option to git-am","fromName":"Zhang Le","fromEmail":"r0bertz@gentoo.org","sentAt":"2010-06-16T05:09:43Z","receivedAt":"2010-06-16T05:09:43Z","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 87ffae2..49cf788 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":"143831","messageId":"7vhbl2eq1g.fsf@alter.siamese.dyndns.org","threadId":"24128","inReplyTo":"1276664983-5693-1-git-send-email-r0bertz@gentoo.org","subject":"Re: [PATCH v3 1/2] add --recode-patch option to git-mailinfo","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-06-16T19:27:39Z","receivedAt":"2010-06-16T19:27:39Z","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/Documentation/git-mailinfo.txt b/Documentation/git-mailinfo.txt\n> index 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\nSomehow this doesn't rhyme well.  Perhaps\n\n    Note that the patch is used as-with without charset conversion; use\n    `--recode-patch` for that.\n\nwould be better?\n\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\nDitto.\n\n\tConvert the patch from the e-mail to UTF-8 (or the value of the\n\tconfiguration variable `i18n.commitencoding`, if it is set).\n\nBy the way, what happens when somebody runs the following command?\n\n\tgit mailinfo -n --recode-patch\n\nIs it desirable?  If not, what _should_ happen instead?\n\n> diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c\n> index 4a9729b..bb87b32 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> @@ -828,8 +829,10 @@ static int handle_commit_msg(struct strbuf *line)\n>  \treturn 0;\n>  }\n>  \n> -static void handle_patch(const struct strbuf *line)\n> +static void handle_patch(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\nDo you need this assignment?\n"},{"id":"143841","messageId":"20100617013915.GA20339@adriano","threadId":"24128","inReplyTo":"7vhbl2eq1g.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v3 1/2] add --recode-patch option to git-mailinfo","fromName":"Zhang Le","fromEmail":"r0bertz@gentoo.org","sentAt":"2010-06-17T01:39:18Z","receivedAt":"2010-06-17T01:39:18Z","isPatch":true,"sender":{"key":"r0bertz@gentoo.org","avatar":"https://avatars.githubusercontent.com/u/29025?v=4"},"body":"On 12:27 Wed 16 Jun     , Junio C Hamano wrote:\n> Zhang Le <r0bertz@gentoo.org> writes:\n> \n> > diff --git a/Documentation/git-mailinfo.txt b/Documentation/git-mailinfo.txt\n> > index 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> Somehow this doesn't rhyme well.  Perhaps\n> \n>     Note that the patch is used as-with without charset conversion; use\n>     `--recode-patch` for that.\n> \n> would be better?\n\nOK\n\n> \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> Ditto.\n> \n> \tConvert the patch from the e-mail to UTF-8 (or the value of the\n> \tconfiguration variable `i18n.commitencoding`, if it is set).\n> \n\nOK\n\n> By the way, what happens when somebody runs the following command?\n> \n> \tgit mailinfo -n --recode-patch\n> \n> Is it desirable?  If not, what _should_ happen instead?\n\nThis is not desirable. If -n is used, no recoding will happen.\nMaybe we should warn users.\nMaybe we use a separate variable like patch_charset, instead of reusing\nmetainfo_charset?\n\n> \n> > diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c\n> > index 4a9729b..bb87b32 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> > @@ -828,8 +829,10 @@ static int handle_commit_msg(struct strbuf *line)\n> >  \treturn 0;\n> >  }\n> >  \n> > -static void handle_patch(const struct strbuf *line)\n> > +static void handle_patch(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> Do you need this assignment?\n\nOf course, It is not required. Since variable in bss secton will be initialized\nto 0. I just thought maybe it is better to initialized it explicitly, to make\nit clear. Of course, this is only personal taste.\n\nI will remove it, if that will suit git's coding style 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"}]}