Mercurial > repos > fubar > egapx_runner
annotate oldgit/hooks/fsmonitor-watchman.sample @ 2:a3b158471bd3 draft
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
author | fubar |
---|---|
date | Sun, 04 Aug 2024 00:06:43 +0000 |
parents | |
children |
rev | line source |
---|---|
2
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
1 #!/usr/bin/perl |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
2 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
3 use strict; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
4 use warnings; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
5 use IPC::Open2; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
6 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
7 # An example hook script to integrate Watchman |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
8 # (https://facebook.github.io/watchman/) with git to speed up detecting |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
9 # new and modified files. |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
10 # |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
11 # The hook is passed a version (currently 2) and last update token |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
12 # formatted as a string and outputs to stdout a new update token and |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
13 # all files that have been modified since the update token. Paths must |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
14 # be relative to the root of the working tree and separated by a single NUL. |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
15 # |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
16 # To enable this hook, rename this file to "query-watchman" and set |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
17 # 'git config core.fsmonitor .git/hooks/query-watchman' |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
18 # |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
19 my ($version, $last_update_token) = @ARGV; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
20 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
21 # Uncomment for debugging |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
22 # print STDERR "$0 $version $last_update_token\n"; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
23 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
24 # Check the hook interface version |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
25 if ($version ne 2) { |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
26 die "Unsupported query-fsmonitor hook version '$version'.\n" . |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
27 "Falling back to scanning...\n"; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
28 } |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
29 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
30 my $git_work_tree = get_working_dir(); |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
31 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
32 my $retry = 1; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
33 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
34 my $json_pkg; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
35 eval { |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
36 require JSON::XS; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
37 $json_pkg = "JSON::XS"; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
38 1; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
39 } or do { |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
40 require JSON::PP; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
41 $json_pkg = "JSON::PP"; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
42 }; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
43 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
44 launch_watchman(); |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
45 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
46 sub launch_watchman { |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
47 my $o = watchman_query(); |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
48 if (is_work_tree_watched($o)) { |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
49 output_result($o->{clock}, @{$o->{files}}); |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
50 } |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
51 } |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
52 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
53 sub output_result { |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
54 my ($clockid, @files) = @_; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
55 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
56 # Uncomment for debugging watchman output |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
57 # open (my $fh, ">", ".git/watchman-output.out"); |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
58 # binmode $fh, ":utf8"; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
59 # print $fh "$clockid\n@files\n"; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
60 # close $fh; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
61 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
62 binmode STDOUT, ":utf8"; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
63 print $clockid; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
64 print "\0"; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
65 local $, = "\0"; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
66 print @files; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
67 } |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
68 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
69 sub watchman_clock { |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
70 my $response = qx/watchman clock "$git_work_tree"/; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
71 die "Failed to get clock id on '$git_work_tree'.\n" . |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
72 "Falling back to scanning...\n" if $? != 0; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
73 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
74 return $json_pkg->new->utf8->decode($response); |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
75 } |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
76 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
77 sub watchman_query { |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
78 my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
79 or die "open2() failed: $!\n" . |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
80 "Falling back to scanning...\n"; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
81 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
82 # In the query expression below we're asking for names of files that |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
83 # changed since $last_update_token but not from the .git folder. |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
84 # |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
85 # To accomplish this, we're using the "since" generator to use the |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
86 # recency index to select candidate nodes and "fields" to limit the |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
87 # output to file names only. Then we're using the "expression" term to |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
88 # further constrain the results. |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
89 my $last_update_line = ""; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
90 if (substr($last_update_token, 0, 1) eq "c") { |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
91 $last_update_token = "\"$last_update_token\""; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
92 $last_update_line = qq[\n"since": $last_update_token,]; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
93 } |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
94 my $query = <<" END"; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
95 ["query", "$git_work_tree", {$last_update_line |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
96 "fields": ["name"], |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
97 "expression": ["not", ["dirname", ".git"]] |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
98 }] |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
99 END |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
100 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
101 # Uncomment for debugging the watchman query |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
102 # open (my $fh, ">", ".git/watchman-query.json"); |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
103 # print $fh $query; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
104 # close $fh; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
105 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
106 print CHLD_IN $query; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
107 close CHLD_IN; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
108 my $response = do {local $/; <CHLD_OUT>}; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
109 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
110 # Uncomment for debugging the watch response |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
111 # open ($fh, ">", ".git/watchman-response.json"); |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
112 # print $fh $response; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
113 # close $fh; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
114 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
115 die "Watchman: command returned no output.\n" . |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
116 "Falling back to scanning...\n" if $response eq ""; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
117 die "Watchman: command returned invalid output: $response\n" . |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
118 "Falling back to scanning...\n" unless $response =~ /^\{/; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
119 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
120 return $json_pkg->new->utf8->decode($response); |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
121 } |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
122 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
123 sub is_work_tree_watched { |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
124 my ($output) = @_; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
125 my $error = $output->{error}; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
126 if ($retry > 0 and $error and $error =~ m/unable to resolve root .* directory (.*) is not watched/) { |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
127 $retry--; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
128 my $response = qx/watchman watch "$git_work_tree"/; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
129 die "Failed to make watchman watch '$git_work_tree'.\n" . |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
130 "Falling back to scanning...\n" if $? != 0; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
131 $output = $json_pkg->new->utf8->decode($response); |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
132 $error = $output->{error}; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
133 die "Watchman: $error.\n" . |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
134 "Falling back to scanning...\n" if $error; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
135 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
136 # Uncomment for debugging watchman output |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
137 # open (my $fh, ">", ".git/watchman-output.out"); |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
138 # close $fh; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
139 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
140 # Watchman will always return all files on the first query so |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
141 # return the fast "everything is dirty" flag to git and do the |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
142 # Watchman query just to get it over with now so we won't pay |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
143 # the cost in git to look up each individual file. |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
144 my $o = watchman_clock(); |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
145 $error = $output->{error}; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
146 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
147 die "Watchman: $error.\n" . |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
148 "Falling back to scanning...\n" if $error; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
149 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
150 output_result($o->{clock}, ("/")); |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
151 $last_update_token = $o->{clock}; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
152 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
153 eval { launch_watchman() }; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
154 return 0; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
155 } |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
156 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
157 die "Watchman: $error.\n" . |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
158 "Falling back to scanning...\n" if $error; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
159 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
160 return 1; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
161 } |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
162 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
163 sub get_working_dir { |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
164 my $working_dir; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
165 if ($^O =~ 'msys' || $^O =~ 'cygwin') { |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
166 $working_dir = Win32::GetCwd(); |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
167 $working_dir =~ tr/\\/\//; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
168 } else { |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
169 require Cwd; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
170 $working_dir = Cwd::cwd(); |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
171 } |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
172 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
173 return $working_dir; |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
174 } |