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

[RFC PATCH v2 02/12] submodule: factor out a config_set_in_gitmodules_file_gently function

From
Antonio Ospite <ao2@ao2.it>
Date
Aug 2, 2018, 13:46 UTC
Message-ID
<20180802134634.10300-3-ao2@ao2.it>
In-Reply-To
<20180802134634.10300-1-ao2@ao2.it>

Introduce a new config_set_in_gitmodules_file_gently() function to write config values to the .gitmodules file.

This is in preparation for a future change which will use the function to write to the .gitmodules file in a more controlled way instead of using "git config -f .gitmodules".

The purpose of the change is mainly to centralize the code that writes to the .gitmodules file to avoid some duplication.

The naming follows git_config_set_in_file_gently() but the git_ prefix is removed to communicate that this is not a generic git-config API.

Signed-off-by: Antonio Ospite <ao2@ao2.it>
---
 submodule-config.c | 12 ++++++++++++
 submodule-config.h |  1 +
 submodule.c        | 10 +++-------
 3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/submodule-config.c b/submodule-config.c
index 6f6f5f9960..702d40dd6b 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -707,6 +707,18 @@ int print_config_from_gitmodules(const char *key)
 	return 0;
 }
 
+int config_set_in_gitmodules_file_gently(const char *key, const char *value)
+{
+	int ret;
+
+	ret = git_config_set_in_file_gently(GITMODULES_FILE, key, value);
+	if (ret < 0)
+		/* Maybe the user already did that, don't error out here */
+		warning(_("Could not update .gitmodules entry %s"), key);
+
+	return ret;
+}
+
 struct fetch_config {
 	int *max_children;
 	int *recurse_submodules;
diff --git a/submodule-config.h b/submodule-config.h
index 6fec3caadd..074e74a01c 100644
--- a/submodule-config.h
+++ b/submodule-config.h
@@ -57,6 +57,7 @@ void submodule_free(struct repository *r);
 int check_submodule_name(const char *name);
 
 extern int print_config_from_gitmodules(const char *key);
+extern int config_set_in_gitmodules_file_gently(const char *key, const char *value);
 
 /*
  * Note: these helper functions exist solely to maintain backward
diff --git a/submodule.c b/submodule.c
index 2a6381864e..2af09068d7 100644
--- a/submodule.c
+++ b/submodule.c
@@ -89,6 +89,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
 {
 	struct strbuf entry = STRBUF_INIT;
 	const struct submodule *submodule;
+	int ret;
 
 	if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
 		return -1;
@@ -104,14 +105,9 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
 	strbuf_addstr(&entry, "submodule.");
 	strbuf_addstr(&entry, submodule->name);
 	strbuf_addstr(&entry, ".path");
-	if (git_config_set_in_file_gently(GITMODULES_FILE, entry.buf, newpath) < 0) {
-		/* Maybe the user already did that, don't error out here */
-		warning(_("Could not update .gitmodules entry %s"), entry.buf);
-		strbuf_release(&entry);
-		return -1;
-	}
+	ret = config_set_in_gitmodules_file_gently(entry.buf, newpath);
 	strbuf_release(&entry);
-	return 0;
+	return ret;
 }
 
 /*
-- 
2.18.0
Previous: Stefan BellerNext: Antonio Ospite
Message 24 of 38 in “Make submodules work if .gitmodules is not checked out”
  1. 00/12 Make submodules work if .gitmodules is not checked outAntonio Ospite, Aug 2, 2018
  2. 01/12 submodule: add a print_config_from_gitmodules() helperAntonio Ospite, Aug 2, 2018
  3. Stefan BellerAug 2, 2018
  4. Antonio OspiteAug 9, 2018
  5. 10/12 t7416: add new test about HEAD:.gitmodules and not existing .gitmodulesAntonio Ospite, Aug 2, 2018
  6. Stefan BellerAug 2, 2018
  7. Antonio OspiteAug 9, 2018
  8. 07/12 submodule: use 'submodule--helper config --stage' to stage .gitmodulesAntonio Ospite, Aug 2, 2018
  9. 08/12 t7506: cleanup .gitmodules properly before setting up new scenarioAntonio Ospite, Aug 2, 2018
  10. Stefan BellerAug 2, 2018
  11. 12/12 submodule: remove the .gitmodules file when it is emptyAntonio Ospite, Aug 2, 2018
  12. Stefan BellerAug 2, 2018
  13. Antonio OspiteAug 3, 2018
  14. 11/12 dir: move is_empty_file() from builtin/am.c to dir.c and make it publicAntonio Ospite, Aug 2, 2018
  15. Stefan BellerAug 2, 2018
  16. Antonio OspiteAug 3, 2018
  17. 03/12 t7411: be nicer to future tests and really clean things upAntonio Ospite, Aug 2, 2018
  18. SZEDER GáborAug 2, 2018
  19. Stefan BellerAug 2, 2018
  20. Antonio OspiteAug 9, 2018
  21. Junio C HamanoAug 2, 2018
  22. 09/12 submodule: support reading .gitmodules even when it's not checked outAntonio Ospite, Aug 2, 2018
  23. Stefan BellerAug 2, 2018
  24. 02/12 submodule: factor out a config_set_in_gitmodules_file_gently functionAntonio Ospite, Aug 2, 2018
  25. 05/12 submodule: use the 'submodule--helper config' commandAntonio Ospite, Aug 2, 2018
  26. Stefan BellerAug 2, 2018
  27. 04/12 submodule--helper: add a new 'config' subcommandAntonio Ospite, Aug 2, 2018
  28. Stefan BellerAug 2, 2018
  29. Jeff KingAug 2, 2018
  30. Antonio OspiteAug 3, 2018
  31. 06/12 submodule--helper: add a '--stage' option to the 'config' sub commandAntonio Ospite, Aug 2, 2018
  32. Junio C HamanoAug 2, 2018
  33. Antonio OspiteAug 3, 2018
  34. Junio C HamanoAug 3, 2018
  35. Antonio OspiteAug 6, 2018
  36. Junio C HamanoAug 6, 2018
  37. Antonio OspiteAug 7, 2018
  38. Stefan BellerAug 6, 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.