Commit 6a4a17f3 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Remove native git calls from MR. Dump diff as array, not class

parent 5f8f685b
...@@ -24,8 +24,6 @@ require Rails.root.join("lib/static_model") ...@@ -24,8 +24,6 @@ require Rails.root.join("lib/static_model")
class MergeRequest < ActiveRecord::Base class MergeRequest < ActiveRecord::Base
include Issuable include Issuable
BROKEN_DIFF = "--broken-diff"
attr_accessible :title, :assignee_id, :target_branch, :source_branch, :milestone_id, attr_accessible :title, :assignee_id, :target_branch, :source_branch, :milestone_id,
:author_id_of_changes, :state_event :author_id_of_changes, :state_event
...@@ -109,22 +107,18 @@ class MergeRequest < ActiveRecord::Base ...@@ -109,22 +107,18 @@ class MergeRequest < ActiveRecord::Base
end end
def diffs def diffs
st_diffs || [] load_diffs(st_diffs) || []
end end
def reloaded_diffs def reloaded_diffs
if opened? && unmerged_diffs.any? if opened? && unmerged_diffs.any?
self.st_diffs = unmerged_diffs self.st_diffs = dump_diffs(unmerged_diffs)
self.save self.save
end end
rescue Grit::Git::GitTimeout
self.st_diffs = [BROKEN_DIFF]
self.save
end end
def broken_diffs? def broken_diffs?
diffs == [BROKEN_DIFF] diffs == [Gitlab::Git::Diff::BROKEN_DIFF]
end end
def valid_diffs? def valid_diffs?
...@@ -132,11 +126,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -132,11 +126,7 @@ class MergeRequest < ActiveRecord::Base
end end
def unmerged_diffs def unmerged_diffs
# Only show what is new in the source branch compared to the target branch, not the other way around. project.repository.diffs_between(source_branch, target_branch)
# The linex below with merge_base is equivalent to diff with three dots (git diff branch1...branch2)
# From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B"
common_commit = project.repo.git.native(:merge_base, {}, [target_branch, source_branch]).strip
diffs = project.repo.diff(common_commit, source_branch)
end end
def last_commit def last_commit
...@@ -222,4 +212,12 @@ class MergeRequest < ActiveRecord::Base ...@@ -222,4 +212,12 @@ class MergeRequest < ActiveRecord::Base
def load_commits(array) def load_commits(array)
array.map { |hash| Commit.new(Gitlab::Git::Commit.new(hash)) } array.map { |hash| Commit.new(Gitlab::Git::Commit.new(hash)) }
end end
def dump_diffs(diffs)
diffs.map(&:to_hash)
end
def load_diffs(array)
array.map { |hash| Gitlab::Git::Diff.new(hash) }
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment