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>
Zbigniew Jędrzejewski-Szmek committed
Mar 1, 2012 at 13:26 UTC
df44483a5dde62f4b49c80fd90d7fe12ddcfb084
8 files changed
+32
-8
Documentation/diff-config.txt
+4
@@ -52,6 +52,10 @@ directories with less than 10% of the total amount of changed files,
52
and accumulating child directory counts in the parent directories:
53
`files,10,cumulative`.
54
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
+
59
diff.external::
60
If this config variable is set, diff generation is not
61
performed using the internal diff machinery, but using the
Documentation/diff-options.txt
+9
-7
@@ -54,13 +54,15 @@ endif::git-format-patch[]
54
55
--stat[=<width>[,<name-width>[,<count>]]]::
56
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`).
66
By giving a third parameter `<count>`, you can limit the
67
output to the first `<count>` lines, followed by `...` if
68
there are more.
builtin/diff.c
+2
-1
@@ -285,8 +285,9 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
285
/* Otherwise, we are doing the usual "git" diff */
286
rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
287
288
- /* Scale to real terminal size */
288
+ /* Scale to real terminal size and respect statGraphWidth config */
289
rev.diffopt.stat_width = -1;
290
+ rev.diffopt.stat_graph_width = -1;
291
292
/* Default to let external and textconv be used */
293
DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);
builtin/log.c
+1
@@ -78,6 +78,7 @@ static void cmd_log_init_defaults(struct rev_info *rev)
78
rev->verbose_header = 1;
79
DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
80
rev->diffopt.stat_width = -1; /* use full terminal width */
81
+ rev->diffopt.stat_graph_width = -1; /* respect statGraphWidth config */
82
rev->abbrev_commit = default_abbrev_commit;
83
rev->show_root_diff = default_show_root;
84
rev->subject_prefix = fmt_patch_subject_prefix;
builtin/merge.c
+1
@@ -400,6 +400,7 @@ static void finish(struct commit *head_commit,
400
struct diff_options opts;
401
diff_setup(&opts);
402
opts.stat_width = -1; /* use full terminal width */
403
+ opts.stat_graph_width = -1; /* respect statGraphWidth config */
404
opts.output_format |=
405
DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
406
opts.detect_rename = DIFF_DETECT_RENAME;
contrib/completion/git-completion.bash
+1
@@ -2118,6 +2118,7 @@ _git_config ()
2118
core.whitespace
2119
core.worktree
2120
diff.autorefreshindex
2121
+ diff.statGraphWidth
2122
diff.external
2123
diff.ignoreSubmodules
2124
diff.mnemonicprefix
diff.c
+8
@@ -31,6 +31,7 @@ static const char *external_diff_cmd_cfg;
31
int diff_auto_refresh_index = 1;
32
static int diff_mnemonic_prefix;
33
static int diff_no_prefix;
34
+static int diff_stat_graph_width;
35
static int diff_dirstat_permille_default = 30;
36
static struct diff_options default_diff_options;
37
@@ -156,6 +157,10 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
157
diff_no_prefix = git_config_bool(var, value);
158
return 0;
159
}
160
+ if (!strcmp(var, "diff.statgraphwidth")) {
161
+ diff_stat_graph_width = git_config_int(var, value);
162
+ return 0;
163
+ }
164
if (!strcmp(var, "diff.external"))
165
return git_config_string(&external_diff_cmd_cfg, var, value);
166
if (!strcmp(var, "diff.wordregex"))
@@ -1398,6 +1403,9 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1403
else
1404
width = options->stat_width ? options->stat_width : 80;
1405
1406
+ if (options->stat_graph_width == -1)
1407
+ options->stat_graph_width = diff_stat_graph_width;
1408
+
1409
/*
1410
* Guarantee 3/8*16==6 for the graph part
1411
* and 5/8*16==10 for the filename part
t/t4052-stat-output.sh
+6
@@ -112,6 +112,12 @@ do
112
grep " | " output >actual &&
113
test_cmp "$expect" actual
114
'
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
+ '
121
done <<\EOF
122
ignores expect80 format-patch -1 --stdout
123
respects expect40 diff HEAD^ HEAD --stat