]> git.ipfire.org Git - thirdparty/git.git/blobdiff - grep.c
Merge branch 'en/fetch-negotiation-default-fix'
[thirdparty/git.git] / grep.c
diff --git a/grep.c b/grep.c
index 47c75ab7fb6ab362e988e7a1231e912d95efda7b..5bec7fd7935dedc94bbde1e8efe67745e2022702 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -26,10 +26,10 @@ static struct grep_opt grep_defaults = {
        .pattern_type_option = GREP_PATTERN_TYPE_UNSPECIFIED,
        .colors = {
                [GREP_COLOR_CONTEXT] = "",
-               [GREP_COLOR_FILENAME] = "",
+               [GREP_COLOR_FILENAME] = GIT_COLOR_MAGENTA,
                [GREP_COLOR_FUNCTION] = "",
-               [GREP_COLOR_LINENO] = "",
-               [GREP_COLOR_COLUMNNO] = "",
+               [GREP_COLOR_LINENO] = GIT_COLOR_GREEN,
+               [GREP_COLOR_COLUMNNO] = GIT_COLOR_GREEN,
                [GREP_COLOR_MATCH_CONTEXT] = GIT_COLOR_BOLD_RED,
                [GREP_COLOR_MATCH_SELECTED] = GIT_COLOR_BOLD_RED,
                [GREP_COLOR_SELECTED] = "",
@@ -595,6 +595,35 @@ 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_binexp(enum grep_expr_node kind,
+                                    struct grep_expr *left,
+                                    struct grep_expr *right)
+{
+       struct grep_expr *z = xcalloc(1, sizeof(*z));
+       z->node = kind;
+       z->u.binary.left = left;
+       z->u.binary.right = right;
+       return z;
+}
+
+static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *right)
+{
+       return grep_binexp(GREP_NODE_OR, left, right);
+}
+
+static struct grep_expr *grep_and_expr(struct grep_expr *left, struct grep_expr *right)
+{
+       return grep_binexp(GREP_NODE_AND, left, right);
+}
+
 static struct grep_expr *compile_pattern_or(struct grep_pat **);
 static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
 {
@@ -638,12 +667,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);
        }
@@ -652,7 +679,7 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)
 static struct grep_expr *compile_pattern_and(struct grep_pat **list)
 {
        struct grep_pat *p;
-       struct grep_expr *x, *y, *z;
+       struct grep_expr *x, *y;
 
        x = compile_pattern_not(list);
        p = *list;
@@ -665,11 +692,7 @@ static struct grep_expr *compile_pattern_and(struct grep_pat **list)
                y = compile_pattern_and(list);
                if (!y)
                        die("--and not followed by pattern expression");
-               CALLOC_ARRAY(z, 1);
-               z->node = GREP_NODE_AND;
-               z->u.binary.left = x;
-               z->u.binary.right = y;
-               return z;
+               return grep_and_expr(x, y);
        }
        return x;
 }
@@ -677,7 +700,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 +708,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;
 }
@@ -699,14 +718,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));
@@ -714,15 +725,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;