]> source.dussan.org Git - redmine.git/commitdiff
remove is_binary_data? from String (#25563)
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Sat, 10 Jun 2017 04:29:15 +0000 (04:29 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Sat, 10 Jun 2017 04:29:15 +0000 (04:29 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16644 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/repositories_controller.rb
lib/redmine/core_ext/string.rb
lib/redmine/scm/adapters/abstract_adapter.rb
lib/redmine/scm/adapters/git_adapter.rb

index cbe38210ed629afb68296aee79870dff0284894c..2a7642772423e7ec4043592a9440b6926a80af20 100644 (file)
@@ -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?
index c865284ac60466232cf0564dd6b5361f8ded4466..2da5ffef99a08f2d8a46c6acb5d81a6b9af5f442 100644 (file)
@@ -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
index 9ed8b25db0f4a4c6fa923ff5dc96dc8c1ef53b87..68fea1da434cf2654e78562252fa1a6c4e20f389 100644 (file)
@@ -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
index 1dd317d72e03771a0280d65ee8ad72a39d9a58cf..8d9821eedce9e094e6ba2c9c4be28a87228ada97 100644 (file)
@@ -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 = {}