summaryrefslogtreecommitdiff
path: root/app/models/merge_request.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-02 21:30:36 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-02 21:30:36 +0300
commit5f4445c3d384741c45242f077b3c0dbf76234ee8 (patch)
tree21962b2905103f2b3a585bda0ba6e60a669cb190 /app/models/merge_request.rb
parent7af16bbb0fdce36cf8b7e43e5cd64a712dfdaa1d (diff)
downloadgitlab-ce-5f4445c3d384741c45242f077b3c0dbf76234ee8.tar.gz
store commits for MR as array of hashes
Diffstat (limited to 'app/models/merge_request.rb')
-rw-r--r--app/models/merge_request.rb30
1 files changed, 12 insertions, 18 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 6ce944173cd..0bab88313c1 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -152,17 +152,7 @@ class MergeRequest < ActiveRecord::Base
end
def commits
- if st_commits.present?
- # check if merge request commits are valid
- if st_commits.first.respond_to?(:short_id)
- st_commits
- else
- # if commits are invalid - simply reload it from repo
- reloaded_commits
- end
- else
- []
- end
+ load_commits(st_commits) || []
end
def probably_merged?
@@ -172,13 +162,7 @@ class MergeRequest < ActiveRecord::Base
def reloaded_commits
if opened? && unmerged_commits.any?
- # we need to reset st_commits field first
- # in order to prevent internal rails comparison
- self.st_commits = []
- save
-
- # Then we can safely write unmerged commits
- self.st_commits = unmerged_commits
+ self.st_commits = dump_commits(unmerged_commits)
save
end
commits
@@ -228,4 +212,14 @@ class MergeRequest < ActiveRecord::Base
def last_commit_short_sha
@last_commit_short_sha ||= last_commit.sha[0..10]
end
+
+ private
+
+ def dump_commits(commits)
+ commits.map(&:to_hash)
+ end
+
+ def load_commits(array)
+ array.map { |hash| Commit.new(Gitlab::Git::Commit.new(hash)) }
+ end
end