]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/SolverGit.pm
5ac27988591c961a9335735727d8b3cf80f825a4
[public-inbox.git] / lib / PublicInbox / SolverGit.pm
1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # "Solve" blobs which don't exist in git code repositories by
5 # searching inboxes for post-image blobs.
6
7 # this emits a lot of debugging/tracing information which may be
8 # publically viewed over HTTP(S).  Be careful not to expose
9 # local filesystem layouts in the process.
10 package PublicInbox::SolverGit;
11 use strict;
12 use warnings;
13 use 5.010_001;
14 use File::Temp 0.19 ();
15 use Fcntl qw(SEEK_SET);
16 use PublicInbox::Git qw(git_unquote git_quote);
17 use PublicInbox::MsgIter qw(msg_iter msg_part_text);
18 use PublicInbox::Qspawn;
19 use PublicInbox::Tmpfile;
20 use URI::Escape qw(uri_escape_utf8);
21
22 # POSIX requires _POSIX_ARG_MAX >= 4096, and xargs is required to
23 # subtract 2048 bytes.  We also don't factor in environment variable
24 # headroom into this.
25 use POSIX qw(sysconf _SC_ARG_MAX);
26 my $ARG_SIZE_MAX = (sysconf(_SC_ARG_MAX) || 4096) - 2048;
27 my $OID_MIN = 7;
28
29 # By default, "git format-patch" generates filenames with a four-digit
30 # prefix, so that means 9999 patch series are OK, right? :>
31 # Maybe we can make this configurable, main concern is disk space overhead
32 # for uncompressed patch fragments.  Aside from space, public-inbox-httpd
33 # is otherwise unaffected by having many patches, here, as it can share
34 # work fairly.  Other PSGI servers may have trouble, though.
35 my $MAX_PATCH = 9999;
36
37 # di = diff info / a hashref with information about a diff ($di):
38 # {
39 #       oid_a => abbreviated pre-image oid,
40 #       oid_b => abbreviated post-image oid,
41 #       tmp => anonymous file handle with the diff,
42 #       hdr_lines => string of various header lines for mode information
43 #       mode_a => original mode of oid_a (string, not integer),
44 #       ibx => PublicInbox::Inbox object containing the diff
45 #       smsg => PublicInbox::SearchMsg object containing diff
46 #       path_a => pre-image path
47 #       path_b => post-image path
48 #       n => numeric path of the patch (relative to worktree)
49 # }
50
51 sub dbg ($$) {
52         print { $_[0]->{out} } $_[1], "\n" or ERR($_[0], "print(dbg): $!");
53 }
54
55 sub done ($$) {
56         my ($self, $res) = @_;
57         my $ucb = delete($self->{user_cb}) or return;
58         $ucb->($res, $self->{uarg});
59 }
60
61 sub ERR ($$) {
62         my ($self, $err) = @_;
63         print { $self->{out} } $err, "\n";
64         eval { done($self, $err) };
65         die $err;
66 }
67
68 # look for existing objects already in git repos
69 sub solve_existing ($$) {
70         my ($self, $want) = @_;
71         my $oid_b = $want->{oid_b};
72         my $have_hints = scalar keys %$want > 1;
73         my @ambiguous; # Array of [ git, $oids]
74         foreach my $git (@{$self->{gits}}) {
75                 my ($oid_full, $type, $size) = $git->check($oid_b);
76                 if (defined($type) && (!$have_hints || $type eq 'blob')) {
77                         return [ $git, $oid_full, $type, int($size) ];
78                 }
79
80                 next if length($oid_b) == 40;
81
82                 # parse stderr of "git cat-file --batch-check"
83                 my $err = $git->last_check_err;
84                 my (@oids) = ($err =~ /\b([a-f0-9]{40})\s+blob\b/g);
85                 next unless scalar(@oids);
86
87                 # TODO: do something with the ambiguous array?
88                 # push @ambiguous, [ $git, @oids ];
89
90                 dbg($self, "`$oid_b' ambiguous in " .
91                                 join("\n\t", $git->pub_urls($self->{psgi_env}))
92                                 . "\n" .
93                                 join('', map { "$_ blob\n" } @oids));
94         }
95         scalar(@ambiguous) ? \@ambiguous : undef;
96 }
97
98 sub extract_diff ($$) {
99         my ($p, $arg) = @_;
100         my ($self, $diffs, $pre, $post, $ibx, $smsg) = @$arg;
101         my ($part) = @$p; # ignore $depth and @idx;
102         my $ct = $part->content_type || 'text/plain';
103         my ($s, undef) = msg_part_text($part, $ct);
104         defined $s or return;
105
106         # Email::MIME::Encodings forces QP to be CRLF upon decoding,
107         # change it back to LF:
108         my $cte = $part->header('Content-Transfer-Encoding') || '';
109         if ($cte =~ /\bquoted-printable\b/i && $part->crlf eq "\n") {
110                 $s =~ s/\r\n/\n/sg;
111         }
112
113         state $LF = qr!\r?\n!;
114         state $ANY = qr![^\r\n]+!;
115         state $MODE = '100644|120000|100755';
116         state $FN = qr!(?:("?[^/\n]+/[^\r\n]+)|/dev/null)!;
117
118         $s =~ m!( # $1 start header lines we save for debugging:
119
120                 # everything before ^index is optional, but we don't
121                 # want to match ^(old|copy|rename|deleted|...) unless
122                 # we match /^diff --git/ first:
123                 (?: # begin optional stuff:
124
125                 # try to get the pre-and-post filenames as $2 and $3
126                 (?:^diff\x20--git\x20$FN\x20$FN$LF)
127
128                 (?:^(?: # pass all this to git-apply:
129                         # old mode $4
130                         (?:old\x20mode\x20($MODE))
131                         |
132                         # new mode (possibly new file) ($5)
133                         (?:new\x20(?:file\x20)?mode\x20($MODE))
134                         |
135                         (?:(?:copy|rename|deleted|
136                                 dissimilarity|similarity)$ANY)
137                 )$LF)*
138
139                 )? # end of optional stuff, everything below is required
140
141                 # match the pre and post-image OIDs as $6 $7
142                 ^index\x20(${pre}[a-f0-9]*)\.\.(${post}[a-f0-9]*)
143                         # mode if unchanged $8
144                         (?:\x20(100644|120000|100755))?$LF
145         ) # end of header lines ($1)
146         ( # $9 is the patch body
147                 # "--- a/foo.c" sets pre-filename ($10) in case
148                 # $2 is missing
149                 (?:^---\x20$FN$LF)
150
151                 # "+++ b/foo.c" sets post-filename ($11) in case
152                 # $3 is missing
153                 (?:^\+{3}\x20$FN$LF)
154
155                 # the meat of the diff, including "^\\No newline ..."
156                 # We also allow for totally blank lines w/o leading spaces,
157                 # because git-apply(1) handles that case, too
158                 (?:^(?:[\@\+\x20\-\\][^\n]*|)$LF)+
159         )!smx or return;
160
161         my $di = {
162                 hdr_lines => $1,
163                 oid_a => $6,
164                 oid_b => $7,
165                 mode_a => $5 // $8 // $4, # new (file) // unchanged // old
166         };
167         my $path_a = $2 // $10;
168         my $path_b = $3 // $11;
169         my $patch = $9;
170
171         # don't care for leading 'a/' and 'b/'
172         my (undef, @a) = split(m{/}, git_unquote($path_a));
173         my (undef, @b) = split(m{/}, git_unquote($path_b));
174
175         # get rid of path-traversal attempts and junk patches:
176         # it's junk at best, an attack attempt at worse:
177         state $bad_component = { map { $_ => 1 } ('', '.', '..') };
178         foreach (@a, @b) { return if $bad_component->{$_} }
179
180         $di->{path_a} = join('/', @a);
181         $di->{path_b} = join('/', @b);
182
183         my $path = ++$self->{tot};
184         $di->{n} = $path;
185         open(my $tmp, '>:utf8', $self->{tmp}->dirname . "/$path") or
186                 die "open(tmp): $!";
187         print $tmp $di->{hdr_lines}, $patch or die "print(tmp): $!";
188         close $tmp or die "close(tmp): $!";
189
190         # for debugging/diagnostics:
191         $di->{ibx} = $ibx;
192         $di->{smsg} = $smsg;
193
194         push @$diffs, $di;
195 }
196
197 sub path_searchable ($) { defined($_[0]) && $_[0] =~ m!\A[\w/\. \-]+\z! }
198
199 # ".." appears in path names, which confuses Xapian into treating
200 # it as a range query.  So we split on ".." since Xapian breaks
201 # on punctuation anyways:
202 sub filename_query ($) {
203         join('', map { qq( dfn:"$_") } split(/\.\./, $_[0]));
204 }
205
206 sub find_extract_diffs ($$$) {
207         my ($self, $ibx, $want) = @_;
208         my $srch = $ibx->search or return;
209
210         my $post = $want->{oid_b} or die 'BUG: no {oid_b}';
211         $post =~ /\A[a-f0-9]+\z/ or die "BUG: oid_b not hex: $post";
212
213         my $q = "dfpost:$post";
214         my $pre = $want->{oid_a};
215         if (defined $pre && $pre =~ /\A[a-f0-9]+\z/) {
216                 $q .= " dfpre:$pre";
217         } else {
218                 $pre = '[a-f0-9]{7}'; # for $re below
219         }
220
221         my $path_b = $want->{path_b};
222         if (path_searchable($path_b)) {
223                 $q .= filename_query($path_b);
224
225                 my $path_a = $want->{path_a};
226                 if (path_searchable($path_a) && $path_a ne $path_b) {
227                         $q .= filename_query($path_a);
228                 }
229         }
230
231         my $msgs = $srch->query($q, { relevance => 1 });
232
233         my $diffs = [];
234         foreach my $smsg (@$msgs) {
235                 $ibx->smsg_mime($smsg) or next;
236                 my $mime = delete $smsg->{mime};
237                 msg_iter($mime, \&extract_diff,
238                                 [$self, $diffs, $pre, $post, $ibx, $smsg]);
239         }
240         @$diffs ? $diffs : undef;
241 }
242
243 sub update_index_result ($$) {
244         my ($bref, $self) = @_;
245         my ($qsp, $msg) = delete @$self{qw(-qsp -msg)};
246         if (my $err = $qsp->{err}) {
247                 ERR($self, "git update-index error: $err");
248         }
249         dbg($self, $msg);
250         next_step($self); # onto do_git_apply
251 }
252
253 sub prepare_index ($) {
254         my ($self) = @_;
255         my $patches = $self->{patches};
256         $self->{nr} = 0;
257
258         my $di = $patches->[0] or die 'no patches';
259         my $oid_a = $di->{oid_a} or die '{oid_a} unset';
260         my $existing = $self->{found}->{$oid_a};
261
262         # no index creation for added files
263         $oid_a =~ /\A0+\z/ and return next_step($self);
264
265         die "BUG: $oid_a not not found" unless $existing;
266
267         my $oid_full = $existing->[1];
268         my $path_a = $di->{path_a} or die "BUG: path_a missing for $oid_full";
269         my $mode_a = $di->{mode_a} // '100644';
270
271         my $in = tmpfile("update-index.$oid_full") or die "tmpfile: $!";
272         print $in "$mode_a $oid_full\t$path_a\0" or die "print: $!";
273         $in->flush or die "flush: $!";
274         sysseek($in, 0, 0) or die "seek: $!";
275
276         dbg($self, 'preparing index');
277         my $rdr = { 0 => $in };
278         my $cmd = [ qw(git update-index -z --index-info) ];
279         my $qsp = PublicInbox::Qspawn->new($cmd, $self->{git_env}, $rdr);
280         $path_a = git_quote($path_a);
281         $self->{-qsp} = $qsp;
282         $self->{-msg} = "index prepared:\n$mode_a $oid_full\t$path_a";
283         $qsp->psgi_qx($self->{psgi_env}, undef, \&update_index_result, $self);
284 }
285
286 # pure Perl "git init"
287 sub do_git_init ($) {
288         my ($self) = @_;
289         my $dir = $self->{tmp}->dirname;
290         my $git_dir = "$dir/git";
291
292         foreach ('', qw(objects refs objects/info refs/heads)) {
293                 mkdir("$git_dir/$_") or die "mkdir $_: $!";
294         }
295         open my $fh, '>', "$git_dir/config" or die "open git/config: $!";
296         print $fh <<'EOF' or die "print git/config $!";
297 [core]
298         repositoryFormatVersion = 0
299         filemode = true
300         bare = false
301         fsyncObjectfiles = false
302         logAllRefUpdates = false
303 EOF
304         close $fh or die "close git/config: $!";
305
306         open $fh, '>', "$git_dir/HEAD" or die "open git/HEAD: $!";
307         print $fh "ref: refs/heads/master\n" or die "print git/HEAD: $!";
308         close $fh or die "close git/HEAD: $!";
309
310         my $f = 'objects/info/alternates';
311         open $fh, '>', "$git_dir/$f" or die "open: $f: $!";
312         foreach my $git (@{$self->{gits}}) {
313                 print $fh $git->git_path('objects'),"\n" or die "print $f: $!";
314         }
315         close $fh or die "close: $f: $!";
316         my $tmp_git = $self->{tmp_git} = PublicInbox::Git->new($git_dir);
317         $tmp_git->{-tmp} = $self->{tmp};
318         $self->{git_env} = {
319                 GIT_DIR => $git_dir,
320                 GIT_INDEX_FILE => "$git_dir/index",
321         };
322         prepare_index($self);
323 }
324
325 sub do_finish ($) {
326         my ($self) = @_;
327         my ($found, $oid_want) = @$self{qw(found oid_want)};
328         if (my $exists = $found->{$oid_want}) {
329                 return done($self, $exists);
330         }
331
332         # let git disambiguate if oid_want was too short,
333         # but long enough to be unambiguous:
334         my $tmp_git = $self->{tmp_git};
335         if (my @res = $tmp_git->check($oid_want)) {
336                 return done($self, $found->{$res[0]});
337         }
338         if (my $err = $tmp_git->last_check_err) {
339                 dbg($self, $err);
340         }
341         done($self, undef);
342 }
343
344 sub event_step ($) {
345         my ($self) = @_;
346         eval {
347                 # step 1: resolve blobs to patches in the todo queue
348                 if (my $want = pop @{$self->{todo}}) {
349                         # this populates {patches} and {todo}
350                         resolve_patch($self, $want);
351
352                 # step 2: then we instantiate a working tree once
353                 # the todo queue is finally empty:
354                 } elsif (!defined($self->{tmp_git})) {
355                         do_git_init($self);
356
357                 # step 3: apply each patch in the stack
358                 } elsif (scalar @{$self->{patches}}) {
359                         do_git_apply($self);
360
361                 # step 4: execute the user-supplied callback with
362                 # our result: (which may be undef)
363                 # Other steps may call user_cb to terminate prematurely
364                 # on error
365                 } elsif (exists $self->{user_cb}) {
366                         do_finish($self);
367                 } else {
368                         die 'about to call user_cb twice'; # Oops :x
369                 }
370         }; # eval
371         my $err = $@;
372         if ($err) {
373                 $err =~ s/^\s*Exception:\s*//; # bad word to show users :P
374                 dbg($self, "E: $err");
375                 eval { done($self, $err) };
376         }
377 }
378
379 sub next_step ($) {
380         my ($self) = @_;
381         # if outside of public-inbox-httpd, caller is expected to be
382         # looping event_step, anyways
383         my $async = $self->{psgi_env}->{'pi-httpd.async'} or return;
384         # PublicInbox::HTTPD::Async->new
385         $async->(undef, undef, $self);
386 }
387
388 sub mark_found ($$$) {
389         my ($self, $oid, $found_info) = @_;
390         my $found = $self->{found};
391         $found->{$oid} = $found_info;
392         my $oid_cur = $found_info->[1];
393         while ($oid_cur ne $oid && length($oid_cur) > $OID_MIN) {
394                 $found->{$oid_cur} = $found_info;
395                 chop($oid_cur);
396         }
397 }
398
399 sub parse_ls_files ($$) {
400         my ($self, $bref) = @_;
401         my ($qsp, $di) = delete @$self{qw(-qsp -cur_di)};
402         if (my $err = $qsp->{err}) {
403                 die "git ls-files error: $err";
404         }
405
406         my ($line, @extra) = split(/\0/, $$bref);
407         scalar(@extra) and die "BUG: extra files in index: <",
408                                 join('> <', @extra), ">";
409
410         my ($info, $file) = split(/\t/, $line, 2);
411         my ($mode_b, $oid_b_full, $stage) = split(/ /, $info);
412         if ($file ne $di->{path_b}) {
413                 die
414 "BUG: index mismatch: file=$file != path_b=$di->{path_b}";
415         }
416
417         my $tmp_git = $self->{tmp_git} or die 'no git working tree';
418         my (undef, undef, $size) = $tmp_git->check($oid_b_full);
419         defined($size) or die "check $oid_b_full failed";
420
421         dbg($self, "index at:\n$mode_b $oid_b_full\t$file");
422         my $created = [ $tmp_git, $oid_b_full, 'blob', $size, $di ];
423         mark_found($self, $di->{oid_b}, $created);
424         next_step($self); # onto the next patch
425 }
426
427 sub ls_files_result {
428         my ($bref, $self) = @_;
429         eval { parse_ls_files($self, $bref) };
430         ERR($self, $@) if $@;
431 }
432
433 sub oids_same_ish ($$) {
434         (index($_[0], $_[1]) == 0) || (index($_[1], $_[0]) == 0);
435 }
436
437 sub skip_identical ($$$) {
438         my ($self, $patches, $cur_oid_b) = @_;
439         while (my $nxt = $patches->[0]) {
440                 if (oids_same_ish($cur_oid_b, $nxt->{oid_b})) {
441                         dbg($self, 'skipping '.di_url($self, $nxt).
442                                 " for $cur_oid_b");
443                         shift @$patches;
444                 } else {
445                         return;
446                 }
447         }
448 }
449
450 sub apply_result ($$) {
451         my ($bref, $self) = @_;
452         my ($qsp, $di) = delete @$self{qw(-qsp -cur_di)};
453         dbg($self, $$bref);
454         my $patches = $self->{patches};
455         if (my $err = $qsp->{err}) {
456                 my $msg = "git apply error: $err";
457                 my $nxt = $patches->[0];
458                 if ($nxt && oids_same_ish($nxt->{oid_b}, $di->{oid_b})) {
459                         dbg($self, $msg);
460                         dbg($self, 'trying '.di_url($self, $nxt));
461                         return do_git_apply($self);
462                 } else {
463                         ERR($self, $msg);
464                 }
465         } else {
466                 skip_identical($self, $patches, $di->{oid_b});
467         }
468
469         my @cmd = qw(git ls-files -s -z);
470         $qsp = PublicInbox::Qspawn->new(\@cmd, $self->{git_env});
471         $self->{-cur_di} = $di;
472         $self->{-qsp} = $qsp;
473         $qsp->psgi_qx($self->{psgi_env}, undef, \&ls_files_result, $self);
474 }
475
476 sub do_git_apply ($) {
477         my ($self) = @_;
478         my $dn = $self->{tmp}->dirname;
479         my $patches = $self->{patches};
480
481         # we need --ignore-whitespace because some patches are CRLF
482         my @cmd = (qw(git apply --cached --ignore-whitespace
483                         --unidiff-zero --whitespace=warn --verbose));
484         my $len = length(join(' ', @cmd));
485         my $total = $self->{tot};
486         my $di; # keep track of the last one for "git ls-files"
487         my $prv_oid_b;
488
489         do {
490                 my $i = ++$self->{nr};
491                 $di = shift @$patches;
492                 dbg($self, "\napplying [$i/$total] " . di_url($self, $di) .
493                         "\n" . $di->{hdr_lines});
494                 my $path = $di->{n};
495                 $len += length($path) + 1;
496                 push @cmd, $path;
497                 $prv_oid_b = $di->{oid_b};
498         } while (@$patches && $len < $ARG_SIZE_MAX &&
499                  !oids_same_ish($patches->[0]->{oid_b}, $prv_oid_b));
500
501         my $opt = { 2 => 1, -C => $dn, quiet => 1 };
502         my $qsp = PublicInbox::Qspawn->new(\@cmd, $self->{git_env}, $opt);
503         $self->{-cur_di} = $di;
504         $self->{-qsp} = $qsp;
505         $qsp->psgi_qx($self->{psgi_env}, undef, \&apply_result, $self);
506 }
507
508 sub di_url ($$) {
509         my ($self, $di) = @_;
510         # note: we don't pass the PSGI env unconditionally, here,
511         # different inboxes can have different HTTP_HOST on the same instance.
512         my $ibx = $di->{ibx};
513         my $env = $self->{psgi_env} if $ibx eq $self->{inboxes}->[0];
514         my $url = $ibx->base_url($env);
515         my $mid = $di->{smsg}->{mid};
516         defined($url) ? "$url$mid/" : "<$mid>";
517 }
518
519 sub resolve_patch ($$) {
520         my ($self, $want) = @_;
521
522         if (scalar(@{$self->{patches}}) > $MAX_PATCH) {
523                 die "Aborting, too many steps to $self->{oid_want}";
524         }
525
526         # see if we can find the blob in an existing git repo:
527         my $cur_want = $want->{oid_b};
528         if ($self->{seen_oid}->{$cur_want}++) {
529                 die "Loop detected solving $cur_want\n";
530         }
531         if (my $existing = solve_existing($self, $want)) {
532                 my ($found_git, undef, $type, undef) = @$existing;
533                 dbg($self, "found $cur_want in " .
534                         join("\n", $found_git->pub_urls($self->{psgi_env})));
535
536                 if ($cur_want eq $self->{oid_want} || $type ne 'blob') {
537                         eval { done($self, $existing) };
538                         die "E: $@" if $@;
539                         return;
540                 }
541                 mark_found($self, $cur_want, $existing);
542                 return next_step($self); # onto patch application
543         }
544
545         # scan through inboxes to look for emails which results in
546         # the oid we want:
547         foreach my $ibx (@{$self->{inboxes}}) {
548                 my $diffs = find_extract_diffs($self, $ibx, $want) or next;
549
550                 unshift @{$self->{patches}}, @$diffs;
551                 dbg($self, "found $cur_want in ".
552                         join("\n\t", map { di_url($self, $_) } @$diffs));
553
554                 # good, we can find a path to the oid we $want, now
555                 # lets see if we need to apply more patches:
556                 my $di = $diffs->[0];
557                 my $src = $di->{oid_a};
558
559                 unless ($src =~ /\A0+\z/) {
560                         # we have to solve it using another oid, fine:
561                         my $job = { oid_b => $src, path_b => $di->{path_a} };
562                         push @{$self->{todo}}, $job;
563                 }
564                 return next_step($self); # onto the next todo item
565         }
566         if (length($cur_want) > $OID_MIN) {
567                 chop($cur_want);
568                 dbg($self, "retrying $want->{oid_b} as $cur_want");
569                 $want->{oid_b} = $cur_want;
570                 push @{$self->{todo}}, $want;
571                 return next_step($self); # retry with shorter abbrev
572         }
573
574         dbg($self, "could not find $cur_want");
575         eval { done($self, undef) };
576         die "E: $@" if $@;
577 }
578
579 # this API is designed to avoid creating self-referential structures;
580 # so user_cb never references the SolverGit object
581 sub new {
582         my ($class, $ibx, $user_cb, $uarg) = @_;
583
584         bless {
585                 gits => $ibx->{-repo_objs},
586                 user_cb => $user_cb,
587                 uarg => $uarg,
588                 # -cur_di, -qsp, -msg => temporary fields for Qspawn callbacks
589
590                 # TODO: config option for searching related inboxes
591                 inboxes => [ $ibx ],
592         }, $class;
593 }
594
595 # recreate $oid_want using $hints
596 # hints keys: path_a, path_b, oid_a
597 # Calls {user_cb} with: [ ::Git object, oid_full, type, size, di (diff_info) ]
598 # with found object, or undef if nothing was found
599 # Calls {user_cb} with a string error on fatal errors
600 sub solve ($$$$$) {
601         my ($self, $env, $out, $oid_want, $hints) = @_;
602
603         # should we even get here? Probably not, but somebody
604         # could be manually typing URLs:
605         return done($self, undef) if $oid_want =~ /\A0+\z/;
606
607         $self->{oid_want} = $oid_want;
608         $self->{out} = $out;
609         $self->{seen_oid} = {};
610         $self->{tot} = 0;
611         $self->{psgi_env} = $env;
612         $self->{todo} = [ { %$hints, oid_b => $oid_want } ];
613         $self->{patches} = []; # [ $di, $di, ... ]
614         $self->{found} = {}; # { abbr => [ ::Git, oid, type, size, $di ] }
615         $self->{tmp} = File::Temp->newdir("solver.$oid_want-XXXXXXXX", TMPDIR => 1);
616
617         dbg($self, "solving $oid_want ...");
618         if (my $async = $env->{'pi-httpd.async'}) {
619                 # PublicInbox::HTTPD::Async->new
620                 $async->(undef, undef, $self);
621         } else {
622                 event_step($self) while $self->{user_cb};
623         }
624 }
625
626 1;