about summary refs log tree commit homepage
path: root/lib/PublicInbox/RepobrowseGitDiff.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/RepobrowseGitDiff.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/RepobrowseGitDiff.pm')
-rw-r--r--lib/PublicInbox/RepobrowseGitDiff.pm17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/PublicInbox/RepobrowseGitDiff.pm b/lib/PublicInbox/RepobrowseGitDiff.pm
index 8c349e9b..fb44c752 100644
--- a/lib/PublicInbox/RepobrowseGitDiff.pm
+++ b/lib/PublicInbox/RepobrowseGitDiff.pm
@@ -36,8 +36,7 @@ sub call_git_diff {
         $req->{dbuf} = '';
         $req->{p} = [ $id2 ];
         $req->{h} = $id;
-        $req->{end} = sub {
-                $req->{fail} = $req->{cb} = $req->{end} = undef;
+        my $end = sub {
                 if (my $fh = delete $req->{fh}) {
                         # write out the last bit that was buffered
                         my @buf = split(/\n/, delete $req->{dbuf}, -1);
@@ -54,21 +53,21 @@ sub call_git_diff {
                         $rpipe->close; # _may_ be Danga::Socket::close
                 }
         };
-        $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 diff ($git->{git_dir}): $e\n");
         };
-        $req->{cb} = sub {
+        my $cb = sub {
                 my $off = length($req->{dbuf});
                 my $n = $req->{rpipe}->sysread($req->{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;
                 if (my $res = delete $req->{res}) {
                         my $h = ['Content-Type', 'text/html; charset=UTF-8'];
                         my $fh = $req->{fh} = $res->([200, $h]);
@@ -84,14 +83,14 @@ sub call_git_diff {
                 }
         };
         if (my $async = $env->{'pi-httpd.async'}) {
-                $req->{rpipe} = $async->($req->{rpipe}, $req->{cb});
+                $req->{rpipe} = $async->($req->{rpipe}, $cb);
                 sub { $req->{res} = $_[0] } # let Danga::Socket handle the rest.
         } else { # synchronous loop for other PSGI servers
                 $vin = '';
                 vec($vin, fileno($req->{rpipe}), 1) = 1;
                 sub {
                         $req->{res} = $_[0];
-                        while ($req->{rpipe}) { $req->{cb}->() }
+                        while ($req->{rpipe}) { $cb->() }
                 }
         }
 }