Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- builtin/grep.c | 4 ++-- builtin/log.c | 2 +- grep.c | 13 ++++++++----- grep.h | 7 +++++-- revision.c | 4 ++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index 601f801158..0667ffde84 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -904,9 +904,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix) OPT_END() }; - init_grep_defaults(); + init_grep_defaults(the_repository); 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 diff --git a/builtin/log.c b/builtin/log.c index f32a07f6a9..b62082472c 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -115,7 +115,7 @@ static int log_line_range_callback(const struct option *option, const char *arg, static void init_log_defaults(void) { - init_grep_defaults(); + init_grep_defaults(the_repository); init_diff_ui_defaults(); decoration_style = auto_decoration_style(); diff --git a/grep.c b/grep.c index e146ff20bb..6c0eede3a1 100644 --- a/grep.c +++ b/grep.c @@ -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 * 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 +52,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 +150,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; @@ -1708,7 +1710,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 +1744,7 @@ static int fill_textconv_grep(struct userdiff_driver *driver, * structure. */ grep_read_lock(); - size = fill_textconv(the_repository, driver, df, &buf); + size = fill_textconv(r, driver, df, &buf); grep_read_unlock(); free_filespec(df); @@ -1837,7 +1840,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; diff --git a/grep.h b/grep.h index 0ba62a11c5..3651183971 100644 --- a/grep.h +++ b/grep.h @@ -36,6 +36,8 @@ typedef int pcre2_jit_stack; #include "thread-utils.h" #include "userdiff.h" +struct repository; + enum grep_pat_token { GREP_PATTERN, GREP_PATTERN_HEAD, @@ -136,6 +138,7 @@ struct grep_opt { struct grep_pat *header_list; struct grep_pat **header_tail; struct grep_expr *pattern_expression; + struct repository *repo; const char *prefix; int prefix_length; regex_t regexp; @@ -183,9 +186,9 @@ struct grep_opt { 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 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); 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); diff --git a/revision.c b/revision.c index de4dce600d..3457064ff3 100644 --- a/revision.c +++ b/revision.c @@ -1464,8 +1464,8 @@ void init_revisions(struct rev_info *revs, const char *prefix) revs->commit_format = CMIT_FMT_DEFAULT; revs->expand_tabs_in_log_default = 8; - init_grep_defaults(); - grep_init(&revs->grep_filter, prefix); + init_grep_defaults(the_repository); + grep_init(&revs->grep_filter, the_repository, prefix); revs->grep_filter.status_only = 1; diff_setup(&revs->diffopt); -- 2.19.0.rc0.337.ge906d732e7