bin env perl use strict use warnings use FindBin use File Basename use

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/env perl
use strict;
use warnings;
use FindBin;
use File::Basename;
use File::Path;
use File::Temp qw /tempdir/;
my $magic = "MVUETS_GIT_VDIFF";
my $base_dir = $ENV{$magic} || tempdir('gwm-XXXX', TMPDIR => 1, CLEANUP => 1);
my $old_dir = "$base_dir/a";
my $new_dir = "$base_dir/b";
unless ($ENV{$magic})
{
mkpath([$old_dir, $new_dir]);
$ENV{$magic} = $base_dir;
$ENV{GIT_EXTERNAL_DIFF} = "$FindBin::Bin/$FindBin::Script";
system 'git', '--no-pager', 'diff', @ARGV;
$? >> 8 == 0 or die "Could not run `git diff`";
print STDERR "\n";
system 'winmergeu', '/r', $old_dir, $new_dir;
$? >> 8 == 0 or die "Could not run `winmergeu`";
}
else
{
print STDERR '.';
# $GIT_EXTERNAL_DIFF is called with 7 parameters:
# path old-file old-hex old-mode new-file new-hex new-mode
my ($rel_path, $old_file, undef, undef, $new_file, undef, undef) = @ARGV;
my $rel_dir = dirname($rel_path);
my $filename = basename($rel_path);
if ($old_file ne '/dev/null')
{
my $d = "$old_dir/$rel_dir";
mkpath([$d]);
link $old_file, "$d/$filename" or die "link failed";
}
if ($new_file ne '/dev/null')
{
my $d = "$new_dir/$rel_dir";
mkpath([$d]);
link $new_file, "$d/$filename" or die "link failed";
}
}