From: Toshi MARUYAMA Date: Sat, 10 Jun 2017 04:29:15 +0000 (+0000) Subject: remove is_binary_data? from String (#25563) X-Git-Tag: 3.4.0~58 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=06babbec7e788f2f3684f257ac817b424aedbf46;p=redmine.git remove is_binary_data? from String (#25563) git-svn-id: http://svn.redmine.org/redmine/trunk@16644 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index cbe38210e..2a7642772 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -172,7 +172,7 @@ class RepositoriesController < ApplicationController return true if Redmine::MimeType.is_type?('text', path) # Ruby 1.8.6 has a bug of integer divisions. # http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F - return false if ent.is_binary_data? + return false if Redmine::Scm::Adapters::ScmData.binary?(ent) true end private :is_entry_text_data? diff --git a/lib/redmine/core_ext/string.rb b/lib/redmine/core_ext/string.rb index c865284ac..2da5ffef9 100644 --- a/lib/redmine/core_ext/string.rb +++ b/lib/redmine/core_ext/string.rb @@ -4,8 +4,4 @@ require File.dirname(__FILE__) + '/string/inflections' class String #:nodoc: include Redmine::CoreExtensions::String::Conversions include Redmine::CoreExtensions::String::Inflections - - def is_binary_data? - ( self.count( "^ -~", "^\r\n" ).fdiv(self.size) > 0.3 || self.index( "\x00" ) ) unless empty? - end end diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb index 9ed8b25db..68fea1da4 100644 --- a/lib/redmine/scm/adapters/abstract_adapter.rb +++ b/lib/redmine/scm/adapters/abstract_adapter.rb @@ -430,6 +430,14 @@ module Redmine class Branch < String attr_accessor :revision, :scmid end + + module ScmData + def self.binary?(data) + unless data.empty? + data.count( "^ -~", "^\r\n" ).fdiv(data.size) > 0.3 || data.index( "\x00" ) + end + end + end end end end diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb index 1dd317d72..8d9821eed 100644 --- a/lib/redmine/scm/adapters/git_adapter.rb +++ b/lib/redmine/scm/adapters/git_adapter.rb @@ -338,7 +338,7 @@ module Redmine content = nil git_cmd(cmd_args) { |io| io.binmode; content = io.read } # git annotates binary files - return nil if content.is_binary_data? + return nil if ScmData.binary?(content) identifier = '' # git shows commit author on the first occurrence only authors_by_commit = {}