From 6a4a17f3399904b43275c4a2d53322cb2b011aca Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 15 Apr 2013 19:01:36 +0300 Subject: [PATCH] Remove native git calls from MR. Dump diff as array, not class --- app/models/merge_request.rb | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 105d923..c1b4d4e 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -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 -- libgit2 0.21.2