提交 38bbc2ea 编写于 作者: N Nguyễn Thái Ngọc Duy 提交者: Junio C Hamano

grep.c: remove implicit dependency on the_index

Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 6afaf807
...@@ -904,9 +904,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix) ...@@ -904,9 +904,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
OPT_END() OPT_END()
}; };
init_grep_defaults(); init_grep_defaults(the_repository);
git_config(grep_cmd_config, NULL); git_config(grep_cmd_config, NULL);
grep_init(&opt, prefix); grep_init(&opt, the_repository, prefix);
/* /*
* If there is no -- then the paths must exist in the working * If there is no -- then the paths must exist in the working
......
...@@ -115,7 +115,7 @@ static int log_line_range_callback(const struct option *option, const char *arg, ...@@ -115,7 +115,7 @@ static int log_line_range_callback(const struct option *option, const char *arg,
static void init_log_defaults(void) static void init_log_defaults(void)
{ {
init_grep_defaults(); init_grep_defaults(the_repository);
init_diff_ui_defaults(); init_diff_ui_defaults();
decoration_style = auto_decoration_style(); decoration_style = auto_decoration_style();
......
...@@ -42,7 +42,7 @@ static void color_set(char *dst, const char *color_bytes) ...@@ -42,7 +42,7 @@ static void color_set(char *dst, const char *color_bytes)
* We could let the compiler do this, but without C99 initializers * We could let the compiler do this, but without C99 initializers
* the code gets unwieldy and unreadable, so... * 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; struct grep_opt *opt = &grep_defaults;
static int run_once; static int run_once;
...@@ -52,6 +52,7 @@ void init_grep_defaults(void) ...@@ -52,6 +52,7 @@ void init_grep_defaults(void)
run_once++; run_once++;
memset(opt, 0, sizeof(*opt)); memset(opt, 0, sizeof(*opt));
opt->repo = repo;
opt->relative = 1; opt->relative = 1;
opt->pathname = 1; opt->pathname = 1;
opt->max_depth = -1; opt->max_depth = -1;
...@@ -149,12 +150,13 @@ int grep_config(const char *var, const char *value, void *cb) ...@@ -149,12 +150,13 @@ int grep_config(const char *var, const char *value, void *cb)
* default values from the template we read the configuration * default values from the template we read the configuration
* information in an earlier call to git_config(grep_config). * 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; struct grep_opt *def = &grep_defaults;
int i; int i;
memset(opt, 0, sizeof(*opt)); memset(opt, 0, sizeof(*opt));
opt->repo = repo;
opt->prefix = prefix; opt->prefix = prefix;
opt->prefix_length = (prefix && *prefix) ? strlen(prefix) : 0; opt->prefix_length = (prefix && *prefix) ? strlen(prefix) : 0;
opt->pattern_tail = &opt->pattern_list; opt->pattern_tail = &opt->pattern_list;
...@@ -1708,7 +1710,8 @@ static int look_ahead(struct grep_opt *opt, ...@@ -1708,7 +1710,8 @@ static int look_ahead(struct grep_opt *opt,
return 0; 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 grep_source *gs)
{ {
struct diff_filespec *df; struct diff_filespec *df;
...@@ -1741,7 +1744,7 @@ static int fill_textconv_grep(struct userdiff_driver *driver, ...@@ -1741,7 +1744,7 @@ static int fill_textconv_grep(struct userdiff_driver *driver,
* structure. * structure.
*/ */
grep_read_lock(); grep_read_lock();
size = fill_textconv(the_repository, driver, df, &buf); size = fill_textconv(r, driver, df, &buf);
grep_read_unlock(); grep_read_unlock();
free_filespec(df); free_filespec(df);
...@@ -1837,7 +1840,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle ...@@ -1837,7 +1840,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
try_lookahead = should_lookahead(opt); try_lookahead = should_lookahead(opt);
if (fill_textconv_grep(textconv, gs) < 0) if (fill_textconv_grep(opt->repo, textconv, gs) < 0)
return 0; return 0;
bol = gs->buf; bol = gs->buf;
......
...@@ -36,6 +36,8 @@ typedef int pcre2_jit_stack; ...@@ -36,6 +36,8 @@ typedef int pcre2_jit_stack;
#include "thread-utils.h" #include "thread-utils.h"
#include "userdiff.h" #include "userdiff.h"
struct repository;
enum grep_pat_token { enum grep_pat_token {
GREP_PATTERN, GREP_PATTERN,
GREP_PATTERN_HEAD, GREP_PATTERN_HEAD,
...@@ -136,6 +138,7 @@ struct grep_opt { ...@@ -136,6 +138,7 @@ struct grep_opt {
struct grep_pat *header_list; struct grep_pat *header_list;
struct grep_pat **header_tail; struct grep_pat **header_tail;
struct grep_expr *pattern_expression; struct grep_expr *pattern_expression;
struct repository *repo;
const char *prefix; const char *prefix;
int prefix_length; int prefix_length;
regex_t regexp; regex_t regexp;
...@@ -183,9 +186,9 @@ struct grep_opt { ...@@ -183,9 +186,9 @@ struct grep_opt {
void *output_priv; void *output_priv;
}; };
extern void init_grep_defaults(void); extern void init_grep_defaults(struct repository *);
extern int grep_config(const char *var, const char *value, void *); extern int grep_config(const char *var, const char *value, void *);
extern void grep_init(struct grep_opt *, const char *prefix); extern void grep_init(struct grep_opt *, struct repository *repo, const char *prefix);
void grep_commit_pattern_type(enum grep_pattern_type, struct grep_opt *opt); void grep_commit_pattern_type(enum grep_pattern_type, struct grep_opt *opt);
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); 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);
......
...@@ -1464,8 +1464,8 @@ void init_revisions(struct rev_info *revs, const char *prefix) ...@@ -1464,8 +1464,8 @@ void init_revisions(struct rev_info *revs, const char *prefix)
revs->commit_format = CMIT_FMT_DEFAULT; revs->commit_format = CMIT_FMT_DEFAULT;
revs->expand_tabs_in_log_default = 8; revs->expand_tabs_in_log_default = 8;
init_grep_defaults(); init_grep_defaults(the_repository);
grep_init(&revs->grep_filter, prefix); grep_init(&revs->grep_filter, the_repository, prefix);
revs->grep_filter.status_only = 1; revs->grep_filter.status_only = 1;
diff_setup(&revs->diffopt); diff_setup(&revs->diffopt);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册