From: Dan Brook Date: Fri, 30 Apr 2010 21:39:31 +0000 (+0100) Subject: Fixed Gitalist::Utils::is_binary to work. X-Git-Tag: 0.002001_01~17 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b30f0e2ecd3986b563b3529c1143f1d5f631a3ff;p=catagits%2FGitalist.git Fixed Gitalist::Utils::is_binary to work. For some reason calling -B with an in-memory filehandle doesn't work. In lieu of that functionality I used a shoddy heuristic to look for a line or two of printable characters. --- diff --git a/lib/Gitalist/Utils.pm b/lib/Gitalist/Utils.pm index c40d825..f11dc34 100644 --- a/lib/Gitalist/Utils.pm +++ b/lib/Gitalist/Utils.pm @@ -46,9 +46,8 @@ sub age_string { } sub is_binary { - my($str) = @_; - open my $fh, '<', \$str or return; - return -B $fh; + # Crappy heuristic - does the first line or so look printable? + return $_[0] !~ /^[[:print:]]+$ (?: \s ^[[:print:]]+$ )?/mx; } 1;