| 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($!)
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/2
$fan_out_table[$i] || 0
MC/DC0%0/1
$fan_out_table[$i] || 0
$fan_out_table[$i]
Truth table0%0/2
A
A= $fan_out_table[$i]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | $fan_out_table[ $i + 1 ] += $fan_out_table[$i] || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$fan_out_table[$i] || 0
MC/DC0%0/1
$fan_out_table[$i] || 0
$fan_out_table[$i]
Truth table0%0/2
A
A= $fan_out_table[$i]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | $index_fh->print( pack( 'H*', $sha1 ) ) || die $!; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | my $read = $fh->read( my $pack_sha1, 20 ) || die $!; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$fh->read(my $pack_sha1, 20) || die($!)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $index_fh->print($pack_sha1) || die $!; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $index_fh->print( $iod->digest ) || die $!; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $index_fh->close() || die $!; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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: $!")
MC/DC0%0/1
$fh->tell || die("Error telling filehandle: $!")
$fh->tell
Truth table0%0/2
A
A= $fh->tell
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $obj_offset = $offset; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $fh->read( my $c, 1 ) || die "Error reading from pack: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $c = unpack( 'C', $c ) || die $!; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
unpack('C', $c) || die($!)
MC/DC0%0/1
unpack('C', $c) || die($!)
unpack('C', $c)
Truth table0%0/2
A
A= unpack('C', $c)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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")
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $fh->read( $c, 1 ) || die $!; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | $c = unpack( 'C', $c ) || die $!; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
unpack('C', $c) || die($!)
MC/DC0%0/1
unpack('C', $c) || die($!)
unpack('C', $c)
Truth table0%0/2
A
A= unpack('C', $c)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$type eq "ofs_delta" or $type eq "ref_delta"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
$type eq "commit" or $type eq "tree" or $type eq "blob"
$type eq "commit" or $type eq "tree"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return $self->unpack_object($offset); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||