Skip to content

Commit 69aba53

Browse files
bmwillgitster
authored andcommitted
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>
1 parent bf12fcd commit 69aba53

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

submodule.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "cache.h"
2+
#include "repository.h"
23
#include "config.h"
34
#include "submodule-config.h"
45
#include "submodule.h"
@@ -255,6 +256,20 @@ void gitmodules_config(void)
255256
}
256257
}
257258

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+
258273
void gitmodules_config_sha1(const unsigned char *commit_sha1)
259274
{
260275
struct strbuf rev = STRBUF_INIT;

submodule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef SUBMODULE_H
22
#define SUBMODULE_H
33

4+
struct repository;
45
struct diff_options;
56
struct argv_array;
67
struct oid_array;
@@ -46,6 +47,7 @@ int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
4647
const char *arg, int unset);
4748
void load_submodule_cache(void);
4849
extern void gitmodules_config(void);
50+
extern void repo_read_gitmodules(struct repository *repo);
4951
extern void gitmodules_config_sha1(const unsigned char *commit_sha1);
5052
extern int is_submodule_initialized(const char *path);
5153
/*

0 commit comments

Comments
 (0)