Skip to content

Commit

Permalink
Merge pull request #2127 from dscho/fix-fsmonitor
Browse files Browse the repository at this point in the history
Do query the fsmonitor again after the index has been discarded
  • Loading branch information
dscho authored May 9, 2019
2 parents 2ac5f42 + 912cfd3 commit 81a060a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ struct index_state {
struct cache_time timestamp;
unsigned name_hash_initialized : 1,
initialized : 1,
drop_cache_tree : 1;
drop_cache_tree : 1,
fsmonitor_has_run_once : 1;
struct hashmap name_hash;
struct hashmap dir_hash;
struct object_id oid;
Expand Down
5 changes: 2 additions & 3 deletions fsmonitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,16 @@ 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 */
uint64_t last_update;
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");
/*
Expand Down
1 change: 1 addition & 0 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -2309,6 +2309,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);
Expand Down
24 changes: 23 additions & 1 deletion t/helper/test-read-cache.c
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
8 changes: 8 additions & 0 deletions t/t7519-status-fsmonitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 81a060a

Please sign in to comment.