]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fetch/pull: use the sparse index
authorDerrick Stolee <dstolee@microsoft.com>
Wed, 22 Dec 2021 14:20:52 +0000 (14:20 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 22 Dec 2021 19:42:39 +0000 (11:42 -0800)
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>
builtin/fetch.c
builtin/pull.c
t/t1092-sparse-checkout-compatibility.sh

index e45185cf9cf5ec71fa0a294a5f250c2d79342119..a0757dd0158d11751013e634684b1e36b2d94545 100644 (file)
@@ -1999,6 +1999,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
        }
 
        git_config(git_fetch_config, NULL);
+       prepare_repo_settings(the_repository);
+       the_repository->settings.command_requires_full_index = 0;
 
        argc = parse_options(argc, argv, prefix,
                             builtin_fetch_options, builtin_fetch_usage, 0);
index c8457619d865c57c2a3a228d64acad3a253c181f..100cbf9fb85b59fee6a8f9f90ced02c9abdaac6e 100644 (file)
@@ -994,6 +994,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
                set_reflog_message(argc, argv);
 
        git_config(git_pull_config, NULL);
+       prepare_repo_settings(the_repository);
+       the_repository->settings.command_requires_full_index = 0;
 
        argc = parse_options(argc, argv, prefix, pull_options, pull_usage, 0);
 
index 49f70a656927d0a6893a78ac079a8ac76c53c429..8d3c21fc84ce3d7e23466acda68b8fc75359d236 100755 (executable)
@@ -1009,6 +1009,16 @@ test_expect_success 'sparse index is not expanded: blame' '
        done
 '
 
+test_expect_success 'sparse index is not expanded: fetch/pull' '
+       init_repos &&
+
+       git -C sparse-index remote add full "file://$(pwd)/full-checkout" &&
+       ensure_not_expanded fetch full &&
+       git -C full-checkout commit --allow-empty -m "for pull merge" &&
+       git -C sparse-index commit --allow-empty -m "for pull merge" &&
+       ensure_not_expanded pull full base
+'
+
 # NEEDSWORK: a sparse-checkout behaves differently from a full checkout
 # in this scenario, but it shouldn't.
 test_expect_success 'reset mixed and checkout orphan' '