]> git.ipfire.org Git - thirdparty/git.git/blobdiff - grep.c
Merge branch 'pk/rebase-in-c-2-basic'
[thirdparty/git.git] / grep.c
diff --git a/grep.c b/grep.c
index 2b26cee08d559ceba6dd5a83ae90aaa0155ebca8..f6bd89e40b7f7a8442a6e0a302a1e6080df5afbd 100644 (file)
--- 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;
@@ -1545,7 +1548,7 @@ static int match_funcname(struct grep_opt *opt, struct grep_source *gs, char *bo
 {
        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 +1711,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 +1745,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,7 +1805,7 @@ 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.
@@ -1818,11 +1822,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 +1841,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 +2172,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;