THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
5.2KB

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