FastExport.pm

filter: Statementstmt 93.2% 55 / 59 Branchbran 83.3% 20 / 24 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 91.8% 90 / 98 CC 14 SCAR 23.0
CC
14
Cov
91%
next_block
14.4
BEGIN
1.0
BEGIN
1.0
CRAP 9.9
« FastExport/Stitch.pm ↑ Summary FastExport/Block.pm »
1 package Git::FastExport;
2 6 $Git::FastExport::VERSION = '0.108';
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 ▶use Git::Repository;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Git::FastExport::Block;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 my $LF = "\012";
12  
13 66 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
14 66 my ( $class, $handle ) = @_;
15 66 return bless { stream => $handle }, $class;
16 }
17  
18 682 ▶sub next_block {
Subroutine next_block: called CC=14 SCAR=26.7
Pod documented
19 682 my ($self) = @_;
20 682 my $fh = $self->{stream};
21 682 ▶ return if !defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 1 681 682
22  
23 681 my $block = bless {}, 'Git::FastExport::Block';
24  
25 # pick up the header from the previous round, or read it (first time)
26 681 ▶ $self->{header} ||= <$fh>;
Condition100%3/3
$self->{"header"} ||= readline $fh
l!l&&r!l&&!r
5536464
MC/DC100%2/2
$self->{"header"} ||= readline $fh
$self->{"header"} readline $fh
Truth table100%3/3
A ||= B
A= $self->{"header"}B= readline $fh
ABresult
1X1
011
000
27 681 $block->{header} = delete $self->{header};
28  
29 # nothing left to process
30 681 ▶ return if !defined $block->{header};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $block->{"header"} 64 617 681
31  
32 617 chomp $block->{header};
33 617 ( $block->{type} ) = $block->{header} =~ /^(\w+)/g;
34  
35 617 local $_;
36 617 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 2224 63 2287
37  
38 # we've reached the beginning of the next block
39 2224 ▶ if (/^(commit|tag|reset|blob|checkpoint|progress|feature|option|done)\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(commit|tag|reset|blob|checkpoint|progress|feature|option|done)\b/) 554 1670 2224
40 554 ▶ s/^progress /progress [$self->{source}] / if exists $self->{source};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"source"} 0 554 554
41 554 $self->{header} = $_;
42 554 last;
43 }
44  
45 1670 chomp;
46  
47 # special case of data block
48 1670 ▶ if (/^data (.*)/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^data (.*)/) { } 286 1384 1670
elsif (/^(?:[MDRC] |deleteall)/) { } 8 1376 1384
elsif (/^(\w+)/) { } 1089 287 1376
49 286 ▶ if ( substr( $1, 0, 2 ) eq '<<' ) { # Delimited format
Branch: 1 branch
BranchTrueFalseTotal
if (substr($1, 0, 2) eq '<<') { } 0 286 286
50  
51 # 'data' SP '<<' <delim> LF
52 # <raw> LF
53 # <delim> LF
54 # LF?
55 0 my $delim = substr( $1, 2 );
56 0 local $/ = "$LF$delim$LF";
57 0 chomp( $block->{data} = <$fh> );
58 }
59 else { # Exact byte count format
60  
61 # 'data' SP <count> LF
62 # <raw> LF?
63 286 my $bytes = $1;
64 286 ▶ if ($bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bytes) { } 286 0 286
65 286 local $/ = \$bytes;
66 286 $block->{data} = <$fh>;
67 }
68 else {
69 0 $block->{data} = "";
70 }
71 }
72 }
73 elsif (/^(?:[MDRC] |deleteall)/) {
74 8 push @{ $block->{files} }, $_;
75 }
76 elsif (/^(\w+)/) {
77 1089 push @{ $block->{$1} }, $_;
78 }
79 else {
80  
81 # ignore empty lines, but choke on others
82 287 ▶ die "Unexpected line:\n$_\n" if !/^$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^$/ 0 287 287
83 287 $block->{footer} .= "\012";
84 }
85 }
86  
87 # post-processing
88 617 ▶ if ( $block->{type} eq 'commit' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($block->{"type"} eq "commit") 272 345 617
89 ( $block->{committer_date} )
90 272 = $block->{committer}[0] =~ /^committer [^>]*> (\d+) [-+]\d+$/g;
91 ( $block->{author_date} )
92 272 = $block->{author}[0] =~ /^author [^>]*> (\d+) [-+]\d+$/g;
93 }
94  
95 617 return $block;
96 }
97  
98 6 'progress 1 objects';
99  
100 __END__
« FastExport/Stitch.pm ↑ Summary FastExport/Block.pm »