Cogit/Pack/WithoutIndex.pm

filter: Statementstmt 23.5% 20 / 85 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 3 totaltotal 15.2% 25 / 164 CC 30 SCAR 52.7
CC
30
Cov
14%
create_index
240.0
create_index_offsets
240.0
get_object
6.0
CRAP 195.1
↑ Summary Cogit/Protocol.pm »
1 package Cogit::Pack::WithoutIndex;
2 4 $Cogit::Pack::WithoutIndex::VERSION = '0.001001';
3 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use IO::Digest;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use MooX::Types::MooseLike::Base 'HashRef';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 extends 'Cogit::Pack';
10  
11 4 has offsets => (
12 is => 'rw',
13 isa => HashRef,
14 );
15  
16 4 my @TYPES = (qw(none commit tree blob tag), '', 'ofs_delta', 'ref_delta' );
17  
18 0 ▶sub create_index {
Subroutine create_index: not called CC=15 SCAR=54.8
Pod undocumented
19 0 my ($self) = @_;
20 0 my $index_filename = $self->filename;
21 0 $index_filename =~ s/\.pack/.idx/;
22 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
23  
24 0 my $iod = IO::Digest->new( $index_fh, 'SHA' );
25  
26 0 my $offsets = $self->create_index_offsets;
27 0 my @fan_out_table;
28 0 for my $sha1 ( sort keys %$offsets ) {
29 0 my $offset = $offsets->{$sha1};
30 0 my $slot = unpack( 'C', pack( 'H*', $sha1 ) );
31 0 $fan_out_table[$slot]++;
32 }
33 0 for my $i ( 0 .. 255 ) {
34 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
35 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
36 }
37 0 for my $sha1 ( sort keys %$offsets ) {
38 0 my $offset = $offsets->{$sha1};
39 0 ▶ $index_fh->print( pack( 'N', $offset ) ) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
$index_fh->print(pack("N", $offset)) or die $! 0 0 0
40 0 ▶ $index_fh->print( pack( 'H*', $sha1 ) ) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
$index_fh->print(pack("H*", $sha1)) or die $! 0 0 0
41 }
42  
43 # read the pack checksum from the end of the pack file
44 0 my $size = -s $self->filename;
45 0 my $fh = $self->fh;
46 0 ▶ $fh->seek( $size - 20, 0 ) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
$fh->seek($size - 20, 0) or die $! 0 0 0
47 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
48  
49 0 ▶ $index_fh->print($pack_sha1) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
$index_fh->print($pack_sha1) or die $! 0 0 0
50 0 ▶ $index_fh->print( $iod->digest ) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
$index_fh->print($iod->digest) or die $! 0 0 0
51  
52 0 ▶ $index_fh->close() || die $!;
Branch: 1 branch
BranchTrueFalseTotal
$index_fh->close or die $! 0 0 0
53 }
54  
55 0 ▶sub create_index_offsets {
Subroutine create_index_offsets: not called CC=15 SCAR=54.8
Pod undocumented
56 0 my ($self) = @_;
57 0 my $fh = $self->fh;
58  
59 0 $fh->read( my $signature, 4 );
60 0 $fh->read( my $version, 4 );
61 0 $version = unpack( 'N', $version );
62 0 $fh->read( my $objects, 4 );
63 0 $objects = unpack( 'N', $objects );
64  
65 0 my %offsets;
66 0 $self->offsets( \%offsets );
67  
68 0 for my $i ( 1 .. $objects ) {
69 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
70 0 my $obj_offset = $offset;
71 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
72 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
73 0 $offset++;
74  
75 0 my $size = ( $c & 0xf );
76 0 my $type_number = ( $c >> 4 ) & 7;
77 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
78 || confess
79 "invalid type $type_number at offset $offset, size $size";
80  
81 0 my $shift = 4;
82  
83 0 ▶ while ( ( $c & 0x80 ) != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($c & 128) != 0) 0 0 0
84 0 ▶ $fh->read( $c, 1 ) || die $!;
Branch: 1 branch
BranchTrueFalseTotal
$fh->read($c, 1) or die $! 0 0 0
85 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
86 0 $offset++;
87 0 $size |= ( ( $c & 0x7f ) << $shift );
88 0 $shift += 7;
89 }
90  
91 0 my $content;
92  
93 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
94 0 ( $type, $size, $content )
95 = $self->unpack_deltified( $type, $offset, $obj_offset, $size,
96 \%offsets );
97 ▶ } 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
98 || $type eq 'tree'
99 || $type eq 'blob'
100 || $type eq 'tag' )
101 {
102 0 $content = $self->read_compressed( $offset, $size );
103 } else {
104 0 confess "invalid type $type";
105 }
106  
107 0 my $raw = $type . ' ' . $size . "\0" . $content;
108 0 my $sha1 = Digest::SHA->new;
109 0 $sha1->add($raw);
110 0 my $sha1_hex = $sha1->hexdigest;
111 0 $offsets{$sha1_hex} = $obj_offset;
112 }
113  
114 0 return \%offsets;
115 }
116  
117 0 ▶sub get_object {
Subroutine get_object: not called CC=2 SCAR=17.9
Pod undocumented
118 0 my ( $self, $want_sha1 ) = @_;
119 0 my $offset = $self->offsets->{$want_sha1};
120 0 ▶ return unless $offset;
Branch: 1 branch
BranchTrueFalseTotal
unless $offset 0 0 0
121 0 return $self->unpack_object($offset);
122 }
123  
124 4 1;
125  
126 __END__
↑ Summary Cogit/Protocol.pm »