@matheusbsbs / matheus-bagliano / commits / e5b942136e
Fork 0

fetch: avoid reading submodule config until needed

In "fetch", there are two parameters submodule_fetch_jobs_config and recurse_submodules that can be set in a variety of ways: through .gitmodules, through .git/config, and through the command line. Currently "fetch" handles this by first reading .gitmodules, then reading .git/config (allowing it to overwrite existing values), then reading the command line (allowing it to overwrite existing values). Notice that we can avoid reading .gitmodules if .git/config and/or the command line already provides us with what we need. In addition, if recurse_submodules is found to be "no", we do not need the value of submodule_fetch_jobs_config. Avoiding reading .gitmodules is especially important when we use "git fetch" to perform lazy fetches in a partial clone because the .gitmodules file itself might need to be lazy fetched (and otherwise causing an infinite loop). In light of all this, avoid reading .gitmodules until necessary. When reading it, we may only need one of the two parameters it provides, so teach fetch_config_from_gitmodules() to support NULL arguments. With this patch, users (including Git itself when invoking "git fetch" to lazy-fetch) will be able to guarantee avoiding reading .gitmodules by passing --recurse-submodules=no. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Aug 17, 2020 at 21:01 UTC e5b942136ec1af98551b259997872e9849b2766c
2 files changed +14 -4
builtin/fetch.c
+8 -2
@@ -1782,12 +1782,18 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
1782 free(anon);
1783 }
1784
1785 - fetch_config_from_gitmodules(&submodule_fetch_jobs_config,
1786 - &recurse_submodules);
1785 git_config(git_fetch_config, NULL);
1786
1787 argc = parse_options(argc, argv, prefix,
1788 builtin_fetch_options, builtin_fetch_usage, 0);
1789 + if (recurse_submodules != RECURSE_SUBMODULES_OFF) {
1790 + int *sfjc = submodule_fetch_jobs_config == -1
1791 + ? &submodule_fetch_jobs_config : NULL;
1792 + int *rs = recurse_submodules == RECURSE_SUBMODULES_DEFAULT
1793 + ? &recurse_submodules : NULL;
1794 +
1795 + fetch_config_from_gitmodules(sfjc, rs);
1796 + }
1797
1798 if (deepen_relative) {
1799 if (deepen_relative < 0)
submodule-config.c
+6 -2
@@ -777,10 +777,14 @@ static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
777 {
778 struct fetch_config *config = cb;
779 if (!strcmp(var, "submodule.fetchjobs")) {
780 - *(config->max_children) = parse_submodule_fetchjobs(var, value);
780 + if (config->max_children)
781 + *(config->max_children) =
782 + parse_submodule_fetchjobs(var, value);
783 return 0;
784 } else if (!strcmp(var, "fetch.recursesubmodules")) {
783 - *(config->recurse_submodules) = parse_fetch_recurse_submodules_arg(var, value);
785 + if (config->recurse_submodules)
786 + *(config->recurse_submodules) =
787 + parse_fetch_recurse_submodules_arg(var, value);
788 return 0;
789 }
790