Skip to content

Commit 1e57208

Browse files
moygitster
authored andcommitted
diff: parse separate options --stat-width n, --stat-name-width n
Part of a campaign for unstuck forms of options. [jn: with some refactoring] Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4d7f7a4 commit 1e57208

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

diff.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,16 +3035,34 @@ static int stat_opt(struct diff_options *options, const char **av)
30353035
char *end;
30363036
int width = options->stat_width;
30373037
int name_width = options->stat_name_width;
3038+
int argcount = 1;
30383039

30393040
arg += strlen("--stat");
30403041
end = (char *)arg;
30413042

30423043
switch (*arg) {
30433044
case '-':
3044-
if (!prefixcmp(arg, "-width="))
3045-
width = strtoul(arg + 7, &end, 10);
3046-
else if (!prefixcmp(arg, "-name-width="))
3047-
name_width = strtoul(arg + 12, &end, 10);
3045+
if (!prefixcmp(arg, "-width")) {
3046+
arg += strlen("-width");
3047+
if (*arg == '=')
3048+
width = strtoul(arg + 1, &end, 10);
3049+
else if (!*arg && !av[1])
3050+
die("Option '--stat-width' requires a value");
3051+
else if (!*arg) {
3052+
width = strtoul(av[1], &end, 10);
3053+
argcount = 2;
3054+
}
3055+
} else if (!prefixcmp(arg, "-name-width")) {
3056+
arg += strlen("-name-width");
3057+
if (*arg == '=')
3058+
name_width = strtoul(arg + 1, &end, 10);
3059+
else if (!*arg && !av[1])
3060+
die("Option '--stat-name-width' requires a value");
3061+
else if (!*arg) {
3062+
name_width = strtoul(av[1], &end, 10);
3063+
argcount = 2;
3064+
}
3065+
}
30483066
break;
30493067
case '=':
30503068
width = strtoul(arg+1, &end, 10);
@@ -3058,7 +3076,7 @@ static int stat_opt(struct diff_options *options, const char **av)
30583076
options->output_format |= DIFF_FORMAT_DIFFSTAT;
30593077
options->stat_name_width = name_width;
30603078
options->stat_width = width;
3061-
return 1;
3079+
return argcount;
30623080
}
30633081

30643082
int diff_opt_parse(struct diff_options *options, const char **av, int ac)

0 commit comments

Comments
 (0)