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

[PATCHv5 3/8] submodule--helper module-clone: allow multiple references

From
Stefan Beller <sbeller@google.com>
Date
Aug 15, 2016, 21:53 UTC
Message-ID
<20160815215327.15682-4-sbeller@google.com>
In-Reply-To
<20160815215327.15682-1-sbeller@google.com>

Allow users to pass in multiple references, just as clone accepts multiple references as well.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/submodule--helper.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 6f6d67a..ce9b3e9 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -442,7 +442,7 @@ static int module_name(int argc, const char **argv, const char *prefix)
 }
 
 static int clone_submodule(const char *path, const char *gitdir, const char *url,
-			   const char *depth, const char *reference, int quiet)
+			   const char *depth, struct string_list *reference, int quiet)
 {
 	struct child_process cp;
 	child_process_init(&cp);
@@ -453,8 +453,12 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
 		argv_array_push(&cp.args, "--quiet");
 	if (depth && *depth)
 		argv_array_pushl(&cp.args, "--depth", depth, NULL);
-	if (reference && *reference)
-		argv_array_pushl(&cp.args, "--reference", reference, NULL);
+	if (reference->nr) {
+		struct string_list_item *item;
+		for_each_string_list_item(item, reference)
+			argv_array_pushl(&cp.args, "--reference",
+					 item->string, NULL);
+	}
 	if (gitdir && *gitdir)
 		argv_array_pushl(&cp.args, "--separate-git-dir", gitdir, NULL);
 
@@ -470,13 +474,13 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
 
 static int module_clone(int argc, const char **argv, const char *prefix)
 {
-	const char *name = NULL, *url = NULL;
-	const char *reference = NULL, *depth = NULL;
+	const char *name = NULL, *url = NULL, *depth = NULL;
 	int quiet = 0;
 	FILE *submodule_dot_git;
 	char *p, *path = NULL, *sm_gitdir;
 	struct strbuf rel_path = STRBUF_INIT;
 	struct strbuf sb = STRBUF_INIT;
+	struct string_list reference = STRING_LIST_INIT_NODUP;
 
 	struct option module_clone_options[] = {
 		OPT_STRING(0, "prefix", &prefix,
@@ -491,8 +495,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 		OPT_STRING(0, "url", &url,
 			   N_("string"),
 			   N_("url where to clone the submodule from")),
-		OPT_STRING(0, "reference", &reference,
-			   N_("string"),
+		OPT_STRING_LIST(0, "reference", &reference,
+			   N_("repo"),
 			   N_("reference repository")),
 		OPT_STRING(0, "depth", &depth,
 			   N_("string"),
@@ -528,7 +532,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 	if (!file_exists(sm_gitdir)) {
 		if (safe_create_leading_directories_const(sm_gitdir) < 0)
 			die(_("could not create directory '%s'"), sm_gitdir);
-		if (clone_submodule(path, sm_gitdir, url, depth, reference, quiet))
+		if (clone_submodule(path, sm_gitdir, url, depth, &reference, quiet))
 			die(_("clone of '%s' into submodule path '%s' failed"),
 			    url, path);
 	} else {
-- 
2.9.2.730.g525ad04.dirty
Previous: Jacob KellerNext: Jacob Keller
Message 12 of 24 in “[PATCHv5 0/8] git clone: Marry --recursive and --reference”
  1. Stefan BellerAug 15, 2016
  2. 1/8 t7408: modernize styleStefan Beller, Aug 15, 2016
  3. Jacob KellerAug 23, 2016
  4. 2/8 t7408: merge short tests, factor out testing methodStefan Beller, Aug 15, 2016
  5. Jacob KellerAug 23, 2016
  6. 4/8 submodule--helper update-clone: allow multiple referencesStefan Beller, Aug 15, 2016
  7. Jacob KellerAug 23, 2016
  8. 5/8 clone: factor out checking for an alternate pathStefan Beller, Aug 15, 2016
  9. Jacob KellerAug 23, 2016
  10. 6/8 clone: clarify option_reference as requiredStefan Beller, Aug 15, 2016
  11. Jacob KellerAug 23, 2016
  12. 3/8 submodule--helper module-clone: allow multiple referencesStefan Beller, Aug 15, 2016
  13. Jacob KellerAug 23, 2016
  14. 7/8 clone: implement optional referencesStefan Beller, Aug 15, 2016
  15. Jacob KellerAug 23, 2016
  16. 8/8 clone: recursive and reference option triggers submodule alternatesStefan Beller, Aug 15, 2016
  17. Jacob KellerAug 23, 2016
  18. Stefan BellerAug 23, 2016
  19. Jacob KellerAug 24, 2016
  20. Stefan BellerAug 24, 2016
  21. Jacob KellerAug 24, 2016
  22. Stefan BellerAug 31, 2016
  23. Jacob KellerAug 31, 2016
  24. Junio C HamanoAug 15, 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.