2018-09-13 21:11:35 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Git
|
|
|
|
class DiffStatsCollection
|
2018-09-19 08:26:28 -04:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
2018-09-13 21:11:35 -04:00
|
|
|
include Enumerable
|
|
|
|
|
|
|
|
def initialize(diff_stats)
|
|
|
|
@collection = diff_stats
|
|
|
|
end
|
|
|
|
|
|
|
|
def each(&block)
|
|
|
|
@collection.each(&block)
|
|
|
|
end
|
2018-09-19 08:26:28 -04:00
|
|
|
|
|
|
|
def find_by_path(path)
|
|
|
|
indexed_by_path[path]
|
|
|
|
end
|
|
|
|
|
2018-09-28 09:13:04 -04:00
|
|
|
def paths
|
|
|
|
@collection.map(&:path)
|
|
|
|
end
|
|
|
|
|
2021-11-23 13:12:49 -05:00
|
|
|
def real_size
|
|
|
|
max_files = ::Commit.diff_max_files
|
2020-04-09 11:09:29 -04:00
|
|
|
if paths.size > max_files
|
|
|
|
"#{max_files}+"
|
|
|
|
else
|
|
|
|
paths.size.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-19 08:26:28 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def indexed_by_path
|
|
|
|
strong_memoize(:indexed_by_path) do
|
|
|
|
index_by { |stats| stats.path }
|
|
|
|
end
|
|
|
|
end
|
2018-09-13 21:11:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|