submodule--helper module-clone: allow multiple references

Allow users to pass in multiple references, just as clone accepts multiple references as well. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Aug 11, 2016 at 16:14 UTC 965dbea09a5a71e78f72f11fd792646a4ce2a17a
1 file changed +12 -8
builtin/submodule--helper.c
+12 -8
@@ -442,7 +442,7 @@ static int module_name(int argc, const char **argv, const char *prefix)
442 }
443
444 static int clone_submodule(const char *path, const char *gitdir, const char *url,
445 - const char *depth, const char *reference, int quiet)
445 + const char *depth, struct string_list *reference, int quiet)
446 {
447 struct child_process cp;
448 child_process_init(&cp);
@@ -453,8 +453,12 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
453 argv_array_push(&cp.args, "--quiet");
454 if (depth && *depth)
455 argv_array_pushl(&cp.args, "--depth", depth, NULL);
456 - if (reference && *reference)
457 - argv_array_pushl(&cp.args, "--reference", reference, NULL);
456 + if (reference->nr) {
457 + struct string_list_item *item;
458 + for_each_string_list_item(item, reference)
459 + argv_array_pushl(&cp.args, "--reference",
460 + item->string, NULL);
461 + }
462 if (gitdir && *gitdir)
463 argv_array_pushl(&cp.args, "--separate-git-dir", gitdir, NULL);
464
@@ -470,13 +474,13 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
474
475 static int module_clone(int argc, const char **argv, const char *prefix)
476 {
473 - const char *name = NULL, *url = NULL;
474 - const char *reference = NULL, *depth = NULL;
477 + const char *name = NULL, *url = NULL, *depth = NULL;
478 int quiet = 0;
479 FILE *submodule_dot_git;
480 char *p, *path = NULL, *sm_gitdir;
481 struct strbuf rel_path = STRBUF_INIT;
482 struct strbuf sb = STRBUF_INIT;
483 + struct string_list reference = STRING_LIST_INIT_NODUP;
484
485 struct option module_clone_options[] = {
486 OPT_STRING(0, "prefix", &prefix,
@@ -491,8 +495,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
495 OPT_STRING(0, "url", &url,
496 N_("string"),
497 N_("url where to clone the submodule from")),
494 - OPT_STRING(0, "reference", &reference,
495 - N_("string"),
498 + OPT_STRING_LIST(0, "reference", &reference,
499 + N_("repo"),
500 N_("reference repository")),
501 OPT_STRING(0, "depth", &depth,
502 N_("string"),
@@ -528,7 +532,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
532 if (!file_exists(sm_gitdir)) {
533 if (safe_create_leading_directories_const(sm_gitdir) < 0)
534 die(_("could not create directory '%s'"), sm_gitdir);
531 - if (clone_submodule(path, sm_gitdir, url, depth, reference, quiet))
535 + if (clone_submodule(path, sm_gitdir, url, depth, &reference, quiet))
536 die(_("clone of '%s' into submodule path '%s' failed"),
537 url, path);
538 } else {