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