Thread (30 messages) 30 messages, 4 authors, 2018-08-09

Re: [RFC PATCH v2 01/12] submodule: add a print_config_from_gitmodules() helper

From: Stefan Beller <hidden>
Date: 2018-08-02 18:05:16

On Thu, Aug 2, 2018 at 6:47 AM Antonio Ospite [off-list ref] wrote:
quoted hunk ↗ jump to hunk
This will be used to print values just like "git config -f .gitmodules"
would.

Signed-off-by: Antonio Ospite <redacted>
---
 submodule-config.c | 25 +++++++++++++++++++++++++
 submodule-config.h |  2 ++
 2 files changed, 27 insertions(+)
diff --git a/submodule-config.c b/submodule-config.c
index 2a7259ba8b..6f6f5f9960 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 *key_, const char *value_, void *cb_data)
+{
+       char *key = cb_data;
+
+       if (!strcmp(key, key_))
+               printf("%s\n", value_);
+
+       return 0;
+}
+
+int print_config_from_gitmodules(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, the_repository, store_key);
+
+       free(store_key);
+       return 0;
+}
+
 struct fetch_config {
        int *max_children;
        int *recurse_submodules;
diff --git a/submodule-config.h b/submodule-config.h
index dc7278eea4..6fec3caadd 100644
--- a/submodule-config.h
+++ b/submodule-config.h
@@ -56,6 +56,8 @@ void submodule_free(struct repository *r);
  */
 int check_submodule_name(const char *name);

+extern int print_config_from_gitmodules(const char *key);
The only real pushback for this patch I'd have is lack of documentation
in public functions, though this is pretty self explanatory; so I'd be fine
for lacking the docs here.

In case a resend is needed, please drop the extern keyword here.

Thanks,
Stefan
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help