Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 73ff8cf

Browse files
committed
Merge branch 'lp/diffstat-with-graph'
"log --graph" was not very friendly with "--stat" option and its output had line breaks at wrong places. By Lucian Poston (5) and Zbigniew Jędrzejewski-Szmek (2) * lp/diffstat-with-graph: t4052: work around shells unable to set COLUMNS to 1 Prevent graph_width of stat width from falling below min t4052: Test diff-stat output with minimum columns t4052: Adjust --graph --stat output for prefixes Adjust stat width calculations to take --graph output into account Add output_prefix_length to diff_options t4052: test --stat output with --graph
2 parents 85dcc38 + bafa16e commit 73ff8cf

File tree

4 files changed

+130
-6
lines changed

4 files changed

+130
-6
lines changed

diff.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
15091509
*/
15101510

15111511
if (options->stat_width == -1)
1512-
width = term_columns();
1512+
width = term_columns() - options->output_prefix_length;
15131513
else
15141514
width = options->stat_width ? options->stat_width : 80;
15151515

@@ -1537,8 +1537,12 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
15371537
* Adjust adjustable widths not to exceed maximum width
15381538
*/
15391539
if (name_width + number_width + 6 + graph_width > width) {
1540-
if (graph_width > width * 3/8 - number_width - 6)
1540+
if (graph_width > width * 3/8 - number_width - 6) {
15411541
graph_width = width * 3/8 - number_width - 6;
1542+
if (graph_width < 6)
1543+
graph_width = 6;
1544+
}
1545+
15421546
if (options->stat_graph_width &&
15431547
graph_width > options->stat_graph_width)
15441548
graph_width = options->stat_graph_width;

diff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ struct diff_options {
152152
diff_format_fn_t format_callback;
153153
void *format_callback_data;
154154
diff_prefix_fn_t output_prefix;
155+
int output_prefix_length;
155156
void *output_prefix_data;
156157
};
157158

graph.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,10 @@ static struct strbuf *diff_output_prefix_callback(struct diff_options *opt, void
194194
struct git_graph *graph = data;
195195
static struct strbuf msgbuf = STRBUF_INIT;
196196

197+
assert(opt);
197198
assert(graph);
198199

200+
opt->output_prefix_length = graph->width;
199201
strbuf_reset(&msgbuf);
200202
graph_padding_line(graph, &msgbuf);
201203
return &msgbuf;
@@ -245,6 +247,7 @@ struct git_graph *graph_init(struct rev_info *opt)
245247
*/
246248
opt->diffopt.output_prefix = diff_output_prefix_callback;
247249
opt->diffopt.output_prefix_data = graph;
250+
opt->diffopt.output_prefix_length = 0;
248251

249252
return graph;
250253
}

t/t4052-stat-output.sh

Lines changed: 120 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,30 @@ test_expect_success 'preparation for big change tests' '
8282
cat >expect80 <<'EOF'
8383
abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8484
EOF
85-
85+
cat >expect80-graph <<'EOF'
86+
| abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
87+
EOF
8688
cat >expect200 <<'EOF'
8789
abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8890
EOF
89-
91+
cat >expect200-graph <<'EOF'
92+
| abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
93+
EOF
9094
while read verb expect cmd args
9195
do
9296
test_expect_success "$cmd $verb COLUMNS (big change)" '
9397
COLUMNS=200 git $cmd $args >output
9498
grep " | " output >actual &&
9599
test_cmp "$expect" actual
96100
'
101+
102+
test "$cmd" != diff || continue
103+
104+
test_expect_success "$cmd --graph $verb COLUMNS (big change)" '
105+
COLUMNS=200 git $cmd $args --graph >output
106+
grep " | " output >actual &&
107+
test_cmp "$expect-graph" actual
108+
'
97109
done <<\EOF
98110
ignores expect80 format-patch -1 --stdout
99111
respects expect200 diff HEAD^ HEAD --stat
@@ -104,7 +116,9 @@ EOF
104116
cat >expect40 <<'EOF'
105117
abcd | 1000 ++++++++++++++++++++++++++
106118
EOF
107-
119+
cat >expect40-graph <<'EOF'
120+
| abcd | 1000 ++++++++++++++++++++++++
121+
EOF
108122
while read verb expect cmd args
109123
do
110124
test_expect_success "$cmd $verb not enough COLUMNS (big change)" '
@@ -113,11 +127,41 @@ do
113127
test_cmp "$expect" actual
114128
'
115129

130+
test "$cmd" != diff || continue
131+
132+
test_expect_success "$cmd --graph $verb not enough COLUMNS (big change)" '
133+
COLUMNS=40 git $cmd $args --graph >output
134+
grep " | " output >actual &&
135+
test_cmp "$expect-graph" actual
136+
'
137+
done <<\EOF
138+
ignores expect80 format-patch -1 --stdout
139+
respects expect40 diff HEAD^ HEAD --stat
140+
respects expect40 show --stat
141+
respects expect40 log -1 --stat
142+
EOF
143+
144+
cat >expect40 <<'EOF'
145+
abcd | 1000 ++++++++++++++++++++++++++
146+
EOF
147+
cat >expect40-graph <<'EOF'
148+
| abcd | 1000 ++++++++++++++++++++++++++
149+
EOF
150+
while read verb expect cmd args
151+
do
116152
test_expect_success "$cmd $verb statGraphWidth config" '
117153
git -c diff.statGraphWidth=26 $cmd $args >output
118154
grep " | " output >actual &&
119155
test_cmp "$expect" actual
120156
'
157+
158+
test "$cmd" != diff || continue
159+
160+
test_expect_success "$cmd --graph $verb statGraphWidth config" '
161+
git -c diff.statGraphWidth=26 $cmd $args --graph >output
162+
grep " | " output >actual &&
163+
test_cmp "$expect-graph" actual
164+
'
121165
done <<\EOF
122166
ignores expect80 format-patch -1 --stdout
123167
respects expect40 diff HEAD^ HEAD --stat
@@ -129,6 +173,9 @@ EOF
129173
cat >expect <<'EOF'
130174
abcd | 1000 ++++++++++++++++++++++++++
131175
EOF
176+
cat >expect-graph <<'EOF'
177+
| abcd | 1000 ++++++++++++++++++++++++++
178+
EOF
132179
while read cmd args
133180
do
134181
test_expect_success "$cmd --stat=width with big change" '
@@ -143,11 +190,25 @@ do
143190
test_cmp expect actual
144191
'
145192

146-
test_expect_success "$cmd --stat-graph--width with big change" '
193+
test_expect_success "$cmd --stat-graph-width with big change" '
147194
git $cmd $args --stat-graph-width=26 >output
148195
grep " | " output >actual &&
149196
test_cmp expect actual
150197
'
198+
199+
test "$cmd" != diff || continue
200+
201+
test_expect_success "$cmd --stat-width=width --graph with big change" '
202+
git $cmd $args --stat-width=40 --graph >output
203+
grep " | " output >actual &&
204+
test_cmp expect-graph actual
205+
'
206+
207+
test_expect_success "$cmd --stat-graph-width --graph with big change" '
208+
git $cmd $args --stat-graph-width=26 --graph >output
209+
grep " | " output >actual &&
210+
test_cmp expect-graph actual
211+
'
151212
done <<\EOF
152213
format-patch -1 --stdout
153214
diff HEAD^ HEAD --stat
@@ -164,13 +225,24 @@ test_expect_success 'preparation for long filename tests' '
164225
cat >expect <<'EOF'
165226
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
166227
EOF
228+
cat >expect-graph <<'EOF'
229+
| ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
230+
EOF
167231
while read cmd args
168232
do
169233
test_expect_success "$cmd --stat=width with big change is more balanced" '
170234
git $cmd $args --stat-width=60 >output &&
171235
grep " | " output >actual &&
172236
test_cmp expect actual
173237
'
238+
239+
test "$cmd" != diff || continue
240+
241+
test_expect_success "$cmd --stat=width --graph with big change is balanced" '
242+
git $cmd $args --stat-width=60 --graph >output &&
243+
grep " | " output >actual &&
244+
test_cmp expect-graph actual
245+
'
174246
done <<\EOF
175247
format-patch -1 --stdout
176248
diff HEAD^ HEAD --stat
@@ -181,23 +253,67 @@ EOF
181253
cat >expect80 <<'EOF'
182254
...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
183255
EOF
256+
cat >expect80-graph <<'EOF'
257+
| ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
258+
EOF
184259
cat >expect200 <<'EOF'
185260
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
186261
EOF
262+
cat >expect200-graph <<'EOF'
263+
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
264+
EOF
187265
while read verb expect cmd args
188266
do
189267
test_expect_success "$cmd $verb COLUMNS (long filename)" '
190268
COLUMNS=200 git $cmd $args >output
191269
grep " | " output >actual &&
192270
test_cmp "$expect" actual
193271
'
272+
273+
test "$cmd" != diff || continue
274+
275+
test_expect_success "$cmd --graph $verb COLUMNS (long filename)" '
276+
COLUMNS=200 git $cmd $args --graph >output
277+
grep " | " output >actual &&
278+
test_cmp "$expect-graph" actual
279+
'
194280
done <<\EOF
195281
ignores expect80 format-patch -1 --stdout
196282
respects expect200 diff HEAD^ HEAD --stat
197283
respects expect200 show --stat
198284
respects expect200 log -1 --stat
199285
EOF
200286

287+
cat >expect1 <<'EOF'
288+
...aaaaaaa | 1000 ++++++
289+
EOF
290+
cat >expect1-graph <<'EOF'
291+
| ...aaaaaaa | 1000 ++++++
292+
EOF
293+
while read verb expect cmd args
294+
do
295+
test_expect_success COLUMNS_CAN_BE_1 \
296+
"$cmd $verb prefix greater than COLUMNS (big change)" '
297+
COLUMNS=1 git $cmd $args >output
298+
grep " | " output >actual &&
299+
test_cmp "$expect" actual
300+
'
301+
302+
test "$cmd" != diff || continue
303+
304+
test_expect_success COLUMNS_CAN_BE_1 \
305+
"$cmd --graph $verb prefix greater than COLUMNS (big change)" '
306+
COLUMNS=1 git $cmd $args --graph >output
307+
grep " | " output >actual &&
308+
test_cmp "$expect-graph" actual
309+
'
310+
done <<\EOF
311+
ignores expect80 format-patch -1 --stdout
312+
respects expect1 diff HEAD^ HEAD --stat
313+
respects expect1 show --stat
314+
respects expect1 log -1 --stat
315+
EOF
316+
201317
cat >expect <<'EOF'
202318
abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
203319
EOF

0 commit comments

Comments
 (0)