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 <zbyszek@in.waw.pl>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2012-03-01 13:26:46 +01:00 committed by Junio C Hamano
parent 969fe57b84
commit df44483a5d
8 changed files with 32 additions and 8 deletions

View File

@ -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: and accumulating child directory counts in the parent directories:
`files,10,cumulative`. `files,10,cumulative`.
diff.statGraphWidth::
Limit the width of the graph part in --stat output. If set, applies
to all commands generating --stat outuput except format-patch.
diff.external:: diff.external::
If this config variable is set, diff generation is not If this config variable is set, diff generation is not
performed using the internal diff machinery, but using the performed using the internal diff machinery, but using the

View File

@ -54,13 +54,15 @@ endif::git-format-patch[]
--stat[=<width>[,<name-width>[,<count>]]]:: --stat[=<width>[,<name-width>[,<count>]]]::
Generate a diffstat. By default, as much space as necessary Generate a diffstat. By default, as much space as necessary
will be used for the filename part, and the rest for will be used for the filename part, and the rest for the graph
the graph part. Maximum width defaults to terminal width, part. Maximum width defaults to terminal width, or 80 columns
or 80 columns if not connected to a terminal, and can be if not connected to a terminal, and can be overriden by
overriden by `<width>`. The width of the filename part can be `<width>`. The width of the filename part can be limited by
limited by giving another width `<name-width>` after a comma. giving another width `<name-width>` after a comma. The width
The width of the graph part can be limited by using of the graph part can be limited by using
`--stat-graph-width=<width>`. `--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 By giving a third parameter `<count>`, you can limit the
output to the first `<count>` lines, followed by `...` if output to the first `<count>` lines, followed by `...` if
there are more. there are more.

View File

@ -285,8 +285,9 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
/* Otherwise, we are doing the usual "git" diff */ /* Otherwise, we are doing the usual "git" diff */
rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index; rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
/* Scale to real terminal size */ /* Scale to real terminal size and respect statGraphWidth config */
rev.diffopt.stat_width = -1; rev.diffopt.stat_width = -1;
rev.diffopt.stat_graph_width = -1;
/* Default to let external and textconv be used */ /* Default to let external and textconv be used */
DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL); DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);

View File

@ -78,6 +78,7 @@ static void cmd_log_init_defaults(struct rev_info *rev)
rev->verbose_header = 1; rev->verbose_header = 1;
DIFF_OPT_SET(&rev->diffopt, RECURSIVE); DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
rev->diffopt.stat_width = -1; /* use full terminal width */ rev->diffopt.stat_width = -1; /* use full terminal width */
rev->diffopt.stat_graph_width = -1; /* respect statGraphWidth config */
rev->abbrev_commit = default_abbrev_commit; rev->abbrev_commit = default_abbrev_commit;
rev->show_root_diff = default_show_root; rev->show_root_diff = default_show_root;
rev->subject_prefix = fmt_patch_subject_prefix; rev->subject_prefix = fmt_patch_subject_prefix;

View File

@ -400,6 +400,7 @@ static void finish(struct commit *head_commit,
struct diff_options opts; struct diff_options opts;
diff_setup(&opts); diff_setup(&opts);
opts.stat_width = -1; /* use full terminal width */ opts.stat_width = -1; /* use full terminal width */
opts.stat_graph_width = -1; /* respect statGraphWidth config */
opts.output_format |= opts.output_format |=
DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT; DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
opts.detect_rename = DIFF_DETECT_RENAME; opts.detect_rename = DIFF_DETECT_RENAME;

View File

@ -2118,6 +2118,7 @@ _git_config ()
core.whitespace core.whitespace
core.worktree core.worktree
diff.autorefreshindex diff.autorefreshindex
diff.statGraphWidth
diff.external diff.external
diff.ignoreSubmodules diff.ignoreSubmodules
diff.mnemonicprefix diff.mnemonicprefix

8
diff.c
View File

@ -31,6 +31,7 @@ static const char *external_diff_cmd_cfg;
int diff_auto_refresh_index = 1; int diff_auto_refresh_index = 1;
static int diff_mnemonic_prefix; static int diff_mnemonic_prefix;
static int diff_no_prefix; static int diff_no_prefix;
static int diff_stat_graph_width;
static int diff_dirstat_permille_default = 30; static int diff_dirstat_permille_default = 30;
static struct diff_options default_diff_options; static struct diff_options default_diff_options;
@ -156,6 +157,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
diff_no_prefix = git_config_bool(var, value); diff_no_prefix = git_config_bool(var, value);
return 0; return 0;
} }
if (!strcmp(var, "diff.statgraphwidth")) {
diff_stat_graph_width = git_config_int(var, value);
return 0;
}
if (!strcmp(var, "diff.external")) if (!strcmp(var, "diff.external"))
return git_config_string(&external_diff_cmd_cfg, var, value); return git_config_string(&external_diff_cmd_cfg, var, value);
if (!strcmp(var, "diff.wordregex")) if (!strcmp(var, "diff.wordregex"))
@ -1398,6 +1403,9 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
else else
width = options->stat_width ? options->stat_width : 80; width = options->stat_width ? options->stat_width : 80;
if (options->stat_graph_width == -1)
options->stat_graph_width = diff_stat_graph_width;
/* /*
* Guarantee 3/8*16==6 for the graph part * Guarantee 3/8*16==6 for the graph part
* and 5/8*16==10 for the filename part * and 5/8*16==10 for the filename part

View File

@ -112,6 +112,12 @@ do
grep " | " output >actual && grep " | " output >actual &&
test_cmp "$expect" actual test_cmp "$expect" actual
' '
test_expect_success "$cmd $verb statGraphWidth config" '
git -c diff.statGraphWidth=26 $cmd $args >output
grep " | " output >actual &&
test_cmp "$expect" actual
'
done <<\EOF done <<\EOF
ignores expect80 format-patch -1 --stdout ignores expect80 format-patch -1 --stdout
respects expect40 diff HEAD^ HEAD --stat respects expect40 diff HEAD^ HEAD --stat