grep: make sure NO_LIBPCRE1_JIT disable JIT in PCRE1
[git/debian.git] / grep.h
blob1a044c501ed49cfae8235379e9f79b1167523526
1 #ifndef GREP_H
2 #define GREP_H
3 #include "color.h"
4 #ifdef USE_LIBPCRE1
5 #include <pcre.h>
6 #ifndef NO_LIBPCRE1_JIT
7 #ifdef PCRE_CONFIG_JIT
8 #define GIT_PCRE1_USE_JIT
9 #define GIT_PCRE_STUDY_JIT_COMPILE PCRE_STUDY_JIT_COMPILE
10 #endif
11 #endif
12 #ifndef GIT_PCRE_STUDY_JIT_COMPILE
13 #define GIT_PCRE_STUDY_JIT_COMPILE 0
14 #endif
15 #else
16 typedef int pcre;
17 typedef int pcre_extra;
18 #endif
19 #ifdef USE_LIBPCRE2
20 #define PCRE2_CODE_UNIT_WIDTH 8
21 #include <pcre2.h>
22 #else
23 typedef int pcre2_code;
24 typedef int pcre2_match_data;
25 typedef int pcre2_compile_context;
26 #endif
27 #include "thread-utils.h"
28 #include "userdiff.h"
30 struct repository;
32 enum grep_pat_token {
33 GREP_PATTERN,
34 GREP_PATTERN_HEAD,
35 GREP_PATTERN_BODY,
36 GREP_AND,
37 GREP_OPEN_PAREN,
38 GREP_CLOSE_PAREN,
39 GREP_NOT,
40 GREP_OR
43 enum grep_context {
44 GREP_CONTEXT_HEAD,
45 GREP_CONTEXT_BODY
48 enum grep_header_field {
49 GREP_HEADER_FIELD_MIN = 0,
50 GREP_HEADER_AUTHOR = GREP_HEADER_FIELD_MIN,
51 GREP_HEADER_COMMITTER,
52 GREP_HEADER_REFLOG,
54 /* Must be at the end of the enum */
55 GREP_HEADER_FIELD_MAX
58 enum grep_color {
59 GREP_COLOR_CONTEXT,
60 GREP_COLOR_FILENAME,
61 GREP_COLOR_FUNCTION,
62 GREP_COLOR_LINENO,
63 GREP_COLOR_COLUMNNO,
64 GREP_COLOR_MATCH_CONTEXT,
65 GREP_COLOR_MATCH_SELECTED,
66 GREP_COLOR_SELECTED,
67 GREP_COLOR_SEP,
68 NR_GREP_COLORS
71 struct grep_pat {
72 struct grep_pat *next;
73 const char *origin;
74 int no;
75 enum grep_pat_token token;
76 char *pattern;
77 size_t patternlen;
78 enum grep_header_field field;
79 regex_t regexp;
80 pcre *pcre1_regexp;
81 pcre_extra *pcre1_extra_info;
82 const unsigned char *pcre1_tables;
83 int pcre1_jit_on;
84 pcre2_code *pcre2_pattern;
85 pcre2_match_data *pcre2_match_data;
86 pcre2_compile_context *pcre2_compile_context;
87 uint32_t pcre2_jit_on;
88 unsigned fixed:1;
89 unsigned is_fixed:1;
90 unsigned ignore_case:1;
91 unsigned word_regexp:1;
94 enum grep_expr_node {
95 GREP_NODE_ATOM,
96 GREP_NODE_NOT,
97 GREP_NODE_AND,
98 GREP_NODE_TRUE,
99 GREP_NODE_OR
102 enum grep_pattern_type {
103 GREP_PATTERN_TYPE_UNSPECIFIED = 0,
104 GREP_PATTERN_TYPE_BRE,
105 GREP_PATTERN_TYPE_ERE,
106 GREP_PATTERN_TYPE_FIXED,
107 GREP_PATTERN_TYPE_PCRE
110 struct grep_expr {
111 enum grep_expr_node node;
112 unsigned hit;
113 union {
114 struct grep_pat *atom;
115 struct grep_expr *unary;
116 struct {
117 struct grep_expr *left;
118 struct grep_expr *right;
119 } binary;
120 } u;
123 struct grep_opt {
124 struct grep_pat *pattern_list;
125 struct grep_pat **pattern_tail;
126 struct grep_pat *header_list;
127 struct grep_pat **header_tail;
128 struct grep_expr *pattern_expression;
129 struct repository *repo;
130 const char *prefix;
131 int prefix_length;
132 regex_t regexp;
133 int linenum;
134 int columnnum;
135 int invert;
136 int ignore_case;
137 int status_only;
138 int name_only;
139 int unmatch_name_only;
140 int count;
141 int word_regexp;
142 int fixed;
143 int all_match;
144 int debug;
145 #define GREP_BINARY_DEFAULT 0
146 #define GREP_BINARY_NOMATCH 1
147 #define GREP_BINARY_TEXT 2
148 int binary;
149 int allow_textconv;
150 int extended;
151 int use_reflog_filter;
152 int pcre1;
153 int pcre2;
154 int relative;
155 int pathname;
156 int null_following_name;
157 int only_matching;
158 int color;
159 int max_depth;
160 int funcname;
161 int funcbody;
162 int extended_regexp_option;
163 int pattern_type_option;
164 int ignore_locale;
165 char colors[NR_GREP_COLORS][COLOR_MAXLEN];
166 unsigned pre_context;
167 unsigned post_context;
168 unsigned last_shown;
169 int show_hunk_mark;
170 int file_break;
171 int heading;
172 void *priv;
174 void (*output)(struct grep_opt *opt, const void *data, size_t size);
175 void *output_priv;
178 void init_grep_defaults(struct repository *);
179 int grep_config(const char *var, const char *value, void *);
180 void grep_init(struct grep_opt *, struct repository *repo, const char *prefix);
181 void grep_commit_pattern_type(enum grep_pattern_type, struct grep_opt *opt);
183 void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t);
184 void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
185 void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *);
186 void compile_grep_patterns(struct grep_opt *opt);
187 void free_grep_patterns(struct grep_opt *opt);
188 int grep_buffer(struct grep_opt *opt, char *buf, unsigned long size);
190 struct grep_source {
191 char *name;
193 enum grep_source_type {
194 GREP_SOURCE_OID,
195 GREP_SOURCE_FILE,
196 GREP_SOURCE_BUF,
197 } type;
198 void *identifier;
200 char *buf;
201 unsigned long size;
203 char *path; /* for attribute lookups */
204 struct userdiff_driver *driver;
207 void grep_source_init(struct grep_source *gs, enum grep_source_type type,
208 const char *name, const char *path,
209 const void *identifier);
210 void grep_source_clear_data(struct grep_source *gs);
211 void grep_source_clear(struct grep_source *gs);
212 void grep_source_load_driver(struct grep_source *gs,
213 struct index_state *istate);
216 int grep_source(struct grep_opt *opt, struct grep_source *gs);
218 struct grep_opt *grep_opt_dup(const struct grep_opt *opt);
219 int grep_threads_ok(const struct grep_opt *opt);
222 * Mutex used around access to the attributes machinery if
223 * opt->use_threads. Must be initialized/destroyed by callers!
225 extern int grep_use_locks;
226 extern pthread_mutex_t grep_attr_mutex;
227 extern pthread_mutex_t grep_read_mutex;
229 static inline void grep_read_lock(void)
231 if (grep_use_locks)
232 pthread_mutex_lock(&grep_read_mutex);
235 static inline void grep_read_unlock(void)
237 if (grep_use_locks)
238 pthread_mutex_unlock(&grep_read_mutex);
241 #endif