Skip to content

Commit b22e51c

Browse files
bmwillgitster
authored andcommitted
config: add config_from_gitmodules
Add 'config_from_gitmodules()' function which can be used by 'fetch' and 'update_clone' in order to maintain backwards compatibility with configuration being stored in .gitmodules' since a future patch will remove reading these values in the submodule-config. This function should not be used anywhere other than in 'fetch' and 'update_clone'. Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4c0eeaf commit b22e51c

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

config.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,23 @@ int git_config_get_pathname(const char *key, const char **dest)
20532053
return repo_config_get_pathname(the_repository, key, dest);
20542054
}
20552055

2056+
/*
2057+
* Note: This function exists solely to maintain backward compatibility with
2058+
* 'fetch' and 'update_clone' storing configuration in '.gitmodules' and should
2059+
* NOT be used anywhere else.
2060+
*
2061+
* Runs the provided config function on the '.gitmodules' file found in the
2062+
* working directory.
2063+
*/
2064+
void config_from_gitmodules(config_fn_t fn, void *data)
2065+
{
2066+
if (the_repository->worktree) {
2067+
char *file = repo_worktree_path(the_repository, GITMODULES_FILE);
2068+
git_config_from_file(fn, file, data);
2069+
free(file);
2070+
}
2071+
}
2072+
20562073
int git_config_get_expiry(const char *key, const char **output)
20572074
{
20582075
int ret = git_config_get_string_const(key, output);

config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ extern int repo_config_get_maybe_bool(struct repository *repo,
187187
extern int repo_config_get_pathname(struct repository *repo,
188188
const char *key, const char **dest);
189189

190+
/*
191+
* Note: This function exists solely to maintain backward compatibility with
192+
* 'fetch' and 'update_clone' storing configuration in '.gitmodules' and should
193+
* NOT be used anywhere else.
194+
*
195+
* Runs the provided config function on the '.gitmodules' file found in the
196+
* working directory.
197+
*/
198+
extern void config_from_gitmodules(config_fn_t fn, void *data);
199+
190200
extern int git_config_get_value(const char *key, const char **value);
191201
extern const struct string_list *git_config_get_value_multi(const char *key);
192202
extern void git_config_clear(void);

0 commit comments

Comments
 (0)