]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/ViewVCS.pm
viewvcs: flesh out some functionality and test
[public-inbox.git] / lib / PublicInbox / ViewVCS.pm
index 962dc66baccd708ca34666939a6ad306c5ad78a4..842c873cc2e3f7ee3d20589d54ba0938eae44a5c 100644 (file)
@@ -20,6 +20,7 @@ use bytes (); # only for bytes::length
 use PublicInbox::SolverGit;
 use PublicInbox::WwwStream;
 use PublicInbox::Linkify;
+use PublicInbox::Tmpfile;
 use PublicInbox::Hval qw(ascii_html to_filename);
 my $hl = eval {
        require PublicInbox::HlMod;
@@ -27,7 +28,7 @@ my $hl = eval {
 };
 
 my %QP_MAP = ( A => 'oid_a', B => 'oid_b', a => 'path_a', b => 'path_b' );
-my $max_size = 1024 * 1024; # TODO: configurable
+our $MAX_SIZE = 1024 * 1024; # TODO: configurable
 my $BIN_DETECT = 8000; # same as git
 
 sub html_page ($$$) {
@@ -48,6 +49,7 @@ sub stream_large_blob ($$$$) {
        my $qsp = PublicInbox::Qspawn->new($cmd);
        my @cl = ('Content-Length', $size);
        my $env = $ctx->{env};
+       $env->{'public-inbox.tmpgit'} = $git; # for {-tmp}/File::Temp::Dir
        $env->{'qspawn.wcb'} = delete $ctx->{-wcb};
        $qsp->psgi_return($env, undef, sub {
                my ($r, $bref) = @_;
@@ -74,7 +76,7 @@ sub stream_large_blob ($$$$) {
 sub show_other ($$$$) {
        my ($ctx, $res, $logref, $fn) = @_;
        my ($git, $oid, $type, $size) = @$res;
-       if ($size > $max_size) {
+       if ($size > $MAX_SIZE) {
                $$logref = "$oid is too big to show\n" . $$logref;
                return html_page($ctx, 200, $logref);
        }
@@ -120,11 +122,11 @@ sub solve_result {
        return show_other($ctx, $res, \$log, $fn) if $type ne 'blob';
        my $path = to_filename($di->{path_b} || $hints->{path_b} || 'blob');
        my $raw_link = "(<a\nhref=$path>raw</a>)";
-       if ($size > $max_size) {
+       if ($size > $MAX_SIZE) {
                return stream_large_blob($ctx, $res, \$log, $fn) if defined $fn;
                $log = "<pre><b>Too big to show, download available</b>\n" .
                        "$oid $type $size bytes $raw_link</pre>" . $log;
-               return html_page($ctx, 500, \$log);
+               return html_page($ctx, 200, \$log);
        }
 
        my $blob = $git->cat_file($oid);
@@ -184,7 +186,7 @@ sub show ($$;$) {
                $hints->{$to} = $v;
        }
 
-       open my $log, '+>', undef or die "open: $!";
+       my $log = tmpfile("solve.$oid_b");
        my $solver = PublicInbox::SolverGit->new($ctx->{-inbox}, sub {
                solve_result($ctx, $_[0], $log, $hints, $fn);
        });