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

[RFC/WIP PATCH 3/3] submodule: simplify decision tree whether to or not to fetch

From
Heiko Voigt <hvoigt@hvoigt.net>
Date
Feb 25, 2013, 01:06 UTC
Message-ID
<5062c014d5567e0b30e12fb1bc084fcfd71d5d0c.1361751905.git.hvoigt@hvoigt.net>
In-Reply-To
<cover.1361751905.git.hvoigt@hvoigt.net>
To make extending this logic later easier.
Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
---
 submodule.c | 50 +++++++++++++++++++++++++++-----------------------
 1 file changed, 27 insertions(+), 23 deletions(-)
diff --git a/submodule.c b/submodule.c
index b603000..a6fe16e 100644
--- a/submodule.c
+++ b/submodule.c
@@ -737,6 +737,23 @@ static void calculate_changed_submodule_paths(void)
 	submodule_config_cache_free(&submodule_config_cache);
 }
 
+static int get_fetch_recurse_config(const char *name, int command_line_option)
+{
+	if (command_line_option != RECURSE_SUBMODULES_DEFAULT)
+		return command_line_option;
+
+	struct string_list_item *fetch_recurse_submodules_option;
+	fetch_recurse_submodules_option = unsorted_string_list_lookup(&config_fetch_recurse_submodules_for_name, name);
+	if (fetch_recurse_submodules_option)
+		/* local config overrules everything except commandline */
+		return (intptr_t)fetch_recurse_submodules_option->util;
+
+	if (gitmodules_is_unmerged)
+		return RECURSE_SUBMODULES_OFF;
+
+	return config_fetch_recurse_submodules;
+}
+
 int fetch_populated_submodules(const struct argv_array *options,
 			       const char *prefix, int command_line_option,
 			       int quiet)
@@ -781,32 +798,19 @@ int fetch_populated_submodules(const struct argv_array *options,
 		if (name_for_path)
 			name = name_for_path->util;
 
-		default_argv = "yes";
-		if (command_line_option == RECURSE_SUBMODULES_DEFAULT) {
-			struct string_list_item *fetch_recurse_submodules_option;
-			fetch_recurse_submodules_option = unsorted_string_list_lookup(&config_fetch_recurse_submodules_for_name, name);
-			if (fetch_recurse_submodules_option) {
-				if ((intptr_t)fetch_recurse_submodules_option->util == RECURSE_SUBMODULES_OFF)
-					continue;
-				if ((intptr_t)fetch_recurse_submodules_option->util == RECURSE_SUBMODULES_ON_DEMAND) {
-					if (!unsorted_string_list_lookup(&changed_submodule_names, name))
-						continue;
-					default_argv = "on-demand";
-				}
-			} else {
-				if ((config_fetch_recurse_submodules == RECURSE_SUBMODULES_OFF) ||
-				    gitmodules_is_unmerged)
-					continue;
-				if (config_fetch_recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) {
-					if (!unsorted_string_list_lookup(&changed_submodule_names, name))
-						continue;
-					default_argv = "on-demand";
-				}
-			}
-		} else if (command_line_option == RECURSE_SUBMODULES_ON_DEMAND) {
+		switch (get_fetch_recurse_config(name, command_line_option)) {
+		default:
+		case RECURSE_SUBMODULES_DEFAULT:
+		case RECURSE_SUBMODULES_ON_DEMAND:
 			if (!unsorted_string_list_lookup(&changed_submodule_names, name))
 				continue;
 			default_argv = "on-demand";
+			break;
+		case RECURSE_SUBMODULES_ON:
+			default_argv = "yes";
+			break;
+		case RECURSE_SUBMODULES_OFF:
+			continue;
 		}
 
 		strbuf_addf(&submodule_path, "%s/%s", work_tree, ce->name);
-- 
1.8.2.rc0.25.g5062c01
Previous: Heiko Voigt
Message 25 of 25 in “fetch moved submodules on-demand”
  1. 0/3 fetch moved submodules on-demandHeiko Voigt, Feb 25, 2013
  2. 1/3 teach config parsing to read from strbufHeiko Voigt, Feb 25, 2013
  3. Junio C HamanoFeb 25, 2013
  4. Heiko VoigtFeb 25, 2013
  5. 0/4 allow more sources for config valuesHeiko Voigt, Feb 26, 2013
  6. 1/4 config: factor out config file stack managementHeiko Voigt, Feb 26, 2013
  7. Jeff KingFeb 26, 2013
  8. Heiko VoigtFeb 26, 2013
  9. Jeff KingFeb 26, 2013
  10. Junio C HamanoFeb 26, 2013
  11. Heiko VoigtFeb 27, 2013
  12. Junio C HamanoFeb 26, 2013
  13. Heiko VoigtFeb 27, 2013
  14. 2/4 config: drop file pointer validity check in get_next_char()Heiko Voigt, Feb 26, 2013
  15. Jeff KingFeb 26, 2013
  16. Heiko VoigtFeb 27, 2013
  17. Heiko VoigtFeb 28, 2013
  18. Heiko VoigtFeb 28, 2013
  19. 3/4 config: make parsing stack struct independent from actual data sourceHeiko Voigt, Feb 26, 2013
  20. 4/4 teach config parsing to read from strbufHeiko Voigt, Feb 26, 2013
  21. Ramsay JonesMar 7, 2013
  22. Heiko VoigtMar 10, 2013
  23. Jeff KingFeb 26, 2013
  24. 2/3 implement fetching of moved submodulesHeiko Voigt, Feb 25, 2013
  25. 3/3 submodule: simplify decision tree whether to or not to fetchHeiko Voigt, Feb 25, 2013

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.