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 7 $Git::FastExport::VERSION = '0.106';
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 ▶use Git::Repository;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Git::FastExport::Block;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 7 my $LF = "\012";
12  
13 sub new {
14 62 ▶ my ( $class, $handle ) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
15 62 return bless { stream => $handle }, $class;
16 }
17  
18 sub next_block {
19 1070 ▶ my ($self) = @_;
Subroutine next_block: called CC=14 SCAR=26.7
Pod documented
20 1070 my $fh = $self->{stream};
21 1070 ▶ return if !defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 1 1069 1070
22  
23 1069 my $block = bless {}, 'Git::FastExport::Block';
24  
25 # pick up the header from the previous round, or read it (first time)
26 1069 ▶ $self->{header} ||= <$fh>;
Condition100%3/3
$self->{"header"} ||= readline $fh
l!l&&r!l&&!r
9496060
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 1069 $block->{header} = delete $self->{header};
28  
29 # nothing left to process
30 1069 ▶ return if !defined $block->{header};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $block->{"header"} 60 1009 1069
31  
32 1009 chomp $block->{header};
33 1009 ( $block->{type} ) = $block->{header} =~ /^(\w+)/g;
34  
35 1009 local $_;
36 1009 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 3391 59 3450
37  
38 # we've reached the beginning of the next block
39 3391 ▶ 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/) 950 2441 3391
40 950 ▶ s/^progress /progress [$self->{source}] / if exists $self->{source};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"source"} 0 950 950
41 950 $self->{header} = $_;
42 950 last;
43 }
44  
45 2441 chomp;
46  
47 # special case of data block
48 2441 ▶ if (/^data (.*)/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^data (.*)/) { } 485 1956 2441
elsif (/^(?:[MDRC] |deleteall)/) { } 220 1736 1956
elsif (/^(\w+)/) { } 1250 486 1736
49 485 ▶ if ( substr( $1, 0, 2 ) eq '<<' ) { # Delimited format
Branch: 1 branch
BranchTrueFalseTotal
if (substr($1, 0, 2) eq '<<') { } 0 485 485
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 485 my $bytes = $1;
64 485 ▶ if ($bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bytes) { } 485 0 485
65 485 local $/ = \$bytes;
66 485 $block->{data} = <$fh>;
67 }
68 else {
69 0 $block->{data} = "";
70 }
71 }
72 }
73 elsif (/^(?:[MDRC] |deleteall)/) {
74 220 push @{ $block->{files} }, $_;
75 }
76 elsif (/^(\w+)/) {
77 1250 push @{ $block->{$1} }, $_;
78 }
79 else {
80  
81 # ignore empty lines, but choke on others
82 486 ▶ die "Unexpected line:\n$_\n" if !/^$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^$/ 0 486 486
83 486 $block->{footer} .= "\012";
84 }
85 }
86  
87 # post-processing
88 1009 ▶ if ( $block->{type} eq 'commit' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($block->{"type"} eq "commit") 258 751 1009
89 ( $block->{committer_date} )
90 258 = $block->{committer}[0] =~ /^committer [^>]*> (\d+) [-+]\d+$/g;
91 ( $block->{author_date} )
92 258 = $block->{author}[0] =~ /^author [^>]*> (\d+) [-+]\d+$/g;
93 }
94  
95 1009 return $block;
96 }
97  
98 7 'progress 1 objects';
99  
100 __END__
« FastExport/Stitch.pm ↑ Summary FastExport/Block.pm »