Skip to content

Commit 2b3873f

Browse files
René Scharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fc45675 commit 2b3873f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

grep.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ static struct grep_pat *create_grep_pat(const char *pat, size_t patlen,
1818
return p;
1919
}
2020

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+
2128
void append_header_grep_pattern(struct grep_opt *opt,
2229
enum grep_header_field field, const char *pat)
2330
{
2431
struct grep_pat *p = create_grep_pat(pat, strlen(pat), "header", 0,
2532
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);
2934
}
3035

3136
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,
3843
const char *origin, int no, enum grep_pat_token t)
3944
{
4045
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);
4447
}
4548

4649
struct grep_opt *grep_opt_dup(const struct grep_opt *opt)

0 commit comments

Comments
 (0)