submodule--helper update-clone: allow multiple references

Allow the user to pass in multiple references to update_clone. Currently this is only internal API, but once the shell script is replaced by a C version, this is needed. This fixes an API bug between the shell script and the helper. Currently the helper accepts "--reference" "--reference=foo" as a OPT_STRING whose value happens to be "--reference=foo", and then uses if (suc->reference) argv_array_push(&child->args, suc->reference) where suc->reference _is_ "--reference=foo" when invoking the underlying "git clone", it cancels out. With this change we omit one of the "--reference" arguments when passing references from the shell script to the helper. 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 5f50f33e875cc877747a40a80e8ead73db0ec8c1
2 files changed +10 -6
builtin/submodule--helper.c
+9 -5
@@ -584,7 +584,7 @@ struct submodule_update_clone {
584 /* configuration parameters which are passed on to the children */
585 int quiet;
586 int recommend_shallow;
587 - const char *reference;
587 + struct string_list references;
588 const char *depth;
589 const char *recursive_prefix;
590 const char *prefix;
@@ -600,7 +600,8 @@ struct submodule_update_clone {
600 int failed_clones_nr, failed_clones_alloc;
601 };
602 #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
603 - SUBMODULE_UPDATE_STRATEGY_INIT, 0, -1, NULL, NULL, NULL, NULL, \
603 + SUBMODULE_UPDATE_STRATEGY_INIT, 0, -1, STRING_LIST_INIT_DUP, \
604 + NULL, NULL, NULL, \
605 STRING_LIST_INIT_DUP, 0, NULL, 0, 0}
606
607
@@ -710,8 +711,11 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
711 argv_array_pushl(&child->args, "--path", sub->path, NULL);
712 argv_array_pushl(&child->args, "--name", sub->name, NULL);
713 argv_array_pushl(&child->args, "--url", url, NULL);
713 - if (suc->reference)
714 - argv_array_push(&child->args, suc->reference);
714 + if (suc->references.nr) {
715 + struct string_list_item *item;
716 + for_each_string_list_item(item, &suc->references)
717 + argv_array_pushl(&child->args, "--reference", item->string, NULL);
718 + }
719 if (suc->depth)
720 argv_array_push(&child->args, suc->depth);
721
@@ -830,7 +834,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
834 OPT_STRING(0, "update", &update,
835 N_("string"),
836 N_("rebase, merge, checkout or none")),
833 - OPT_STRING(0, "reference", &suc.reference, N_("repo"),
837 + OPT_STRING_LIST(0, "reference", &suc.references, N_("repo"),
838 N_("reference repository")),
839 OPT_STRING(0, "depth", &suc.depth, "<depth>",
840 N_("Create a shallow clone truncated to the "
git-submodule.sh
+1 -1
@@ -575,7 +575,7 @@ cmd_update()
575 ${wt_prefix:+--prefix "$wt_prefix"} \
576 ${prefix:+--recursive-prefix "$prefix"} \
577 ${update:+--update "$update"} \
578 - ${reference:+--reference "$reference"} \
578 + ${reference:+"$reference"} \
579 ${depth:+--depth "$depth"} \
580 ${recommend_shallow:+"$recommend_shallow"} \
581 ${jobs:+$jobs} \