From bd48adc31d0522e7877aa494ce7df91581e09587 Mon Sep 17 00:00:00 2001 From: Dragan Simic Date: Mon, 11 Sep 2023 17:39:44 +0200 Subject: diff --stat: add config option to limit filename width Add new configuration option diff.statNameWidth= that is equivalent to the command-line option --stat-name-width=, but it is ignored by format-patch. This follows the logic established by the already existing configuration option diff.statGraphWidth=. 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=. While there, perform a few minor code and whitespace cleanups here and there, as spotted. Signed-off-by: Dragan Simic Signed-off-by: Junio C Hamano --- diff.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'diff.c') diff --git a/diff.c b/diff.c index bccb018da4..353e3b2cc9 100644 --- a/diff.c +++ b/diff.c @@ -65,6 +65,7 @@ int diff_auto_refresh_index = 1; static int diff_mnemonic_prefix; static int diff_no_prefix; static int diff_relative; +static int diff_stat_name_width; static int diff_stat_graph_width; static int diff_dirstat_permille_default = 30; static struct diff_options default_diff_options; @@ -410,6 +411,10 @@ int git_diff_ui_config(const char *var, const char *value, diff_relative = git_config_bool(var, value); return 0; } + if (!strcmp(var, "diff.statnamewidth")) { + diff_stat_name_width = git_config_int(var, value, ctx->kvi); + return 0; + } if (!strcmp(var, "diff.statgraphwidth")) { diff_stat_graph_width = git_config_int(var, value, ctx->kvi); return 0; @@ -2704,12 +2709,14 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options) number_width = decimal_width(max_change) > number_width ? decimal_width(max_change) : number_width; + if (options->stat_name_width == -1) + options->stat_name_width = diff_stat_name_width; if (options->stat_graph_width == -1) options->stat_graph_width = diff_stat_graph_width; /* - * Guarantee 3/8*16==6 for the graph part - * and 5/8*16==10 for the filename part + * Guarantee 3/8*16 == 6 for the graph part + * and 5/8*16 == 10 for the filename part */ if (width < 16 + 6 + number_width) width = 16 + 6 + number_width; -- cgit v1.2.3