Merge branch 'bw/protocol-v2' into maint
[gitweb.git] / templates / hooks--fsmonitor-watchman.sample
index 870a59d23791cbd51cc66ea49aca6e3d6b2e25ce..e673bb3980f3c286291809e05f80873852bc3e9c 100755 (executable)
@@ -28,19 +28,13 @@ if ($version == 1) {
            "Falling back to scanning...\n";
 }
 
-# Convert unix style paths to escaped Windows style paths when running
-# in Windows command prompt
-
-my $system = `uname -s`;
-$system =~ s/[\r\n]+//g;
 my $git_work_tree;
-
-if ($system =~ m/^MSYS_NT/) {
-       $git_work_tree = `cygpath -aw "\$PWD"`;
-       $git_work_tree =~ s/[\r\n]+//g;
-       $git_work_tree =~ s,\\,/,g;
+if ($^O =~ 'msys' || $^O =~ 'cygwin') {
+       $git_work_tree = Win32::GetCwd();
+       $git_work_tree =~ tr/\\/\//;
 } else {
-       $git_work_tree = $ENV{'PWD'};
+       require Cwd;
+       $git_work_tree = Cwd::cwd();
 }
 
 my $retry = 1;
@@ -49,10 +43,7 @@ launch_watchman();
 
 sub launch_watchman {
 
-       # Set input record separator
-       local $/ = 0666;
-
-       my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j')
+       my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty')
            or die "open2() failed: $!\n" .
            "Falling back to scanning...\n";
 
@@ -78,7 +69,8 @@ sub launch_watchman {
        END
 
        print CHLD_IN $query;
-       my $response = <CHLD_OUT>;
+       close CHLD_IN;
+       my $response = do {local $/; <CHLD_OUT>};
 
        die "Watchman: command returned no output.\n" .
            "Falling back to scanning...\n" if $response eq "";