user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] githttpbackend: avoid copying PSGI env
Date: Tue,  3 Jan 2023 00:03:00 +0000	[thread overview]
Message-ID: <20230103000300.2015853-1-e@80x24.org> (raw)

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 <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);
 }

                 reply	other threads:[~2023-01-03  0:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230103000300.2015853-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).