From: Jeff Hostetler Date: Fri, 30 Apr 2021 15:18:51 GMT Subject: Re: [PATCH 09/23] fsmonitor--daemon: implement daemon command options Message-ID: In-Reply-To: <3aa3c802-0ad1-0a65-d646-0cd574cb8036@gmail.com> On 4/26/21 12:12 PM, Derrick Stolee wrote: > On 4/26/2021 11:47 AM, Derrick Stolee wrote: >> On 4/1/21 11:40 AM, Jeff Hostetler via GitGitGadget wrote: >>> From: Jeff Hostetler >> ... >>> + /* Prepare to (recursively) watch the directory. */ >>> + strbuf_init(&state.path_worktree_watch, 0); >>> + strbuf_addstr(&state.path_worktree_watch, absolute_path(get_git_work_tree())); >>> + state.nr_paths_watching = 1; >> >> Yes, let's watch the working directory. >> >>> + /* >>> + * If ".git" is not a directory, then is not inside the >>> + * cone of , so set up a second watch for it. >>> + */ >>> + strbuf_init(&state.path_gitdir_watch, 0); >>> + strbuf_addbuf(&state.path_gitdir_watch, &state.path_worktree_watch); >>> + strbuf_addstr(&state.path_gitdir_watch, "/.git"); >>> + if (!is_directory(state.path_gitdir_watch.buf)) { >>> + strbuf_reset(&state.path_gitdir_watch); >>> + strbuf_addstr(&state.path_gitdir_watch, absolute_path(get_git_dir())); >>> + state.nr_paths_watching = 2; >>> + } >> >> But why watch the .git directory, especially for a worktree (or >> submodule I guess)? What benefit do we get from events within the >> .git directory? I'm expecting any event within the .git directory >> should be silently ignored. > > I see in a following patch that we place a cookie file within the > .git directory. I'm reminded that this is done for a reason: other > filesystem watchers can get into a loop if we place the cookie > file outside of the .git directory. The classic example is VS Code > running 'git status' in a loop because Watchman writes a cookie > into the root of the working directory. Yes. I'll add a comment explaining the need for the second watch.