print { $_[0]->{out} } $_[1], "\n" or ERR($_[0], "print(dbg): $!");
}
+sub done ($$) {
+ my ($self, $res) = @_;
+ my $ucb = delete($self->{user_cb}) or return;
+ $ucb->($res, $self->{uarg});
+}
+
sub ERR ($$) {
my ($self, $err) = @_;
print { $self->{out} } $err, "\n";
- my $ucb = delete($self->{user_cb});
- eval { $ucb->($err) } if $ucb;
+ eval { done($self, $err) };
die $err;
}
scalar(@ambiguous) ? \@ambiguous : undef;
}
-sub extract_diff ($$$$$) {
- my ($self, $p, $re, $ibx, $smsg) = @_;
+sub extract_diff ($$) {
+ my ($p, $arg) = @_;
+ my ($self, $diffs, $re, $ibx, $smsg) = @$arg;
my ($part) = @$p; # ignore $depth and @idx;
my $hdr_lines; # diff --git a/... b/...
my $tmp;
}
return undef unless $tmp;
close $tmp or die "close(tmp): $!";
- $di;
+ push @$diffs, $di;
}
sub path_searchable ($) { defined($_[0]) && $_[0] =~ m!\A[\w/\. \-]+\z! }
my $msgs = $srch->query($q, { relevance => 1 });
my $re = qr/\Aindex ($pre[a-f0-9]*)\.\.($post[a-f0-9]*)(?: ([0-9]+))?/;
-
- my @di;
+ my $diffs = [];
foreach my $smsg (@$msgs) {
$ibx->smsg_mime($smsg) or next;
- msg_iter(delete($smsg->{mime}), sub {
- my $di = extract_diff($self, $_[0], $re, $ibx, $smsg);
- push @di, $di if defined($di);
- });
+ my $mime = delete $smsg->{mime};
+ msg_iter($mime, \&extract_diff,
+ [$self, $diffs, $re, $ibx, $smsg]);
}
- @di ? \@di : undef;
+ @$diffs ? $diffs : undef;
}
sub update_index_result ($$) {
sysseek($in, 0, 0) or die "seek: $!";
dbg($self, 'preparing index');
- my $rdr = { 0 => fileno($in), -hold => $in };
+ my $rdr = { 0 => $in };
my $cmd = [ qw(git update-index -z --index-info) ];
my $qsp = PublicInbox::Qspawn->new($cmd, $self->{git_env}, $rdr);
$path_a = git_quote($path_a);
'100644';
}
-sub do_finish ($$) {
- my ($self, $user_cb) = @_;
- my $found = $self->{found};
- my $oid_want = $self->{oid_want};
+sub do_finish ($) {
+ my ($self) = @_;
+ my ($found, $oid_want) = @$self{qw(found oid_want)};
if (my $exists = $found->{$oid_want}) {
- return $user_cb->($exists);
+ return done($self, $exists);
}
# let git disambiguate if oid_want was too short,
# but long enough to be unambiguous:
my $tmp_git = $self->{tmp_git};
if (my @res = $tmp_git->check($oid_want)) {
- return $user_cb->($found->{$res[0]});
+ return done($self, $found->{$res[0]});
}
if (my $err = $tmp_git->last_check_err) {
dbg($self, $err);
}
- $user_cb->(undef);
+ done($self, undef);
}
sub event_step ($) {
# our result: (which may be undef)
# Other steps may call user_cb to terminate prematurely
# on error
- } elsif (my $user_cb = delete($self->{user_cb})) {
- do_finish($self, $user_cb);
+ } elsif (exists $self->{user_cb}) {
+ do_finish($self);
} else {
die 'about to call user_cb twice'; # Oops :x
}
if ($err) {
$err =~ s/^\s*Exception:\s*//; # bad word to show users :P
dbg($self, "E: $err");
- my $ucb = delete($self->{user_cb});
- eval { $ucb->($err) } if $ucb;
+ eval { done($self, $err) };
}
}
if ($nxt && oids_same_ish($nxt->{oid_b}, $di->{oid_b})) {
dbg($self, $msg);
dbg($self, 'trying '.di_url($self, $nxt));
+ return do_git_apply($self);
} else {
ERR($self, $msg);
}
my $patches = $self->{patches};
# we need --ignore-whitespace because some patches are CRLF
- my @cmd = (qw(git -C), $dn, qw(apply --cached --ignore-whitespace
+ my @cmd = (qw(git apply --cached --ignore-whitespace
--unidiff-zero --whitespace=warn --verbose));
my $len = length(join(' ', @cmd));
my $total = $self->{tot};
} while (@$patches && $len < $ARG_SIZE_MAX &&
!oids_same_ish($patches->[0]->{oid_b}, $prv_oid_b));
- my $rdr = { 2 => 1 };
- my $qsp = PublicInbox::Qspawn->new(\@cmd, $self->{git_env}, $rdr);
+ my $opt = { 2 => 1, -C => $dn };
+ my $qsp = PublicInbox::Qspawn->new(\@cmd, $self->{git_env}, $opt);
$self->{-cur_di} = $di;
$self->{-qsp} = $qsp;
$qsp->psgi_qx($self->{psgi_env}, undef, \&apply_result, $self);
join("\n", $found_git->pub_urls($self->{psgi_env})));
if ($cur_want eq $self->{oid_want} || $type ne 'blob') {
- eval { delete($self->{user_cb})->($existing) };
+ eval { done($self, $existing) };
die "E: $@" if $@;
return;
}
}
dbg($self, "could not find $cur_want");
- eval { delete($self->{user_cb})->(undef) }; # not found! :<
+ eval { done($self, undef) };
die "E: $@" if $@;
}
# this API is designed to avoid creating self-referential structures;
# so user_cb never references the SolverGit object
sub new {
- my ($class, $ibx, $user_cb) = @_;
+ my ($class, $ibx, $user_cb, $uarg) = @_;
bless {
gits => $ibx->{-repo_objs},
user_cb => $user_cb,
+ uarg => $uarg,
# -cur_di, -qsp, -msg => temporary fields for Qspawn callbacks
# TODO: config option for searching related inboxes
# should we even get here? Probably not, but somebody
# could be manually typing URLs:
- return (delete $self->{user_cb})->(undef) if $oid_want =~ /\A0+\z/;
+ return done($self, undef) if $oid_want =~ /\A0+\z/;
$self->{oid_want} = $oid_want;
$self->{out} = $out;