]> git.ipfire.org Git - thirdparty/git.git/blobdiff - read-cache.c
Merge branch 'vd/sparse-clean-etc'
[thirdparty/git.git] / read-cache.c
index a932e01fc7a8247520646ec6495f5020c17d95fa..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;
@@ -3153,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;