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

[PATCH 2/3] grep: factor out do_append_grep_pat()

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
May 20, 2012, 14:32 UTC
Message-ID
<4FB90096.9070600@lsrfire.ath.cx>
In-Reply-To
<CAEV-rjd=WjLu8e+UCnAHVxg7DTLWe+YrEO_Gs2rh5Oy1=KA5sw@mail.gmail.com>

Add do_append_grep_pat() as a shared function for adding patterns to the header pattern list and the general pattern list.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
Our first three star function. :)
 grep.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/grep.c b/grep.c
index a673ced..f961c2e 100644
--- a/grep.c
+++ b/grep.c
@@ -18,14 +18,19 @@ static struct grep_pat *create_grep_pat(const char *pat, size_t patlen,
 	return p;
 }
 
+static void do_append_grep_pat(struct grep_pat ***tail, struct grep_pat *p)
+{
+	**tail = p;
+	*tail = &p->next;
+	p->next = NULL;
+}
+
 void append_header_grep_pattern(struct grep_opt *opt,
 				enum grep_header_field field, const char *pat)
 {
 	struct grep_pat *p = create_grep_pat(pat, strlen(pat), "header", 0,
 					     GREP_PATTERN_HEAD, field);
-	*opt->header_tail = p;
-	opt->header_tail = &p->next;
-	p->next = NULL;
+	do_append_grep_pat(&opt->header_tail, p);
 }
 
 void append_grep_pattern(struct grep_opt *opt, const char *pat,
@@ -38,9 +43,7 @@ void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen,
 		     const char *origin, int no, enum grep_pat_token t)
 {
 	struct grep_pat *p = create_grep_pat(pat, patlen, origin, no, t, 0);
-	*opt->pattern_tail = p;
-	opt->pattern_tail = &p->next;
-	p->next = NULL;
+	do_append_grep_pat(&opt->pattern_tail, p);
 }
 
 struct grep_opt *grep_opt_dup(const struct grep_opt *opt)
-- 
1.7.10.2
Previous: René ScharfeNext: René Scharfe
Message 5 of 8 in “git grep -F doesn't behave like grep -F?”
  1. Torne (Richard Coles)May 18, 2012
  2. René ScharfeMay 18, 2012
  3. Torne (Richard Coles)May 18, 2012
  4. 1/3 grep: factor out create_grep_pat()René Scharfe, May 20, 2012
  5. 2/3 grep: factor out do_append_grep_pat()René Scharfe, May 20, 2012
  6. 3/3 grep: support newline separated pattern listRené Scharfe, May 20, 2012
  7. Junio C HamanoMay 20, 2012
  8. René ScharfeMay 21, 2012

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.