about summary refs log tree commit homepage
path: root/lib/PublicInbox/ExtMsg.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-12-22 00:17:33 +0000
committerEric Wong <e@80x24.org>2015-12-22 00:58:13 +0000
commit4c2c2325d2948ec5340e2fcafbee798cf568f5fd (patch)
tree85dd6e48f4b7c658cb3eee12032143839000f218 /lib/PublicInbox/ExtMsg.pm
parentb140961420c0f240c9c3f55e83c52cfc3efa709d (diff)
downloadpublic-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.pm19
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