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

[PATCHv18 03/11] fetching submodules: respect `submodule.fetchJobs` config option

From
Stefan Beller <sbeller@google.com>
Date
Feb 25, 2016, 23:08 UTC
Message-ID
<1456441708-13512-4-git-send-email-sbeller@google.com>
In-Reply-To
<1456441708-13512-1-git-send-email-sbeller@google.com>

This allows to configure fetching and updating in parallel without having the command line option.

This moved the responsibility to determine how many parallel processes to start from builtin/fetch to submodule.c as we need a way to communicate "The user did not specify the number of parallel processes in the command line options" in the builtin fetch. The submodule code takes care of the precedence (CLI > config > default).

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 Documentation/config.txt    |  6 ++++++
 builtin/fetch.c             |  2 +-
 submodule.c                 | 16 +++++++++++++++-
 submodule.h                 |  2 ++
 t/t5526-fetch-submodules.sh | 14 ++++++++++++++
 5 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 2d06b11..3b02732 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2646,6 +2646,12 @@ submodule.<name>.ignore::
 	"--ignore-submodules" option. The 'git submodule' commands are not
 	affected by this setting.
 
+submodule.fetchJobs::
+	Specifies how many submodules are fetched/cloned at the same time.
+	A positive integer allows up to that number of submodules fetched
+	in parallel. A value of 0 will give some reasonable default.
+	If unset, it defaults to 1.
+
 tag.sort::
 	This variable controls the sort ordering of tags when displayed by
 	linkgit:git-tag[1]. Without the "--sort=<value>" option provided, the
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 586840d..5aa1c2d 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -37,7 +37,7 @@ static int prune = -1; /* unspecified */
 static int all, append, dry_run, force, keep, multiple, update_head_ok, verbosity;
 static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
 static int tags = TAGS_DEFAULT, unshallow, update_shallow;
-static int max_children = 1;
+static int max_children = -1;
 static const char *depth;
 static const char *upload_pack;
 static struct strbuf default_rla = STRBUF_INIT;
diff --git a/submodule.c b/submodule.c
index b38dd51..051f722 100644
--- a/submodule.c
+++ b/submodule.c
@@ -15,6 +15,7 @@
 #include "thread-utils.h"
 
 static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
+static int parallel_jobs = 1;
 static struct string_list changed_submodule_paths;
 static int initialized_fetch_ref_tips;
 static struct sha1_array ref_tips_before_fetch;
