Skip to content

Commit bcbc780

Browse files
ao2gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1d4361b commit bcbc780

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

submodule-config.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,31 @@ void submodule_free(struct repository *r)
682682
submodule_cache_clear(r->submodule_cache);
683683
}
684684

685+
static int config_print_callback(const char *var, const char *value, void *cb_data)
686+
{
687+
char *wanted_key = cb_data;
688+
689+
if (!strcmp(wanted_key, var))
690+
printf("%s\n", value);
691+
692+
return 0;
693+
}
694+
695+
int print_config_from_gitmodules(struct repository *repo, const char *key)
696+
{
697+
int ret;
698+
char *store_key;
699+
700+
ret = git_config_parse_key(key, &store_key, NULL);
701+
if (ret < 0)
702+
return CONFIG_INVALID_KEY;
703+
704+
config_from_gitmodules(config_print_callback, repo, store_key);
705+
706+
free(store_key);
707+
return 0;
708+
}
709+
685710
struct fetch_config {
686711
int *max_children;
687712
int *recurse_submodules;

submodule-config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const struct submodule *submodule_from_path(struct repository *r,
4848
const struct object_id *commit_or_tree,
4949
const char *path);
5050
void submodule_free(struct repository *r);
51+
int print_config_from_gitmodules(struct repository *repo, const char *key);
5152

5253
/*
5354
* Returns 0 if the name is syntactically acceptable as a submodule "name"

0 commit comments

Comments
 (0)