diff options
Diffstat (limited to 'lib/gitlab/git/diff.rb')
-rw-r--r-- | lib/gitlab/git/diff.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/gitlab/git/diff.rb b/lib/gitlab/git/diff.rb index 2a017c93f57..276e8e595a0 100644 --- a/lib/gitlab/git/diff.rb +++ b/lib/gitlab/git/diff.rb @@ -19,6 +19,9 @@ module Gitlab # The maximum size before a diff is collapsed. DIFF_COLLAPSE_LIMIT = 10240 # 10 KB + # Blank SHA + BLANK_SHA = ("0" * 40).freeze + class << self def between(repo, head, base, options = {}, *paths) straight = options.delete(:straight) || false @@ -179,6 +182,8 @@ module Gitlab init_from_hash(raw_diff, collapse: collapse) when Rugged::Patch, Rugged::Diff::Delta init_from_rugged(raw_diff, collapse: collapse) + when Gitaly::CommitDiffResponse + init_from_gitaly(raw_diff, collapse: collapse) when nil raise "Nil as raw diff passed" else @@ -277,6 +282,20 @@ module Gitlab prune_collapsed_diff! if collapse && collapsible? end + def init_from_gitaly(diff_msg, collapse: false) + @diff = diff_msg.raw_chunks.join + @new_path = encode!(diff_msg.to_path.dup) + @old_path = encode!(diff_msg.from_path.dup) + @a_mode = diff_msg.old_mode.to_s(8) + @b_mode = diff_msg.new_mode.to_s(8) + @new_file = diff_msg.from_id == BLANK_SHA + @renamed_file = diff_msg.from_path != diff_msg.to_path + @deleted_file = diff_msg.to_id == BLANK_SHA + + prune_large_diff! if too_large? + prune_collapsed_diff! if collapse && collapsible? + end + # 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) |