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

[PATCH 4/7] builtin/submodule--helper: store update_clone information in a struct

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

The information that is printed for update_submodules in 'submodule--helper update-clone' and consumed by 'git submodule update' is stored as a string per submodule. This made sense at the time of 48308681b07 (git submodule update: have a dedicated helper for cloning, 2016-02-29), but as we want to migrate the rest of the submodule update into C, we're better off having access to the raw information in a helper struct.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/submodule--helper.c | 37 +++++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 10 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 32f00ca6f87..40b94dd622e 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1446,6 +1446,12 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 	return 0;
 }
 
+struct update_clone_data {
+	const struct submodule *sub;
+	struct object_id oid;
+	unsigned just_cloned;
+};
+
 struct submodule_update_clone {
 	/* index into 'list', the list of submodules to look into for cloning */
 	int current;
@@ -1465,8 +1471,9 @@ struct submodule_update_clone {
 	const char *recursive_prefix;
 	const char *prefix;
 
-	/* Machine-readable status lines to be consumed by git-submodule.sh */
-	struct string_list projectlines;
+	/* to be consumed by git-submodule.sh */
+	struct update_clone_data *update_clone;
+	int update_clone_nr; int update_clone_alloc;
 
 	/* If we want to stop as fast as possible and return an error */
 	unsigned quickstop : 1;
@@ -1480,7 +1487,7 @@ struct submodule_update_clone {
 #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
 	SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
 	NULL, NULL, NULL, \
-	STRING_LIST_INIT_DUP, 0, NULL, 0, 0}
+	NULL, 0, 0, 0, NULL, 0, 0, 0}
 
 
 static void next_submodule_warn_missing(struct submodule_update_clone *suc,
@@ -1574,10 +1581,12 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
 	strbuf_addf(&sb, "%s/.git", ce->name);
 	needs_cloning = !file_exists(sb.buf);
 
-	strbuf_reset(&sb);
-	strbuf_addf(&sb, "dummy %s %d\t%s\n",
-		    oid_to_hex(&ce->oid), needs_cloning, ce->name);
-	string_list_append(&suc->projectlines, sb.buf);
+	ALLOC_GROW(suc->update_clone, suc->update_clone_nr + 1,
+		   suc->update_clone_alloc);
+	oidcpy(&suc->update_clone[suc->update_clone_nr].oid, &ce->oid);
+	suc->update_clone[suc->update_clone_nr].just_cloned = needs_cloning;
+	suc->update_clone[suc->update_clone_nr].sub = sub;
+	suc->update_clone_nr++;
 
 	if (!needs_cloning)
 		goto cleanup;
@@ -1720,7 +1729,8 @@ static int git_update_clone_config(const char *var, const char *value,
 
 static int update_submodules(struct submodule_update_clone *suc)
 {
-	struct string_list_item *item;
+	int i;
+	struct strbuf sb = STRBUF_INIT;
 
 	run_processes_parallel(suc->max_jobs,
 			       update_clone_get_next_task,
@@ -1739,9 +1749,16 @@ static int update_submodules(struct submodule_update_clone *suc)
 	if (suc->quickstop)
 		return 1;
 
-	for_each_string_list_item(item, &suc->projectlines)
-		fprintf(stdout, "%s", item->string);
+	for (i = 0; i < suc->update_clone_nr; i++) {
+		strbuf_addf(&sb, "dummy %s %d\t%s\n",
+			oid_to_hex(&suc->update_clone[i].oid),
+			suc->update_clone[i].just_cloned,
+			suc->update_clone[i].sub->path);
+		fprintf(stdout, "%s", sb.buf);
+		strbuf_reset(&sb);
+	}
 
+	strbuf_release(&sb);
 	return 0;
 }
 
-- 
2.18.0.132.g195c49a2227
Previous: Stefan BellerNext: Stefan Beller
Message 5 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.