Skip to content

Commit afb0d08

Browse files
committed
Merge branch 'ds/init-diffstat-width'
Code clean-up. * ds/init-diffstat-width: diff --stat: set the width defaults in a helper function
2 parents a7a2d10 + 4ca7a3f commit afb0d08

File tree

7 files changed

+51
-35
lines changed

7 files changed

+51
-35
lines changed

builtin/diff.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
474474
repo_init_revisions(the_repository, &rev, prefix);
475475

476476
/* Set up defaults that will apply to both no-index and regular diffs. */
477-
rev.diffopt.stat_width = -1;
478-
rev.diffopt.stat_name_width = -1;
479-
rev.diffopt.stat_graph_width = -1;
477+
init_diffstat_widths(&rev.diffopt);
480478
rev.diffopt.flags.allow_external = 1;
481479
rev.diffopt.flags.allow_textconv = 1;
482480

builtin/log.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,15 @@ static void cmd_log_init_defaults(struct rev_info *rev)
176176
if (default_follow)
177177
rev->diffopt.flags.default_follow_renames = 1;
178178
rev->verbose_header = 1;
179+
init_diffstat_widths(&rev->diffopt);
179180
rev->diffopt.flags.recursive = 1;
180-
rev->diffopt.stat_width = -1; /* use full terminal width */
181-
rev->diffopt.stat_name_width = -1; /* respect statNameWidth config */
182-
rev->diffopt.stat_graph_width = -1; /* respect statGraphWidth config */
181+
rev->diffopt.flags.allow_textconv = 1;
183182
rev->abbrev_commit = default_abbrev_commit;
184183
rev->show_root_diff = default_show_root;
185184
rev->subject_prefix = fmt_patch_subject_prefix;
186185
rev->patch_name_max = fmt_patch_name_max;
187186
rev->show_signature = default_show_signature;
188187
rev->encode_email_headers = default_encode_email_headers;
189-
rev->diffopt.flags.allow_textconv = 1;
190188

191189
if (default_date_mode)
192190
parse_date_format(default_date_mode, &rev->date_mode);

builtin/merge.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,7 @@ static void finish(struct commit *head_commit,
466466
if (new_head && show_diffstat) {
467467
struct diff_options opts;
468468
repo_diff_setup(the_repository, &opts);
469-
opts.stat_width = -1; /* use full terminal width */
470-
opts.stat_name_width = -1; /* respect statNameWidth config */
471-
opts.stat_graph_width = -1; /* respect statGraphWidth config */
469+
init_diffstat_widths(&opts);
472470
opts.output_format |=
473471
DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
474472
opts.detect_rename = DIFF_DETECT_RENAME;

builtin/rebase.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,9 +1803,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
18031803

18041804
/* We want color (if set), but no pager */
18051805
repo_diff_setup(the_repository, &opts);
1806-
opts.stat_width = -1; /* use full terminal width */
1807-
opts.stat_name_width = -1; /* respect statNameWidth config */
1808-
opts.stat_graph_width = -1; /* respect statGraphWidth config */
1806+
init_diffstat_widths(&opts);
18091807
opts.output_format |=
18101808
DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
18111809
opts.detect_rename = DIFF_DETECT_RENAME;

diff.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6936,6 +6936,13 @@ void diff_queued_diff_prefetch(void *repository)
69366936
oid_array_clear(&to_fetch);
69376937
}
69386938

6939+
void init_diffstat_widths(struct diff_options *options)
6940+
{
6941+
options->stat_width = -1; /* use full terminal width */
6942+
options->stat_name_width = -1; /* respect diff.statNameWidth config */
6943+
options->stat_graph_width = -1; /* respect diff.statGraphWidth config */
6944+
}
6945+
69396946
void diffcore_std(struct diff_options *options)
69406947
{
69416948
int output_formats_to_prefetch = DIFF_FORMAT_DIFFSTAT |

diff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ int git_config_rename(const char *var, const char *value);
573573

574574
#define DIFF_PICKAXE_IGNORE_CASE 32
575575

576+
void init_diffstat_widths(struct diff_options *);
576577
void diffcore_std(struct diff_options *);
577578
void diffcore_fix_diff_index(void);
578579

t/t4052-stat-output.sh

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TEST_PASSES_SANITIZE_LEAK=true
1212
. ./test-lib.sh
1313
. "$TEST_DIRECTORY"/lib-terminal.sh
1414

15-
# 120 character name
15+
# 120-character name
1616
name=aaaaaaaaaa
1717
name=$name$name$name$name$name$name$name$name$name$name$name$name
1818
test_expect_success 'preparation' '
@@ -58,15 +58,15 @@ while read verb expect cmd args
5858
do
5959
# No width limit applied when statNameWidth is ignored
6060
case "$expect" in expect72|expect.6030)
61-
test_expect_success "$cmd $verb statNameWidth config with long name" '
61+
test_expect_success "$cmd $verb diff.statNameWidth with long name" '
6262
git -c diff.statNameWidth=30 $cmd $args >output &&
6363
grep " | " output >actual &&
6464
test_cmp $expect actual
6565
';;
6666
esac
6767
# Maximum width limit still applied when statNameWidth is ignored
6868
case "$expect" in expect.60|expect.6030)
69-
test_expect_success "$cmd --stat=width $verb statNameWidth config with long name" '
69+
test_expect_success "$cmd --stat=width $verb diff.statNameWidth with long name" '
7070
git -c diff.statNameWidth=30 $cmd $args --stat=60 >output &&
7171
grep " | " output >actual &&
7272
test_cmp $expect actual
@@ -111,7 +111,7 @@ do
111111
test_cmp $expect.6030 actual
112112
'
113113

