@matheusbsbs / matheus-bagliano / commits / 5c5b2ea9ab
Fork 0

diff --stat=width[,name-width]: allow custom diffstat output width.

Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Sep 28, 2006 at 15:07 UTC 5c5b2ea9ab95f71ac155f12d75d1432b5c93c2bb
2 files changed +30 -10
Documentation/diff-options.txt
+5 -2
@@ -10,8 +10,11 @@
10 --patch-with-raw::
11 Synonym for "-p --raw".
12
13 ---stat::
14 - Generate a diffstat.
13 +--stat[=width[,name-width]]::
14 + Generate a diffstat. You can override the default
15 + output width for 80-column terminal by "--stat=width".
16 + The width of the filename part can be controlled by
17 + giving another width to it separated by a comma.
18
19 --summary::
20 Output a condensed summary of extended header information
diff.c
+25 -8
@@ -1735,15 +1735,32 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
1735 else if (!strcmp(arg, "--patch-with-raw")) {
1736 options->output_format |= DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW;
1737 }
1738 - else if (!strcmp(arg, "--stat"))
1739 - options->output_format |= DIFF_FORMAT_DIFFSTAT;
1740 - else if (!strncmp(arg, "--stat-width=", 13)) {
1741 - options->stat_width = strtoul(arg + 13, NULL, 10);
1742 - options->output_format |= DIFF_FORMAT_DIFFSTAT;
1743 - }
1744 - else if (!strncmp(arg, "--stat-name-width=", 18)) {
1745 - options->stat_name_width = strtoul(arg + 18, NULL, 10);
1738 + else if (!strncmp(arg, "--stat", 6)) {
1739 + char *end;
1740 + int width = options->stat_width;
1741 + int name_width = options->stat_name_width;
1742 + arg += 6;
1743 + end = (char *)arg;
1744 +
1745 + switch (*arg) {
1746 + case '-':
1747 + if (!strncmp(arg, "-width=", 7))
1748 + width = strtoul(arg + 7, &end, 10);
1749 + else if (!strncmp(arg, "-name-width=", 12))
1750 + name_width = strtoul(arg + 12, &end, 10);
1751 + break;
1752 + case '=':
1753 + width = strtoul(arg+1, &end, 10);
1754 + if (*end == ',')
1755 + name_width = strtoul(end+1, &end, 10);
1756 + }
1757 +
1758 + /* Important! This checks all the error cases! */
1759 + if (*end)
1760 + return 0;
1761 options->output_format |= DIFF_FORMAT_DIFFSTAT;
1762 + options->stat_name_width = name_width;
1763 + options->stat_width = width;
1764 }
1765 else if (!strcmp(arg, "--check"))
1766 options->output_format |= DIFF_FORMAT_CHECKDIFF;