line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cogit::PackIndex::Version1; |
2
|
|
|
|
|
|
|
$Cogit::PackIndex::Version1::VERSION = '0.001001'; |
3
|
4
|
|
|
4
|
|
18
|
use Moo; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
17
|
|
4
|
4
|
|
|
4
|
|
7056
|
use namespace::clean; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
30
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
extends 'Cogit::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
|
1
|
|
|
1
|
0
|
14
|
return 0; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub all_sha1s { |
23
|
2
|
|
|
2
|
0
|
11
|
my ( $self, $want_sha1 ) = @_; |
24
|
2
|
|
|
|
|
28
|
my $fh = $self->fh; |
25
|
2
|
|
|
|
|
9
|
my @sha1s; |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
|
|
5
|
my $pos = $OffsetStart; |
28
|
2
|
50
|
|
|
|
9
|
$fh->seek( $pos, 0 ) || die $!; |
29
|
2
|
|
|
|
|
43
|
for my $i ( 1 .. $self->size ) { |
30
|
18
|
50
|
|
|
|
38
|
$fh->read( my $data, $OffsetSize ) || die $!; |
31
|
18
|
|
|
|
|
75
|
my $offset = unpack( 'N', $data ); |
32
|
18
|
50
|
|
|
|
24
|
$fh->read( $data, $SHA1Size ) || die $!; |
33
|
18
|
|
|
|
|
61
|
my $sha1 = unpack( 'H*', $data ); |
34
|
18
|
|
|
|
|
17
|
push @sha1s, $sha1; |
35
|
18
|
|
|
|
|
16
|
$pos += $EntrySize; |
36
|
|
|
|
|
|
|
} |
37
|
2
|
|
|
|
|
64
|
return @sha1s; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get_object_offset { |
41
|
25
|
|
|
25
|
0
|
117
|
my ( $self, $want_sha1 ) = @_; |
42
|
25
|
|
|
|
|
24
|
my @offsets = @{$self->offsets}; |
|
25
|
|
|
|
|
315
|
|
43
|
25
|
|
|
|
|
623
|
my $fh = $self->fh; |
44
|
|
|
|
|
|
|
|
45
|
25
|
|
|
|
|
174
|
my $slot = unpack( 'C', pack( 'H*', $want_sha1 ) ); |
46
|
25
|
50
|
|
|
|
53
|
return unless defined $slot; |
47
|
|
|
|
|
|
|
|
48
|
25
|
|
|
|
|
46
|
my ( $first, $last ) = @offsets[ $slot, $slot + 1 ]; |
49
|
|
|
|
|
|
|
|
50
|
25
|
|
|
|
|
44
|
while ( $first < $last ) { |
51
|
25
|
|
|
|
|
59
|
my $mid = int( ( $first + $last ) / 2 ); |
52
|
25
|
50
|
|
|
|
75
|
$fh->seek( $SHA1Start + $mid * $EntrySize, 0 ) || die $!; |
53
|
25
|
50
|
|
|
|
217
|
$fh->read( my $data, $SHA1Size ) || die $!; |
54
|
25
|
|
|
|
|
253
|
my $midsha1 = unpack( 'H*', $data ); |
55
|
25
|
50
|
|
|
|
67
|
if ( $midsha1 lt $want_sha1 ) { |
|
|
50
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
$first = $mid + 1; |
57
|
|
|
|
|
|
|
} elsif ( $midsha1 gt $want_sha1 ) { |
58
|
0
|
|
|
|
|
0
|
$last = $mid; |
59
|
|
|
|
|
|
|
} else { |
60
|
25
|
|
|
|
|
29
|
my $pos = $OffsetStart + $mid * $EntrySize; |
61
|
25
|
50
|
|
|
|
42
|
$fh->seek( $pos, 0 ) || die $!; |
62
|
25
|
50
|
|
|
|
127
|
$fh->read( my $data, $OffsetSize ) || die $!; |
63
|
25
|
|
|
|
|
135
|
my $offset = unpack( 'N', $data ); |
64
|
25
|
|
|
|
|
157
|
return $offset; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=pod |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=encoding UTF-8 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 NAME |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Cogit::PackIndex::Version1 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 VERSION |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
version 0.001001 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 AUTHOR |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Arthur Axel "fREW" Schmidt <cogit@afoolishmanifesto.com> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Arthur Axel "fREW" Schmidt. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
96
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |