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

[PATCH 4/8] submodule loading: separate code path for .gitmodules and config overlay

From
Stefan Beller <sbeller@google.com>
Date
May 26, 2017, 19:10 UTC
Message-ID
<20170526191017.19155-5-sbeller@google.com>
In-Reply-To
<20170526191017.19155-1-sbeller@google.com>

The .gitmodules file is not supposed to have all the options available, that are available in the configuration so separate it out.

A configuration option such as the hypothetical submodule.color.diff that determines in which color a submodule change is printed, is a very user specific thing, that the .gitmodules file should not tamper with.

The .gitmodules file should only be used for settings that required to setup the project in which the .gitmodules file is tracked. As the minimum this would only include the name<->path mapping of the submodule and its URL and branch.

Any further setting (such as 'fetch.recursesubmodules' or 'submodule.<name>.{update, ignore, shallow}') is not specific to the project setup requirements, but rather is a distribution of suggested developer configurations. In other areas of Git a suggested developer configuration is not transported in-tree but via other means. In an organisation this could be done by deploying an opinionated system wide config (/etc/gitconfig) or by putting the settings in the users home directory when they start at the organisation. In open source projects this is often accomplished via extensive READMEs (cf. our SubmittingPatches/CodingGuidlines).

As a later patch in this series wants to introduce a generic submodule recursion option, we want to make sure that switch is not exposed via the gitmodules file.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/submodule.c b/submodule.c
index c9e764b519..78cccb7563 100644
--- a/submodule.c
+++ b/submodule.c
@@ -153,7 +153,8 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
 	}
 }
 
-int submodule_config(const char *var, const char *value, void *cb)
+/* For loading from the .gitmodules file. */
+static int git_modules_config(const char *var, const char *value, void *cb)
 {
 	if (!strcmp(var, "submodule.fetchjobs")) {
 		parallel_jobs = git_config_int(var, value);
@@ -169,6 +170,12 @@ int submodule_config(const char *var, const char *value, void *cb)
 	return 0;
 }
 
+/* Loads all submodule settings from the config */
+int submodule_config(const char *var, const char *value, void *cb)
+{
+	return git_modules_config(var, value, cb);
+}
+
 int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
 						     const char *arg, int unset)
 {
@@ -222,7 +229,8 @@ void gitmodules_config(void)
 		}
 
 		if (!gitmodules_is_unmerged)
-			git_config_from_file(submodule_config, gitmodules_path.buf, NULL);
+			git_config_from_file(git_modules_config,
+				gitmodules_path.buf, NULL);
 		strbuf_release(&gitmodules_path);
 	}
 }
@@ -233,7 +241,7 @@ void gitmodules_config_sha1(const unsigned char *commit_sha1)
 	unsigned char sha1[20];
 
 	if (gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
-		git_config_from_blob_sha1(submodule_config, rev.buf,
+		git_config_from_blob_sha1(git_modules_config, rev.buf,
 					  sha1, NULL);
 	}
 	strbuf_release(&rev);
-- 
2.13.0.17.g582985b1e4
Previous: Stefan BellerNext: Stefan Beller
Message 3 of 15 in “[PATCHv2 0/8] A reroll of sb/submodule-blanket-recursive”
  1. Stefan BellerMay 26, 2017
  2. 1/8 submodule recursing: do not write a config variable twiceStefan Beller, May 26, 2017
  3. 4/8 submodule loading: separate code path for .gitmodules and config overlayStefan Beller, May 26, 2017
  4. 8/8 builtin/fetch.c: respect 'submodule.recurse' optionStefan Beller, May 26, 2017
  5. 5/8 Introduce 'submodule.recurse' option for worktree manipulatorsStefan Beller, May 26, 2017
  6. 3/8 reset/checkout/read-tree: unify config callback for submodule recursionStefan Beller, May 26, 2017
  7. 6/8 builtin/grep.c: respect 'submodule.recurse' optionStefan Beller, May 26, 2017
  8. 2/8 submodule test invocation: only pass additional argumentsStefan Beller, May 26, 2017
  9. 7/8 builtin/push.c: respect 'submodule.recurse' optionStefan Beller, May 26, 2017
  10. Junio C HamanoMay 30, 2017
  11. 0/4 A reroll of sb/submodule-blanket-recursiveStefan Beller, Jun 1, 2017
  12. 1/4 Introduce 'submodule.recurse' option for worktree manipulatorsStefan Beller, Jun 1, 2017
  13. 3/4 builtin/push.c: respect 'submodule.recurse' optionStefan Beller, Jun 1, 2017
  14. 2/4 builtin/grep.c: respect 'submodule.recurse' optionStefan Beller, Jun 1, 2017
  15. 4/4 builtin/fetch.c: respect 'submodule.recurse' optionStefan Beller, Jun 1, 2017

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.