@matheusbsbs / matheus-bagliano / commits / 74e2abe5b7
Fork 0

diff --numstat

[jc: with documentation from Jakub] Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Oct 12, 2006 at 03:01 UTC 74e2abe5b70aadf06984472ba9aa9a29900040e6
4 files changed +47 -12
Documentation/diff-options.txt
+5
@@ -16,6 +16,11 @@
16 The width of the filename part can be controlled by
17 giving another width to it separated by a comma.
18
19 +--numstat::
20 + Similar to \--stat, but shows number of added and
21 + deleted lines in decimal notation and pathname without
22 + abbreviation, to make it more machine friendly.
23 +
24 --summary::
25 Output a condensed summary of extended header information
26 such as creations, renames and mode changes.
combine-diff.c
+6 -3
@@ -856,8 +856,10 @@ void diff_tree_combined(const unsigned char *sha1,
856 /* show stat against the first parent even
857 * when doing combined diff.
858 */
859 - if (i == 0 && opt->output_format & DIFF_FORMAT_DIFFSTAT)
860 - diffopts.output_format = DIFF_FORMAT_DIFFSTAT;
859 + int stat_opt = (opt->output_format &
860 + (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT));
861 + if (i == 0 && stat_opt)
862 + diffopts.output_format = stat_opt;
863 else
864 diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
865 diff_tree_sha1(parent[i], sha1, "", &diffopts);
@@ -887,7 +889,8 @@ void diff_tree_combined(const unsigned char *sha1,
889 }
890 needsep = 1;
891 }
890 - else if (opt->output_format & DIFF_FORMAT_DIFFSTAT)
892 + else if (opt->output_format &
893 + (DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIFFSTAT))
894 needsep = 1;
895 if (opt->output_format & DIFF_FORMAT_PATCH) {
896 if (needsep)
diff.c
+27 -2
@@ -795,6 +795,23 @@ static void show_stats(struct diffstat_t* data, struct diff_options *options)
795 set, total_files, adds, dels, reset);
796 }
797
798 +static void show_numstat(struct diffstat_t* data, struct diff_options *options)
799 +{
800 + int i;
801 +
802 + for (i = 0; i < data->nr; i++) {
803 + struct diffstat_file *file = data->files[i];
804 +
805 + printf("%d\t%d\t", file->added, file->deleted);
806 + if (options->line_termination &&
807 + quote_c_style(file->name, NULL, NULL, 0))
808 + quote_c_style(file->name, NULL, stdout, 0);
809 + else
810 + fputs(file->name, stdout);
811 + putchar(options->line_termination);
812 + }
813 +}
814 +
815 struct checkdiff_t {
816 struct xdiff_emit_state xm;
817 const char *filename;
@@ -1731,6 +1748,7 @@ int diff_setup_done(struct diff_options *options)
1748 DIFF_FORMAT_CHECKDIFF |
1749 DIFF_FORMAT_NO_OUTPUT))
1750 options->output_format &= ~(DIFF_FORMAT_RAW |
1751 + DIFF_FORMAT_NUMSTAT |
1752 DIFF_FORMAT_DIFFSTAT |
1753 DIFF_FORMAT_SUMMARY |
1754 DIFF_FORMAT_PATCH);
@@ -1740,6 +1758,7 @@ int diff_setup_done(struct diff_options *options)
1758 * recursive bits for other formats here.
1759 */
1760 if (options->output_format & (DIFF_FORMAT_PATCH |
1761 + DIFF_FORMAT_NUMSTAT |
1762 DIFF_FORMAT_DIFFSTAT |
1763 DIFF_FORMAT_CHECKDIFF))
1764 options->recursive = 1;
@@ -1828,6 +1847,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
1847 else if (!strcmp(arg, "--patch-with-raw")) {
1848 options->output_format |= DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW;
1849 }
1850 + else if (!strcmp(arg, "--numstat")) {
1851 + options->output_format |= DIFF_FORMAT_NUMSTAT;
1852 + }
1853 else if (!strncmp(arg, "--stat", 6)) {
1854 char *end;
1855 int width = options->stat_width;
@@ -2602,7 +2624,7 @@ void diff_flush(struct diff_options *options)
2624 separator++;
2625 }
2626
2605 - if (output_format & DIFF_FORMAT_DIFFSTAT) {
2627 + if (output_format & (DIFF_FORMAT_DIFFSTAT|DIFF_FORMAT_NUMSTAT)) {
2628 struct diffstat_t diffstat;
2629
2630 memset(&diffstat, 0, sizeof(struct diffstat_t));
@@ -2612,7 +2634,10 @@ void diff_flush(struct diff_options *options)
2634 if (check_pair_status(p))
2635 diff_flush_stat(p, options, &diffstat);
2636 }
2615 - show_stats(&diffstat, options);
2637 + if (output_format & DIFF_FORMAT_NUMSTAT)
2638 + show_numstat(&diffstat, options);
2639 + if (output_format & DIFF_FORMAT_DIFFSTAT)
2640 + show_stats(&diffstat, options);
2641 separator++;
2642 }
2643
diff.h
+9 -7
@@ -26,20 +26,21 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
26
27 #define DIFF_FORMAT_RAW 0x0001
28 #define DIFF_FORMAT_DIFFSTAT 0x0002
29 -#define DIFF_FORMAT_SUMMARY 0x0004
30 -#define DIFF_FORMAT_PATCH 0x0008
29 +#define DIFF_FORMAT_NUMSTAT 0x0004
30 +#define DIFF_FORMAT_SUMMARY 0x0008
31 +#define DIFF_FORMAT_PATCH 0x0010
32
33 /* These override all above */
33 -#define DIFF_FORMAT_NAME 0x0010
34 -#define DIFF_FORMAT_NAME_STATUS 0x0020
35 -#define DIFF_FORMAT_CHECKDIFF 0x0040
34 +#define DIFF_FORMAT_NAME 0x0100
35 +#define DIFF_FORMAT_NAME_STATUS 0x0200
36 +#define DIFF_FORMAT_CHECKDIFF 0x0400
37
38 /* Same as output_format = 0 but we know that -s flag was given
39 * and we should not give default value to output_format.
40 */
40 -#define DIFF_FORMAT_NO_OUTPUT 0x0080
41 +#define DIFF_FORMAT_NO_OUTPUT 0x0800
42
42 -#define DIFF_FORMAT_CALLBACK 0x0100
43 +#define DIFF_FORMAT_CALLBACK 0x1000
44
45 struct diff_options {
46 const char *filter;
@@ -170,6 +171,7 @@ extern void diffcore_std_no_resolve(struct diff_options *);
171 " --patch-with-raw\n" \
172 " output both a patch and the diff-raw format.\n" \
173 " --stat show diffstat instead of patch.\n" \
174 +" --numstat show numeric diffstat instead of patch.\n" \
175 " --patch-with-stat\n" \
176 " output a patch and prepend its diffstat.\n" \
177 " --name-only show only names of changed files.\n" \