114-
test_expect_success "$cmd --stat-name-width with long name" '
114+
test_expect_success "$cmd --stat-name-width=width with long name" '
115115
git $cmd $args --stat-name-width=30 >output &&
116116
grep " | " output >actual &&
117117
test_cmp $expect.6030 actual
@@ -123,7 +123,7 @@ expect show --stat
123123
expect log -1 --stat
124124
EOF
125125

126-
test_expect_success 'preparation for big change tests' '
126+
test_expect_success 'preparation for big-change tests' '
127127
>abcd &&
128128
git add abcd &&
129129
git commit -m message &&
@@ -139,7 +139,7 @@ cat >expect72 <<'EOF'
139139
abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
140140
abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
141141
EOF
142-
test_expect_success "format-patch --cover-letter ignores COLUMNS (big change)" '
142+
test_expect_success "format-patch --cover-letter ignores COLUMNS with big change" '
143143
COLUMNS=200 git format-patch -1 --stdout --cover-letter >output &&
144144
grep " | " output >actual &&
145145
test_cmp expect72 actual
@@ -159,15 +159,15 @@ cat >expect200-graph <<'EOF'
159159
EOF
160160
while read verb expect cmd args
161161
do
162-
test_expect_success "$cmd $verb COLUMNS (big change)" '
162+
test_expect_success "$cmd $verb COLUMNS with big change" '
163163
COLUMNS=200 git $cmd $args >output &&
164164
grep " | " output >actual &&
165165
test_cmp "$expect" actual
166166
'
167167

168168
case "$cmd" in diff|show) continue;; esac
169169

170-
test_expect_success "$cmd --graph $verb COLUMNS (big change)" '
170+
test_expect_success "$cmd --graph $verb COLUMNS with big change" '
171171
COLUMNS=200 git $cmd $args --graph >output &&
172172
grep " | " output >actual &&
173173
test_cmp "$expect-graph" actual
@@ -187,15 +187,15 @@ cat >expect40-graph <<'EOF'
187187
EOF
188188
while read verb expect cmd args
189189
do
190-
test_expect_success "$cmd $verb not enough COLUMNS (big change)" '
190+
test_expect_success "$cmd $verb not enough COLUMNS with big change" '
191191
COLUMNS=40 git $cmd $args >output &&
192192
grep " | " output >actual &&
193193
test_cmp "$expect" actual
194194
'
195195

196196
case "$cmd" in diff|show) continue;; esac
197197

198-
test_expect_success "$cmd --graph $verb not enough COLUMNS (big change)" '
198+
test_expect_success "$cmd --graph $verb not enough COLUMNS with big change" '
199199
COLUMNS=40 git $cmd $args --graph >output &&
200200
grep " | " output >actual &&
201201
test_cmp "$expect-graph" actual
@@ -215,15 +215,15 @@ cat >expect40-graph <<'EOF'
215215
EOF
216216
while read verb expect cmd args
217217
do
218-
test_expect_success "$cmd $verb statGraphWidth config" '
218+
test_expect_success "$cmd $verb diff.statGraphWidth" '
219219
git -c diff.statGraphWidth=26 $cmd $args >output &&
220220
grep " | " output >actual &&
221221
test_cmp "$expect" actual
222222
'
223223

224224
case "$cmd" in diff|show) continue;; esac
225225

226-
test_expect_success "$cmd --graph $verb statGraphWidth config" '
226+
test_expect_success "$cmd --graph $verb diff.statGraphWidth" '
227227
git -c diff.statGraphWidth=26 $cmd $args --graph >output &&
228228
grep " | " output >actual &&
229229
test_cmp "$expect-graph" actual
@@ -255,7 +255,7 @@ do
255255
test_cmp expect actual
256256
'
257257

