PurePerl/Pack/WithoutIndex.pm

filter: Statementstmt 16.6% 13 / 78 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 50.0% 3 / 6 Podpod 0.0% 0 / 3 totaltotal 10.3% 16 / 155 CC 30 SCAR 53.3
CC
30
Cov
10%
create_index
240.0
create_index_offsets
240.0
get_object
6.0
CRAP 206.1
↑ Summary PurePerl/Protocol.pm »
1 package Git::PurePerl::Pack::WithoutIndex;
2 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 extends 'Git::PurePerl::Pack';
7  
8 4 has 'offsets' => ( is => 'rw', isa => 'HashRef', required => 0 );
9  
10 4 my @TYPES = ( 'none', 'commit', 'tree', 'blob', 'tag', '', 'ofs_delta',
11 'ref_delta' );
12  
13 0 ▶sub create_index {
Subroutine create_index: not called CC=15 SCAR=54.8
Pod undocumented
14 0 my ($self) = @_;
15 0 my $index_filename = $self->filename;
16 0 $index_filename =~ s/\.pack/.idx/;
17 0 ▶ my $index_fh = IO::File->new("> $index_filename") || die $!;
Condition0%0/2
'IO::File'->new("> $index_filename") || die($!)
l!l
00
MC/DC0%0/1
'IO::File'->new("> $index_filename") || die($!)
'IO::File'->new("> $index_filename")
Truth table0%0/2
A
A= 'IO::File'->new("> $index_filename")
Aresult
11
00
18  
19 0 my $iod = IO::Digest->new( $index_fh, 'SHA' );
20  
21 0 my $offsets = $self->create_index_offsets;
22 0 my @fan_out_table;
23 0 foreach my $sha1 ( sort keys %$offsets ) {
24 0 my $offset = $offsets->{$sha1};
25 0 my $slot = unpack( 'C', pack( 'H*', $sha1 ) );
26 0 $fan_out_table[$slot]++;
27 }
28 0 foreach my $i ( 0 .. 255 ) {
29 0 ▶ $index_fh->print( pack( 'N', $fan_out_table[$i] || 0 ) ) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
$index_fh->print(pack("N", $fan_out_table[$i] || 0)) or die $! 0 0 0
Condition0%0/2
$fan_out_table[$i] || 0
l!l
00
MC/DC0%0/1
$fan_out_table[$i] || 0
$fan_out_table[$i]
Truth table0%0/2
A
A= $fan_out_table[$i]
Aresult
11
00
30 0 ▶ $fan_out_table[ $i + 1 ] += $fan_out_table[$i] || 0;
Condition0%0/2
$fan_out_table[$i] || 0
l!l
00
MC/DC0%0/1
$fan_out_table[$i] || 0
$fan_out_table[$i]
Truth table0%0/2
A
A= $fan_out_table[$i]
Aresult
11
00
31 }
32 0 foreach my $sha1 ( sort keys %$offsets ) {
33 0 my $offset = $offsets->{$sha1};
34 0 ▶ $index_fh->print( pack( 'N', $offset ) ) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
$index_fh->print(pack("N", $offset)) or die $! 0 0 0
35 0 ▶ $index_fh->print( pack( 'H*', $sha1 ) ) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
$index_fh->print(pack("H*", $sha1)) or die $! 0 0 0
36 }
37  
38 # read the pack checksum from the end of the pack file
39 0 my $size = -s $self->filename;
40 0 my $fh = $self->fh;
41 0 ▶ $fh->seek( $size - 20, 0 ) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
$fh->seek($size - 20, 0) or die $! 0 0 0
42 0 ▶ my $read = $fh->read( my $pack_sha1, 20 ) || die $!;
Condition0%0/2
$fh->read(my $pack_sha1, 20) || die($!)
l!l
00
MC/DC0%0/1
$fh->read(my $pack_sha1, 20) || die($!)
$fh->read(my $pack_sha1, 20)
Truth table0%0/2
A
A= $fh->read(my $pack_sha1, 20)
Aresult
11
00
43  
44 0 ▶ $index_fh->print($pack_sha1) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
$index_fh->print($pack_sha1) or die $! 0 0 0
45 0 ▶ $index_fh->print( $iod->digest ) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
$index_fh->print($iod->digest) or die $! 0 0 0
46  
47 0 ▶ $index_fh->close() || die $!;
Branch: 1 branch
BranchTrueFalseTotal
$index_fh->close or die $! 0 0 0
48 }
49  
50 0 ▶sub create_index_offsets {
Subroutine create_index_offsets: not called CC=15 SCAR=54.8
Pod undocumented
51 0 my ($self) = @_;
52 0 my $fh = $self->fh;
53  
54 0 $fh->read( my $signature, 4 );
55 0 $fh->read( my $version, 4 );
56 0 $version = unpack( 'N', $version );
57 0 $fh->read( my $objects, 4 );
58 0 $objects = unpack( 'N', $objects );
59  
60 0 my %offsets;
61 0 $self->offsets( \%offsets );
62  
63 0 foreach my $i ( 1 .. $objects ) {
64 0 ▶ my $offset = $fh->tell || die "Error telling filehandle: $!";
Condition0%0/2
$fh->tell || die("Error telling filehandle: $!")
l!l
00
MC/DC0%0/1
$fh->tell || die("Error telling filehandle: $!")
$fh->tell
Truth table0%0/2
A
A= $fh->tell
Aresult
11
00
65 0 my $obj_offset = $offset;
66 0 ▶ $fh->read( my $c, 1 ) || die "Error reading from pack: $!";
Branch: 1 branch
BranchTrueFalseTotal
$fh->read(my $c, 1) or die "Error reading from pack: $!" 0 0 0
67 0 ▶ $c = unpack( 'C', $c ) || die $!;
Condition0%0/2
unpack('C', $c) || die($!)
l!l
00
MC/DC0%0/1
unpack('C', $c) || die($!)
unpack('C', $c)
Truth table0%0/2
A
A= unpack('C', $c)
Aresult
11
00
68 0 $offset++;
69  
70 0 my $size = ( $c & 0xf );
71 0 my $type_number = ( $c >> 4 ) & 7;
72 0 ▶ my $type = $TYPES[$type_number]
Condition0%0/2
$TYPES[$type_number] || confess("invalid type $type_number at offset $offset, size $size")
l!l
00
MC/DC0%0/1
$TYPES[$type_number] || confess("invalid type $type_number at offset $offset, size $size")
$TYPES[$type_number]
Truth table0%0/2
A
A= $TYPES[$type_number]
Aresult
11
00
73 || confess
74 "invalid type $type_number at offset $offset, size $size";
75  
76 0 my $shift = 4;
77  
78 0 ▶ while ( ( $c & 0x80 ) != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($c & 128) != 0) 0 0 0
79 0 ▶ $fh->read( $c, 1 ) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
$fh->read($c, 1) or die $! 0 0 0
80 0 ▶ $c = unpack( 'C', $c ) || die $!;
Condition0%0/2
unpack('C', $c) || die($!)
l!l
00
MC/DC0%0/1
unpack('C', $c) || die($!)
unpack('C', $c)
Truth table0%0/2
A
A= unpack('C', $c)
Aresult
11
00
81 0 $offset++;
82 0 $size |= ( ( $c & 0x7f ) << $shift );
83 0 $shift += 7;
84 }
85  
86 0 my $content;
87  
88 0 ▶ if ( $type eq 'ofs_delta' || $type eq 'ref_delta' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'ofs_delta' or $type eq 'ref_delta') { } 0 0 0
elsif ($type eq 'commit' or $type eq 'tree' or $type eq 'blob' or $type eq 'tag') { } 0 0 0
Condition0%0/3
$type eq "ofs_delta" or $type eq "ref_delta"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "ofs_delta" or $type eq "ref_delta"
$type eq "ofs_delta" $type eq "ref_delta"
Truth table0%0/3
A or B
A= $type eq "ofs_delta"B= $type eq "ref_delta"
ABresult
1X1
011
000
89 0 ( $type, $size, $content )
90 = $self->unpack_deltified( $type, $offset, $obj_offset, $size,
91 \%offsets );
92 ▶ } elsif ( $type eq 'commit'
Condition0%0/9
$type eq "commit" or $type eq "tree" or $type eq "blob" or $type eq "tag"
l!l&&r!l&&!r
000
$type eq "commit" or $type eq "tree" or $type eq "blob"
l!l&&r!l&&!r
000
$type eq "commit" or $type eq "tree"
l!l&&r!l&&!r
000
MC/DC0%0/4
$type eq "commit" or $type eq "tree" or $type eq "blob" or $type eq "tag"
$type eq "commit" $type eq "tree" $type eq "blob" $type eq "tag"
Truth table0%0/5
A or B or C or D
A= $type eq "commit"B= $type eq "tree"C= $type eq "blob"D= $type eq "tag"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
93 || $type eq 'tree'
94 || $type eq 'blob'
95 || $type eq 'tag' )
96 {
97 0 $content = $self->read_compressed( $offset, $size );
98 } else {
99 0 confess "invalid type $type";
100 }
101  
102 0 my $raw = $type . ' ' . $size . "\0" . $content;
103 0 my $sha1 = Digest::SHA->new;
104 0 $sha1->add($raw);
105 0 my $sha1_hex = $sha1->hexdigest;
106 0 $offsets{$sha1_hex} = $obj_offset;
107 }
108  
109 0 return \%offsets;
110 }
111  
112 0 ▶sub get_object {
Subroutine get_object: not called CC=2 SCAR=17.9
Pod undocumented
113 0 my ( $self, $want_sha1 ) = @_;
114 0 my $offset = $self->offsets->{$want_sha1};
115 0 ▶ return unless $offset;
Branch: 1 branch
BranchTrueFalseTotal
unless $offset 0 0 0
116 0 return $self->unpack_object($offset);
117 }
118  
119 4 __PACKAGE__->meta->make_immutable;
120  
↑ Summary PurePerl/Protocol.pm »