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 <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
2335b870fa7942d9ca9e73e96e35171fda741376
4 files changed
+34
-2
Documentation/git-submodule.txt
+6
-1
@@ -16,7 +16,7 @@ SYNOPSIS
16
'git submodule' [--quiet] deinit [-f|--force] [--] <path>...
17
'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]
18
[-f|--force] [--rebase|--merge] [--reference <repository>]
19
- [--depth <depth>] [--recursive] [--] [<path>...]
19
+ [--depth <depth>] [--recursive] [--jobs <n>] [--] [<path>...]
20
'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
21
[commit] [--] [<path>...]
22
'git submodule' [--quiet] foreach [--recursive] <command>
@@ -377,6 +377,11 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.
377
clone with a history truncated to the specified number of revisions.
378
See linkgit:git-clone[1]
379
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.
385
386
<path>...::
387
Paths to submodule(s). When specified this will restrict the command
builtin/submodule--helper.c
+7
-1
@@ -430,6 +430,7 @@ static int update_clone_task_finished(int result,
430
static int update_clone(int argc, const char **argv, const char *prefix)
431
{
432
const char *update = NULL;
433
+ int max_jobs = -1;
434
struct string_list_item *item;
435
struct pathspec pathspec;
436
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)
451
OPT_STRING(0, "depth", &suc.depth, "<depth>",
452
N_("Create a shallow clone truncated to the "
453
"specified number of revisions")),
454
+ OPT_INTEGER('j', "jobs", &max_jobs,
455
+ N_("parallel jobs")),
456
OPT__QUIET(&suc.quiet, N_("don't print cloning progress")),
457
OPT_END()
458
};
@@ -477,7 +480,10 @@ static int update_clone(int argc, const char **argv, const char *prefix)
480
gitmodules_config();
481
git_config(submodule_config, NULL);
482
480
- run_processes_parallel(1,
483
+ if (max_jobs < 0)
484
+ max_jobs = parallel_submodules();
485
+
486
+ run_processes_parallel(max_jobs,
487
update_clone_get_next_task,
488
update_clone_start_failure,
489
update_clone_task_finished,
git-submodule.sh
+9
@@ -645,6 +645,14 @@ cmd_update()
645
--depth=*)
646
depth=$1
647
;;
648
+ -j|--jobs)
649
+ case "$2" in '') usage ;; esac
650
+ jobs="--jobs=$2"
651
+ shift
652
+ ;;
653
+ --jobs=*)
654
+ jobs=$1
655
+ ;;
656
--)
657
shift
658
break
@@ -671,6 +679,7 @@ cmd_update()
679
${update:+--update "$update"} \
680
${reference:+--reference "$reference"} \
681
${depth:+--depth "$depth"} \
682
+ ${jobs:+$jobs} \
683
"$@" || echo "#unmatched"
684
} | {
685
err=
t/t7406-submodule-update.sh
+12
@@ -774,4 +774,16 @@ test_expect_success 'submodule update --recursive drops module name before recur
774
test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
775
)
776
'
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
+'
789
test_done