Merge branch 'js/fsmonitor-refresh-after-discarding-index'
authorJunio C Hamano <gitster@pobox.com>
Sun, 19 May 2019 07:45:33 +0000 (16:45 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sun, 19 May 2019 07:45:33 +0000 (16:45 +0900)
The fsmonitor interface got out of sync after the in-core index
file gets discarded, which has been corrected.

* js/fsmonitor-refresh-after-discarding-index:
fsmonitor: force a refresh after the index was discarded
fsmonitor: demonstrate that it is not refreshed after discard_index()

cache.h
fsmonitor.c
read-cache.c
t/helper/test-read-cache.c
t/t7519-status-fsmonitor.sh
diff --git a/cache.h b/cache.h
index fa8ede9a2d6441842f49740482bb74f6c23c1a5d..b4bb2e2c11adff0061065fa975874c7c4a2a318b 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -341,7 +341,8 @@ struct index_state {
                 initialized : 1,
                 drop_cache_tree : 1,
                 updated_workdir : 1,
-                updated_skipworktree : 1;
+                updated_skipworktree : 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 4fad4e3f9ab004c85c0b2614b4d0637809d7e1b8..22e7b9944e35d257b144fe06dce2073c91d4819f 100644 (file)
@@ -2326,6 +2326,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 d674c88ba092d60366a14eaeccc9f4bc6f32660c..7e79b555de8059fae8f47ae1d2382d14b830a4d1 100644 (file)
@@ -1,14 +1,36 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "config.h"
 
 int cmd__read_cache(int argc, const char **argv)
 {
-       int i, cnt = 1;
+       int i, cnt = 1, namelen;
+       const char *name = NULL;
+
+       if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
+               namelen = strlen(name);
+               argc--;
+               argv++;
+       }
+
        if (argc == 2)
                cnt = strtol(argv[1], NULL, 0);
        setup_git_directory();
+       git_config(git_default_config, NULL);
        for (i = 0; i < cnt; i++) {
                read_cache();
+               if (name) {
+                       int pos;
+
+                       refresh_index(&the_index, REFRESH_QUIET,
+                                     NULL, NULL, NULL);
+                       pos = index_name_pos(&the_index, name, namelen);
+                       if (pos < 0)
+                               die("%s not in index", name);
+                       printf("%s is%s up to date\n", name,
+                              ce_uptodate(the_index.cache[pos]) ? "" : " not");
+                       write_file(name, "%d\n", i);
+               }
                discard_cache();
        }
        return 0;
index 3e0a61db2348577ed5c6cef4f844c2a26548de1d..81a375fa0ff9845cb755dd77df9921d2b71c764b 100755 (executable)
@@ -346,4 +346,12 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR'
        test_cmp before after
 '
 
+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 &&
+       printf "tracked is%s up to date\n" "" " not" >expect &&
+       test_cmp expect actual
+'
+
 test_done