debian-mirror-gitlab/lib/gitlab/diff/file_collection/base.rb

45 lines
1.3 KiB
Ruby
Raw Normal View History

2016-09-13 17:45:13 +05:30
module Gitlab
module Diff
module FileCollection
class Base
2017-09-10 17:25:29 +05:30
attr_reader :project, :diff_options, :diff_refs, :fallback_diff_refs
2016-09-13 17:45:13 +05:30
delegate :count, :size, :real_size, to: :diff_files
def self.default_options
2017-09-10 17:25:29 +05:30
::Commit.max_diff_options.merge(ignore_whitespace_change: false, expanded: false)
2016-09-13 17:45:13 +05:30
end
2017-09-10 17:25:29 +05:30
def initialize(diffable, project:, diff_options: nil, diff_refs: nil, fallback_diff_refs: nil)
2016-09-13 17:45:13 +05:30
diff_options = self.class.default_options.merge(diff_options || {})
2017-09-10 17:25:29 +05:30
@diffable = diffable
@diffs = diffable.raw_diffs(diff_options)
@project = project
2016-09-13 17:45:13 +05:30
@diff_options = diff_options
2017-09-10 17:25:29 +05:30
@diff_refs = diff_refs
@fallback_diff_refs = fallback_diff_refs
2016-09-13 17:45:13 +05:30
end
def diff_files
@diff_files ||= @diffs.decorate! { |diff| decorate_diff!(diff) }
end
2017-09-10 17:25:29 +05:30
def diff_file_with_old_path(old_path)
diff_files.find { |diff_file| diff_file.old_path == old_path }
end
def diff_file_with_new_path(new_path)
diff_files.find { |diff_file| diff_file.new_path == new_path }
end
2016-09-13 17:45:13 +05:30
private
def decorate_diff!(diff)
2017-09-10 17:25:29 +05:30
Gitlab::Diff::File.new(diff, repository: project.repository, diff_refs: diff_refs, fallback_diff_refs: fallback_diff_refs)
2016-09-13 17:45:13 +05:30
end
end
end
end
end