]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Git.pm
git: remove src_blob_url
[public-inbox.git] / lib / PublicInbox / Git.pm
index f5c7a95c34d7aedad7860a1189f8e121167eb1fb..218846f3d1d25d42699a4a4be55351394c6a5341 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 {
@@ -256,17 +261,6 @@ sub local_nick ($) {
        wantarray ? ($ret) : $ret;
 }
 
-# show the blob URL for cgit/gitweb/whatever
-sub src_blob_url {
-       my ($self, $oid) = @_;
-       # blob_url_format = "https://example.com/foo.git/blob/%s"
-       if (my $bfu = $self->{blob_url_format}) {
-               return map { sprintf($_, $oid) } @$bfu if wantarray;
-               return sprintf($bfu->[0], $oid);
-       }
-       local_nick($self);
-}
-
 sub host_prefix_url ($$) {
        my ($env, $url) = @_;
        return $url if index($url, '//') >= 0;