summaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2022-01-06 09:54:19 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-01-06 20:07:10 (GMT)
commite2b154277addad0a70b23d03c9156ac8e08c4a82 (patch)
tree7323697dad83b16e3f9f0f87925199eef1686090 /grep.c
parent9dbf00ba785e2cf950fadb2c20e81422ebb1a4d5 (diff)
downloadgit-e2b154277addad0a70b23d03c9156ac8e08c4a82.zip
git-e2b154277addad0a70b23d03c9156ac8e08c4a82.tar.gz
git-e2b154277addad0a70b23d03c9156ac8e08c4a82.tar.bz2
grep: use grep_not_expr() in compile_pattern_not()
Move the definition of grep_not_expr() up and use this function in compile_pattern_not() to simplify the code and reduce 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.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/grep.c b/grep.c
index f1bbe80..bdbd06d 100644
--- a/grep.c
+++ b/grep.c
@@ -595,6 +595,14 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
}
}
+static struct grep_expr *grep_not_expr(struct grep_expr *expr)
+{
+ struct grep_expr *z = xcalloc(1, sizeof(*z));
+ z->node = GREP_NODE_NOT;
+ z->u.unary = expr;
+ 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));
@@ -647,12 +655,10 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)
if (!p->next)
die("--not not followed by pattern expression");
*list = p->next;
- CALLOC_ARRAY(x, 1);
- x->node = GREP_NODE_NOT;
- x->u.unary = compile_pattern_not(list);
- if (!x->u.unary)
+ x = compile_pattern_not(list);
+ if (!x)
die("--not followed by non pattern expression");
- return x;
+ return grep_not_expr(x);
default:
return compile_pattern_atom(list);
}
@@ -704,14 +710,6 @@ static struct grep_expr *compile_pattern_expr(struct grep_pat **list)
return compile_pattern_or(list);
}
-static struct grep_expr *grep_not_expr(struct grep_expr *expr)
-{
- struct grep_expr *z = xcalloc(1, sizeof(*z));
- z->node = GREP_NODE_NOT;
- z->u.unary = expr;
- return z;
-}
-
static struct grep_expr *grep_true_expr(void)
{
struct grep_expr *z = xcalloc(1, sizeof(*z));