Skip to content

Commit 566ccf5

Browse files
author
Dan Brook
committed
Lazily build the fh attribute of Git::PurePerl::Pack objects.
Not allocating the filehandle at BUILD time means that a large number of G::PP::Pack objects can be thrown around without necessarily hitting a filehandle limit (as was encountered with Gitalist and a repo with a large numbers of refs).
1 parent 2f92ecc commit 566ccf5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/Git/PurePerl/Pack.pm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use namespace::autoclean;
88

99
has 'filename' =>
1010
( is => 'ro', isa => 'Path::Class::File', required => 1, coerce => 1 );
11-
has 'fh' => ( is => 'rw', isa => 'IO::File', required => 0 );
11+
has 'fh' =>
12+
( is => 'rw', isa => 'IO::File', required => 0, lazy_build => 1 );
1213

1314
my @TYPES = ( 'none', 'commit', 'tree', 'blob', 'tag', '', 'ofs_delta',
1415
'ref_delta' );
@@ -22,11 +23,11 @@ my $OBJ_REF_DELTA = 7;
2223

2324
my $SHA1Size = 20;
2425

25-
sub BUILD {
26+
sub _build_fh {
2627
my $self = shift;
2728
my $fh = IO::File->new( $self->filename ) || confess($!);
2829
$fh->binmode();
29-
$self->fh($fh);
30+
return $fh;
3031
}
3132

3233
sub all_sha1s {

0 commit comments

Comments
 (0)