Skip to content

Commit 284aeb7

Browse files
pcloudsgitster
authored andcommitted
format-patch: respect --stat in cover letter's diffstat
Commit 43662b2 (format-patch: keep cover-letter diffstat wrapped in 72 columns - 2018-01-24) uncondtionally sets stat width to 72 when generating diffstat for the cover letter, ignoring --stat from command line. But it should only do so when stat width is still default (i.e. stat_width == 0). In order to fix this, we should only set stat_width if stat_width is zero. But it will never be. Commit 071dd0b (format-patch: reduce patch diffstat width to 72 - 2018-02-01) makes sure that default stat width will be 72 (ignoring $COLUMNS, but could still be overriden by --stat). So all we need to do here is drop the assignment. Reported-by: Laszlo Ersek <[email protected]> Helped-by: Leif Lindholm <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cae598d commit 284aeb7

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

builtin/log.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,6 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
10691069

10701070
memcpy(&opts, &rev->diffopt, sizeof(opts));
10711071
opts.output_format = DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
1072-
opts.stat_width = MAIL_DEFAULT_WRAP;
1073-
10741072
diff_setup_done(&opts);
10751073

10761074
diff_tree_oid(get_commit_tree_oid(origin),

t/t4052-stat-output.sh

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,42 +44,50 @@ show --stat
4444
log -1 --stat
4545
EOF
4646

47-
while read cmd args
47+
cat >expect.60 <<-'EOF'
48+
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
49+
EOF
50+
cat >expect.6030 <<-'EOF'
51+
...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
52+
EOF
53+
cat >expect2.60 <<-'EOF'
54+
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
55+
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
56+
EOF
57+
cat >expect2.6030 <<-'EOF'
58+
...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
59+
...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
60+
EOF
61+
while read expect cmd args
4862
do
49-
cat >expect <<-'EOF'
50-
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
51-
EOF
5263
test_expect_success "$cmd --stat=width: a long name is given more room when the bar is short" '
5364
git $cmd $args --stat=40 >output &&
5465
grep " | " output >actual &&
55-
test_cmp expect actual
66+
test_cmp $expect.60 actual
5667
'
5768

5869
test_expect_success "$cmd --stat-width=width with long name" '
5970
git $cmd $args --stat-width=40 >output &&
6071
grep " | " output >actual &&
61-
test_cmp expect actual
72+
test_cmp $expect.60 actual
6273
'
6374

64-
cat >expect <<-'EOF'
65-
...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
66-
EOF
6775
test_expect_success "$cmd --stat=...,name-width with long name" '
6876
git $cmd $args --stat=60,30 >output &&
6977
grep " | " output >actual &&
70-
test_cmp expect actual
78+
test_cmp $expect.6030 actual
7179
'
7280

7381
test_expect_success "$cmd --stat-name-width with long name" '
7482
git $cmd $args --stat-name-width=30 >output &&
7583
grep " | " output >actual &&
76-
test_cmp expect actual
84+
test_cmp $expect.6030 actual
7785
'
7886
done <<\EOF
79-
format-patch -1 --stdout
80-
diff HEAD^ HEAD --stat
81-
show --stat
82-
log -1 --stat
87+
expect2 format-patch --cover-letter -1 --stdout
88+
expect diff HEAD^ HEAD --stat
89+
expect show --stat
90+
expect log -1 --stat
8391
EOF
8492

8593

@@ -95,6 +103,16 @@ test_expect_success 'preparation for big change tests' '
95103
git commit -m message abcd
96104
'
97105

106+
cat >expect72 <<'EOF'
107+
abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
108+
abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
109+
EOF
110+
test_expect_success "format-patch --cover-letter ignores COLUMNS (big change)" '
111+
COLUMNS=200 git format-patch -1 --stdout --cover-letter >output &&
112+
grep " | " output >actual &&
113+
test_cmp expect72 actual
114+
'
115+
98116
cat >expect72 <<'EOF'
99117
abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
100118
EOF

0 commit comments

Comments
 (0)