submodule-config: add helper to get 'update-clone' config from .gitmodules

Add a helper function to make it clearer that retrieving 'update-clone' 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' for options not strictly related to submodules: "submodule.fetchjobs" does not describe a property of a submodule, but a behavior of other commands when dealing with submodules, so it does not really belong to the .gitmodules file. This is 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 057449978efe3e803d1d1ec382e1f238a405a833
3 files changed +19 -4
builtin/submodule--helper.c
+4 -4
@@ -1706,8 +1706,8 @@ static int update_clone_task_finished(int result,
1706 return 0;
1707 }
1708
1709 -static int gitmodules_update_clone_config(const char *var, const char *value,
1710 - void *cb)
1709 +static int git_update_clone_config(const char *var, const char *value,
1710 + void *cb)
1711 {
1712 int *max_jobs = cb;
1713 if (!strcmp(var, "submodule.fetchjobs"))
@@ -1757,8 +1757,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
1757 };
1758 suc.prefix = prefix;
1759
1760 - config_from_gitmodules(gitmodules_update_clone_config, &max_jobs);
1761 - git_config(gitmodules_update_clone_config, &max_jobs);
1760 + update_clone_config_from_gitmodules(&max_jobs);
1761 + git_config(git_update_clone_config, &max_jobs);
1762
1763 argc = parse_options(argc, argv, prefix, module_update_clone_options,
1764 git_submodule_helper_usage, 0);
submodule-config.c
+14
@@ -716,3 +716,17 @@ void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules)
716 };
717 config_from_gitmodules(gitmodules_fetch_config, &config);
718 }
719 +
720 +static int gitmodules_update_clone_config(const char *var, const char *value,
721 + void *cb)
722 +{
723 + int *max_jobs = cb;
724 + if (!strcmp(var, "submodule.fetchjobs"))
725 + *max_jobs = parse_submodule_fetchjobs(var, value);
726 + return 0;
727 +}
728 +
729 +void update_clone_config_from_gitmodules(int *max_jobs)
730 +{
731 + config_from_gitmodules(gitmodules_update_clone_config, &max_jobs);
732 +}
submodule-config.h
+1
@@ -67,5 +67,6 @@ int check_submodule_name(const char *name);
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 +extern void update_clone_config_from_gitmodules(int *max_jobs);
71
72 #endif /* SUBMODULE_CONFIG_H */