Skip to content

Commit cfd635c

Browse files
committed
Merge branch 'js/fsmonitor-refresh-after-discarding-index'
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()
2 parents 521d3ef + 398a3b0 commit cfd635c

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

cache.h

+2-1
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

+2-3
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

+1
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/helper/test-read-cache.c

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
11
#include "test-tool.h"
22
#include "cache.h"
3+
#include "config.h"
34

45
int cmd__read_cache(int argc, const char **argv)
56
{
6-
int i, cnt = 1;
7+
int i, cnt = 1, namelen;
8+
const char *name = NULL;
9+
10+
if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
11+
namelen = strlen(name);
12+
argc--;
13+
argv++;
14+
}
15+
716
if (argc == 2)
817
cnt = strtol(argv[1], NULL, 0);
918
setup_git_directory();
19+
git_config(git_default_config, NULL);
1020
for (i = 0; i < cnt; i++) {
1121
read_cache();
22+
if (name) {
23+
int pos;
24+
25+
refresh_index(&the_index, REFRESH_QUIET,
26+
NULL, NULL, NULL);
27+
pos = index_name_pos(&the_index, name, namelen);
28+
if (pos < 0)
29+
die("%s not in index", name);
30+
printf("%s is%s up to date\n", name,
31+
ce_uptodate(the_index.cache[pos]) ? "" : " not");
32+
write_file(name, "%d\n", i);
33+
}
1234
discard_cache();
1335
}
1436
return 0;

t/t7519-status-fsmonitor.sh

+8
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,12 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR'
346346
test_cmp before after
347347
'
348348

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 &&
353+
printf "tracked is%s up to date\n" "" " not" >expect &&
354+
test_cmp expect actual
355+
'
356+
349357
test_done

0 commit comments

Comments
 (0)