]> git.ipfire.org Git - thirdparty/git.git/commitdiff
mailinfo: allow stripping quoted CR without warning
authorĐoàn Trần Công Danh <congdanhqx@gmail.com>
Sun, 9 May 2021 17:12:12 +0000 (00:12 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 May 2021 06:06:22 +0000 (15:06 +0900)
In previous changes, we've turned on warning for quoted CR in base64 or
quoted-printable email messages. Some projects see those quoted CR a lot,
they know that it happens most of the time, and they find it's desirable
to always strip those CR.

Those projects in question usually fall back to use other tools to handle
patches when receive such patches.

Let's help those projects handle those patches by stripping those
excessive CR.

Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-mailinfo.txt
mailinfo.c
mailinfo.h
t/t5100-mailinfo.sh

index 824947a0703c7c9b962b536f06a3c11ef4e84704..3fcfd965fdec62613567278dbd7b08b0080778c7 100644 (file)
@@ -102,6 +102,7 @@ The valid actions are:
 *      `nowarn`: Git will do nothing when such a CRLF is found.
 *      `warn`: Git will issue a warning for each message if such a CRLF is
        found.
+*      `strip`: Git will convert those CRLF to LF.
 --
 +
 The default action could be set by configuration option `mailinfo.quotedCR`.
index a784552c7b2636324083a5f1313d82005c658c6a..ed863c3a9528157141c4adb9e5afe6590b2722c1 100644 (file)
@@ -998,6 +998,11 @@ static void handle_filter_flowed(struct mailinfo *mi, struct strbuf *line,
                    line->buf[len - 2] == '\r' &&
                    line->buf[len - 1] == '\n') {
                        mi->have_quoted_cr = 1;
+                       if (mi->quoted_cr == quoted_cr_strip) {
+                               strbuf_setlen(line, len - 2);
+                               strbuf_addch(line, '\n');
+                               len--;
+                       }
                }
                handle_filter(mi, line);
                return;
@@ -1227,6 +1232,8 @@ int mailinfo_parse_quoted_cr_action(const char *actionstr, int *action)
                *action = quoted_cr_nowarn;
        else if (!strcmp(actionstr, "warn"))
                *action = quoted_cr_warn;
+       else if (!strcmp(actionstr, "strip"))
+               *action = quoted_cr_strip;
        else
                return -1;
        return 0;
index 768d06ac2a803e2f9782e3100c6fd02d1854504f..2ddf8be90ffa61b1de9ee2d0ee89f783f40d2f91 100644 (file)
@@ -8,6 +8,7 @@
 enum quoted_cr_action {
        quoted_cr_nowarn,
        quoted_cr_warn,
+       quoted_cr_strip,
 };
 
 struct mailinfo {
index 1ecefa381d9cf6406083db05145656ce217747c0..141b29f0319a606ceefce3a06cd26990a64c8f06 100755 (executable)
@@ -259,6 +259,12 @@ test_expect_success 'mailinfo warn CR in base64 encoded email' '
        check_quoted_cr_mail quoted-cr/0001 --quoted-cr=nowarn &&
        test_must_be_empty quoted-cr/0001.err &&
        check_quoted_cr_mail quoted-cr/0002 --quoted-cr=nowarn &&
+       test_must_be_empty quoted-cr/0002.err &&
+       cp quoted-cr/0001-expected.msg quoted-cr/0002-expected.msg &&
+       cp quoted-cr/0001-expected.patch quoted-cr/0002-expected.patch &&
+       check_quoted_cr_mail quoted-cr/0001 --quoted-cr=strip &&
+       test_must_be_empty quoted-cr/0001.err &&
+       check_quoted_cr_mail quoted-cr/0002 --quoted-cr=strip &&
        test_must_be_empty quoted-cr/0002.err
 '