]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sequencer: ensure full index if not ORT strategy
authorDerrick Stolee <dstolee@microsoft.com>
Wed, 8 Sep 2021 11:24:00 +0000 (11:24 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Sep 2021 22:49:05 +0000 (15:49 -0700)
The sequencer is used by 'cherry-pick' and 'rebase' to sequence a list
of operations that modify the index. Since we intend to remove the need
for 'command_requires_full_index', we need to ensure the sparse index is
expanded every time it is written to disk between these steps. That is,
unless the merge strategy is 'ort' where the index can remain sparse
throughout.

There are two main places to be extra careful about a full index:

1. Right before calling merge_trees(), ensure the index is full. This
   happens within an 'else' where the 'if' block checks if the 'ort'
   strategy is selected.

2. During read_and_refresh_cache(), the index might be written to disk
   and converted to sparse in the process. Ensure it expands back to
   full afterwards by checking if the strategy is _not_ 'ort'. This
   'if' statement is the logical negation of the 'if' in item (1).

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c

index 7f07cd00f3f20ab3dc0c508653ac28bdd8e8b8c1..228bc089d226a0a1c3acb0419317204cfca6bb92 100644 (file)
@@ -652,6 +652,7 @@ static int do_recursive_merge(struct repository *r,
                merge_switch_to_result(&o, head_tree, &result, 1, show_output);
                clean = result.clean;
        } else {
+               ensure_full_index(r->index);
                clean = merge_trees(&o, head_tree, next_tree, base_tree);
                if (is_rebase_i(opts) && clean <= 0)
                        fputs(o.obuf.buf, stdout);
@@ -2346,6 +2347,7 @@ static int read_and_refresh_cache(struct repository *r,
                        _(action_name(opts)));
        }
        refresh_index(r->index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);
+
        if (index_fd >= 0) {
                if (write_locked_index(r->index, &index_lock,
                                       COMMIT_LOCK | SKIP_IF_UNCHANGED)) {
@@ -2353,6 +2355,13 @@ static int read_and_refresh_cache(struct repository *r,
                                _(action_name(opts)));
                }
        }
+
+       /*
+        * If we are resolving merges in any way other than "ort", then
+        * expand the sparse index.
+        */
+       if (opts->strategy && strcmp(opts->strategy, "ort"))
+               ensure_full_index(r->index);
        return 0;
 }