Re: [PATCH 2/2] git-send-email: add --transfer-encoding option

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

 



On Tue, Nov 25, 2014 at 9:00 AM, Paolo Bonzini <bonzini@xxxxxxx> wrote:
> From: Paolo Bonzini <pbonzini@xxxxxxxxxx>
>
> The thread at http://thread.gmane.org/gmane.comp.version-control.git/257392
> details problems when applying patches with "git am" in a repository with
> CRLF line endings.  In the example in the thread, the repository originated
> from "git-svn" so it is not possible to use core.eol and friends on it.
>
> Right now, the best option is to use "git am --keep-cr".  However, when
> a patch create new files, the patch application process will reject the
> new file because it finds a "/dev/null\r" string instead of "/dev/null".
>
> The problem is that SMTP transport is CRLF-unsafe.  Sending a patch by
> email is the same as passing it through "dos2unix | unix2dos".  The newly
> introduced CRLFs are normally transparent because git-am strips them. The
> keepcr=true setting preserves them, but it is mostly working by chance
> and it would be very problematic to have a "git am" workflow in a
> repository with mixed LF and CRLF line endings.
>
> The MIME solution to this is the quoted-printable transfer enconding.
> This is not something that we want to enable by default, since it makes
> received emails horrible to look at.  However, it is a very good match
> for projects that store CRLF line endings in the repository.
>
> The only disadvantage of quoted-printable is that quoted-printable
> patches fail to apply if the maintainer uses "git am --keep-cr".  This
> is because the decoded patch will have two carriage returns at the end
> of the line.  Therefore, add support for base64 transfer encoding too,
> which makes received emails downright impossible to look at outside
> a MUA, but really just works.
>
> The patch covers all bases, including users that still live in the late
> 80s, by also providing a 7bit content transfer encoding that refuses
> to send emails with non-ASCII character in them.  And finally, "8bit"
> will add a Content-Transfer-Encoding header but otherwise do nothing.
>
> Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
> ---
> diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
> index 19a3ced..e5016f4 100755
> --- a/t/t9001-send-email.sh
> +++ b/t/t9001-send-email.sh
> @@ -1298,6 +1298,163 @@ test_expect_success $PREREQ '--8bit-encoding also treats subject' '
>         test_cmp expected actual
>  '
>
> +test_expect_success $PREREQ 'setup expect' '
> +cat >email-using-8bit <<EOF

The test title says "setup expect", but this is creating an 8-bit
email message for input to git-send-email rather than expected output.
Perhaps the test title should be adjusted.

> +From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
> +Message-Id: <bogus-message-id@xxxxxxxxxxx>
> +From: A U Thor <author@xxxxxxxxxxx>
> +Date: Sat, 12 Jun 2010 15:53:58 +0200
> +Content-Type: text/plain; charset=UTF-8
> +Subject: Nothing to see here.
> +
> +Dieser Betreff enthält auch einen Umlaut!
> +EOF
> +'
> +
> +test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
> +       clean_fake_sendmail &&
> +       git config sendemail.transferEncoding 7bit &&

test_config here and elsewhere perhaps?

> +       test_must_fail git send-email \
> +         --transfer-encoding=7bit \

Redundant 7bit request.

> +         --smtp-server="$(pwd)/fake.sendmail" \
> +         email-using-8bit \
> +         2>errors >out &&
> +       grep "cannot send message as 7bit" errors &&
> +       test -z "$(ls msgtxt*)"
> +'
> +
> +test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
> +       clean_fake_sendmail &&
> +       git config sendemail.transferEncoding 8bit

Broken &&-chain.

> +       test_must_fail git send-email \
> +         --transfer-encoding=7bit \
> +         --smtp-server="$(pwd)/fake.sendmail" \
> +         email-using-8bit \
> +         2>errors >out &&
> +       grep "cannot send message as 7bit" errors &&
> +       test -z "$(ls msgtxt*)"
> +'
> +
> +test_expect_success $PREREQ 'sendemail.transferencoding=8bit' '
> +       clean_fake_sendmail &&
> +       git send-email \
> +         --transfer-encoding=8bit \
> +         --smtp-server="$(pwd)/fake.sendmail" \
> +         email-using-8bit \
> +         2>errors >out &&

Is it necessary here to capture stdout and stderr rather than allowing
them to be handled automatically by the testing framework? In the two
prior tests, you do consult 'error' so it makes send to capture it,
but this test does not, nor do any following tests which capture those
streams. (The same question applies to the capture of stdout in the
above two tests. Is it necessary?)

