]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Git.pm
doc: avoid [<directory>] arg for git-clone(1)
[public-inbox.git] / lib / PublicInbox / Git.pm
index 6a87661c290faaa4ea0275f70a1fe23bf15898ba..ff3838b3ff8b7fc5d9baeda7c3cb5bb03a4d79b8 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2014-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2014-2019 all contributors <meta@public-inbox.org>
 # License: GPLv2 or later <https://www.gnu.org/licenses/gpl-2.0.txt>
 #
 # Used to read files from a git repository without excessive forking.
@@ -12,6 +12,7 @@ use warnings;
 use POSIX qw(dup2);
 require IO::Handle;
 use PublicInbox::Spawn qw(spawn popen_rd);
+use PublicInbox::Tmpfile;
 use base qw(Exporter);
 our @EXPORT_OK = qw(git_unquote git_quote);
 
@@ -110,7 +111,8 @@ sub _bidi_pipe {
                        qw(-c core.abbrev=40 cat-file), $batch);
        my $redir = { 0 => fileno($out_r), 1 => fileno($in_w) };
        if ($err) {
-               open(my $fh, '+>', undef) or fail($self, "open.err failed: $!");
+               my $id = "git.$self->{git_dir}$batch.err";
+               my $fh = tmpfile($id) or fail($self, "tmpfile($id): $!");
                $self->{$err} = $fh;
                $redir->{2} = fileno($fh);
        }
@@ -198,7 +200,10 @@ sub _destroy {
        my $p = delete $self->{$pid} or return;
        delete @$self{($in, $out)};
        delete $self->{$err} if $err; # `err_c'
-       waitpid $p, 0;
+
+       # 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 {
@@ -303,7 +308,7 @@ sub modified ($) {
                chomp $oid;
                my $buf = cat_file($self, $oid) or next;
                $$buf =~ /^committer .*?> ([0-9]+) [\+\-]?[0-9]+/sm or next;
-               my $cmt_time = $1;
+               my $cmt_time = $1 + 0;
                $modified = $cmt_time if $cmt_time > $modified;
        }
        $modified || time;