Nguyễn Thái Ngọc Duy <[email protected]> writes:
> @@ -1603,10 +1613,12 @@ void read_early_config(config_fn_t cb, void *data)
> {
> struct config_options opts = {0};
> struct strbuf buf = STRBUF_INIT;
> + char *to_free = NULL;
>
> opts.respect_includes = 1;
> - git_config_with_options(cb, data, NULL, &opts);
>
> + if (have_git_dir())
> + opts.git_dir = get_git_dir();
> /*
> * When setup_git_directory() was not yet asked to discover the
> * GIT_DIR, we ask discover_git_directory() to figure out whether there
> @@ -1615,7 +1627,12 @@ void read_early_config(config_fn_t cb, void *data)
> * notably, the current working directory is still the same after the
> * call).
> */
> - if (!have_git_dir() && discover_git_directory(&buf)) {
> + else if (discover_git_directory(&buf))
> + opts.git_dir = to_free = xstrdup(buf.buf);
> +
> + git_config_with_options(cb, data, NULL, &opts);
This one I can understand. By having NULL for config_source, this
does the usual do_git_config_sequence() dance, which knows to treat
opts.git_dir is the "repository config" without necessarily being
able to do git_pathdup("config").
> + if (!have_git_dir() && opts.git_dir) {
> struct git_config_source repo_config;
>
> memset(&repo_config, 0, sizeof(repo_config));
But this one I do not quite understand. When have_git_dir() was
false and asked discover_git_directory() to set opts.git_dir, we
enter the body of this block and then end up doing
git_config_with_options(cb, data &repo_config, &opts);
with repo_config set to the discovered git directory plus "/config";
we'd read the repository configuration twice, in other words.