Skip to content

Commit e469e9c

Browse files
committed
Merge branch 'nd/format-patch-stat-width'
"git format-patch" learned to give 72-cols to diffstat, which is consistent with other line length limits the subcommand uses for its output meant for e-mails. * nd/format-patch-stat-width: format-patch: reduce patch diffstat width to 72 format-patch: keep cover-letter diffstat wrapped in 72 columns
2 parents a4ee444 + 071dd0b commit e469e9c

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

builtin/log.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "gpg-interface.h"
3030
#include "progress.h"
3131

32+
#define MAIL_DEFAULT_WRAP 72
33+
3234
/* Set a default date-time format for git log ("log.date" config variable) */
3335
static const char *default_date_mode = NULL;
3436

@@ -1044,7 +1046,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
10441046

10451047
shortlog_init(&log);
10461048
log.wrap_lines = 1;
1047-
log.wrap = 72;
1049+
log.wrap = MAIL_DEFAULT_WRAP;
10481050
log.in1 = 2;
10491051
log.in2 = 4;
10501052
log.file = rev->diffopt.file;
@@ -1061,6 +1063,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
10611063

10621064
memcpy(&opts, &rev->diffopt, sizeof(opts));
10631065
opts.output_format = DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
1066+
opts.stat_width = MAIL_DEFAULT_WRAP;
10641067

10651068
diff_setup_done(&opts);
10661069

@@ -1614,6 +1617,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
16141617
(!rev.diffopt.output_format ||
16151618
rev.diffopt.output_format == DIFF_FORMAT_PATCH))
16161619
rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY;
1620+
if (!rev.diffopt.stat_width)
1621+
rev.diffopt.stat_width = MAIL_DEFAULT_WRAP;
16171622

16181623
/* Always generate a patch */
16191624
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)