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 <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Apr 15, 2006 at 13:41 UTC
293532739415d287786a312ec10849723383796e
3 files changed
+22
-1
Documentation/diff-options.txt
+3
@@ -10,6 +10,9 @@
10
--stat::
11
Generate a diffstat instead of a patch.
12
13
+--patch-with-stat::
14
+ Generate patch and prepend its diffstat.
15
+
16
-z::
17
\0 line termination on output
18
diff.c
+16
-1
@@ -1060,6 +1060,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
1060
}
1061
else if (!strcmp(arg, "--stat"))
1062
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
+ }
1067
else if (!strcmp(arg, "-z"))
1068
options->line_termination = 0;
1069
else if (!strncmp(arg, "-l", 2))
@@ -1529,7 +1533,7 @@ void diff_flush(struct diff_options *options)
1533
int diff_output_format = options->output_format;
1534
struct diffstat_t *diffstat = NULL;
1535
1532
- if (diff_output_format == DIFF_FORMAT_DIFFSTAT) {
1536
+ if (diff_output_format == DIFF_FORMAT_DIFFSTAT || options->with_stat) {
1537
diffstat = xcalloc(sizeof (struct diffstat_t), 1);
1538
diffstat->xm.consume = diffstat_consume;
1539
}
@@ -1541,6 +1545,17 @@ void diff_flush(struct diff_options *options)
1545
}
1546
putchar(options->line_termination);
1547
}
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
+ }
1559
for (i = 0; i < q->nr; i++) {
1560
struct diff_filepair *p = q->queue[i];
1561
flush_one_pair(p, diff_output_format, options, diffstat);
diff.h
+3
@@ -25,6 +25,7 @@ struct diff_options {
25
const char *pickaxe;
26
unsigned recursive:1,
27
with_raw:1,
28
+ with_stat:1,
29
tree_in_recursive:1,
30
full_index:1;
31
int break_opt;
@@ -120,6 +121,8 @@ extern void diffcore_std_no_resolve(struct diff_options *);
121
" --patch-with-raw\n" \
122
" output both a patch and the diff-raw format.\n" \
123
" --stat show diffstat instead of patch.\n" \
124
+" --patch-with-stat\n" \
125
+" output a patch and prepend its diffstat.\n" \
126
" --name-only show only names of changed files.\n" \
127
" --name-status show names and status of changed files.\n" \
128
" --full-index show full object name on index lines.\n" \