mailinfo: allow stripping quoted CR without warning

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>

Đoàn Trần Công Danh committed May 10, 2021 at 00:12 UTC 133a4fda59e7e68be13191082e14be32143bd61b
4 files changed +15
Documentation/git-mailinfo.txt
+1
@@ -102,6 +102,7 @@ The valid actions are:
102 * `nowarn`: Git will do nothing when such a CRLF is found.
103 * `warn`: Git will issue a warning for each message if such a CRLF is
104 found.
105 +* `strip`: Git will convert those CRLF to LF.
106 --
107 +
108 The default action could be set by configuration option `mailinfo.quotedCR`.
mailinfo.c
+7
@@ -998,6 +998,11 @@ static void handle_filter_flowed(struct mailinfo *mi, struct strbuf *line,
998 line->buf[len - 2] == '\r' &&
999 line->buf[len - 1] == '\n') {
1000 mi->have_quoted_cr = 1;
1001 + if (mi->quoted_cr == quoted_cr_strip) {
1002 + strbuf_setlen(line, len - 2);
1003 + strbuf_addch(line, '\n');
1004 + len--;
1005 + }
1006 }
1007 handle_filter(mi, line);
1008 return;
@@ -1227,6 +1232,8 @@ int mailinfo_parse_quoted_cr_action(const char *actionstr, int *action)
1232 *action = quoted_cr_nowarn;
1233 else if (!strcmp(actionstr, "warn"))
1234 *action = quoted_cr_warn;
1235 + else if (!strcmp(actionstr, "strip"))
1236 + *action = quoted_cr_strip;
1237 else
1238 return -1;
1239 return 0;
mailinfo.h
+1
@@ -8,6 +8,7 @@
8 enum quoted_cr_action {
9 quoted_cr_nowarn,
10 quoted_cr_warn,
11 + quoted_cr_strip,
12 };
13
14 struct mailinfo {
t/t5100-mailinfo.sh
+6
@@ -259,6 +259,12 @@ test_expect_success 'mailinfo warn CR in base64 encoded email' '
259 check_quoted_cr_mail quoted-cr/0001 --quoted-cr=nowarn &&
260 test_must_be_empty quoted-cr/0001.err &&
261 check_quoted_cr_mail quoted-cr/0002 --quoted-cr=nowarn &&
262 + test_must_be_empty quoted-cr/0002.err &&
263 + cp quoted-cr/0001-expected.msg quoted-cr/0002-expected.msg &&
264 + cp quoted-cr/0001-expected.patch quoted-cr/0002-expected.patch &&
265 + check_quoted_cr_mail quoted-cr/0001 --quoted-cr=strip &&
266 + test_must_be_empty quoted-cr/0001.err &&
267 + check_quoted_cr_mail quoted-cr/0002 --quoted-cr=strip &&
268 test_must_be_empty quoted-cr/0002.err
269 '
270