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

[PATCH v2 2/6] submodule-config: add helper function to get 'fetch' config from .gitmodules

From
Antonio Ospite <ao2@ao2.it>
Date
Jun 26, 2018, 10:47 UTC
Message-ID
<20180626104710.9859-3-ao2@ao2.it>
In-Reply-To
<20180626104710.9859-1-ao2@ao2.it>

Add a helper function to make it clearer that retrieving 'fetch' configuration from the .gitmodules file is a special case supported solely for backward compatibility purposes.

This change removes one direct use of 'config_from_gitmodules' in code not strictly related to submodules, in the effort to communicate better that .gitmodules is not to be used as a mechanism to store arbitrary configuration in the repository that any command can retrieve.

Signed-off-by: Antonio Ospite <ao2@ao2.it>
---
 builtin/fetch.c    | 15 +--------------
 submodule-config.c | 28 ++++++++++++++++++++++++++++
 submodule-config.h |  2 ++
 3 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index ea5b9669a..92a5d235d 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -93,19 +93,6 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
 	return git_default_config(k, v, cb);
 }
 
-static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
-{
-	if (!strcmp(var, "submodule.fetchjobs")) {
-		max_children = parse_submodule_fetchjobs(var, value);
-		return 0;
-	} else if (!strcmp(var, "fetch.recursesubmodules")) {
-		recurse_submodules = parse_fetch_recurse_submodules_arg(var, value);
-		return 0;
-	}
-
-	return 0;
-}
-
 static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
 {
 	/*
@@ -1433,7 +1420,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 	for (i = 1; i < argc; i++)
 		strbuf_addf(&default_rla, " %s", argv[i]);
 
-	config_from_gitmodules(gitmodules_fetch_config, NULL);
+	fetch_config_from_gitmodules(&max_children, &recurse_submodules);
 	git_config(git_fetch_config, NULL);
 
 	argc = parse_options(argc, argv, prefix,
diff --git a/submodule-config.c b/submodule-config.c
index b431555db..f44d6a777 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -688,3 +688,31 @@ void config_from_gitmodules(config_fn_t fn, void *data)
 		free(file);
 	}
 }
+
+struct fetch_config {
+	int *max_children;
+	int *recurse_submodules;
+};
+
+static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
+{
+	struct fetch_config *config = cb;
+	if (!strcmp(var, "submodule.fetchjobs")) {
+		*(config->max_children) = parse_submodule_fetchjobs(var, value);
+		return 0;
+	} else if (!strcmp(var, "fetch.recursesubmodules")) {
+		*(config->recurse_submodules) = parse_fetch_recurse_submodules_arg(var, value);
+		return 0;
+	}
+
+	return 0;
+}
+
+void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules)
+{
+	struct fetch_config config = {
+		.max_children = max_children,
+		.recurse_submodules = recurse_submodules
+	};
+	config_from_gitmodules(gitmodules_fetch_config, &config);
+}
diff --git a/submodule-config.h b/submodule-config.h
index 5148801f4..cff297a75 100644
--- a/submodule-config.h
+++ b/submodule-config.h
@@ -66,4 +66,6 @@ int check_submodule_name(const char *name);
  */
 extern void config_from_gitmodules(config_fn_t fn, void *data);
 
+extern void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules);
+
 #endif /* SUBMODULE_CONFIG_H */
-- 
2.18.0
Previous: Antonio OspiteNext: Junio C Hamano
Message 8 of 14 in “Restrict the usage of config_from_gitmodules to submodule-config”
  1. 0/6 Restrict the usage of config_from_gitmodules to submodule-configAntonio Ospite, Jun 26, 2018
  2. 1/6 config: move config_from_gitmodules to submodule-config.cAntonio Ospite, Jun 26, 2018
  3. 6/6 submodule-config: reuse config_from_gitmodules in repo_read_gitmodulesAntonio Ospite, Jun 26, 2018
  4. 3/6 submodule-config: add helper to get 'update-clone' config from .gitmodulesAntonio Ospite, Jun 26, 2018
  5. 5/6 submodule-config: pass repository as argument to config_from_gitmodulesAntonio Ospite, Jun 26, 2018
  6. Junio C HamanoJun 26, 2018
  7. Antonio OspiteJun 26, 2018
  8. 2/6 submodule-config: add helper function to get 'fetch' config from .gitmodulesAntonio Ospite, Jun 26, 2018
  9. Junio C HamanoJun 26, 2018
  10. Antonio OspiteJun 26, 2018
  11. 4/6 submodule-config: make 'config_from_gitmodules' privateAntonio Ospite, Jun 26, 2018
  12. Junio C HamanoJun 26, 2018
  13. Brandon WilliamsJun 26, 2018
  14. Junio C HamanoJun 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.