]> Sergey Matveev's repositories - public-inbox.git/commitdiff
viewvcs: match 8000-byte lookup for git
authorEric Wong <e@80x24.org>
Sun, 24 Feb 2019 02:55:40 +0000 (02:55 +0000)
committerEric Wong <e@80x24.org>
Thu, 4 Apr 2019 09:13:58 +0000 (09:13 +0000)
No need to scan the entire string, but prefer to match git
behavior.  This might be faster if/when Perl can create
substrings efficiently using CoW.

Fix a 80-column violation while we're at it.

lib/PublicInbox/ViewVCS.pm

index b41adc44b4418abedca31e93d1cfa9b2e6b73ef5..962dc66baccd708ca34666939a6ad306c5ad78a4 100644 (file)
@@ -135,14 +135,14 @@ sub solve_result {
                return html_page($ctx, 500, \$log);
        }
 
-       my $binary = index($$blob, "\0") >= 0;
+       my $bin = index(substr($$blob, 0, $BIN_DETECT), "\0") >= 0;
        if (defined $fn) {
                my $h = [ 'Content-Length', $size, 'Content-Type' ];
-               push(@$h, ($binary ? 'application/octet-stream' : 'text/plain'));
+               push(@$h, ($bin ? 'application/octet-stream' : 'text/plain'));
                return delete($ctx->{-wcb})->([200, $h, [ $$blob ]]);
        }
 
-       if ($binary) {
+       if ($bin) {
                $log = "<pre>$oid $type $size bytes (binary)" .
                        " $raw_link</pre>" . $log;
                return html_page($ctx, 200, \$log);