submodule: add repo_read_gitmodules
authorBrandon Williams <bmwill@google.com>
Thu, 22 Jun 2017 18:43:45 +0000 (11:43 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 24 Jun 2017 01:24:34 +0000 (18:24 -0700)
Teach the repo object to be able to populate the submodule_cache by
reading the repository's gitmodules file.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule.c
submodule.h
index da0b805493b9e7cd4c26f027a9f24c823109850a..d0b894772696ff9ca4289cd15d72505b34a64e11 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "repository.h"
 #include "config.h"
 #include "submodule-config.h"
 #include "submodule.h"
@@ -255,6 +256,20 @@ void gitmodules_config(void)
        }
 }
 
+static int gitmodules_cb(const char *var, const char *value, void *data)
+{
+       struct repository *repo = data;
+       return submodule_config_option(repo, var, value);
+}
+
+void repo_read_gitmodules(struct repository *repo)
+{
+       char *gitmodules_path = repo_worktree_path(repo, ".gitmodules");
+
+       git_config_from_file(gitmodules_cb, gitmodules_path, repo);
+       free(gitmodules_path);
+}
+
 void gitmodules_config_sha1(const unsigned char *commit_sha1)
 {
        struct strbuf rev = STRBUF_INIT;
index cbe5c1726f9adab2b032d872d4bd84425e6ce518..8a3771ec6317bd1deabac83ca75dcacc5d39cb89 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef SUBMODULE_H
 #define SUBMODULE_H
 
+struct repository;
 struct diff_options;
 struct argv_array;
 struct oid_array;
@@ -46,6 +47,7 @@ int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
                                                     const char *arg, int unset);
 void load_submodule_cache(void);
 extern void gitmodules_config(void);
+extern void repo_read_gitmodules(struct repository *repo);
 extern void gitmodules_config_sha1(const unsigned char *commit_sha1);
 extern int is_submodule_initialized(const char *path);
 /*