Skip to content

Commit 2ada529

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 <johannes.schindelin@gmx.de>
1 parent 3d68d8c commit 2ada529

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
@@ -341,7 +341,8 @@ struct index_state {
341341
initialized : 1,
342342
drop_cache_tree : 1,
343343
updated_workdir : 1,
344-
updated_skipworktree : 1;
344+
updated_skipworktree : 1,
345+
fsmonitor_has_run_once : 1;
345346
struct hashmap name_hash;
346347
struct hashmap dir_hash;
347348
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
@@ -2326,6 +2326,7 @@ int discard_index(struct index_state *istate)
23262326
free_name_hash(istate);
23272327
cache_tree_free(&(istate->cache_tree));
23282328
istate->initialized = 0;
2329+
istate->fsmonitor_has_run_once = 0;
23292330
FREE_AND_NULL(istate->cache);
23302331
istate->cache_alloc = 0;
23312332
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)