VCI/VCS/Cvs/Project.pm

filter: Statementstmt 26.3% 29 / 110 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 8 / 16 Podpod 0.0% 0 / 3 totaltotal 20.9% 37 / 177 CC 25 SCAR 42.4
CC
25
Cov
19%
_build_history
182.0
__ANON__
30.0
_x_parse_members
30.0
CRAP 69.3
« VCI/Abstract/Directory.pm ↑ Summary VCI/Abstract/Project.pm »
1 package VCI::VCS::Cvs::Project;
2 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use MooseX::Method;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use IPC::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Temp qw(tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use VCI::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 extends 'VCI::Abstract::Project';
12  
13 1 ▶use constant CVSPS_SEPARATOR => "---------------------";
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use constant CVSPS_MEMBER => qr/^\s+(.+):(INITIAL|[\d\.]+)->([\d\.]+)(\(DEAD\))?/o;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 has 'x_tmp' => (is => 'ro', isa => 'Str', lazy => 1,
18 0 ▶ default => sub { tempdir('vci.cvs.XXXXXX', TMPDIR => 1,
Subroutine __ANON__: not called CC=1 SCAR=6.9
19 1 CLEANUP => 1) });
20  
21 0 ▶sub BUILD {
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
22 0 my $self = shift;
23 0 $self->_name_never_ends_with_slash();
24 0 $self->_name_never_starts_with_slash();
25 }
26  
27 method 'get_file' => named (
28 path => { isa => 'VCI::Type::Path', coerce => 1, required => 1 },
29 revision => { isa => 'Str' },
30 0 ▶) => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
31 0 my $self = shift;
32 0 my ($params) = @_;
33 0 my $path = $params->{path};
34 0 my $rev = $params->{revision};
35
36 0 ▶ confess("Empty path name passed to get_file") if $path->is_empty;
Branch: 1 branch
BranchTrueFalseTotal
if $path->is_empty 0 0 0
37
38 0 ▶ if (defined $rev) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rev) 0 0 0
39 0 my $file = $self->file_class->new(path => $path, revision => $rev,
40 project => $self);
41 # If $file->time works, then we have a valid file & revision.
42 0 ▶ return $file if defined eval { $file->time };
Branch: 1 branch
BranchTrueFalseTotal
if defined eval { do { $file->time } } 0 0 0
43 0 undef $@; # Don't mess up anything else that checks $@.
44 0 return undef;
45 }
46
47 # MooseX::Method always has a hash key for each parameter, even if they
48 # weren't passed by the caller.
49 0 delete $params->{$_} foreach (grep(!defined $params->{$_}, keys %$params));
50 0 return $self->SUPER::get_file(@_);
51 1 };
52  
53 0 ▶sub _build_history {
Subroutine _build_history: not called CC=13 SCAR=52.0
54 0 my $self = shift;
55 0 my @lines = split "\n", $self->x_cvsps_do(undef, 1);
56  
57 0 my @commits;
58 my %current_commit;
59 0 my $new_patchset = 1;
60 # The first line is a CVSPS_SEPARATOR, so we just discard it.
61 0 shift @lines;
62 0 ▶ while (@lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines) 0 0 0
63 0 my $line = shift @lines;
64 0 ▶ if ($line =~ /^Log:\s*$/) {
Branch: 5 branches
BranchTrueFalseTotal
if ($line =~ /^Log:\s*$/) { } 0 0 0
elsif ($line =~ /^Members:\s*$/) { } 0 0 0
elsif ($line =~ /^(\S+):\s+(.+)?$/) { } 0 0 0
elsif ($new_patchset and $line =~ /^PatchSet\s+(\d+)\s*$/) { } 0 0 0
elsif ($line eq '---------------------') { } 0 0 0
65 0 my @log_lines;
66 0 ▶ while (@lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines) 0 0 0
67 0 ▶ last if $lines[0] =~ /^Members:\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $lines[0] =~ /^Members:\s*$/ 0 0 0
68 0 my $log_line = shift @lines;
69 0 push(@log_lines, $log_line);
70 }
71 0 $current_commit{'Log'} = \@log_lines;
72 }
73 elsif ($line =~ /^Members:\s*$/) {
74 0 my @member_lines;
75 0 ▶ while (@lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines) 0 0 0
76 0 my $member_line = shift @lines;
77 # This discards the extra newline at the end of "Members:"
78 0 ▶ last if $member_line eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $member_line eq "" 0 0 0
79 0 push(@member_lines, $member_line);
80 }
81 0 $current_commit{'Members'} = \@member_lines;
82 }
83 elsif ($line =~ /^(\S+):\s+(.+)?$/) {
84 0 my ($field, $value) = ($1, $2);
85 0 $current_commit{$field} = $value;
86 }
87 ▶ elsif ($new_patchset and $line =~ /^PatchSet\s+(\d+)\s*$/) {
Condition0%0/3
$new_patchset and $line =~ /^PatchSet\s+(\d+)\s*$/
!ll&&!rl&&r
000
MC/DC0%0/2
$new_patchset and $line =~ /^PatchSet\s+(\d+)\s*$/
$new_patchset $line =~ /^PatchSet\s+(\d+)\s*$/
Truth table0%0/3
A and B
A= $new_patchsetB= $line =~ /^PatchSet\s+(\d+)\s*$/
ABresult
0X0
100
111
88 0 $current_commit{PatchSet} = $1;
89 0 $new_patchset = 0;
90 }
91 elsif ($line eq CVSPS_SEPARATOR) {
92 0 $new_patchset = 1;
93 0 push(@commits, $self->_x_commit_from_patchset(\%current_commit));
94 0 %current_commit = ();
95 }
96 else {
97 0 warn "Unparsed cvsps line: $line";
98 }
99 }
100
101 0 ▶ if (keys %current_commit) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %current_commit) 0 0 0
102 0 push(@commits, $self->_x_commit_from_patchset(\%current_commit));
103 }
104
105 0 return $self->history_class->new(commits => \@commits, project => $self);
106 }
107
108 0 ▶sub _x_commit_from_patchset {
Subroutine _x_commit_from_patchset: not called CC=1 SCAR=6.9
109 0 my ($self, $data) = @_;
110 0 my $log_lines = $data->{Log};
111 # There's an extra newline at the end of @log_lines.
112 0 pop @$log_lines;
113
114 0 my ($added, $removed, $modified) = $self->_x_parse_members($data);
115
116 return $self->commit_class->new(
117 revision => $data->{PatchSet},
118 time => $data->{Date} . ' UTC',
119 committer => $data->{Author},
120 0 message => join("\n", @$log_lines),
121 added => $added,
122 removed => $removed,
123 modified => $modified,
124 project => $self,
125 );
126 }
127  
128 0 ▶sub _x_parse_members {
Subroutine _x_parse_members: not called CC=5 SCAR=34.0
129 0 my ($self, $data) = @_;
130 0 my $members = $data->{Members};
131 0 my $date = $data->{Date} . 'UTC';
132  
133 0 my (@added, @removed, @modified);
134 0 foreach my $item (@$members) {
135 0 ▶ if ($item =~ CVSPS_MEMBER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item =~ /^\s+(.+):(INITIAL|[\d\.]+)->([\d\.]+)(\(DEAD\))?/) { } 0 0 0
136 0 my ($path, $from_rev, $to_rev, $dead) = ($1, $2, $3, $4);
137 0 my $file = $self->file_class->new(
138 path => $path, revision => $to_rev, project => $self,
139 time => $date);
140 0 ▶ if ($from_rev eq 'INITIAL') {
Branch: 2 branches
BranchTrueFalseTotal
if ($from_rev eq 'INITIAL') { } 0 0 0
elsif ($dead) { } 0 0 0
141 0 push(@added, $file);
142 }
143 elsif ($dead) {
144 0 push(@removed, $file);
145 }
146 else {
147 0 push(@modified, $file);
148 }
149 }
150 else {
151 warn "Failed to parse message item: [$item] for patchset "
152 0 . $data->{PatchSet};
153 }
154 }
155 0 return (\@added, \@removed, \@modified);
156 }
157  
158 0 ▶sub x_cvsps_do {
Subroutine x_cvsps_do: not called CC=4 SCAR=30.0
Pod undocumented
159 0 my ($self, $addl_args) = @_;
160 0 ▶ $addl_args ||= [];
Condition0%0/2
$addl_args ||= []
l!l
00
MC/DC0%0/1
$addl_args ||= []
$addl_args
Truth table0%0/2
A
A= $addl_args
Aresult
11
00
161 0 my @args = (@$addl_args, '-u', '-b', 'HEAD', $self->name);
162 0 my $root = $self->repository->root;
163 0 my $cvsps = $self->vci->x_cvsps;
164
165 0 ▶ if ($self->vci->debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->vci->debug) 0 0 0
166 0 print STDERR "Running CVSROOT=$root $cvsps " . join(' ', @args)
167 . "\n";
168 }
169  
170 # Just using the --root argument of cvsps doesn't work.
171 0 local $ENV{CVSROOT} = $root;
172 0 local $ENV{TZ} = 'UTC';
173 # XXX cvsps must be able to write to $HOME or this will fail.
174 0 my ($success, $error_msg, $all, $stdout, $stderr) =
175 IPC::Cmd::run(command => [$self->vci->x_cvsps, @args]);
176 0 ▶ if (!$success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 0 0
177 0 confess "$error_msg: " . join('', @$stderr);
178 }
179
180 0 return join('', @$stdout);
181 }
182  
183 0 ▶sub DEMOLISH {
Subroutine DEMOLISH: not called CC=2 SCAR=17.9
Pod undocumented
184 0 ▶ File::Path::rmtree($_[0]->x_tmp) if $_[0]->{x_tmp};
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"x_tmp"} 0 0 0
185 }
186  
187 1 __PACKAGE__->meta->make_immutable;
188  
189 1 1;
« VCI/Abstract/Directory.pm ↑ Summary VCI/Abstract/Project.pm »