summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 38529e2)
raw | patch | inline | side by side (parent: 38529e2)
author | Linus Torvalds <torvalds@osdl.org> | |
Thu, 14 Sep 2006 17:45:12 +0000 (10:45 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Thu, 14 Sep 2006 18:46:11 +0000 (11:46 -0700) |
It turns out that I actually wanted to avoid the filenames (because I
didn't care - I just wanted to see the context in which something was
used) when doing a grep. But since "git grep" didn't take the "-h"
parameter, I ended up having to do "grep -5 -h *.c" instead.
So here's a trivial patch that adds "-h" (and thus has to enable -H too)
to "git grep" parsing.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
didn't care - I just wanted to see the context in which something was
used) when doing a grep. But since "git grep" didn't take the "-h"
parameter, I ended up having to do "grep -5 -h *.c" instead.
So here's a trivial patch that adds "-h" (and thus has to enable -H too)
to "git grep" parsing.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-grep.c | patch | blob | history |
diff --git a/builtin-grep.c b/builtin-grep.c
index 6430f6d79ed58afa810a2643a13700be6579aee5..ed87a5550c7dab6de56327b8acc0e3e2c897e39e 100644 (file)
--- a/builtin-grep.c
+++ b/builtin-grep.c
unsigned binary:2;
unsigned extended:1;
unsigned relative:1;
+ unsigned pathname:1;
int regflags;
unsigned pre_context;
unsigned post_context;
static void show_line(struct grep_opt *opt, const char *bol, const char *eol,
const char *name, unsigned lno, char sign)
{
- printf("%s%c", name, sign);
+ if (opt->pathname)
+ printf("%s%c", name, sign);
if (opt->linenum)
printf("%d%c", lno, sign);
printf("%.*s\n", (int)(eol-bol), bol);
push_arg("-F");
if (opt->linenum)
push_arg("-n");
+ if (!opt->pathname)
+ push_arg("-h");
if (opt->regflags & REG_EXTENDED)
push_arg("-E");
if (opt->regflags & REG_ICASE)
memset(&opt, 0, sizeof(opt));
opt.prefix_length = (prefix && *prefix) ? strlen(prefix) : 0;
opt.relative = 1;
+ opt.pathname = 1;
opt.pattern_tail = &opt.pattern_list;
opt.regflags = REG_NEWLINE;
opt.linenum = 1;
continue;
}
+ if (!strcmp("-h", arg)) {
+ opt.pathname = 0;
+ continue;
+ }
if (!strcmp("-H", arg)) {
- /* We always show the pathname, so this
- * is a noop.
- */
+ opt.pathname = 1;
continue;
}
if (!strcmp("-l", arg) ||