5 #define PCRE2_CODE_UNIT_WIDTH 8
7 #if (PCRE2_MAJOR >= 10 && PCRE2_MINOR >= 36) || PCRE2_MAJOR >= 11
8 #define GIT_PCRE2_VERSION_10_36_OR_HIGHER
10 #if (PCRE2_MAJOR >= 10 && PCRE2_MINOR >= 35) || PCRE2_MAJOR >= 11
11 #define GIT_PCRE2_VERSION_10_35_OR_HIGHER
13 #if (PCRE2_MAJOR >= 10 && PCRE2_MINOR >= 34) || PCRE2_MAJOR >= 11
14 #define GIT_PCRE2_VERSION_10_34_OR_HIGHER
17 typedef int pcre2_code
;
18 typedef int pcre2_match_data
;
19 typedef int pcre2_compile_context
;
20 typedef int pcre2_general_context
;
22 #ifndef PCRE2_MATCH_INVALID_UTF
23 /* PCRE2_MATCH_* dummy also with !USE_LIBPCRE2, for test-pcre2-config.c */
24 #define PCRE2_MATCH_INVALID_UTF 0
26 #include "thread-utils.h"
47 enum grep_header_field
{
48 GREP_HEADER_FIELD_MIN
= 0,
49 GREP_HEADER_AUTHOR
= GREP_HEADER_FIELD_MIN
,
50 GREP_HEADER_COMMITTER
,
53 /* Must be at the end of the enum */
63 GREP_COLOR_MATCH_CONTEXT
,
64 GREP_COLOR_MATCH_SELECTED
,
71 struct grep_pat
*next
;
74 enum grep_pat_token token
;
77 enum grep_header_field field
;
79 pcre2_code
*pcre2_pattern
;
80 pcre2_match_data
*pcre2_match_data
;
81 pcre2_compile_context
*pcre2_compile_context
;
82 pcre2_general_context
*pcre2_general_context
;
83 const uint8_t *pcre2_tables
;
84 uint32_t pcre2_jit_on
;
87 unsigned ignore_case
:1;
88 unsigned word_regexp
:1;
99 enum grep_pattern_type
{
100 GREP_PATTERN_TYPE_UNSPECIFIED
= 0,
101 GREP_PATTERN_TYPE_BRE
,
102 GREP_PATTERN_TYPE_ERE
,
103 GREP_PATTERN_TYPE_FIXED
,
104 GREP_PATTERN_TYPE_PCRE
108 enum grep_expr_node node
;
111 struct grep_pat
*atom
;
112 struct grep_expr
*unary
;
114 struct grep_expr
*left
;
115 struct grep_expr
*right
;
121 struct grep_pat
*pattern_list
;
122 struct grep_pat
**pattern_tail
;
123 struct grep_pat
*header_list
;
124 struct grep_pat
**header_tail
;
125 struct grep_expr
*pattern_expression
;
128 * NEEDSWORK: See if we can remove this field, because the repository
129 * should probably be per-source. That is, grep.c functions using this
130 * field should probably start using "repo" in "struct grep_source"
133 * This is potentially the cause of at least one bug - "git grep"
134 * using the textconv attributes from the superproject on the
135 * submodules. See the failing "git grep --textconv" tests in
136 * t7814-grep-recurse-submodules.sh for more information.
138 struct repository
*repo
;
146 int unmatch_name_only
;
152 #define GREP_BINARY_DEFAULT 0
153 #define GREP_BINARY_NOMATCH 1
154 #define GREP_BINARY_TEXT 2
157 int use_reflog_filter
;
160 int null_following_name
;
166 int extended_regexp_option
;
167 enum grep_pattern_type pattern_type_option
;
169 char colors
[NR_GREP_COLORS
][COLOR_MAXLEN
];
170 unsigned pre_context
;
171 unsigned post_context
;
179 void (*output
)(struct grep_opt
*opt
, const void *data
, size_t size
);
183 #define GREP_OPT_INIT { \
188 .pattern_type_option = GREP_PATTERN_TYPE_UNSPECIFIED, \
190 [GREP_COLOR_CONTEXT] = "", \
191 [GREP_COLOR_FILENAME] = GIT_COLOR_MAGENTA, \
192 [GREP_COLOR_FUNCTION] = "", \
193 [GREP_COLOR_LINENO] = GIT_COLOR_GREEN, \
194 [GREP_COLOR_COLUMNNO] = GIT_COLOR_GREEN, \
195 [GREP_COLOR_MATCH_CONTEXT] = GIT_COLOR_BOLD_RED, \
196 [GREP_COLOR_MATCH_SELECTED] = GIT_COLOR_BOLD_RED, \
197 [GREP_COLOR_SELECTED] = "", \
198 [GREP_COLOR_SEP] = GIT_COLOR_CYAN, \
200 .only_matching = 0, \
202 .output = std_output, \
205 struct config_context
;
206 int grep_config(const char *var
, const char *value
,
207 const struct config_context
*ctx
, void *data
);
208 void grep_init(struct grep_opt
*, struct repository
*repo
);
210 void append_grep_pat(struct grep_opt
*opt
, const char *pat
, size_t patlen
, const char *origin
, int no
, enum grep_pat_token t
);
211 void append_grep_pattern(struct grep_opt
*opt
, const char *pat
, const char *origin
, int no
, enum grep_pat_token t
);
212 void append_header_grep_pattern(struct grep_opt
*, enum grep_header_field
, const char *);
213 void compile_grep_patterns(struct grep_opt
*opt
);
214 void free_grep_patterns(struct grep_opt
*opt
);
215 int grep_buffer(struct grep_opt
*opt
, const char *buf
, unsigned long size
);
217 /* The field parameter is only used to filter header patterns
218 * (where appropriate). If filtering isn't desirable
219 * GREP_HEADER_FIELD_MAX should be supplied.
221 int grep_next_match(struct grep_opt
*opt
,
222 const char *bol
, const char *eol
,
223 enum grep_context ctx
, regmatch_t
*pmatch
,
224 enum grep_header_field field
, int eflags
);
229 enum grep_source_type
{
235 struct repository
*repo
; /* if GREP_SOURCE_OID */
240 char *path
; /* for attribute lookups */
241 struct userdiff_driver
*driver
;
244 void grep_source_init_file(struct grep_source
*gs
, const char *name
,
246 void grep_source_init_oid(struct grep_source
*gs
, const char *name
,
247 const char *path
, const struct object_id
*oid
,
248 struct repository
*repo
);
249 void grep_source_clear_data(struct grep_source
*gs
);
250 void grep_source_clear(struct grep_source
*gs
);
251 void grep_source_load_driver(struct grep_source
*gs
,
252 struct index_state
*istate
);
255 int grep_source(struct grep_opt
*opt
, struct grep_source
*gs
);
257 struct grep_opt
*grep_opt_dup(const struct grep_opt
*opt
);
260 * Mutex used around access to the attributes machinery if
261 * opt->use_threads. Must be initialized/destroyed by callers!
263 extern int grep_use_locks
;
264 extern pthread_mutex_t grep_attr_mutex
;