about summary refs log tree commit homepage
path: root/lib/PublicInbox/ViewVCS.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-12-25 07:50:47 +0000
committerEric Wong <e@80x24.org>2019-12-26 10:48:19 +0000
commita7949988f7f8690c868d2150fe3000fcf6a6d5f4 (patch)
tree71c6782191d29573c4e2b025eb4b6d81deddd7ff /lib/PublicInbox/ViewVCS.pm
parent3eba4cbd05b348622e772889b06a5994ba69d157 (diff)
downloadpublic-inbox-a7949988f7f8690c868d2150fe3000fcf6a6d5f4.tar.gz
Callers can supply an arg to parse_hdr, now, eliminating the
need for closures to capture local variables.
Diffstat (limited to 'lib/PublicInbox/ViewVCS.pm')
-rw-r--r--lib/PublicInbox/ViewVCS.pm48
1 files changed, 26 insertions, 22 deletions
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 886e10cb..7618b198 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -42,35 +42,39 @@ sub html_page ($$$) {
         $wcb ? $wcb->($res) : $res;
 }
 
+sub stream_blob_parse_hdr { # {parse_hdr} for Qspawn
+        my ($r, $bref, $ctx) = @_;
+        my ($res, $logref) = delete @$ctx{qw(-res -logref)};
+        my ($git, $oid, $type, $size, $di) = @$res;
+        my @cl = ('Content-Length', $size);
+        if (!defined $r) { # error
+                html_page($ctx, 500, $logref);
+        } elsif (index($$bref, "\0") >= 0) {
+                [200, [qw(Content-Type application/octet-stream), @cl] ];
+        } else {
+                my $n = bytes::length($$bref);
+                if ($n >= $BIN_DETECT || $n == $size) {
+                        return [200, [ 'Content-Type',
+                                'text/plain; charset=UTF-8', @cl ] ];
+                }
+                if ($r == 0) {
+                        warn "premature EOF on $oid $$logref\n";
+                        return html_page($ctx, 500, $logref);
+                }
+                undef; # bref keeps growing
+        }
+}
+
 sub stream_large_blob ($$$$) {
         my ($ctx, $res, $logref, $fn) = @_;
+        $ctx->{-logref} = $logref;
+        $ctx->{-res} = $res;
         my ($git, $oid, $type, $size, $di) = @$res;
         my $cmd = ['git', "--git-dir=$git->{git_dir}", 'cat-file', $type, $oid];
         my $qsp = PublicInbox::Qspawn->new($cmd);
-        my @cl = ('Content-Length', $size);
         my $env = $ctx->{env};
-        $env->{'public-inbox.tmpgit'} = $git; # for {-tmp}/File::Temp::Dir
         $env->{'qspawn.wcb'} = delete $ctx->{-wcb};
-        $qsp->psgi_return($env, undef, sub {
-                my ($r, $bref) = @_;
-                if (!defined $r) { # error
-                        html_page($ctx, 500, $logref);
-                } elsif (index($$bref, "\0") >= 0) {
-                        my $ct = 'application/octet-stream';
-                        [200, ['Content-Type', $ct, @cl ] ];
-                } else {
-                        my $n = bytes::length($$bref);
-                        if ($n >= $BIN_DETECT || $n == $size) {
-                                my $ct = 'text/plain; charset=UTF-8';
-                                return [200, ['Content-Type', $ct, @cl] ];
-                        }
-                        if ($r == 0) {
-                                warn "premature EOF on $oid $$logref\n";
-                                return html_page($ctx, 500, $logref);
-                        }
-                        undef; # bref keeps growing
-                }
-        });
+        $qsp->psgi_return($env, undef, \&stream_blob_parse_hdr, $ctx);
 }
 
 sub show_other_result ($$) {