diff options
author | Eric Wong <e@80x24.org> | 2015-12-22 00:17:33 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-12-22 00:58:13 +0000 |
commit | 4c2c2325d2948ec5340e2fcafbee798cf568f5fd (patch) | |
tree | 85dd6e48f4b7c658cb3eee12032143839000f218 /lib/PublicInbox/ExtMsg.pm | |
parent | b140961420c0f240c9c3f55e83c52cfc3efa709d (diff) | |
download | public-inbox-4c2c2325d2948ec5340e2fcafbee798cf568f5fd.tar.gz |
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.
Diffstat (limited to 'lib/PublicInbox/ExtMsg.pm')
-rw-r--r-- | lib/PublicInbox/ExtMsg.pm | 19 |
1 files changed, 4 insertions, 15 deletions
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 |