]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule: add a print_config_from_gitmodules() helper
authorAntonio Ospite <ao2@ao2.it>
Fri, 5 Oct 2018 13:05:52 +0000 (15:05 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 9 Oct 2018 03:40:20 +0000 (12:40 +0900)
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 <ao2@ao2.it>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
submodule-config.c
submodule-config.h

index fc2c41b947cb471deef42323c83f8b28f42780d6..5aaf7ac00ed34deed969fdee0c12dbc2e2749988 100644 (file)
@@ -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;
index dc7278eea45deedc33635af50b016e9ee28df7d2..031747ccf8a219748b713dcb1be2e246db50e6f6 100644 (file)
@@ -48,6 +48,7 @@ const struct submodule *submodule_from_path(struct repository *r,
                                            const struct object_id *commit_or_tree,
                                            const char *path);
 void submodule_free(struct repository *r);
+int print_config_from_gitmodules(struct repository *repo, const char *key);
 
 /*
  * Returns 0 if the name is syntactically acceptable as a submodule "name"