diff mbox series

diff --stat: set the width defaults in a helper function

Message ID 166396f0a98e248fc3d1236757632c5d648ddc0b.1695364961.git.dsimic@manjaro.org (mailing list archive)
State Superseded
Headers show
Series diff --stat: set the width defaults in a helper function | expand

Commit Message

Dragan Simic Sept. 22, 2023, 6:44 a.m. UTC
Extract the commonly used initialization of the --stat-width=<width>,
--stat-name-width=<width> and --stat-graph-with=<width> parameters to the
internal default values into a helper function, to avoid repeating the same
initialization code in a few places.

Add a couple of tests to additionally cover existing configuration options
diff.statNameWidth=<width> and diff.statGraphWidth=<width> when used by
git-merge to generate --stat outputs.  This closes the gap in the tests that
existed previously for the --stat tests, reducing the chances for having
any regressions introduced by this commit.

While there, perform a bunch of small wording improvements and some minor
code cleanups in the improved unit test, as spotted, to make it a bit neater
and to improve its test-level consistency.

Signed-off-by: Dragan Simic <dsimic@manjaro.org>
---
 builtin/diff.c         |  4 +--
 builtin/log.c          |  6 ++--
 builtin/merge.c        |  4 +--
 builtin/rebase.c       |  4 +--
 diff.c                 |  7 +++++
 diff.h                 |  1 +
 t/t4052-stat-output.sh | 65 ++++++++++++++++++++++++++----------------
 7 files changed, 53 insertions(+), 38 deletions(-)

Comments

Junio C Hamano Sept. 22, 2023, 5:04 p.m. UTC | #1
Dragan Simic <dsimic@manjaro.org> writes:

> Extract the commonly used initialization of the --stat-width=<width>,
> --stat-name-width=<width> and --stat-graph-with=<width> parameters to the
> internal default values into a helper function, to avoid repeating the same
> initialization code in a few places.

Thanks.

If this is only about settings related to controlling widths of
various elements on diffstat lines, isn't the "std" in name a bit
too broad, though?  init_diffstat_widths(&rev.diffopt) or something
like that might be a better fit.  I dunno if it is a huge deal,
though.

> Add a couple of tests to additionally cover existing configuration options
> diff.statNameWidth=<width> and diff.statGraphWidth=<width> when used by
> git-merge to generate --stat outputs.  This closes the gap in the tests that
> existed previously for the --stat tests, reducing the chances for having
> any regressions introduced by this commit.

Nice.

> While there, perform a bunch of small wording improvements and some minor
> code cleanups in the improved unit test, as spotted, to make it a bit neater
> and to improve its test-level consistency.

Alright.  The last category of changes need somebody else to review
them in addition to myself, as I expect that it would be somewhat
subjective and I tend to be change-averse.

The code changes all looked sensible.

> diff --git a/t/t4052-stat-output.sh b/t/t4052-stat-output.sh
> index beb2ec2a55..aa947d93cf 100755
> --- a/t/t4052-stat-output.sh
> +++ b/t/t4052-stat-output.sh
> @@ -12,32 +12,31 @@ TEST_PASSES_SANITIZE_LEAK=true
>  . ./test-lib.sh
>  . "$TEST_DIRECTORY"/lib-terminal.sh
>  
> -# 120 character name
> -name=aaaaaaaaaa
> -name=$name$name$name$name$name$name$name$name$name$name$name$name
> +# 120-character name
> +printf -v name 'a%.0s' {1..120}

This is a totally unnecessary and unacceptable change.  "-v name"
may be available in the built-in variant found in bash, but you
would likely find that it is missing from other shells.  {1..120} is
also a bash-ism.

And because we are still calling the result a "name" (not
"filename") ...

>  cat >expect72 <<-'EOF'
>   ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
>  EOF
> -test_expect_success "format-patch: small change with long name gives more space to the name" '
> +test_expect_success "format-patch: small change with long filename gives more space to the filename" '

... I do not see the point of this change (and similar ones in the
rest of the patch).  Even the configuration is called statNameWidth
and not statFileNameWidth.  In the context of the tests that check
"stat-output" (that is in the filename of this script), we should be
able to use "name" consistently without causing any confusion, as it
is unlikely to be mistaken with other kinds of "name".

