Skip to content

Commit df44483

Browse files
keszybzgitster
authored andcommitted
diff --stat: add config option to limit graph width
Config option diff.statGraphWidth=<width> is equivalent to --stat-graph-width=<width>, except that the config option is ignored by format-patch. For the graph-width limiting to be usable, it should happen 'automatically' once configured, hence the config option. Nevertheless, graph width limiting only makes sense when used on a wide terminal, so it should not influence the output of format-patch, which adheres to the 80-column standard. Signed-off-by: Zbigniew Jędrzejewski-Szmek <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 969fe57 commit df44483

File tree

8 files changed

+32
-8
lines changed

8 files changed

+32
-8
lines changed

Documentation/diff-config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ directories with less than 10% of the total amount of changed files,
5252
and accumulating child directory counts in the parent directories:
5353
`files,10,cumulative`.
5454

55+
diff.statGraphWidth::
56+
Limit the width of the graph part in --stat output. If set, applies
57+
to all commands generating --stat outuput except format-patch.
58+
5559
diff.external::
5660
If this config variable is set, diff generation is not
5761
performed using the internal diff machinery, but using the

Documentation/diff-options.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ endif::git-format-patch[]
5454

5555
--stat[=<width>[,<name-width>[,<count>]]]::
5656
Generate a diffstat. By default, as much space as necessary
57-
will be used for the filename part, and the rest for
58-
the graph part. Maximum width defaults to terminal width,
59-
or 80 columns if not connected to a terminal, and can be
60-
overriden by `<width>`. The width of the filename part can be
61-
limited by giving another width `<name-width>` after a comma.
62-
The width of the graph part can be limited by using
63-
`--stat-graph-width=<width>`.
57+
will be used for the filename part, and the rest for the graph
58+
part. Maximum width defaults to terminal width, or 80 columns
59+
if not connected to a terminal, and can be overriden by
60+
`<width>`. The width of the filename part can be limited by
61+
giving another width `<name-width>` after a comma. The width
62+
of the graph part can be limited by using
63+
`--stat-graph-width=<width>` (affects all commands generating
64+
a stat graph) or by setting `diff.statGraphWidth=<width>`
65+
(does not affect `git format-patch`).
6466
By giving a third parameter `<count>`, you can limit the
6567
output to the first `<count>` lines, followed by `...` if
6668
there are more.

builtin/diff.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,9 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
285285
/* Otherwise, we are doing the usual "git" diff */
286286
rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
287287

288-
/* Scale to real terminal size */
288+
/* Scale to real terminal size and respect statGraphWidth config */
289289
rev.diffopt.stat_width = -1;
290+
rev.diffopt.stat_graph_width = -1;
290291

291292
/* Default to let external and textconv be used */
292293
DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);

builtin/log.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static void cmd_log_init_defaults(struct rev_info *rev)
7878
rev->verbose_header = 1;
7979
DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
8080
rev->diffopt.stat_width = -1; /* use full terminal width */
81+
rev->diffopt.stat_graph_width = -1; /* respect statGraphWidth config */
8182
rev->abbrev_commit = default_abbrev_commit;
8283
rev->show_root_diff = default_show_root;
8384
rev->subject_prefix = fmt_patch_subject_prefix;

builtin/merge.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ static void finish(struct commit *head_commit,
400400
struct diff_options opts;
401401
diff_setup(&opts);
402402
opts.stat_width = -1; /* use full terminal width */
403+
opts.stat_graph_width = -1; /* respect statGraphWidth config */
403404
opts.output_format |=
404405
DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
405406
opts.detect_rename = DIFF_DETECT_RENAME;

contrib/completion/git-completion.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,7 @@ _git_config ()
21182118
core.whitespace
21192119
core.worktree
21202120
diff.autorefreshindex
2121+
diff.statGraphWidth
21212122
diff.external
21222123
diff.ignoreSubmodules
21232124
diff.mnemonicprefix

diff.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static const char *external_diff_cmd_cfg;
3131
int diff_auto_refresh_index = 1;
3232
static int diff_mnemonic_prefix;
3333
static int diff_no_prefix;
34+
static int diff_stat_graph_width;
3435
static int diff_dirstat_permille_default = 30;
3536
static struct diff_options default_diff_options;
3637

@@ -156,6 +157,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
156157
diff_no_prefix = git_config_bool(var, value);
157158
return 0;
158159
}
160+
if (!strcmp(var, "diff.statgraphwidth")) {
161+
diff_stat_graph_width = git_config_int(var, value);
162+
return 0;
163+
}
159164
if (!strcmp(var, "diff.external"))
160165
return git_config_string(&external_diff_cmd_cfg, var, value);
161166
if (!strcmp(var, "diff.wordregex"))
@@ -1398,6 +1403,9 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
13981403
else
13991404
width = options->stat_width ? options->stat_width : 80;
14001405

1406+
if (options->stat_graph_width == -1)
1407+
options->stat_graph_width = diff_stat_graph_width;
1408+
14011409
/*
14021410
* Guarantee 3/8*16==6 for the graph part
14031411
* and 5/8*16==10 for the filename part

t/t4052-stat-output.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ do
112112
grep " | " output >actual &&
113113
test_cmp "$expect" actual
114114
'
115+
116+
test_expect_success "$cmd $verb statGraphWidth config" '
117+
git -c diff.statGraphWidth=26 $cmd $args >output
118+
grep " | " output >actual &&
119+
test_cmp "$expect" actual
120+
'
115121
done <<\EOF
116122
ignores expect80 format-patch -1 --stdout
117123
respects expect40 diff HEAD^ HEAD --stat

0 commit comments

Comments
 (0)