pathspec: only match across submodule boundaries when requested
[gitweb.git] / submodule.c
index 3b0e70c51d41d1fd18637e711c4f262ab0d624a6..9d5eacaf9f2ffad4a7f5d17ced4137e0162215d5 100644 (file)
@@ -230,23 +230,6 @@ void load_submodule_cache(void)
        git_config(submodule_config, NULL);
 }
 
-void gitmodules_config(void)
-{
-       const char *work_tree = get_git_work_tree();
-       if (work_tree) {
-               struct strbuf gitmodules_path = STRBUF_INIT;
-               strbuf_addstr(&gitmodules_path, work_tree);
-               strbuf_addstr(&gitmodules_path, "/" GITMODULES_FILE);
-               if (read_cache() < 0)
-                       die("index file corrupt");
-
-               if (!is_gitmodules_unmerged(&the_index))
-                       git_config_from_file(git_modules_config,
-                               gitmodules_path.buf, NULL);
-               strbuf_release(&gitmodules_path);
-       }
-}
-
 static int gitmodules_cb(const char *var, const char *value, void *data)
 {
        struct repository *repo = data;
@@ -255,10 +238,24 @@ static int gitmodules_cb(const char *var, const char *value, void *data)
 
 void repo_read_gitmodules(struct repository *repo)
 {
-       char *gitmodules_path = repo_worktree_path(repo, GITMODULES_FILE);
+       if (repo->worktree) {
+               char *gitmodules;
+
+               if (repo_read_index(repo) < 0)
+                       return;
 
-       git_config_from_file(gitmodules_cb, gitmodules_path, repo);
-       free(gitmodules_path);
+               gitmodules = repo_worktree_path(repo, GITMODULES_FILE);
+
+               if (!is_gitmodules_unmerged(repo->index))
+                       git_config_from_file(gitmodules_cb, gitmodules, repo);
+
+               free(gitmodules);
+       }
+}
+
+void gitmodules_config(void)
+{
+       repo_read_gitmodules(the_repository);
 }
 
 void gitmodules_config_sha1(const unsigned char *commit_sha1)