From: Chris Packham <judge.packham@gmail.com>
To: Jens.Lehmann@web.de
Cc: git@vger.kernel.org, Chris Packham <judge.packham@gmail.com>
Subject: [RFC PATCH 2/3] grep: prepare grep for submodules
Date: Wed, 29 Sep 2010 13:28:53 -0700 [thread overview]
Message-ID: <1285792134-26339-3-git-send-email-judge.packham@gmail.com> (raw)
In-Reply-To: <1285792134-26339-1-git-send-email-judge.packham@gmail.com>
Add --submodule-prefix option to pass to subprocess grep invocations. The
prefix is then used when outputting the results.
Signed-off-by: Chris Packham <judge.packham@gmail.com>
---
builtin/grep.c | 2 ++
grep.c | 8 ++++++++
grep.h | 1 +
3 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index da32f3d..8315ff0 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -927,6 +927,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
"allow calling of grep(1) (ignored by this build)"),
{ OPTION_CALLBACK, 0, "help-all", &options, NULL, "show usage",
PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, help_callback },
+ OPT_STRING(0, "submodule-prefix", &opt.submodule_prefix, "DIR",
+ "prepend this to submodule path output"),
OPT_END()
};
diff --git a/grep.c b/grep.c
index 63c4280..36bec98 100644
--- a/grep.c
+++ b/grep.c
@@ -370,6 +370,10 @@ static void output_sep(struct grep_opt *opt, char sign)
static void show_name(struct grep_opt *opt, const char *name)
{
+ if (opt->submodule_prefix) {
+ output_color(opt, opt->submodule_prefix,
+ strlen(opt->submodule_prefix), opt->color_filename);
+ }
output_color(opt, name, strlen(name), opt->color_filename);
opt->output(opt, opt->null_following_name ? "\0" : "\n", 1);
}
@@ -644,6 +648,10 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
}
opt->last_shown = lno;
+ if (opt->submodule_prefix) {
+ output_color(opt, opt->submodule_prefix,
+ strlen(opt->submodule_prefix), opt->color_filename);
+ }
if (opt->pathname) {
output_color(opt, name, strlen(name), opt->color_filename);
output_sep(opt, sign);
diff --git a/grep.h b/grep.h
index 06621fe..d918da4 100644
--- a/grep.h
+++ b/grep.h
@@ -67,6 +67,7 @@ struct grep_opt {
struct grep_expr *pattern_expression;
const char *prefix;
int prefix_length;
+ const char *submodule_prefix;
regex_t regexp;
int linenum;
int invert;
--
1.7.3.dirty
next prev parent reply other threads:[~2010-09-29 20:29 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-29 20:28 [RFC PATCH 0/3] grep: submodule support Chris Packham
2010-09-29 20:28 ` [RFC PATCH 1/3] add test for git grep --recursive Chris Packham
2010-09-29 20:35 ` Ævar Arnfjörð Bjarmason
2010-09-29 20:48 ` Chris Packham
2010-09-29 21:34 ` Kevin Ballard
2010-09-29 20:28 ` Chris Packham [this message]
2010-09-30 1:10 ` [RFC PATCH 2/3] grep: prepare grep for submodules Nguyen Thai Ngoc Duy
2010-09-30 18:34 ` Chris Packham
2010-10-01 14:37 ` Nguyen Thai Ngoc Duy
2010-10-01 16:26 ` Chris Packham
2010-09-29 20:28 ` [RFC PATCH 3/3] grep: add support for grepping in submodules Chris Packham
2010-09-29 22:21 ` Jens Lehmann
2010-09-29 22:59 ` Junio C Hamano
2010-09-29 23:47 ` Chris Packham
2010-09-30 11:09 ` Jens Lehmann
2010-09-30 11:28 ` Johannes Sixt
2010-09-30 15:07 ` Jens Lehmann
2010-09-29 23:02 ` Chris Packham
2010-09-30 11:24 ` Jens Lehmann
2010-09-30 16:48 ` Chris Packham
2010-09-30 18:59 ` Heiko Voigt
2010-09-30 19:48 ` Jens Lehmann
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=1285792134-26339-3-git-send-email-judge.packham@gmail.com \
--to=judge.packham@gmail.com \
--cc=Jens.Lehmann@web.de \
--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).