diff --stat: add config option to limit filename width
Add new configuration option diff.statNameWidth=<width> that is equivalent
to the command-line option --stat-name-width=<width>, but it is ignored
by format-patch. This follows the logic established by the already
existing configuration option diff.statGraphWidth=<width>.
Limiting the widths of names and graphs in the --stat output makes sense
for interactive work on wide terminals with many columns, hence the support
for these configuration options. They don't affect format-patch because
it already adheres to the traditional 80-column standard.
Update the documentation and add more tests to cover new configuration
option diff.statNameWidth=<width>. While there, perform a few minor code
and whitespace cleanups here and there, as spotted.
Signed-off-by: Dragan Simic <dsimic@manjaro.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Dragan Simic committedSep 11, 2023 at 17:39 UTCbd48adc31d0522e7877aa494ce7df91581e09587
9 files changed+60-18
Documentation/config/diff.txt
+4
index 35a7bf86d7..9391c77e55 100644--- a/Documentation/config/diff.txt+++ b/Documentation/config/diff.txt@@ -52,6 +52,10 @@ directories with less than 10% of the total amount of changed files, and accumulating child directory counts in the parent directories: `files,10,cumulative`.+diff.statNameWidth::+ Limit the width of the filename part in --stat output. If set, applies+ to all commands generating --stat output except format-patch.+ diff.statGraphWidth:: Limit the width of the graph part in --stat output. If set, applies to all commands generating --stat output except format-patch.
Documentation/diff-options.txt
+9-8
index c07488b123..35fae7c87c 100644--- a/Documentation/diff-options.txt+++ b/Documentation/diff-options.txt@@ -204,14 +204,15 @@ have to use `--diff-algorithm=default` option. part. Maximum width defaults to terminal width, or 80 columns if not connected to a terminal, and can be overridden by `<width>`. The width of the filename part can be limited by- giving another width `<name-width>` after a comma. The width- of the graph part can be limited by using- `--stat-graph-width=<width>` (affects all commands generating- a stat graph) or by setting `diff.statGraphWidth=<width>`- (does not affect `git format-patch`).- By giving a third parameter `<count>`, you can limit the- output to the first `<count>` lines, followed by `...` if- there are more.+ giving another width `<name-width>` after a comma or by setting+ `diff.statNameWidth=<width>`. The width of the graph part can be+ limited by using `--stat-graph-width=<width>` or by setting+ `diff.statGraphWidth=<width>`. Using `--stat` or+ `--stat-graph-width` affects all commands generating a stat graph,+ while setting `diff.statNameWidth` or `diff.statGraphWidth`+ does not affect `git format-patch`.+ By giving a third parameter `<count>`, you can limit the output to+ the first `<count>` lines, followed by `...` if there are more. + These parameters can also be set individually with `--stat-width=<width>`, `--stat-name-width=<name-width>` and `--stat-count=<count>`.
builtin/diff.c
+1
index 0b313549c7..c0f564273a 100644--- a/builtin/diff.c+++ b/builtin/diff.c@@ -475,6 +475,7 @@ int cmd_diff(int argc, const char **argv, const char *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; rev.diffopt.flags.allow_external = 1; rev.diffopt.flags.allow_textconv = 1;