]> git.ipfire.org Git - thirdparty/git.git/commitdiff
unpack-trees: ensure full index
authorDerrick Stolee <dstolee@microsoft.com>
Tue, 30 Mar 2021 13:10:52 +0000 (13:10 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 Mar 2021 19:57:46 +0000 (12:57 -0700)
The next change will translate full indexes into sparse indexes at write
time. The existing logic provides a way for every sparse index to be
expanded to a full index at read time. However, there are cases where an
index is written and then continues to be used in-memory to perform
further updates.

unpack_trees() is frequently called after such a write. In particular,
commands like 'git reset' do this double-update of the index.

Ensure that we have a full index when entering unpack_trees(), but only
when command_requires_full_index is true. This is always true at the
moment, but we will later relax that after unpack_trees() is updated to
handle sparse directory entries.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
unpack-trees.c

index f5f668f532d8d574735da064f4dfb5feb8c0cd95..4dd99219073a4f664a1ebb2c310932db0bad3d9b 100644 (file)
@@ -1567,6 +1567,7 @@ static int verify_absent(const struct cache_entry *,
  */
 int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options *o)
 {
+       struct repository *repo = the_repository;
        int i, ret;
        static struct cache_entry *dfc;
        struct pattern_list pl;
@@ -1578,6 +1579,12 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
        trace_performance_enter();
        trace2_region_enter("unpack_trees", "unpack_trees", the_repository);
 
+       prepare_repo_settings(repo);
+       if (repo->settings.command_requires_full_index) {
+               ensure_full_index(o->src_index);
+               ensure_full_index(o->dst_index);
+       }
+
        if (!core_apply_sparse_checkout || !o->update)
                o->skip_sparse_checkout = 1;
        if (!o->skip_sparse_checkout && !o->pl) {