git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v7 01/10] submodule: add a print_config_from_gitmodules() helper

From
Antonio Ospite <ao2@ao2.it>
Date
Oct 25, 2018, 16:18 UTC
Message-ID
<20181025161813.17252-2-ao2@ao2.it>
In-Reply-To
<20181025161813.17252-1-ao2@ao2.it>

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>
---
 submodule-config.c | 25 +++++++++++++++++++++++++
 submodule-config.h |  1 +
 2 files changed, 26 insertions(+)
diff --git a/submodule-config.c b/submodule-config.c
index b132f7a80b..e36d4e2271 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -692,6 +692,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;
diff --git a/submodule-config.h b/submodule-config.h
index dc7278eea4..031747ccf8 100644
--- a/submodule-config.h
+++ b/submodule-config.h
@@ -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"
-- 
2.19.1
Previous: Antonio OspiteNext: Antonio Ospite
Message 2 of 17 in “Make submodules work if .gitmodules is not checked out”
  1. 00/10 Make submodules work if .gitmodules is not checked outAntonio Ospite, Oct 25, 2018
  2. 01/10 submodule: add a print_config_from_gitmodules() helperAntonio Ospite, Oct 25, 2018
  3. 05/10 submodule--helper: add a new 'config' subcommandAntonio Ospite, Oct 25, 2018
  4. 04/10 t7411: be nicer to future tests and really clean things upAntonio Ospite, Oct 25, 2018
  5. 09/10 submodule: support reading .gitmodules when it's not in the working treeAntonio Ospite, Oct 25, 2018
  6. Johannes SchindelinOct 30, 2018
  7. Antonio OspiteOct 30, 2018
  8. Junio C HamanoOct 31, 2018
  9. 07/10 t7506: clean up .gitmodules properly before setting up new scenarioAntonio Ospite, Oct 25, 2018
  10. 06/10 submodule: use the 'submodule--helper config' commandAntonio Ospite, Oct 25, 2018
  11. 08/10 submodule: add a helper to check if it is safe to write to .gitmodulesAntonio Ospite, Oct 25, 2018
  12. 10/10 t/helper: add test-submodule-nested-repo-configAntonio Ospite, Oct 25, 2018
  13. 02/10 submodule: factor out a config_set_in_gitmodules_file_gently functionAntonio Ospite, Oct 25, 2018
  14. 03/10 t7411: merge tests 5 and 6Antonio Ospite, Oct 25, 2018
  15. Stefan BellerOct 25, 2018
  16. Junio C HamanoOct 26, 2018
  17. Stefan BellerOct 26, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.