summaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2022-01-06 09:51:00 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-01-06 20:07:09 (GMT)
commit9dbf00ba785e2cf950fadb2c20e81422ebb1a4d5 (patch)
tree50176dbaf6e151fe71b11881c53e485e5a94e318 /grep.c
parente83ba647f7c61cf945690d6a0bd8c172a6498dc8 (diff)
downloadgit-9dbf00ba785e2cf950fadb2c20e81422ebb1a4d5.zip
git-9dbf00ba785e2cf950fadb2c20e81422ebb1a4d5.tar.gz
git-9dbf00ba785e2cf950fadb2c20e81422ebb1a4d5.tar.bz2
grep: use grep_or_expr() in compile_pattern_or()
Move the definition of grep_or_expr() up and use this function in compile_pattern_or() to reduce code duplication. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/grep.c b/grep.c
index 47c75ab..f1bbe80 100644
--- a/grep.c
+++ b/grep.c
@@ -595,6 +595,15 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
}
}
+static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right)
+{
+ struct grep_expr *z = xcalloc(1, sizeof(*z));
+ z->node = GREP_NODE_OR;
+ z->u.binary.left = left;
+ z->u.binary.right = right;
+ return z;
+}
+
static struct grep_expr *compile_pattern_or(struct grep_pat **);
static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
{
@@ -677,7 +686,7 @@ static struct grep_expr *compile_pattern_and(struct grep_pat **list)
static struct grep_expr *compile_pattern_or(struct grep_pat **list)
{
struct grep_pat *p;
- struct grep_expr *x, *y, *z;
+ struct grep_expr *x, *y;
x = compile_pattern_and(list);
p = *list;
@@ -685,11 +694,7 @@ static struct grep_expr *compile_pattern_or(struct grep_pat **list)
y = compile_pattern_or(list);
if (!y)
die("not a pattern expression %s", p->pattern);
- CALLOC_ARRAY(z, 1);
- z->node = GREP_NODE_OR;
- z->u.binary.left = x;
- z->u.binary.right = y;
- return z;
+ return grep_or_expr(x, y);
}
return x;
}
@@ -714,15 +719,6 @@ static struct grep_expr *grep_true_expr(void)
return z;
}
-static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right)
-{
- struct grep_expr *z = xcalloc(1, sizeof(*z));
- z->node = GREP_NODE_OR;
- z->u.binary.left = left;
- z->u.binary.right = right;
- return z;
-}
-
static struct grep_expr *prep_header_patterns(struct grep_opt *opt)
{
struct grep_pat *p;