grep.hon commit oneway_merge(): only lstat() when told to update worktree (686b2de)
   1#ifndef GREP_H
   2#define GREP_H
   3#include "color.h"
   4#ifdef USE_LIBPCRE
   5#include <pcre.h>
   6#else
   7typedef int pcre;
   8typedef int pcre_extra;
   9#endif
  10#include "kwset.h"
  11#include "thread-utils.h"
  12#include "userdiff.h"
  13
  14enum grep_pat_token {
  15        GREP_PATTERN,
  16        GREP_PATTERN_HEAD,
  17        GREP_PATTERN_BODY,
  18        GREP_AND,
  19        GREP_OPEN_PAREN,
  20        GREP_CLOSE_PAREN,
  21        GREP_NOT,
  22        GREP_OR
  23};
  24
  25enum grep_context {
  26        GREP_CONTEXT_HEAD,
  27        GREP_CONTEXT_BODY
  28};
  29
  30enum grep_header_field {
  31        GREP_HEADER_AUTHOR = 0,
  32        GREP_HEADER_COMMITTER
  33};
  34#define GREP_HEADER_FIELD_MAX (GREP_HEADER_COMMITTER + 1)
  35
  36struct grep_pat {
  37        struct grep_pat *next;
  38        const char *origin;
  39        int no;
  40        enum grep_pat_token token;
  41        char *pattern;
  42        size_t patternlen;
  43        enum grep_header_field field;
  44        regex_t regexp;
  45        pcre *pcre_regexp;
  46        pcre_extra *pcre_extra_info;
  47        kwset_t kws;
  48        unsigned fixed:1;
  49        unsigned ignore_case:1;
  50        unsigned word_regexp:1;
  51};
  52
  53enum grep_expr_node {
  54        GREP_NODE_ATOM,
  55        GREP_NODE_NOT,
  56        GREP_NODE_AND,
  57        GREP_NODE_TRUE,
  58        GREP_NODE_OR
  59};
  60
  61struct grep_expr {
  62        enum grep_expr_node node;
  63        unsigned hit;
  64        union {
  65                struct grep_pat *atom;
  66                struct grep_expr *unary;
  67                struct {
  68                        struct grep_expr *left;
  69                        struct grep_expr *right;
  70                } binary;
  71        } u;
  72};
  73
  74struct grep_opt {
  75        struct grep_pat *pattern_list;
  76        struct grep_pat **pattern_tail;
  77        struct grep_pat *header_list;
  78        struct grep_pat **header_tail;
  79        struct grep_expr *pattern_expression;
  80        const char *prefix;
  81        int prefix_length;
  82        regex_t regexp;
  83        int linenum;
  84        int invert;
  85        int ignore_case;
  86        int status_only;
  87        int name_only;
  88        int unmatch_name_only;
  89        int count;
  90        int word_regexp;
  91        int fixed;
  92        int all_match;
  93        int debug;
  94#define GREP_BINARY_DEFAULT     0
  95#define GREP_BINARY_NOMATCH     1
  96#define GREP_BINARY_TEXT        2
  97        int binary;
  98        int extended;
  99        int pcre;
 100        int relative;
 101        int pathname;
 102        int null_following_name;
 103        int color;
 104        int max_depth;
 105        int funcname;
 106        int funcbody;
 107        char color_context[COLOR_MAXLEN];
 108        char color_filename[COLOR_MAXLEN];
 109        char color_function[COLOR_MAXLEN];
 110        char color_lineno[COLOR_MAXLEN];
 111        char color_match[COLOR_MAXLEN];
 112        char color_selected[COLOR_MAXLEN];
 113        char color_sep[COLOR_MAXLEN];
 114        int regflags;
 115        unsigned pre_context;
 116        unsigned post_context;
 117        unsigned last_shown;
 118        int show_hunk_mark;
 119        int file_break;
 120        int heading;
 121        void *priv;
 122
 123        void (*output)(struct grep_opt *opt, const void *data, size_t size);
 124        void *output_priv;
 125};
 126
 127extern void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t);
 128extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
 129extern void append_header_grep_pattern(struct grep_opt *, enum grep_header_field, const char *);
 130extern void compile_grep_patterns(struct grep_opt *opt);
 131extern void free_grep_patterns(struct grep_opt *opt);
 132extern int grep_buffer(struct grep_opt *opt, char *buf, unsigned long size);
 133
 134struct grep_source {
 135        char *name;
 136
 137        enum grep_source_type {
 138                GREP_SOURCE_SHA1,
 139                GREP_SOURCE_FILE,
 140                GREP_SOURCE_BUF,
 141        } type;
 142        void *identifier;
 143
 144        char *buf;
 145        unsigned long size;
 146
 147        struct userdiff_driver *driver;
 148};
 149
 150void grep_source_init(struct grep_source *gs, enum grep_source_type type,
 151                      const char *name, const void *identifier);
 152void grep_source_clear_data(struct grep_source *gs);
 153void grep_source_clear(struct grep_source *gs);
 154void grep_source_load_driver(struct grep_source *gs);
 155
 156
 157int grep_source(struct grep_opt *opt, struct grep_source *gs);
 158
 159extern struct grep_opt *grep_opt_dup(const struct grep_opt *opt);
 160extern int grep_threads_ok(const struct grep_opt *opt);
 161
 162#ifndef NO_PTHREADS
 163/*
 164 * Mutex used around access to the attributes machinery if
 165 * opt->use_threads.  Must be initialized/destroyed by callers!
 166 */
 167extern int grep_use_locks;
 168extern pthread_mutex_t grep_attr_mutex;
 169extern pthread_mutex_t grep_read_mutex;
 170
 171static inline void grep_read_lock(void)
 172{
 173        if (grep_use_locks)
 174                pthread_mutex_lock(&grep_read_mutex);
 175}
 176
 177static inline void grep_read_unlock(void)
 178{
 179        if (grep_use_locks)
 180                pthread_mutex_unlock(&grep_read_mutex);
 181}
 182
 183#else
 184#define grep_read_lock()
 185#define grep_read_unlock()
 186#endif
 187
 188#endif