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