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

[PATCH 1/7] config: move config_from_gitmodules to submodule-config.c

From
Antonio Ospite <ao2@ao2.it>
Date
Jun 22, 2018, 16:26 UTC
Message-ID
<20180622162656.19338-2-ao2@ao2.it>
In-Reply-To
<20180622162656.19338-1-ao2@ao2.it>

The .gitmodules file is not meant as a place to store arbitrary configuration to distribute with the repository.

Move config_from_gitmodules() out of config.c and into submodule-config.c to make it even clearer that it is not a mechanism to retrieve arbitrary configuration from the .gitmodules file.

Signed-off-by: Antonio Ospite <ao2@ao2.it>
---
 config.c           | 17 -----------------
 config.h           | 10 ----------
 submodule-config.c | 17 +++++++++++++++++
 submodule-config.h | 11 +++++++++++
 4 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/config.c b/config.c
index fbbf0f8e9..2e4dbfa19 100644
--- a/config.c
+++ b/config.c
@@ -2172,23 +2172,6 @@ int git_config_get_pathname(const char *key, const char **dest)
 	return repo_config_get_pathname(the_repository, key, dest);
 }
 
-/*
- * Note: This function exists solely to maintain backward compatibility with
- * 'fetch' and 'update_clone' storing configuration in '.gitmodules' and should
- * NOT be used anywhere else.
- *
- * Runs the provided config function on the '.gitmodules' file found in the
- * working directory.
- */
-void config_from_gitmodules(config_fn_t fn, void *data)
-{
-	if (the_repository->worktree) {
-		char *file = repo_worktree_path(the_repository, GITMODULES_FILE);
-		git_config_from_file(fn, file, data);
-		free(file);
-	}
-}
-
 int git_config_get_expiry(const char *key, const char **output)
 {
 	int ret = git_config_get_string_const(key, output);
diff --git a/config.h b/config.h
index cdac2fc73..3faf4fba9 100644
--- a/config.h
+++ b/config.h
@@ -215,16 +215,6 @@ extern int repo_config_get_maybe_bool(struct repository *repo,
 extern int repo_config_get_pathname(struct repository *repo,
 				    const char *key, const char **dest);
 
-/*
- * Note: This function exists solely to maintain backward compatibility with
- * 'fetch' and 'update_clone' storing configuration in '.gitmodules' and should
- * NOT be used anywhere else.
- *
- * Runs the provided config function on the '.gitmodules' file found in the
- * working directory.
- */
-extern void config_from_gitmodules(config_fn_t fn, void *data);
-
 extern int git_config_get_value(const char *key, const char **value);
 extern const struct string_list *git_config_get_value_multi(const char *key);
 extern void git_config_clear(void);
diff --git a/submodule-config.c b/submodule-config.c
index 388ef1f89..b431555db 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -671,3 +671,20 @@ void submodule_free(struct repository *r)
 	if (r->submodule_cache)
 		submodule_cache_clear(r->submodule_cache);
 }
+
+/*
+ * Note: This function exists solely to maintain backward compatibility with
+ * 'fetch' and 'update_clone' storing configuration in '.gitmodules' and should
+ * NOT be used anywhere else.
+ *
+ * Runs the provided config function on the '.gitmodules' file found in the
+ * working directory.
+ */
+void config_from_gitmodules(config_fn_t fn, void *data)
+{
+	if (the_repository->worktree) {
+		char *file = repo_worktree_path(the_repository, GITMODULES_FILE);
+		git_config_from_file(fn, file, data);
+		free(file);
+	}
+}
diff --git a/submodule-config.h b/submodule-config.h
index ca1f94e2d..5148801f4 100644
--- a/submodule-config.h
+++ b/submodule-config.h
@@ -2,6 +2,7 @@
 #define SUBMODULE_CONFIG_CACHE_H
 
 #include "cache.h"
+#include "config.h"
 #include "hashmap.h"
 #include "submodule.h"
 #include "strbuf.h"
@@ -55,4 +56,14 @@ void submodule_free(struct repository *r);
  */
 int check_submodule_name(const char *name);
 
+/*
+ * Note: This function exists solely to maintain backward compatibility with
+ * 'fetch' and 'update_clone' storing configuration in '.gitmodules' and should
+ * NOT be used anywhere else.
+ *
+ * Runs the provided config function on the '.gitmodules' file found in the
+ * working directory.
+ */
+extern void config_from_gitmodules(config_fn_t fn, void *data);
+
 #endif /* SUBMODULE_CONFIG_H */
-- 
2.18.0
Previous: Brandon WilliamsNext: Antonio Ospite
Message 5 of 15 in “Restrict the usage of config_from_gitmodules()”
  1. 0/7 Restrict the usage of config_from_gitmodules()Antonio Ospite, Jun 22, 2018
  2. 5/7 submodule-config: pass repository as argument to config_from_gitmodulesAntonio Ospite, Jun 22, 2018
  3. 2/7 submodule-config: add helper function to get 'fetch' config from .gitmodulesAntonio Ospite, Jun 22, 2018
  4. Brandon WilliamsJun 22, 2018
  5. 1/7 config: move config_from_gitmodules to submodule-config.cAntonio Ospite, Jun 22, 2018
  6. 7/7 submodule-config: cleanup backward compatibility helpersAntonio Ospite, Jun 22, 2018
  7. Brandon WilliamsJun 22, 2018
  8. 4/7 submodule-config: make 'config_from_gitmodules' privateAntonio Ospite, Jun 22, 2018
  9. 3/7 submodule-config: add helper to get 'update-clone' config from .gitmodulesAntonio Ospite, Jun 22, 2018
  10. Brandon WilliamsJun 22, 2018
  11. 6/7 submodule-config: reuse config_from_gitmodules in repo_read_gitmodulesAntonio Ospite, Jun 22, 2018
  12. Brandon WilliamsJun 22, 2018
  13. Brandon WilliamsJun 22, 2018
  14. Antonio OspiteJun 22, 2018
  15. Brandon WilliamsJun 22, 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.