builtin/submodule--helper: factor out submodule updating
[gitweb.git] / builtin / submodule--helper.c
index 216e3daf5c9ea95d174efc89be2f42942d85472e..32f00ca6f87db9a396f3ff084072466c7548487f 100644 (file)
@@ -1474,6 +1474,8 @@ struct submodule_update_clone {
        /* failed clones to be retried again */
        const struct cache_entry **failed_clones;
        int failed_clones_nr, failed_clones_alloc;
+
+       int max_jobs;
 };
 #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
        SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
@@ -1573,9 +1575,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
        needs_cloning = !file_exists(sb.buf);
 
        strbuf_reset(&sb);
-       strbuf_addf(&sb, "%06o %s %d %d\t%s\n", ce->ce_mode,
-                       oid_to_hex(&ce->oid), ce_stage(ce),
-                       needs_cloning, ce->name);
+       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);
 
        if (!needs_cloning)
@@ -1708,8 +1709,8 @@ static int update_clone_task_finished(int result,
        return 0;
 }
 
-static int gitmodules_update_clone_config(const char *var, const char *value,
-                                         void *cb)
+static int git_update_clone_config(const char *var, const char *value,
+                                  void *cb)
 {
        int *max_jobs = cb;
        if (!strcmp(var, "submodule.fetchjobs"))
@@ -1717,11 +1718,36 @@ static int gitmodules_update_clone_config(const char *var, const char *value,
        return 0;
 }
 
+static int update_submodules(struct submodule_update_clone *suc)
+{
+       struct string_list_item *item;
+
+       run_processes_parallel(suc->max_jobs,
+                              update_clone_get_next_task,
+                              update_clone_start_failure,
+                              update_clone_task_finished,
+                              suc);
+
+       /*
+        * We saved the output and put it out all at once now.
+        * That means:
+        * - the listener does not have to interleave their (checkout)
+        *   work with our fetching.  The writes involved in a
+        *   checkout involve more straightforward sequential I/O.
+        * - the listener can avoid doing any work if fetching failed.
+        */
+       if (suc->quickstop)
+               return 1;
+
+       for_each_string_list_item(item, &suc->projectlines)
+               fprintf(stdout, "%s", item->string);
+
+       return 0;
+}
+
 static int update_clone(int argc, const char **argv, const char *prefix)
 {
        const char *update = NULL;
-       int max_jobs = 1;
-       struct string_list_item *item;
        struct pathspec pathspec;
        struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
 
@@ -1743,7 +1769,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
                OPT_STRING(0, "depth", &suc.depth, "<depth>",
                           N_("Create a shallow clone truncated to the "
                              "specified number of revisions")),
-               OPT_INTEGER('j', "jobs", &max_jobs,
+               OPT_INTEGER('j', "jobs", &suc.max_jobs,
                            N_("parallel jobs")),
                OPT_BOOL(0, "recommend-shallow", &suc.recommend_shallow,
                            N_("whether the initial clone should follow the shallow recommendation")),
@@ -1759,8 +1785,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
        };
        suc.prefix = prefix;
 
-       config_from_gitmodules(gitmodules_update_clone_config, &max_jobs);
-       git_config(gitmodules_update_clone_config, &max_jobs);
+       update_clone_config_from_gitmodules(&suc.max_jobs);
+       git_config(git_update_clone_config, &suc.max_jobs);
 
        argc = parse_options(argc, argv, prefix, module_update_clone_options,
                             git_submodule_helper_usage, 0);
@@ -1775,27 +1801,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
        if (pathspec.nr)
                suc.warn_if_uninitialized = 1;
 
-       run_processes_parallel(max_jobs,
-                              update_clone_get_next_task,
-                              update_clone_start_failure,
-                              update_clone_task_finished,
-                              &suc);
-
-       /*
-        * We saved the output and put it out all at once now.
-        * That means:
-        * - the listener does not have to interleave their (checkout)
-        *   work with our fetching.  The writes involved in a
-        *   checkout involve more straightforward sequential I/O.
-        * - the listener can avoid doing any work if fetching failed.
-        */
-       if (suc.quickstop)
-               return 1;
-
-       for_each_string_list_item(item, &suc.projectlines)
-               fprintf(stdout, "%s", item->string);
-
-       return 0;
+       return update_submodules(&suc);
 }
 
 static int resolve_relative_path(int argc, const char **argv, const char *prefix)