lib/gitlab_git/diff.rb in gitlab_git-9.0.3 vs lib/gitlab_git/diff.rb in gitlab_git-10.0.0

- old
+ new

@@ -9,10 +9,12 @@ attr_accessor :old_path, :new_path, :a_mode, :b_mode, :diff # Stats properties attr_accessor :new_file, :renamed_file, :deleted_file + attr_accessor :too_large + class << self def between(repo, head, base, options = {}, *paths) # Only show what is new in the source branch compared to the target branch, not the other way around. # The linex below with merge_base is equivalent to diff with three dots (git diff branch1...branch2) # From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B" @@ -167,11 +169,11 @@ raise "Invalid raw diff type: #{raw_diff.class}" end end def serialize_keys - @serialize_keys ||= %i(diff new_path old_path a_mode b_mode new_file renamed_file deleted_file) + @serialize_keys ||= %i(diff new_path old_path a_mode b_mode new_file renamed_file deleted_file too_large) end def to_hash hash = {} @@ -188,9 +190,23 @@ a_mode == '160000' || b_mode == '160000' end def line_count @line_count ||= Util.count_lines(@diff) + end + + def too_large? + if @too_large.nil? + @too_large = @diff.bytesize >= 102400 # 100 KB + else + @too_large + end + end + + def prune_large_diff! + @diff = '' + @line_count = 0 + @too_large = true end private def init_from_rugged(rugged)