clone: allow an explicit argument for parallel submodule clones

Just pass it along to "git submodule update", which may pick reasonable defaults if you don't specify an explicit number. Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Feb 29, 2016 at 18:07 UTC 72290d6a1d8cccd22f58c21418c0f75bfcdf574d
3 files changed +33 -7
Documentation/git-clone.txt
+5 -1
@@ -14,7 +14,7 @@ SYNOPSIS
14 [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
15 [--dissociate] [--separate-git-dir <git dir>]
16 [--depth <depth>] [--[no-]single-branch]
17 - [--recursive | --recurse-submodules] [--] <repository>
17 + [--recursive | --recurse-submodules] [--jobs <n>] [--] <repository>
18 [<directory>]
19
20 DESCRIPTION
@@ -221,6 +221,10 @@ objects from the source repository into a pack in the cloned repository.
221 The result is Git repository can be separated from working
222 tree.
223
224 +-j <n>::
225 +--jobs <n>::
226 + The number of submodules fetched at the same time.
227 + Defaults to the `submodule.fetchJobs` option.
228
229 <repository>::
230 The (possibly remote) repository to clone from. See the
builtin/clone.c
+13 -6
@@ -50,6 +50,7 @@ static int option_progress = -1;
50 static struct string_list option_config;
51 static struct string_list option_reference;
52 static int option_dissociate;
53 +static int max_jobs = -1;
54
55 static struct option builtin_clone_options[] = {
56 OPT__VERBOSITY(&option_verbosity),
@@ -72,6 +73,8 @@ static struct option builtin_clone_options[] = {
73 N_("initialize submodules in the clone")),
74 OPT_BOOL(0, "recurse-submodules", &option_recursive,
75 N_("initialize submodules in the clone")),
76 + OPT_INTEGER('j', "jobs", &max_jobs,
77 + N_("number of submodules cloned in parallel")),
78 OPT_STRING(0, "template", &option_template, N_("template-directory"),
79 N_("directory from which templates will be used")),
80 OPT_STRING_LIST(0, "reference", &option_reference, N_("repo"),
@@ -95,10 +98,6 @@ static struct option builtin_clone_options[] = {
98 OPT_END()
99 };
100
98 -static const char *argv_submodule[] = {
99 - "submodule", "update", "--init", "--recursive", NULL
100 -};
101 -
101 static const char *get_repo_path_1(struct strbuf *path, int *is_bundle)
102 {
103 static char *suffix[] = { "/.git", "", ".git/.git", ".git" };
@@ -724,8 +723,16 @@ static int checkout(void)
723 err |= run_hook_le(NULL, "post-checkout", sha1_to_hex(null_sha1),
724 sha1_to_hex(sha1), "1", NULL);
725
727 - if (!err && option_recursive)
728 - err = run_command_v_opt(argv_submodule, RUN_GIT_CMD);
726 + if (!err && option_recursive) {
727 + struct argv_array args = ARGV_ARRAY_INIT;
728 + argv_array_pushl(&args, "submodule", "update", "--init", "--recursive", NULL);
729 +
730 + if (max_jobs != -1)
731 + argv_array_pushf(&args, "--jobs=%d", max_jobs);
732 +
733 + err = run_command_v_opt(args.argv, RUN_GIT_CMD);
734 + argv_array_clear(&args);
735 + }
736
737 return err;
738 }
t/t7406-submodule-update.sh
+15
@@ -786,4 +786,19 @@ test_expect_success 'submodule update can be run in parallel' '
786 grep "9 tasks" trace.out
787 )
788 '
789 +
790 +test_expect_success 'git clone passes the parallel jobs config on to submodules' '
791 + test_when_finished "rm -rf super4" &&
792 + GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
793 + grep "7 tasks" trace.out &&
794 + rm -rf super4 &&
795 + git config --global submodule.fetchJobs 8 &&
796 + GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
797 + grep "8 tasks" trace.out &&
798 + rm -rf super4 &&
799 + GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
800 + grep "9 tasks" trace.out &&
801 + rm -rf super4
802 +'
803 +
804 test_done