line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Git::PurePerl::PackIndex::Version2; |
2
|
4
|
|
|
4
|
|
17
|
use Moose; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
24
|
|
3
|
4
|
|
|
4
|
|
18973
|
use MooseX::StrictConstructor; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
27
|
|
4
|
4
|
|
|
4
|
|
8574
|
use namespace::autoclean; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
28
|
|
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
|
676
|
return 8; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub all_sha1s { |
23
|
2
|
|
|
2
|
0
|
3
|
my ( $self, $want_sha1 ) = @_; |
24
|
2
|
|
|
|
|
46
|
my $fh = $self->fh; |
25
|
2
|
|
|
|
|
4
|
my @sha1s; |
26
|
|
|
|
|
|
|
my @data; |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
3
|
my $pos = $OffsetStart; |
29
|
2
|
50
|
|
|
|
7
|
$fh->seek( $pos + $self->global_offset, 0 ) || die $!; |
30
|
2
|
|
|
|
|
57
|
foreach my $i ( 0 .. $self->size - 1 ) { |
31
|
18
|
50
|
|
|
|
24
|
$fh->read( my $sha1, $SHA1Size ) || die $!; |
32
|
18
|
|
|
|
|
88
|
$data[$i] = [ unpack( 'H*', $sha1 ), 0, 0 ]; |
33
|
18
|
|
|
|
|
18
|
$pos += $SHA1Size; |
34
|
|
|
|
|
|
|
} |
35
|
2
|
50
|
|
|
|
5
|
$fh->seek( $pos + $self->global_offset, 0 ) || die $!; |
36
|
2
|
|
|
|
|
59
|
foreach my $i ( 0 .. $self->size - 1 ) { |
37
|
18
|
50
|
|
|
|
23
|
$fh->read( my $crc, $CrcSize ) || die $!; |
38
|
18
|
|
|
|
|
73
|
$data[$i]->[1] = unpack( 'H*', $crc ); |
39
|
18
|
|
|
|
|
16
|
$pos += $CrcSize; |
40
|
|
|
|
|
|
|
} |
41
|
2
|
50
|
|
|
|
6
|
$fh->seek( $pos + $self->global_offset, 0 ) || die $!; |
42
|
2
|
|
|
|
|
56
|
foreach my $i ( 0 .. $self->size - 1 ) { |
43
|
18
|
50
|
|
|
|
26
|
$fh->read( my $offset, $OffsetSize ) || die $!; |
44
|
18
|
|
|
|
|
63
|
$data[$i]->[2] = unpack( 'N', $offset ); |
45
|
18
|
|
|
|
|
17
|
$pos += $OffsetSize; |
46
|
|
|
|
|
|
|
} |
47
|
2
|
|
|
|
|
3
|
foreach my $data (@data) { |
48
|
18
|
|
|
|
|
16
|
my ( $sha1, $crc, $offset ) = @$data; |
49
|
18
|
|
|
|
|
17
|
push @sha1s, $sha1; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
2
|
|
|
|
|
64
|
return @sha1s; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub get_object_offset { |
56
|
23
|
|
|
23
|
0
|
25
|
my ( $self, $want_sha1 ) = @_; |
57
|
23
|
|
|
|
|
519
|
my @offsets = $self->offsets; |
58
|
23
|
|
|
|
|
633
|
my $fh = $self->fh; |
59
|
|
|
|
|
|
|
|
60
|
23
|
|
|
|
|
83
|
my $slot = unpack( 'C', pack( 'H*', $want_sha1 ) ); |
61
|
23
|
50
|
|
|
|
40
|
return unless defined $slot; |
62
|
|
|
|
|
|
|
|
63
|
23
|
|
|
|
|
35
|
my ( $first, $last ) = @offsets[ $slot, $slot + 1 ]; |
64
|
|
|
|
|
|
|
|
65
|
23
|
|
|
|
|
36
|
while ( $first < $last ) { |
66
|
23
|
|
|
|
|
42
|
my $mid = int( ( $first + $last ) / 2 ); |
67
|
|
|
|
|
|
|
|
68
|
23
|
50
|
|
|
|
44
|
$fh->seek( $self->global_offset + $OffsetStart + ( $mid * $SHA1Size ), |
69
|
|
|
|
|
|
|
0 ) |
70
|
|
|
|
|
|
|
|| die $!; |
71
|
23
|
50
|
|
|
|
181
|
$fh->read( my $data, $SHA1Size ) || die $!; |
72
|
23
|
|
|
|
|
206
|
my $midsha1 = unpack( 'H*', $data ); |
73
|
23
|
50
|
|
|
|
52
|
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
|
|
|
|
|
29
|
my $pos |
79
|
|
|
|
|
|
|
= $self->global_offset |
80
|
|
|
|
|
|
|
+ $OffsetStart |
81
|
|
|
|
|
|
|
+ ( $self->size * ( $SHA1Size + $CrcSize ) ) |
82
|
|
|
|
|
|
|
+ ( $mid * $OffsetSize ); |
83
|
23
|
50
|
|
|
|
46
|
$fh->seek( $pos, 0 ) || die $!; |
84
|
23
|
50
|
|
|
|
146
|
$fh->read( my $data, $OffsetSize ) || die $!; |
85
|
23
|
|
|
|
|
147
|
my $offset = unpack( 'N', $data ); |
86
|
23
|
|
|
|
|
158
|
return $offset; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
|
return; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
93
|
|
|
|
|
|
|
|