> -test_expect_success "format-patch --cover-letter ignores COLUMNS (big change)" '
> +test_expect_success "format-patch --cover-letter ignores COLUMNS envvar with big change" '

Not wrong per-se, but I wonder if it is necessary to stress that
COLUMNS is an environment variable that tells the programs how wide
a terminal they are showing their output.  A usual shell variable
would not affect the "git" process it runs, and COLUMNS without any
dot in it cannot be our configuration variable, so even without deep
knowledge of tradition, I thought it would be rather obvious.

Same comment for "statNameWidth config"; with fewer number of bytes,
it would be more descriptive to say "diff.statNameWidth".

> -	test_expect_success "$cmd --stat-graph-width with big change" '
> +	test_expect_success "$cmd --stat-graph-width=width with big change" '
>  		git $cmd $args --stat-graph-width=26 >output &&

This may be a good change, especially if there are tests that feed
different parameters and if it helps clarifying which variant is
tested, e.g. "--stat=<width>,<name-width>" vs "--stat=<width>".

Ah, wait, "--stat-graph-width" always takes a single value, so the
above justification does not quite apply.  But still, it is not
making it worse, and because there is another test that is labeled
with "--stat-width=width", being consistent with it has value.

OK.

> -	test_expect_success "$cmd --stat-graph-width --graph with big change" '
> +	test_expect_success "$cmd --stat-graph-width=width --graph with big change" '

Ditto.

Thanks.
Dragan Simic Sept. 22, 2023, 5:52 p.m. UTC | #2
On 2023-09-22 19:04, Junio C Hamano wrote:
> Dragan Simic <dsimic@manjaro.org> writes:
> 
>> Extract the commonly used initialization of the --stat-width=<width>,
>> --stat-name-width=<width> and --stat-graph-with=<width> parameters to 
>> the
>> internal default values into a helper function, to avoid repeating the 
>> same
>> initialization code in a few places.
> 
> Thanks.
> 
> If this is only about settings related to controlling widths of
> various elements on diffstat lines, isn't the "std" in name a bit
> too broad, though?  init_diffstat_widths(&rev.diffopt) or something
> like that might be a better fit.  I dunno if it is a huge deal,
> though.

Makes sense to me, init_diffstat_widths(&rev.diffopt) fits better and 
it's more descriptive.  I'm a big fan of using self-descriptive naming, 
but originally I wanted to follow the already present naming scheme, so 
I'm glad to see that you asked for a more descriptive function name.

>> Add a couple of tests to additionally cover existing configuration 
>> options
>> diff.statNameWidth=<width> and diff.statGraphWidth=<width> when used 
>> by
>> git-merge to generate --stat outputs.  This closes the gap in the 
>> tests that
>> existed previously for the --stat tests, reducing the chances for 
>> having
>> any regressions introduced by this commit.
> 
> Nice.

Thanks.

>> While there, perform a bunch of small wording improvements and some 
>> minor
>> code cleanups in the improved unit test, as spotted, to make it a bit 
>> neater
>> and to improve its test-level consistency.
> 
> Alright.  The last category of changes need somebody else to review
> them in addition to myself, as I expect that it would be somewhat
> subjective and I tend to be change-averse.
> 
> The code changes all looked sensible.
> 
>> diff --git a/t/t4052-stat-output.sh b/t/t4052-stat-output.sh
>> index beb2ec2a55..aa947d93cf 100755
>> --- a/t/t4052-stat-output.sh
>> +++ b/t/t4052-stat-output.sh
>> @@ -12,32 +12,31 @@ TEST_PASSES_SANITIZE_LEAK=true
>>  . ./test-lib.sh
>>  . "$TEST_DIRECTORY"/lib-terminal.sh
>> 
>> -# 120 character name
>> -name=aaaaaaaaaa
>> -name=$name$name$name$name$name$name$name$name$name$name$name$name
>> +# 120-character name
>> +printf -v name 'a%.0s' {1..120}
> 
> This is a totally unnecessary and unacceptable change.  "-v name"
> may be available in the built-in variant found in bash, but you
> would likely find that it is missing from other shells.  {1..120} is
> also a bash-ism.

Makes sense to stick with the simpler variant, which won't cause 
compatibility issues.

