]> git.ipfire.org Git - thirdparty/git.git/blobdiff - read-cache.c
Merge branch 'vd/sparse-clean-etc'
[thirdparty/git.git] / read-cache.c
index cbe73f14e5e7efc63b20e80a2702fb5c0dea9a5d..79b9b99ebf7d65b6663014deaadea12a039db29d 100644 (file)
@@ -28,6 +28,7 @@
 #include "sparse-index.h"
 #include "csum-file.h"
 #include "promisor-remote.h"
+#include "hook.h"
 
 /* Mask for the name length in ce_flags in the on-disk index */
 
@@ -1339,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.
@@ -1352,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)
@@ -2775,7 +2780,7 @@ static int repo_verify_index(struct repository *repo)
        return verify_index_from(repo->index, repo->index_file);
 }
 
-static int has_racy_timestamp(struct index_state *istate)
+int has_racy_timestamp(struct index_state *istate)
 {
        int entries = istate->cache_nr;
        int i;
@@ -3009,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;
@@ -3150,7 +3158,7 @@ static int do_write_locked_index(struct index_state *istate, struct lock_file *l
        else
                ret = close_lock_file_gently(lock);
 
-       run_hook_le(NULL, "post-index-change",
+       run_hooks_l("post-index-change",
                        istate->updated_workdir ? "1" : "0",
                        istate->updated_skipworktree ? "1" : "0", NULL);
        istate->updated_workdir = 0;