]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/ExtMsg.pm
rename 'GitCatFile' package to 'Git'
[public-inbox.git] / lib / PublicInbox / ExtMsg.pm
index 82f4c63dc5ddd8b19820b58bda131f87a535d68d..0b667545a6e06e29744e6efec151d783510405be 100644 (file)
@@ -72,21 +72,10 @@ sub ext_msg {
        my $path = "HEAD:" . mid2path($mid);
 
        foreach my $n (@nox) {
-               my @cmd = ('git', "--git-dir=$n->{git_dir}", 'cat-file',
-                          '-t', $path);
-               my $pid = open my $fh, '-|';
-               defined $pid or die "fork failed: $!\n";
-
-               if ($pid == 0) {
-                       open STDERR, '>', '/dev/null'; # ignore errors
-                       exec @cmd or die "exec failed: $!\n";
-               } else {
-                       my $type = eval { local $/; <$fh> };
-                       close $fh;
-                       if ($? == 0 && $type eq "blob\n") {
-                               return r302($n->{url}, $mid);
-                       }
-               }
+               # TODO: reuse existing PublicInbox::Git objects to save forks
+               my $git = PublicInbox::Git->new($n->{git_dir});
+               my (undef, $type, undef) = $git->check($path);
+               return r302($n->{url}, $mid) if ($type eq 'blob');
        }
 
        # fall back to partial MID matching