fsmonitor: force a refresh after the index was discarded
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>
Johannes Schindelin committed
May 7, 2019 at 13:10 UTC
398a3b0899dd8a440d4adbcbda38362e3f8359b1
4 files changed
+6
-5
cache.h
+2
-1
@@ -338,7 +338,8 @@ struct index_state {
338
struct cache_time timestamp;
339
unsigned name_hash_initialized : 1,
340
initialized : 1,
341
- drop_cache_tree : 1;
341
+ drop_cache_tree : 1,
342
+ fsmonitor_has_run_once : 1;
343
struct hashmap name_hash;
344
struct hashmap dir_hash;
345
struct object_id oid;
fsmonitor.c
+2
-3
@@ -129,7 +129,6 @@ static void fsmonitor_refresh_callback(struct index_state *istate, const char *n
129
130
void refresh_fsmonitor(struct index_state *istate)
131
{
132
- static int has_run_once = 0;
132
struct strbuf query_result = STRBUF_INIT;
133
int query_success = 0;
134
size_t bol; /* beginning of line */
@@ -137,9 +136,9 @@ void refresh_fsmonitor(struct index_state *istate)
136
char *buf;
137
int i;
138
140
- if (!core_fsmonitor || has_run_once)
139
+ if (!core_fsmonitor || istate->fsmonitor_has_run_once)
140
return;
142
- has_run_once = 1;
141
+ istate->fsmonitor_has_run_once = 1;
142
143
trace_printf_key(&trace_fsmonitor, "refresh fsmonitor");
144
/*
read-cache.c
+1
@@ -2307,6 +2307,7 @@ int discard_index(struct index_state *istate)
2307
free_name_hash(istate);
2308
cache_tree_free(&(istate->cache_tree));
2309
istate->initialized = 0;
2310
+ istate->fsmonitor_has_run_once = 0;
2311
FREE_AND_NULL(istate->cache);
2312
istate->cache_alloc = 0;
2313
discard_split_index(istate);
t/t7519-status-fsmonitor.sh
+1
-1
@@ -346,7 +346,7 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR'
346
test_cmp before after
347
'
348
349
-test_expect_failure 'discard_index() also discards fsmonitor info' '
349
+test_expect_success 'discard_index() also discards fsmonitor info' '
350
test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" &&
351
test_might_fail git update-index --refresh &&
352
test-tool read-cache --print-and-refresh=tracked 2 >actual &&