From: Bert Wesarg <bert.wesarg@googlemail.com>
To: git@vger.kernel.org
Cc: Bert Wesarg <bert.wesarg@googlemail.com>
Subject: [PATCH/RFC 4/4] grep: provide option to match line number
Date: Mon, 2 May 2011 13:39:13 +0200 [thread overview]
Message-ID: <1028f8b6b8da69b8cb80e39a543b0775bc4d935a.1304321122.git.bert.wesarg@googlemail.com> (raw)
In-Reply-To: <f85d783d43bfe7f9e9f23a10e72e8a2a83033cac.1304321122.git.bert.wesarg@googlemail.com>
In-Reply-To: <cover.1304321122.git.bert.wesarg@googlemail.com>
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
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[=<when>] | --no-color]
[-A <post-context>] [-B <pre-context>] [-C <context>]
[-f <file>] [-e] <pattern>
- [--and|--or|--not|(|)|-e <pattern>...]
+ [--and|--or|--not|(|)|-e <pattern>|-@ <line>...]
[--cached | --no-index | <tree>...]
[--] [<pathspec>...]
@@ -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 <pattern>", PARSE_OPT_NONEG, pattern_callback },
+ { OPTION_CALLBACK, '@', NULL, &opt, "lno",
+ "match <line>", 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
next prev parent reply other threads:[~2011-05-02 11:39 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-02 11:39 [PATCH/RFC 0/4] grep: support to match by line number Bert Wesarg
[not found] ` <cover.1304321122.git.bert.wesarg@googlemail.com>
2011-05-02 11:39 ` [PATCH/RFC 1/4] grep: prepare for re-using the space of the regexp member in struct grep_pat Bert Wesarg
2011-05-02 13:27 ` Thiago Farina
2011-05-02 14:25 ` Bert Wesarg
2011-05-02 11:39 ` [PATCH/RFC 2/4] grep: pass current line number down to match_one_pattern Bert Wesarg
2011-05-02 13:30 ` Thiago Farina
2011-05-02 14:29 ` Bert Wesarg
2011-05-02 16:40 ` Junio C Hamano
2011-05-02 11:39 ` [PATCH/RFC 3/4] grep: introduce pattern which matches at line number Bert Wesarg
2011-05-02 13:33 ` Thiago Farina
2011-05-02 14:32 ` Bert Wesarg
2011-05-02 11:39 ` Bert Wesarg [this message]
2011-05-02 11:54 ` [PATCH/RFC 0/4] grep: support to match by " Sverre Rabbelier
2011-05-02 12:20 ` Bert Wesarg
2011-05-02 16:46 ` Junio C Hamano
2011-05-02 19:14 ` Bert Wesarg
2011-05-02 19:30 ` Junio C Hamano
2011-05-02 16:38 ` Junio C Hamano
2011-05-02 17:11 ` Jakub Narebski
2011-05-02 18:54 ` Bert Wesarg
2011-05-02 19:08 ` Junio C Hamano
2011-05-02 19:33 ` Bert Wesarg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1028f8b6b8da69b8cb80e39a543b0775bc4d935a.1304321122.git.bert.wesarg@googlemail.com \
--to=bert.wesarg@googlemail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).