grep: factor out do_append_grep_pat()

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed May 20, 2012 at 16:32 UTC 2b3873ff34ff937dad729407da4308be6a5bcd66
1 file changed +9 -6
grep.c
+9 -6
@@ -18,14 +18,19 @@ static struct grep_pat *create_grep_pat(const char *pat, size_t patlen,
18 return p;
19 }
20
21 +static void do_append_grep_pat(struct grep_pat ***tail, struct grep_pat *p)
22 +{
23 + **tail = p;
24 + *tail = &p->next;
25 + p->next = NULL;
26 +}
27 +
28 void append_header_grep_pattern(struct grep_opt *opt,
29 enum grep_header_field field, const char *pat)
30 {
31 struct grep_pat *p = create_grep_pat(pat, strlen(pat), "header", 0,
32 GREP_PATTERN_HEAD, field);
26 - *opt->header_tail = p;
27 - opt->header_tail = &p->next;
28 - p->next = NULL;
33 + do_append_grep_pat(&opt->header_tail, p);
34 }
35
36 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,
43 const char *origin, int no, enum grep_pat_token t)
44 {
45 struct grep_pat *p = create_grep_pat(pat, patlen, origin, no, t, 0);
41 - *opt->pattern_tail = p;
42 - opt->pattern_tail = &p->next;
43 - p->next = NULL;
46 + do_append_grep_pat(&opt->pattern_tail, p);
47 }
48
49 struct grep_opt *grep_opt_dup(const struct grep_opt *opt)