1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-29 14:26:11 +02:00

builtin-grep: allow -<n> and -[ABC]<n> notation for context lines.

Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Junio C Hamano 2006-05-02 15:17:05 -07:00
parent a24f1e254e
commit f462ebb48b

View File

@ -402,18 +402,34 @@ int cmd_grep(int argc, const char **argv, char **envp)
opt.name_only = 1;
continue;
}
if (!strcmp("-A", arg) ||
!strcmp("-B", arg) ||
!strcmp("-C", arg)) {
if (!strncmp("-A", arg, 2) ||
!strncmp("-B", arg, 2) ||
!strncmp("-C", arg, 2) ||
(arg[0] == '-' && '1' <= arg[1] && arg[1] <= '9')) {
unsigned num;
if (argc <= 1 ||
sscanf(*++argv, "%u", &num) != 1)
const char *scan;
switch (arg[1]) {
case 'A': case 'B': case 'C':
if (!arg[2]) {
if (argc <= 1)
usage(builtin_grep_usage);
scan = *++argv;
argc--;
}
else
scan = arg + 2;
break;
default:
scan = arg + 1;
break;
}
if (sscanf(scan, "%u", &num) != 1)
usage(builtin_grep_usage);
argc--;
switch (arg[1]) {
case 'A':
opt.post_context = num;
break;
default:
case 'C':
opt.post_context = num;
case 'B':