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