From 324098fecf1126233578cc2f6290b4c8fdd9207b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 3 Jan 2023 00:03:00 +0000 Subject: [PATCH] githttpbackend: avoid copying PSGI env 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 | 10 ++++------ lib/PublicInbox/ViewVCS.pm | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm index e84d4ff8..5b879871 100644 --- a/lib/PublicInbox/GitHTTPBackend.pm +++ b/lib/PublicInbox/GitHTTPBackend.pm @@ -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 ] diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm index 02e98768..99ee2c11 100644 --- a/lib/PublicInbox/ViewVCS.pm +++ b/lib/PublicInbox/ViewVCS.pm @@ -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 tree object. 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); } -- 2.44.0