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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Feb 1, 2018 at 19:47 UTC
071dd0ba43b51a2124f3f9884283cd68a9506323
2 files changed
+33
-15
builtin/log.c
+2
@@ -1617,6 +1617,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1617
(!rev.diffopt.output_format ||
1618
rev.diffopt.output_format == DIFF_FORMAT_PATCH))
1619
rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY;
1620
+ if (!rev.diffopt.stat_width)
1621
+ rev.diffopt.stat_width = MAIL_DEFAULT_WRAP;
1622
1623
/* Always generate a patch */
1624
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
t/t4052-stat-output.sh
+31
-15
@@ -19,17 +19,33 @@ test_expect_success 'preparation' '
19
git commit -m message "$name"
20
'
21
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
+
31
while read cmd args
32
do
24
- cat >expect <<-'EOF'
33
+ cat >expect80 <<-'EOF'
34
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
35
EOF
36
test_expect_success "$cmd: small change with long name gives more space to the name" '
37
git $cmd $args >output &&
38
grep " | " output >actual &&
30
- test_cmp expect actual
39
+ test_cmp expect80 actual
40
'
41
+done <<\EOF
42
+diff HEAD^ HEAD --stat
43
+show --stat
44
+log -1 --stat
45
+EOF
46
47
+while read cmd args
48
+do
49
cat >expect <<-'EOF'
50
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
51
EOF
@@ -79,11 +95,11 @@ test_expect_success 'preparation for big change tests' '
95
git commit -m message abcd
96
'
97
82
-cat >expect80 <<'EOF'
83
- abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
98
+cat >expect72 <<'EOF'
99
+ abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
100
EOF
85
-cat >expect80-graph <<'EOF'
86
-| abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
101
+cat >expect72-graph <<'EOF'
102
+| abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
103
EOF
104
cat >expect200 <<'EOF'
105
abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -107,7 +123,7 @@ do
123
test_cmp "$expect-graph" actual
124
'
125
done <<\EOF
110
-ignores expect80 format-patch -1 --stdout
126
+ignores expect72 format-patch -1 --stdout
127
respects expect200 diff HEAD^ HEAD --stat
128
respects expect200 show --stat
129
respects expect200 log -1 --stat
@@ -135,7 +151,7 @@ do
151
test_cmp "$expect-graph" actual
152
'
153
done <<\EOF
138
-ignores expect80 format-patch -1 --stdout
154
+ignores expect72 format-patch -1 --stdout
155
respects expect40 diff HEAD^ HEAD --stat
156
respects expect40 show --stat
157
respects expect40 log -1 --stat
@@ -163,7 +179,7 @@ do
179
test_cmp "$expect-graph" actual
180
'
181
done <<\EOF
166
-ignores expect80 format-patch -1 --stdout
182
+ignores expect72 format-patch -1 --stdout
183
respects expect40 diff HEAD^ HEAD --stat
184
respects expect40 show --stat
185
respects expect40 log -1 --stat
@@ -250,11 +266,11 @@ show --stat
266
log -1 --stat
267
EOF
268
253
-cat >expect80 <<'EOF'
254
- ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
269
+cat >expect72 <<'EOF'
270
+ ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
271
EOF
256
-cat >expect80-graph <<'EOF'
257
-| ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
272
+cat >expect72-graph <<'EOF'
273
+| ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
274
EOF
275
cat >expect200 <<'EOF'
276
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -278,7 +294,7 @@ do
294
test_cmp "$expect-graph" actual
295
'
296
done <<\EOF
281
-ignores expect80 format-patch -1 --stdout
297
+ignores expect72 format-patch -1 --stdout
298
respects expect200 diff HEAD^ HEAD --stat
299
respects expect200 show --stat
300
respects expect200 log -1 --stat
@@ -308,7 +324,7 @@ do
324
test_cmp "$expect-graph" actual
325
'
326
done <<\EOF
311
-ignores expect80 format-patch -1 --stdout
327
+ignores expect72 format-patch -1 --stdout
328
respects expect1 diff HEAD^ HEAD --stat
329
respects expect1 show --stat
330
respects expect1 log -1 --stat