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")
class MergeRequest < ActiveRecord::Base
include Issuable
BROKEN_DIFF = "--broken-diff"
attr_accessible :title, :assignee_id, :target_branch, :source_branch, :milestone_id,
:author_id_of_changes, :state_event
......@@ -109,22 +107,18 @@ class MergeRequest < ActiveRecord::Base
end
def diffs
st_diffs || []
load_diffs(st_diffs) || []
end
def reloaded_diffs
if opened? && unmerged_diffs.any?
self.st_diffs = unmerged_diffs
self.st_diffs = dump_diffs(unmerged_diffs)
self.save
end
rescue Grit::Git::GitTimeout
self.st_diffs = [BROKEN_DIFF]
self.save
end
def broken_diffs?
diffs == [BROKEN_DIFF]
diffs == [Gitlab::Git::Diff::BROKEN_DIFF]
end
def valid_diffs?
......@@ -132,11 +126,7 @@ class MergeRequest < ActiveRecord::Base
end
def unmerged_diffs
# Only show what is new in the source branch compared to the target branch, not the other way around.
# 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)
project.repository.diffs_between(source_branch, target_branch)
end
def last_commit
......@@ -222,4 +212,12 @@ class MergeRequest < ActiveRecord::Base
def load_commits(array)
array.map { |hash| Commit.new(Gitlab::Git::Commit.new(hash)) }
end
def dump_diffs(diffs)
diffs.map(&:to_hash)
end
def load_diffs(array)
array.map { |hash| Gitlab::Git::Diff.new(hash) }
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