]> git.ipfire.org Git - thirdparty/git.git/commitdiff
grep: don't set up a "default" repo for grep
authorMartin Ågren <martin.agren@gmail.com>
Sat, 21 Nov 2020 18:31:07 +0000 (19:31 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 21 Nov 2020 22:50:29 +0000 (14:50 -0800)
`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>
Documentation/MyFirstObjectWalk.txt
builtin/grep.c
builtin/log.c
grep.c
grep.h
revision.c

index c3f2d1a831e3b1d9c3e7cd5d555248e01bffbd73..85434d193867684263bc60ceb8bdb8bb019a175b 100644 (file)
@@ -394,7 +394,7 @@ First some setup. Add `init_grep_defaults()` to `init_walken_defaults()` and add
 ----
 static void init_walken_defaults(void)
 {
-       init_grep_defaults(the_repository);
+       init_grep_defaults();
 }
 
 ...
index e58e57504c3b5108eb09c9d8198efaa4128ff363..2b96efa8c243dede73dbfca25eacbd9235654a58 100644 (file)
@@ -950,7 +950,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                OPT_END()
        };
 
-       init_grep_defaults(the_repository);
+       init_grep_defaults();
        git_config(grep_cmd_config, NULL);
        grep_init(&opt, the_repository, prefix);
 
index 49eb8f6431b198d8942d48c77c1cc96e95fd3a0e..eee4beca4d7e73f4357663e5ff3c6a7aa6f23c1c 100644 (file)
@@ -131,7 +131,7 @@ static int log_line_range_callback(const struct option *option, const char *arg,
 
 static void init_log_defaults(void)
 {
-       init_grep_defaults(the_repository);
+       init_grep_defaults();
        init_diff_ui_defaults();
 
        decoration_style = auto_decoration_style();
diff --git a/grep.c b/grep.c
index 54af9f813e99043c723ba4f6e9fd32023d0be655..b351449f7ff8958ddec5420acc1fc1a32af155d4 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -57,7 +57,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(struct repository *repo)
+void init_grep_defaults(void)
 {
        struct grep_opt *opt = &grep_defaults;
        static int run_once;
@@ -67,7 +67,6 @@ void init_grep_defaults(struct repository *repo)
        run_once++;
 
        memset(opt, 0, sizeof(*opt));
-       opt->repo = repo;
        opt->relative = 1;
        opt->pathname = 1;
        opt->max_depth = -1;
diff --git a/grep.h b/grep.h
index 9115db8515059bf170d3d56e8146f9193d3318e4..1c5478f381e07397e001013ab1ab280dc5a39a43 100644 (file)
--- a/grep.h
+++ b/grep.h
@@ -170,7 +170,7 @@ struct grep_opt {
        void *output_priv;
 };
 
-void init_grep_defaults(struct repository *);
+void init_grep_defaults(void);
 int grep_config(const char *var, const char *value, void *);
 void grep_init(struct grep_opt *, struct repository *repo, const char *prefix);
 void grep_destroy(void);
index aa62212040814e29d17b8d1d7cafc15d1d50612d..f35ea1db110f5d4dbc342dd8456580930ec2890a 100644 (file)
@@ -1834,7 +1834,7 @@ void repo_init_revisions(struct repository *r,
        revs->commit_format = CMIT_FMT_DEFAULT;
        revs->expand_tabs_in_log_default = 8;
 
-       init_grep_defaults(revs->repo);
+       init_grep_defaults();
        grep_init(&revs->grep_filter, revs->repo, prefix);
        revs->grep_filter.status_only = 1;