line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Git::Diff; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
58434
|
use Git; |
|
1
|
|
|
|
|
19064
|
|
|
1
|
|
|
|
|
56
|
|
4
|
1
|
|
|
1
|
|
561
|
use utf8; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
5
|
|
5
|
1
|
|
|
1
|
|
39
|
use 5.018; |
|
1
|
|
|
|
|
3
|
|
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
481
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$Git::Diff::VERSION = '0.000102'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
1
|
|
|
1
|
1
|
638
|
my $s_class = shift; |
13
|
1
|
|
|
|
|
3
|
return bless {@_}, $s_class; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _repository { |
17
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
18
|
0
|
|
0
|
|
|
|
$self->{_repository} //= Git->repository( %{$self} ); |
|
0
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
return $self->{_repository}; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub changes_by_line { |
23
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
24
|
0
|
|
|
|
|
|
my $hr_files = $self->changed_lines(); |
25
|
0
|
|
|
|
|
|
for my $s_file ( keys %{$hr_files} ) { |
|
0
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my $hr_changed_lines = $hr_files->{$s_file}->{changed}; |
27
|
0
|
|
|
|
|
|
for my $s_line_key ( keys %{$hr_changed_lines} ) { |
|
0
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my ( $i_subtraction, $i_addition ) = ( $s_line_key =~ m/\-(\d+)(?:,\d+)*\s\+(\d+)/ ); |
29
|
0
|
|
|
|
|
|
for my $s_changed_line ( split /^/, $hr_changed_lines->{$s_line_key} ) { |
30
|
0
|
0
|
|
|
|
|
if ( $s_changed_line =~ /^\+(.*)/ ) { |
|
|
0
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
$hr_files->{$s_file}->{addition}->{ $i_addition++ } = $1; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif ( $s_changed_line =~ /^\-(.*)/ ) { |
34
|
0
|
|
|
|
|
|
$hr_files->{$s_file}->{subtraction}->{ $i_subtraction++ } = $1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
return $hr_files; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub changed_lines { |
43
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
44
|
0
|
|
0
|
|
|
|
my $s_gitresult = $self->diff( $self->{base_branch} // 'master', '-U0' ); |
45
|
0
|
|
|
|
|
|
my @a_splitted = split /^diff /ms, $s_gitresult; |
46
|
0
|
|
|
|
|
|
shift @a_splitted; |
47
|
0
|
|
|
|
|
|
my $hr_files = {}; |
48
|
0
|
|
|
|
|
|
for my $s_line (@a_splitted) { |
49
|
0
|
|
|
|
|
|
my ($s_file_name) = ( $s_line =~ m/^--git .* b\/(.*)/ ); |
50
|
0
|
|
|
|
|
|
my @a_lines = split /@@\s+/, $s_line; |
51
|
0
|
0
|
|
|
|
|
shift @a_lines if scalar @a_lines % 2 == 1; |
52
|
0
|
|
|
|
|
|
my %h_changed_lines = @a_lines; |
53
|
0
|
|
|
|
|
|
$hr_files->{$s_file_name} = { raw => $_, changed => \%h_changed_lines }; |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
return $hr_files; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub diff { |
59
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
60
|
0
|
|
|
|
|
|
my @a_command_params = @_; |
61
|
0
|
|
|
|
|
|
unshift @a_command_params, 'diff'; |
62
|
0
|
|
|
|
|
|
return $self->_repository->command(@a_command_params); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |