From 4c2c2325d2948ec5340e2fcafbee798cf568f5fd Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 22 Dec 2015 00:17:33 +0000 Subject: rename 'GitCatFile' package to 'Git' We'll be using it for more than just cat-file. Adding a `popen' API for internal use allows us to save a bunch of code in other places. --- lib/PublicInbox/ExtMsg.pm | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'lib/PublicInbox/ExtMsg.pm') diff --git a/lib/PublicInbox/ExtMsg.pm b/lib/PublicInbox/ExtMsg.pm index 82f4c63d..0b667545 100644 --- a/lib/PublicInbox/ExtMsg.pm +++ b/lib/PublicInbox/ExtMsg.pm @@ -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 -- cgit v1.2.3-24-ge0c7