]> git.ipfire.org Git - thirdparty/git.git/blobdiff - read-cache.c
Merge branch 'vd/sparse-clean-etc'
[thirdparty/git.git] / read-cache.c
index eeb1c9e8f75c9dbf5b7a2d999737e3d87fe63f2f..79b9b99ebf7d65b6663014deaadea12a039db29d 100644 (file)
@@ -1340,9 +1340,6 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
        int skip_df_check = option & ADD_CACHE_SKIP_DFCHECK;
        int new_only = option & ADD_CACHE_NEW_ONLY;
 
-       if (!(option & ADD_CACHE_KEEP_CACHE_TREE))
-               cache_tree_invalidate_path(istate, ce->name);
-
        /*
         * If this entry's path sorts after the last entry in the index,
         * we can avoid searching for it.
@@ -1353,6 +1350,13 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
        else
                pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce), EXPAND_SPARSE);
 
+       /*
+        * Cache tree path should be invalidated only after index_name_stage_pos,
+        * in case it expands a sparse index.
+        */
+       if (!(option & ADD_CACHE_KEEP_CACHE_TREE))
+               cache_tree_invalidate_path(istate, ce->name);
+
        /* existing match? Just replace it. */
        if (pos >= 0) {
                if (!new_only)
@@ -3010,6 +3014,9 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
            !is_null_oid(&istate->split_index->base_oid)) {
                struct strbuf sb = STRBUF_INIT;
 
+               if (istate->sparse_index)
+                       die(_("cannot write split index for a sparse index"));
+
                err = write_link_extension(&sb, istate) < 0 ||
                        write_index_ext_header(f, eoie_c, CACHE_EXT_LINK,
                                               sb.len) < 0;