From bcbc780d143c4e8a9c6449f38b8c83d62da14906 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Fri, 5 Oct 2018 15:05:52 +0200 Subject: submodule: add a print_config_from_gitmodules() helper Add a new print_config_from_gitmodules() helper function to print values from .gitmodules just like "git config -f .gitmodules" would. This will be used by a new submodule--helper subcommand to be able to access the .gitmodules file in a more controlled way. Signed-off-by: Antonio Ospite Signed-off-by: Junio C Hamano --- submodule-config.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'submodule-config.c') diff --git a/submodule-config.c b/submodule-config.c index fc2c41b947..5aaf7ac00e 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -682,6 +682,31 @@ void submodule_free(struct repository *r) submodule_cache_clear(r->submodule_cache); } +static int config_print_callback(const char *var, const char *value, void *cb_data) +{ + char *wanted_key = cb_data; + + if (!strcmp(wanted_key, var)) + printf("%s\n", value); + + return 0; +} + +int print_config_from_gitmodules(struct repository *repo, const char *key) +{ + int ret; + char *store_key; + + ret = git_config_parse_key(key, &store_key, NULL); + if (ret < 0) + return CONFIG_INVALID_KEY; + + config_from_gitmodules(config_print_callback, repo, store_key); + + free(store_key); + return 0; +} + struct fetch_config { int *max_children; int *recurse_submodules; -- cgit v1.3