Skip to content

Commit d99f80d

Browse files
stefanbellergitster
authored andcommitted
builtin/submodule--helper: factor out submodule updating
Separate the command line parsing from the actual execution of the command within the repository. For now there is not a lot of execution as most of it is still in git-submodule.sh. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 96c3429 commit d99f80d

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

builtin/submodule--helper.c

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,8 @@ struct submodule_update_clone {
14721472
/* failed clones to be retried again */
14731473
const struct cache_entry **failed_clones;
14741474
int failed_clones_nr, failed_clones_alloc;
1475+
1476+
int max_jobs;
14751477
};
14761478
#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
14771479
SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
@@ -1714,11 +1716,36 @@ static int gitmodules_update_clone_config(const char *var, const char *value,
17141716
return 0;
17151717
}
17161718

1719+
static int update_submodules(struct submodule_update_clone *suc)
1720+
{
1721+
struct string_list_item *item;
1722+
1723+
run_processes_parallel(suc->max_jobs,
1724+
update_clone_get_next_task,
1725+
update_clone_start_failure,
1726+
update_clone_task_finished,
1727+
suc);
1728+
1729+
/*
1730+
* We saved the output and put it out all at once now.
1731+
* That means:
1732+
* - the listener does not have to interleave their (checkout)
1733+
* work with our fetching. The writes involved in a
1734+
* checkout involve more straightforward sequential I/O.
1735+
* - the listener can avoid doing any work if fetching failed.
1736+
*/
1737+
if (suc->quickstop)
1738+
return 1;
1739+
1740+
for_each_string_list_item(item, &suc->projectlines)
1741+
fprintf(stdout, "%s", item->string);
1742+
1743+
return 0;
1744+
}
1745+
17171746
static int update_clone(int argc, const char **argv, const char *prefix)
17181747
{
17191748
const char *update = NULL;
1720-
int max_jobs = 1;
1721-
struct string_list_item *item;
17221749
struct pathspec pathspec;
17231750
struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
17241751

@@ -1740,7 +1767,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
17401767
OPT_STRING(0, "depth", &suc.depth, "<depth>",
17411768
N_("Create a shallow clone truncated to the "
17421769
"specified number of revisions")),
1743-
OPT_INTEGER('j', "jobs", &max_jobs,
1770+
OPT_INTEGER('j', "jobs", &suc.max_jobs,
17441771
N_("parallel jobs")),
17451772
OPT_BOOL(0, "recommend-shallow", &suc.recommend_shallow,
17461773
N_("whether the initial clone should follow the shallow recommendation")),
@@ -1756,8 +1783,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
17561783
};
17571784
suc.prefix = prefix;
17581785

1759-
config_from_gitmodules(gitmodules_update_clone_config, &max_jobs);
1760-
git_config(gitmodules_update_clone_config, &max_jobs);
1786+
config_from_gitmodules(gitmodules_update_clone_config, &suc.max_jobs);
1787+
git_config(gitmodules_update_clone_config, &suc.max_jobs);
17611788

17621789
argc = parse_options(argc, argv, prefix, module_update_clone_options,
17631790
git_submodule_helper_usage, 0);
@@ -1772,27 +1799,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
17721799
if (pathspec.nr)
17731800
suc.warn_if_uninitialized = 1;
17741801

1775-
run_processes_parallel(max_jobs,
1776-
update_clone_get_next_task,
1777-
update_clone_start_failure,
1778-
update_clone_task_finished,
1779-
&suc);
1780-
1781-
/*
1782-
* We saved the output and put it out all at once now.
1783-
* That means:
1784-
* - the listener does not have to interleave their (checkout)
1785-
* work with our fetching. The writes involved in a
1786-
* checkout involve more straightforward sequential I/O.
1787-
* - the listener can avoid doing any work if fetching failed.
1788-
*/
1789-
if (suc.quickstop)
1790-
return 1;
1791-
1792-
for_each_string_list_item(item, &suc.projectlines)
1793-
fprintf(stdout, "%s", item->string);
1794-
1795-
return 0;
1802+
return update_submodules(&suc);
17961803
}
17971804

17981805
static int resolve_relative_path(int argc, const char **argv, const char *prefix)

0 commit comments

Comments
 (0)