grep API: call grep_config() after grep_init()
The grep_init() function used the odd pattern of initializing the passed-in "struct grep_opt" with a statically defined "grep_defaults" struct, which would be modified in-place when we invoked grep_config(). So we effectively (b) initialized config, (a) then defaults, (c) followed by user options. Usually those are ordered as "a", "b" and "c" instead. As the comments being removed here show the previous behavior needed to be carefully explained as we'd potentially share the populated configuration among different instances of grep_init(). In practice we didn't do that, but now that it can't be a concern anymore let's remove those comments. This does not change the behavior of any of the configuration variables or options. That would have been the case if we didn't move around the grep_config() call in "builtin/log.c". But now that we call "grep_config" after "git_log_config" and "git_format_config" we'll need to pass in the already initialized "struct grep_opt *". See6ba9bb76e0(grep: copy struct in one fell swoop, 2020-11-29) and7687a0541e(grep: move the configuration parsing logic to grep.[ch], 2012-10-09) for the commits that added the comments. The memcpy() pattern here will be optimized away and follows the convention of other *_init() functions. See5726a6b401(*.c *_init(): define in terms of corresponding *_INIT macro, 2021-07-01). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
b8db6ed826
commit
72365bb499
@ -285,7 +285,7 @@ static int wait_all(void)
|
||||
|
||||
static int grep_cmd_config(const char *var, const char *value, void *cb)
|
||||
{
|
||||
int st = grep_config(var, value, NULL);
|
||||
int st = grep_config(var, value, cb);
|
||||
if (git_color_default_config(var, value, NULL) < 0)
|
||||
st = -1;
|
||||
|
||||
@ -966,8 +966,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
|
||||
};
|
||||
grep_prefix = prefix;
|
||||
|
||||
git_config(grep_cmd_config, NULL);
|
||||
grep_init(&opt, the_repository);
|
||||
git_config(grep_cmd_config, &opt);
|
||||
|
||||
/*
|
||||
* If there is no -- then the paths must exist in the working
|
||||
|
||||
Reference in New Issue
Block a user