Skip to content
Snippets Groups Projects
Commit 6a4a17f3 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

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

parent 5f8f685b
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
 
Loading
Loading
@@ -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?
Loading
Loading
@@ -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
Loading
Loading
@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment