diff --git a/.watchmanconfig b/.watchmanconfig index e69de29..0967ef4 100644 --- a/.watchmanconfig +++ b/.watchmanconfig @@ -0,0 +1 @@ +{} diff --git a/doc/command-t.txt b/doc/command-t.txt index d8dd1f4..f77047b 100644 --- a/doc/command-t.txt +++ b/doc/command-t.txt @@ -1413,32 +1413,32 @@ AUTHORS *command-t-authors* Command-T is written and maintained by Greg Hurrell . Other contributors that have submitted patches include, in alphabetical order: - Abhinav Gupta Nate Kane - Adrian Keet Nicholas T. - Aleksandrs Ļedovskis Nicolas Alpi - Alexey Terekhov Nikolai Aleksandrovich Pavlov - Andrius Grabauskas Nilo César Teixeira - Andy Waite Noon Silk - Anthony Panozzo Ole Petter Bang - Artem Nezvigin Patrick Hayes - Ben Boeckel Paul Jolly - Brendan Mulholland Pavel Sergeev - Daniel Burgess Rainux Luo - Daniel Hahler Richard Feldman - David Emett Roland Puntaier - David Szotten Ross Lagerwall - Douglas Drumond Sam Morris - Emily Strickland Scott Bronson - Felix Tjandrawibawa Seth Fowler - Gary Bernhardt Sherzod Gapirov - Henric Trotzig Shlomi Fish - Ivan Ukhov Stefan Schmidt - Jakob Pfender Stephen Gelman - Jeff Kreeftmeijer Steve Herrell - Jerome Castaneda Steven Moazami - Joe Lencioni Steven Stallion - KJ Tsanaktsidis Sung Pae - Kevin Webster Thomas Pelletier + Abhinav Gupta Nicholas T. + Adrian Keet Nicolas Alpi + Aleksandrs Ļedovskis Nikolai Aleksandrovich Pavlov + Alexey Terekhov Nilo César Teixeira + Andrius Grabauskas Noon Silk + Andy Waite Ole Petter Bang + Anthony Panozzo Patrick Hayes + Artem Nezvigin Paul Jolly + Ben Boeckel Pavel Sergeev + Brendan Mulholland Rainux Luo + Daniel Burgess Richard Feldman + Daniel Hahler Roland Puntaier + David Emett Ross Lagerwall + David Szotten Sam Morris + Douglas Drumond Scott Bronson + Emily Strickland Seth Fowler + Felix Tjandrawibawa Sherzod Gapirov + Gary Bernhardt Shlomi Fish + Henric Trotzig Stefan Schmidt + Ivan Ukhov Stephen Gelman + Jakob Pfender Steve Herrell + Jeff Kreeftmeijer Steven Moazami + Jerome Castaneda Steven Stallion + Joe Lencioni Sung Pae + KJ Tsanaktsidis Thomas Pelletier + Kevin Webster Todd Derr Kien Nguyen Duc Ton van den Heuvel Lucas de Vries Victor Hugo Borja Marcus Brito Vlad Seghete @@ -1447,6 +1447,7 @@ Other contributors that have submitted patches include, in alphabetical order: Max Timkovich Yan Pritzker Mike Lundy Zak Johnson Nadav Samet xiaodezhang + Nate Kane This list produced with: @@ -1572,6 +1573,11 @@ POSSIBILITY OF SUCH DAMAGE. HISTORY *command-t-history* +main (not yet released) ~ + +- Teach watchman scanner to favor `watch-project` over `watch` when + available (#390, patch from Todd Derr). + 5.0.4 (28 May 2022) ~ - Support opening files which contain newlines (#365). diff --git a/ruby/command-t/lib/command-t/scanner/file_scanner/watchman_file_scanner.rb b/ruby/command-t/lib/command-t/scanner/file_scanner/watchman_file_scanner.rb index 60f412a..5616d8f 100644 --- a/ruby/command-t/lib/command-t/scanner/file_scanner/watchman_file_scanner.rb +++ b/ruby/command-t/lib/command-t/scanner/file_scanner/watchman_file_scanner.rb @@ -25,20 +25,29 @@ def paths! UNIXSocket.open(sockname) do |socket| root = Pathname.new(@path).realpath.to_s - roots = Watchman::Utils.query(['watch-list'], socket)['roots'] - if !roots.include?(root) - # this path isn't being watched yet; try to set up watch - result = Watchman::Utils.query(['watch', root], socket) + # Use `watch-project` for efficiency if available. + if use_watch_project? + result = Watchman::Utils.query(['watch-project', root], socket) + root = extract_value(result, 'watch') + relative_root = extract_value(result, 'relative_path') if result.has_key?('relative_path') + else + roots = Watchman::Utils.query(['watch-list'], socket)['roots'] + if !roots.include?(root) + # This path isn't being watched yet; try to set up watch. + result = Watchman::Utils.query(['watch', root], socket) - # root_restrict_files setting may prevent Watchman from working - # or enforce_root_files/root_files (>= version 3.1) - extract_value(result) + # `root_restrict_files` setting may prevent Watchman from + # working or enforce_root_files/root_files (>= version 3.1). + extract_value(result) + end end - query = ['query', root, { + query_params = { 'expression' => ['type', 'f'], 'fields' => ['name'], - }] + } + query_params['relative_root'] = relative_root if relative_root + query = ['query', root, query_params] paths = Watchman::Utils.query(query, socket) # could return error if watch is removed @@ -68,6 +77,15 @@ def get_raw_sockname end raw_sockname end + + # `watch_project` is available in 3.1+ but it's awkward to use without + # `relative_root` (3.3+), so use the latter as our minimum version. + def use_watch_project? + return @use_watch_project if defined?(@use_watch_project) + version = %x{watchman --version 2>/dev/null} + major, minor = version.split('.')[0..1] if !$?.exitstatus.nil? && $?.exitstatus.zero? && version + @use_watch_project = major.to_i > 3 || (major.to_i == 3 && minor.to_i >= 3) + end end end end