config: add read_very_early_config()
authorJeff Hostetler <jeffhost@microsoft.com>
Mon, 15 Apr 2019 20:39:46 +0000 (13:39 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 16 Apr 2019 04:37:06 +0000 (13:37 +0900)
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>
config.c
config.h
index c809f7621941b7f1208c8bcd282df3c21005a084..d7a08713a82fe2710d2096a01cee0ff39a2de8c0 100644 (file)
--- 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;
index ee5d3fa7b4264f24e8b36c2e1154546ae626c191..6a58d61d2250d316771ba536e80ba16ee3e299ce 100644 (file)
--- a/config.h
+++ b/config.h
@@ -55,6 +55,9 @@ typedef int (*config_parser_event_fn_t)(enum config_event_t type,
 
 struct config_options {
        unsigned int respect_includes : 1;
+       unsigned int ignore_repo : 1;
+       unsigned int ignore_worktree : 1;
+       unsigned int ignore_cmdline : 1;
        const char *commondir;
        const char *git_dir;
        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,
 extern void git_config_push_parameter(const char *text);
 extern int git_config_from_parameters(config_fn_t fn, void *data);
 extern void read_early_config(config_fn_t cb, void *data);
+extern void read_very_early_config(config_fn_t cb, void *data);
 extern void git_config(config_fn_t fn, void *);
 extern int config_with_options(config_fn_t fn, void *,
                               struct git_config_source *config_source,