diff options
-rw-r--r-- | app/views/commits/_diffs.html.haml | 6 | ||||
-rw-r--r-- | lib/gitlab/git/commit.rb | 25 |
2 files changed, 12 insertions, 19 deletions
diff --git a/app/views/commits/_diffs.html.haml b/app/views/commits/_diffs.html.haml index 9d57edb1d97..c95215036ae 100644 --- a/app/views/commits/_diffs.html.haml +++ b/app/views/commits/_diffs.html.haml @@ -17,14 +17,14 @@ - diffs.each_with_index do |diff, i| - next if diff.diff.empty? - file = Tree.new(@repository, @commit.id, @ref, diff.new_path) - - file = (@commit.prev_commit.tree / diff.old_path) unless file + - file = Tree.new(@repository, @commit.parent_id, @ref, diff.old_path) unless file - next unless file .file{id: "diff-#{i}"} .header - if diff.deleted_file %span= diff.old_path - - if @commit.prev_commit + - if @commit.parent_ids.present? = link_to project_tree_path(@project, tree_join(@commit.prev_commit_id, diff.new_path)), {:class => 'btn btn-tiny pull-right view-file'} do View file @ %span.commit-short-id= @commit.short_id(6) @@ -43,7 +43,7 @@ - if file.text? = render "commits/text_file", diff: diff, index: i - elsif file.image? - - old_file = (@commit.prev_commit.tree / diff.old_path) if !@commit.prev_commit.nil? + - old_file = Tree.new(@repository, @commit.parent_id, @ref, diff.old_path) if @commit.parent_id = render "commits/image", diff: diff, old_file: old_file, file: file, index: i - else %p.nothing_here_message No preview for this file type diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb index c691ea3d223..b7c5558739b 100644 --- a/lib/gitlab/git/commit.rb +++ b/lib/gitlab/git/commit.rb @@ -5,8 +5,8 @@ module Gitlab module Git class Commit attr_accessor :raw_commit, :head, :refs, - :sha, :authored_date, :committed_date, :message, - :author_name, :author_email, + :id, :authored_date, :committed_date, :message, + :author_name, :author_email, :parent_ids, :committer_name, :committer_email delegate :parents, :diffs, :tree, :stats, :to_patch, @@ -14,7 +14,7 @@ module Gitlab class << self def serialize_keys - %w(sha authored_date committed_date author_name author_email committer_name committer_email message) + %w(id authored_date committed_date author_name author_email committer_name committer_email message parent_ids) end def find_or_first(repo, commit_id = nil, root_ref) @@ -88,8 +88,8 @@ module Gitlab @head = head end - def id - sha + def sha + id end def short_id(length = 10) @@ -109,16 +109,8 @@ module Gitlab author_name != committer_name || author_email != committer_email end - def prev_commit - @prev_commit ||= if parents.present? - Commit.new(parents.first) - else - nil - end - end - - def prev_commit_id - prev_commit.try :id + def parent_id + parent_ids.first end # Shows the diff between the commit's parent and the commit. @@ -164,7 +156,7 @@ module Gitlab def init_from_grit(grit) @raw_commit = grit - @sha = grit.sha + @id = grit.id @message = grit.message @authored_date = grit.authored_date @committed_date = grit.committed_date @@ -172,6 +164,7 @@ module Gitlab @author_email = grit.author.email @committer_name = grit.committer.name @committer_email = grit.committer.email + @parent_ids = grit.parents.map(&:id) end def init_from_hash(hash) |