From: Bert Wesarg Date: Mon, 02 May 2011 11:39:13 GMT Subject: [PATCH/RFC 4/4] grep: provide option to match line number Message-ID: <1028f8b6b8da69b8cb80e39a543b0775bc4d935a.1304321122.git.bert.wesarg@googlemail.com> In-Reply-To: Signed-off-by: Bert Wesarg --- Documentation/git-grep.txt | 6 +++++- builtin/grep.c | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletions(-) diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index d7523b3..05deb58 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -21,7 +21,7 @@ SYNOPSIS [--color[=] | --no-color] [-A ] [-B ] [-C ] [-f ] [-e] - [--and|--or|--not|(|)|-e ...] + [--and|--or|--not|(|)|-e |-@ ...] [--cached | --no-index | ...] [--] [...] @@ -168,6 +168,10 @@ OPTIONS scripts passing user input to grep. Multiple patterns are combined by 'or'. +-@:: + The next parameter is a line number. This special pattern matches + this line of the input file. + --and:: --or:: --not:: diff --git a/builtin/grep.c b/builtin/grep.c index 10a1f65..8b11c87 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -733,6 +733,14 @@ static int pattern_callback(const struct option *opt, const char *arg, return 0; } +static int lno_pattern_callback(const struct option *opt, const char *arg, + int unset) +{ + struct grep_opt *grep_opt = opt->value; + append_grep_pattern(grep_opt, arg, "-@ option", 0, GREP_LNO); + return 0; +} + static int help_callback(const struct option *opt, const char *arg, int unset) { return -1; @@ -816,6 +824,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix) "read patterns from file", file_callback), { OPTION_CALLBACK, 'e', NULL, &opt, "pattern", "match ", PARSE_OPT_NONEG, pattern_callback }, + { OPTION_CALLBACK, '@', NULL, &opt, "lno", + "match ", PARSE_OPT_NONEG, lno_pattern_callback }, { OPTION_CALLBACK, 0, "and", &opt, NULL, "combine patterns specified with -e", PARSE_OPT_NOARG | PARSE_OPT_NONEG, and_callback }, -- 1.7.5.349.gfeb1a