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