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 <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Hostetler committed Apr 15, 2019 at 13:39 UTC 800a7f99a8776b18a48cf9c1b0f9418bf4644bbd
2 files changed +24 -3
config.c
+20 -3
@@ -1688,14 +1688,15 @@ static int do_git_config_sequence(const struct config_options *opts,
1688 ret += git_config_from_file(fn, user_config, data);
1689
1690 current_parsing_scope = CONFIG_SCOPE_REPO;
1691 - if (repo_config && !access_or_die(repo_config, R_OK, 0))
1691 + if (!opts->ignore_repo && repo_config &&
1692 + !access_or_die(repo_config, R_OK, 0))
1693 ret += git_config_from_file(fn, repo_config, data);
1694
1695 /*
1696 * Note: this should have a new scope, CONFIG_SCOPE_WORKTREE.
1697 * But let's not complicate things before it's actually needed.
1698 */
1698 - if (repository_format_worktree_config) {
1699 + if (!opts->ignore_worktree && repository_format_worktree_config) {
1700 char *path = git_pathdup("config.worktree");
1701 if (!access_or_die(path, R_OK, 0))
1702 ret += git_config_from_file(fn, path, data);
@@ -1703,7 +1704,7 @@ static int do_git_config_sequence(const struct config_options *opts,
1704 }
1705
1706 current_parsing_scope = CONFIG_SCOPE_CMDLINE;
1706 - if (git_config_from_parameters(fn, data) < 0)
1707 + if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0)
1708 die(_("unable to parse command-line config"));
1709
1710 current_parsing_scope = CONFIG_SCOPE_UNKNOWN;
@@ -1794,6 +1795,22 @@ void read_early_config(config_fn_t cb, void *data)
1795 strbuf_release(&gitdir);
1796 }
1797
1798 +/*
1799 + * Read config but only enumerate system and global settings.
1800 + * Omit any repo-local, worktree-local, or command-line settings.
1801 + */
1802 +void read_very_early_config(config_fn_t cb, void *data)
1803 +{
1804 + struct config_options opts = { 0 };
1805 +
1806 + opts.respect_includes = 1;
1807 + opts.ignore_repo = 1;
1808 + opts.ignore_worktree = 1;
1809 + opts.ignore_cmdline = 1;
1810 +
1811 + config_with_options(cb, data, NULL, &opts);
1812 +}
1813 +
1814 static struct config_set_element *configset_find_element(struct config_set *cs, const char *key)
1815 {
1816 struct config_set_element k;
config.h
+4
@@ -55,6 +55,9 @@ typedef int (*config_parser_event_fn_t)(enum config_event_t type,
55
56 struct config_options {
57 unsigned int respect_includes : 1;
58 + unsigned int ignore_repo : 1;
59 + unsigned int ignore_worktree : 1;
60 + unsigned int ignore_cmdline : 1;
61 const char *commondir;
62 const char *git_dir;
63 config_parser_event_fn_t event_fn;
@@ -83,6 +86,7 @@ extern int git_config_from_blob_oid(config_fn_t fn, const char *name,
86 extern void git_config_push_parameter(const char *text);
87 extern int git_config_from_parameters(config_fn_t fn, void *data);
88 extern void read_early_config(config_fn_t cb, void *data);
89 +extern void read_very_early_config(config_fn_t cb, void *data);
90 extern void git_config(config_fn_t fn, void *);
91 extern int config_with_options(config_fn_t fn, void *,
92 struct git_config_source *config_source,