258-
test_expect_success "$cmd --stat-graph-width with big change" '
258+
test_expect_success "$cmd --stat-graph-width=width with big change" '
259259
git $cmd $args --stat-graph-width=26 >output &&
260260
grep " | " output >actual &&
261261
test_cmp expect actual
@@ -269,7 +269,7 @@ do
269269
test_cmp expect-graph actual
270270
'
271271

272-
test_expect_success "$cmd --stat-graph-width --graph with big change" '
272+
test_expect_success "$cmd --stat-graph-width=width --graph with big change" '
273273
git $cmd $args --stat-graph-width=26 --graph >output &&
274274
grep " | " output >actual &&
275275
test_cmp expect-graph actual
@@ -281,7 +281,7 @@ show --stat
281281
log -1 --stat
282282
EOF
283283

284-
test_expect_success 'preparation for long filename tests' '
284+
test_expect_success 'preparation for long-name tests' '
285285
cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
286286
git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
287287
git commit -m message
@@ -329,15 +329,15 @@ cat >expect200-graph <<'EOF'
329329
EOF
330330
while read verb expect cmd args
331331
do
332-
test_expect_success "$cmd $verb COLUMNS (long filename)" '
332+
test_expect_success "$cmd $verb COLUMNS with long name" '
333333
COLUMNS=200 git $cmd $args >output &&
334334
grep " | " output >actual &&
335335
test_cmp "$expect" actual
336336
'
337337

338338
case "$cmd" in diff|show) continue;; esac
339339

340-
test_expect_success "$cmd --graph $verb COLUMNS (long filename)" '
340+
test_expect_success "$cmd --graph $verb COLUMNS with long name" '
341341
COLUMNS=200 git $cmd $args --graph >output &&
342342
grep " | " output >actual &&
343343
test_cmp "$expect-graph" actual
@@ -358,7 +358,7 @@ EOF
358358
while read verb expect cmd args
359359
do
360360
test_expect_success COLUMNS_CAN_BE_1 \
361-
"$cmd $verb prefix greater than COLUMNS (big change)" '
361+
"$cmd $verb prefix greater than COLUMNS with big change" '
362362
COLUMNS=1 git $cmd $args >output &&
363363
grep " | " output >actual &&
364364
test_cmp "$expect" actual
@@ -367,7 +367,7 @@ do
367367
case "$cmd" in diff|show) continue;; esac
368368

369369
test_expect_success COLUMNS_CAN_BE_1 \
370-
"$cmd --graph $verb prefix greater than COLUMNS (big change)" '
370+
"$cmd --graph $verb prefix greater than COLUMNS with big change" '
371371
COLUMNS=1 git $cmd $args --graph >output &&
372372
grep " | " output >actual &&
373373
test_cmp "$expect-graph" actual
@@ -382,8 +382,14 @@ EOF
382382
cat >expect <<'EOF'
383383
abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
384384
EOF
385-
test_expect_success 'merge --stat respects COLUMNS (big change)' '
386-
git checkout -b branch HEAD^^ &&
385+
test_expect_success 'merge --stat respects diff.statGraphWidth with big change' '
386+
git checkout -b branch1 HEAD^^ &&
387+
git -c diff.statGraphWidth=26 merge --stat --no-ff main^ >output &&
388+
grep " | " output >actual &&
389+
test_cmp expect40 actual
390+
'
391+
test_expect_success 'merge --stat respects COLUMNS with big change' '
392+
git checkout -b branch2 HEAD^^ &&
387393
COLUMNS=100 git merge --stat --no-ff main^ >output &&
388394
grep " | " output >actual &&
389395
test_cmp expect actual
@@ -392,7 +398,17 @@ test_expect_success 'merge --stat respects COLUMNS (big change)' '
392398
cat >expect <<'EOF'
393399
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++
394400
EOF
395-
test_expect_success 'merge --stat respects COLUMNS (long filename)' '
401+
cat >expect.30 <<'EOF'
402+
...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++++++++++++++++++++++
403+
EOF
404+
test_expect_success 'merge --stat respects diff.statNameWidth with long name' '
405+
git switch branch1 &&
406+
git -c diff.statNameWidth=30 merge --stat --no-ff main >output &&
407+
grep " | " output >actual &&
408+
test_cmp expect.30 actual
409+
'
410+
test_expect_success 'merge --stat respects COLUMNS with long name' '
411+
git switch branch2 &&
396412
COLUMNS=100 git merge --stat --no-ff main >output &&
397413
grep " | " output >actual &&
398414
test_cmp expect actual

0 commit comments

Comments
 (0)