{"thread":{"id":"31723","subject":"[PATCH 2/2] git-send-email: use locale encoding for compose","startedAt":"2012-10-03T22:05:30Z","lastAt":"2012-10-09T23:02:56Z","messageCount":4,"participants":["Krzysztof Mazur","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"200476","messageId":"1349301931-11912-1-git-send-email-krzysiek@podlesie.net","threadId":"31723","inReplyTo":null,"subject":"[PATCH 1/2] git-send-email: introduce compose-encoding","fromName":"Krzysztof Mazur","fromEmail":"krzysiek@podlesie.net","sentAt":"2012-10-03T22:05:30Z","receivedAt":"2012-10-03T22:05:30Z","isPatch":true,"sender":{"key":"krzysiek@podlesie.net","avatar":null},"body":"The introduction email (--compose option) have encoding hardcoded to\nUTF-8, but invoked editor may not use UTF-8 encoding.\nThe encoding used by patches can be changed by the \"8bit-encoding\"\noption, but this option does not have effect on introduction email\nand equivalent for introduction email is missing.\n\nAdded compose-encoding command line option and sendemail.composeencoding\nconfiguration option specify encoding of introduction email.\n\nSigned-off-by: Krzysztof Mazur <krzysiek@podlesie.net>\n---\n Documentation/git-send-email.txt | 5 +++++\n git-send-email.perl              | 9 ++++++++-\n 2 files changed, 13 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt\nindex 3241170..9f09e92 100644\n--- a/Documentation/git-send-email.txt\n+++ b/Documentation/git-send-email.txt\n@@ -126,6 +126,11 @@ The --to option must be repeated for each user you want on the to list.\n +\n Note that no attempts whatsoever are made to validate the encoding.\n \n+--compose-encoding=<encoding>::\n+\tSpecify encoding of compose message. Default is the value of the\n+\t'sendemail.composeencoding'; if that is unspecified, UTF-8 is assumed.\n++\n+\n \n Sending\n ~~~~~~~\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex aea66a0..107e814 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -56,6 +56,7 @@ git send-email [options] <file | directory | rev-list options >\n     --in-reply-to           <str>  * Email \"In-Reply-To:\"\n     --annotate                     * Review each patch that will be sent in an editor.\n     --compose                      * Open an editor for introduction.\n+    --compose-encoding      <str>  * Encoding to assume for introduction.\n     --8bit-encoding         <str>  * Encoding to assume 8bit mails if undeclared\n \n   Sending:\n@@ -198,6 +199,7 @@ my ($identity, $aliasfiletype, @alias_files, $smtp_domain);\n my ($validate, $confirm);\n my (@suppress_cc);\n my ($auto_8bit_encoding);\n+my ($compose_encoding);\n \n my ($debug_net_smtp) = 0;\t\t# Net::SMTP, see send_message()\n \n@@ -231,6 +233,7 @@ my %config_settings = (\n     \"confirm\"   => \\$confirm,\n     \"from\" => \\$sender,\n     \"assume8bitencoding\" => \\$auto_8bit_encoding,\n+    \"composeencoding\" => \\$compose_encoding,\n );\n \n my %config_path_settings = (\n@@ -315,6 +318,7 @@ my $rc = GetOptions(\"h\" => \\$help,\n \t\t    \"validate!\" => \\$validate,\n \t\t    \"format-patch!\" => \\$format_patch,\n \t\t    \"8bit-encoding=s\" => \\$auto_8bit_encoding,\n+\t\t    \"compose-encoding=s\" => \\$compose_encoding,\n \t\t    \"force\" => \\$force,\n \t );\n \n@@ -638,10 +642,13 @@ EOT\n \t\t\t$summary_empty = 0 unless (/^\\n$/);\n \t\t} elsif (/^\\n$/) {\n \t\t\t$in_body = 1;\n+\t\t\tif (!defined $compose_encoding) {\n+\t\t\t\t$compose_encoding = \"UTF-8\";\n+\t\t\t}\n \t\t\tif ($need_8bit_cte) {\n \t\t\t\tprint $c2 \"MIME-Version: 1.0\\n\",\n \t\t\t\t\t \"Content-Type: text/plain; \",\n-\t\t\t\t\t   \"charset=UTF-8\\n\",\n+\t\t\t\t\t   \"charset=$compose_encoding\\n\",\n \t\t\t\t\t \"Content-Transfer-Encoding: 8bit\\n\";\n \t\t\t}\n \t\t} elsif (/^MIME-Version:/i) {\n-- \n1.7.12.2.2.g1c3c581\n"},{"id":"200470","messageId":"1349301931-11912-2-git-send-email-krzysiek@podlesie.net","threadId":"31723","inReplyTo":"1349301931-11912-1-git-send-email-krzysiek@podlesie.net","subject":"[PATCH 2/2] git-send-email: use locale encoding for compose","fromName":"Krzysztof Mazur","fromEmail":"krzysiek@podlesie.net","sentAt":"2012-10-03T22:05:31Z","receivedAt":"2012-10-03T22:05:31Z","isPatch":true,"sender":{"key":"krzysiek@podlesie.net","avatar":null},"body":"The introduction email (--compose option) use UTF-8 as default encoding.\nThe current locale encoding is much better default value.\n\nSigned-off-by: Krzysztof Mazur <krzysiek@podlesie.net>\n---\n git-send-email.perl | 12 +++++++++++-\n 1 file changed, 11 insertions(+), 1 deletion(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 107e814..139bb35 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -590,6 +590,16 @@ sub get_patch_subject {\n \tdie \"No subject line in $fn ?\";\n }\n \n+sub locale_encoding {\n+\tmy $encoding = \"UTF-8\";\n+\teval {\n+\t\trequire I18N::Langinfo;\n+\t\tI18N::Langinfo->import(qw(langinfo CODESET));\n+\t\t$encoding = langinfo(CODESET());\n+\t};\n+\treturn $encoding;\n+}\n+\n if ($compose) {\n \t# Note that this does not need to be secure, but we will make a small\n \t# effort to have it be unique\n@@ -643,7 +653,7 @@ EOT\n \t\t} elsif (/^\\n$/) {\n \t\t\t$in_body = 1;\n \t\t\tif (!defined $compose_encoding) {\n-\t\t\t\t$compose_encoding = \"UTF-8\";\n+\t\t\t\t$compose_encoding = locale_encoding();\n \t\t\t}\n \t\t\tif ($need_8bit_cte) {\n \t\t\t\tprint $c2 \"MIME-Version: 1.0\\n\",\n-- \n1.7.12.2.2.g1c3c581\n"},{"id":"200863","messageId":"7vehl7e3cs.fsf@alter.siamese.dyndns.org","threadId":"31723","inReplyTo":"1349301931-11912-2-git-send-email-krzysiek@podlesie.net","subject":"Re: [PATCH 2/2] git-send-email: use locale encoding for compose","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-10-09T21:34:59Z","receivedAt":"2012-10-09T21:34:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Krzysztof Mazur <krzysiek@podlesie.net> writes:\n\n> The introduction email (--compose option) use UTF-8 as default encoding.\n> The current locale encoding is much better default value.\n>\n> Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net>\n> ---\n>  git-send-email.perl | 12 +++++++++++-\n>  1 file changed, 11 insertions(+), 1 deletion(-)\n>\n> diff --git a/git-send-email.perl b/git-send-email.perl\n> index 107e814..139bb35 100755\n> --- a/git-send-email.perl\n> +++ b/git-send-email.perl\n> @@ -590,6 +590,16 @@ sub get_patch_subject {\n>  \tdie \"No subject line in $fn ?\";\n>  }\n>  \n> +sub locale_encoding {\n> +\tmy $encoding = \"UTF-8\";\n> +\teval {\n> +\t\trequire I18N::Langinfo;\n> +\t\tI18N::Langinfo->import(qw(langinfo CODESET));\n> +\t\t$encoding = langinfo(CODESET());\n> +\t};\n> +\treturn $encoding;\n> +}\n> +\n>  if ($compose) {\n>  \t# Note that this does not need to be secure, but we will make a small\n>  \t# effort to have it be unique\n> @@ -643,7 +653,7 @@ EOT\n>  \t\t} elsif (/^\\n$/) {\n>  \t\t\t$in_body = 1;\n>  \t\t\tif (!defined $compose_encoding) {\n> -\t\t\t\t$compose_encoding = \"UTF-8\";\n> +\t\t\t\t$compose_encoding = locale_encoding();\n>  \t\t\t}\n>  \t\t\tif ($need_8bit_cte) {\n>  \t\t\t\tprint $c2 \"MIME-Version: 1.0\\n\",\n\nThese two patches make sense in general, but t9001.62 (--compose\nadds MIME for utf8 body) seems to be broken by it.  I didn't check\nto see if the code is broken, or the test has expecting a wrong\nbehaviour.  If the latter, the test needs to be updated to match the\nimproved new world order.\n\nThanks.\n"},{"id":"200866","messageId":"20121009230256.GA22477@shrek.podlesie.net","threadId":"31723","inReplyTo":"7vehl7e3cs.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 2/2] git-send-email: use locale encoding for compose","fromName":"Krzysztof Mazur","fromEmail":"krzysiek@podlesie.net","sentAt":"2012-10-09T23:02:56Z","receivedAt":"2012-10-09T23:02:56Z","isPatch":true,"sender":{"key":"krzysiek@podlesie.net","avatar":null},"body":"On Tue, Oct 09, 2012 at 02:34:59PM -0700, Junio C Hamano wrote:\n> Krzysztof Mazur <krzysiek@podlesie.net> writes:\n> \n> > The introduction email (--compose option) use UTF-8 as default encoding.\n> > The current locale encoding is much better default value.\n> >\n> \n> These two patches make sense in general, but t9001.62 (--compose\n> adds MIME for utf8 body) seems to be broken by it.  I didn't check\n> to see if the code is broken, or the test has expecting a wrong\n> behaviour.  If the latter, the test needs to be updated to match the\n> improved new world order.\n> \n> Thanks.\n\nThe second patch was broken - for C locale the ANSI_X3.4-1968 codeset\nwas used, which is insane because git-send-email adds Content-Type\nonly when non-ASCII characters were found. I think this can be fixed\nby just using UTF-8 if langinfo returns ANSI_X3.4-1968.\n\nHowever I think that that patch should be dropped for now, because also\nother git commands like \"git commit\" don't use codeset from locale.\nThe git commit just detects invalid UTF-8 characters and prints hint\nfor user to set i18n.commitencoding. If you like the idea of using codeset\nfrom locale I can send fixed patch and also change \"git commit\".\n\nFor now I think it's better to just take only the first patch.\n\nI'm resending the first patch with added tests.\n\nThanks,\nChris\n--- \nFrom 0d1fccc5e70367f3eeb2372b8fc24401bf88d748 Mon Sep 17 00:00:00 2001\nFrom: Krzysztof Mazur <krzysiek@podlesie.net>\nDate: Wed, 10 Oct 2012 00:17:29 +0200\nSubject: [PATCH] git-send-email: introduce compose-encoding\n\nThe introduction email (--compose option) have encoding hardcoded to\nUTF-8, but invoked editor may not use UTF-8 encoding.\nThe encoding used by patches can be changed by the \"8bit-encoding\"\noption, but this option does not have effect on introduction email\nand equivalent for introduction email is missing.\n\nAdded compose-encoding command line option and sendemail.composeencoding\nconfiguration option specify encoding of introduction email.\n\nSigned-off-by: Krzysztof Mazur <krzysiek@podlesie.net>\n---\n Documentation/git-send-email.txt |  5 ++++\n git-send-email.perl              |  9 ++++++-\n t/t9001-send-email.sh            | 55 ++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 68 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt\nindex 3241170..9f09e92 100644\n--- a/Documentation/git-send-email.txt\n+++ b/Documentation/git-send-email.txt\n@@ -126,6 +126,11 @@ The --to option must be repeated for each user you want on the to list.\n +\n Note that no attempts whatsoever are made to validate the encoding.\n \n+--compose-encoding=<encoding>::\n+\tSpecify encoding of compose message. Default is the value of the\n+\t'sendemail.composeencoding'; if that is unspecified, UTF-8 is assumed.\n++\n+\n \n Sending\n ~~~~~~~\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex aea66a0..107e814 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -56,6 +56,7 @@ git send-email [options] <file | directory | rev-list options >\n     --in-reply-to           <str>  * Email \"In-Reply-To:\"\n     --annotate                     * Review each patch that will be sent in an editor.\n     --compose                      * Open an editor for introduction.\n+    --compose-encoding      <str>  * Encoding to assume for introduction.\n     --8bit-encoding         <str>  * Encoding to assume 8bit mails if undeclared\n \n   Sending:\n@@ -198,6 +199,7 @@ my ($identity, $aliasfiletype, @alias_files, $smtp_domain);\n my ($validate, $confirm);\n my (@suppress_cc);\n my ($auto_8bit_encoding);\n+my ($compose_encoding);\n \n my ($debug_net_smtp) = 0;\t\t# Net::SMTP, see send_message()\n \n@@ -231,6 +233,7 @@ my %config_settings = (\n     \"confirm\"   => \\$confirm,\n     \"from\" => \\$sender,\n     \"assume8bitencoding\" => \\$auto_8bit_encoding,\n+    \"composeencoding\" => \\$compose_encoding,\n );\n \n my %config_path_settings = (\n@@ -315,6 +318,7 @@ my $rc = GetOptions(\"h\" => \\$help,\n \t\t    \"validate!\" => \\$validate,\n \t\t    \"format-patch!\" => \\$format_patch,\n \t\t    \"8bit-encoding=s\" => \\$auto_8bit_encoding,\n+\t\t    \"compose-encoding=s\" => \\$compose_encoding,\n \t\t    \"force\" => \\$force,\n \t );\n \n@@ -638,10 +642,13 @@ EOT\n \t\t\t$summary_empty = 0 unless (/^\\n$/);\n \t\t} elsif (/^\\n$/) {\n \t\t\t$in_body = 1;\n+\t\t\tif (!defined $compose_encoding) {\n+\t\t\t\t$compose_encoding = \"UTF-8\";\n+\t\t\t}\n \t\t\tif ($need_8bit_cte) {\n \t\t\t\tprint $c2 \"MIME-Version: 1.0\\n\",\n \t\t\t\t\t \"Content-Type: text/plain; \",\n-\t\t\t\t\t   \"charset=UTF-8\\n\",\n+\t\t\t\t\t   \"charset=$compose_encoding\\n\",\n \t\t\t\t\t \"Content-Transfer-Encoding: 8bit\\n\";\n \t\t\t}\n \t\t} elsif (/^MIME-Version:/i) {\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex 0351228..265ae04 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -854,6 +854,61 @@ test_expect_success $PREREQ 'utf8 author is correctly passed on' '\n \tgrep \"^From: FĂźĂąnĂ˝ NĂ˘mĂŠ <odd_?=mail@example.com>\" msgtxt1\n '\n \n+test_expect_success $PREREQ 'sendemail.composeencoding works' '\n+\tclean_fake_sendmail &&\n+\tgit config sendemail.composeencoding iso-8859-1 &&\n+\t(echo \"#!$SHELL_PATH\" &&\n+\t echo \"echo utf8 body: Ă ĂŠĂŹĂśĂş >>\\\"\\$1\\\"\"\n+\t) >fake-editor-utf8 &&\n+\tchmod +x fake-editor-utf8 &&\n+\t  GIT_EDITOR=\"\\\"$(pwd)/fake-editor-utf8\\\"\" \\\n+\t  git send-email \\\n+\t  --compose --subject foo \\\n+\t  --from=\"Example <nobody@example.com>\" \\\n+\t  --to=nobody@example.com \\\n+\t  --smtp-server=\"$(pwd)/fake.sendmail\" \\\n+\t  $patches &&\n+\tgrep \"^utf8 body\" msgtxt1 &&\n+\tgrep \"^Content-Type: text/plain; charset=iso-8859-1\" msgtxt1\n+'\n+\n+test_expect_success $PREREQ '--compose-encoding works' '\n+\tclean_fake_sendmail &&\n+\t(echo \"#!$SHELL_PATH\" &&\n+\t echo \"echo utf8 body: Ă ĂŠĂŹĂśĂş >>\\\"\\$1\\\"\"\n+\t) >fake-editor-utf8 &&\n+\tchmod +x fake-editor-utf8 &&\n+\t  GIT_EDITOR=\"\\\"$(pwd)/fake-editor-utf8\\\"\" \\\n+\t  git send-email \\\n+\t  --compose-encoding iso-8859-1 \\\n+\t  --compose --subject foo \\\n+\t  --from=\"Example <nobody@example.com>\" \\\n+\t  --to=nobody@example.com \\\n+\t  --smtp-server=\"$(pwd)/fake.sendmail\" \\\n+\t  $patches &&\n+\tgrep \"^utf8 body\" msgtxt1 &&\n+\tgrep \"^Content-Type: text/plain; charset=iso-8859-1\" msgtxt1\n+'\n+\n+test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '\n+\tclean_fake_sendmail &&\n+\tgit config sendemail.composeencoding iso-8859-1 &&\n+\t(echo \"#!$SHELL_PATH\" &&\n+\t echo \"echo utf8 body: Ă ĂŠĂŹĂśĂş >>\\\"\\$1\\\"\"\n+\t) >fake-editor-utf8 &&\n+\tchmod +x fake-editor-utf8 &&\n+\t  GIT_EDITOR=\"\\\"$(pwd)/fake-editor-utf8\\\"\" \\\n+\t  git send-email \\\n+\t  --compose-encoding iso-8859-2 \\\n+\t  --compose --subject foo \\\n+\t  --from=\"Example <nobody@example.com>\" \\\n+\t  --to=nobody@example.com \\\n+\t  --smtp-server=\"$(pwd)/fake.sendmail\" \\\n+\t  $patches &&\n+\tgrep \"^utf8 body\" msgtxt1 &&\n+\tgrep \"^Content-Type: text/plain; charset=iso-8859-2\" msgtxt1\n+'\n+\n test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '\n \techo master > master &&\n \tgit add master &&\n-- \n1.7.12.2.2.g1c3c581\n"}]}