Re: [PATCH 3/3] revision traversal: --author, --committer, and --grep.
- From
Linus Torvalds <torvalds@osdl.org>
- Date
- Sep 18, 2006, 17:07 UTC
- Message-ID
- <Pine.LNX.4.64.0609181001361.4388@g5.osdl.org>
- In-Reply-To
- <7vslipsm4x.fsf@assigned-by-dhcp.cox.net>
On Sun, 17 Sep 2006, Junio C Hamano wrote:
> > I wanted to default it to left anchored, so this was somewhat > deliberate, but this is probably subject to taste.
I know that I'd prefer a rule where
"--author=^Junio"
would result in the grep-pattern being "^author Junio", but without the initial '^' it would be "^author .*Junio".
So something like this, perhaps? It allows the regular left anchoring syntax ('^' at the start of a pattern), but defaults to the default grep behaviour ("anywhere in the line").
Linus
---
diff --git a/revision.c b/revision.c index 26dd418..bca1229 100644 --- a/revision.c +++ b/revision.c @@ -677,6 +677,7 @@ int handle_revision_arg(const char *arg, static void add_header_grep(struct rev_info *revs, const char *field, const char *pattern) { char *pat; + const char *prefix; int patlen, fldlen; if (!revs->header_filter) { @@ -689,8 +690,13 @@ static void add_header_grep(struct rev_i fldlen = strlen(field); patlen = strlen(pattern); - pat = xmalloc(patlen + fldlen + 3); - sprintf(pat, "^%s %s", field, pattern); + pat = xmalloc(patlen + fldlen + 10); + prefix = ".*"; + if (*pattern == '^') { + prefix = ""; + pattern++; + } + sprintf(pat, "^%s %s%s", field, prefix, pattern); append_grep_pattern(revs->header_filter, pat, "command line", 0, GREP_PATTERN); }