diff options
author | Eric Wong <e@80x24.org> | 2023-10-25 06:33:55 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-10-25 07:28:51 +0000 |
commit | 9d8a15fdb93e3a32f73169f827953c69c5ff251e (patch) | |
tree | 8f9374fe75f1cfee78a01670c6d3bd70010fc44f /lib/PublicInbox/Git.pm | |
parent | a309ca6ba5f3c0a541bb15414a4c3357a86dfbda (diff) | |
download | public-inbox-9d8a15fdb93e3a32f73169f827953c69c5ff251e.tar.gz |
While uncommon, some git repos have hundreds of thousands of refs and slurping that output into memory can bloat the heap. Introduce a sha_all sub in PublicInbox::SHA to loop until EOF and rely on autodie for checking sysread errors.
Diffstat (limited to 'lib/PublicInbox/Git.pm')
-rw-r--r-- | lib/PublicInbox/Git.pm | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 476dcf30..9c26d8bf 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -23,7 +23,7 @@ use PublicInbox::ProcessIONBF; use PublicInbox::Tmpfile; use IO::Poll qw(POLLIN); use Carp qw(croak carp); -use PublicInbox::SHA (); +use PublicInbox::SHA qw(sha_all); our %HEXLEN2SHA = (40 => 1, 64 => 256); our %OFMT2HEXLEN = (sha1 => 40, sha256 => 64); our @EXPORT_OK = qw(git_unquote git_quote %HEXLEN2SHA %OFMT2HEXLEN read_all); @@ -620,10 +620,8 @@ sub manifest_entry { $ent->{reference} = $buf; } } - my $dig = PublicInbox::SHA->new(1); - while (CORE::read($sr, $buf, 65536)) { $dig->add($buf) } + $ent->{fingerprint} = sha_all(1, $sr)->hexdigest; CORE::close $sr or return; # empty, uninitialized git repo - $ent->{fingerprint} = $dig->hexdigest; $ent->{modified} = modified(undef, $mod); chomp($buf = <$own> // ''); utf8::decode($buf); |