Skip to content

Commit 912cfd3

Browse files
committed
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 <[email protected]>
1 parent 328b4a2 commit 912cfd3

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

cache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ struct index_state {
338338
struct cache_time timestamp;
339339
unsigned name_hash_initialized : 1,
340340
initialized : 1,
341-
drop_cache_tree : 1;
341+
drop_cache_tree : 1,
342+
fsmonitor_has_run_once : 1;
342343
struct hashmap name_hash;
343344
struct hashmap dir_hash;
344345
struct object_id oid;

fsmonitor.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,16 @@ static void fsmonitor_refresh_callback(struct index_state *istate, const char *n
129129

130130
void refresh_fsmonitor(struct index_state *istate)
131131
{
132-
static int has_run_once = 0;
133132
struct strbuf query_result = STRBUF_INIT;
134133
int query_success = 0;
135134
size_t bol; /* beginning of line */
136135
uint64_t last_update;
137136
char *buf;
138137
int i;
139138

140-
if (!core_fsmonitor || has_run_once)
139+
if (!core_fsmonitor || istate->fsmonitor_has_run_once)
141140
return;
142-
has_run_once = 1;
141+
istate->fsmonitor_has_run_once = 1;
143142

144143
trace_printf_key(&trace_fsmonitor, "refresh fsmonitor");
145144
/*

read-cache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,6 +2307,7 @@ int discard_index(struct index_state *istate)
23072307
free_name_hash(istate);
23082308
cache_tree_free(&(istate->cache_tree));
23092309
istate->initialized = 0;
2310+
istate->fsmonitor_has_run_once = 0;
23102311
FREE_AND_NULL(istate->cache);
23112312
istate->cache_alloc = 0;
23122313
discard_split_index(istate);

t/t7519-status-fsmonitor.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR'
346346
test_cmp before after
347347
'
348348

349-
test_expect_failure 'discard_index() also discards fsmonitor info' '
349+
test_expect_success 'discard_index() also discards fsmonitor info' '
350350
test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" &&
351351
test_might_fail git update-index --refresh &&
352352
test-tool read-cache --print-and-refresh=tracked 2 >actual &&

0 commit comments

Comments
 (0)