fsmonitor: force a refresh after the index was discarded
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Tue, 7 May 2019 11:10:21 +0000 (13:10 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 8 May 2019 03:03:48 +0000 (12:03 +0900)
With this change, the `index_state` struct becomes the new home for the
flag that says whether the fsmonitor hook has been run, i.e. it is now
per-index.

It also gets re-set when the index is discarded, fixing the bug
demonstrated by the "test_expect_failure" test added in the preceding
commit. In that case fsmonitor-enabled Git would miss updates under
certain circumstances, see that preceding commit for details.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
fsmonitor.c
read-cache.c
t/t7519-status-fsmonitor.sh
diff --git a/cache.h b/cache.h
index 27fe635f622c49e2a21ffcb91d3113d3b3fbad8c..06ca755c9375e2dfaddfa6b5a47a0061917f680e 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -338,7 +338,8 @@ struct index_state {
        struct cache_time timestamp;
        unsigned name_hash_initialized : 1,
                 initialized : 1,
-                drop_cache_tree : 1;
+                drop_cache_tree : 1,
+                fsmonitor_has_run_once : 1;
        struct hashmap name_hash;
        struct hashmap dir_hash;
        struct object_id oid;
index 665bd2d4254b12edf38e94cb0e8b2200ae3bf34a..1dee0aded1c433c7cfb90195328f270559c9b421 100644 (file)
@@ -129,7 +129,6 @@ static void fsmonitor_refresh_callback(struct index_state *istate, const char *n
 
 void refresh_fsmonitor(struct index_state *istate)
 {
-       static int has_run_once = 0;
        struct strbuf query_result = STRBUF_INIT;
        int query_success = 0;
        size_t bol; /* beginning of line */
@@ -137,9 +136,9 @@ void refresh_fsmonitor(struct index_state *istate)
        char *buf;
        int i;
 
-       if (!core_fsmonitor || has_run_once)
+       if (!core_fsmonitor || istate->fsmonitor_has_run_once)
                return;
-       has_run_once = 1;
+       istate->fsmonitor_has_run_once = 1;
 
        trace_printf_key(&trace_fsmonitor, "refresh fsmonitor");
        /*
index 0e0c93edc9be5a7af5de1097eafe9d860e7d183e..b298c7f5351d572a300cf274dffb7ee5b00bc9df 100644 (file)
@@ -2307,6 +2307,7 @@ int discard_index(struct index_state *istate)
        free_name_hash(istate);
        cache_tree_free(&(istate->cache_tree));
        istate->initialized = 0;
+       istate->fsmonitor_has_run_once = 0;
        FREE_AND_NULL(istate->cache);
        istate->cache_alloc = 0;
        discard_split_index(istate);
index afd8fa7532a6e5513666e1fcb0c8f391409c5871..81a375fa0ff9845cb755dd77df9921d2b71c764b 100755 (executable)
@@ -346,7 +346,7 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR'
        test_cmp before after
 '
 
-test_expect_failure 'discard_index() also discards fsmonitor info' '
+test_expect_success 'discard_index() also discards fsmonitor info' '
        test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" &&
        test_might_fail git update-index --refresh &&
        test-tool read-cache --print-and-refresh=tracked 2 >actual &&