Single Watchman subscription to support multiple roots
commit531781fc9e88850257d875bdf34f25d23df4a409
authorGabe Levi <gabe@fb.com>
Fri, 21 Sep 2018 13:41:31 +0000 (21 06:41 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Fri, 21 Sep 2018 13:42:44 +0000 (21 06:42 -0700)
tree6aea8f01a05ad020a571289c00a9df8c773e56b8
parentfda6d8a932473c3f77cd4b56f63b0aa4840656a4
Single Watchman subscription to support multiple roots

Summary:
{D8209048} added multiple root support to Watchman. This is because Flow can be configured to watch directories and files outside of the root directory. The approach I took was to subscribe to each included directory/file. It felt like the cleanest abstraction, but there was a downside. Each subscription would push results separately. So after a rebase, we might get a response from each subscription. So I had to add some debouncing to make sure we wait for all subscriptions. This debouncing made Flow a little less responsive to file system changes when using Watchman.

More recently, there are some cool Watchman extensions I'd like to use. However, these are tricky to use with multiple subscriptions.

So this diff introduces a different approach. Instead of sending multiple subscriptions, we have a single subscription. We use expression terms to specify which files and directories we'd like to watch.

For example, if we want to watch `foo/dirA` and `bar/fileB`, we will add to our expressions:

```
["anyof",["dirname","foo/dirA"],["name","foo/dirA"],["dirname","bar/fileB"],["name","bar/fileB"]]
```

which will match any file named `foo/dirA` or `bar/fileB` and will match any file under the directory `foo/dirA` or `bar/dirB`.

This new approach does require that every watched path is under the same watchman watch root. However, we were already arbitrarily asserting that anyway, so there's no loss of expressivity here.

Reviewed By: samwgoldman

Differential Revision: D9751231

fbshipit-source-id: 687d39a3f27780787a8b5d1b3c71b725ea8f0ff1
hphp/hack/src/watchman/watchman.ml
hphp/hack/src/watchman/watchman_lwt.ml
hphp/hack/src/watchman/watchman_sig.ml