Project

General

Profile

Defect #25563 » issue-25563_2.diff

Dmitry Lisichkin, 2017-05-11 21:44

View differences:

app/controllers/repositories_controller.rb
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?
lib/redmine/core_ext/string.rb
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
lib/redmine/scm/adapters/abstract_adapter.rb
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
lib/redmine/scm/adapters/git_adapter.rb
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 = {}
(3-3/3)