Skip to content

Commit 72290d6

Browse files
stefanbellergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2335b87 commit 72290d6

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

Documentation/git-clone.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ SYNOPSIS
1414
[-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
1515
[--dissociate] [--separate-git-dir <git dir>]
1616
[--depth <depth>] [--[no-]single-branch]
17-
[--recursive | --recurse-submodules] [--] <repository>
17+
[--recursive | --recurse-submodules] [--jobs <n>] [--] <repository>
1818
[<directory>]
1919

2020
DESCRIPTION
@@ -221,6 +221,10 @@ objects from the source repository into a pack in the cloned repository.
221221
The result is Git repository can be separated from working
222222
tree.
223223

224+
-j <n>::
225+
--jobs <n>::
226+
The number of submodules fetched at the same time.
227+
Defaults to the `submodule.fetchJobs` option.
224228

225229
<repository>::
226230
The (possibly remote) repository to clone from. See the

builtin/clone.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static int option_progress = -1;
5050
static struct string_list option_config;
5151
static struct string_list option_reference;
5252
static int option_dissociate;
53+
static int max_jobs = -1;
5354

5455
static struct option builtin_clone_options[] = {
5556
OPT__VERBOSITY(&option_verbosity),
@@ -72,6 +73,8 @@ static struct option builtin_clone_options[] = {
7273
N_("initialize submodules in the clone")),
7374
OPT_BOOL(0, "recurse-submodules", &option_recursive,
7475
N_("initialize submodules in the clone")),
76+
OPT_INTEGER('j', "jobs", &max_jobs,
77+
N_("number of submodules cloned in parallel")),
7578
OPT_STRING(0, "template", &option_template, N_("template-directory"),
7679
N_("directory from which templates will be used")),
7780
OPT_STRING_LIST(0, "reference", &option_reference, N_("repo"),
@@ -95,10 +98,6 @@ static struct option builtin_clone_options[] = {
9598
OPT_END()
9699
};
97100

98-
static const char *argv_submodule[] = {
99-
"submodule", "update", "--init", "--recursive", NULL
100-
};
101-
102101
static const char *get_repo_path_1(struct strbuf *path, int *is_bundle)
103102
{
104103
static char *suffix[] = { "/.git", "", ".git/.git", ".git" };
@@ -724,8 +723,16 @@ static int checkout(void)
724723
err |= run_hook_le(NULL, "post-checkout", sha1_to_hex(null_sha1),
725724
sha1_to_hex(sha1), "1", NULL);
726725

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+
}
729736

730737
return err;
731738
}

t/t7406-submodule-update.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,4 +786,19 @@ test_expect_success 'submodule update can be run in parallel' '
786786
grep "9 tasks" trace.out
787787
)
788788
'
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+
789804
test_done

0 commit comments

Comments
 (0)