about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiMirror.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-10-25 06:33:55 +0000
committerEric Wong <e@80x24.org>2023-10-25 07:28:51 +0000
commit9d8a15fdb93e3a32f73169f827953c69c5ff251e (patch)
tree8f9374fe75f1cfee78a01670c6d3bd70010fc44f /lib/PublicInbox/LeiMirror.pm
parenta309ca6ba5f3c0a541bb15414a4c3357a86dfbda (diff)
downloadpublic-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/LeiMirror.pm')
-rw-r--r--lib/PublicInbox/LeiMirror.pm14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm
index 47fb767b..43e59e6c 100644
--- a/lib/PublicInbox/LeiMirror.pm
+++ b/lib/PublicInbox/LeiMirror.pm
@@ -19,10 +19,10 @@ use PublicInbox::Inbox;
 use PublicInbox::Git qw(read_all);
 use PublicInbox::LeiCurl;
 use PublicInbox::OnDestroy;
-use PublicInbox::SHA qw(sha256_hex sha1_hex);
+use PublicInbox::SHA qw(sha256_hex sha_all);
 use POSIX qw(strftime);
-use autodie qw(chdir chmod close open pipe readlink seek symlink sysopen
-                truncate unlink);
+use autodie qw(chdir chmod close open pipe readlink
+                seek symlink sysopen sysseek truncate unlink);
 
 our $LIVE; # pid => callback
 our $FGRP_TODO; # objstore -> [[ to resume ], [ to clone ]]
@@ -533,10 +533,10 @@ sub fp_done {
         }
         return if !keep_going($self);
         my $fh = delete $self->{-show_ref} // die 'BUG: no show-ref output';
-        seek($fh, SEEK_SET, 0);
+        sysseek($fh, SEEK_SET, 0);
         $self->{-ent} // die 'BUG: no -ent';
         my $A = $self->{-ent}->{fingerprint} // die 'BUG: no fingerprint';
-        my $B = sha1_hex(read_all($fh));
+        my $B = sha_all(1, $fh)->hexdigest;
         return $cb->($self, @arg) if $A ne $B;
         $self->{lei}->qerr("# $self->{-key} up-to-date");
 }
@@ -730,10 +730,10 @@ sub up_fp_done {
         my ($self) = @_;
         return if !keep_going($self);
         my $fh = delete $self->{-show_ref_up} // die 'BUG: no show-ref output';
-        seek($fh, SEEK_SET, 0);
+        sysseek($fh, SEEK_SET, 0);
         $self->{-ent} // die 'BUG: no -ent';
         my $A = $self->{-ent}->{fingerprint} // die 'BUG: no fingerprint';
-        my $B = sha1_hex(read_all($fh));
+        my $B = sha_all(1, $fh)->hexdigest;
         return if $A eq $B;
         $self->{-ent}->{fingerprint} = $B;
         push @{$self->{chg}->{fp_mismatch}}, $self->{-key};