diff options
author | Eric Wong <e@80x24.org> | 2023-10-25 00:29:25 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-10-25 07:28:31 +0000 |
commit | 07f639c9219968a01d5c722424e9c61d3b146014 (patch) | |
tree | 90819294795e27bf2ee74893a4e4cabebf05d84b /lib/PublicInbox/SearchIdx.pm | |
parent | f81954fe591c6a6358ba528118874313e3920e83 (diff) | |
download | public-inbox-07f639c9219968a01d5c722424e9c61d3b146014.tar.gz |
This is similar to `backtick` but supports all our existing spawn functionality (chdir, env, rlimit, redirects, etc.). It also supports SCALAR ref redirects like run_script in our test suite for std{in,out,err}. We can probably use :utf8 by default for these redirects, even.
Diffstat (limited to 'lib/PublicInbox/SearchIdx.pm')
-rw-r--r-- | lib/PublicInbox/SearchIdx.pm | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 8a571cfb..3c64c715 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -22,7 +22,7 @@ use POSIX qw(strftime); use Fcntl qw(SEEK_SET); use Time::Local qw(timegm); use PublicInbox::OverIdx; -use PublicInbox::Spawn qw(run_wait); +use PublicInbox::Spawn qw(run_wait run_qx); use PublicInbox::Git qw(git_unquote); use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp); use PublicInbox::Address; @@ -351,23 +351,18 @@ sub index_diff ($$$) { } sub patch_id { - my ($self) = @_; # $_[1] is the diff (may be huge) - open(my $fh, '+>:utf8', undef) or die "open: $!"; - open(my $eh, '+>', undef) or die "open: $!"; - $fh->autoflush(1); - print $fh $_[1] or die "print: $!"; - sysseek($fh, 0, SEEK_SET) or die "sysseek: $!"; - my $id = ($self->{ibx} // $self->{eidx} // $self)->git->qx( - [qw(patch-id --stable)], {}, { 0 => $fh, 2 => $eh }); - seek($eh, 0, SEEK_SET) or die "seek: $!"; - while (<$eh>) { warn $_ } + my ($self, $sref) = @_; + my $git = ($self->{ibx} // $self->{eidx} // $self)->git; + my $opt = { 0 => $sref, 2 => \(my $err) }; + my $id = run_qx($git->cmd(qw(patch-id --stable)), undef, $opt); + warn $err if $err; $id =~ /\A([a-f0-9]{40,})/ ? $1 : undef; } sub index_body_text { my ($self, $doc, $sref) = @_; if ($$sref =~ /^(?:diff|---|\+\+\+) /ms) { - my $id = patch_id($self, $$sref); + my $id = patch_id($self, $sref); $doc->add_term('XDFID'.$id) if defined($id); } |