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>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2018-02-01 19:47:50 +07:00 committed by Junio C Hamano
parent 43662b23ab
commit 071dd0ba43
2 changed files with 33 additions and 15 deletions

View File

@ -1617,6 +1617,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
(!rev.diffopt.output_format || (!rev.diffopt.output_format ||
rev.diffopt.output_format == DIFF_FORMAT_PATCH)) rev.diffopt.output_format == DIFF_FORMAT_PATCH))
rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY; rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY;
if (!rev.diffopt.stat_width)
rev.diffopt.stat_width = MAIL_DEFAULT_WRAP;
/* Always generate a patch */ /* Always generate a patch */
rev.diffopt.output_format |= DIFF_FORMAT_PATCH; rev.diffopt.output_format |= DIFF_FORMAT_PATCH;

View File

@ -19,17 +19,33 @@ test_expect_success 'preparation' '
git commit -m message "$name" git commit -m message "$name"
' '
cat >expect72 <<-'EOF'
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
EOF
test_expect_success "format-patch: small change with long name gives more space to the name" '
git format-patch -1 --stdout >output &&
grep " | " output >actual &&
test_cmp expect72 actual
'
while read cmd args while read cmd args
do do
cat >expect <<-'EOF' cat >expect80 <<-'EOF'
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 + ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
EOF EOF
test_expect_success "$cmd: small change with long name gives more space to the name" ' test_expect_success "$cmd: small change with long name gives more space to the name" '
git $cmd $args >output && git $cmd $args >output &&
grep " | " output >actual && grep " | " output >actual &&
test_cmp expect actual test_cmp expect80 actual
' '
done <<\EOF
diff HEAD^ HEAD --stat
show --stat
log -1 --stat
EOF
while read cmd args
do
cat >expect <<-'EOF' cat >expect <<-'EOF'
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 + ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
EOF EOF
@ -79,11 +95,11 @@ test_expect_success 'preparation for big change tests' '
git commit -m message abcd git commit -m message abcd
' '
cat >expect80 <<'EOF' cat >expect72 <<'EOF'
abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
EOF EOF
cat >expect80-graph <<'EOF' cat >expect72-graph <<'EOF'
| abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
EOF EOF
cat >expect200 <<'EOF' cat >expect200 <<'EOF'
abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@ -107,7 +123,7 @@ do
test_cmp "$expect-graph" actual test_cmp "$expect-graph" actual
' '
done <<\EOF done <<\EOF
ignores expect80 format-patch -1 --stdout ignores expect72 format-patch -1 --stdout
respects expect200 diff HEAD^ HEAD --stat respects expect200 diff HEAD^ HEAD --stat
respects expect200 show --stat respects expect200 show --stat
respects expect200 log -1 --stat respects expect200 log -1 --stat
@ -135,7 +151,7 @@ do
test_cmp "$expect-graph" actual test_cmp "$expect-graph" actual
' '
done <<\EOF done <<\EOF
ignores expect80 format-patch -1 --stdout ignores expect72 format-patch -1 --stdout
respects expect40 diff HEAD^ HEAD --stat respects expect40 diff HEAD^ HEAD --stat
respects expect40 show --stat respects expect40 show --stat
respects expect40 log -1 --stat respects expect40 log -1 --stat
@ -163,7 +179,7 @@ do
test_cmp "$expect-graph" actual test_cmp "$expect-graph" actual
' '
done <<\EOF done <<\EOF
ignores expect80 format-patch -1 --stdout ignores expect72 format-patch -1 --stdout
respects expect40 diff HEAD^ HEAD --stat respects expect40 diff HEAD^ HEAD --stat
respects expect40 show --stat respects expect40 show --stat
respects expect40 log -1 --stat respects expect40 log -1 --stat
@ -250,11 +266,11 @@ show --stat
log -1 --stat log -1 --stat
EOF EOF
cat >expect80 <<'EOF' cat >expect72 <<'EOF'
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++ ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
EOF EOF
cat >expect80-graph <<'EOF' cat >expect72-graph <<'EOF'
| ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++ | ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
EOF EOF
cat >expect200 <<'EOF' cat >expect200 <<'EOF'
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@ -278,7 +294,7 @@ do
test_cmp "$expect-graph" actual test_cmp "$expect-graph" actual
' '
done <<\EOF done <<\EOF
ignores expect80 format-patch -1 --stdout ignores expect72 format-patch -1 --stdout
respects expect200 diff HEAD^ HEAD --stat respects expect200 diff HEAD^ HEAD --stat
respects expect200 show --stat respects expect200 show --stat
respects expect200 log -1 --stat respects expect200 log -1 --stat
@ -308,7 +324,7 @@ do
test_cmp "$expect-graph" actual test_cmp "$expect-graph" actual
' '
done <<\EOF done <<\EOF
ignores expect80 format-patch -1 --stdout ignores expect72 format-patch -1 --stdout
respects expect1 diff HEAD^ HEAD --stat respects expect1 diff HEAD^ HEAD --stat
respects expect1 show --stat respects expect1 show --stat
respects expect1 log -1 --stat respects expect1 log -1 --stat