Skip to content

Commit 7a76e68

Browse files
Jan H. Schönherrgitster
authored andcommitted
format-patch: do not wrap non-rfc2047 headers too early
Do not wrap the second and later lines of non-rfc2047-encoded headers substantially before the 78 character limit. Instead of passing the remaining length of the first line as wrapping width, use the correct maximum length and tell strbuf_add_wrapped_bytes() how many characters of the first line are already used. Signed-off-by: Jan H. Schönherr <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 14e1a4e commit 7a76e68

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

pretty.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static void add_rfc2047(struct strbuf *sb, const char *line, int len,
286286
if ((i + 1 < len) && (ch == '=' && line[i+1] == '?'))
287287
goto needquote;
288288
}
289-
strbuf_add_wrapped_bytes(sb, line, len, 0, 1, max_length - line_len);
289+
strbuf_add_wrapped_bytes(sb, line, len, -line_len, 1, max_length);
290290
return;
291291

292292
needquote:

t/t4014-format-patch.sh

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -752,16 +752,14 @@ M64=$M8$M8$M8$M8$M8$M8$M8$M8
752752
M512=$M64$M64$M64$M64$M64$M64$M64$M64
753753
cat >expect <<'EOF'
754754
Subject: [PATCH] foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
755-
bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
756-
foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
757-
bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
758-
foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
759-
bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
760-
foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
761-
bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
762-
foo bar foo bar foo bar foo bar
755+
bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
756+
foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
757+
bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
758+
foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
759+
bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
760+
foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
763761
EOF
764-
test_expect_success 'format-patch wraps extremely long headers (ascii)' '
762+
test_expect_success 'format-patch wraps extremely long subject (ascii)' '
765763
echo content >>file &&
766764
git add file &&
767765
git commit -m "$M512" &&
@@ -807,28 +805,12 @@ test_expect_success 'format-patch wraps extremely long headers (rfc2047)' '
807805
test_cmp expect subject
808806
'
809807

810-
M8="foo_bar_"
811-
M64=$M8$M8$M8$M8$M8$M8$M8$M8
812-
cat >expect <<EOF
813-
From: $M64
814-
815-
EOF
816-
test_expect_success 'format-patch wraps non-quotable headers' '
817-
rm -rf patches/ &&
818-
echo content >>file &&
819-
git add file &&
820-
git commit -mfoo --author "$M64 <[email protected]>" &&
821-
git format-patch --stdout -1 >patch &&
822-
sed -n "/^From: /p; /^ /p; /^$/q" <patch >from &&
823-
test_cmp expect from
824-
'
825-
826808
check_author() {
827809
echo content >>file &&
828810
git add file &&
829811
GIT_AUTHOR_NAME=$1 git commit -m author-check &&
830812
git format-patch --stdout -1 >patch &&
831-
grep ^From: patch >actual &&
813+
sed -n "/^From: /p; /^ /p; /^$/q" <patch >actual &&
832814
test_cmp expect actual
833815
}
834816

@@ -853,6 +835,32 @@ test_expect_success 'rfc2047-encoded headers also double-quote 822 specials' '
853835
check_author "Föo B. Bar"
854836
'
855837

838+
cat >expect <<EOF
839+
From: foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_
840+
841+
EOF
842+
test_expect_success 'format-patch wraps moderately long from-header (ascii)' '
843+
check_author "foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_foo_bar_"
844+
'
845+
846+
cat >expect <<'EOF'
847+
From: Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar
848+
Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo
849+
Bar Foo Bar Foo Bar Foo Bar <[email protected]>
850+
EOF
851+
test_expect_success 'format-patch wraps extremely long from-header (ascii)' '
852+
check_author "Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar"
853+
'
854+
855+
cat >expect <<'EOF'
856+
From: "Foo.Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar
857+
Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo
858+
Bar Foo Bar Foo Bar Foo Bar" <[email protected]>
859+
EOF
860+
test_expect_success 'format-patch wraps extremely long from-header (rfc822)' '
861+
check_author "Foo.Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar"
862+
'
863+
856864
cat >expect <<'EOF'
857865
Subject: header with . in it
858866
EOF

0 commit comments

Comments
 (0)