use strict;
use warnings;
use POSIX qw(dup2);
-require IO::Handle;
+use IO::Handle; # ->autoflush
use PublicInbox::Spawn qw(spawn popen_rd);
use PublicInbox::Tmpfile;
use base qw(Exporter);
my @cmd = (qw(git), "--git-dir=$self->{git_dir}",
qw(-c core.abbrev=40 cat-file), $batch);
- my $redir = { 0 => fileno($out_r), 1 => fileno($in_w) };
+ my $redir = { 0 => $out_r, 1 => $in_w };
if ($err) {
my $id = "git.$self->{git_dir}$batch.err";
my $fh = tmpfile($id) or fail($self, "tmpfile($id): $!");
$self->{$err} = $fh;
- $redir->{2} = fileno($fh);
+ $redir->{2} = $fh;
}
my $p = spawn(\@cmd, undef, $redir);
- defined $p or fail($self, "spawn failed: $!");
$self->{$pid} = $p;
$out_w->autoflush(1);
$self->{$out} = $out_w;
sub qx {
my ($self, @cmd) = @_;
my $fh = $self->popen(@cmd);
- defined $fh or return;
local $/ = "\n";
return <$fh> if wantarray;
local $/;
my ($env, $url) = @_;
return $url if index($url, '//') >= 0;
my $scheme = $env->{'psgi.url_scheme'};
- my $host_port = $env->{HTTP_HOST} ||
+ my $host_port = $env->{HTTP_HOST} //
"$env->{SERVER_NAME}:$env->{SERVER_PORT}";
"$scheme://$host_port". ($env->{SCRIPT_NAME} || '/') . $url;
}
push(@$inflight, [ $cb, $arg ]);
}
-sub commit_title ($$) {
- my ($self, $oid) = @_; # PublicInbox::Git, $sha1hex
- my $buf = cat_file($self, $oid) or return;
- utf8::decode($$buf);
- ($$buf =~ /\r?\n\r?\n([^\r\n]+)\r?\n?/)[0]
+sub extract_cmt_time {
+ my ($bref, undef, undef, undef, $modified) = @_;
+
+ if ($$bref =~ /^committer .*?> ([0-9]+) [\+\-]?[0-9]+/sm) {
+ my $cmt_time = $1 + 0;
+ $$modified = $cmt_time if $cmt_time > $$modified;
+ }
}
# returns the modified time of a git repo, same as the "modified" field
my ($self) = @_;
my $modified = 0;
my $fh = popen($self, qw(rev-parse --branches));
- defined $fh or return $modified;
+ cat_async_begin($self);
local $/ = "\n";
- foreach my $oid (<$fh>) {
+ while (my $oid = <$fh>) {
chomp $oid;
- my $buf = cat_file($self, $oid) or next;
- $$buf =~ /^committer .*?> ([0-9]+) [\+\-]?[0-9]+/sm or next;
- my $cmt_time = $1 + 0;
- $modified = $cmt_time if $cmt_time > $modified;
+ cat_async($self, $oid, \&extract_cmt_time, \$modified);
}
+ cat_async_wait($self);
$modified || time;
}