line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Git::PurePerl::PackIndex::Version2; |
2
|
4
|
|
|
4
|
|
18
|
use Moose; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
26
|
|
3
|
4
|
|
|
4
|
|
19694
|
use MooseX::StrictConstructor; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
60
|
|
4
|
4
|
|
|
4
|
|
10212
|
use namespace::autoclean; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
40
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
extends 'Git::PurePerl::PackIndex'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my $FanOutCount = 256; |
9
|
|
|
|
|
|
|
my $SHA1Size = 20; |
10
|
|
|
|
|
|
|
my $IdxOffsetSize = 4; |
11
|
|
|
|
|
|
|
my $OffsetSize = 4; |
12
|
|
|
|
|
|
|
my $CrcSize = 4; |
13
|
|
|
|
|
|
|
my $OffsetStart = $FanOutCount * $IdxOffsetSize; |
14
|
|
|
|
|
|
|
my $SHA1Start = $OffsetStart + $OffsetSize; |
15
|
|
|
|
|
|
|
my $EntrySize = $OffsetSize + $SHA1Size; |
16
|
|
|
|
|
|
|
my $EntrySizeV2 = $SHA1Size + $CrcSize + $OffsetSize; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub global_offset { |
19
|
53
|
|
|
53
|
0
|
884
|
return 8; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub all_sha1s { |
23
|
2
|
|
|
2
|
0
|
4
|
my ( $self, $want_sha1 ) = @_; |
24
|
2
|
|
|
|
|
55
|
my $fh = $self->fh; |
25
|
2
|
|
|
|
|
3
|
my @sha1s; |
26
|
|
|
|
|
|
|
my @data; |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
6
|
my $pos = $OffsetStart; |
29
|
2
|
50
|
|
|
|
7
|
$fh->seek( $pos + $self->global_offset, 0 ) || die $!; |
30
|
2
|
|
|
|
|
68
|
foreach my $i ( 0 .. $self->size - 1 ) { |
31
|
18
|
50
|
|
|
|
29
|
$fh->read( my $sha1, $SHA1Size ) || die $!; |
32
|
18
|
|
|
|
|
105
|
$data[$i] = [ unpack( 'H*', $sha1 ), 0, 0 ]; |
33
|
18
|
|
|
|
|
20
|
$pos += $SHA1Size; |
34
|
|
|
|
|
|
|
} |
35
|
2
|
50
|
|
|
|
5
|
$fh->seek( $pos + $self->global_offset, 0 ) || die $!; |
36
|
2
|
|
|
|
|
64
|
foreach my $i ( 0 .. $self->size - 1 ) { |
37
|
18
|
50
|
|
|
|
28
|
$fh->read( my $crc, $CrcSize ) || die $!; |
38
|
18
|
|
|
|
|
86
|
$data[$i]->[1] = unpack( 'H*', $crc ); |
39
|
18
|
|
|
|
|
20
|
$pos += $CrcSize; |
40
|
|
|
|
|
|
|
} |
41
|
2
|
50
|
|
|
|
6
|
$fh->seek( $pos + $self->global_offset, 0 ) || die $!; |
42
|
2
|
|
|
|
|
63
|
foreach my $i ( 0 .. $self->size - 1 ) { |
43
|
18
|
50
|
|
|
|
24
|
$fh->read( my $offset, $OffsetSize ) || die $!; |
44
|
18
|
|
|
|
|
78
|
$data[$i]->[2] = unpack( 'N', $offset ); |
45
|
18
|
|
|
|
|
16
|
$pos += $OffsetSize; |
46
|
|
|
|
|
|
|
} |
47
|
2
|
|
|
|
|
8
|
foreach my $data (@data) { |
48
|
18
|
|
|
|
|
16
|
my ( $sha1, $crc, $offset ) = @$data; |
49
|
18
|
|
|
|
|
20
|
push @sha1s, $sha1; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
2
|
|
|
|
|
75
|
return @sha1s; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub get_object_offset { |
56
|
23
|
|
|
23
|
0
|
37
|
my ( $self, $want_sha1 ) = @_; |
57
|
23
|
|
|
|
|
658
|
my @offsets = $self->offsets; |
58
|
23
|
|
|
|
|
751
|
my $fh = $self->fh; |
59
|
|
|
|
|
|
|
|
60
|
23
|
|
|
|
|
147
|
my $slot = unpack( 'C', pack( 'H*', $want_sha1 ) ); |
61
|
23
|
50
|
|
|
|
56
|
return unless defined $slot; |
62
|
|
|
|
|
|
|
|
63
|
23
|
|
|
|
|
55
|
my ( $first, $last ) = @offsets[ $slot, $slot + 1 ]; |
64
|
|
|
|
|
|
|
|
65
|
23
|
|
|
|
|
65
|
while ( $first < $last ) { |
66
|
23
|
|
|
|
|
58
|
my $mid = int( ( $first + $last ) / 2 ); |
67
|
|
|
|
|
|
|
|
68
|
23
|
50
|
|
|
|
60
|
$fh->seek( $self->global_offset + $OffsetStart + ( $mid * $SHA1Size ), |
69
|
|
|
|
|
|
|
0 ) |
70
|
|
|
|
|
|
|
|| die $!; |
71
|
23
|
50
|
|
|
|
280
|
$fh->read( my $data, $SHA1Size ) || die $!; |
72
|
23
|
|
|
|
|
328
|
my $midsha1 = unpack( 'H*', $data ); |
73
|
23
|
50
|
|
|
|
87
|
if ( $midsha1 lt $want_sha1 ) { |
|
|
50
|
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
$first = $mid + 1; |
75
|
|
|
|
|
|
|
} elsif ( $midsha1 gt $want_sha1 ) { |
76
|
0
|
|
|
|
|
0
|
$last = $mid; |
77
|
|
|
|
|
|
|
} else { |
78
|
23
|
|
|
|
|
39
|
my $pos |
79
|
|
|
|
|
|
|
= $self->global_offset |
80
|
|
|
|
|
|
|
+ $OffsetStart |
81
|
|
|
|
|
|
|
+ ( $self->size * ( $SHA1Size + $CrcSize ) ) |
82
|
|
|
|
|
|
|
+ ( $mid * $OffsetSize ); |
83
|
23
|
50
|
|
|
|
57
|
$fh->seek( $pos, 0 ) || die $!; |
84
|
23
|
50
|
|
|
|
149
|
$fh->read( my $data, $OffsetSize ) || die $!; |
85
|
23
|
|
|
|
|
190
|
my $offset = unpack( 'N', $data ); |
86
|
23
|
|
|
|
|
160
|
return $offset; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
|
return; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
93
|
|
|
|
|
|
|
|