]>
Commit | Line | Data |
---|---|---|
83b5d2f5 JH |
1 | #ifndef GREP_H |
2 | #define GREP_H | |
7e8f59d5 | 3 | #include "color.h" |
94da9193 ÆAB |
4 | #ifdef USE_LIBPCRE2 |
5 | #define PCRE2_CODE_UNIT_WIDTH 8 | |
6 | #include <pcre2.h> | |
797c3599 ÆAB |
7 | #if (PCRE2_MAJOR >= 10 && PCRE2_MINOR >= 36) || PCRE2_MAJOR >= 11 |
8 | #define GIT_PCRE2_VERSION_10_36_OR_HIGHER | |
9 | #endif | |
94da9193 ÆAB |
10 | #else |
11 | typedef int pcre2_code; | |
12 | typedef int pcre2_match_data; | |
13 | typedef int pcre2_compile_context; | |
94da9193 | 14 | #endif |
95ca1f98 ÆAB |
15 | #ifndef PCRE2_MATCH_INVALID_UTF |
16 | /* PCRE2_MATCH_* dummy also with !USE_LIBPCRE2, for test-pcre2-config.c */ | |
17 | #define PCRE2_MATCH_INVALID_UTF 0 | |
18 | #endif | |
0579f91d | 19 | #include "thread-utils.h" |
94ad9d9e | 20 | #include "userdiff.h" |
83b5d2f5 | 21 | |
38bbc2ea NTND |
22 | struct repository; |
23 | ||
83b5d2f5 JH |
24 | enum grep_pat_token { |
25 | GREP_PATTERN, | |
480c1ca6 JH |
26 | GREP_PATTERN_HEAD, |
27 | GREP_PATTERN_BODY, | |
83b5d2f5 JH |
28 | GREP_AND, |
29 | GREP_OPEN_PAREN, | |
30 | GREP_CLOSE_PAREN, | |
31 | GREP_NOT, | |
4b05548f | 32 | GREP_OR |
83b5d2f5 JH |
33 | }; |
34 | ||
480c1ca6 JH |
35 | enum grep_context { |
36 | GREP_CONTEXT_HEAD, | |
4b05548f | 37 | GREP_CONTEXT_BODY |
480c1ca6 JH |
38 | }; |
39 | ||
a4d7d2c6 | 40 | enum grep_header_field { |
3ce3ffb8 AP |
41 | GREP_HEADER_FIELD_MIN = 0, |
42 | GREP_HEADER_AUTHOR = GREP_HEADER_FIELD_MIN, | |
ad4813b3 | 43 | GREP_HEADER_COMMITTER, |
72fd13f7 | 44 | GREP_HEADER_REFLOG, |
ad4813b3 NTND |
45 | |
46 | /* Must be at the end of the enum */ | |
47 | GREP_HEADER_FIELD_MAX | |
a4d7d2c6 JH |
48 | }; |
49 | ||
fa151dc5 NTND |
50 | enum grep_color { |
51 | GREP_COLOR_CONTEXT, | |
52 | GREP_COLOR_FILENAME, | |
53 | GREP_COLOR_FUNCTION, | |
54 | GREP_COLOR_LINENO, | |
d036d667 | 55 | GREP_COLOR_COLUMNNO, |
fa151dc5 NTND |
56 | GREP_COLOR_MATCH_CONTEXT, |
57 | GREP_COLOR_MATCH_SELECTED, | |
58 | GREP_COLOR_SELECTED, | |
59 | GREP_COLOR_SEP, | |
60 | NR_GREP_COLORS | |
61 | }; | |
62 | ||
83b5d2f5 JH |
63 | struct grep_pat { |
64 | struct grep_pat *next; | |
65 | const char *origin; | |
66 | int no; | |
67 | enum grep_pat_token token; | |
526a858a | 68 | char *pattern; |
ed40a095 | 69 | size_t patternlen; |
a4d7d2c6 | 70 | enum grep_header_field field; |
83b5d2f5 | 71 | regex_t regexp; |
94da9193 ÆAB |
72 | pcre2_code *pcre2_pattern; |
73 | pcre2_match_data *pcre2_match_data; | |
74 | pcre2_compile_context *pcre2_compile_context; | |
10da030a | 75 | const uint8_t *pcre2_tables; |
94da9193 | 76 | uint32_t pcre2_jit_on; |
c822255c | 77 | unsigned fixed:1; |
09872f64 | 78 | unsigned is_fixed:1; |
5183bf67 | 79 | unsigned ignore_case:1; |
d7eb527d | 80 | unsigned word_regexp:1; |
83b5d2f5 JH |
81 | }; |
82 | ||
83 | enum grep_expr_node { | |
84 | GREP_NODE_ATOM, | |
85 | GREP_NODE_NOT, | |
86 | GREP_NODE_AND, | |
5aaeb733 | 87 | GREP_NODE_TRUE, |
4b05548f | 88 | GREP_NODE_OR |
83b5d2f5 JH |
89 | }; |
90 | ||
84befcd0 S |
91 | enum grep_pattern_type { |
92 | GREP_PATTERN_TYPE_UNSPECIFIED = 0, | |
93 | GREP_PATTERN_TYPE_BRE, | |
94 | GREP_PATTERN_TYPE_ERE, | |
95 | GREP_PATTERN_TYPE_FIXED, | |
96 | GREP_PATTERN_TYPE_PCRE | |
97 | }; | |
98 | ||
83b5d2f5 JH |
99 | struct grep_expr { |
100 | enum grep_expr_node node; | |
0ab7befa | 101 | unsigned hit; |
83b5d2f5 JH |
102 | union { |
103 | struct grep_pat *atom; | |
104 | struct grep_expr *unary; | |
105 | struct { | |
106 | struct grep_expr *left; | |
107 | struct grep_expr *right; | |
108 | } binary; | |
109 | } u; | |
110 | }; | |
111 | ||
112 | struct grep_opt { | |
113 | struct grep_pat *pattern_list; | |
114 | struct grep_pat **pattern_tail; | |
80235ba7 JH |
115 | struct grep_pat *header_list; |
116 | struct grep_pat **header_tail; | |
83b5d2f5 | 117 | struct grep_expr *pattern_expression; |
38bbc2ea | 118 | struct repository *repo; |
493b7a08 | 119 | const char *prefix; |
83b5d2f5 JH |
120 | int prefix_length; |
121 | regex_t regexp; | |
3e230fa1 | 122 | int linenum; |
017c0fcf | 123 | int columnnum; |
3e230fa1 | 124 | int invert; |
5183bf67 | 125 | int ignore_case; |
3e230fa1 RS |
126 | int status_only; |
127 | int name_only; | |
128 | int unmatch_name_only; | |
129 | int count; | |
130 | int word_regexp; | |
131 | int fixed; | |
132 | int all_match; | |
83b5d2f5 JH |
133 | #define GREP_BINARY_DEFAULT 0 |
134 | #define GREP_BINARY_NOMATCH 1 | |
135 | #define GREP_BINARY_TEXT 2 | |
3e230fa1 | 136 | int binary; |
335ec3bf | 137 | int allow_textconv; |
3e230fa1 | 138 | int extended; |
baa6378f | 139 | int use_reflog_filter; |
94da9193 | 140 | int pcre2; |
3e230fa1 RS |
141 | int relative; |
142 | int pathname; | |
143 | int null_following_name; | |
9d8db06e | 144 | int only_matching; |
7e8f59d5 | 145 | int color; |
a91f453f | 146 | int max_depth; |
2944e4e6 | 147 | int funcname; |
ba8ea749 | 148 | int funcbody; |
84befcd0 S |
149 | int extended_regexp_option; |
150 | int pattern_type_option; | |
44570188 | 151 | int ignore_locale; |
fa151dc5 | 152 | char colors[NR_GREP_COLORS][COLOR_MAXLEN]; |
83b5d2f5 JH |
153 | unsigned pre_context; |
154 | unsigned post_context; | |
5dd06d38 | 155 | unsigned last_shown; |
046802d0 | 156 | int show_hunk_mark; |
a8f0e764 | 157 | int file_break; |
1d84f72e | 158 | int heading; |
60ecac98 | 159 | void *priv; |
5b594f45 FK |
160 | |
161 | void (*output)(struct grep_opt *opt, const void *data, size_t size); | |
162 | void *output_priv; | |
83b5d2f5 JH |
163 | }; |
164 | ||
55454427 DL |
165 | int grep_config(const char *var, const char *value, void *); |
166 | void grep_init(struct grep_opt *, struct repository *repo, const char *prefix); | |
513f2b0b | 167 | void grep_destroy(void); |
c5c31d33 | 168 | void grep_commit_pattern_type(enum grep_pattern_type, struct grep_opt *opt); |
7687a054 | 169 | |
55454427 DL |
170 | void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t); |
171 | void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t); | |
172 | void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *); | |
173 | void compile_grep_patterns(struct grep_opt *opt); | |
174 | void free_grep_patterns(struct grep_opt *opt); | |
175 | int grep_buffer(struct grep_opt *opt, char *buf, unsigned long size); | |
83b5d2f5 | 176 | |
e1327023 JK |
177 | struct grep_source { |
178 | char *name; | |
179 | ||
180 | enum grep_source_type { | |
1c41c82b | 181 | GREP_SOURCE_OID, |
e1327023 JK |
182 | GREP_SOURCE_FILE, |
183 | GREP_SOURCE_BUF, | |
184 | } type; | |
185 | void *identifier; | |
186 | ||
187 | char *buf; | |
188 | unsigned long size; | |
94ad9d9e | 189 | |
55c61688 | 190 | char *path; /* for attribute lookups */ |
94ad9d9e | 191 | struct userdiff_driver *driver; |
e1327023 JK |
192 | }; |
193 | ||
194 | void grep_source_init(struct grep_source *gs, enum grep_source_type type, | |
55c61688 NTND |
195 | const char *name, const char *path, |
196 | const void *identifier); | |
e1327023 JK |
197 | void grep_source_clear_data(struct grep_source *gs); |
198 | void grep_source_clear(struct grep_source *gs); | |
acd00ea0 NTND |
199 | void grep_source_load_driver(struct grep_source *gs, |
200 | struct index_state *istate); | |
07a7d656 | 201 | |
e1327023 JK |
202 | |
203 | int grep_source(struct grep_opt *opt, struct grep_source *gs); | |
204 | ||
55454427 DL |
205 | struct grep_opt *grep_opt_dup(const struct grep_opt *opt); |
206 | int grep_threads_ok(const struct grep_opt *opt); | |
5b594f45 | 207 | |
0579f91d TR |
208 | /* |
209 | * Mutex used around access to the attributes machinery if | |
210 | * opt->use_threads. Must be initialized/destroyed by callers! | |
211 | */ | |
78db6ea9 | 212 | extern int grep_use_locks; |
0579f91d | 213 | extern pthread_mutex_t grep_attr_mutex; |
b3aeb285 | 214 | |
83b5d2f5 | 215 | #endif |