git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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);
 }
Previous: Junio C HamanoNext: Jeff King
Message 4 of 5 in “revision traversal: --author, --committer, and --grep.”
  1. 3/3 revision traversal: --author, --committer, and --grep.Junio C Hamano, Sep 18, 2006
  2. Jeff KingSep 18, 2006
  3. Junio C HamanoSep 18, 2006
  4. Linus TorvaldsSep 18, 2006
  5. rev-list: fix segfault with --{author,committer,grep}Jeff King, Sep 18, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.