Fixed Gitalist::Utils::is_binary to work.
Dan Brook [Fri, 30 Apr 2010 21:39:31 +0000 (22:39 +0100)]
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.

lib/Gitalist/Utils.pm

index c40d825..f11dc34 100644 (file)
@@ -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;