]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/ViewVCS.pm
86bae7d656fbce3d62779328bcaed4f27200f319
[public-inbox.git] / lib / PublicInbox / ViewVCS.pm
1 # Copyright (C) all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # show any VCS object, similar to "git show"
5 #
6 # This can use a "solver" to reconstruct blobs based on git
7 # patches (with abbreviated OIDs in the header).  However, the
8 # abbreviated OIDs must match exactly what's in the original
9 # email (unless a normal code repo already has the blob).
10 #
11 # In other words, we can only reliably reconstruct blobs based
12 # on links generated by ViewDiff (and only if the emailed
13 # patches apply 100% cleanly to published blobs).
14
15 package PublicInbox::ViewVCS;
16 use strict;
17 use v5.10.1;
18 use File::Temp 0.19 (); # newdir
19 use PublicInbox::SolverGit;
20 use PublicInbox::GitAsyncCat;
21 use PublicInbox::WwwStream qw(html_oneshot);
22 use PublicInbox::Linkify;
23 use PublicInbox::Tmpfile;
24 use PublicInbox::ViewDiff qw(flush_diff uri_escape_path);
25 use PublicInbox::View;
26 use PublicInbox::Eml;
27 use Text::Wrap qw(wrap);
28 use PublicInbox::Hval qw(ascii_html to_filename prurl);
29 my $hl = eval {
30         require PublicInbox::HlMod;
31         PublicInbox::HlMod->new;
32 };
33
34 my %QP_MAP = ( A => 'oid_a', a => 'path_a', b => 'path_b' );
35 our $MAX_SIZE = 1024 * 1024; # TODO: configurable
36 my $BIN_DETECT = 8000; # same as git
37 my $SHOW_FMT = '--pretty=format:'.join('%n', '%P', '%p', '%H', '%T', '%s', '%f',
38         '%an <%ae>  %ai', '%cn <%ce>  %ci', '%b%x00');
39
40 my %GIT_MODE = (
41         '100644' => ' ', # blob
42         '100755' => 'x', # executable blob
43         '040000' => 'd', # tree
44         '120000' => 'l', # symlink
45         '160000' => 'g', # commit (gitlink)
46 );
47
48 sub html_page ($$;@) {
49         my ($ctx, $code) = @_[0, 1];
50         my $wcb = delete $ctx->{-wcb};
51         $ctx->{-upfx} = '../../'; # from "/$INBOX/$OID/s/"
52         my $res = html_oneshot($ctx, $code, @_[2..$#_]);
53         $wcb ? $wcb->($res) : $res;
54 }
55
56 sub dbg_log ($) {
57         my ($ctx) = @_;
58         my $log = delete $ctx->{lh} // die 'BUG: already captured debug log';
59         if (!seek($log, 0, 0)) {
60                 warn "seek(log): $!";
61                 return '<pre>debug log seek error</pre>';
62         }
63         $log = do { local $/; <$log> } // do {
64                 warn "readline(log): $!";
65                 return '<pre>debug log read error</pre>';
66         };
67         $ctx->{-linkify} //= PublicInbox::Linkify->new;
68         "<hr><pre>debug log:\n\n".
69                 $ctx->{-linkify}->to_html($log).'</pre>';
70 }
71
72 sub stream_blob_parse_hdr { # {parse_hdr} for Qspawn
73         my ($r, $bref, $ctx) = @_;
74         my ($git, $oid, $type, $size, $di) = @{$ctx->{-res}};
75         my @cl = ('Content-Length', $size);
76         if (!defined $r) { # sysread error
77                 html_page($ctx, 500, dbg_log($ctx));
78         } elsif (index($$bref, "\0") >= 0) {
79                 [200, [qw(Content-Type application/octet-stream), @cl] ];
80         } else {
81                 my $n = length($$bref);
82                 if ($n >= $BIN_DETECT || $n == $size) {
83                         return [200, [ 'Content-Type',
84                                 'text/plain; charset=UTF-8', @cl ] ];
85                 }
86                 if ($r == 0) {
87                         my $log = dbg_log($ctx);
88                         warn "premature EOF on $oid $log";
89                         return html_page($ctx, 500, $log);
90                 }
91                 undef; # bref keeps growing
92         }
93 }
94
95 sub stream_large_blob ($$) {
96         my ($ctx, $res) = @_;
97         $ctx->{-res} = $res;
98         my ($git, $oid, $type, $size, $di) = @$res;
99         my $cmd = ['git', "--git-dir=$git->{git_dir}", 'cat-file', $type, $oid];
100         my $qsp = PublicInbox::Qspawn->new($cmd);
101         my $env = $ctx->{env};
102         $env->{'qspawn.wcb'} = delete $ctx->{-wcb};
103         $qsp->psgi_return($env, undef, \&stream_blob_parse_hdr, $ctx);
104 }
105
106 sub show_other_result ($$) { # tag
107         my ($bref, $ctx) = @_;
108         if (my $qsp_err = delete $ctx->{-qsp_err}) {
109                 return html_page($ctx, 500, dbg_log($ctx) .
110                                 "git show error:$qsp_err");
111         }
112         my $l = PublicInbox::Linkify->new;
113         utf8::decode($$bref);
114         html_page($ctx, 200, '<pre>', $l->to_html($$bref), '</pre><hr>',
115                 dbg_log($ctx));
116 }
117
118 sub cmt_title { # git->cat_async callback
119         my ($bref, $oid, $type, $size, $ctx) = @_;
120         utf8::decode($$bref);
121         my $title = $$bref =~ /\r?\n\r?\n([^\r\n]+)\r?\n?/ ? $1 : '';
122         push(@{$ctx->{-cmt_pt}} , ascii_html($title)) == @{$ctx->{-cmt_P}} and
123                 cmt_finalize($ctx);
124 }
125
126 sub show_commit_start { # ->psgi_qx callback
127         my ($bref, $ctx) = @_;
128         if (my $qsp_err = delete $ctx->{-qsp_err}) {
129                 return html_page($ctx, 500, dbg_log($ctx) .
130                                 "git show/patch-id error:$qsp_err");
131         }
132         my $patchid = (split(/ /, $$bref))[0]; # ignore commit
133         $ctx->{-q_value_html} = "patchid:$patchid" if defined $patchid;
134         open my $fh, '<:utf8', "$ctx->{-tmp}/h" or
135                 die "open $ctx->{-tmp}/h: $!";
136         chop(my $buf = do { local $/ = "\0"; <$fh> });
137         chomp $buf;
138         my ($P, $p);
139         ($P, $p, @{$ctx->{cmt_info}}) = split(/\n/, $buf, 9);
140         return cmt_finalize($ctx) if !$P;
141         @{$ctx->{-cmt_P}} = split(/ /, $P);
142         @{$ctx->{-cmt_p}} = split(/ /, $p); # abbreviated
143         if ($ctx->{env}->{'pi-httpd.async'}) {
144                 for (@{$ctx->{-cmt_P}}) {
145                         ibx_async_cat($ctx, $_, \&cmt_title, $ctx);
146                 }
147         } else { # synchronous
148                 for (@{$ctx->{-cmt_P}}) {
149                         $ctx->{git}->cat_async($_, \&cmt_title, $ctx);
150                 }
151                 $ctx->{git}->cat_async_wait;
152         }
153 }
154
155 sub ibx_url_for {
156         my ($ctx) = @_;
157         $ctx->{ibx} and return; # just fall back to $upfx
158         $ctx->{git} or return; # /$CODEREPO/$OID/s/ to (eidx|ibx)
159         if (my $ALL = $ctx->{www}->{pi_cfg}->ALL) {
160                 $ALL->base_url // $ALL->base_url($ctx->{env});
161         } elsif (my $ibxs = $ctx->{git}->{-ibxs}) {
162                 for my $ibx (@$ibxs) {
163                         if ($ibx->isrch) {
164                                 return defined($ibx->{url}) ?
165                                         prurl($ctx->{env}, $ibx->{url}) :
166                                         "../../../$ibx->{name}/";
167                         }
168                 }
169         } else {
170                 undef;
171         }
172 }
173
174 sub cmt_finalize {
175         my ($ctx) = @_;
176         $ctx->{-linkify} //= PublicInbox::Linkify->new;
177         my $upfx = $ctx->{-upfx} = '../../'; # from "/$INBOX/$OID/s/"
178         my ($H, $T, $s, $f, $au, $co, $bdy) = @{delete $ctx->{cmt_info}};
179         # try to keep author and committer dates lined up
180         my $x = length($au) - length($co);
181         if ($x > 0) {
182                 $x = ' ' x $x;
183                 $co =~ s/>/>$x/;
184         } elsif ($x < 0) {
185                 $x = ' ' x (-$x);
186                 $au =~ s/>/>$x/;
187         }
188         $_ = ascii_html($_) for ($au, $co);
189         $au =~ s!(&gt; +)([0-9]{4,}-\S+ \S+)!
190                 my ($gt, $t) = ($1, $2);
191                 $t =~ tr/ :-//d;
192                 qq($gt<a
193 href="$upfx?t=$t"
194 title="list contemporary emails">$2</a>)
195                 !e;
196         $ctx->{-title_html} = $s = $ctx->{-linkify}->to_html($s);
197         my ($P, $p, $pt) = delete @$ctx{qw(-cmt_P -cmt_p -cmt_pt)};
198         $_ = qq(<a href="$upfx$_/s/">).shift(@$p).'</a> '.shift(@$pt) for @$P;
199         if (@$P == 1) {
200                 $x = qq{ (<a
201 href="$f.patch">patch</a>)\n   <a href=#parent>parent</a> $P->[0]};
202         } elsif (@$P > 1) {
203                 $x = qq(\n  <a href=#parents>parents</a> $P->[0]\n);
204                 shift @$P;
205                 $x .= qq(          $_\n) for @$P;
206                 chop $x;
207         } else {
208                 $x = ' (<a href=#root_commit>root commit</a>)';
209         }
210         PublicInbox::WwwStream::html_init($ctx);
211         my $zfh = $ctx->zfh;
212         print $zfh <<EOM;
213 <pre>   <a href=#commit>commit</a> $H$x
214      <a href=#tree>tree</a> <a href="$upfx$T/s/">$T</a>
215    author $au
216 committer $co
217
218 <b>$s</b>
219 EOM
220         print $zfh "\n", $ctx->{-linkify}->to_html($bdy) if length($bdy);
221         $bdy = '';
222         open my $fh, '<:utf8', "$ctx->{-tmp}/p" or
223                 die "open $ctx->{-tmp}/p: $!";
224         if (-s $fh > $MAX_SIZE) {
225                 print $zfh "---\n patch is too large to show\n";
226         } else { # prepare flush_diff:
227                 read($fh, $x, -s _);
228                 $ctx->{-apfx} = $ctx->{-spfx} = $upfx;
229                 $x =~ s/\r?\n/\n/gs;
230                 $ctx->{-anchors} = {} if $x =~ /^diff --git /sm;
231                 flush_diff($ctx, \$x); # undefs $x
232                 # TODO: should there be another textarea which attempts to
233                 # search for the exact email which was applied to make this
234                 # commit?
235                 if (my $qry = delete $ctx->{-qry}) {
236                         my $q = '';
237                         for (@{$qry->{dfpost}}, @{$qry->{dfpre}}) {
238                                 # keep blobs as short as reasonable, emails
239                                 # are going to be older than what's in git
240                                 substr($_, 7, 64, '');
241                                 $q .= "dfblob:$_ ";
242                         }
243                         chop $q; # no trailing SP
244                         local $Text::Wrap::columns = PublicInbox::View::COLS;
245                         local $Text::Wrap::huge = 'overflow';
246                         $q = wrap('', '', $q);
247                         my $rows = ($q =~ tr/\n/\n/) + 1;
248                         $q = ascii_html($q);
249                         my $ibx_url = ibx_url_for($ctx);
250                         my $alt;
251                         if (defined $ibx_url) {
252                                 $ibx_url = ascii_html($ibx_url);
253                                 $alt = ' '.$ibx_url;
254                         } else {
255                                 $ibx_url = $upfx;
256                                 $alt = '';
257                         }
258                         print $zfh <<EOM;
259 <hr><form action="$ibx_url"
260 id=related><pre>find related emails, including ancestors/descendants/conflicts
261 <textarea name=q cols=${\PublicInbox::View::COLS} rows=$rows>$q</textarea>
262 <input type=submit value="search$alt"
263 />\t(<a href="${ibx_url}_/text/help/">help</a>)</pre></form>
264 EOM
265                 }
266         }
267         chop($x = <<EOM);
268 <hr><pre>glossary
269 --------
270 <dfn
271 id=commit>Commit</dfn> objects reference one tree, and zero or more parents.
272
273 Single <dfn
274 id=parent>parent</dfn> commits can typically generate a patch in
275 unified diff format via `git format-patch'.
276
277 Multiple <dfn id=parents>parents</dfn> means the commit is a merge.
278
279 <dfn id=root_commit>Root commits</dfn> have no ancestor.  Note that it is
280 possible to have multiple root commits when merging independent histories.
281
282 Every commit references one top-level <dfn id=tree>tree</dfn> object.</pre>
283 EOM
284         delete($ctx->{env}->{'qspawn.wcb'})->($ctx->html_done($x));
285 }
286
287 sub stream_patch_parse_hdr { # {parse_hdr} for Qspawn
288         my ($r, $bref, $ctx) = @_;
289         if (!defined $r) { # sysread error
290                 html_page($ctx, 500, dbg_log($ctx));
291         } elsif (index($$bref, "\n\n") >= 0) {
292                 my $eml = bless { hdr => $bref }, 'PublicInbox::Eml';
293                 my $fn = to_filename($eml->header('Subject') // '');
294                 $fn = substr($fn // 'PATCH-no-subject', 6); # drop "PATCH-"
295                 return [ 200, [ 'Content-Type', 'text/plain; charset=UTF-8',
296                                 'Content-Disposition',
297                                 qq(inline; filename=$fn.patch) ] ];
298         } elsif ($r == 0) {
299                 my $log = dbg_log($ctx);
300                 warn "premature EOF on $ctx->{patch_oid} $log";
301                 return html_page($ctx, 500, $log);
302         } else {
303                 undef; # bref keeps growing until "\n\n"
304         }
305 }
306
307 sub show_patch ($$) {
308         my ($ctx, $res) = @_;
309         my ($git, $oid) = @$res;
310         my @cmd = ('git', "--git-dir=$git->{git_dir}",
311                 qw(format-patch -1 --stdout -C),
312                 "--signature=git format-patch -1 --stdout -C $oid", $oid);
313         my $qsp = PublicInbox::Qspawn->new(\@cmd);
314         $ctx->{env}->{'qspawn.wcb'} = delete $ctx->{-wcb};
315         $ctx->{patch_oid} = $oid;
316         $qsp->psgi_return($ctx->{env}, undef, \&stream_patch_parse_hdr, $ctx);
317 }
318
319 sub show_commit ($$) {
320         my ($ctx, $res) = @_;
321         return show_patch($ctx, $res) if ($ctx->{fn} // '') =~ /\.patch\z/;
322         my ($git, $oid) = @$res;
323         # patch-id needs two passes, and we use the initial show to ensure
324         # a patch embedded inside the commit message body doesn't get fed
325         # to patch-id:
326         my $cmd = [ '/bin/sh', '-c',
327                 "git show --encoding=UTF-8 '$SHOW_FMT'".
328                 " -z --no-notes --no-patch $oid >h && ".
329                 'git show --encoding=UTF-8 --pretty=format:%n -M'.
330                 " --stat -p $oid >p && ".
331                 "git patch-id --stable <p" ];
332         my $e = { GIT_DIR => $git->{git_dir} };
333         my $qsp = PublicInbox::Qspawn->new($cmd, $e, { -C => "$ctx->{-tmp}" });
334         $qsp->{qsp_err} = \($ctx->{-qsp_err} = '');
335         $ctx->{env}->{'qspawn.wcb'} = delete $ctx->{-wcb};
336         $ctx->{git} = $git;
337         $qsp->psgi_qx($ctx->{env}, undef, \&show_commit_start, $ctx);
338 }
339
340 sub show_other ($$) {
341         my ($ctx, $res) = @_;
342         my ($git, $oid, $type, $size) = @$res;
343         $size > $MAX_SIZE and return html_page($ctx, 200,
344                 ascii_html($type)." $oid is too big to show\n". dbg_log($ctx));
345         my $cmd = ['git', "--git-dir=$git->{git_dir}",
346                 qw(show --encoding=UTF-8 --no-color --no-abbrev), $oid ];
347         my $qsp = PublicInbox::Qspawn->new($cmd);
348         $qsp->{qsp_err} = \($ctx->{-qsp_err} = '');
349         $qsp->psgi_qx($ctx->{env}, undef, \&show_other_result, $ctx);
350 }
351
352 sub show_tree_result ($$) {
353         my ($bref, $ctx) = @_;
354         if (my $qsp_err = delete $ctx->{-qsp_err}) {
355                 return html_page($ctx, 500, dbg_log($ctx) .
356                                 "git ls-tree -z error:$qsp_err");
357         }
358         my @ent = split(/\0/, $$bref);
359         my $qp = delete $ctx->{qp};
360         my $l = $ctx->{-linkify} //= PublicInbox::Linkify->new;
361         my $pfx = $qp->{b};
362         $$bref = "<pre><a href=#tree>tree</a> $ctx->{tree_oid}";
363         if (defined $pfx) {
364                 my $x = ascii_html($pfx);
365                 $pfx .= '/';
366                 $$bref .= qq(  <a href=#path>path</a>: $x</a>\n);
367         } else {
368                 $pfx = '';
369                 $$bref .= qq[  (<a href=#path>path</a> unknown)\n];
370         }
371         my ($x, $m, $t, $oid, $sz, $f, $n);
372         $$bref .= "\n   size    name";
373         for (@ent) {
374                 ($x, $f) = split(/\t/, $_, 2);
375                 undef $_;
376                 ($m, $t, $oid, $sz) = split(/ +/, $x, 4);
377                 $m = $GIT_MODE{$m} // '?';
378                 utf8::decode($f);
379                 $n = ascii_html($f);
380                 if ($m eq 'g') { # gitlink submodule commit
381                         $$bref .= "\ng\t\t$n @ <a\nhref=#g>commit</a>$oid";
382                         next;
383                 }
384                 my $q = 'b='.ascii_html(uri_escape_path($pfx.$f));
385                 if ($m eq 'd') { $n .= '/' }
386                 elsif ($m eq 'x') { $n = "<b>$n</b>" }
387                 elsif ($m eq 'l') { $n = "<i>$n</i>" }
388                 $$bref .= qq(\n$m\t$sz\t<a\nhref="../../$oid/s/?$q">$n</a>);
389         }
390         $$bref .= dbg_log($ctx);
391         $$bref .= <<EOM;
392 <pre>glossary
393 --------
394 <dfn
395 id=tree>Tree</dfn> objects belong to commits or other tree objects.  Trees may
396 reference blobs, sub-trees, or commits of submodules.
397
398 <dfn
399 id=path>Path</dfn> names are stored in tree objects, but trees do not know
400 their own path name.  A tree's path name comes from their parent tree,
401 or it is the root tree referenced by a commit object.  Thus, this web UI
402 relies on the `b=' URI parameter as a hint to display the path name.
403
404 <dfn title="submodule commit"
405 id=g>Commit</dfn> objects may be stored in trees to reference submodules.</pre>
406 EOM
407         chop $$bref;
408         html_page($ctx, 200, $$bref);
409 }
410
411 sub show_tree ($$) {
412         my ($ctx, $res) = @_;
413         my ($git, $oid, undef, $size) = @$res;
414         $size > $MAX_SIZE and return html_page($ctx, 200,
415                         "tree $oid is too big to show\n". dbg_log($ctx));
416         my $cmd = [ 'git', "--git-dir=$git->{git_dir}",
417                 qw(ls-tree -z -l --no-abbrev), $oid ];
418         my $qsp = PublicInbox::Qspawn->new($cmd);
419         $ctx->{tree_oid} = $oid;
420         $qsp->{qsp_err} = \($ctx->{-qsp_err} = '');
421         $qsp->psgi_qx($ctx->{env}, undef, \&show_tree_result, $ctx);
422 }
423
424 # user_cb for SolverGit, called as: user_cb->($result_or_error, $uarg)
425 sub solve_result {
426         my ($res, $ctx) = @_;
427         my $hints = delete $ctx->{hints};
428         $res or return html_page($ctx, 404, dbg_log($ctx));
429         ref($res) eq 'ARRAY' or return html_page($ctx, 500, dbg_log($ctx));
430
431         my ($git, $oid, $type, $size, $di) = @$res;
432         return show_commit($ctx, $res) if $type eq 'commit';
433         return show_tree($ctx, $res) if $type eq 'tree';
434         return show_other($ctx, $res) if $type ne 'blob';
435         my $path = to_filename($di->{path_b} // $hints->{path_b} // 'blob');
436         my $raw_link = "(<a\nhref=$path>raw</a>)";
437         if ($size > $MAX_SIZE) {
438                 return stream_large_blob($ctx, $res) if defined $ctx->{fn};
439                 return html_page($ctx, 200, <<EOM . dbg_log($ctx));
440 <pre><b>Too big to show, download available</b>
441 blob $oid $size bytes $raw_link</pre>
442 EOM
443         }
444         @{$ctx->{-paths}} = ($path, $raw_link);
445         bless $ctx, 'PublicInbox::WwwStream'; # for DESTROY
446         $ctx->{git} = $git;
447         if ($ctx->{env}->{'pi-httpd.async'}) {
448                 ibx_async_cat($ctx, $oid, \&show_blob, $ctx);
449         } else { # synchronous
450                 $git->cat_async($oid, \&show_blob, $ctx);
451                 $git->cat_async_wait;
452         }
453 }
454
455 sub show_blob { # git->cat_async callback
456         my ($blob, $oid, $type, $size, $ctx) = @_;
457         if (!$blob) {
458                 my $e = "Failed to retrieve generated blob ($oid)";
459                 warn "$e ($ctx->{git}->{git_dir}) type=$type";
460                 return html_page($ctx, 500, "<pre><b>$e</b></pre>".dbg_log($ctx))
461         }
462
463         my $bin = index(substr($$blob, 0, $BIN_DETECT), "\0") >= 0;
464         if (defined $ctx->{fn}) {
465                 my $h = [ 'Content-Length', $size, 'Content-Type' ];
466                 push(@$h, ($bin ? 'application/octet-stream' : 'text/plain'));
467                 return delete($ctx->{-wcb})->([200, $h, [ $$blob ]]);
468         }
469
470         my ($path, $raw_link) = @{delete $ctx->{-paths}};
471         $bin and return html_page($ctx, 200,
472                                 "<pre>blob $oid $size bytes (binary)" .
473                                 " $raw_link</pre>".dbg_log($ctx));
474
475         # TODO: detect + convert to ensure validity
476         utf8::decode($$blob);
477         my $nl = ($$blob =~ s/\r?\n/\n/sg);
478         my $pad = length($nl);
479
480         ($ctx->{-linkify} //= PublicInbox::Linkify->new)->linkify_1($$blob);
481         my $ok = $hl->do_hl($blob, $path) if $hl;
482         if ($ok) {
483                 $blob = $ok;
484         } else {
485                 $$blob = ascii_html($$blob);
486         }
487
488         # using some of the same CSS class names and ids as cgit
489         my $x = "<pre>blob $oid $size bytes $raw_link</pre>" .
490                 "<hr /><table\nclass=blob>".
491                 "<tr><td\nclass=linenumbers><pre>";
492         # scratchpad in this loop is faster here than `printf $zfh':
493         $x .= sprintf("<a id=n$_ href=#n$_>% ${pad}u</a>\n", $_) for (1..$nl);
494         $x .= '</pre></td><td><pre> </pre></td>'. # pad for non-CSS users
495                 "<td\nclass=lines><pre\nstyle='white-space:pre'><code>";
496         html_page($ctx, 200, $x, $ctx->{-linkify}->linkify_2($$blob),
497                 '</code></pre></td></tr></table>'.dbg_log($ctx));
498 }
499
500 # GET /$INBOX/$GIT_OBJECT_ID/s/
501 # GET /$INBOX/$GIT_OBJECT_ID/s/$FILENAME
502 sub show ($$;$) {
503         my ($ctx, $oid_b, $fn) = @_;
504         my $qp = $ctx->{qp};
505         my $hints = $ctx->{hints} = {};
506         while (my ($from, $to) = each %QP_MAP) {
507                 defined(my $v = $qp->{$from}) or next;
508                 $hints->{$to} = $v if $v ne '';
509         }
510         $ctx->{fn} = $fn;
511         $ctx->{-tmp} = File::Temp->newdir("solver.$oid_b-XXXX", TMPDIR => 1);
512         open $ctx->{lh}, '+>>', "$ctx->{-tmp}/solve.log" or die "open: $!";
513         my $solver = PublicInbox::SolverGit->new($ctx->{ibx},
514                                                 \&solve_result, $ctx);
515         $solver->{gits} //= [ $ctx->{git} ];
516         $solver->{tmp} = $ctx->{-tmp}; # share tmpdir
517         # PSGI server will call this immediately and give us a callback (-wcb)
518         sub {
519                 $ctx->{-wcb} = $_[0]; # HTTP write callback
520                 $solver->solve($ctx->{env}, $ctx->{lh}, $oid_b, $hints);
521         };
522 }
523
524 1;