lib/gitlab_git/diff.rb in gitlab_git-10.6.8 vs lib/gitlab_git/diff.rb in gitlab_git-10.7.0
- old
+ new
@@ -259,22 +259,12 @@
end
def init_from_rugged_patch(patch, collapse: false)
# Don't bother initializing diffs that are too large. If a diff is
# binary we're not going to display anything so we skip the size check.
- unless patch.delta.binary?
- diff_size = patch_size(patch)
+ return if !patch.delta.binary? && prune_large_patch(patch, collapse)
- if diff_size >= DIFF_SIZE_LIMIT
- prune_large_diff!
- return
- elsif collapse && diff_size >= DIFF_COLLAPSE_LIMIT
- prune_collapsed_diff!
- return
- end
- end
-
@diff = encode!(strip_diff_headers(patch.to_s))
end
def init_from_hash(hash, collapse: false)
raw_diff = hash.symbolize_keys
@@ -285,20 +275,31 @@
prune_large_diff! if too_large?
prune_collapsed_diff! if collapse && collapsible?
end
- # Returns the size of a diff without taking any diff markers into account.
- def patch_size(patch)
+ # If the patch surpasses any of the diff limits it calls the appropiate
+ # prune method and returns true. Otherwise returns false.
+ def prune_large_patch(patch, collapse)
size = 0
patch.each_hunk do |hunk|
hunk.each_line do |line|
size += line.content.bytesize
+
+ if size >= DIFF_SIZE_LIMIT
+ prune_large_diff!
+ return true
+ end
end
end
- size
+ if collapse && size >= DIFF_COLLAPSE_LIMIT
+ prune_collapsed_diff!
+ return true
+ end
+
+ false
end
# Strip out the information at the beginning of the patch's text to match
# Grit's output
def strip_diff_headers(diff_text)