Skip to content

Commit

Permalink
Store diff head and start commit shas on MR diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
DouweM committed Jul 6, 2016
1 parent c66a7b0 commit 18a5bb0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app/models/merge_request_diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MergeRequestDiff < ActiveRecord::Base
serialize :st_diffs

after_create :reload_content, unless: :importing?
after_save :keep_around_commit
after_save :keep_around_commits

def reload_content
reload_commits
Expand Down Expand Up @@ -147,12 +147,13 @@ def reload_diffs

new_attributes[:st_diffs] = new_diffs

base_commit_sha = self.repository.merge_base(self.head, self.base)
new_attributes[:base_commit_sha] = base_commit_sha

self.repository.keep_around(base_commit_sha)
new_attributes[:start_commit_sha] = self.target_branch_sha
new_attributes[:head_commit_sha] = self.source_branch_sha
new_attributes[:base_commit_sha] = branch_base_sha

update_columns_serialized(new_attributes)

keep_around_commits
end

# Collect array of Git::Diff objects
Expand Down Expand Up @@ -223,7 +224,9 @@ def update_columns_serialized(new_attributes)
reload
end

def keep_around_commit
self.repository.keep_around(self.base_commit_sha)
def keep_around_commits
self.repository.keep_around(target_branch_sha)
self.repository.keep_around(source_branch_sha)
self.repository.keep_around(branch_base_sha)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddHeadCommitIdToMergeRequestDiffs < ActiveRecord::Migration
def change
add_column :merge_request_diffs, :head_commit_sha, :string
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddStartCommitIdToMergeRequestDiffs < ActiveRecord::Migration
def change
add_column :merge_request_diffs, :start_commit_sha, :string
end
end

0 comments on commit 18a5bb0

Please sign in to comment.