submodule: remove submodule.fetchjobs from submodule-config parsing

The '.gitmodules' file should only contain information pertinent to configuring individual submodules (name to path mapping, URL where to obtain the submodule, etc.) while other configuration like the number of jobs to use when fetching submodules should be a part of the repository's config. Remove the 'submodule.fetchjobs' configuration option from the general submodule-config parsing and instead rely on using the 'config_from_gitmodules()' in order to maintain backwards compatibility with this config being placed in the '.gitmodules' file. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Aug 2, 2017 at 12:49 UTC f20e7c1ea2459d9b8c12f8ed1f1546665841b643
6 files changed +40 -21
builtin/fetch.c
+17 -1
@@ -39,7 +39,7 @@ static int prune = -1; /* unspecified */
39 static int all, append, dry_run, force, keep, multiple, update_head_ok, verbosity, deepen_relative;
40 static int progress = -1;
41 static int tags = TAGS_DEFAULT, unshallow, update_shallow, deepen;
42 -static int max_children = -1;
42 +static int max_children = 1;
43 static enum transport_family family;
44 static const char *depth;
45 static const char *deepen_since;
@@ -68,9 +68,24 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
68 recurse_submodules = r;
69 }
70
71 + if (!strcmp(k, "submodule.fetchjobs")) {
72 + max_children = parse_submodule_fetchjobs(k, v);
73 + return 0;
74 + }
75 +
76 return git_default_config(k, v, cb);
77 }
78
79 +static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
80 +{
81 + if (!strcmp(var, "submodule.fetchjobs")) {
82 + max_children = parse_submodule_fetchjobs(var, value);
83 + return 0;
84 + }
85 +
86 + return 0;
87 +}
88 +
89 static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
90 {
91 ALLOC_GROW(refmap_array, refmap_nr + 1, refmap_alloc);
@@ -1311,6 +1326,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
1326 for (i = 1; i < argc; i++)
1327 strbuf_addf(&default_rla, " %s", argv[i]);
1328
1329 + config_from_gitmodules(gitmodules_fetch_config, NULL);
1330 git_config(git_fetch_config, NULL);
1331
1332 argc = parse_options(argc, argv, prefix,
builtin/submodule--helper.c
+13 -4
@@ -960,10 +960,19 @@ static int update_clone_task_finished(int result,
960 return 0;
961 }
962
963 +static int gitmodules_update_clone_config(const char *var, const char *value,
964 + void *cb)
965 +{
966 + int *max_jobs = cb;
967 + if (!strcmp(var, "submodule.fetchjobs"))
968 + *max_jobs = parse_submodule_fetchjobs(var, value);
969 + return 0;
970 +}
971 +
972 static int update_clone(int argc, const char **argv, const char *prefix)
973 {
974 const char *update = NULL;
966 - int max_jobs = -1;
975 + int max_jobs = 1;
976 struct string_list_item *item;
977 struct pathspec pathspec;
978 struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
@@ -1000,6 +1009,9 @@ static int update_clone(int argc, const char **argv, const char *prefix)
1009 };
1010 suc.prefix = prefix;
1011
1012 + config_from_gitmodules(gitmodules_update_clone_config, &max_jobs);
1013 + git_config(gitmodules_update_clone_config, &max_jobs);
1014 +
1015 argc = parse_options(argc, argv, prefix, module_update_clone_options,
1016 git_submodule_helper_usage, 0);
1017
@@ -1017,9 +1029,6 @@ static int update_clone(int argc, const char **argv, const char *prefix)
1029 gitmodules_config();
1030 git_config(submodule_config, NULL);
1031
1020 - if (max_jobs < 0)
1021 - max_jobs = parallel_submodules();
1022 -
1032 run_processes_parallel(max_jobs,
1033 update_clone_get_next_task,
1034 update_clone_start_failure,
submodule-config.c
+8
@@ -248,6 +248,14 @@ static int parse_fetch_recurse(const char *opt, const char *arg,
248 }
249 }
250
251 +int parse_submodule_fetchjobs(const char *var, const char *value)
252 +{
253 + int fetchjobs = git_config_int(var, value);
254 + if (fetchjobs < 0)
255 + die(_("negative values not allowed for submodule.fetchjobs"));
256 + return fetchjobs;
257 +}
258 +
259 int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg)
260 {
261 return parse_fetch_recurse(opt, arg, 1);
submodule-config.h
+1
@@ -27,6 +27,7 @@ struct repository;
27
28 extern void submodule_cache_free(struct submodule_cache *cache);
29
30 +extern int parse_submodule_fetchjobs(const char *var, const char *value);
31 extern int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg);
32 struct option;
33 extern int option_fetch_parse_recurse_submodules(const struct option *opt,
submodule.c
+1 -15
@@ -22,7 +22,6 @@
22
23 static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
24 static int config_update_recurse_submodules = RECURSE_SUBMODULES_OFF;
25 -static int parallel_jobs = 1;
25 static struct string_list changed_submodule_paths = STRING_LIST_INIT_DUP;
26 static int initialized_fetch_ref_tips;
27 static struct oid_array ref_tips_before_fetch;
@@ -159,12 +158,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
158 /* For loading from the .gitmodules file. */
159 static int git_modules_config(const char *var, const char *value, void *cb)
160 {
162 - if (!strcmp(var, "submodule.fetchjobs")) {
163 - parallel_jobs = git_config_int(var, value);
164 - if (parallel_jobs < 0)
165 - die(_("negative values not allowed for submodule.fetchJobs"));
166 - return 0;
167 - } else if (starts_with(var, "submodule."))
161 + if (starts_with(var, "submodule."))
162 return parse_submodule_config_option(var, value);
163 else if (!strcmp(var, "fetch.recursesubmodules")) {
164 config_fetch_recurse_submodules = parse_fetch_recurse_submodules_arg(var, value);
@@ -1303,9 +1297,6 @@ int fetch_populated_submodules(const struct argv_array *options,
1297 argv_array_push(&spf.args, "--recurse-submodules-default");
1298 /* default value, "--submodule-prefix" and its value are added later */
1299
1306 - if (max_parallel_jobs < 0)
1307 - max_parallel_jobs = parallel_jobs;
1308 -
1300 calculate_changed_submodule_paths();
1301 run_processes_parallel(max_parallel_jobs,
1302 get_next_submodule,
@@ -1825,11 +1816,6 @@ int merge_submodule(struct object_id *result, const char *path,
1816 return 0;
1817 }
1818
1828 -int parallel_submodules(void)
1829 -{
1830 - return parallel_jobs;
1831 -}
1832 -
1819 /*
1820 * Embeds a single submodules git directory into the superprojects git dir,
1821 * non recursively.
submodule.h
-1
@@ -112,7 +112,6 @@ extern int push_unpushed_submodules(struct oid_array *commits,
112 const struct string_list *push_options,
113 int dry_run);
114 extern void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
115 -extern int parallel_submodules(void);
115 /*
116 * Given a submodule path (as in the index), return the repository
117 * path of that submodule in 'buf'. Return -1 on error or when the