@matheusbsbs / matheus-bagliano / commits / 7d8b7c21c9
Fork 0

git-apply --numstat

The new option, --numstat, shows number of inserted and deleted lines for each path. It is similar to --stat output but is meant to be more machine friendly by giving number of added and deleted lines and unabbreviated paths. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Oct 28, 2005 at 02:43 UTC 7d8b7c21c9c0bee0d94fcf3b350e24ebdb920b74
2 files changed +32 -2
Documentation/git-apply.txt
+7 -1
@@ -8,7 +8,7 @@ git-apply - Apply patch on a git index file and a work tree
8
9 SYNOPSIS
10 --------
11 -'git-apply' [--stat] [--summary] [--check] [--index] [--apply] [--index-info] [-z] [<patch>...]
11 +'git-apply' [--stat] [--numstat] [--summary] [--check] [--index] [--apply] [--index-info] [-z] [<patch>...]
12
13 DESCRIPTION
14 -----------
@@ -25,6 +25,12 @@ OPTIONS
25 Instead of applying the patch, output diffstat for the
26 input. Turns off "apply".
27
28 +--numstat::
29 + Similar to \--stat, but shows number of added and
30 + deleted lines in decimal notation and pathname without
31 + abbreviation, to make it more machine friendly. Turns
32 + off "apply".
33 +
34 --summary::
35 Instead of applying the patch, output a condensed
36 summary of information obtained from git diff extended
apply.c
+25 -1
@@ -13,18 +13,20 @@
13 // --check turns on checking that the working tree matches the
14 // files that are being modified, but doesn't apply the patch
15 // --stat does just a diffstat, and doesn't actually apply
16 +// --numstat does numeric diffstat, and doesn't actually apply
17 // --index-info shows the old and new index info for paths if available.
18 //
19 static int check_index = 0;
20 static int write_index = 0;
21 static int diffstat = 0;
22 +static int numstat = 0;
23 static int summary = 0;
24 static int check = 0;
25 static int apply = 1;
26 static int show_index_info = 0;
27 static int line_termination = '\n';
28 static const char apply_usage[] =
27 -"git-apply [--stat] [--summary] [--check] [--index] [--apply] [--index-info] [-z] <patch>...";
29 +"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--apply] [--index-info] [-z] <patch>...";
30
31 /*
32 * For "diff-stat" like behaviour, we keep track of the biggest change
@@ -1317,6 +1319,20 @@ static void stat_patch_list(struct patch *patch)
1319 printf(" %d files changed, %d insertions(+), %d deletions(-)\n", files, adds, dels);
1320 }
1321
1322 +static void numstat_patch_list(struct patch *patch)
1323 +{
1324 + for ( ; patch; patch = patch->next) {
1325 + const char *name;
1326 + name = patch->old_name ? patch->old_name : patch->new_name;
1327 + printf("%d\t%d\t", patch->lines_added, patch->lines_deleted);
1328 + if (line_termination && quote_c_style(name, NULL, NULL, 0))
1329 + quote_c_style(name, NULL, stdout, 0);
1330 + else
1331 + fputs(name, stdout);
1332 + putchar('\n');
1333 + }
1334 +}
1335 +
1336 static void show_file_mode_name(const char *newdelete, unsigned int mode, const char *name)
1337 {
1338 if (mode)
@@ -1650,6 +1666,9 @@ static int apply_patch(int fd)
1666 if (diffstat)
1667 stat_patch_list(list);
1668
1669 + if (numstat)
1670 + numstat_patch_list(list);
1671 +
1672 if (summary)
1673 summary_patch_list(list);
1674
@@ -1683,6 +1702,11 @@ int main(int argc, char **argv)
1702 diffstat = 1;
1703 continue;
1704 }
1705 + if (!strcmp(arg, "--numstat")) {
1706 + apply = 0;
1707 + numstat = 1;
1708 + continue;
1709 + }
1710 if (!strcmp(arg, "--summary")) {
1711 apply = 0;
1712 summary = 1;