VCS/CVS.pm

filter: Statementstmt 19.5% 39 / 200 Branchbran 0.0% 0 / 94 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 45.8% 11 / 24 Podpod 77.7% 7 / 9 totaltotal 17.1% 57 / 332 CC 51 SCAR 38.8
CC
51
Cov
13%
_process_cvs_entries
110.0
genchangelog
90.0
checkcommitted
72.0
CRAP 48.4
« VCS.pm ↑ Summary VCS/SVN.pm »
1 package LCFG::Build::VCS::CVS; # -*-perl-*-
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # $Id: CVS.pm.in 35424 2019-01-18 10:01:16Z squinney@INF.ED.AC.UK $
6 # $Source: /var/cvs/dice/LCFG-Build-VCS/lib/LCFG/Build/VCS/CVS.pm.in,v $
7 # $Revision: 35424 $
8 # $HeadURL: https://svn.lcfg.org/svn/source/tags/LCFG-Build-VCS/LCFG_Build_VCS_0_3_9/lib/LCFG/Build/VCS/CVS.pm.in $
9 # $Date: 2019-01-18 10:01:16 +0000 (Fri, 18 Jan 2019) $
10  
11 1 our $VERSION = '0.3.9';
12  
13 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use File::Find ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use File::Path ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use IO::File qw(O_WRONLY O_CREAT O_NONBLOCK O_NOCTTY);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 with 'LCFG::Build::VCS';
24  
25 1 has '+binpath' => ( default => 'cvs' );
26  
27 has 'root' => (
28 is => 'rw',
29 isa => 'Str',
30 lazy => 1,
31 0 ▶ default => sub { _get_root(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 1 );
33  
34 1 has '+id' => ( default => 'CVS' );
35  
36 # This should give a speed-up in loading
37  
38 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 __PACKAGE__->meta->make_immutable;
40  
41 0 ▶sub auto_detect {
Subroutine auto_detect: not called CC=2 SCAR=17.9
Pod documented
42 0 my ( $class, $dir ) = @_;
43  
44 0 my $rootfile = File::Spec->catfile( $dir, 'CVS', 'Root' );
45 0 ▶ my $is_cvs = -f $rootfile ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
-f $rootfile ? : 0 0 0
46  
47 0 return $is_cvs;
48 }
49  
50 0 ▶sub build_cmd {
Subroutine build_cmd: not called CC=2 SCAR=17.9
Pod undocumented
51 0 my ( $self, @args ) = @_;
52  
53 0 my @cmd = ( $self->binpath, '-d', $self->root );
54 0 ▶ if ( $self->quiet ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->quiet) 0 0 0
55 0 push @cmd, '-Q';
56 }
57 0 push @cmd, @args;
58  
59 0 return @cmd;
60 }
61  
62 0 ▶sub _get_root {
Subroutine _get_root: not called CC=3 SCAR=24.8
63 0 my ($self) = @_;
64  
65 0 my $root;
66  
67 0 my $rootfile = File::Spec->catfile( $self->workdir, 'CVS', 'Root' );
68 0 ▶ if ( -f $rootfile ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $rootfile) 0 0 0
69 0 eval {
70 0 my $fh = IO::File->new( $rootfile, 'r' );
71 0 chomp( $root = $fh->getline );
72 0 $fh->close;
73 };
74 }
75  
76 0 ▶ if ( !$root ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($root) 0 0 0
77 0 $root = $ENV{CVSROOT};
78 }
79  
80 0 return $root;
81 }
82  
83 0 ▶sub genchangelog {
Subroutine genchangelog: not called CC=9 SCAR=45.0
Pod documented
84 0 my ($self) = @_;
85  
86 0 my $dir = $self->workdir;
87 0 my $logfile = $self->logfile;
88  
89 0 my $orig_dir = Cwd::abs_path();
90 0 ▶ chdir $dir or die "gen: Could not access directory, $dir: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $dir or die "gen: Could not access directory, ${dir}: $!\n" 0 0 0
91  
92 0 ▶ if ( !-e $logfile ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $logfile) 0 0 0
93  
94 # This bit borrowed from File::Touch
95 0 ▶ sysopen my $fh, $logfile, O_WRONLY | O_CREAT | O_NONBLOCK | O_NOCTTY
Branch: 1 branch
BranchTrueFalseTotal
sysopen my $fh, $logfile, 2369 or die "Cannot create $logfile : $!\n" 0 0 0
96 or die "Cannot create $logfile : $!\n";
97 0 ▶ $fh->close or die "Cannot close $logfile : $!\n";
Branch: 1 branch
BranchTrueFalseTotal
$fh->close or die "Cannot close $logfile : $!\n" 0 0 0
98  
99 # Assume it is not already part of the repository
100 0 $self->run_cmd( 'add', $logfile );
101 }
102  
103 0 my $cmd = 'cvs2cl --hide-filenames --accum --file ' . $logfile;
104  
105 0 ▶ if ( $self->quiet ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->quiet) 0 0 0
106 0 $cmd .= ' --global-opts \'-Q\'';
107 }
108  
109 # This requires a full shell to actually work, I think the cvs
110 # command is the root cause.
111  
112 0 ▶ if ( $self->dryrun ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dryrun) { } 0 0 0
113 0 print "Dry-run: $cmd\n";
114 }
115 else {
116 0 system $cmd;
117 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
118 0 die "Could not run cvs2cl: $!\n";
119 }
120 }
121  
122 0 ▶ chdir $orig_dir
Branch: 1 branch
BranchTrueFalseTotal
chdir $orig_dir or die "Could not return to original directory, ${orig_dir}: $!\n" 0 0 0
123 or die "Could not return to original directory, $orig_dir: $!\n";
124  
125 0 return;
126 }
127  
128 0 ▶sub checkcommitted {
Subroutine checkcommitted: not called CC=8 SCAR=42.8
Pod documented
129 0 my ($self) = @_;
130  
131 0 my $orig_dir = Cwd::abs_path();
132  
133 0 my $dir = $self->workdir;
134 0 ▶ chdir $dir or die "check: Could not access directory, $dir: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $dir or die "check: Could not access directory, ${dir}: $!\n" 0 0 0
135  
136 0 my @status = $self->run_cmd('status');
137  
138 0 my @notcommitted;
139 0 for my $line (@status) {
140 0 ▶ if ( $line =~ m/^File: (.+?)\s+Status: (.+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^File: (.+?)\s+Status: (.+)$/) 0 0 0
141 0 my ( $file, $status ) = ( $1, $2 );
142 0 ▶ if ( $status !~ m/Up-to-date/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($status =~ /Up-to-date/) 0 0 0
143 0 push @notcommitted, $file;
144 }
145 }
146 }
147  
148 0 ▶ chdir $orig_dir
Branch: 1 branch
BranchTrueFalseTotal
chdir $orig_dir or die "Could not return to original directory, ${orig_dir}: $!\n" 0 0 0
149 or die "Could not return to original directory, $orig_dir: $!\n";
150  
151 0 my $allcommitted;
152 0 ▶ if ( scalar @notcommitted > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @notcommitted > 0) { } 0 0 0
153 0 $allcommitted = 0;
154 }
155 else {
156 0 $allcommitted = 1;
157 }
158  
159 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
160 0 return ( $allcommitted, @notcommitted );
161 }
162 else {
163 0 return $allcommitted;
164 }
165 }
166  
167 0 ▶sub tagversion {
Subroutine tagversion: not called CC=6 SCAR=37.4
Pod documented
168 0 my ( $self, $version ) = @_;
169  
170 0 $self->update_changelog($version);
171  
172 0 my $tag = $self->gen_tag($version);
173  
174 0 my $orig_dir = Cwd::abs_path();
175  
176 0 my $dir = $self->workdir;
177 0 ▶ chdir $dir or die "tag: Could not access directory, $dir: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $dir or die "tag: Could not access directory, ${dir}: $!\n" 0 0 0
178  
179 0 eval { $self->run_cmd( 'commit', '-m', "Release: $version" ) };
180 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
181 0 die "Could not mark release for $dir at $version\n";
182 }
183  
184 0 eval { $self->run_cmd( 'tag', '-F', '-c', $tag ) };
185 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
186 0 die "Could not tag $dir with $tag\n";
187 }
188  
189 0 eval { $self->run_cmd( 'tag', '-F', '-c', 'latest' ) };
190 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
191 0 die "Could not tag $dir as latest\n";
192 }
193  
194 0 ▶ chdir $orig_dir
Branch: 1 branch
BranchTrueFalseTotal
chdir $orig_dir or die "Could not return to original directory, ${orig_dir}: $!\n" 0 0 0
195 or die "Could not return to original directory, $orig_dir: $!\n";
196  
197 0 return;
198 }
199  
200 0 ▶sub _process_cvs_entries {
Subroutine _process_cvs_entries: not called CC=10 SCAR=47.0
201 0 my ( $workdir, $entries ) = @_;
202  
203 0 my $path = $File::Find::name;
204  
205 0 ▶ if ( -f $path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $path) 0 0 0
206 0 my ( $vol, $dirname, $basename ) = File::Spec->splitpath($path);
207 0 my @dirs = File::Spec->splitdir($dirname);
208  
209 # If the last element of the directory list is empty throw it away
210 0 ▶ if ( length $dirs[-1] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $dirs[-1] == 0) 0 0 0
211 0 pop @dirs;
212 }
213  
214 0 ▶ if ( $dirs[-1] eq 'CVS' && $basename eq 'Entries' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirs[-1] eq "CVS" and $basename eq "Entries") 0 0 0
Condition0%0/3
$dirs[-1] eq "CVS" and $basename eq "Entries"
!ll&&!rl&&r
000
MC/DC0%0/2
$dirs[-1] eq "CVS" and $basename eq "Entries"
$dirs[-1] eq "CVS" $basename eq "Entries"
Truth table0%0/3
A and B
A= $dirs[-1] eq "CVS"B= $basename eq "Entries"
ABresult
0X0
100
111
215 0 pop @dirs; # remove the 'CVS' directory
216  
217 # This is a (hopefully) system-independent way of removing
218 # the working directory from the front of the current
219 # directory name to produce relative filenames.
220  
221 0 ▶ for ( my $i=0; $i<scalar(@{$workdir}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$workdir;}) 0 0 0
222 0 ▶ if ( $dirs[0] eq $workdir->[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirs[0] eq $workdir->[$i]) { } 0 0 0
223 0 shift @dirs;
224 }
225 else {
226 0 last;
227 }
228 }
229  
230 0 my $dir = File::Spec->catdir(@dirs);
231  
232 0 ▶ my $fh = IO::File->new( $path, 'r' )
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new($path, "r") or die "Could not open $path for reading: $!\n" 0 0 0
233 or die "Could not open $path for reading: $!\n";
234 0 ▶ while ( defined( my $entry = $fh->getline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = $fh->getline)) 0 0 0
235  
236 0 ▶ if ( $entry =~ m{^/ # Line starts with a forward slash
Branch: 1 branch
BranchTrueFalseTotal
if ($entry =~ m[^/ # Line starts with a forward slash ([^/]+) # Stuff which is not a forward slash / # Another forward slash \d # Any digit (avoids deleted files) ]x) 0 0 0
237 ([^/]+) # Stuff which is not a forward slash
238 / # Another forward slash
239 \d # Any digit (avoids deleted files)
240 }x ) {
241 0 push @{$entries}, [ $dir, $1 ];
242 }
243 }
244 0 $fh->close;
245 }
246 }
247  
248 0 return;
249 }
250  
251 0 ▶sub export_devel {
Subroutine export_devel: not called CC=5 SCAR=34.0
Pod documented
252 0 my ( $self, $version, $builddir ) = @_;
253  
254 0 my $workdir = $self->workdir;
255 0 my $target = join q{-}, $self->module, $version;
256  
257 0 my $exportdir = File::Spec->catdir( $builddir, $target );
258  
259 0 ▶ if ( !$self->dryrun ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->dryrun) 0 0 0
260 0 File::Path::rmtree($exportdir);
261 0 eval { File::Path::mkpath($exportdir) };
262 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
263 0 die "Could not create $exportdir: $@\n";
264 }
265 }
266  
267 0 my @workdir = File::Spec->splitdir($workdir);
268 # If the last element of the directory list is empty throw it away
269 0 ▶ if ( length $workdir[-1] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $workdir[-1] == 0) 0 0 0
270 0 pop @workdir;
271 }
272  
273 0 my @entries;
274 File::Find::find(
275 0 ▶ { wanted => sub { _process_cvs_entries( \@workdir, \@entries ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
276 0 no_chdir => 1,
277 },
278 $workdir
279 );
280  
281 0 for my $entry (@entries) {
282 0 $self->mirror_file( $workdir, $exportdir, @{$entry} );
283 }
284  
285 0 return $exportdir;
286 }
287  
288 0 ▶sub export {
Subroutine export: not called CC=7 SCAR=40.3
Pod documented
289 0 my ( $self, $version, $builddir ) = @_;
290  
291 0 my $tag = $self->gen_tag($version);
292  
293 0 my $target = join q{-}, $self->module, $version;
294 0 my $exportdir = File::Spec->catdir( $builddir, $target );
295  
296 0 ▶ if ( !$self->dryrun ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->dryrun) 0 0 0
297 0 ▶ if ( !-d $builddir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $builddir) 0 0 0
298 0 eval { File::Path::mkpath($builddir) };
299 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
300 0 die "Could not create $builddir: $@\n";
301 }
302 }
303  
304 0 ▶ if ( -d $exportdir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $exportdir) 0 0 0
305 0 File::Path::rmtree($exportdir);
306 }
307 }
308  
309 0 my $orig_dir = Cwd::abs_path();
310  
311 0 ▶ chdir $builddir
Branch: 1 branch
BranchTrueFalseTotal
chdir $builddir or die "export: Could not access directory, ${builddir}: $!\n" 0 0 0
312 or die "export: Could not access directory, $builddir: $!\n";
313  
314 0 $self->run_cmd( 'export', '-r', $tag, '-d', $target, $self->module );
315  
316 0 ▶ chdir $orig_dir
Branch: 1 branch
BranchTrueFalseTotal
chdir $orig_dir or die "Could not return to original directory, ${orig_dir}: $!\n" 0 0 0
317 or die "Could not return to original directory, $orig_dir: $!\n";
318  
319 0 return $exportdir;
320 }
321  
322 0 ▶sub checkout_project {
Subroutine checkout_project: not called CC=5 SCAR=34.0
Pod undocumented
323 0 my ( $self, $version, $outdir ) = @_;
324  
325 0 ▶ if ( !defined $outdir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $outdir) 0 0 0
326 0 $outdir = '.';
327 }
328  
329 0 my @args;
330 0 ▶ if ( defined $version ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $version) 0 0 0
331 0 my $tag = $self->gen_tag($version);
332  
333 0 @args = ( 'r', $tag );
334 }
335  
336 0 my $orig_dir = Cwd::abs_path();
337  
338 0 ▶ chdir $outdir or die "tag: Could not access directory, $outdir: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $outdir or die "tag: Could not access directory, ${outdir}: $!\n" 0 0 0
339  
340 0 $self->run_cmd( 'checkout', @args, $self->module );
341  
342 0 ▶ chdir $orig_dir
Branch: 1 branch
BranchTrueFalseTotal
chdir $orig_dir or die "Could not return to original directory, ${orig_dir}: $!\n" 0 0 0
343 or die "Could not return to original directory, $orig_dir: $!\n";
344  
345 0 return;
346 }
347  
348 0 ▶sub import_project {
Subroutine import_project: not called CC=4 SCAR=30.0
Pod documented
349 0 my ( $self, $dir, $version, $message ) = @_;
350  
351 0 ▶ if ( !defined $message ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $message) 0 0 0
352 0 $message = 'Imported with LCFG build tools';
353 }
354  
355 0 my $vendor_tag = $self->gen_tag();
356 0 my $release_tag = $self->gen_tag($version);
357  
358 0 my $orig_dir = Cwd::abs_path();
359  
360 0 ▶ chdir $dir or die "tag: Could not access directory, $dir: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $dir or die "tag: Could not access directory, ${dir}: $!\n" 0 0 0
361  
362 0 $self->run_cmd( 'import',
363 '-I', '!',
364 '-m', $message,
365 $self->module, $vendor_tag, $release_tag );
366  
367 0 ▶ chdir $orig_dir
Branch: 1 branch
BranchTrueFalseTotal
chdir $orig_dir or die "Could not return to original directory, ${orig_dir}: $!\n" 0 0 0
368 or die "Could not return to original directory, $orig_dir: $!\n";
369  
370 0 return;
371 }
372  
373 1 1;
374 __END__
« VCS.pm ↑ Summary VCS/SVN.pm »