@@ -169,7 +170,12 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
 
 int submodule_config(const char *var, const char *value, void *cb)
 {
-	if (starts_with(var, "submodule."))
+	if (!strcmp(var, "submodule.fetchjobs")) {
+		parallel_jobs = git_config_int(var, value);
+		if (parallel_jobs < 0)
+			die(_("negative values not allowed for submodule.fetchJobs"));
+		return 0;
+	} else if (starts_with(var, "submodule."))
 		return parse_submodule_config_option(var, value);
 	else if (!strcmp(var, "fetch.recursesubmodules")) {
 		config_fetch_recurse_submodules = parse_fetch_recurse_submodules_arg(var, value);
@@ -772,6 +778,9 @@ int fetch_populated_submodules(const struct argv_array *options,
 	argv_array_push(&spf.args, "--recurse-submodules-default");
 	/* default value, "--submodule-prefix" and its value are added later */
 
+	if (max_parallel_jobs < 0)
+		max_parallel_jobs = parallel_jobs;
+
 	calculate_changed_submodule_paths();
 	run_processes_parallel(max_parallel_jobs,
 			       get_next_submodule,
@@ -1118,3 +1127,8 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
 	strbuf_release(&rel_path);
 	free((void *)real_work_tree);
 }
+
+int parallel_submodules(void)
+{
+	return parallel_jobs;
+}
diff --git a/submodule.h b/submodule.h
index 3464500..3166608 100644
--- a/submodule.h
+++ b/submodule.h
@@ -26,6 +26,7 @@ struct submodule_update_strategy {
 	enum submodule_update_type type;
 	const char *command;
 };
+#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}
 
 int is_staging_gitmodules_ok(void);
 int update_path_in_gitmodules(const char *oldpath, const char *newpath);
@@ -57,5 +58,6 @@ int find_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_nam
 		struct string_list *needs_pushing);
 int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name);
 void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
+int parallel_submodules(void);
 
 #endif
diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh
index 1241146..954d0e4 100755
--- a/t/t5526-fetch-submodules.sh
+++ b/t/t5526-fetch-submodules.sh
@@ -471,4 +471,18 @@ test_expect_success "don't fetch submodule when newly recorded commits are alrea
 	test_i18ncmp expect.err actual.err
 '
 
+test_expect_success 'fetching submodules respects parallel settings' '
+	git config fetch.recurseSubmodules true &&
+	(
+		cd downstream &&
+		GIT_TRACE=$(pwd)/trace.out git fetch --jobs 7 &&
+		grep "7 tasks" trace.out &&
+		git config submodule.fetchJobs 8 &&
+		GIT_TRACE=$(pwd)/trace.out git fetch &&
+		grep "8 tasks" trace.out &&
+		GIT_TRACE=$(pwd)/trace.out git fetch --jobs 9 &&
+		grep "9 tasks" trace.out
+	)
+'
+
 test_done
-- 
2.7.0.rc0.36.g75877e4.dirty
Previous: Stefan BellerNext: Stefan Beller
Message 21 of 59 in “[PATCHv17 00/11] Expose submodule parallelism to the user”
  1. Stefan BellerFeb 25, 2016
  2. 01/11 submodule-config: keep update strategy aroundStefan Beller, Feb 25, 2016
  3. Junio C HamanoFeb 25, 2016
  4. Stefan BellerFeb 25, 2016
  5. 02/11 submodule-config: drop check against NULLStefan Beller, Feb 25, 2016
  6. 03/11 fetching submodules: respect `submodule.fetchJobs` config optionStefan Beller, Feb 25, 2016
  7. 04/11 submodule update: direct error message to stderrStefan Beller, Feb 25, 2016
  8. 05/11 run_processes_parallel: treat output of children as byte arrayStefan Beller, Feb 25, 2016
  9. Junio C HamanoFeb 25, 2016
  10. Stefan BellerFeb 25, 2016
  11. 06/11 run-command: expose default_{start_failure, task_finished}Stefan Beller, Feb 25, 2016
  12. 07/11 run_processes_parallel: rename parameters for the callbacksStefan Beller, Feb 25, 2016
  13. 08/11 run_processes_parallel: correctly terminate callbacks with an LFStefan Beller, Feb 25, 2016
  14. 09/11 git submodule update: have a dedicated helper for cloningStefan Beller, Feb 25, 2016
  15. 10/11 submodule update: expose parallelism to the userStefan Beller, Feb 25, 2016
  16. 11/11 clone: allow an explicit argument for parallel submodule clonesStefan Beller, Feb 25, 2016
  17. Junio C HamanoFeb 25, 2016
  18. 00/11 ExposeStefan Beller, Feb 25, 2016
  19. 01/11 submodule-config: keep update strategy aroundStefan Beller, Feb 25, 2016
  20. 02/11 submodule-config: drop check against NULLStefan Beller, Feb 25, 2016
  21. 03/11 fetching submodules: respect `submodule.fetchJobs` config optionStefan Beller, Feb 25, 2016
  22. 04/11 submodule update: direct error message to stderrStefan Beller, Feb 25, 2016
  23. 05/11 run_processes_parallel: treat output of children as byte arrayStefan Beller, Feb 25, 2016
  24. 06/11 run-command: expose default_{start_failure, task_finished}Stefan Beller, Feb 25, 2016
  25. 07/11 run_processes_parallel: rename parameters for the callbacksStefan Beller, Feb 25, 2016
  26. 08/11 run_processes_parallel: correctly terminate callbacks with an LFStefan Beller, Feb 25, 2016
  27. 09/11 git submodule update: have a dedicated helper for cloningStefan Beller, Feb 25, 2016
  28. 10/11 submodule update: expose parallelism to the userStefan Beller, Feb 25, 2016
  29. 11/11 clone: allow an explicit argument for parallel submodule clonesStefan Beller, Feb 25, 2016
  30. Stefan BellerFeb 25, 2016
  31. Jonathan NiederFeb 25, 2016
  32. Stefan BellerFeb 25, 2016
  33. Jonathan NiederFeb 25, 2016
  34. Junio C HamanoFeb 25, 2016
  35. 00/11 Expose submodule parallelism to the userStefan Beller, Feb 25, 2016
  36. 01/11 submodule-config: keep update strategy aroundStefan Beller, Feb 25, 2016
  37. 02/11 submodule-config: drop check against NULLStefan Beller, Feb 25, 2016
  38. 03/11 fetching submodules: respect `submodule.fetchJobs` config optionStefan Beller, Feb 25, 2016
  39. 04/11 submodule update: direct error message to stderrStefan Beller, Feb 25, 2016
  40. 05/11 run_processes_parallel: treat output of children as byte arrayStefan Beller, Feb 25, 2016
  41. 06/11 run-command: expose default_{start_failure, task_finished}Stefan Beller, Feb 25, 2016
  42. 07/11 run_processes_parallel: rename parameters for the callbacksStefan Beller, Feb 25, 2016
  43. 08/11 run_processes_parallel: correctly terminate callbacks with an LFStefan Beller, Feb 25, 2016
  44. 09/11 git submodule update: have a dedicated helper for cloningStefan Beller, Feb 25, 2016
  45. Duy NguyenFeb 27, 2016
  46. Stefan BellerFeb 29, 2016
  47. 10/11 submodule update: expose parallelism to the userStefan Beller, Feb 25, 2016
  48. 11/11 clone: allow an explicit argument for parallel submodule clonesStefan Beller, Feb 25, 2016
  49. Jonathan NiederFeb 25, 2016
  50. Johannes SixtFeb 29, 2016
  51. Stefan BellerFeb 29, 2016
  52. Junio C HamanoFeb 29, 2016
  53. Stefan BellerFeb 29, 2016
  54. Junio C HamanoFeb 29, 2016
  55. Stefan BellerFeb 29, 2016
  56. Johannes SixtFeb 29, 2016
  57. Junio C HamanoFeb 29, 2016
  58. Stefan BellerFeb 29, 2016
  59. Jonathan NiederFeb 25, 2016

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.