Skip to content

Commit 1d38787

Browse files
Martin Ågrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent faefdd6 commit 1d38787

File tree

6 files changed

+6
-7
lines changed

6 files changed

+6
-7
lines changed

Documentation/MyFirstObjectWalk.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ First some setup. Add `init_grep_defaults()` to `init_walken_defaults()` and add
394394
----
395395
static void init_walken_defaults(void)
396396
{
397-
init_grep_defaults(the_repository);
397+
init_grep_defaults();
398398
}
399399

400400
...

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
950950
OPT_END()
951951
};
952952

953-
init_grep_defaults(the_repository);
953+
init_grep_defaults();
954954
git_config(grep_cmd_config, NULL);
955955
grep_init(&opt, the_repository, prefix);
956956

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static int log_line_range_callback(const struct option *option, const char *arg,
131131

132132
static void init_log_defaults(void)
133133
{
134-
init_grep_defaults(the_repository);
134+
init_grep_defaults();
135135
init_diff_ui_defaults();
136136

137137
decoration_style = auto_decoration_style();

grep.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static void color_set(char *dst, const char *color_bytes)
5757
* We could let the compiler do this, but without C99 initializers
5858
* the code gets unwieldy and unreadable, so...
5959
*/
60-
void init_grep_defaults(struct repository *repo)
60+
void init_grep_defaults(void)
6161
{
6262
struct grep_opt *opt = &grep_defaults;
6363
static int run_once;
@@ -67,7 +67,6 @@ void init_grep_defaults(struct repository *repo)
6767
run_once++;
6868

6969
memset(opt, 0, sizeof(*opt));
70-
opt->repo = repo;
7170
opt->relative = 1;
7271
opt->pathname = 1;
7372
opt->max_depth = -1;

grep.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ struct grep_opt {
170170
void *output_priv;
171171
};
172172

173-
void init_grep_defaults(struct repository *);
173+
void init_grep_defaults(void);
174174
int grep_config(const char *var, const char *value, void *);
175175
void grep_init(struct grep_opt *, struct repository *repo, const char *prefix);
176176
void grep_destroy(void);

revision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,7 @@ void repo_init_revisions(struct repository *r,
18341834
revs->commit_format = CMIT_FMT_DEFAULT;
18351835
revs->expand_tabs_in_log_default = 8;
18361836

1837-
init_grep_defaults(revs->repo);
1837+
init_grep_defaults();
18381838
grep_init(&revs->grep_filter, revs->repo, prefix);
18391839
revs->grep_filter.status_only = 1;
18401840

0 commit comments

Comments
 (0)