grep.c: remove implicit dependency on the_index

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Sep 21, 2018 at 17:57 UTC 38bbc2ea39372ce1b7eb494b31948f4a8a903f88
5 files changed +18 -12
builtin/grep.c
+2 -2
@@ -904,9 +904,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
904 OPT_END()
905 };
906
907 - init_grep_defaults();
907 + init_grep_defaults(the_repository);
908 git_config(grep_cmd_config, NULL);
909 - grep_init(&opt, prefix);
909 + grep_init(&opt, the_repository, prefix);
910
911 /*
912 * If there is no -- then the paths must exist in the working
builtin/log.c
+1 -1
@@ -115,7 +115,7 @@ static int log_line_range_callback(const struct option *option, const char *arg,
115
116 static void init_log_defaults(void)
117 {
118 - init_grep_defaults();
118 + init_grep_defaults(the_repository);
119 init_diff_ui_defaults();
120
121 decoration_style = auto_decoration_style();
grep.c
+8 -5
@@ -42,7 +42,7 @@ static void color_set(char *dst, const char *color_bytes)
42 * We could let the compiler do this, but without C99 initializers
43 * the code gets unwieldy and unreadable, so...
44 */
45 -void init_grep_defaults(void)
45 +void init_grep_defaults(struct repository *repo)
46 {
47 struct grep_opt *opt = &grep_defaults;
48 static int run_once;
@@ -52,6 +52,7 @@ void init_grep_defaults(void)
52 run_once++;
53
54 memset(opt, 0, sizeof(*opt));
55 + opt->repo = repo;
56 opt->relative = 1;
57 opt->pathname = 1;
58 opt->max_depth = -1;
@@ -149,12 +150,13 @@ int grep_config(const char *var, const char *value, void *cb)
150 * default values from the template we read the configuration
151 * information in an earlier call to git_config(grep_config).
152 */
152 -void grep_init(struct grep_opt *opt, const char *prefix)
153 +void grep_init(struct grep_opt *opt, struct repository *repo, const char *prefix)
154 {
155 struct grep_opt *def = &grep_defaults;
156 int i;
157
158 memset(opt, 0, sizeof(*opt));
159 + opt->repo = repo;
160 opt->prefix = prefix;
161 opt->prefix_length = (prefix && *prefix) ? strlen(prefix) : 0;
162 opt->pattern_tail = &opt->pattern_list;
@@ -1708,7 +1710,8 @@ static int look_ahead(struct grep_opt *opt,
1710 return 0;
1711 }
1712
1711 -static int fill_textconv_grep(struct userdiff_driver *driver,
1713 +static int fill_textconv_grep(struct repository *r,
1714 + struct userdiff_driver *driver,
1715 struct grep_source *gs)
1716 {
1717 struct diff_filespec *df;
@@ -1741,7 +1744,7 @@ static int fill_textconv_grep(struct userdiff_driver *driver,
1744 * structure.
1745 */
1746 grep_read_lock();
1744 - size = fill_textconv(the_repository, driver, df, &buf);
1747 + size = fill_textconv(r, driver, df, &buf);
1748 grep_read_unlock();
1749 free_filespec(df);
1750
@@ -1837,7 +1840,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
1840
1841 try_lookahead = should_lookahead(opt);
1842
1840 - if (fill_textconv_grep(textconv, gs) < 0)
1843 + if (fill_textconv_grep(opt->repo, textconv, gs) < 0)
1844 return 0;
1845
1846 bol = gs->buf;
grep.h
+5 -2
@@ -36,6 +36,8 @@ typedef int pcre2_jit_stack;
36 #include "thread-utils.h"
37 #include "userdiff.h"
38
39 +struct repository;
40 +
41 enum grep_pat_token {
42 GREP_PATTERN,
43 GREP_PATTERN_HEAD,
@@ -136,6 +138,7 @@ struct grep_opt {
138 struct grep_pat *header_list;
139 struct grep_pat **header_tail;
140 struct grep_expr *pattern_expression;
141 + struct repository *repo;
142 const char *prefix;
143 int prefix_length;
144 regex_t regexp;
@@ -183,9 +186,9 @@ struct grep_opt {
186 void *output_priv;
187 };
188
186 -extern void init_grep_defaults(void);
189 +extern void init_grep_defaults(struct repository *);
190 extern int grep_config(const char *var, const char *value, void *);
188 -extern void grep_init(struct grep_opt *, const char *prefix);
191 +extern void grep_init(struct grep_opt *, struct repository *repo, const char *prefix);
192 void grep_commit_pattern_type(enum grep_pattern_type, struct grep_opt *opt);
193
194 extern void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t);
revision.c
+2 -2
@@ -1464,8 +1464,8 @@ void init_revisions(struct rev_info *revs, const char *prefix)
1464 revs->commit_format = CMIT_FMT_DEFAULT;
1465 revs->expand_tabs_in_log_default = 8;
1466
1467 - init_grep_defaults();
1468 - grep_init(&revs->grep_filter, prefix);
1467 + init_grep_defaults(the_repository);
1468 + grep_init(&revs->grep_filter, the_repository, prefix);
1469 revs->grep_filter.status_only = 1;
1470
1471 diff_setup(&revs->diffopt);