submodule-config: add helper function to get 'fetch' config from .gitmodules

Add a helper function to make it clearer that retrieving 'fetch' configuration from the .gitmodules file is a special case supported solely for backward compatibility purposes. This change removes one direct use of 'config_from_gitmodules' in code not strictly related to submodules, in the effort to communicate better that .gitmodules is not to be used as a mechanism to store arbitrary configuration in the repository that any command can retrieve. Signed-off-by: Antonio Ospite <ao2@ao2.it> Acked-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Antonio Ospite committed Jun 26, 2018 at 12:47 UTC 71a6953d164012647fcb9682e4e705ba61b95929
3 files changed +31 -14
builtin/fetch.c
+1 -14
@@ -93,19 +93,6 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
93 return git_default_config(k, v, cb);
94 }
95
96 -static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
97 -{
98 - if (!strcmp(var, "submodule.fetchjobs")) {
99 - max_children = parse_submodule_fetchjobs(var, value);
100 - return 0;
101 - } else if (!strcmp(var, "fetch.recursesubmodules")) {
102 - recurse_submodules = parse_fetch_recurse_submodules_arg(var, value);
103 - return 0;
104 - }
105 -
106 - return 0;
107 -}
108 -
96 static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
97 {
98 /*
@@ -1433,7 +1420,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
1420 for (i = 1; i < argc; i++)
1421 strbuf_addf(&default_rla, " %s", argv[i]);
1422
1436 - config_from_gitmodules(gitmodules_fetch_config, NULL);
1423 + fetch_config_from_gitmodules(&max_children, &recurse_submodules);
1424 git_config(git_fetch_config, NULL);
1425
1426 argc = parse_options(argc, argv, prefix,
submodule-config.c
+28
@@ -688,3 +688,31 @@ void config_from_gitmodules(config_fn_t fn, void *data)
688 free(file);
689 }
690 }
691 +
692 +struct fetch_config {
693 + int *max_children;
694 + int *recurse_submodules;
695 +};
696 +
697 +static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
698 +{
699 + struct fetch_config *config = cb;
700 + if (!strcmp(var, "submodule.fetchjobs")) {
701 + *(config->max_children) = parse_submodule_fetchjobs(var, value);
702 + return 0;
703 + } else if (!strcmp(var, "fetch.recursesubmodules")) {
704 + *(config->recurse_submodules) = parse_fetch_recurse_submodules_arg(var, value);
705 + return 0;
706 + }
707 +
708 + return 0;
709 +}
710 +
711 +void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules)
712 +{
713 + struct fetch_config config = {
714 + .max_children = max_children,
715 + .recurse_submodules = recurse_submodules
716 + };
717 + config_from_gitmodules(gitmodules_fetch_config, &config);
718 +}
submodule-config.h
+2
@@ -66,4 +66,6 @@ int check_submodule_name(const char *name);
66 */
67 extern void config_from_gitmodules(config_fn_t fn, void *data);
68
69 +extern void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules);
70 +
71 #endif /* SUBMODULE_CONFIG_H */