{"thread":{"id":"60262","subject":"[PATCH v2] diff --stat: set the width defaults in a helper function","startedAt":"2023-09-23T04:03:59Z","lastAt":"2023-09-28T20:35:35Z","messageCount":4,"participants":["Dragan Simic","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"482196","messageId":"d45d1dac1a20699e370905b88b6fd0ec296751e7.1695441501.git.dsimic@manjaro.org","threadId":"60262","inReplyTo":null,"subject":"[PATCH v2] diff --stat: set the width defaults in a helper function","fromName":"Dragan Simic","fromEmail":"dsimic@manjaro.org","sentAt":"2023-09-23T04:01:14Z","receivedAt":"2023-09-23T04:03:59Z","isPatch":true,"sender":{"key":"dsimic@manjaro.org","avatar":null},"body":"Extract the commonly used initialization of the --stat-width=<width>,\n--stat-name-width=<width> and --stat-graph-with=<width> parameters to their\ninternal default values into a helper function, to avoid repeating the same\ninitialization code in a few places.\n\nAdd a couple of tests to additionally cover existing configuration options\ndiff.statNameWidth=<width> and diff.statGraphWidth=<width> when used by\ngit-merge to generate --stat outputs.  This closes the gap that existed\npreviously in the --stat tests, and reduces the chances for having any\nregressions introduced by this commit.\n\nWhile there, perform a small bunch of minor wording tweaks in the improved\nunit test, to improve its test-level consistency a bit.\n\nSigned-off-by: Dragan Simic <dsimic@manjaro.org>\n---\n builtin/diff.c         |  4 +--\n builtin/log.c          |  6 ++---\n builtin/merge.c        |  4 +--\n builtin/rebase.c       |  4 +--\n diff.c                 |  7 +++++\n diff.h                 |  1 +\n t/t4052-stat-output.sh | 60 ++++++++++++++++++++++++++----------------\n 7 files changed, 51 insertions(+), 35 deletions(-)\n\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex c0f564273a..55e7d21755 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -474,9 +474,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \trepo_init_revisions(the_repository, &rev, prefix);\n \n \t/* Set up defaults that will apply to both no-index and regular diffs. */\n-\trev.diffopt.stat_width = -1;\n-\trev.diffopt.stat_name_width = -1;\n-\trev.diffopt.stat_graph_width = -1;\n+\tinit_diffstat_widths(&rev.diffopt);\n \trev.diffopt.flags.allow_external = 1;\n \trev.diffopt.flags.allow_textconv = 1;\n \ndiff --git a/builtin/log.c b/builtin/log.c\nindex 80e1be1645..ba775d7b5c 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -176,17 +176,15 @@ static void cmd_log_init_defaults(struct rev_info *rev)\n \tif (default_follow)\n \t\trev->diffopt.flags.default_follow_renames = 1;\n \trev->verbose_header = 1;\n+\tinit_diffstat_widths(&rev->diffopt);\n \trev->diffopt.flags.recursive = 1;\n-\trev->diffopt.stat_width = -1; /* use full terminal width */\n-\trev->diffopt.stat_name_width = -1; /* respect statNameWidth config */\n-\trev->diffopt.stat_graph_width = -1; /* respect statGraphWidth config */\n+\trev->diffopt.flags.allow_textconv = 1;\n \trev->abbrev_commit = default_abbrev_commit;\n \trev->show_root_diff = default_show_root;\n \trev->subject_prefix = fmt_patch_subject_prefix;\n \trev->patch_name_max = fmt_patch_name_max;\n \trev->show_signature = default_show_signature;\n \trev->encode_email_headers = default_encode_email_headers;\n-\trev->diffopt.flags.allow_textconv = 1;\n \n \tif (default_date_mode)\n \t\tparse_date_format(default_date_mode, &rev->date_mode);\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex fd21c0d4f4..8f397cbeff 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -466,9 +466,7 @@ static void finish(struct commit *head_commit,\n \tif (new_head && show_diffstat) {\n \t\tstruct diff_options opts;\n \t\trepo_diff_setup(the_repository, &opts);\n-\t\topts.stat_width = -1; /* use full terminal width */\n-\t\topts.stat_name_width = -1; /* respect statNameWidth config */\n-\t\topts.stat_graph_width = -1; /* respect statGraphWidth config */\n+\t\tinit_diffstat_widths(&opts);\n \t\topts.output_format |=\n \t\t\tDIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;\n \t\topts.detect_rename = DIFF_DETECT_RENAME;\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex b93dca95a6..4783f90ac5 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -1806,9 +1806,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \n \t\t/* We want color (if set), but no pager */\n \t\trepo_diff_setup(the_repository, &opts);\n-\t\topts.stat_width = -1; /* use full terminal width */\n-\t\topts.stat_name_width = -1; /* respect statNameWidth config */\n-\t\topts.stat_graph_width = -1; /* respect statGraphWidth config */\n+\t\tinit_diffstat_widths(&opts);\n \t\topts.output_format |=\n \t\t\tDIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;\n \t\topts.detect_rename = DIFF_DETECT_RENAME;\ndiff --git a/diff.c b/diff.c\nindex 353e3b2cc9..2c602df10a 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -6936,6 +6936,13 @@ void diff_queued_diff_prefetch(void *repository)\n \toid_array_clear(&to_fetch);\n }\n \n+void init_diffstat_widths(struct diff_options *options)\n+{\n+\toptions->stat_width = -1;        /* use full terminal width */\n+\toptions->stat_name_width = -1;   /* respect diff.statNameWidth config */\n+\toptions->stat_graph_width = -1;  /* respect diff.statGraphWidth config */\n+}\n+\n void diffcore_std(struct diff_options *options)\n {\n \tint output_formats_to_prefetch = DIFF_FORMAT_DIFFSTAT |\ndiff --git a/diff.h b/diff.h\nindex caf1528bf0..66bd8aeb29 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -573,6 +573,7 @@ int git_config_rename(const char *var, const char *value);\n \n #define DIFF_PICKAXE_IGNORE_CASE\t32\n \n+void init_diffstat_widths(struct diff_options *);\n void diffcore_std(struct diff_options *);\n void diffcore_fix_diff_index(void);\n \ndiff --git a/t/t4052-stat-output.sh b/t/t4052-stat-output.sh\nindex beb2ec2a55..7badd72488 100755\n--- a/t/t4052-stat-output.sh\n+++ b/t/t4052-stat-output.sh\n@@ -12,7 +12,7 @@ TEST_PASSES_SANITIZE_LEAK=true\n . ./test-lib.sh\n . \"$TEST_DIRECTORY\"/lib-terminal.sh\n \n-# 120 character name\n+# 120-character name\n name=aaaaaaaaaa\n name=$name$name$name$name$name$name$name$name$name$name$name$name\n test_expect_success 'preparation' '\n@@ -58,15 +58,15 @@ while read verb expect cmd args\n do\n \t# No width limit applied when statNameWidth is ignored\n \tcase \"$expect\" in expect72|expect.6030)\n-\t\ttest_expect_success \"$cmd $verb statNameWidth config with long name\" '\n+\t\ttest_expect_success \"$cmd $verb diff.statNameWidth with long name\" '\n \t\t\tgit -c diff.statNameWidth=30 $cmd $args >output &&\n \t\t\tgrep \" | \" output >actual &&\n \t\t\ttest_cmp $expect actual\n \t\t';;\n \tesac\n \t# Maximum width limit still applied when statNameWidth is ignored\n \tcase \"$expect\" in expect.60|expect.6030)\n-\t\ttest_expect_success \"$cmd --stat=width $verb statNameWidth config with long name\" '\n+\t\ttest_expect_success \"$cmd --stat=width $verb diff.statNameWidth with long name\" '\n \t\t\tgit -c diff.statNameWidth=30 $cmd $args --stat=60 >output &&\n \t\t\tgrep \" | \" output >actual &&\n \t\t\ttest_cmp $expect actual\n@@ -111,19 +111,19 @@ do\n \t\ttest_cmp $expect.6030 actual\n \t'\n \n-\ttest_expect_success \"$cmd --stat-name-width with long name\" '\n+\ttest_expect_success \"$cmd --stat-name-width=width with long name\" '\n \t\tgit $cmd $args --stat-name-width=30 >output &&\n \t\tgrep \" | \" output >actual &&\n \t\ttest_cmp $expect.6030 actual\n \t'\n done <<\\EOF\n expect2 format-patch --cover-letter -1 --stdout\n expect diff HEAD^ HEAD --stat\n expect show --stat\n expect log -1 --stat\n EOF\n \n-test_expect_success 'preparation for big change tests' '\n+test_expect_success 'preparation for big-change tests' '\n \t>abcd &&\n \tgit add abcd &&\n \tgit commit -m message &&\n@@ -139,7 +139,7 @@ cat >expect72 <<'EOF'\n  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n EOF\n-test_expect_success \"format-patch --cover-letter ignores COLUMNS (big change)\" '\n+test_expect_success \"format-patch --cover-letter ignores COLUMNS with big change\" '\n \tCOLUMNS=200 git format-patch -1 --stdout --cover-letter >output &&\n \tgrep \" | \" output >actual &&\n \ttest_cmp expect72 actual\n@@ -159,15 +159,15 @@ cat >expect200-graph <<'EOF'\n EOF\n while read verb expect cmd args\n do\n-\ttest_expect_success \"$cmd $verb COLUMNS (big change)\" '\n+\ttest_expect_success \"$cmd $verb COLUMNS with big change\" '\n \t\tCOLUMNS=200 git $cmd $args >output &&\n \t\tgrep \" | \" output >actual &&\n \t\ttest_cmp \"$expect\" actual\n \t'\n \n \tcase \"$cmd\" in diff|show) continue;; esac\n \n-\ttest_expect_success \"$cmd --graph $verb COLUMNS (big change)\" '\n+\ttest_expect_success \"$cmd --graph $verb COLUMNS with big change\" '\n \t\tCOLUMNS=200 git $cmd $args --graph >output &&\n \t\tgrep \" | \" output >actual &&\n \t\ttest_cmp \"$expect-graph\" actual\n@@ -187,15 +187,15 @@ cat >expect40-graph <<'EOF'\n EOF\n while read verb expect cmd args\n do\n-\ttest_expect_success \"$cmd $verb not enough COLUMNS (big change)\" '\n+\ttest_expect_success \"$cmd $verb not enough COLUMNS with big change\" '\n \t\tCOLUMNS=40 git $cmd $args >output &&\n \t\tgrep \" | \" output >actual &&\n \t\ttest_cmp \"$expect\" actual\n \t'\n \n \tcase \"$cmd\" in diff|show) continue;; esac\n \n-\ttest_expect_success \"$cmd --graph $verb not enough COLUMNS (big change)\" '\n+\ttest_expect_success \"$cmd --graph $verb not enough COLUMNS with big change\" '\n \t\tCOLUMNS=40 git $cmd $args --graph >output &&\n \t\tgrep \" | \" output >actual &&\n \t\ttest_cmp \"$expect-graph\" actual\n@@ -215,15 +215,15 @@ cat >expect40-graph <<'EOF'\n EOF\n while read verb expect cmd args\n do\n-\ttest_expect_success \"$cmd $verb statGraphWidth config\" '\n+\ttest_expect_success \"$cmd $verb diff.statGraphWidth\" '\n \t\tgit -c diff.statGraphWidth=26 $cmd $args >output &&\n \t\tgrep \" | \" output >actual &&\n \t\ttest_cmp \"$expect\" actual\n \t'\n \n \tcase \"$cmd\" in diff|show) continue;; esac\n \n-\ttest_expect_success \"$cmd --graph $verb statGraphWidth config\" '\n+\ttest_expect_success \"$cmd --graph $verb diff.statGraphWidth\" '\n \t\tgit -c diff.statGraphWidth=26 $cmd $args --graph >output &&\n \t\tgrep \" | \" output >actual &&\n \t\ttest_cmp \"$expect-graph\" actual\n@@ -255,33 +255,33 @@ do\n \t\ttest_cmp expect actual\n \t'\n \n-\ttest_expect_success \"$cmd --stat-graph-width with big change\" '\n+\ttest_expect_success \"$cmd --stat-graph-width=width with big change\" '\n \t\tgit $cmd $args --stat-graph-width=26 >output &&\n \t\tgrep \" | \" output >actual &&\n \t\ttest_cmp expect actual\n \t'\n \n \tcase \"$cmd\" in diff|show) continue;; esac\n \n \ttest_expect_success \"$cmd --stat-width=width --graph with big change\" '\n \t\tgit $cmd $args --stat-width=40 --graph >output &&\n \t\tgrep \" | \" output >actual &&\n \t\ttest_cmp expect-graph actual\n \t'\n \n-\ttest_expect_success \"$cmd --stat-graph-width --graph with big change\" '\n+\ttest_expect_success \"$cmd --stat-graph-width=width --graph with big change\" '\n \t\tgit $cmd $args --stat-graph-width=26 --graph >output &&\n \t\tgrep \" | \" output >actual &&\n \t\ttest_cmp expect-graph actual\n \t'\n done <<\\EOF\n format-patch -1 --stdout\n diff HEAD^ HEAD --stat\n show --stat\n log -1 --stat\n EOF\n \n-test_expect_success 'preparation for long filename tests' '\n+test_expect_success 'preparation for long-name tests' '\n \tcp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&\n \tgit add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&\n \tgit commit -m message\n@@ -329,15 +329,15 @@ cat >expect200-graph <<'EOF'\n EOF\n while read verb expect cmd args\n do\n-\ttest_expect_success \"$cmd $verb COLUMNS (long filename)\" '\n+\ttest_expect_success \"$cmd $verb COLUMNS with long name\" '\n \t\tCOLUMNS=200 git $cmd $args >output &&\n \t\tgrep \" | \" output >actual &&\n \t\ttest_cmp \"$expect\" actual\n \t'\n \n \tcase \"$cmd\" in diff|show) continue;; esac\n \n-\ttest_expect_success \"$cmd --graph $verb COLUMNS (long filename)\" '\n+\ttest_expect_success \"$cmd --graph $verb COLUMNS with long name\" '\n \t\tCOLUMNS=200 git $cmd $args --graph >output &&\n \t\tgrep \" | \" output >actual &&\n \t\ttest_cmp \"$expect-graph\" actual\n@@ -358,41 +358,57 @@ EOF\n while read verb expect cmd args\n do\n \ttest_expect_success COLUMNS_CAN_BE_1 \\\n-\t\t\"$cmd $verb prefix greater than COLUMNS (big change)\" '\n+\t\t\"$cmd $verb prefix greater than COLUMNS with big change\" '\n \t\tCOLUMNS=1 git $cmd $args >output &&\n \t\tgrep \" | \" output >actual &&\n \t\ttest_cmp \"$expect\" actual\n \t'\n \n \tcase \"$cmd\" in diff|show) continue;; esac\n \n \ttest_expect_success COLUMNS_CAN_BE_1 \\\n-\t\t\"$cmd --graph $verb prefix greater than COLUMNS (big change)\" '\n+\t\t\"$cmd --graph $verb prefix greater than COLUMNS with big change\" '\n \t\tCOLUMNS=1 git $cmd $args --graph >output &&\n \t\tgrep \" | \" output >actual &&\n \t\ttest_cmp \"$expect-graph\" actual\n \t'\n done <<\\EOF\n ignores expect72 format-patch -1 --stdout\n respects expect1 diff HEAD^ HEAD --stat\n respects expect1 show --stat\n respects expect1 log -1 --stat\n EOF\n \n cat >expect <<'EOF'\n  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n EOF\n-test_expect_success 'merge --stat respects COLUMNS (big change)' '\n-\tgit checkout -b branch HEAD^^ &&\n+test_expect_success 'merge --stat respects diff.statGraphWidth with big change' '\n+\tgit checkout -b branch1 HEAD^^ &&\n+\tgit -c diff.statGraphWidth=26 merge --stat --no-ff main^ >output &&\n+\tgrep \" | \" output >actual &&\n+\ttest_cmp expect40 actual\n+'\n+test_expect_success 'merge --stat respects COLUMNS with big change' '\n+\tgit checkout -b branch2 HEAD^^ &&\n \tCOLUMNS=100 git merge --stat --no-ff main^ >output &&\n \tgrep \" | \" output >actual &&\n \ttest_cmp expect actual\n '\n \n cat >expect <<'EOF'\n  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++\n EOF\n-test_expect_success 'merge --stat respects COLUMNS (long filename)' '\n+cat >expect.30 <<'EOF'\n+ ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++++++++++++++++++++++\n+EOF\n+test_expect_success 'merge --stat respects diff.statNameWidth with long name' '\n+\tgit switch branch1 &&\n+\tgit -c diff.statNameWidth=30 merge --stat --no-ff main >output &&\n+\tgrep \" | \" output >actual &&\n+\ttest_cmp expect.30 actual\n+'\n+test_expect_success 'merge --stat respects COLUMNS with long name' '\n+\tgit switch branch2 &&\n \tCOLUMNS=100 git merge --stat --no-ff main >output &&\n \tgrep \" | \" output >actual &&\n \ttest_cmp expect actual\n"},{"id":"482363","messageId":"0570bd5c26caef1ff66a643558305fb0@manjaro.org","threadId":"60262","inReplyTo":"d45d1dac1a20699e370905b88b6fd0ec296751e7.1695441501.git.dsimic@manjaro.org","subject":"Re: [PATCH v2] diff --stat: set the width defaults in a helper function","fromName":"Dragan Simic","fromEmail":"dsimic@manjaro.org","sentAt":"2023-09-27T02:30:53Z","receivedAt":"2023-09-27T03:14:49Z","isPatch":true,"sender":{"key":"dsimic@manjaro.org","avatar":null},"body":"Just a brief reminder about version 2 of this patch...\n\n\nOn 2023-09-23 06:01, Dragan Simic wrote:\n> Extract the commonly used initialization of the --stat-width=<width>,\n> --stat-name-width=<width> and --stat-graph-with=<width> parameters to \n> their\n> internal default values into a helper function, to avoid repeating the \n> same\n> initialization code in a few places.\n> \n> Add a couple of tests to additionally cover existing configuration \n> options\n> diff.statNameWidth=<width> and diff.statGraphWidth=<width> when used by\n> git-merge to generate --stat outputs.  This closes the gap that existed\n> previously in the --stat tests, and reduces the chances for having any\n> regressions introduced by this commit.\n> \n> While there, perform a small bunch of minor wording tweaks in the \n> improved\n> unit test, to improve its test-level consistency a bit.\n> \n> Signed-off-by: Dragan Simic <dsimic@manjaro.org>\n> ---\n>  builtin/diff.c         |  4 +--\n>  builtin/log.c          |  6 ++---\n>  builtin/merge.c        |  4 +--\n>  builtin/rebase.c       |  4 +--\n>  diff.c                 |  7 +++++\n>  diff.h                 |  1 +\n>  t/t4052-stat-output.sh | 60 ++++++++++++++++++++++++++----------------\n>  7 files changed, 51 insertions(+), 35 deletions(-)\n> \n> diff --git a/builtin/diff.c b/builtin/diff.c\n> index c0f564273a..55e7d21755 100644\n> --- a/builtin/diff.c\n> +++ b/builtin/diff.c\n> @@ -474,9 +474,7 @@ int cmd_diff(int argc, const char **argv, const\n> char *prefix)\n>  \trepo_init_revisions(the_repository, &rev, prefix);\n> \n>  \t/* Set up defaults that will apply to both no-index and regular \n> diffs. */\n> -\trev.diffopt.stat_width = -1;\n> -\trev.diffopt.stat_name_width = -1;\n> -\trev.diffopt.stat_graph_width = -1;\n> +\tinit_diffstat_widths(&rev.diffopt);\n>  \trev.diffopt.flags.allow_external = 1;\n>  \trev.diffopt.flags.allow_textconv = 1;\n> \n> diff --git a/builtin/log.c b/builtin/log.c\n> index 80e1be1645..ba775d7b5c 100644\n> --- a/builtin/log.c\n> +++ b/builtin/log.c\n> @@ -176,17 +176,15 @@ static void cmd_log_init_defaults(struct rev_info \n> *rev)\n>  \tif (default_follow)\n>  \t\trev->diffopt.flags.default_follow_renames = 1;\n>  \trev->verbose_header = 1;\n> +\tinit_diffstat_widths(&rev->diffopt);\n>  \trev->diffopt.flags.recursive = 1;\n> -\trev->diffopt.stat_width = -1; /* use full terminal width */\n> -\trev->diffopt.stat_name_width = -1; /* respect statNameWidth config */\n> -\trev->diffopt.stat_graph_width = -1; /* respect statGraphWidth config \n> */\n> +\trev->diffopt.flags.allow_textconv = 1;\n>  \trev->abbrev_commit = default_abbrev_commit;\n>  \trev->show_root_diff = default_show_root;\n>  \trev->subject_prefix = fmt_patch_subject_prefix;\n>  \trev->patch_name_max = fmt_patch_name_max;\n>  \trev->show_signature = default_show_signature;\n>  \trev->encode_email_headers = default_encode_email_headers;\n> -\trev->diffopt.flags.allow_textconv = 1;\n> \n>  \tif (default_date_mode)\n>  \t\tparse_date_format(default_date_mode, &rev->date_mode);\n> diff --git a/builtin/merge.c b/builtin/merge.c\n> index fd21c0d4f4..8f397cbeff 100644\n> --- a/builtin/merge.c\n> +++ b/builtin/merge.c\n> @@ -466,9 +466,7 @@ static void finish(struct commit *head_commit,\n>  \tif (new_head && show_diffstat) {\n>  \t\tstruct diff_options opts;\n>  \t\trepo_diff_setup(the_repository, &opts);\n> -\t\topts.stat_width = -1; /* use full terminal width */\n> -\t\topts.stat_name_width = -1; /* respect statNameWidth config */\n> -\t\topts.stat_graph_width = -1; /* respect statGraphWidth config */\n> +\t\tinit_diffstat_widths(&opts);\n>  \t\topts.output_format |=\n>  \t\t\tDIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;\n>  \t\topts.detect_rename = DIFF_DETECT_RENAME;\n> diff --git a/builtin/rebase.c b/builtin/rebase.c\n> index b93dca95a6..4783f90ac5 100644\n> --- a/builtin/rebase.c\n> +++ b/builtin/rebase.c\n> @@ -1806,9 +1806,7 @@ int cmd_rebase(int argc, const char **argv,\n> const char *prefix)\n> \n>  \t\t/* We want color (if set), but no pager */\n>  \t\trepo_diff_setup(the_repository, &opts);\n> -\t\topts.stat_width = -1; /* use full terminal width */\n> -\t\topts.stat_name_width = -1; /* respect statNameWidth config */\n> -\t\topts.stat_graph_width = -1; /* respect statGraphWidth config */\n> +\t\tinit_diffstat_widths(&opts);\n>  \t\topts.output_format |=\n>  \t\t\tDIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;\n>  \t\topts.detect_rename = DIFF_DETECT_RENAME;\n> diff --git a/diff.c b/diff.c\n> index 353e3b2cc9..2c602df10a 100644\n> --- a/diff.c\n> +++ b/diff.c\n> @@ -6936,6 +6936,13 @@ void diff_queued_diff_prefetch(void *repository)\n>  \toid_array_clear(&to_fetch);\n>  }\n> \n> +void init_diffstat_widths(struct diff_options *options)\n> +{\n> +\toptions->stat_width = -1;        /* use full terminal width */\n> +\toptions->stat_name_width = -1;   /* respect diff.statNameWidth config \n> */\n> +\toptions->stat_graph_width = -1;  /* respect diff.statGraphWidth \n> config */\n> +}\n> +\n>  void diffcore_std(struct diff_options *options)\n>  {\n>  \tint output_formats_to_prefetch = DIFF_FORMAT_DIFFSTAT |\n> diff --git a/diff.h b/diff.h\n> index caf1528bf0..66bd8aeb29 100644\n> --- a/diff.h\n> +++ b/diff.h\n> @@ -573,6 +573,7 @@ int git_config_rename(const char *var, const char \n> *value);\n> \n>  #define DIFF_PICKAXE_IGNORE_CASE\t32\n> \n> +void init_diffstat_widths(struct diff_options *);\n>  void diffcore_std(struct diff_options *);\n>  void diffcore_fix_diff_index(void);\n> \n> diff --git a/t/t4052-stat-output.sh b/t/t4052-stat-output.sh\n> index beb2ec2a55..7badd72488 100755\n> --- a/t/t4052-stat-output.sh\n> +++ b/t/t4052-stat-output.sh\n> @@ -12,7 +12,7 @@ TEST_PASSES_SANITIZE_LEAK=true\n>  . ./test-lib.sh\n>  . \"$TEST_DIRECTORY\"/lib-terminal.sh\n> \n> -# 120 character name\n> +# 120-character name\n>  name=aaaaaaaaaa\n>  name=$name$name$name$name$name$name$name$name$name$name$name$name\n>  test_expect_success 'preparation' '\n> @@ -58,15 +58,15 @@ while read verb expect cmd args\n>  do\n>  \t# No width limit applied when statNameWidth is ignored\n>  \tcase \"$expect\" in expect72|expect.6030)\n> -\t\ttest_expect_success \"$cmd $verb statNameWidth config with long name\" \n> '\n> +\t\ttest_expect_success \"$cmd $verb diff.statNameWidth with long name\" '\n>  \t\t\tgit -c diff.statNameWidth=30 $cmd $args >output &&\n>  \t\t\tgrep \" | \" output >actual &&\n>  \t\t\ttest_cmp $expect actual\n>  \t\t';;\n>  \tesac\n>  \t# Maximum width limit still applied when statNameWidth is ignored\n>  \tcase \"$expect\" in expect.60|expect.6030)\n> -\t\ttest_expect_success \"$cmd --stat=width $verb statNameWidth config\n> with long name\" '\n> +\t\ttest_expect_success \"$cmd --stat=width $verb diff.statNameWidth\n> with long name\" '\n>  \t\t\tgit -c diff.statNameWidth=30 $cmd $args --stat=60 >output &&\n>  \t\t\tgrep \" | \" output >actual &&\n>  \t\t\ttest_cmp $expect actual\n> @@ -111,19 +111,19 @@ do\n>  \t\ttest_cmp $expect.6030 actual\n>  \t'\n> \n> -\ttest_expect_success \"$cmd --stat-name-width with long name\" '\n> +\ttest_expect_success \"$cmd --stat-name-width=width with long name\" '\n>  \t\tgit $cmd $args --stat-name-width=30 >output &&\n>  \t\tgrep \" | \" output >actual &&\n>  \t\ttest_cmp $expect.6030 actual\n>  \t'\n>  done <<\\EOF\n>  expect2 format-patch --cover-letter -1 --stdout\n>  expect diff HEAD^ HEAD --stat\n>  expect show --stat\n>  expect log -1 --stat\n>  EOF\n> \n> -test_expect_success 'preparation for big change tests' '\n> +test_expect_success 'preparation for big-change tests' '\n>  \t>abcd &&\n>  \tgit add abcd &&\n>  \tgit commit -m message &&\n> @@ -139,7 +139,7 @@ cat >expect72 <<'EOF'\n>   abcd | 1000 \n> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n>   abcd | 1000 \n> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n>  EOF\n> -test_expect_success \"format-patch --cover-letter ignores COLUMNS (big\n> change)\" '\n> +test_expect_success \"format-patch --cover-letter ignores COLUMNS with\n> big change\" '\n>  \tCOLUMNS=200 git format-patch -1 --stdout --cover-letter >output &&\n>  \tgrep \" | \" output >actual &&\n>  \ttest_cmp expect72 actual\n> @@ -159,15 +159,15 @@ cat >expect200-graph <<'EOF'\n>  EOF\n>  while read verb expect cmd args\n>  do\n> -\ttest_expect_success \"$cmd $verb COLUMNS (big change)\" '\n> +\ttest_expect_success \"$cmd $verb COLUMNS with big change\" '\n>  \t\tCOLUMNS=200 git $cmd $args >output &&\n>  \t\tgrep \" | \" output >actual &&\n>  \t\ttest_cmp \"$expect\" actual\n>  \t'\n> \n>  \tcase \"$cmd\" in diff|show) continue;; esac\n> \n> -\ttest_expect_success \"$cmd --graph $verb COLUMNS (big change)\" '\n> +\ttest_expect_success \"$cmd --graph $verb COLUMNS with big change\" '\n>  \t\tCOLUMNS=200 git $cmd $args --graph >output &&\n>  \t\tgrep \" | \" output >actual &&\n>  \t\ttest_cmp \"$expect-graph\" actual\n> @@ -187,15 +187,15 @@ cat >expect40-graph <<'EOF'\n>  EOF\n>  while read verb expect cmd args\n>  do\n> -\ttest_expect_success \"$cmd $verb not enough COLUMNS (big change)\" '\n> +\ttest_expect_success \"$cmd $verb not enough COLUMNS with big change\" '\n>  \t\tCOLUMNS=40 git $cmd $args >output &&\n>  \t\tgrep \" | \" output >actual &&\n>  \t\ttest_cmp \"$expect\" actual\n>  \t'\n> \n>  \tcase \"$cmd\" in diff|show) continue;; esac\n> \n> -\ttest_expect_success \"$cmd --graph $verb not enough COLUMNS (big \n> change)\" '\n> +\ttest_expect_success \"$cmd --graph $verb not enough COLUMNS with big \n> change\" '\n>  \t\tCOLUMNS=40 git $cmd $args --graph >output &&\n>  \t\tgrep \" | \" output >actual &&\n>  \t\ttest_cmp \"$expect-graph\" actual\n> @@ -215,15 +215,15 @@ cat >expect40-graph <<'EOF'\n>  EOF\n>  while read verb expect cmd args\n>  do\n> -\ttest_expect_success \"$cmd $verb statGraphWidth config\" '\n> +\ttest_expect_success \"$cmd $verb diff.statGraphWidth\" '\n>  \t\tgit -c diff.statGraphWidth=26 $cmd $args >output &&\n>  \t\tgrep \" | \" output >actual &&\n>  \t\ttest_cmp \"$expect\" actual\n>  \t'\n> \n>  \tcase \"$cmd\" in diff|show) continue;; esac\n> \n> -\ttest_expect_success \"$cmd --graph $verb statGraphWidth config\" '\n> +\ttest_expect_success \"$cmd --graph $verb diff.statGraphWidth\" '\n>  \t\tgit -c diff.statGraphWidth=26 $cmd $args --graph >output &&\n>  \t\tgrep \" | \" output >actual &&\n>  \t\ttest_cmp \"$expect-graph\" actual\n> @@ -255,33 +255,33 @@ do\n>  \t\ttest_cmp expect actual\n>  \t'\n> \n> -\ttest_expect_success \"$cmd --stat-graph-width with big change\" '\n> +\ttest_expect_success \"$cmd --stat-graph-width=width with big change\" '\n>  \t\tgit $cmd $args --stat-graph-width=26 >output &&\n>  \t\tgrep \" | \" output >actual &&\n>  \t\ttest_cmp expect actual\n>  \t'\n> \n>  \tcase \"$cmd\" in diff|show) continue;; esac\n> \n>  \ttest_expect_success \"$cmd --stat-width=width --graph with big change\" \n> '\n>  \t\tgit $cmd $args --stat-width=40 --graph >output &&\n>  \t\tgrep \" | \" output >actual &&\n>  \t\ttest_cmp expect-graph actual\n>  \t'\n> \n> -\ttest_expect_success \"$cmd --stat-graph-width --graph with big change\" \n> '\n> +\ttest_expect_success \"$cmd --stat-graph-width=width --graph with big \n> change\" '\n>  \t\tgit $cmd $args --stat-graph-width=26 --graph >output &&\n>  \t\tgrep \" | \" output >actual &&\n>  \t\ttest_cmp expect-graph actual\n>  \t'\n>  done <<\\EOF\n>  format-patch -1 --stdout\n>  diff HEAD^ HEAD --stat\n>  show --stat\n>  log -1 --stat\n>  EOF\n> \n> -test_expect_success 'preparation for long filename tests' '\n> +test_expect_success 'preparation for long-name tests' '\n>  \tcp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&\n>  \tgit add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&\n>  \tgit commit -m message\n> @@ -329,15 +329,15 @@ cat >expect200-graph <<'EOF'\n>  EOF\n>  while read verb expect cmd args\n>  do\n> -\ttest_expect_success \"$cmd $verb COLUMNS (long filename)\" '\n> +\ttest_expect_success \"$cmd $verb COLUMNS with long name\" '\n>  \t\tCOLUMNS=200 git $cmd $args >output &&\n>  \t\tgrep \" | \" output >actual &&\n>  \t\ttest_cmp \"$expect\" actual\n>  \t'\n> \n>  \tcase \"$cmd\" in diff|show) continue;; esac\n> \n> -\ttest_expect_success \"$cmd --graph $verb COLUMNS (long filename)\" '\n> +\ttest_expect_success \"$cmd --graph $verb COLUMNS with long name\" '\n>  \t\tCOLUMNS=200 git $cmd $args --graph >output &&\n>  \t\tgrep \" | \" output >actual &&\n>  \t\ttest_cmp \"$expect-graph\" actual\n> @@ -358,41 +358,57 @@ EOF\n>  while read verb expect cmd args\n>  do\n>  \ttest_expect_success COLUMNS_CAN_BE_1 \\\n> -\t\t\"$cmd $verb prefix greater than COLUMNS (big change)\" '\n> +\t\t\"$cmd $verb prefix greater than COLUMNS with big change\" '\n>  \t\tCOLUMNS=1 git $cmd $args >output &&\n>  \t\tgrep \" | \" output >actual &&\n>  \t\ttest_cmp \"$expect\" actual\n>  \t'\n> \n>  \tcase \"$cmd\" in diff|show) continue;; esac\n> \n>  \ttest_expect_success COLUMNS_CAN_BE_1 \\\n> -\t\t\"$cmd --graph $verb prefix greater than COLUMNS (big change)\" '\n> +\t\t\"$cmd --graph $verb prefix greater than COLUMNS with big change\" '\n>  \t\tCOLUMNS=1 git $cmd $args --graph >output &&\n>  \t\tgrep \" | \" output >actual &&\n>  \t\ttest_cmp \"$expect-graph\" actual\n>  \t'\n>  done <<\\EOF\n>  ignores expect72 format-patch -1 --stdout\n>  respects expect1 diff HEAD^ HEAD --stat\n>  respects expect1 show --stat\n>  respects expect1 log -1 --stat\n>  EOF\n> \n>  cat >expect <<'EOF'\n>   abcd | 1000\n> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n>  EOF\n> -test_expect_success 'merge --stat respects COLUMNS (big change)' '\n> -\tgit checkout -b branch HEAD^^ &&\n> +test_expect_success 'merge --stat respects diff.statGraphWidth with\n> big change' '\n> +\tgit checkout -b branch1 HEAD^^ &&\n> +\tgit -c diff.statGraphWidth=26 merge --stat --no-ff main^ >output &&\n> +\tgrep \" | \" output >actual &&\n> +\ttest_cmp expect40 actual\n> +'\n> +test_expect_success 'merge --stat respects COLUMNS with big change' '\n> +\tgit checkout -b branch2 HEAD^^ &&\n>  \tCOLUMNS=100 git merge --stat --no-ff main^ >output &&\n>  \tgrep \" | \" output >actual &&\n>  \ttest_cmp expect actual\n>  '\n> \n>  cat >expect <<'EOF'\n>   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000\n> +++++++++++++++++++++++++++++++++++++++\n>  EOF\n> -test_expect_success 'merge --stat respects COLUMNS (long filename)' '\n> +cat >expect.30 <<'EOF'\n> + ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 \n> ++++++++++++++++++++++++++++++++++++++++\n> +EOF\n> +test_expect_success 'merge --stat respects diff.statNameWidth with \n> long name' '\n> +\tgit switch branch1 &&\n> +\tgit -c diff.statNameWidth=30 merge --stat --no-ff main >output &&\n> +\tgrep \" | \" output >actual &&\n> +\ttest_cmp expect.30 actual\n> +'\n> +test_expect_success 'merge --stat respects COLUMNS with long name' '\n> +\tgit switch branch2 &&\n>  \tCOLUMNS=100 git merge --stat --no-ff main >output &&\n>  \tgrep \" | \" output >actual &&\n>  \ttest_cmp expect actual\n"},{"id":"482439","messageId":"xmqq7coajb6a.fsf@gitster.g","threadId":"60262","inReplyTo":"0570bd5c26caef1ff66a643558305fb0@manjaro.org","subject":"Re: [PATCH v2] diff --stat: set the width defaults in a helper function","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-09-28T20:27:25Z","receivedAt":"2023-09-28T20:27:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dragan Simic <dsimic@manjaro.org> writes:\n\n> Just a brief reminder about version 2 of this patch...\n\nIt still is a bit premature to queue this before the topic, to which\nthis is a clean-up for, graduates to the 'master' branch, though.\n"},{"id":"482440","messageId":"69302fd3955f12f282a579d57143e5ed@manjaro.org","threadId":"60262","inReplyTo":"xmqq7coajb6a.fsf@gitster.g","subject":"Re: [PATCH v2] diff --stat: set the width defaults in a helper function","fromName":"Dragan Simic","fromEmail":"dsimic@manjaro.org","sentAt":"2023-09-28T20:35:28Z","receivedAt":"2023-09-28T20:35:35Z","isPatch":true,"sender":{"key":"dsimic@manjaro.org","avatar":null},"body":"On 2023-09-28 22:27, Junio C Hamano wrote:\n> Dragan Simic <dsimic@manjaro.org> writes:\n> \n>> Just a brief reminder about version 2 of this patch...\n> \n> It still is a bit premature to queue this before the topic, to which\n> this is a clean-up for, graduates to the 'master' branch, though.\n\nOh, I agree, thanks.  Actually, I just wanted to check with you does the \nversion 2 of this patch require any further cleanups or improvements?\n"}]}