Skip to content

Commit 62104ba

Browse files
stefanbellergitster
authored andcommitted
submodules: allow parallel fetching, add tests and documentation
This enables the work of the previous patches. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe85ee6 commit 62104ba

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

Documentation/fetch-options.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ ifndef::git-pull[]
100100
reference to a commit that isn't already in the local submodule
101101
clone.
102102

103+
-j::
104+
--jobs=<n>::
105+
Number of parallel children to be used for fetching submodules.
106+
Each will fetch from different submodules, such that fetching many
107+
submodules will be faster. By default submodules will be fetched
108+
one at a time.
109+
103110
--no-recurse-submodules::
104111
Disable recursive fetching of submodules (this has the same effect as
105112
using the '--recurse-submodules=no' option).

builtin/fetch.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +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;
4041
static const char *depth;
4142
static const char *upload_pack;
4243
static struct strbuf default_rla = STRBUF_INIT;
@@ -99,6 +100,8 @@ static struct option builtin_fetch_options[] = {
99100
N_("fetch all tags and associated objects"), TAGS_SET),
100101
OPT_SET_INT('n', NULL, &tags,
101102
N_("do not fetch all tags (--no-tags)"), TAGS_UNSET),
103+
OPT_INTEGER('j', "jobs", &max_children,
104+
N_("number of submodules fetched in parallel")),
102105
OPT_BOOL('p', "prune", &prune,
103106
N_("prune remote-tracking branches no longer on remote")),
104107
{ OPTION_CALLBACK, 0, "recurse-submodules", NULL, N_("on-demand"),
@@ -1213,7 +1216,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
12131216
result = fetch_populated_submodules(&options,
12141217
submodule_prefix,
12151218
recurse_submodules,
1216-
verbosity < 0);
1219+
verbosity < 0,
1220+
max_children);
12171221
argv_array_clear(&options);
12181222
}
12191223

builtin/pull.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static int opt_force;
9595
static char *opt_tags;
9696
static char *opt_prune;
9797
static char *opt_recurse_submodules;
98+
static char *max_children;
9899
static int opt_dry_run;
99100
static char *opt_keep;
100101
static char *opt_depth;
@@ -178,6 +179,9 @@ static struct option pull_options[] = {
178179
N_("on-demand"),
179180
N_("control recursive fetching of submodules"),
180181
PARSE_OPT_OPTARG),
182+
OPT_PASSTHRU('j', "jobs", &max_children, N_("n"),
183+
N_("number of submodules pulled in parallel"),
184+
PARSE_OPT_OPTARG),
181185
OPT_BOOL(0, "dry-run", &opt_dry_run,
182186
N_("dry run")),
183187
OPT_PASSTHRU('k', "keep", &opt_keep, NULL,
@@ -525,6 +529,8 @@ static int run_fetch(const char *repo, const char **refspecs)
525529
argv_array_push(&args, opt_prune);
526530
if (opt_recurse_submodules)
527531
argv_array_push(&args, opt_recurse_submodules);
532+
if (max_children)
533+
argv_array_push(&args, max_children);
528534
if (opt_dry_run)
529535
argv_array_push(&args, "--dry-run");
530536
if (opt_keep)

submodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,10 +729,9 @@ static int fetch_finish(int retvalue, struct child_process *cp,
729729

730730
int fetch_populated_submodules(const struct argv_array *options,
731731
const char *prefix, int command_line_option,
732-
int quiet)
732+
int quiet, int max_parallel_jobs)
733733
{
734734
int i;
735-
int max_parallel_jobs = 1;
736735
struct submodule_parallel_fetch spf = SPF_INIT;
737736

738737
spf.work_tree = get_git_work_tree();

submodule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void set_config_fetch_recurse_submodules(int value);
3131
void check_for_new_submodule_commits(unsigned char new_sha1[20]);
3232
int fetch_populated_submodules(const struct argv_array *options,
3333
const char *prefix, int command_line_option,
34-
int quiet);
34+
int quiet, int max_parallel_jobs);
3535
unsigned is_submodule_modified(const char *path, int ignore_untracked);
3636
int submodule_uses_gitfile(const char *path);
3737
int ok_to_remove_submodule(const char *path);

t/t5526-fetch-submodules.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ test_expect_success "fetch --recurse-submodules recurses into submodules" '
7171
test_i18ncmp expect.err actual.err
7272
'
7373

74+
test_expect_success "fetch --recurse-submodules -j2 has the same output behaviour" '
75+
add_upstream_commit &&
76+
(
77+
cd downstream &&
78+
GIT_TRACE=$(pwd)/../trace.out git fetch --recurse-submodules -j2 2>../actual.err
79+
) &&
80+
test_must_be_empty actual.out &&
81+
test_i18ncmp expect.err actual.err &&
82+
grep "2 tasks" trace.out
83+
'
84+
7485
test_expect_success "fetch alone only fetches superproject" '
7586
add_upstream_commit &&
7687
(
@@ -140,6 +151,15 @@ test_expect_success "--quiet propagates to submodules" '
140151
! test -s actual.err
141152
'
142153

154+
test_expect_success "--quiet propagates to parallel submodules" '
155+
(
156+
cd downstream &&
157+
git fetch --recurse-submodules -j 2 --quiet >../actual.out 2>../actual.err
158+
) &&
159+
! test -s actual.out &&
160+
! test -s actual.err
161+
'
162+
143163
test_expect_success "--dry-run propagates to submodules" '
144164
add_upstream_commit &&
145165
(

0 commit comments

Comments
 (0)