From 1703751f21d286b383c198157a1342c35ebc11b7 Mon Sep 17 00:00:00 2001 From: Jeff Hostetler Date: Mon, 15 Apr 2019 13:39:42 -0700 Subject: config: initialize opts structure in repo_read_config() Initialize opts structure in repo_read_config(). This change fixes a crash in later commit after a new field is added to the structure. In commit 3b256228a66f8587661481ef3e08259864f3ba2a, repo_read_config() was added. It only initializes 3 fields in the opts structure. It is passed to config_with_options() and then to do_git_config_sequence(). However, do_git_config_sequence() drops the opts on the floor and calls git_config_from_file() rather than git_config_from_file_with_options(), so that may be why this hasn't been a problem in the past. Signed-off-by: Johannes Schindelin Signed-off-by: Jeff Hostetler Signed-off-by: Junio C Hamano --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config.c') diff --git a/config.c b/config.c index 0f0cdd8c0f..c809f76219 100644 --- a/config.c +++ b/config.c @@ -2011,7 +2011,7 @@ int git_configset_get_pathname(struct config_set *cs, const char *key, const cha /* Functions use to read configuration from a repository */ static void repo_read_config(struct repository *repo) { - struct config_options opts; + struct config_options opts = { 0 }; opts.respect_includes = 1; opts.commondir = repo->commondir; -- cgit v1.2.3 From 800a7f99a8776b18a48cf9c1b0f9418bf4644bbd Mon Sep 17 00:00:00 2001 From: Jeff Hostetler Date: Mon, 15 Apr 2019 13:39:46 -0700 Subject: config: add read_very_early_config() Created an even lighter version of read_early_config() that only looks at system and global config settings. It omits repo-local, worktree-local, and command-line settings. Signed-off-by: Jeff Hostetler Signed-off-by: Junio C Hamano --- config.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index c809f76219..d7a08713a8 100644 --- a/config.c +++ b/config.c @@ -1688,14 +1688,15 @@ static int do_git_config_sequence(const struct config_options *opts, ret += git_config_from_file(fn, user_config, data); current_parsing_scope = CONFIG_SCOPE_REPO; - if (repo_config && !access_or_die(repo_config, R_OK, 0)) + if (!opts->ignore_repo && repo_config && + !access_or_die(repo_config, R_OK, 0)) ret += git_config_from_file(fn, repo_config, data); /* * Note: this should have a new scope, CONFIG_SCOPE_WORKTREE. * But let's not complicate things before it's actually needed. */ - if (repository_format_worktree_config) { + if (!opts->ignore_worktree && repository_format_worktree_config) { char *path = git_pathdup("config.worktree"); if (!access_or_die(path, R_OK, 0)) ret += git_config_from_file(fn, path, data); @@ -1703,7 +1704,7 @@ static int do_git_config_sequence(const struct config_options *opts, } current_parsing_scope = CONFIG_SCOPE_CMDLINE; - if (git_config_from_parameters(fn, data) < 0) + if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0) die(_("unable to parse command-line config")); current_parsing_scope = CONFIG_SCOPE_UNKNOWN; @@ -1794,6 +1795,22 @@ void read_early_config(config_fn_t cb, void *data) strbuf_release(&gitdir); } +/* + * Read config but only enumerate system and global settings. + * Omit any repo-local, worktree-local, or command-line settings. + */ +void read_very_early_config(config_fn_t cb, void *data) +{ + struct config_options opts = { 0 }; + + opts.respect_includes = 1; + opts.ignore_repo = 1; + opts.ignore_worktree = 1; + opts.ignore_cmdline = 1; + + config_with_options(cb, data, NULL, &opts); +} + static struct config_set_element *configset_find_element(struct config_set *cs, const char *key) { struct config_set_element k; -- cgit v1.2.3 From f672deec2d56b0d7ae64ce3efd918e02efc58b9c Mon Sep 17 00:00:00 2001 From: Jeff Hostetler Date: Mon, 29 Apr 2019 13:14:22 -0700 Subject: trace2: fixup access problem on /etc/gitconfig in read_very_early_config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Teach do_git_config_sequence() to optionally gently check for access to the system config. Use this option in read_very_early_config() when initializing trace2. In [1] SZEDER Gábor reported that my changes in [2] introduced a regression when the user does not have permission to read the system config. This commit addresses that problem by optionally ignoring that error. [1] https://public-inbox.org/git/285beb2b2d740ce20fdd8af1becf371ab39703db.1554995916.git.gitgitgadget@gmail.com/T/#m342e839289aec515523a98b5e34d7f42d3f1fd79 [2] https://public-inbox.org/git/285beb2b2d740ce20fdd8af1becf371ab39703db.1554995916.git.gitgitgadget@gmail.com/T/#m11b59c9228c698442f750ee8f9b10c629399ae48 Signed-off-by: Jeff Hostetler Signed-off-by: Junio C Hamano --- config.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'config.c') diff --git a/config.c b/config.c index d7a08713a8..3f5ad9dc3c 100644 --- a/config.c +++ b/config.c @@ -1676,7 +1676,9 @@ static int do_git_config_sequence(const struct config_options *opts, repo_config = NULL; current_parsing_scope = CONFIG_SCOPE_SYSTEM; - if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0)) + if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, + opts->system_gently ? + ACCESS_EACCES_OK : 0)) ret += git_config_from_file(fn, git_etc_gitconfig(), data); @@ -1807,6 +1809,7 @@ void read_very_early_config(config_fn_t cb, void *data) opts.ignore_repo = 1; opts.ignore_worktree = 1; opts.ignore_cmdline = 1; + opts.system_gently = 1; config_with_options(cb, data, NULL, &opts); } -- cgit v1.2.3