line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Rex::Hook::File::Diff; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: show diff of changes for files managed by Rex |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
229204
|
use 5.012; |
|
2
|
|
|
|
|
17
|
|
6
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
75
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
12
|
use File::Basename; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
183
|
|
9
|
2
|
|
|
2
|
|
594
|
use Rex 1.013004 -base; |
|
2
|
|
|
|
|
59212
|
|
|
2
|
|
|
|
|
16
|
|
10
|
2
|
|
|
2
|
|
571582
|
use Rex::Helper::Run; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
147
|
|
11
|
2
|
|
|
2
|
|
15
|
use Rex::Hook; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
127
|
|
12
|
2
|
|
|
2
|
|
42
|
use Text::Diff 1.44; |
|
2
|
|
|
|
|
23517
|
|
|
2
|
|
|
|
|
1000
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = 'v0.4.0'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
register_function_hooks { before_change => { file => \&show_diff, }, }; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub show_diff { |
19
|
12
|
|
|
12
|
0
|
754476
|
my ( $original_file, @opts ) = @_; |
20
|
|
|
|
|
|
|
|
21
|
12
|
|
|
|
|
175
|
my $diff; |
22
|
12
|
|
|
|
|
550
|
my $diff_command = can_run('diff'); |
23
|
12
|
|
|
|
|
128255
|
state $managing_windows = is_windows(); |
24
|
|
|
|
|
|
|
|
25
|
12
|
50
|
33
|
|
|
74748
|
if ( !$managing_windows && $diff_command ) { |
|
|
0
|
|
|
|
|
|
26
|
12
|
|
|
|
|
333
|
my $command = join q( ), $diff_command, '-u', involved_files($original_file); |
27
|
|
|
|
|
|
|
|
28
|
12
|
100
|
|
|
|
703
|
if ( $diff = i_run $command, fail_ok => TRUE ) { |
29
|
10
|
|
|
|
|
90213
|
$diff .= "\n"; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif ( Rex::is_local() ) { |
33
|
0
|
|
|
|
|
0
|
$diff = diff( involved_files($original_file) ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
0
|
|
|
|
|
0
|
Rex::Logger::debug( |
37
|
|
|
|
|
|
|
'Skipping File::Diff hook due to remote operation without the diff utility'); |
38
|
0
|
|
|
|
|
0
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
12
|
100
|
|
|
|
16232
|
if ( length $diff > 0 ) { |
42
|
10
|
|
|
|
|
353
|
Rex::Commands::say("Diff for: $original_file\n$diff"); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
12
|
|
|
|
|
2170
|
return; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub involved_files { |
49
|
15
|
|
|
15
|
0
|
18820
|
my $file = shift; |
50
|
|
|
|
|
|
|
|
51
|
15
|
|
|
|
|
262
|
my $temp_file = Rex::Commands::File::get_tmp_file_name($file); |
52
|
15
|
|
|
|
|
5141
|
my $null = File::Spec->devnull(); |
53
|
|
|
|
|
|
|
|
54
|
15
|
100
|
|
|
|
380
|
if ( !is_file($file) ) { $file = $null } # creating file |
|
4
|
|
|
|
|
33251
|
|
55
|
15
|
100
|
|
|
|
7284
|
if ( !is_file($temp_file) ) { $temp_file = $null } # removing file |
|
5
|
|
|
|
|
1474
|
|
56
|
|
|
|
|
|
|
|
57
|
15
|
|
|
|
|
2496
|
return ( $file, $temp_file ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |