line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OTRS::OPM::Maker::Utils::Git; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
215396
|
use strict; |
|
4
|
|
|
|
|
41
|
|
|
4
|
|
|
|
|
115
|
|
4
|
4
|
|
|
4
|
|
24
|
use warnings; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
141
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
27
|
use List::Util qw(first); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
352
|
|
7
|
4
|
|
|
4
|
|
30
|
use Carp; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
2815
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $GIT = 'git'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub commits { |
12
|
2
|
|
|
2
|
0
|
258
|
my ($class, %params) = @_; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
|
|
22
|
chdir $params{dir}; |
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
|
|
13745
|
my $log = qx{$GIT log -G"" --pretty=format:"%H %aI" *.sopm}; |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
|
|
59
|
my @lines = split /\n/, $log; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
9
|
my @found_commits; |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
14
|
for my $line ( reverse @lines ) { |
23
|
12
|
|
|
|
|
124
|
my ($commit_hash, $date) = split /\s+/, $line, 2; |
24
|
|
|
|
|
|
|
|
25
|
12
|
|
|
|
|
90656
|
my $commit_log = qx{ $GIT log -p $commit_hash }; |
26
|
12
|
|
|
|
|
432
|
my ($version) = $commit_log =~ m{\+ \s+ (.*?) }xms; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $is_found_version_greater = _check_version( |
29
|
|
|
|
|
|
|
old_version => $params{version}, |
30
|
12
|
|
|
|
|
194
|
new_version => $version, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
12
|
100
|
|
|
|
63
|
if ( $is_found_version_greater ) { |
34
|
9
|
|
|
|
|
136
|
push @found_commits, { hash => $commit_hash, version => $version, date => $date }; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
2
|
50
|
|
|
|
26
|
return if !@found_commits; |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
11
|
my $changes = ''; |
41
|
2
|
|
|
|
|
17
|
for my $index ( reverse 0 .. $#found_commits ) { |
42
|
9
|
|
|
|
|
32
|
my $commit = $found_commits[$index]; |
43
|
9
|
|
|
|
|
32
|
my $version = $commit->{version}; |
44
|
9
|
|
|
|
|
31
|
my $hash = $commit->{hash}; |
45
|
9
|
|
|
|
|
70
|
my $date = $commit->{date}; |
46
|
|
|
|
|
|
|
|
47
|
9
|
100
|
|
|
|
49
|
my $next_hash = $index >= $#found_commits ? '' : $found_commits[$index+1]->{hash}; |
48
|
9
|
|
|
|
|
59
|
my $range = $hash . '..' . $next_hash; |
49
|
|
|
|
|
|
|
|
50
|
9
|
|
|
|
|
59697
|
my $all_commits = qx{ $GIT log --pretty=format:"---%n%m%H%n%B" $range}; |
51
|
|
|
|
|
|
|
|
52
|
9
|
|
|
|
|
253
|
my @commits = split /^---\n>/ms, $all_commits; |
53
|
|
|
|
|
|
|
|
54
|
9
|
|
|
|
|
98
|
$changes .= sprintf "%s %s\n\n", $version, $date; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
COMMIT_ENTITY: |
57
|
9
|
|
|
|
|
56
|
for my $commit_entity ( @commits ) { |
58
|
36
|
|
|
|
|
126
|
my ($commit_hash, @message) = split /\n/, $commit_entity; |
59
|
|
|
|
|
|
|
|
60
|
36
|
100
|
|
|
|
111
|
next COMMIT_ENTITY if !$commit_hash; |
61
|
27
|
50
|
|
|
|
95
|
next COMMIT_ENTITY if !@message; |
62
|
|
|
|
|
|
|
|
63
|
27
|
|
|
|
|
86
|
my $i = 0; |
64
|
27
|
100
|
|
|
|
71
|
$changes .= join "\n", map{ my $indent = $i++ ? 8 : 4; (" " x $indent) . $_ }@message; |
|
45
|
|
|
|
|
140
|
|
|
45
|
|
|
|
|
164
|
|
65
|
27
|
|
|
|
|
73
|
$changes .= "\n\n"; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
9
|
|
|
|
|
57
|
$changes .= "\n"; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
74
|
return $changes |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub find_toplevel { |
75
|
1
|
|
|
1
|
0
|
162
|
my ($class, %params) = @_; |
76
|
|
|
|
|
|
|
|
77
|
1
|
50
|
|
|
|
7
|
return if !$params{dir}; |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
13
|
chdir $params{dir}; |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
6366
|
my $path = qx{$GIT rev-parse --show-toplevel}; |
82
|
1
|
|
|
|
|
28
|
return $path; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _check_version { |
86
|
16
|
|
|
16
|
|
1810
|
my (%params) = @_; |
87
|
|
|
|
|
|
|
|
88
|
16
|
100
|
|
|
|
114
|
return 1 if !$params{old_version}; |
89
|
|
|
|
|
|
|
|
90
|
10
|
|
|
|
|
152
|
my $old = sprintf "%03d%03d%03d", split /\./, $params{old_version}; |
91
|
10
|
|
|
|
|
460
|
my $new = sprintf "%03d%03d%03d", split /\./, $params{new_version}; |
92
|
|
|
|
|
|
|
|
93
|
10
|
|
|
|
|
87
|
return $new > $old; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |