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:51:03 +0000
committerEric Wong <e@80x24.org>2019-12-28 19:38:10 +0000
commitb316f7541ec263fd04ea50530a1d500f43773299 (patch)
treed78a59ef1cd86a61481b91dba3020b41e8365688 /lib/PublicInbox/ViewVCS.pm
parentbc23e3dc4b252dc7e9b6f3824afe74d85456b689 (diff)
downloadpublic-inbox-b316f7541ec263fd04ea50530a1d500f43773299.tar.gz
This allows us to get rid of the requirement to capture
on-stack variables with an anonymous sub, as illustrated
with the update to viewvcs to take advantage of this.

v2: fix error handling for missing OIDs
Diffstat (limited to 'lib/PublicInbox/ViewVCS.pm')
-rw-r--r--lib/PublicInbox/ViewVCS.pm19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index a6dbb9a9..ead8c2b4 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -112,8 +112,10 @@ sub show_other ($$$$) {
         $qsp->psgi_qx($env, undef, \&show_other_result, $ctx);
 }
 
+# user_cb for SolverGit, called as: user_cb->($result_or_error, $uarg)
 sub solve_result {
-        my ($ctx, $res, $log, $hints, $fn) = @_;
+        my ($res, $ctx) = @_;
+        my ($log, $hints, $fn) = delete @$ctx{qw(log hints fn)};
 
         unless (seek($log, 0, 0)) {
                 $ctx->{env}->{'psgi.errors'}->print("seek(log): $!\n");
@@ -192,21 +194,20 @@ sub solve_result {
 sub show ($$;$) {
         my ($ctx, $oid_b, $fn) = @_;
         my $qp = $ctx->{qp};
-        my $hints = {};
+        my $hints = $ctx->{hints} = {};
         while (my ($from, $to) = each %QP_MAP) {
                 defined(my $v = $qp->{$from}) or next;
                 $hints->{$to} = $v;
         }
 
-        my $log = tmpfile("solve.$oid_b");
-        my $solver = PublicInbox::SolverGit->new($ctx->{-inbox}, sub {
-                solve_result($ctx, $_[0], $log, $hints, $fn);
-        });
-
-        # PSGI server will call this and give us a callback
+        $ctx->{'log'} = tmpfile("solve.$oid_b");
+        $ctx->{fn} = $fn;
+        my $solver = PublicInbox::SolverGit->new($ctx->{-inbox},
+                                                \&solve_result, $ctx);
+        # PSGI server will call this immediately and give us a callback (-wcb)
         sub {
                 $ctx->{-wcb} = $_[0]; # HTTP write callback
-                $solver->solve($ctx->{env}, $log, $oid_b, $hints);
+                $solver->solve($ctx->{env}, $ctx->{log}, $oid_b, $hints);
         };
 }