Class: Gitlab::Git::DiffCollection
- Inherits:
-
Object
- Object
- Gitlab::Git::DiffCollection
- Includes:
- Enumerable
- Defined in:
- lib/gitlab/git/diff_collection.rb
Instance Attribute Summary collapse
-
#limits ⇒ Object
readonly
Returns the value of attribute limits.
Class Method Summary collapse
- .collect_all_paths?(collect_all_paths) ⇒ Boolean
- .default_limits ⇒ Object
- .limits(options = {}) ⇒ Object
Instance Method Summary collapse
- #collapsed_safe_bytes? ⇒ Boolean
- #collapsed_safe_files? ⇒ Boolean
- #collapsed_safe_lines? ⇒ Boolean
- #decorate! ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(iterator, options = {}) ⇒ DiffCollection
constructor
A new instance of DiffCollection.
- #line_count ⇒ Object
- #overflow? ⇒ Boolean
- #overflow_max_bytes? ⇒ Boolean
- #overflow_max_files? ⇒ Boolean
- #overflow_max_lines? ⇒ Boolean
- #real_size ⇒ Object
- #size ⇒ Object
- #sort(&block) ⇒ Object
Constructor Details
#initialize(iterator, options = {}) ⇒ DiffCollection
Returns a new instance of DiffCollection.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/gitlab/git/diff_collection.rb', line 36 def initialize(iterator, = {}) @iterator = iterator @limits = self.class.limits() @enforce_limits = !!.fetch(:limits, true) @expanded = !!.fetch(:expanded, true) @offset_index = .fetch(:offset_index, 0) @line_count = 0 @byte_count = 0 @overflow = false @empty = true @array = [] end |
Instance Attribute Details
#limits ⇒ Object (readonly)
Returns the value of attribute limits.
10 11 12 |
# File 'lib/gitlab/git/diff_collection.rb', line 10 def limits @limits end |
Class Method Details
.collect_all_paths?(collect_all_paths) ⇒ Boolean
16 17 18 |
# File 'lib/gitlab/git/diff_collection.rb', line 16 def self.collect_all_paths?(collect_all_paths) Gitlab::Git::Diff.collect_patch_overage? ? collect_all_paths : false end |
.default_limits ⇒ Object
12 13 14 |
# File 'lib/gitlab/git/diff_collection.rb', line 12 def self.default_limits { max_files: ::Commit.diff_safe_max_files, max_lines: ::Commit.diff_safe_max_lines } end |
.limits(options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gitlab/git/diff_collection.rb', line 20 def self.limits( = {}) limits = {} defaults = default_limits limits[:max_files] = .fetch(:max_files, defaults[:max_files]) limits[:max_lines] = .fetch(:max_lines, defaults[:max_lines]) limits[:max_bytes] = limits[:max_files] * 5.kilobytes # Average 5 KB per file limits[:safe_max_files] = [limits[:max_files], defaults[:max_files]].min limits[:safe_max_lines] = [limits[:max_lines], defaults[:max_lines]].min limits[:safe_max_bytes] = limits[:safe_max_files] * 5.kilobytes # Average 5 KB per file limits[:max_patch_bytes] = Gitlab::Git::Diff.patch_hard_limit_bytes limits[:max_patch_bytes_for_file_extension] = .fetch(:max_patch_bytes_for_file_extension, {}) limits[:collect_all_paths] = collect_all_paths?(.fetch(:collect_all_paths, false)) limits end |
Instance Method Details
#collapsed_safe_bytes? ⇒ Boolean
104 105 106 |
# File 'lib/gitlab/git/diff_collection.rb', line 104 def collapsed_safe_bytes? !!@collapsed_safe_bytes end |
#collapsed_safe_files? ⇒ Boolean
100 101 102 |
# File 'lib/gitlab/git/diff_collection.rb', line 100 def collapsed_safe_files? !!@collapsed_safe_files end |
#collapsed_safe_lines? ⇒ Boolean
96 97 98 |
# File 'lib/gitlab/git/diff_collection.rb', line 96 def collapsed_safe_lines? !!@collapsed_safe_lines end |
#decorate! ⇒ Object
128 129 130 131 132 |
# File 'lib/gitlab/git/diff_collection.rb', line 128 def decorate! each_with_index do |element, i| @array[i] = yield(element) end end |
#each(&block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gitlab/git/diff_collection.rb', line 50 def each(&block) @array.each(&block) return if @overflow return if @iterator.nil? if @iterator.is_a?(Gitlab::GitalyClient::DiffStitcher) each_gitaly_patch(&block) else each_serialized_patch(&block) end @populated = true # Allow iterator to be garbage-collected. It cannot be reused anyway. @iterator = nil end |
#empty? ⇒ Boolean
74 75 76 77 |
# File 'lib/gitlab/git/diff_collection.rb', line 74 def empty? any? # Make sure the iterator has been exercised @empty end |
#line_count ⇒ Object
122 123 124 125 126 |
# File 'lib/gitlab/git/diff_collection.rb', line 122 def line_count populate! @line_count end |
#overflow? ⇒ Boolean
79 80 81 82 |
# File 'lib/gitlab/git/diff_collection.rb', line 79 def overflow? populate! !!@overflow end |
#overflow_max_bytes? ⇒ Boolean
88 89 90 |
# File 'lib/gitlab/git/diff_collection.rb', line 88 def overflow_max_bytes? !!@overflow_max_bytes end |
#overflow_max_files? ⇒ Boolean
92 93 94 |
# File 'lib/gitlab/git/diff_collection.rb', line 92 def overflow_max_files? !!@overflow_max_files end |
#overflow_max_lines? ⇒ Boolean
84 85 86 |
# File 'lib/gitlab/git/diff_collection.rb', line 84 def overflow_max_lines? !!@overflow_max_lines end |
#real_size ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/gitlab/git/diff_collection.rb', line 112 def real_size populate! if @overflow "#{size}+" else size.to_s end end |
#size ⇒ Object
108 109 110 |
# File 'lib/gitlab/git/diff_collection.rb', line 108 def size @size ||= count # forces a loop using each method end |
#sort(&block) ⇒ Object
68 69 70 71 72 |
# File 'lib/gitlab/git/diff_collection.rb', line 68 def sort(&block) @array = @array.sort(&block) self end |