blib/lib/App/KGB/Client/CVS.pm

filter: Statementstmt 34.5% 28 / 81 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 80.0% 8 / 10 Podpod 100% 2 / 2 totaltotal 24.8% 38 / 153 CC 30 SCAR 64.7
CC
30
Cov
21%
describe_commit
870.0
new
6.0
BEGIN
1.0
CRAP 647.4
« blib/lib/App/KGB/Client/Git.pm ↑ Summary blib/lib/App/KGB/Client.pm »
1 package App::KGB::Client::CVS;
2 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = 1.23;
8  
9 # vim: ts=4:sw=4:et:ai:sts=4
10 #
11 # KGB - an IRC bot helping collaboration -- CVS support
12 # Copyright © 2012 Damyan Ivanov
13 #
14 # This program is free software; you can redistribute it and/or modify it under
15 # the terms of the GNU General Public License as published by the Free Software
16 # Foundation; either version 2 of the License, or (at your option) any later
17 # version.
18 #
19 # This program is distributed in the hope that it will be useful, but WITHOUT
20 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22 # details.
23 #
24 # You should have received a copy of the GNU General Public License along with
25 # this program; if not, write to the Free Software Foundation, Inc., 51
26 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27  
28 =head1 NAME
29  
30 App::KGB::Client::CVS - KGB interface to CVS
31  
32 =head1 SYNOPSIS
33  
34 use App::KGB::Client::CVS;
35 my $client = App::KGB::Client::CVS(
36 # common App::KGB::Client parameters
37 repo_id => 'my-repo',
38 ...
39 # CVS-specific
40 cvs_root => $ENV{CVSROOT},
41 author => $ENV{USER},
42 directory => 'module/dir',
43 );
44 $client->run;
45  
46 =head1 DESCRIPTION
47  
48 B<App::KGB::Client::CVS> provides CVS-specific retrieval of
49 commits and changes for L<App::KGB::Client>.
50  
51 =head1 CONSTRUCTOR
52  
53 =head2 B<new> ( { initializers } )
54  
55 Standard constructor. Accepts inline hash with initial field values.
56  
57 =head1 FIELDS
58  
59 App:KGB::Client::CVS defines the following additional fields:
60  
61 =over
62  
63 =item B<cvs_root> (B<mandatory>)
64  
65 Physical path to the CVS root directory.
66  
67 =item B<author>
68  
69 The user name of the commit author.
70  
71 =item B<directory>
72  
73 Relative (to CVS root) path to the directory this change is in.
74  
75 As a convention, the first path member is taken as a module.
76  
77 =back
78  
79 =head1 METHODS
80  
81 =over
82  
83 =item describe_commit
84  
85 The first time this method is called, it parses STDIN and determines commit
86 contents, returning an instance of L<App::KGB::Commit> class describing the
87 commit.
88  
89 All subsequential invocations return B<undef>.
90  
91 =back
92  
93 =cut
94  
95 1 require v5.10.0;
96 1 ▶use base 'App::KGB::Client';
Subroutine BEGIN: called CC=1 SCAR=0.0
97 1 ▶use App::KGB::Change;
Subroutine BEGIN: called CC=1 SCAR=0.0
98 1 ▶use App::KGB::Commit;
Subroutine BEGIN: called CC=1 SCAR=0.0
99 1 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
100 1 __PACKAGE__->mk_accessors(qw( _called author cvs_root directory ));
101  
102 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
103 0 my $class = shift;
104 0 my $self = $class->SUPER::new(@_);
105 0 $self->_called(0);
106  
107 0 ▶ defined( $self->cvs_root )
Branch: 1 branch
BranchTrueFalseTotal
defined $self->cvs_root or confess("'cvs_root' is mandatory") 0 0 0
108 or confess "'cvs_root' is mandatory";
109  
110 0 return $self;
111 }
112  
113 1 ▶use Fcntl qw(:flock);
Subroutine BEGIN: called CC=1 SCAR=0.0
114  
115 0 ▶sub describe_commit {
Subroutine describe_commit: not called CC=29 SCAR=67.7
Pod documented
116 0 my ($self) = @_;
117  
118 0 ▶ return undef if $self->_called;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_called 0 0 0
119  
120 0 my $merge_file = File::Spec->catfile( $self->cvs_root, 'CVSROOT',
121 sprintf( 'kgb-client-%d-%d.tmp', $<, getpgrp() ) );
122  
123 0 ▶ open(MERGE, ">>$merge_file") or die "Unable to open $merge_file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open MERGE, ">>$merge_file" or die "Unable to open ${merge_file}: $!\n" 0 0 0
124  
125 0 my $first_dir_in_commit = flock( MERGE, LOCK_EX | LOCK_NB );
126  
127 0 my ( $tag, $log, @changes );
128 # the first element is module, the rest - directory path
129 0 my ($module, $dir) = $self->directory =~ m{([^/]+)(/.+)?};
130 0 ▶ $dir //= '';
Condition0%0/2
$dir //= ""
l!l
00
MC/DC0%0/1
$dir //= ""
$dir
Truth table0%0/2
A
A= $dir
Aresult
11
00
131 0 ▶ $dir .= '/' if $dir;
Branch: 1 branch
BranchTrueFalseTotal
if $dir 0 0 0
132  
133 0 ▶ while ( defined( my $line = <> ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline ARGV)) 0 0 0
134 0 ▶ $tag = $1, next if $line =~ /^\s*Tag: ([a-zA-Z0-9_-]+)/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*Tag: ([a-zA-Z0-9_-]+)/ 0 0 0
135  
136 0 ▶ if ( $line =~ /^Added Files:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Added Files:/) 0 0 0
137 0 ▶ while ( defined( $line = <> ) and $line =~ /^\s+(.+?)\s?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline ARGV) and $line =~ /^\s+(.+?)\s?$/) 0 0 0
Condition0%0/3
defined($line = readline ARGV) and $line =~ /^\s+(.+?)\s?$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined($line = readline ARGV) and $line =~ /^\s+(.+?)\s?$/
defined($line = readline ARGV) $line =~ /^\s+(.+?)\s?$/
Truth table0%0/3
A and B
A= defined($line = readline ARGV)B= $line =~ /^\s+(.+?)\s?$/
ABresult
0X0
100
111
138 0 my $files = $1;
139 push @changes,
140 App::KGB::Change->new(
141 { action => 'A',
142 path => "$dir$_",
143 }
144 0 ) for split( /\s+/, $files );
145 }
146 0 redo;
147 }
148 0 ▶ if ( $line =~ /^Modified Files:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Modified Files:/) 0 0 0
149 0 ▶ while ( defined( $line = <> ) and $line =~ /^\s+(.+?)\s?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline ARGV) and $line =~ /^\s+(.+?)\s?$/) 0 0 0
Condition0%0/3
defined($line = readline ARGV) and $line =~ /^\s+(.+?)\s?$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined($line = readline ARGV) and $line =~ /^\s+(.+?)\s?$/
defined($line = readline ARGV) $line =~ /^\s+(.+?)\s?$/
Truth table0%0/3
A and B
A= defined($line = readline ARGV)B= $line =~ /^\s+(.+?)\s?$/
ABresult
0X0
100
111
150 0 my $files = $1;
151 push @changes,
152 App::KGB::Change->new(
153 { action => 'M',
154 path => "$dir$_",
155 }
156 0 ) for split( /\s+/, $files );
157 }
158 0 redo;
159 }
160 0 ▶ if ( $line =~ /^Removed Files:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Removed Files:/) 0 0 0
161 0 ▶ while ( defined( $line = <> ) and $line =~ /^\s+(.+?)\s?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline ARGV) and $line =~ /^\s+(.+?)\s?$/) 0 0 0
Condition0%0/3
defined($line = readline ARGV) and $line =~ /^\s+(.+?)\s?$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined($line = readline ARGV) and $line =~ /^\s+(.+?)\s?$/
defined($line = readline ARGV) $line =~ /^\s+(.+?)\s?$/
Truth table0%0/3
A and B
A= defined($line = readline ARGV)B= $line =~ /^\s+(.+?)\s?$/
ABresult
0X0
100
111
162 0 my $files = $1;
163 push @changes,
164 App::KGB::Change->new(
165 { action => 'D',
166 path => "$dir$_",
167 }
168 0 ) for split( /\s+/, $files );
169 }
170 0 redo;
171 }
172 0 ▶ last if $line =~ /^Log Message/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^Log Message/ 0 0 0
173 }
174  
175 0 ▶ while(defined(my $line = <>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline ARGV)) 0 0 0
176 0 $log .= $line;
177 }
178  
179 0 my $root = $self->cvs_root;
180 0 ▶ $log =~ s{$root/}{} if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 0 0 0
181  
182 0 print MERGE "$_\n" for @changes;
183  
184 0 ▶ unless ($first_dir_in_commit) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($first_dir_in_commit) 0 0 0
185 0 close(MERGE);
186 0 return undef;
187 }
188  
189 0 ▶ return if fork(); # parent process exits
Branch: 1 branch
BranchTrueFalseTotal
if fork 0 0 0
190  
191 #warn "$$ waiting\n";
192 # wait for the merge file to settle
193 0 ▶ while( time() - (stat(MERGE))[9] < 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (time - (stat MERGE)[9] < 3) 0 0 0
194 0 sleep(1);
195 }
196  
197 0 close(MERGE);
198 0 ▶ open(MERGE, $merge_file) or die "Error reopening $merge_file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open MERGE, $merge_file or die "Error reopening ${merge_file}: $!\n" 0 0 0
199 0 ▶ unlink $merge_file or warn "Error removing $merge_file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
unlink $merge_file or warn "Error removing ${merge_file}: $!\n" 0 0 0
200  
201 0 @changes = ();
202  
203 0 ▶ while ( defined( my $line = <MERGE> ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline MERGE)) 0 0 0
204 0 chomp($line);
205 0 push @changes, App::KGB::Change->new($line);
206 }
207 0 close(MERGE);
208  
209 0 $self->_called(1);
210  
211 0 return App::KGB::Commit->new(
212 { changes => \@changes,
213 author => $self->author,
214 author_name => $self->_get_full_user_name( $self->author ),
215 log => $log,
216 module => $module,
217 }
218 );
219 }
220  
221 1 1;
« blib/lib/App/KGB/Client/Git.pm ↑ Summary blib/lib/App/KGB/Client.pm »