summaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/grep.c b/grep.c
index 2b26cee..0d50598 100644
--- a/grep.c
+++ b/grep.c
@@ -11,7 +11,8 @@
#include "help.h"
static int grep_source_load(struct grep_source *gs);
-static int grep_source_is_binary(struct grep_source *gs);
+static int grep_source_is_binary(struct grep_source *gs,
+ struct index_state *istate);
static struct grep_opt grep_defaults;
@@ -42,7 +43,7 @@ static void color_set(char *dst, const char *color_bytes)
* We could let the compiler do this, but without C99 initializers
* the code gets unwieldy and unreadable, so...
*/
-void init_grep_defaults(void)
+void init_grep_defaults(struct repository *repo)
{
struct grep_opt *opt = &grep_defaults;
static int run_once;
@@ -52,6 +53,7 @@ void init_grep_defaults(void)
run_once++;
memset(opt, 0, sizeof(*opt));
+ opt->repo = repo;
opt->relative = 1;
opt->pathname = 1;
opt->max_depth = -1;
@@ -149,12 +151,13 @@ int grep_config(const char *var, const char *value, void *cb)
* default values from the template we read the configuration
* information in an earlier call to git_config(grep_config).
*/
-void grep_init(struct grep_opt *opt, const char *prefix)
+void grep_init(struct grep_opt *opt, struct repository *repo, const char *prefix)
{
struct grep_opt *def = &grep_defaults;
int i;
memset(opt, 0, sizeof(*opt));
+ opt->repo = repo;
opt->prefix = prefix;
opt->prefix_length = (prefix && *prefix) ? strlen(prefix) : 0;
opt->pattern_tail = &opt->pattern_list;
@@ -1510,7 +1513,6 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
}
}
-#ifndef NO_PTHREADS
int grep_use_locks;
/*
@@ -1536,16 +1538,11 @@ static inline void grep_attr_unlock(void)
*/
pthread_mutex_t grep_read_mutex;
-#else
-#define grep_attr_lock()
-#define grep_attr_unlock()
-#endif
-
static int match_funcname(struct grep_opt *opt, struct grep_source *gs, char *bol, char *eol)
{
xdemitconf_t *xecfg = opt->priv;
if (xecfg && !xecfg->find_func) {
- grep_source_load_driver(gs);
+ grep_source_load_driver(gs, opt->repo->index);
if (gs->driver->funcname.pattern) {
const struct userdiff_funcname *pe = &gs->driver->funcname;
xdiff_set_find_func(xecfg, pe->pattern, pe->cflags);
@@ -1708,7 +1705,8 @@ static int look_ahead(struct grep_opt *opt,
return 0;
}
-static int fill_textconv_grep(struct userdiff_driver *driver,
+static int fill_textconv_grep(struct repository *r,
+ struct userdiff_driver *driver,
struct grep_source *gs)
{
struct diff_filespec *df;
@@ -1741,7 +1739,7 @@ static int fill_textconv_grep(struct userdiff_driver *driver,
* structure.
*/
grep_read_lock();
- size = fill_textconv(driver, df, &buf);
+ size = fill_textconv(r, driver, df, &buf);
grep_read_unlock();
free_filespec(df);
@@ -1801,13 +1799,13 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
opt->last_shown = 0;
if (opt->allow_textconv) {
- grep_source_load_driver(gs);
+ grep_source_load_driver(gs, opt->repo->index);
/*
* We might set up the shared textconv cache data here, which
* is not thread-safe.
*/
grep_attr_lock();
- textconv = userdiff_get_textconv(gs->driver);
+ textconv = userdiff_get_textconv(opt->repo, gs->driver);
grep_attr_unlock();
}
@@ -1818,11 +1816,11 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
if (!textconv) {
switch (opt->binary) {
case GREP_BINARY_DEFAULT:
- if (grep_source_is_binary(gs))
+ if (grep_source_is_binary(gs, opt->repo->index))
binary_match_only = 1;
break;
case GREP_BINARY_NOMATCH:
- if (grep_source_is_binary(gs))
+ if (grep_source_is_binary(gs, opt->repo->index))
return 0; /* Assume unmatch */
break;
case GREP_BINARY_TEXT:
@@ -1837,7 +1835,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
try_lookahead = should_lookahead(opt);
- if (fill_textconv_grep(textconv, gs) < 0)
+ if (fill_textconv_grep(opt->repo, textconv, gs) < 0)
return 0;
bol = gs->buf;
@@ -2168,22 +2166,24 @@ static int grep_source_load(struct grep_source *gs)
BUG("invalid grep_source type to load");
}
-void grep_source_load_driver(struct grep_source *gs)
+void grep_source_load_driver(struct grep_source *gs,
+ struct index_state *istate)
{
if (gs->driver)
return;
grep_attr_lock();
if (gs->path)
- gs->driver = userdiff_find_by_path(gs->path);
+ gs->driver = userdiff_find_by_path(istate, gs->path);
if (!gs->driver)
gs->driver = userdiff_find_by_name("default");
grep_attr_unlock();
}
-static int grep_source_is_binary(struct grep_source *gs)
+static int grep_source_is_binary(struct grep_source *gs,
+ struct index_state *istate)
{
- grep_source_load_driver(gs);
+ grep_source_load_driver(gs, istate);
if (gs->driver->binary != -1)
return gs->driver->binary;