X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FGit.pm;h=d048051ea1e48479d0585ae2df04fa0a67aaa681;hb=9bd675d33ad1e49bd2ebe12a1d216216e61380de;hp=a4daaa48f0914f538e1232b66267384a2dafec0d;hpb=97b45ccc7ae2f721744bd7ee1f1cbaab9e6df790;p=public-inbox.git
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index a4daaa48..d048051e 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2014-2018 all contributors
+# Copyright (C) 2014-2019 all contributors
# License: GPLv2 or later
#
# Used to read files from a git repository without excessive forking.
@@ -141,45 +141,28 @@ again:
}
return;
}
- $head =~ /^[0-9a-f]{40} \S+ (\d+)$/ or
+ $head =~ /^[0-9a-f]{40} \S+ ([0-9]+)$/ or
fail($self, "Unexpected result from git cat-file: $head");
my $size = $1;
- my $ref_type = $ref ? ref($ref) : '';
-
my $rv;
my $left = $size;
- $$ref = $size if ($ref_type eq 'SCALAR');
- my $cb_err;
-
- if ($ref_type eq 'CODE') {
- $rv = eval { $ref->($in, \$left) };
- $cb_err = $@;
- # drain the rest
- my $max = 8192;
- while ($left > 0) {
- my $r = read($in, my $x, $left > $max ? $max : $left);
- defined($r) or fail($self, "read failed: $!");
- $r == 0 and fail($self, 'exited unexpectedly');
- $left -= $r;
- }
- } else {
- my $offset = 0;
- my $buf = '';
- while ($left > 0) {
- my $r = read($in, $buf, $left, $offset);
- defined($r) or fail($self, "read failed: $!");
- $r == 0 and fail($self, 'exited unexpectedly');
- $left -= $r;
- $offset += $r;
- }
- $rv = \$buf;
+ $$ref = $size if $ref;
+
+ my $offset = 0;
+ my $buf = '';
+ while ($left > 0) {
+ my $r = read($in, $buf, $left, $offset);
+ defined($r) or fail($self, "read failed: $!");
+ $r == 0 and fail($self, 'exited unexpectedly');
+ $left -= $r;
+ $offset += $r;
}
+ $rv = \$buf;
- my $r = read($in, my $buf, 1);
+ my $r = read($in, my $lf, 1);
defined($r) or fail($self, "read failed: $!");
- fail($self, 'newline missing after blob') if ($r != 1 || $buf ne "\n");
- die $cb_err if $cb_err;
+ fail($self, 'newline missing after blob') if ($r != 1 || $lf ne "\n");
$rv;
}
@@ -211,20 +194,14 @@ sub check {
}
sub _destroy {
- my ($self, $in, $out, $pid, $expire) = @_;
- my $rfh = $self->{$in} or return;
- if (defined $expire) {
- # at least FreeBSD 11.2 and Linux 4.20 update mtime of the
- # read end of a pipe when the pipe is written to; dunno
- # about other OSes.
- my $mtime = (stat($rfh))[9];
- return if $mtime > $expire;
- }
+ my ($self, $in, $out, $pid, $err) = @_;
my $p = delete $self->{$pid} or return;
- foreach my $f ($in, $out) {
- delete $self->{$f};
- }
- waitpid $p, 0;
+ delete @$self{($in, $out)};
+ delete $self->{$err} if $err; # `err_c'
+
+ # PublicInbox::DS may not be loaded
+ eval { PublicInbox::DS::dwaitpid($p, undef, undef) };
+ waitpid($p, 0) if $@; # wait synchronously if not in event loop
}
sub fail {
@@ -251,9 +228,9 @@ sub qx {
# returns true if there are pending "git cat-file" processes
sub cleanup {
- my ($self, $expire) = @_;
- _destroy($self, qw(in out pid), $expire);
- _destroy($self, qw(in_c out_c pid_c), $expire);
+ my ($self) = @_;
+ _destroy($self, qw(in out pid));
+ _destroy($self, qw(in_c out_c pid_c err_c));
!!($self->{pid} || $self->{pid_c});
}
@@ -328,8 +305,8 @@ sub modified ($) {
foreach my $oid (<$fh>) {
chomp $oid;
my $buf = cat_file($self, $oid) or next;
- $$buf =~ /^committer .*?> (\d+) [\+\-]?\d+/sm or next;
- my $cmt_time = $1;
+ $$buf =~ /^committer .*?> ([0-9]+) [\+\-]?[0-9]+/sm or next;
+ my $cmt_time = $1 + 0;
$modified = $cmt_time if $cmt_time > $modified;
}
$modified || time;