]> Sergey Matveev's repositories - public-inbox.git/commitdiff
cgi: mid2blob does not depend on $ENV{GIT_DIR}
authorEric Wong <e@80x24.org>
Tue, 29 Apr 2014 05:33:45 +0000 (05:33 +0000)
committerEric Wong <e@80x24.org>
Tue, 29 Apr 2014 05:33:45 +0000 (05:33 +0000)
ENV changes do not propagate to child processes under mod_perl

public-inbox.cgi

index ffd6ec08f4a898f9712469ad45391cc98fe3c379..6f20e1450b7393df1110259d82b3f5884d94638a 100755 (executable)
@@ -142,12 +142,16 @@ sub get_index {
 # just returns a string ref for the blob in the current ctx
 sub mid2blob {
        my ($ctx) = @_;
-       local $ENV{GIT_DIR} = $ctx->{git_dir};
        require Digest::SHA;
        my $hex = Digest::SHA::sha1_hex($ctx->{mid});
        $hex =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/i or
                        die "BUG: not a SHA-1 hex: $hex";
-       my $blob = `git cat-file blob HEAD:$1/$2 2>/dev/null`;
+       require IPC::Run;
+       my ($in, $blob, $err);
+       open my $null, '+<', '/dev/null' or die "open: $!\n";
+       IPC::Run::run(['git', '--git-dir', $ctx->{git_dir},
+                       qw(cat-file blob), "HEAD:$1/$2"],
+                       $null, \$blob, $null);
        $? == 0 ? \$blob : undef;
 }