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 <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Aug 3, 2018 at 15:23 UTC
90efe595c53f4bb1851371344c35eff71f604d2b
1 file changed
+33
-26
builtin/submodule--helper.c
+33
-26
@@ -1474,6 +1474,8 @@ struct submodule_update_clone {
1474
/* failed clones to be retried again */
1475
const struct cache_entry **failed_clones;
1476
int failed_clones_nr, failed_clones_alloc;
1477
+
1478
+ int max_jobs;
1479
};
1480
#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
1481
SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
@@ -1716,11 +1718,36 @@ static int git_update_clone_config(const char *var, const char *value,
1718
return 0;
1719
}
1720
1721
+static int update_submodules(struct submodule_update_clone *suc)
1722
+{
1723
+ struct string_list_item *item;
1724
+
1725
+ run_processes_parallel(suc->max_jobs,
1726
+ update_clone_get_next_task,
1727
+ update_clone_start_failure,
1728
+ update_clone_task_finished,
1729
+ suc);
1730
+
1731
+ /*
1732
+ * We saved the output and put it out all at once now.
1733
+ * That means:
1734
+ * - the listener does not have to interleave their (checkout)
1735
+ * work with our fetching. The writes involved in a
1736
+ * checkout involve more straightforward sequential I/O.
1737
+ * - the listener can avoid doing any work if fetching failed.
1738
+ */
1739
+ if (suc->quickstop)
1740
+ return 1;
1741
+
1742
+ for_each_string_list_item(item, &suc->projectlines)
1743
+ fprintf(stdout, "%s", item->string);
1744
+
1745
+ return 0;
1746
+}
1747
+
1748
static int update_clone(int argc, const char **argv, const char *prefix)
1749
{
1750
const char *update = NULL;
1722
- int max_jobs = 1;
1723
- struct string_list_item *item;
1751
struct pathspec pathspec;
1752
struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
1753
@@ -1742,7 +1769,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
1769
OPT_STRING(0, "depth", &suc.depth, "<depth>",
1770
N_("Create a shallow clone truncated to the "
1771
"specified number of revisions")),
1745
- OPT_INTEGER('j', "jobs", &max_jobs,
1772
+ OPT_INTEGER('j', "jobs", &suc.max_jobs,
1773
N_("parallel jobs")),
1774
OPT_BOOL(0, "recommend-shallow", &suc.recommend_shallow,
1775
N_("whether the initial clone should follow the shallow recommendation")),
@@ -1758,8 +1785,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
1785
};
1786
suc.prefix = prefix;
1787
1761
- update_clone_config_from_gitmodules(&max_jobs);
1762
- git_config(git_update_clone_config, &max_jobs);
1788
+ update_clone_config_from_gitmodules(&suc.max_jobs);
1789
+ git_config(git_update_clone_config, &suc.max_jobs);
1790
1791
argc = parse_options(argc, argv, prefix, module_update_clone_options,
1792
git_submodule_helper_usage, 0);
@@ -1774,27 +1801,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
1801
if (pathspec.nr)
1802
suc.warn_if_uninitialized = 1;
1803
1777
- run_processes_parallel(max_jobs,
1778
- update_clone_get_next_task,
1779
- update_clone_start_failure,
1780
- update_clone_task_finished,
1781
- &suc);
1782
-
1783
- /*
1784
- * We saved the output and put it out all at once now.
1785
- * That means:
1786
- * - the listener does not have to interleave their (checkout)
1787
- * work with our fetching. The writes involved in a
1788
- * checkout involve more straightforward sequential I/O.
1789
- * - the listener can avoid doing any work if fetching failed.
1790
- */
1791
- if (suc.quickstop)
1792
- return 1;
1793
-
1794
- for_each_string_list_item(item, &suc.projectlines)
1795
- fprintf(stdout, "%s", item->string);
1796
-
1797
- return 0;
1804
+ return update_submodules(&suc);
1805
}
1806
1807
static int resolve_relative_path(int argc, const char **argv, const char *prefix)