Analizo/Batch/Git.pm

filter: Statementstmt 98.7% 76 / 77 Branchbran 93.7% 15 / 16 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 11 / 11 Podpod 20.0% 1 / 5 totaltotal 94.6% 106 / 112 CC 12 SCAR 16.6
CC
12
Cov
98%
initialize
10.0
new
2.0
fetch_next
2.0
CRAP 5.3
« Analizo/Model.pm ↑ Summary Analizo/Command/metrics_batch.pm »
1 package Analizo::Batch::Git;
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 11 ▶use parent qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
6 Analizo::Batch
7 Class::Accessor::Fast
8 11 );
9  
10 11 ▶use Analizo::Batch::Job::Git;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use Cwd 'abs_path';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use YAML::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 11 __PACKAGE__->mk_ro_accessors(qw( directory ));
15  
16 9 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
17 9 my ($class, $directory) = @_;
18 9 ▶ $directory ||= '.';
Condition100%2/2
$directory ||= "."
l!l
72
MC/DC100%1/1
$directory ||= "."
$directory
Truth table100%2/2
A
A= $directory
Aresult
11
00
19 9 $directory = abs_path($directory);
20 9 $class->SUPER::new(directory => $directory);
21 }
22  
23 18 ▶sub fetch_next {
Subroutine fetch_next: called CC=2 SCAR=6.9
Pod undocumented
24 18 my ($self) = @_;
25 18 $self->initialize();
26 18 my $nextcommit = $self->{relevant}->[$self->{index}];
27 18 ▶ if ($nextcommit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nextcommit) { } 16 2 18
28 16 $self->{index}++;
29 16 return $nextcommit;
30 } else {
31 2 return undef;
32 }
33 }
34  
35 22 ▶sub initialize {
Subroutine initialize: called CC=10 SCAR=23.0
Pod undocumented
36 22 my ($self) = @_;
37 22 ▶ unless(defined($self->{index})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"index"}) 8 14 22
38 # initialize filter: by default look only for files in known languages
39 8 ▶ unless ($self->has_filters) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_filters) 7 1 8
40 7 $self->filters(Analizo::LanguageFilter->new('all'));
41 }
42  
43 # read in list of commits
44 8 my $data = `(cd $self->{directory} && git log --name-status --format='---%nid: %H%nparents: %P%nauthor_date: %at%nauthor_name: %aN%nauthor_email: %aE%n--- |')`;
45 8 $data =~ s/^([[:upper:]])+\d*\t/ $1 /sgm;
46 8 my @data = ();
47 8 eval { @data = Load($data) };
48 8 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 8 8
49 0 die $!;
50 }
51 8 my @jobs = ();
52 8 ▶ while($#data > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#data > 0) 82 8 90
53  
54 82 my $commit_data = shift(@data);
55  
56 82 my @parents = ();
57 82 ▶ @parents = split(/\s+/, $commit_data->{parents}) if defined($commit_data->{parents});
Branch: 1 branch
BranchTrueFalseTotal
if defined $commit_data->{"parents"} 74 8 82
58 82 $commit_data->{parents} = \@parents;
59  
60 82 my $changed_files = shift(@data);
61 82 ▶ if(scalar(@parents) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @parents > 1) 15 67 82
62 # merge commits do not have their changed files listed in `git log`, no
63 # matter what. This way we *need* to do a `git show` here.
64 15 $changed_files = `(cd $self->{directory} && git show --name-status --format='%n' $commit_data->{id})`;
65 }
66 82 chomp($changed_files);
67 82 $changed_files =~ s/^\s*//; # remove leading whitespace
68 82 my %changed_files = map { my ($status, $file) = split(/\s+/, $_); $file => $status } (split("\n", $changed_files));
69 82 for my $file (keys(%changed_files)) {
70 130 ▶ if (!$self->filename_matches_filters($file)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->filename_matches_filters($file)) 52 78 130
71 52 delete $changed_files{$file};
72 }
73 }
74 82 $commit_data->{changed_files} = \%changed_files;
75  
76 82 my $job = Analizo::Batch::Job::Git->new($self->{directory}, $commit_data->{id}, $commit_data);
77 82 $job->batch($self);
78 82 push @jobs, $job;
79  
80 }
81  
82 8 my %jobs = map { $_->id => $_ } @jobs;
83 8 my @relevant = grep { $_->relevant } @jobs;
84 8 $self->{jobs} = \%jobs;
85 8 $self->{relevant} = \@relevant;
86 8 $self->{count} = scalar(@relevant);
87 8 $self->{index} = 0;
88 8 for my $job (@relevant) {
89 # force calculating previous relevant right now
90 50 $job->previous_relevant();
91 }
92 }
93 }
94  
95 1 ▶sub count {
Subroutine count: called CC=1 SCAR=0.0
Pod undocumented
96 1 my ($self) = @_;
97 1 return $self->{count};
98 }
99  
100 110 ▶sub find {
Subroutine find: called CC=1 SCAR=0.0
Pod undocumented
101 110 my ($self, $id) = @_;
102 110 return $self->{jobs}->{$id};
103 }
104  
105 11 1;
« Analizo/Model.pm ↑ Summary Analizo/Command/metrics_batch.pm »