Skip to content

Commit 071dd0b

Browse files
pcloudsgitster
authored andcommitted
format-patch: reduce patch diffstat width to 72
Patches generated by format-patch are meant to be exchanged as emails, most of the time. And since it's generally agreed that text in mails should be wrapped around 70 columns or so, make sure these diffstat follow the convention (especially when used with --cover-letter since we already defaults to wrapping 72 columns). The default can still be overriden with command line options. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 43662b2 commit 071dd0b

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

builtin/log.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
16171617
(!rev.diffopt.output_format ||
16181618
rev.diffopt.output_format == DIFF_FORMAT_PATCH))
16191619
rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY;
1620+
if (!rev.diffopt.stat_width)
1621+
rev.diffopt.stat_width = MAIL_DEFAULT_WRAP;
16201622

16211623
/* Always generate a patch */
16221624
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;

t/t4052-stat-output.sh

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,33 @@ test_expect_success 'preparation' '
1919
git commit -m message "$name"
2020
'
2121

22+
cat >expect72 <<-'EOF'
23+
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
24+
EOF
25+
test_expect_success "format-patch: small change with long name gives more space to the name" '
26+
git format-patch -1 --stdout >output &&
27+
grep " | " output >actual &&
28+
test_cmp expect72 actual
29+
'
30+
2231
while read cmd args
2332
do
24-
cat >expect <<-'EOF'
33+
cat >expect80 <<-'EOF'
2534
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
2635
EOF
2736
test_expect_success "$cmd: small change with long name gives more space to the name" '
2837
git $cmd $args >output &&
2938
grep " | " output >actual &&
30-
test_cmp expect actual
39+
test_cmp expect80 actual
3140
'
41+
done <<\EOF
42+
diff HEAD^ HEAD --stat
43+
show --stat
44+
log -1 --stat
45+
EOF
3246

47+
while read cmd args
48+
do
3349
cat >expect <<-'EOF'
3450
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
3551
EOF
@@ -79,11 +95,11 @@ test_expect_success 'preparation for big change tests' '
7995
git commit -m message abcd
8096
'
8197

82-
cat >expect80 <<'EOF'
83-
abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
98+
cat >expect72 <<'EOF'
99+
abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
84100
EOF
85-
cat >expect80-graph <<'EOF'
86-
| abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
101+
cat >expect72-graph <<'EOF'
102+
| abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
87103
EOF
88104
cat >expect200 <<'EOF'
89105
abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -107,7 +123,7 @@ do
107123
test_cmp "$expect-graph" actual
108124
'
109125
done <<\EOF
110-
ignores expect80 format-patch -1 --stdout
126+
ignores expect72 format-patch -1 --stdout
111127
respects expect200 diff HEAD^ HEAD --stat
112128
respects expect200 show --stat
113129
respects expect200 log -1 --stat
@@ -135,7 +151,7 @@ do
135151
test_cmp "$expect-graph" actual
136152
'
137153
done <<\EOF
138-
ignores expect80 format-patch -1 --stdout
154+
ignores expect72 format-patch -1 --stdout
139155
respects expect40 diff HEAD^ HEAD --stat
140156
respects expect40 show --stat
141157
respects expect40 log -1 --stat
@@ -163,7 +179,7 @@ do
163179
test_cmp "$expect-graph" actual
164180
'
165181
done <<\EOF
166-
ignores expect80 format-patch -1 --stdout
182+
ignores expect72 format-patch -1 --stdout
167183
respects expect40 diff HEAD^ HEAD --stat
168184
respects expect40 show --stat
169185
respects expect40 log -1 --stat
@@ -250,11 +266,11 @@ show --stat
250266
log -1 --stat
251267
EOF
252268

253-
cat >expect80 <<'EOF'
254-
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
269+
cat >expect72 <<'EOF'
270+
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
255271
EOF
256-
cat >expect80-graph <<'EOF'
257-
| ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
272+
cat >expect72-graph <<'EOF'
273+
| ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
258274
EOF
259275
cat >expect200 <<'EOF'
260276
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -278,7 +294,7 @@ do
278294
test_cmp "$expect-graph" actual
279295
'
280296
done <<\EOF
281-
ignores expect80 format-patch -1 --stdout
297+
ignores expect72 format-patch -1 --stdout
282298
respects expect200 diff HEAD^ HEAD --stat
283299
respects expect200 show --stat
284300
respects expect200 log -1 --stat
@@ -308,7 +324,7 @@ do
308324
test_cmp "$expect-graph" actual
309325
'
310326
done <<\EOF
311-
ignores expect80 format-patch -1 --stdout
327+
ignores expect72 format-patch -1 --stdout
312328
respects expect1 diff HEAD^ HEAD --stat
313329
respects expect1 show --stat
314330
respects expect1 log -1 --stat

0 commit comments

Comments
 (0)