Skip to content

Commit 2935327

Browse files
dschoJunio C Hamano
authored andcommitted
diff-options: add --patch-with-stat
With this option, git prepends a diffstat in front of the patch. Since I really, really do not know what a diffstat of a combined diff ("merge diff") should look like, the diffstat is not generated for these. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cbdda02 commit 2935327

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Documentation/diff-options.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
--stat::
1111
Generate a diffstat instead of a patch.
1212

13+
--patch-with-stat::
14+
Generate patch and prepend its diffstat.
15+
1316
-z::
1417
\0 line termination on output
1518

diff.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
10601060
}
10611061
else if (!strcmp(arg, "--stat"))
10621062
options->output_format = DIFF_FORMAT_DIFFSTAT;
1063+
else if (!strcmp(arg, "--patch-with-stat")) {
1064+
options->output_format = DIFF_FORMAT_PATCH;
1065+
options->with_stat = 1;
1066+
}
10631067
else if (!strcmp(arg, "-z"))
10641068
options->line_termination = 0;
10651069
else if (!strncmp(arg, "-l", 2))
@@ -1529,7 +1533,7 @@ void diff_flush(struct diff_options *options)
15291533
int diff_output_format = options->output_format;
15301534
struct diffstat_t *diffstat = NULL;
15311535

1532-
if (diff_output_format == DIFF_FORMAT_DIFFSTAT) {
1536+
if (diff_output_format == DIFF_FORMAT_DIFFSTAT || options->with_stat) {
15331537
diffstat = xcalloc(sizeof (struct diffstat_t), 1);
15341538
diffstat->xm.consume = diffstat_consume;
15351539
}
@@ -1541,6 +1545,17 @@ void diff_flush(struct diff_options *options)
15411545
}
15421546
putchar(options->line_termination);
15431547
}
1548+
if (options->with_stat) {
1549+
for (i = 0; i < q->nr; i++) {
1550+
struct diff_filepair *p = q->queue[i];
1551+
flush_one_pair(p, DIFF_FORMAT_DIFFSTAT, options,
1552+
diffstat);
1553+
}
1554+
show_stats(diffstat);
1555+
free(diffstat);
1556+
diffstat = NULL;
1557+
putchar(options->line_termination);
1558+
}
15441559
for (i = 0; i < q->nr; i++) {
15451560
struct diff_filepair *p = q->queue[i];
15461561
flush_one_pair(p, diff_output_format, options, diffstat);

diff.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct diff_options {
2525
const char *pickaxe;
2626
unsigned recursive:1,
2727
with_raw:1,
28+
with_stat:1,
2829
tree_in_recursive:1,
2930
full_index:1;
3031
int break_opt;
@@ -120,6 +121,8 @@ extern void diffcore_std_no_resolve(struct diff_options *);
120121
" --patch-with-raw\n" \
121122
" output both a patch and the diff-raw format.\n" \
122123
" --stat show diffstat instead of patch.\n" \
124+
" --patch-with-stat\n" \
125+
" output a patch and prepend its diffstat.\n" \
123126
" --name-only show only names of changed files.\n" \
124127
" --name-status show names and status of changed files.\n" \
125128
" --full-index show full object name on index lines.\n" \

0 commit comments

Comments
 (0)