Skip to content

Commit a028a19

Browse files
stefanbellergitster
authored andcommitted
fetching submodules: respect submodule.fetchJobs config option
This allows to configure fetching and updating in parallel without having the command line option. This moved the responsibility to determine how many parallel processes to start from builtin/fetch to submodule.c as we need a way to communicate "The user did not specify the number of parallel processes in the command line options" in the builtin fetch. The submodule code takes care of the precedence (CLI > config > default). Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f73da11 commit a028a19

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,6 +2646,12 @@ submodule.<name>.ignore::
26462646
"--ignore-submodules" option. The 'git submodule' commands are not
26472647
affected by this setting.
26482648

2649+
submodule.fetchJobs::
2650+
Specifies how many submodules are fetched/cloned at the same time.
2651+
A positive integer allows up to that number of submodules fetched
2652+
in parallel. A value of 0 will give some reasonable default.
2653+
If unset, it defaults to 1.
2654+
26492655
tag.sort::
26502656
This variable controls the sort ordering of tags when displayed by
26512657
linkgit:git-tag[1]. Without the "--sort=<value>" option provided, the

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static int prune = -1; /* unspecified */
3737
static int all, append, dry_run, force, keep, multiple, update_head_ok, verbosity;
3838
static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
3939
static int tags = TAGS_DEFAULT, unshallow, update_shallow;
40-
static int max_children = 1;
40+
static int max_children = -1;
4141
static const char *depth;
4242
static const char *upload_pack;
4343
static struct strbuf default_rla = STRBUF_INIT;

submodule.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "thread-utils.h"
1616

1717
static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
18+
static int parallel_jobs = 1;
1819
static struct string_list changed_submodule_paths;
1920
static int initialized_fetch_ref_tips;
2021
static struct sha1_array ref_tips_before_fetch;
@@ -169,7 +170,12 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
169170

170171
int submodule_config(const char *var, const char *value, void *cb)
171172
{
172-
if (starts_with(var, "submodule."))
173+
if (!strcmp(var, "submodule.fetchjobs")) {
174+
parallel_jobs = git_config_int(var, value);
175+
if (parallel_jobs < 0)
176+
die(_("negative values not allowed for submodule.fetchJobs"));
177+
return 0;
178+
} else if (starts_with(var, "submodule."))
173179
return parse_submodule_config_option(var, value);
174180
else if (!strcmp(var, "fetch.recursesubmodules")) {
175181
config_fetch_recurse_submodules = parse_fetch_recurse_submodules_arg(var, value);
@@ -771,6 +777,9 @@ int fetch_populated_submodules(const struct argv_array *options,
771777
argv_array_push(&spf.args, "--recurse-submodules-default");
772778
/* default value, "--submodule-prefix" and its value are added later */
773779

780+
if (max_parallel_jobs < 0)
781+
max_parallel_jobs = parallel_jobs;
782+
774783
calculate_changed_submodule_paths();
775784
run_processes_parallel(max_parallel_jobs,
776785
get_next_submodule,
@@ -1117,3 +1126,8 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
11171126
strbuf_release(&rel_path);
11181127
free((void *)real_work_tree);
11191128
}
1129+
1130+
int parallel_submodules(void)
1131+
{
1132+
return parallel_jobs;
1133+
}

submodule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct submodule_update_strategy {
2626
enum submodule_update_type type;
2727
const char *command;
2828
};
29+
#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}
2930

3031
int is_staging_gitmodules_ok(void);
3132
int update_path_in_gitmodules(const char *oldpath, const char *newpath);
@@ -57,5 +58,6 @@ int find_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_nam
5758
struct string_list *needs_pushing);
5859
int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name);
5960
void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
61+
int parallel_submodules(void);
6062

6163
#endif

t/t5526-fetch-submodules.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,4 +471,18 @@ test_expect_success "don't fetch submodule when newly recorded commits are alrea
471471
test_i18ncmp expect.err actual.err
472472
'
473473

474+
test_expect_success 'fetching submodules respects parallel settings' '
475+
git config fetch.recurseSubmodules true &&
476+
(
477+
cd downstream &&
478+
GIT_TRACE=$(pwd)/trace.out git fetch --jobs 7 &&
479+
grep "7 tasks" trace.out &&
480+
git config submodule.fetchJobs 8 &&
481+
GIT_TRACE=$(pwd)/trace.out git fetch &&
482+
grep "8 tasks" trace.out &&
483+
GIT_TRACE=$(pwd)/trace.out git fetch --jobs 9 &&
484+
grep "9 tasks" trace.out
485+
)
486+
'
487+
474488
test_done

0 commit comments

Comments
 (0)