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

[PATCH 3/7] builtin/submodule--helper: factor out submodule updating

From
Stefan Beller <sbeller@google.com>
Date
Aug 3, 2018, 22:23 UTC
Message-ID
<20180803222322.261813-4-sbeller@google.com>
In-Reply-To
<20180803222322.261813-1-sbeller@google.com>

Separate the command line parsing from the actual execution of the command within the repository. For now there is not a lot of execution as most of it is still in git-submodule.sh.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/submodule--helper.c | 59 +++++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 26 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index da700c88963..32f00ca6f87 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1474,6 +1474,8 @@ struct submodule_update_clone {
 	/* failed clones to be retried again */
 	const struct cache_entry **failed_clones;
 	int failed_clones_nr, failed_clones_alloc;
+
+	int max_jobs;
 };
 #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
 	SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
@@ -1716,11 +1718,36 @@ static int git_update_clone_config(const char *var, const char *value,
 	return 0;
 }
 
+static int update_submodules(struct submodule_update_clone *suc)
+{
+	struct string_list_item *item;
+
+	run_processes_parallel(suc->max_jobs,
+			       update_clone_get_next_task,
+			       update_clone_start_failure,
+			       update_clone_task_finished,
+			       suc);
+
+	/*
+	 * We saved the output and put it out all at once now.
+	 * That means:
+	 * - the listener does not have to interleave their (checkout)
+	 *   work with our fetching.  The writes involved in a
+	 *   checkout involve more straightforward sequential I/O.
+	 * - the listener can avoid doing any work if fetching failed.
+	 */
+	if (suc->quickstop)
+		return 1;
+
+	for_each_string_list_item(item, &suc->projectlines)
+		fprintf(stdout, "%s", item->string);
+
+	return 0;
+}
+
 static int update_clone(int argc, const char **argv, const char *prefix)
 {
 	const char *update = NULL;
-	int max_jobs = 1;
-	struct string_list_item *item;
 	struct pathspec pathspec;
 	struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
 
@@ -1742,7 +1769,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 		OPT_STRING(0, "depth", &suc.depth, "<depth>",
 			   N_("Create a shallow clone truncated to the "
 			      "specified number of revisions")),
-		OPT_INTEGER('j', "jobs", &max_jobs,
+		OPT_INTEGER('j', "jobs", &suc.max_jobs,
 			    N_("parallel jobs")),
 		OPT_BOOL(0, "recommend-shallow", &suc.recommend_shallow,
 			    N_("whether the initial clone should follow the shallow recommendation")),
@@ -1758,8 +1785,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 	};
 	suc.prefix = prefix;
 
-	update_clone_config_from_gitmodules(&max_jobs);
-	git_config(git_update_clone_config, &max_jobs);
+	update_clone_config_from_gitmodules(&suc.max_jobs);
+	git_config(git_update_clone_config, &suc.max_jobs);
 
 	argc = parse_options(argc, argv, prefix, module_update_clone_options,
 			     git_submodule_helper_usage, 0);
@@ -1774,27 +1801,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 	if (pathspec.nr)
 		suc.warn_if_uninitialized = 1;
 
-	run_processes_parallel(max_jobs,
-			       update_clone_get_next_task,
-			       update_clone_start_failure,
-			       update_clone_task_finished,
-			       &suc);
-
-	/*
-	 * We saved the output and put it out all at once now.
-	 * That means:
-	 * - the listener does not have to interleave their (checkout)
-	 *   work with our fetching.  The writes involved in a
-	 *   checkout involve more straightforward sequential I/O.
-	 * - the listener can avoid doing any work if fetching failed.
-	 */
-	if (suc.quickstop)
-		return 1;
-
-	for_each_string_list_item(item, &suc.projectlines)
-		fprintf(stdout, "%s", item->string);
-
-	return 0;
+	return update_submodules(&suc);
 }
 
 static int resolve_relative_path(int argc, const char **argv, const char *prefix)
-- 
2.18.0.132.g195c49a2227
Previous: Stefan BellerNext: Stefan Beller
Message 4 of 24 in “Resend of sb/submodule-update-in-c”
  1. 0/7 Resend of sb/submodule-update-in-cStefan Beller, Aug 3, 2018
  2. 2/7 git-submodule.sh: rename unused variablesStefan Beller, Aug 3, 2018
  3. 1/7 git-submodule.sh: align error reporting for update mode to use pathStefan Beller, Aug 3, 2018
  4. 3/7 builtin/submodule--helper: factor out submodule updatingStefan Beller, Aug 3, 2018
  5. 4/7 builtin/submodule--helper: store update_clone information in a structStefan Beller, Aug 3, 2018
  6. 5/7 builtin/submodule--helper: factor out method to update a single submoduleStefan Beller, Aug 3, 2018
  7. 6/7 submodule--helper: replace connect-gitdir-workingtree by ensure-core-worktreeStefan Beller, Aug 3, 2018
  8. Brandon WilliamsAug 10, 2018
  9. Stefan BellerAug 10, 2018
  10. Brandon WilliamsAug 10, 2018
  11. 7/7 submodule--helper: introduce new update-module-mode helperStefan Beller, Aug 3, 2018
  12. Junio C HamanoAug 3, 2018
  13. 0/7 Resend of sb/submodule-update-in-cStefan Beller, Aug 13, 2018
  14. 1/7 git-submodule.sh: align error reporting for update mode to use pathStefan Beller, Aug 13, 2018
  15. 2/7 git-submodule.sh: rename unused variablesStefan Beller, Aug 13, 2018
  16. 3/7 builtin/submodule--helper: factor out submodule updatingStefan Beller, Aug 13, 2018
  17. 4/7 builtin/submodule--helper: store update_clone information in a structStefan Beller, Aug 13, 2018
  18. 5/7 builtin/submodule--helper: factor out method to update a single submoduleStefan Beller, Aug 13, 2018
  19. 6/7 submodule--helper: replace connect-gitdir-workingtree by ensure-core-worktreeStefan Beller, Aug 13, 2018
  20. 7/7 submodule--helper: introduce new update-module-mode helperStefan Beller, Aug 13, 2018
  21. Duy NguyenAug 18, 2018
  22. Stefan BellerAug 20, 2018
  23. Junio C HamanoAug 14, 2018
  24. Stefan BellerAug 14, 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.