about summary refs log tree commit homepage
path: root/lib/PublicInbox/RepobrowseGitCommit.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-04-05 23:55:12 +0000
committerEric Wong <e@80x24.org>2016-04-05 23:55:12 +0000
commitf744e337c81887f95cc79e27f5cb15ff7e76c776 (patch)
treed9a9ebe5aeb3403c7a789ca75013fb800596cc01 /lib/PublicInbox/RepobrowseGitCommit.pm
parent25b49fc37121d8584b84b44b20c910ef43c44950 (diff)
downloadpublic-inbox-f744e337c81887f95cc79e27f5cb15ff7e76c776.tar.gz
It's unnecessary to rely so much on the req hashref
like this and having to manually drop references could
be considered code smell.
Diffstat (limited to 'lib/PublicInbox/RepobrowseGitCommit.pm')
-rw-r--r--lib/PublicInbox/RepobrowseGitCommit.pm17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/PublicInbox/RepobrowseGitCommit.pm b/lib/PublicInbox/RepobrowseGitCommit.pm
index 8fdbc47e..227dad97 100644
--- a/lib/PublicInbox/RepobrowseGitCommit.pm
+++ b/lib/PublicInbox/RepobrowseGitCommit.pm
@@ -111,13 +111,13 @@ sub git_diff_cc_line_i ($$) {
         }
 }
 
-sub git_commit_stream ($$) {
-        my ($self, $req) = @_;
+sub git_commit_stream ($$$$) {
+        my ($self, $req, $fail, $end) = @_;
         my $dbuf = \($req->{dbuf});
         my $off = length($$dbuf);
         my $n = $req->{rpipe}->sysread($$dbuf, 8192, $off);
-        return $req->{fail}->() unless defined $n;
-        return $req->{end}->() if $n == 0;
+        return $fail->() unless defined $n;
+        return $end->() if $n == 0;
         my $res = $req->{res};
         if ($res) {
                 return if index($$dbuf, "\0") < 0;
@@ -164,8 +164,7 @@ sub call_git_commit {
         my $err = $env->{'psgi.errors'};
         my $vin;
         $req->{dbuf} = '';
-        $req->{end} = sub {
-                $req->{end} = undef;
+        my $end = sub {
                 if (my $fh = delete $req->{fh}) {
                         my $dbuf = delete $req->{dbuf};
                         if (!$req->{diff_state}) {
@@ -194,19 +193,19 @@ sub call_git_commit {
                 # $id to psgi.errors w/o sanitizing...
                 $git->err;
         };
-        $req->{fail} = sub {
+        my $fail = sub {
                 if ($!{EAGAIN} || $!{EINTR}) {
                         select($vin, undef, undef, undef) if defined $vin;
                         # $vin is undef on async, so this is a noop on EAGAIN
                         return;
                 }
                 my $e = $!;
-                $req->{end}->();
+                $end->();
                 $err->print("git show ($git->{git_dir}): $e\n");
         };
         $req->{'q'} = $q;
         my $cb = sub { # read git-show output and stream to client
-                git_commit_stream($self, $req);
+                git_commit_stream($self, $req, $fail, $end);
         };
         if (my $async = $env->{'pi-httpd.async'}) {
                 $req->{rpipe} = $async->($req->{rpipe}, $cb);