> And because we are still calling the result a "name" (not
> "filename") ...
> 
>>  cat >expect72 <<-'EOF'
>>   ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 
>> +
>>  EOF
>> -test_expect_success "format-patch: small change with long name gives 
>> more space to the name" '
>> +test_expect_success "format-patch: small change with long filename 
>> gives more space to the filename" '
> 
> ... I do not see the point of this change (and similar ones in the
> rest of the patch).  Even the configuration is called statNameWidth
> and not statFileNameWidth.  In the context of the tests that check
> "stat-output" (that is in the filename of this script), we should be
> able to use "name" consistently without causing any confusion, as it
> is unlikely to be mistaken with other kinds of "name".

On second thought, I agree that sticking with just "name" is better in 
this test.

>> -test_expect_success "format-patch --cover-letter ignores COLUMNS (big 
>> change)" '
>> +test_expect_success "format-patch --cover-letter ignores COLUMNS 
>> envvar with big change" '
> 
> Not wrong per-se, but I wonder if it is necessary to stress that
> COLUMNS is an environment variable that tells the programs how wide
> a terminal they are showing their output.  A usual shell variable
> would not affect the "git" process it runs, and COLUMNS without any
> dot in it cannot be our configuration variable, so even without deep
> knowledge of tradition, I thought it would be rather obvious.

On second thought, I agree that using just "COLUMN" suffices while also 
being more compact.

> Same comment for "statNameWidth config"; with fewer number of bytes,
> it would be more descriptive to say "diff.statNameWidth".

Oh, nice catch!  Makes sense.

>> -	test_expect_success "$cmd --stat-graph-width with big change" '
>> +	test_expect_success "$cmd --stat-graph-width=width with big change" 
>> '
>>  		git $cmd $args --stat-graph-width=26 >output &&
> 
> This may be a good change, especially if there are tests that feed
> different parameters and if it helps clarifying which variant is
> tested, e.g. "--stat=<width>,<name-width>" vs "--stat=<width>".
> 
> Ah, wait, "--stat-graph-width" always takes a single value, so the
> above justification does not quite apply.  But still, it is not
> making it worse, and because there is another test that is labeled
> with "--stat-width=width", being consistent with it has value.

Yes, I think that the improved consistency outweights the slight 
redundancy.

> OK.
> 
>> -	test_expect_success "$cmd --stat-graph-width --graph with big 
>> change" '
>> +	test_expect_success "$cmd --stat-graph-width=width --graph with big 
>> change" '
> 
> Ditto.
> 
> Thanks.

Thanks, I'll prepare and send v2 of the patch, based on your feedback.
diff mbox series

Patch

diff --git a/builtin/diff.c b/builtin/diff.c
index c0f564273a..041559d6fb 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -474,9 +474,7 @@  int cmd_diff(int argc, const char **argv, const char *prefix)
 	repo_init_revisions(the_repository, &rev, prefix);
 
 	/* Set up defaults that will apply to both no-index and regular diffs. */
-	rev.diffopt.stat_width = -1;
-	rev.diffopt.stat_name_width = -1;
-	rev.diffopt.stat_graph_width = -1;
+	diffstat_std(&rev.diffopt);
 	rev.diffopt.flags.allow_external = 1;
 	rev.diffopt.flags.allow_textconv = 1;
 
diff --git a/builtin/log.c b/builtin/log.c
index 80e1be1645..f15401e966 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -176,17 +176,15 @@  static void cmd_log_init_defaults(struct rev_info *rev)
 	if (default_follow)
 		rev->diffopt.flags.default_follow_renames = 1;
 	rev->verbose_header = 1;
+	diffstat_std(&rev->diffopt);
 	rev->diffopt.flags.recursive = 1;
-	rev->diffopt.stat_width = -1; /* use full terminal width */
-	rev->diffopt.stat_name_width = -1; /* respect statNameWidth config */
-	rev->diffopt.stat_graph_width = -1; /* respect statGraphWidth config */
+	rev->diffopt.flags.allow_textconv = 1;
 	rev->abbrev_commit = default_abbrev_commit;
 	rev->show_root_diff = default_show_root;
 	rev->subject_prefix = fmt_patch_subject_prefix;
 	rev->patch_name_max = fmt_patch_name_max;
 	rev->show_signature = default_show_signature;
 	rev->encode_email_headers = default_encode_email_headers;
