vscode: let cSpell work on commit messages, too
[gitweb.git] / submodule-config.c
index cd1f1e06a67e6b1ed66a786deb81fa959fcf328a..2a7259ba8b5297091c1f1917952cdf560e88a646 100644 (file)
@@ -4,6 +4,7 @@
 #include "submodule-config.h"
 #include "submodule.h"
 #include "strbuf.h"
+#include "object-store.h"
 #include "parse-options.h"
 
 /*
@@ -591,6 +592,23 @@ static void submodule_cache_check_init(struct repository *repo)
        submodule_cache_init(repo->submodule_cache);
 }
 
+/*
+ * Note: This function is private for a reason, the '.gitmodules' file should
+ * not be used as as a mechanism to retrieve arbitrary configuration stored in
+ * the repository.
+ *
+ * Runs the provided config function on the '.gitmodules' file found in the
+ * working directory.
+ */
+static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void *data)
+{
+       if (repo->worktree) {
+               char *file = repo_worktree_path(repo, GITMODULES_FILE);
+               git_config_from_file(fn, file, data);
+               free(file);
+       }
+}
+
 static int gitmodules_cb(const char *var, const char *value, void *data)
 {
        struct repository *repo = data;
@@ -608,19 +626,11 @@ void repo_read_gitmodules(struct repository *repo)
 {
        submodule_cache_check_init(repo);
 
-       if (repo->worktree) {
-               char *gitmodules;
-
-               if (repo_read_index(repo) < 0)
-                       return;
-
-               gitmodules = repo_worktree_path(repo, GITMODULES_FILE);
-
-               if (!is_gitmodules_unmerged(repo->index))
-                       git_config_from_file(gitmodules_cb, gitmodules, repo);
+       if (repo_read_index(repo) < 0)
+               return;
 
-               free(gitmodules);
-       }
+       if (!is_gitmodules_unmerged(repo->index))
+               config_from_gitmodules(gitmodules_cb, repo, repo);
 
        repo->submodule_cache->gitmodules_read = 1;
 }
@@ -672,23 +682,6 @@ void submodule_free(struct repository *r)
                submodule_cache_clear(r->submodule_cache);
 }
 
-/*
- * Note: This function is private for a reason, the '.gitmodules' file should
- * not be used as as a mechanism to retrieve arbitrary configuration stored in
- * the repository.
- *
- * Runs the provided config function on the '.gitmodules' file found in the
- * working directory.
- */
-static void config_from_gitmodules(config_fn_t fn, void *data)
-{
-       if (the_repository->worktree) {
-               char *file = repo_worktree_path(the_repository, GITMODULES_FILE);
-               git_config_from_file(fn, file, data);
-               free(file);
-       }
-}
-
 struct fetch_config {
        int *max_children;
        int *recurse_submodules;
@@ -714,7 +707,7 @@ void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules)
                .max_children = max_children,
                .recurse_submodules = recurse_submodules
        };
-       config_from_gitmodules(gitmodules_fetch_config, &config);
+       config_from_gitmodules(gitmodules_fetch_config, the_repository, &config);
 }
 
 static int gitmodules_update_clone_config(const char *var, const char *value,
@@ -728,5 +721,5 @@ static int gitmodules_update_clone_config(const char *var, const char *value,
 
 void update_clone_config_from_gitmodules(int *max_jobs)
 {
-       config_from_gitmodules(gitmodules_update_clone_config, &max_jobs);
+       config_from_gitmodules(gitmodules_update_clone_config, the_repository, &max_jobs);
 }