diff options
author | Eric Wong <e@80x24.org> | 2017-01-11 04:12:26 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2017-01-11 04:13:18 +0000 |
commit | 33362430ea03e5877ce1d17bbe1da830dcebea3e (patch) | |
tree | 728d45a4c8190e70b4f8a5d05990fe82f8dd2ea3 /lib/PublicInbox/GetlineBody.pm | |
parent | 759d23f90ebd5d7b966784c77c206aabbbdf41d0 (diff) | |
download | public-inbox-33362430ea03e5877ce1d17bbe1da830dcebea3e.tar.gz |
This prevents "git show" processes from monopolizing the system and allows us to better handle backpressure from gigantic commits.
Diffstat (limited to 'lib/PublicInbox/GetlineBody.pm')
-rw-r--r-- | lib/PublicInbox/GetlineBody.pm | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/PublicInbox/GetlineBody.pm b/lib/PublicInbox/GetlineBody.pm index 5f327828..ccc66e48 100644 --- a/lib/PublicInbox/GetlineBody.pm +++ b/lib/PublicInbox/GetlineBody.pm @@ -9,8 +9,13 @@ use strict; use warnings; sub new { - my ($class, $rpipe, $end, $buf) = @_; - bless { rpipe => $rpipe, end => $end, buf => $buf }, $class; + my ($class, $rpipe, $end, $buf, $filter) = @_; + bless { + rpipe => $rpipe, + end => $end, + buf => $buf, + filter => $filter || 0, + }, $class; } # close should always be called after getline returns undef, @@ -20,8 +25,13 @@ sub DESTROY { $_[0]->close } sub getline { my ($self) = @_; + my $filter = $self->{filter}; + return if $filter == -1; # last call was EOF + my $buf = delete $self->{buf}; # initial buffer - defined $buf ? $buf : $self->{rpipe}->getline; + $buf = $self->{rpipe}->getline unless defined $buf; + $self->{filter} = -1 unless defined $buf; # set EOF for next call + $filter ? $filter->($buf) : $buf; } sub close { |