Skip to content

Commit 133a4fd

Browse files
sgngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1aa299 commit 133a4fd

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

Documentation/git-mailinfo.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ The valid actions are:
102102
* `nowarn`: Git will do nothing when such a CRLF is found.
103103
* `warn`: Git will issue a warning for each message if such a CRLF is
104104
found.
105+
* `strip`: Git will convert those CRLF to LF.
105106
--
106107
+
107108
The default action could be set by configuration option `mailinfo.quotedCR`.

mailinfo.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,11 @@ static void handle_filter_flowed(struct mailinfo *mi, struct strbuf *line,
998998
line->buf[len - 2] == '\r' &&
999999
line->buf[len - 1] == '\n') {
10001000
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+
}
10011006
}
10021007
handle_filter(mi, line);
10031008
return;
@@ -1227,6 +1232,8 @@ int mailinfo_parse_quoted_cr_action(const char *actionstr, int *action)
12271232
*action = quoted_cr_nowarn;
12281233
else if (!strcmp(actionstr, "warn"))
12291234
*action = quoted_cr_warn;
1235+
else if (!strcmp(actionstr, "strip"))
1236+
*action = quoted_cr_strip;
12301237
else
12311238
return -1;
12321239
return 0;

mailinfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
enum quoted_cr_action {
99
quoted_cr_nowarn,
1010
quoted_cr_warn,
11+
quoted_cr_strip,
1112
};
1213

1314
struct mailinfo {

t/t5100-mailinfo.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ test_expect_success 'mailinfo warn CR in base64 encoded email' '
259259
check_quoted_cr_mail quoted-cr/0001 --quoted-cr=nowarn &&
260260
test_must_be_empty quoted-cr/0001.err &&
261261
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 &&
262268
test_must_be_empty quoted-cr/0002.err
263269
'
264270

0 commit comments

Comments
 (0)