From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, David Aguilar <davvid@gmail.com>,
Nanako Shiraishi <nanako3@lavabit.com>
Subject: Re: [PATCH] grep --no-index: allow use of "git grep" outside a git repository
Date: Sun, 17 Jan 2010 20:02:25 -0800 [thread overview]
Message-ID: <7v3a24ukku.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <7v8wbwultw.fsf@alter.siamese.dyndns.org> (Junio C. Hamano's message of "Sun\, 17 Jan 2010 19\:35\:23 -0800")
Junio C Hamano <gitster@pobox.com> writes:
> Jeff King <peff@peff.net> writes:
>
>> Agreed. That is the most common log grep pattern for me (author + grep),
>> and I always want all-match. I see from later in the thread, though,
>> that implementing it is not as straightforward as we might hope.
>
> I haven't looked at the codepath for quite some time but I have a feeling
> that it probably won't be too bad.
>
> It just won't be as simple as flipping the all_match bit with a one-liner.
Perhaps something like this.
-- >8 --
Subject: "log --author=me --grep=it" should find intersection, not union
Historically, any grep filter in "git log" family of commands were taken
as restricting to commits with any of the words in the commit log message.
However, the user almost always want to find commits "done by this person
on that topic". With "--all-match" option, a series of grep patterns can
be turned into a requirement that all of them must produce a match, but
that makes it impossible to ask for "done by me, on either this or that"
with:
log --author=me --grep=this --grep=that
because it will require both "this" and "that" to appear.
Change the "header" parser of grep library to treat the headers specially.
When parsing the above, behave as if it was specified like this on the
command line:
--all-match --author=me '(' --grep=this --grep=that ')'
Even though the "log" command line parser doesn't give direct access to
the extended grep syntax to group terms with parentheses, this change will
cover the majority of the case the users would want.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin-grep.c | 1 +
grep.c | 20 ++++++++++++++++++--
grep.h | 2 ++
revision.c | 1 +
4 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/builtin-grep.c b/builtin-grep.c
index 529461f..d57c4d9 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -820,6 +820,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
opt.relative = 1;
opt.pathname = 1;
opt.pattern_tail = &opt.pattern_list;
+ opt.header_tail = &opt.header_list;
opt.regflags = REG_NEWLINE;
opt.max_depth = -1;
diff --git a/grep.c b/grep.c
index bdadf2c..f51fa4a 100644
--- a/grep.c
+++ b/grep.c
@@ -11,8 +11,8 @@ void append_header_grep_pattern(struct grep_opt *opt, enum grep_header_field fie
p->no = 0;
p->token = GREP_PATTERN_HEAD;
p->field = field;
- *opt->pattern_tail = p;
- opt->pattern_tail = &p->next;
+ *opt->header_tail = p;
+ opt->header_tail = &p->next;
p->next = NULL;
}
@@ -173,6 +173,22 @@ void compile_grep_patterns(struct grep_opt *opt)
{
struct grep_pat *p;
+ if (opt->header_list && !opt->all_match) {
+ struct grep_pat *p = opt->pattern_list;
+ opt->pattern_list = opt->header_list;
+ opt->pattern_tail = opt->header_tail;
+ opt->header_list = NULL;
+ opt->header_tail = NULL;
+
+ append_grep_pattern(opt, "(", "internal", 0, GREP_OPEN_PAREN);
+ while (p) {
+ *opt->pattern_tail = p;
+ opt->pattern_tail = &p->next;
+ p = p->next;
+ }
+ append_grep_pattern(opt, ")", "internal", 0, GREP_CLOSE_PAREN);
+ opt->all_match = 1;
+ }
if (opt->all_match)
opt->extended = 1;
diff --git a/grep.h b/grep.h
index 75370f6..e39e514 100644
--- a/grep.h
+++ b/grep.h
@@ -59,6 +59,8 @@ struct grep_expr {
struct grep_opt {
struct grep_pat *pattern_list;
struct grep_pat **pattern_tail;
+ struct grep_pat *header_list;
+ struct grep_pat **header_tail;
struct grep_expr *pattern_expression;
const char *prefix;
int prefix_length;
diff --git a/revision.c b/revision.c
index 25fa14d..18a3658 100644
--- a/revision.c
+++ b/revision.c
@@ -806,6 +806,7 @@ void init_revisions(struct rev_info *revs, const char *prefix)
revs->grep_filter.status_only = 1;
revs->grep_filter.pattern_tail = &(revs->grep_filter.pattern_list);
+ revs->grep_filter.header_tail = &(revs->grep_filter.header_list);
revs->grep_filter.regflags = REG_NEWLINE;
diff_setup(&revs->diffopt);
next prev parent reply other threads:[~2010-01-18 4:02 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-13 16:13 Filenames and prefixes in extended diffs Andreas Gruenbacher
2010-01-13 19:49 ` Junio C Hamano
2010-01-14 0:16 ` Junio C Hamano
2010-01-15 13:32 ` Nanako Shiraishi
2010-01-15 18:09 ` Junio C Hamano
2010-01-15 20:50 ` [PATCH] grep: prepare to run outside of a work tree Junio C Hamano
2010-01-15 20:52 ` [PATCH] grep --no-index: allow use of "git grep" outside a git repository Junio C Hamano
2010-01-15 21:08 ` Jeff King
2010-01-16 1:05 ` Junio C Hamano
2010-01-16 1:15 ` Jeff King
2010-01-16 4:15 ` Junio C Hamano
2010-01-16 6:51 ` David Aguilar
2010-01-16 7:21 ` Junio C Hamano
2010-01-18 1:51 ` Jeff King
2010-01-18 3:35 ` Junio C Hamano
2010-01-18 4:02 ` Junio C Hamano [this message]
2010-01-18 5:57 ` Jeff King
2010-01-18 6:30 ` Junio C Hamano
2010-01-18 6:50 ` Jeff King
2010-01-18 23:22 ` Filenames and prefixes in extended diffs Andreas Gruenbacher
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=7v3a24ukku.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=davvid@gmail.com \
--cc=git@vger.kernel.org \
--cc=nanako3@lavabit.com \
--cc=peff@peff.net \
/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).