Bug in index-helper/watchman?
...and somehow I forgot to CC git@vger, grrrr....
Quoted 125 lines · Duy Nguyen
Bug reports should always be in public (so people are aware of it) unless it's security exploit of course.
I have not read this mail yet, but I will in a couple of hours, hopefully.
Quoted 109 lines · Ben Peart
I’ve been chasing down an issue where it looks like the untracked cache logic doesn’t work correctly in the index-helper/watchman patch series. It’s also entirely possible that I’m just missing something so feel free to correct my misconceptions.
Ultimately, it appears that none of the untracked cache directories are getting flagged as invalid from the data in the watchman extension. I believe this is happening because
untracked->rootdoesn’t get initialized untilvalidate_untracked_cacheis called fromread_directory. This causes all calls tolookup_untrackedto return NULL so thedir->validflag is never set to zero inmark_untracked_invalid. See the call stacks and sequence below for details:
cmd_statusatbuiltin/commit.c:1362status_init_config (s=0x6667a0 <s>, fn=0x432790<
git_status_config>) atbuiltin/commit.c:187
gitmodules_config() at submodule.c:196
read_index(istate=0x693860
<the_index>) at read-cache.c:1442
read_index_from
(istate=0x693860 <the_index>, path=0x2ea3c58 ".git/index") at read-cache.c:1849
do_read_index
read_index_extension
read_watchman_ext
mark_untracked_invalid
find_untracked_cache_dir
lookup_untrackedif (!dir)
return NULL;
wt_status_collect (s=0x6667a0 <s>) at wt-status.c:627 wt_status_collect_untracked (s=0x6667a0 <s>) atwt-status.c:593
fill_directory (dir=0xbafab0,pathspec=0x6667b8 <s+24>) at dir.c:191
read_directory
(dir=0xbafab0, path=0x61cac3 <atat+155> "", len=0, pathspec=0x6667b8 <s+24>) at dir.c:2009
validate_untracked_cacheat dir.c:1903if (!dir->untracked->root)
read_directory_recursive
open_cached_dir
valid_cached_dir
read_directory_recursive
open_cached_dir
valid_cached_dirif (
dir->untracked->use_watchman)If I’m reading this correctly, one potential fix is to move the logic that loops through the directories calling
mark_untracked_invalidto between the call tovalidate_untracked_cacheand the call toread_directory_recursive. I wonder if there is another simpler/better fix.Quoted 5 lines
Thoughts?
Ben
--
Duy
Signature · 1 line
Duy
Quoted 8 lines · Duy Nguyen
Quoted 8 lines · Ben Peart
Quoted 7 lines
I’ve been chasing down an issue where it looks like the untracked cache logic doesn’t work correctly in the index-helper/watchman patch series. It’s also entirely possible that I’m just missing something so feel free to correct my misconceptions.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Ultimately, it appears that none of the untracked cache directories are getting flagged as invalid from the data in the watchman extension. I believe this is happening because
untracked->rootdoesn’t get initialized untilvalidate_untracked_cacheis called fromread_directory. This causes all calls tolookup_untrackedto return NULL so thedir->validflag is never set to zero inmark_untracked_invalid.
No, validate_untracked_cache does not do anything fancy in there to make UC initialized. It may invalidate UC further though.
But you did spot a problem. What if UC extension is loaded _after_ watchman one? Then index->untracked_cache would have nothing in there and invalidation is no-op when we do it (at watchmain ext loading time). We can't control extension loading order (technically we can, but other git implementations may do it differently). So, maybe we should do the invalidation after _all_ index extensions have been loaded.
Maybe we can do it in validate_untracked_cache? We already store the path list in the_index.untracked->invalid_untracked. validate_untracked_cache has all info it needs.
Signature · 1 line
Duy
Quoted 11 lines · Duy Nguyen
But you did spot a problem. What if UC extension is loaded _after_ watchman one? Then
index->untracked_cachewould have nothing in there and invalidation is no-op when we do it (at watchmain ext loading time). We can't control extension loading order (technically we can, but other git implementations may do it differently). So, maybe we should do the invalidation after _all_ index extensions have been loaded.Maybe we can do it in
validate_untracked_cache? We already store the path list inthe_index.untracked->invalid_untracked.validate_untracked_cachehas all info it needs.
The squash for "index-helper: use watchman to avoid refreshing index with lstat()" looks something like this. I did not test it at all though.
-- 8< --
dir.c +42 -0
@@ -1902,6 +1902,43 @@ void remove_untracked_cache(struct index_state *istate) } } +static struct untracked_cache_dir *find_untracked_cache_dir ( +struct untracked_cache *uc,struct untracked_cache_dir *ucd, +const char *name) +{ +int component_len; +const char *end; +struct untracked_cache_dir *dir; + +if (!*name) +return ucd; + + end =strchr (name,'/' ); +if (end) + component_len = end - name; +else + component_len =strlen (name); + + dir =lookup_untracked (uc, ucd, name, component_len); +if (dir) +return find_untracked_cache_dir (uc, dir, name + component_len +1 ); + +return NULL ; +} + +static int mark_untracked_invalid (struct string_list_item *item,void *uc) +{ +struct untracked_cache *untracked = uc; +struct untracked_cache_dir *dir; + + dir =find_untracked_cache_dir (untracked, untracked->root, + item->string); +if (dir) + dir->valid =0 ; + +return 0 ; +} +static struct untracked_cache_dir *validate_untracked_cache (struct dir_struct *dir,int base_len,const struct pathspec *pathspec)
@@ -1984,6 +2021,11 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d/* Make sure this directory is not dropped out at saving phase */ root->recurse =1 ; + +if (dir->untracked->use_watchman) { +for_each_string_list (&dir->untracked->invalid_untracked, + mark_untracked_invalid, dir->untracked); + }return root; }
dir.h +0 -3
@@ -312,7 +312,4 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned longvoid write_untracked_extension (struct strbuf *out,struct untracked_cache *untracked);void add_untracked_cache (struct index_state *istate);void remove_untracked_cache (struct index_state *istate); -struct untracked_cache_dir *lookup_untracked (struct untracked_cache *uc, -struct untracked_cache_dir *dir, -const char *name,int len);#endif
read-cache.c +1 -45
74 lines not on this page · raw message
-- 8< --
--
Duy