/usr/share/perl5/Git/PurePerl/PackIndex/Version1.pm is in libgit-pureperl-perl 0.50-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | package Git::PurePerl::PackIndex::Version1;
use Moose;
use MooseX::StrictConstructor;
use namespace::autoclean;
extends 'Git::PurePerl::PackIndex';
my $FanOutCount = 256;
my $SHA1Size = 20;
my $IdxOffsetSize = 4;
my $OffsetSize = 4;
my $CrcSize = 4;
my $OffsetStart = $FanOutCount * $IdxOffsetSize;
my $SHA1Start = $OffsetStart + $OffsetSize;
my $EntrySize = $OffsetSize + $SHA1Size;
my $EntrySizeV2 = $SHA1Size + $CrcSize + $OffsetSize;
sub global_offset {
return 0;
}
sub all_sha1s {
my ( $self, $want_sha1 ) = @_;
my $fh = $self->fh;
my @sha1s;
my $pos = $OffsetStart;
$fh->seek( $pos, 0 ) || die $!;
foreach my $i ( 1 .. $self->size ) {
$fh->read( my $data, $OffsetSize ) || die $!;
my $offset = unpack( 'N', $data );
$fh->read( $data, $SHA1Size ) || die $!;
my $sha1 = unpack( 'H*', $data );
push @sha1s, $sha1;
$pos += $EntrySize;
}
return @sha1s;
}
sub get_object_offset {
my ( $self, $want_sha1 ) = @_;
my @offsets = $self->offsets;
my $fh = $self->fh;
my $slot = unpack( 'C', pack( 'H*', $want_sha1 ) );
return unless defined $slot;
my ( $first, $last ) = @offsets[ $slot, $slot + 1 ];
while ( $first < $last ) {
my $mid = int( ( $first + $last ) / 2 );
$fh->seek( $SHA1Start + $mid * $EntrySize, 0 ) || die $!;
$fh->read( my $data, $SHA1Size ) || die $!;
my $midsha1 = unpack( 'H*', $data );
if ( $midsha1 lt $want_sha1 ) {
$first = $mid + 1;
} elsif ( $midsha1 gt $want_sha1 ) {
$last = $mid;
} else {
my $pos = $OffsetStart + $mid * $EntrySize;
$fh->seek( $pos, 0 ) || die $!;
$fh->read( my $data, $OffsetSize ) || die $!;
my $offset = unpack( 'N', $data );
return $offset;
}
}
return;
}
__PACKAGE__->meta->make_immutable;
|