-	rev->diffopt.flags.allow_textconv = 1;
 
 	if (default_date_mode)
 		parse_date_format(default_date_mode, &rev->date_mode);
diff --git a/builtin/merge.c b/builtin/merge.c
index fd21c0d4f4..4120ec2dff 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -466,9 +466,7 @@  static void finish(struct commit *head_commit,
 	if (new_head && show_diffstat) {
 		struct diff_options opts;
 		repo_diff_setup(the_repository, &opts);
-		opts.stat_width = -1; /* use full terminal width */
-		opts.stat_name_width = -1; /* respect statNameWidth config */
-		opts.stat_graph_width = -1; /* respect statGraphWidth config */
+		diffstat_std(&opts);
 		opts.output_format |=
 			DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
 		opts.detect_rename = DIFF_DETECT_RENAME;
diff --git a/builtin/rebase.c b/builtin/rebase.c
index b93dca95a6..ae85bc992b 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1806,9 +1806,7 @@  int cmd_rebase(int argc, const char **argv, const char *prefix)
 
 		/* We want color (if set), but no pager */
 		repo_diff_setup(the_repository, &opts);
-		opts.stat_width = -1; /* use full terminal width */
-		opts.stat_name_width = -1; /* respect statNameWidth config */
-		opts.stat_graph_width = -1; /* respect statGraphWidth config */
+		diffstat_std(&opts);
 		opts.output_format |=
 			DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
 		opts.detect_rename = DIFF_DETECT_RENAME;
diff --git a/diff.c b/diff.c
index 353e3b2cc9..845e7f4e84 100644
--- a/diff.c
+++ b/diff.c
@@ -6936,6 +6936,13 @@  void diff_queued_diff_prefetch(void *repository)
 	oid_array_clear(&to_fetch);
 }
 
+void diffstat_std(struct diff_options *options)
+{
+	options->stat_width = -1;        /* use full terminal width */
+	options->stat_name_width = -1;   /* respect diff.statNameWidth config */
+	options->stat_graph_width = -1;  /* respect diff.statGraphWidth config */
+}
+
 void diffcore_std(struct diff_options *options)
 {
 	int output_formats_to_prefetch = DIFF_FORMAT_DIFFSTAT |
diff --git a/diff.h b/diff.h
index caf1528bf0..9a64c53f5f 100644
--- a/diff.h
+++ b/diff.h
@@ -573,6 +573,7 @@  int git_config_rename(const char *var, const char *value);
 
 #define DIFF_PICKAXE_IGNORE_CASE	32
 
+void diffstat_std(struct diff_options *);
 void diffcore_std(struct diff_options *);
 void diffcore_fix_diff_index(void);
 
diff --git a/t/t4052-stat-output.sh b/t/t4052-stat-output.sh
index beb2ec2a55..aa947d93cf 100755
--- a/t/t4052-stat-output.sh
+++ b/t/t4052-stat-output.sh
@@ -12,32 +12,31 @@  TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-terminal.sh
 
-# 120 character name
-name=aaaaaaaaaa
-name=$name$name$name$name$name$name$name$name$name$name$name$name
+# 120-character name
+printf -v name 'a%.0s' {1..120}
 test_expect_success 'preparation' '
 	>"$name" &&
 	git add "$name" &&
 	git commit -m message &&
 	echo a >"$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" '
+test_expect_success "format-patch: small change with long filename gives more space to the filename" '
 	git format-patch -1 --stdout >output &&
 	grep " | " output >actual &&
 	test_cmp expect72 actual
 '
 
 while read cmd args
 do
 	cat >expect80 <<-'EOF'
 	 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
 	EOF
-	test_expect_success "$cmd: small change with long name gives more space to the name" '
+	test_expect_success "$cmd: small change with long filename gives more space to the filename" '
 		git $cmd $args >output &&
 		grep " | " output >actual &&
 		test_cmp expect80 actual
@@ -58,15 +57,15 @@  while read verb expect cmd args
 do
 	# No width limit applied when statNameWidth is ignored
 	case "$expect" in expect72|expect.6030)
-		test_expect_success "$cmd $verb statNameWidth config with long name" '
+		test_expect_success "$cmd $verb statNameWidth config with long filename" '
 			git -c diff.statNameWidth=30 $cmd $args >output &&
 			grep " | " output >actual &&
 			test_cmp $expect actual
 		';;
 	esac
 	# Maximum width limit still applied when statNameWidth is ignored
 	case "$expect" in expect.60|expect.6030)
-		test_expect_success "$cmd --stat=width $verb statNameWidth config with long name" '
+		test_expect_success "$cmd --stat=width $verb statNameWidth config with long filename" '
 			git -c diff.statNameWidth=30 $cmd $args --stat=60 >output &&
 			grep " | " output >actual &&
 			test_cmp $expect actual
@@ -93,25 +92,25 @@  cat >expect2.6030 <<-'EOF'
 EOF
 while read expect cmd args
 do
-	test_expect_success "$cmd --stat=width: a long name is given more room when the bar is short" '
+	test_expect_success "$cmd --stat=width: a long filename is given more room when the bar is short" '
 		git $cmd $args --stat=40 >output &&
 		grep " | " output >actual &&
 		test_cmp $expect.40 actual
 	'
 
-	test_expect_success "$cmd --stat-width=width with long name" '
+	test_expect_success "$cmd --stat-width=width with long filename" '
 		git $cmd $args --stat-width=40 >output &&
 		grep " | " output >actual &&
 		test_cmp $expect.40 actual
 	'
 
-	test_expect_success "$cmd --stat=width,name-width with long name" '
+	test_expect_success "$cmd --stat=width,name-width with long filename" '
 		git $cmd $args --stat=60,30 >output &&
 		grep " | " output >actual &&
 		test_cmp $expect.6030 actual
 	'
 
-	test_expect_success "$cmd --stat-name-width with long name" '
+	test_expect_success "$cmd --stat-name-width with long filename" '
 		git $cmd $args --stat-name-width=30 >output &&
 		grep " | " output >actual &&
 		test_cmp $expect.6030 actual
@@ -139,7 +138,7 @@  cat >expect72 <<'EOF'
  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 EOF
-test_expect_success "format-patch --cover-letter ignores COLUMNS (big change)" '
+test_expect_success "format-patch --cover-letter ignores COLUMNS envvar with big change" '
 	COLUMNS=200 git format-patch -1 --stdout --cover-letter >output &&
 	grep " | " output >actual &&
 	test_cmp expect72 actual
@@ -159,15 +158,15 @@  cat >expect200-graph <<'EOF'
 EOF
 while read verb expect cmd args
 do
-	test_expect_success "$cmd $verb COLUMNS (big change)" '
+	test_expect_success "$cmd $verb COLUMNS envvar with big change" '
 		COLUMNS=200 git $cmd $args >output &&
 		grep " | " output >actual &&
 		test_cmp "$expect" actual
 	'
 
 	case "$cmd" in diff|show) continue;; esac
 
-	test_expect_success "$cmd --graph $verb COLUMNS (big change)" '
+	test_expect_success "$cmd --graph $verb COLUMNS envvar with big change" '
 		COLUMNS=200 git $cmd $args --graph >output &&
 		grep " | " output >actual &&
 		test_cmp "$expect-graph" actual
@@ -187,15 +186,15 @@  cat >expect40-graph <<'EOF'
 EOF
 while read verb expect cmd args
 do
-	test_expect_success "$cmd $verb not enough COLUMNS (big change)" '
+	test_expect_success "$cmd $verb not large enough COLUMNS envvar with big change" '
 		COLUMNS=40 git $cmd $args >output &&
 		grep " | " output >actual &&
 		test_cmp "$expect" actual
 	'
 
 	case "$cmd" in diff|show) continue;; esac
 
-	test_expect_success "$cmd --graph $verb not enough COLUMNS (big change)" '
+	test_expect_success "$cmd --graph $verb not large enough COLUMNS envvar with big change" '
 		COLUMNS=40 git $cmd $args --graph >output &&
 		grep " | " output >actual &&
 		test_cmp "$expect-graph" actual
@@ -255,21 +254,21 @@  do
 		test_cmp expect actual
 	'
 
