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