]> Sergey Matveev's repositories - public-inbox.git/commitdiff
viewvcs: share File::Temp::Dir with solver
authorEric Wong <e@80x24.org>
Mon, 29 Aug 2022 09:26:31 +0000 (09:26 +0000)
committerEric Wong <e@80x24.org>
Mon, 29 Aug 2022 19:05:43 +0000 (19:05 +0000)
This allows reusing inodes for /$COMMIT_OID/s/ requests.
We'll also replace `log' with `lh' in the field name to
avoid confusion with the `log' perlop.

lib/PublicInbox/ViewVCS.pm

index 9bf010c269508765fc04309ed3b06865a2d0af8e..c5d16478f8a96daf5a1d075a0c08019bc404bbc8 100644 (file)
@@ -231,12 +231,10 @@ sub show_commit ($$$$) {
                'git show --encoding=UTF-8 --pretty=format:%n -M'.
                " --stat -p $oid >p && ".
                "git patch-id --stable <p" ];
-       my $xenv = { GIT_DIR => $git->{git_dir} };
-       my $tmp = File::Temp->newdir("show-$oid-XXXX", TMPDIR => 1);
-       my $qsp = PublicInbox::Qspawn->new($cmd, $xenv, { -C => "$tmp" });
+       my $e = { GIT_DIR => $git->{git_dir} };
+       my $qsp = PublicInbox::Qspawn->new($cmd, $e, { -C => "$ctx->{-tmp}" });
        $qsp->{qsp_err} = \($ctx->{-qsp_err} = '');
        $ctx->{-logref} = $logref;
-       $ctx->{-tmp} = $tmp;
        $ctx->{env}->{'qspawn.wcb'} = delete $ctx->{-wcb};
        $ctx->{git} = $git;
        $qsp->psgi_qx($ctx->{env}, undef, \&show_commit_start, $ctx);
@@ -260,7 +258,7 @@ sub show_other ($$$$) {
 # user_cb for SolverGit, called as: user_cb->($result_or_error, $uarg)
 sub solve_result {
        my ($res, $ctx) = @_;
-       my ($log, $hints, $fn) = delete @$ctx{qw(log hints fn)};
+       my ($log, $hints, $fn) = delete @$ctx{qw(lh hints fn)};
 
        unless (seek($log, 0, 0)) {
                warn "seek(log): $!";
@@ -345,15 +343,16 @@ sub show ($$;$) {
                defined(my $v = $qp->{$from}) or next;
                $hints->{$to} = $v if $v ne '';
        }
-
-       $ctx->{'log'} = tmpfile("solve.$oid_b") // die "tmpfile: $!";
        $ctx->{fn} = $fn;
+       $ctx->{-tmp} = File::Temp->newdir("solver.$oid_b-XXXX", TMPDIR => 1);
+       open $ctx->{lh}, '+>>', "$ctx->{-tmp}/solve.log" or die "open: $!";
        my $solver = PublicInbox::SolverGit->new($ctx->{ibx},
                                                \&solve_result, $ctx);
+       $solver->{tmp} = $ctx->{-tmp}; # share tmpdir
        # PSGI server will call this immediately and give us a callback (-wcb)
        sub {
                $ctx->{-wcb} = $_[0]; # HTTP write callback
-               $solver->solve($ctx->{env}, $ctx->{log}, $oid_b, $hints);
+               $solver->solve($ctx->{env}, $ctx->{lh}, $oid_b, $hints);
        };
 }