submodule: add repo_read_gitmodules
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>
Brandon Williams committed
Jun 22, 2017 at 11:43 UTC
69aba5329e3464bfe38d2614033e19c490f8694d
2 files changed
+17
submodule.c
+15
@@ -1,4 +1,5 @@
1
#include "cache.h"
2
+#include "repository.h"
3
#include "config.h"
4
#include "submodule-config.h"
5
#include "submodule.h"
@@ -255,6 +256,20 @@ void gitmodules_config(void)
256
}
257
}
258
259
+static int gitmodules_cb(const char *var, const char *value, void *data)
260
+{
261
+ struct repository *repo = data;
262
+ return submodule_config_option(repo, var, value);
263
+}
264
+
265
+void repo_read_gitmodules(struct repository *repo)
266
+{
267
+ char *gitmodules_path = repo_worktree_path(repo, ".gitmodules");
268
+
269
+ git_config_from_file(gitmodules_cb, gitmodules_path, repo);
270
+ free(gitmodules_path);
271
+}
272
+
273
void gitmodules_config_sha1(const unsigned char *commit_sha1)
274
{
275
struct strbuf rev = STRBUF_INIT;
submodule.h
+2
@@ -1,6 +1,7 @@
1
#ifndef SUBMODULE_H
2
#define SUBMODULE_H
3
4
+struct repository;
5
struct diff_options;
6
struct argv_array;
7
struct oid_array;
@@ -46,6 +47,7 @@ int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
47
const char *arg, int unset);
48
void load_submodule_cache(void);
49
extern void gitmodules_config(void);
50
+extern void repo_read_gitmodules(struct repository *repo);
51
extern void gitmodules_config_sha1(const unsigned char *commit_sha1);
52
extern int is_submodule_initialized(const char *path);
53
/*