]> git.ipfire.org Git - thirdparty/git.git/blobdiff - config.c
t4216: avoid unnecessary subshell in test_bloom_filters_not_used
[thirdparty/git.git] / config.c
index b386c0c6287739d11446873426f7c483f2537745..d17d2bd9dcdef8e4f16316090e1265145834926b 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1702,6 +1702,7 @@ static int do_git_config_sequence(const struct config_options *opts,
        char *xdg_config = xdg_config_home("config");
        char *user_config = expand_user_path("~/.gitconfig", 0);
        char *repo_config;
+       enum config_scope prev_parsing_scope = current_parsing_scope;
 
        if (opts->commondir)
                repo_config = mkpathdup("%s/config", opts->commondir);
@@ -1724,15 +1725,12 @@ static int do_git_config_sequence(const struct config_options *opts,
        if (user_config && !access_or_die(user_config, R_OK, ACCESS_EACCES_OK))
                ret += git_config_from_file(fn, user_config, data);
 
-       current_parsing_scope = CONFIG_SCOPE_REPO;
+       current_parsing_scope = CONFIG_SCOPE_LOCAL;
        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.
-        */
+       current_parsing_scope = CONFIG_SCOPE_WORKTREE;
        if (!opts->ignore_worktree && repository_format_worktree_config) {
                char *path = git_pathdup("config.worktree");
                if (!access_or_die(path, R_OK, 0))
@@ -1740,11 +1738,11 @@ static int do_git_config_sequence(const struct config_options *opts,
                free(path);
        }
 
-       current_parsing_scope = CONFIG_SCOPE_CMDLINE;
+       current_parsing_scope = CONFIG_SCOPE_COMMAND;
        if (!opts->ignore_cmdline && git_config_from_parameters(fn, data) < 0)
                die(_("unable to parse command-line config"));
 
-       current_parsing_scope = CONFIG_SCOPE_UNKNOWN;
+       current_parsing_scope = prev_parsing_scope;
        free(xdg_config);
        free(user_config);
        free(repo_config);
@@ -1765,6 +1763,9 @@ int config_with_options(config_fn_t fn, void *data,
                data = &inc;
        }
 
+       if (config_source)
+               current_parsing_scope = config_source->scope;
+
        /*
         * If we have a specific filename, use it. Otherwise, follow the
         * regular lookup sequence.
@@ -3297,6 +3298,26 @@ const char *current_config_origin_type(void)
        }
 }
 
+const char *config_scope_name(enum config_scope scope)
+{
+       switch (scope) {
+       case CONFIG_SCOPE_SYSTEM:
+               return "system";
+       case CONFIG_SCOPE_GLOBAL:
+               return "global";
+       case CONFIG_SCOPE_LOCAL:
+               return "local";
+       case CONFIG_SCOPE_WORKTREE:
+               return "worktree";
+       case CONFIG_SCOPE_COMMAND:
+               return "command";
+       case CONFIG_SCOPE_SUBMODULE:
+               return "submodule";
+       default:
+               return "unknown";
+       }
+}
+
 const char *current_config_name(void)
 {
        const char *name;
@@ -3317,6 +3338,14 @@ enum config_scope current_config_scope(void)
                return current_parsing_scope;
 }
 
+int current_config_line(void)
+{
+       if (current_config_kvi)
+               return current_config_kvi->linenr;
+       else
+               return cf->linenr;
+}
+
 int lookup_config(const char **mapping, int nr_mapping, const char *var)
 {
        int i;