grep: don't set up a "default" repo for grep

`init_grep_defaults()` fills a `static struct grep_opt grep_defaults`. This struct is then used by `grep_init()` as a blueprint for other such structs. Notably, `grep_init()` takes a `struct repo *` and assigns it into the target struct. As a result, it is unnecessary for us to take a `struct repo *` in `init_grep_defaults()` as well. We assign it into the default struct and never look at it again. And in light of how we return early if we have already set up the default struct, it's not just unnecessary, but is also a bit confusing: If we are called twice and with different repos, is it a bug or a feature that we ignore the second repo? Drop the repo parameter for `init_grep_defaults()`. Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin Ågren committed Nov 21, 2020 at 19:31 UTC 1d3878799f8260968ea9f6a75a92c4daca1da133
6 files changed +6 -7
Documentation/MyFirstObjectWalk.txt
+1 -1
@@ -394,7 +394,7 @@ First some setup. Add `init_grep_defaults()` to `init_walken_defaults()` and add
394 ----
395 static void init_walken_defaults(void)
396 {
397 - init_grep_defaults(the_repository);
397 + init_grep_defaults();
398 }
399
400 ...
builtin/grep.c
+1 -1
@@ -950,7 +950,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
950 OPT_END()
951 };
952
953 - init_grep_defaults(the_repository);
953 + init_grep_defaults();
954 git_config(grep_cmd_config, NULL);
955 grep_init(&opt, the_repository, prefix);
956
builtin/log.c
+1 -1
@@ -131,7 +131,7 @@ static int log_line_range_callback(const struct option *option, const char *arg,
131
132 static void init_log_defaults(void)
133 {
134 - init_grep_defaults(the_repository);
134 + init_grep_defaults();
135 init_diff_ui_defaults();
136
137 decoration_style = auto_decoration_style();
grep.c
+1 -2
@@ -57,7 +57,7 @@ static void color_set(char *dst, const char *color_bytes)
57 * We could let the compiler do this, but without C99 initializers
58 * the code gets unwieldy and unreadable, so...
59 */
60 -void init_grep_defaults(struct repository *repo)
60 +void init_grep_defaults(void)
61 {
62 struct grep_opt *opt = &grep_defaults;
63 static int run_once;
@@ -67,7 +67,6 @@ void init_grep_defaults(struct repository *repo)
67 run_once++;
68
69 memset(opt, 0, sizeof(*opt));
70 - opt->repo = repo;
70 opt->relative = 1;
71 opt->pathname = 1;
72 opt->max_depth = -1;
grep.h
+1 -1
@@ -170,7 +170,7 @@ struct grep_opt {
170 void *output_priv;
171 };
172
173 -void init_grep_defaults(struct repository *);
173 +void init_grep_defaults(void);
174 int grep_config(const char *var, const char *value, void *);
175 void grep_init(struct grep_opt *, struct repository *repo, const char *prefix);
176 void grep_destroy(void);
revision.c
+1 -1
@@ -1834,7 +1834,7 @@ void repo_init_revisions(struct repository *r,
1834 revs->commit_format = CMIT_FMT_DEFAULT;
1835 revs->expand_tabs_in_log_default = 8;
1836
1837 - init_grep_defaults(revs->repo);
1837 + init_grep_defaults();
1838 grep_init(&revs->grep_filter, revs->repo, prefix);
1839 revs->grep_filter.status_only = 1;
1840