-	test_expect_success "$cmd --stat-graph-width with big change" '
+	test_expect_success "$cmd --stat-graph-width=width with big change" '
 		git $cmd $args --stat-graph-width=26 >output &&
 		grep " | " output >actual &&
 		test_cmp expect actual
 	'
 
 	case "$cmd" in diff|show) continue;; esac
 
 	test_expect_success "$cmd --stat-width=width --graph with big change" '
 		git $cmd $args --stat-width=40 --graph >output &&
 		grep " | " output >actual &&
 		test_cmp expect-graph actual
 	'
 
-	test_expect_success "$cmd --stat-graph-width --graph with big change" '
+	test_expect_success "$cmd --stat-graph-width=width --graph with big change" '
 		git $cmd $args --stat-graph-width=26 --graph >output &&
 		grep " | " output >actual &&
 		test_cmp expect-graph actual
@@ -329,15 +328,15 @@  cat >expect200-graph <<'EOF'
 EOF
 while read verb expect cmd args
 do
-	test_expect_success "$cmd $verb COLUMNS (long filename)" '
+	test_expect_success "$cmd $verb COLUMNS envvar with long filename" '
 		COLUMNS=200 git $cmd $args >output &&
 		grep " | " output >actual &&
 		test_cmp "$expect" actual
 	'
 
 	case "$cmd" in diff|show) continue;; esac
 
-	test_expect_success "$cmd --graph $verb COLUMNS (long filename)" '
+	test_expect_success "$cmd --graph $verb COLUMNS envvar with long filename" '
 		COLUMNS=200 git $cmd $args --graph >output &&
 		grep " | " output >actual &&
 		test_cmp "$expect-graph" actual
@@ -358,41 +357,57 @@  EOF
 while read verb expect cmd args
 do
 	test_expect_success COLUMNS_CAN_BE_1 \
-		"$cmd $verb prefix greater than COLUMNS (big change)" '
+		"$cmd $verb prefix greater than COLUMNS envvar with big change" '
 		COLUMNS=1 git $cmd $args >output &&
 		grep " | " output >actual &&
 		test_cmp "$expect" actual
 	'
 
 	case "$cmd" in diff|show) continue;; esac
 
 	test_expect_success COLUMNS_CAN_BE_1 \
-		"$cmd --graph $verb prefix greater than COLUMNS (big change)" '
+		"$cmd --graph $verb prefix greater than COLUMNS envvar with big change" '
 		COLUMNS=1 git $cmd $args --graph >output &&
 		grep " | " output >actual &&
 		test_cmp "$expect-graph" actual
 	'
 done <<\EOF
 ignores expect72 format-patch -1 --stdout
 respects expect1 diff HEAD^ HEAD --stat
 respects expect1 show --stat
 respects expect1 log -1 --stat
 EOF
 
 cat >expect <<'EOF'
  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 EOF
-test_expect_success 'merge --stat respects COLUMNS (big change)' '
-	git checkout -b branch HEAD^^ &&
+test_expect_success 'merge --stat respects statGraphWidth config with big change' '
+	git checkout -b branch1 HEAD^^ &&
+	git -c diff.statGraphWidth=26 merge --stat --no-ff main^ >output &&
+	grep " | " output >actual &&
+	test_cmp expect40 actual
+'
+test_expect_success 'merge --stat respects COLUMNS envvar with big change' '
+	git checkout -b branch2 HEAD^^ &&
 	COLUMNS=100 git merge --stat --no-ff main^ >output &&
 	grep " | " output >actual &&
 	test_cmp expect actual
 '
 
 cat >expect <<'EOF'
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++
 EOF
-test_expect_success 'merge --stat respects COLUMNS (long filename)' '
+cat >expect.30 <<'EOF'
+ ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++++++++++++++++++++++
+EOF
+test_expect_success 'merge --stat respects statNameWidth config with long filename' '
+	git switch branch1 &&
+	git -c diff.statNameWidth=30 merge --stat --no-ff main >output &&
+	grep " | " output >actual &&
+	test_cmp expect.30 actual
+'
+test_expect_success 'merge --stat respects COLUMNS envvar with long filename' '
+	git switch branch2 &&
 	COLUMNS=100 git merge --stat --no-ff main >output &&
 	grep " | " output >actual &&
 	test_cmp expect actual