> +       sed '1,/^$/d' msgtxt1 >actual &&
> +       sed '1,/^$/d' email-using-8bit >expected &&
> +       test_cmp expected actual
> +'
> +
> +test_expect_success $PREREQ 'setup expect' '
> +cat >expected <<EOF
> +Dieser Betreff enth=C3=A4lt auch einen Umlaut!
> +EOF

This "expected" file is used only by the following test. It might be
clearer and more robust (in case someone inserts new tests in between
these) to create the "expected" file directly in the test which uses
it. The same comment applies to other "expected" files each used by
only a single test.

> +'
> +
> +test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
> +       clean_fake_sendmail &&
> +       git send-email \
> +         --transfer-encoding=quoted-printable \
> +         --smtp-server="$(pwd)/fake.sendmail" \
> +         email-using-8bit \
> +         2>errors >out &&
> +       sed '1,/^$/d' msgtxt1 >actual &&
> +       test_cmp expected actual
> +'
> +
> +test_expect_success $PREREQ 'setup expect' '
> +cat >expected <<EOF
> +RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
> +EOF
> +'
> +
> +test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
> +       clean_fake_sendmail &&
> +       git send-email \
> +         --transfer-encoding=base64 \
> +         --smtp-server="$(pwd)/fake.sendmail" \
> +         email-using-8bit \
> +         2>errors >out &&
> +       sed '1,/^$/d' msgtxt1 >actual &&
> +       test_cmp expected actual
> +'
> +
> +test_expect_success $PREREQ 'setup expect' '
> +cat >email-using-qp <<EOF

Test title says "setup expect" but it's really setting up a
quoted-printable email.

> +From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
> +Message-Id: <bogus-message-id@xxxxxxxxxxx>
> +From: A U Thor <author@xxxxxxxxxxx>
> +Date: Sat, 12 Jun 2010 15:53:58 +0200
> +MIME-Version: 1.0
> +Content-Transfer-Encoding: quoted-printable
> +Content-Type: text/plain; charset=UTF-8
> +Subject: Nothing to see here.
> +
> +Dieser Betreff enth=C3=A4lt auch einen Umlaut!
> +EOF
> +'
> +
> +test_expect_success $PREREQ 'convert from quoted-printable to base64' '
> +       clean_fake_sendmail &&
> +       git send-email \
> +         --transfer-encoding=base64 \
> +         --smtp-server="$(pwd)/fake.sendmail" \
> +         email-using-qp \
> +         2>errors >out &&
> +       sed '1,/^$/d' msgtxt1 >actual &&
> +       test_cmp expected actual
> +'
> +
> +test_expect_success $PREREQ 'setup expect' "
> +tr -d '\\015' | tr '%' '\\015' > email-using-crlf <<EOF

Ditto: Test title says "setup expect" but it's setting up a CRLF email.

> +From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
> +Message-Id: <bogus-message-id@xxxxxxxxxxx>
> +From: A U Thor <author@xxxxxxxxxxx>
> +Date: Sat, 12 Jun 2010 15:53:58 +0200
> +Content-Type: text/plain; charset=UTF-8
> +Subject: Nothing to see here.
> +
> +Look, I have a CRLF and an = sign!%
> +EOF
> +"
> +
> +test_expect_success $PREREQ 'setup expect' '
> +cat >expected <<EOF
> +Look, I have a CRLF and an =3D sign!=0D
> +EOF
> +'
> +
> +test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
> +       clean_fake_sendmail &&
> +       git send-email \
> +         --transfer-encoding=quoted-printable \
> +         --smtp-server="$(pwd)/fake.sendmail" \
> +         email-using-crlf \
> +         2>errors >out &&
> +       sed '1,/^$/d' msgtxt1 >actual &&
> +       test_cmp expected actual
> +'
> +
> +test_expect_success $PREREQ 'setup expect' '
> +cat >expected <<EOF
> +TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
> +EOF
> +'
> +
> +test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
> +       clean_fake_sendmail &&
> +       git send-email \
> +         --transfer-encoding=base64 \
> +         --smtp-server="$(pwd)/fake.sendmail" \
> +         email-using-crlf \
> +         2>errors >out &&
> +       sed '1,/^$/d' msgtxt1 >actual &&
> +       test_cmp expected actual
> +'
> +
> +
>  # Note that the patches in this test are deliberately out of order; we
>  # want to make sure it works even if the cover-letter is not in the
>  # first mail.
> --
> 2.1.0
--
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]