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