Class: Gitlab::Diff::FileCollection::Base
- Inherits:
-
Object
- Object
- Gitlab::Diff::FileCollection::Base
show all
- Includes:
- Utils::StrongMemoize
- Defined in:
- lib/gitlab/diff/file_collection/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(diffable, project:, diff_options: nil, diff_refs: nil, fallback_diff_refs: nil) ⇒ Base
Returns a new instance of Base.
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 17
def initialize(diffable, project:, diff_options: nil, diff_refs: nil, fallback_diff_refs: nil)
diff_options = self.class.default_options.merge(diff_options || {})
@diffable = diffable
@include_stats = diff_options.delete(:include_stats)
@pagination_data = diff_options.delete(:pagination_data)
@project = project
@diff_options = diff_options
@diff_refs = diff_refs
@fallback_diff_refs = fallback_diff_refs
@repository = project.repository
@use_extra_viewer_as_main = diff_options.delete(:use_extra_viewer_as_main)
end
|
Instance Attribute Details
#diff_options ⇒ Object
Returns the value of attribute diff_options.
9
10
11
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 9
def diff_options
@diff_options
end
|
#diff_refs ⇒ Object
Returns the value of attribute diff_refs.
9
10
11
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 9
def diff_refs
@diff_refs
end
|
#diffable ⇒ Object
Returns the value of attribute diffable.
9
10
11
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 9
def diffable
@diffable
end
|
#fallback_diff_refs ⇒ Object
Returns the value of attribute fallback_diff_refs.
9
10
11
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 9
def fallback_diff_refs
@fallback_diff_refs
end
|
#project ⇒ Object
Returns the value of attribute project.
9
10
11
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 9
def project
@project
end
|
Class Method Details
.default_options ⇒ Object
13
14
15
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 13
def self.default_options
::Commit.max_diff_options.merge(ignore_whitespace_change: false, expanded: false, include_stats: true, use_extra_viewer_as_main: false)
end
|
Instance Method Details
#clear_cache ⇒ Object
81
82
83
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 81
def clear_cache
end
|
#diff_file_paths ⇒ Object
This is either the new path, otherwise the old path for the diff_file
48
49
50
51
52
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 48
def diff_file_paths
diffs.map do |diff|
diff.new_path.presence || diff.old_path
end
end
|
#diff_file_with_new_path(new_path) ⇒ Object
77
78
79
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 77
def diff_file_with_new_path(new_path)
diff_files.find { |diff_file| diff_file.new_path == new_path }
end
|
#diff_file_with_old_path(old_path) ⇒ Object
73
74
75
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 73
def diff_file_with_old_path(old_path)
diff_files.find { |diff_file| diff_file.old_path == old_path }
end
|
#diff_files(sorted: false) ⇒ Object
35
36
37
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 35
def diff_files(sorted: false)
raw_diff_files(sorted: sorted)
end
|
#diff_paths ⇒ Object
This is both the new and old paths for the diff_file
55
56
57
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 55
def diff_paths
diff_files.map(&:paths).flatten.uniq
end
|
#diffs ⇒ Object
31
32
33
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 31
def diffs
@diffs ||= diffable.raw_diffs(diff_options)
end
|
#overflow? ⇒ Boolean
89
90
91
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 89
def overflow?
raw_diff_files.overflow?
end
|
59
60
61
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 59
def
@pagination_data ||
end
|
#raw_diff_files(sorted: false) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 39
def raw_diff_files(sorted: false)
strong_memoize(:"raw_diff_files_#{sorted}") do
collection = diffs.decorate! { |diff| decorate_diff!(diff) }
collection = sort_diffs(collection) if sorted
collection
end
end
|
#unfold_diff_files(positions) ⇒ Object
This mutates ‘diff_files` lines.
64
65
66
67
68
69
70
71
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 64
def unfold_diff_files(positions)
positions_grouped_by_path = positions.group_by { |position| position.file_path }
diff_files.each do |diff_file|
positions = positions_grouped_by_path.fetch(diff_file.file_path, [])
positions.each { |position| diff_file.unfold_diff_lines(position) }
end
end
|
#write_cache ⇒ Object
85
86
87
|
# File 'lib/gitlab/diff/file_collection/base.rb', line 85
def write_cache
end
|