]> Sergey Matveev's repositories - public-inbox.git/commitdiff
githttpbackend: avoid copying PSGI env
authorEric Wong <e@80x24.org>
Tue, 3 Jan 2023 00:03:00 +0000 (00:03 +0000)
committerEric Wong <e@80x24.org>
Tue, 3 Jan 2023 00:20:45 +0000 (00:20 +0000)
We can stash qspawn.wcb before we fallback to WwwCoderepo to
ensure the qspawn re-dispatch works as expected.  This is still
hacky and I want to tweak it further down the line.  Meanwhile,
lets make it less expensive to do hacky things...

lib/PublicInbox/GitHTTPBackend.pm
lib/PublicInbox/ViewVCS.pm

index e84d4ff802bf763697ee9937257ec84fc6b83c0f..5b879871bbb1d7c9b732b087d88b639526fb64c9 100644 (file)
@@ -149,13 +149,11 @@ sub parse_cgi_headers { # {parse_hdr} for Qspawn
        # This makes qspawn skip ->async_pass and causes
        # PublicInbox::HTTPD::Async::event_step to close shortly after
        if ($code == 404 && $ctx->{www} && !$ctx->{_coderepo_tried}++) {
-               my %ctx = %$ctx;
-               $ctx{env} = +{ %{$ctx->{env}} };
-               delete $ctx->{env}->{'qspawn.wcb'};
+               my $wcb = delete $ctx->{env}->{'qspawn.wcb'};
                $ctx->{env}->{'plack.skip-deflater'} = 1; # prevent 2x gzip
-               my $res = $ctx->{www}->coderepo->srv(\%ctx);
-               # for ->psgi_return_init_cb:
-               $ctx->{env}->{'qspawn.wcb'} = $ctx{env}->{'qspawn.wcb'};
+               my $res = $ctx->{www}->coderepo->srv($ctx);
+               # for ->psgi_return_init_cb
+               $ctx->{env}->{'qspawn.wcb'} = $wcb;
                $res; # CODE or ARRAY ref
        } else {
                [ $code, \@h ]
index 02e98768602ae0d9529f9140a0dbdf20cf81e581..99ee2c116a4eabac80fa87c085dbe6041dd9df51 100644 (file)
@@ -100,7 +100,7 @@ sub stream_large_blob ($$) {
        my $cmd = ['git', "--git-dir=$git->{git_dir}", 'cat-file', $type, $oid];
        my $qsp = PublicInbox::Qspawn->new($cmd);
        my $env = $ctx->{env};
-       $env->{'qspawn.wcb'} = delete $ctx->{-wcb};
+       $env->{'qspawn.wcb'} = $ctx->{-wcb};
        $qsp->psgi_return($env, undef, \&stream_blob_parse_hdr, $ctx);
 }
 
@@ -282,7 +282,7 @@ possible to have multiple root commits when merging independent histories.
 
 Every commit references one top-level <dfn id=tree>tree</dfn> object.</pre>
 EOM
-       delete($ctx->{env}->{'qspawn.wcb'})->($ctx->html_done($x));
+       delete($ctx->{-wcb})->($ctx->html_done($x));
 }
 
 sub stream_patch_parse_hdr { # {parse_hdr} for Qspawn
@@ -312,7 +312,7 @@ sub show_patch ($$) {
                qw(format-patch -1 --stdout -C),
                "--signature=git format-patch -1 --stdout -C $oid", $oid);
        my $qsp = PublicInbox::Qspawn->new(\@cmd);
-       $ctx->{env}->{'qspawn.wcb'} = delete $ctx->{-wcb};
+       $ctx->{env}->{'qspawn.wcb'} = $ctx->{-wcb};
        $ctx->{patch_oid} = $oid;
        $qsp->psgi_return($ctx->{env}, undef, \&stream_patch_parse_hdr, $ctx);
 }
@@ -333,7 +333,7 @@ sub show_commit ($$) {
        my $e = { GIT_DIR => $git->{git_dir} };
        my $qsp = PublicInbox::Qspawn->new($cmd, $e, { -C => "$ctx->{-tmp}" });
        $qsp->{qsp_err} = \($ctx->{-qsp_err} = '');
-       $ctx->{env}->{'qspawn.wcb'} = delete $ctx->{-wcb};
+       $ctx->{env}->{'qspawn.wcb'} = $ctx->{-wcb};
        $ctx->{git} = $git;
        $qsp->psgi_qx($ctx->{env}, undef, \&show_commit_start, $ctx);
 }