fetch: avoid reading submodule config until needed
commite5b942136ec1af98551b259997872e9849b2766c
authorJonathan Tan <jonathantanmy@google.com>
Tue, 18 Aug 2020 04:01:33 +0000 (17 21:01 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Aug 2020 20:25:05 +0000 (18 13:25 -0700)
treea39c432749b498140569babbd35b92d9e428938d
parent2b713c272cd8f9dc70ad746e8ba01a93d8baa023
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>
builtin/fetch.c
submodule-config.c