Project

General

Profile

Defect #25563 » issue-25563_2.diff

Dmitry Lisichkin, 2017-05-11 21:44

View differences:

app/controllers/repositories_controller.rb
172 172
    return true if Redmine::MimeType.is_type?('text', path)
173 173
    # Ruby 1.8.6 has a bug of integer divisions.
174 174
    # http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F
175
    return false if ent.is_binary_data?
175
    return false if Redmine::Scm::Adapters::ScmData.binary?(ent)
176 176
    true
177 177
  end
178 178
  private :is_entry_text_data?
lib/redmine/core_ext/string.rb
4 4
class String #:nodoc:
5 5
  include Redmine::CoreExtensions::String::Conversions
6 6
  include Redmine::CoreExtensions::String::Inflections
7

  
8
  def is_binary_data?
9
    ( self.count( "^ -~", "^\r\n" ).fdiv(self.size) > 0.3 || self.index( "\x00" ) ) unless empty?
10
  end
11 7
end
lib/redmine/scm/adapters/abstract_adapter.rb
430 430
      class Branch < String
431 431
        attr_accessor :revision, :scmid
432 432
      end
433

  
434
      module ScmData
435
        def self.binary?(data)
436
          unless data.empty?
437
            data.count( "^ -~", "^\r\n" ).fdiv(data.size) > 0.3 || data.index( "\x00" )
438
          end
439
        end
440
      end
433 441
    end
434 442
  end
435 443
end
lib/redmine/scm/adapters/git_adapter.rb
338 338
          content = nil
339 339
          git_cmd(cmd_args) { |io| io.binmode; content = io.read }
340 340
          # git annotates binary files
341
          return nil if content.is_binary_data?
341
          return nil if ScmData.binary?(content)
342 342
          identifier = ''
343 343
          # git shows commit author on the first occurrence only
344 344
          authors_by_commit = {}
(3-3/3)