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/CodeSearchIdx.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/CodeSearchIdx.pm')
-rw-r--r-- | lib/PublicInbox/CodeSearchIdx.pm | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm index e31432b9..aeee37c0 100644 --- a/lib/PublicInbox/CodeSearchIdx.pm +++ b/lib/PublicInbox/CodeSearchIdx.pm @@ -45,7 +45,7 @@ use POSIX qw(WNOHANG SEEK_SET); use File::Path (); use File::Spec (); use List::Util qw(max); -use PublicInbox::SHA qw(sha256_hex); +use PublicInbox::SHA qw(sha256_hex sha_all); use PublicInbox::Search qw(xap_terms); use PublicInbox::SearchIdx qw(add_val); use PublicInbox::Config qw(glob2re rel2abs_collapsed); @@ -386,10 +386,7 @@ sub fp_fini { # run_git cb my (undef, $self, $git, $prep_repo) = @_; my $refs = $git->{-repo}->{refs} // die 'BUG: no {-repo}->{refs}'; sysseek($refs, 0, SEEK_SET); - my $buf; - my $dig = PublicInbox::SHA->new(256); - while (sysread($refs, $buf, 65536)) { $dig->add($buf) } - $git->{-repo}->{fp} = $dig->hexdigest; + $git->{-repo}->{fp} = sha_all(256, $refs)->hexdigest; } sub ct_start ($$$) { |