Skip to content

Commit 2335b87

Browse files
stefanbellergitster
authored andcommitted
submodule update: expose parallelism to the user
Expose possible parallelism either via the "--jobs" CLI parameter or the "submodule.fetchJobs" setting. By having the variable initialized to -1, we make sure 0 can be passed into the parallel processing machine, which will then pick as many parallel workers as there are CPUs. Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cdc04b6 commit 2335b87

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

Documentation/git-submodule.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ SYNOPSIS
1616
'git submodule' [--quiet] deinit [-f|--force] [--] <path>...
1717
'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]
1818
[-f|--force] [--rebase|--merge] [--reference <repository>]
19-
[--depth <depth>] [--recursive] [--] [<path>...]
19+
[--depth <depth>] [--recursive] [--jobs <n>] [--] [<path>...]
2020
'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
2121
[commit] [--] [<path>...]
2222
'git submodule' [--quiet] foreach [--recursive] <command>
@@ -377,6 +377,11 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.
377377
clone with a history truncated to the specified number of revisions.
378378
See linkgit:git-clone[1]
379379

380+
-j <n>::
381+
--jobs <n>::
382+
This option is only valid for the update command.
383+
Clone new submodules in parallel with as many jobs.
384+
Defaults to the `submodule.fetchJobs` option.
380385

381386
<path>...::
382387
Paths to submodule(s). When specified this will restrict the command

builtin/submodule--helper.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ static int update_clone_task_finished(int result,
430430
static int update_clone(int argc, const char **argv, const char *prefix)
431431
{
432432
const char *update = NULL;
433+
int max_jobs = -1;
433434
struct string_list_item *item;
434435
struct pathspec pathspec;
435436
struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
@@ -450,6 +451,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
450451
OPT_STRING(0, "depth", &suc.depth, "<depth>",
451452
N_("Create a shallow clone truncated to the "
452453
"specified number of revisions")),
454+
OPT_INTEGER('j', "jobs", &max_jobs,
455+
N_("parallel jobs")),
453456
OPT__QUIET(&suc.quiet, N_("don't print cloning progress")),
454457
OPT_END()
455458
};
@@ -477,7 +480,10 @@ static int update_clone(int argc, const char **argv, const char *prefix)
477480
gitmodules_config();
478481
git_config(submodule_config, NULL);
479482

480-
run_processes_parallel(1,
483+
if (max_jobs < 0)
484+
max_jobs = parallel_submodules();
485+
486+
run_processes_parallel(max_jobs,
481487
update_clone_get_next_task,
482488
update_clone_start_failure,
483489
update_clone_task_finished,

git-submodule.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,14 @@ cmd_update()
645645
--depth=*)
646646
depth=$1
647647
;;
648+
-j|--jobs)
649+
case "$2" in '') usage ;; esac
650+
jobs="--jobs=$2"
651+
shift
652+
;;
653+
--jobs=*)
654+
jobs=$1
655+
;;
648656
--)
649657
shift
650658
break
@@ -671,6 +679,7 @@ cmd_update()
671679
${update:+--update "$update"} \
672680
${reference:+--reference "$reference"} \
673681
${depth:+--depth "$depth"} \
682+
${jobs:+$jobs} \
674683
"$@" || echo "#unmatched"
675684
} | {
676685
err=

t/t7406-submodule-update.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,4 +774,16 @@ test_expect_success 'submodule update --recursive drops module name before recur
774774
test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
775775
)
776776
'
777+
778+
test_expect_success 'submodule update can be run in parallel' '
779+
(cd super2 &&
780+
GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
781+
grep "7 tasks" trace.out &&
782+
git config submodule.fetchJobs 8 &&
783+
GIT_TRACE=$(pwd)/trace.out git submodule update &&
784+
grep "8 tasks" trace.out &&
785+
GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
786+
grep "9 tasks" trace.out
787+
)
788+
'
777789
test_done

0 commit comments

Comments
 (0)