Each submodule that is attempted to be cloned, will be retried once in case of failure after all other submodules were cloned. This helps to mitigate ephemeral server failures and increases chances of a reliable clone of a repo with hundreds of submodules immensely. The choice of the priority queue is a bit miss-leading as we use it as a standard queue, but the priority queue offers the best API to use. Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx> --- builtin/submodule--helper.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index c7deb55..efb6759 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -12,6 +12,7 @@ #include "remote.h" #include "refs.h" #include "connect.h" +#include "prio-queue.h" static char *get_default_remote(void) { @@ -568,6 +569,12 @@ static int module_clone(int argc, const char **argv, const char *prefix) return 0; } +static int compare_ce(const void *one, const void *two, void *cb_data) +{ + const struct cache_entry *ce_one = one, *ce_two = two; + return ce_two - ce_one; +} + struct submodule_update_clone { /* index into 'list', the list of submodules to look into for cloning */ int current; @@ -590,10 +597,13 @@ struct submodule_update_clone { /* If we want to stop as fast as possible and return an error */ unsigned quickstop : 1; + + /* Queue of failed clones, containing the cache_entry */ + struct prio_queue failed_queue; }; #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \ SUBMODULE_UPDATE_STRATEGY_INIT, 0, -1, NULL, NULL, NULL, NULL, \ - STRING_LIST_INIT_DUP, 0} + STRING_LIST_INIT_DUP, 0, { compare_ce }} static void next_submodule_warn_missing(struct submodule_update_clone *suc, @@ -718,23 +728,36 @@ cleanup: static int update_clone_get_next_task(struct child_process *child, struct strbuf *err, void *suc_cb, - void **void_task_cb) + void **ce_task_cb) { struct submodule_update_clone *suc = suc_cb; + const struct cache_entry *ce; for (; suc->current < suc->list.nr; suc->current++) { - const struct cache_entry *ce = suc->list.entries[suc->current]; + ce = suc->list.entries[suc->current]; if (prepare_to_clone_next_submodule(ce, child, suc, err)) { + *ce_task_cb = (struct cache_entry *) ce; suc->current++; return 1; } } + /* + * The loop above tried cloning each submodule once, + * now try the stragglers again. + */ + ce = (struct cache_entry *) prio_queue_get(&suc->failed_queue); + if (ce) { + if (!prepare_to_clone_next_submodule(ce, child, suc, err)) + die("BUG: ce was a submodule before?"); + return 1; + } + return 0; } static int update_clone_start_failure(struct strbuf *err, void *suc_cb, - void *void_task_cb) + void *ce_task_cb) { struct submodule_update_clone *suc = suc_cb; suc->quickstop = 1; @@ -744,15 +767,18 @@ static int update_clone_start_failure(struct strbuf *err, static int update_clone_task_finished(int result, struct strbuf *err, void *suc_cb, - void *void_task_cb) + void *ce_task_cb) { struct submodule_update_clone *suc = suc_cb; + struct cache_entry *ce = ce_task_cb; if (!result) return 0; - suc->quickstop = 1; - return 1; + strbuf_addf(err, _("Failed to clone '%s'. Scheduled for retry"), + ce->name); + prio_queue_put(&suc->failed_queue, ce); + return 0; } static int update_clone(int argc, const char **argv, const char *prefix) -- 2.9.0.rc2.368.gdadd65c -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html