]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge: make sparse-aware with ORT
authorDerrick Stolee <dstolee@microsoft.com>
Wed, 8 Sep 2021 11:23:57 +0000 (11:23 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Sep 2021 22:49:04 +0000 (15:49 -0700)
Allow 'git merge' to operate without expanding a sparse index, at least
not immediately. The index still will be expanded in a few cases:

1. If the merge strategy is 'recursive', then we enable
   command_requires_full_index at the start of the merge_recursive()
   method. We expect sparse-index users to also have the 'ort' strategy
   enabled.

2. With the 'ort' strategy, if the merge results in a conflicted file,
   then we expand the index before updating the working tree. The loop
   that iterates over the worktree replaces index entries and tracks
   'origintal_cache_nr' which can become completely wrong if the index
   expands in the middle of the operation. This safety valve is
   important before that loop starts. A later change will focus this
   to only expand if we indeed have a conflict outside of the
   sparse-checkout cone.

3. Other merge strategies are executed as a 'git merge-X' subcommand,
   and those strategies are currently protected with the
   'command_requires_full_index' guard.

Some test updates are required, including a mistaken 'git checkout -b'
that did not specify the base branch, causing merges to be fast-forward
merges.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/merge.c
merge-ort.c
merge-recursive.c
t/t1092-sparse-checkout-compatibility.sh

index 22f23990b37b6af8756daa5bcf7a1a7bbef2049c..926de328fbb909cdf2cef38cf5f48c97aeda593b 100644 (file)
@@ -1276,6 +1276,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage_with_options(builtin_merge_usage, builtin_merge_options);
 
+       prepare_repo_settings(the_repository);
+       the_repository->settings.command_requires_full_index = 0;
+
        /*
         * Check if we are _not_ on a detached HEAD, i.e. if there is a
         * current branch.
index 6eb910d6f0cf829f6dd028d32f89b3aa628ce12e..1531b4c94c247d548800f2757271df21d7140aa2 100644 (file)
@@ -4058,6 +4058,14 @@ static int record_conflicted_index_entries(struct merge_options *opt)
        if (strmap_empty(&opt->priv->conflicted))
                return 0;
 
+       /*
+        * We are in a conflicted state. These conflicts might be inside
+        * sparse-directory entries, so expand the index preemptively.
+        * Also, we set original_cache_nr below, but that might change if
+        * index_name_pos() calls ask for paths within sparse directories.
+        */
+       ensure_full_index(index);
+
        /* If any entries have skip_worktree set, we'll have to check 'em out */
        state.force = 1;
        state.quiet = 1;
index 3355d50e8ad36b8649e26a340c45d456162f03fe..1f563cd6874ccb04d3a8342a099c7ab558661ef4 100644 (file)
@@ -3750,6 +3750,9 @@ int merge_recursive(struct merge_options *opt,
        assert(opt->ancestor == NULL ||
               !strcmp(opt->ancestor, "constructed merge base"));
 
+       prepare_repo_settings(opt->repo);
+       opt->repo->settings.command_requires_full_index = 1;
+
        if (merge_start(opt, repo_get_commit_tree(opt->repo, h1)))
                return -1;
        clean = merge_recursive_internal(opt, h1, h2, merge_bases, result);
index ddc86bb4152361fbda501c24c3be97b47aefdf6d..3b331a6bfe7db45ae6c799d923329ce1bbe883ea 100755 (executable)
@@ -47,7 +47,7 @@ test_expect_success 'setup' '
                git checkout -b base &&
                for dir in folder1 folder2 deep
                do
-                       git checkout -b update-$dir &&
+                       git checkout -b update-$dir base &&
                        echo "updated $dir" >$dir/a &&
                        git commit -a -m "update $dir" || return 1
                done &&
@@ -647,7 +647,15 @@ test_expect_success 'sparse-index is not expanded' '
        echo >>sparse-index/extra.txt &&
        ensure_not_expanded add extra.txt &&
        echo >>sparse-index/untracked.txt &&
-       ensure_not_expanded add .
+       ensure_not_expanded add . &&
+
+       ensure_not_expanded checkout -f update-deep &&
+       test_config -C sparse-index pull.twohead ort &&
+       (
+               sane_unset GIT_TEST_MERGE_ALGORITHM &&
+               ensure_not_expanded merge -m merge update-folder1 &&
+               ensure_not_expanded merge -m merge update-folder2
+       )
 '
 
 # NEEDSWORK: a sparse-checkout behaves differently from a full checkout