fetch/pull: use the sparse index

The 'git fetch' and 'git pull' commands parse the index in order to determine if submodules exist. Without command_requires_full_index=0, this will expand a sparse index, causing slow performance even when there is no new data to fetch. The .gitmodules file will never be inside a sparse directory entry, and even if it was, the index_name_pos() method would expand the sparse index if needed as we search for the path by name. These commands do not iterate over the index, which is the typical thing we are careful about when integrating with the sparse index. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Dec 22, 2021 at 14:20 UTC 5a4e0547e2386f9bf0565316d7b751fe9459898b
3 files changed +14
builtin/fetch.c
+2
@@ -1999,6 +1999,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
1999 }
2000
2001 git_config(git_fetch_config, NULL);
2002 + prepare_repo_settings(the_repository);
2003 + the_repository->settings.command_requires_full_index = 0;
2004
2005 argc = parse_options(argc, argv, prefix,
2006 builtin_fetch_options, builtin_fetch_usage, 0);
builtin/pull.c
+2
@@ -994,6 +994,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
994 set_reflog_message(argc, argv);
995
996 git_config(git_pull_config, NULL);
997 + prepare_repo_settings(the_repository);
998 + the_repository->settings.command_requires_full_index = 0;
999
1000 argc = parse_options(argc, argv, prefix, pull_options, pull_usage, 0);
1001
t/t1092-sparse-checkout-compatibility.sh
+10
@@ -1009,6 +1009,16 @@ test_expect_success 'sparse index is not expanded: blame' '
1009 done
1010 '
1011
1012 +test_expect_success 'sparse index is not expanded: fetch/pull' '
1013 + init_repos &&
1014 +
1015 + git -C sparse-index remote add full "file://$(pwd)/full-checkout" &&
1016 + ensure_not_expanded fetch full &&
1017 + git -C full-checkout commit --allow-empty -m "for pull merge" &&
1018 + git -C sparse-index commit --allow-empty -m "for pull merge" &&
1019 + ensure_not_expanded pull full base
1020 +'
1021 +
1022 # NEEDSWORK: a sparse-checkout behaves differently from a full checkout
1023 # in this scenario, but it shouldn't.
1024 test_expect_success 'reset mixed and checkout orphan' '